File indexing completed on 2024-12-22 04:15:49

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "ora_export.h"
0008 
0009 #include <QCheckBox>
0010 #include <QSlider>
0011 
0012 #include <kpluginfactory.h>
0013 #include <QFileInfo>
0014 #include <QApplication>
0015 #include <KoStore.h>
0016 #include <KisImportExportManager.h>
0017 #include <KoColorModelStandardIds.h>
0018 #include <KoColorSpace.h>
0019 #include <KisExportCheckRegistry.h>
0020 
0021 #include <KisDocument.h>
0022 #include <kis_image.h>
0023 #include <kis_node.h>
0024 #include <kis_group_layer.h>
0025 #include <kis_paint_layer.h>
0026 #include <kis_shape_layer.h>
0027 #include <KoProperties.h>
0028 
0029 #include "ora_converter.h"
0030 
0031 class KisExternalLayer;
0032 
0033 K_PLUGIN_FACTORY_WITH_JSON(ExportFactory, "krita_ora_export.json", registerPlugin<OraExport>();)
0034 
0035 OraExport::OraExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
0036 {
0037 }
0038 
0039 OraExport::~OraExport()
0040 {
0041 }
0042 
0043 
0044 bool hasShapeLayerChild(KisNodeSP node)
0045 {
0046     if (!node) return false;
0047 
0048     Q_FOREACH (KisNodeSP child, node->childNodes(QStringList(), KoProperties())) {
0049         if (child->inherits("KisShapeLayer")
0050                 || child->inherits("KisGeneratorLayer")
0051                 || child->inherits("KisCloneLayer")) {
0052             return true;
0053         }
0054         else {
0055             if (hasShapeLayerChild(child)) {
0056                 return true;
0057             }
0058         }
0059     }
0060     return false;
0061 }
0062 
0063 KisImportExportErrorCode OraExport::convert(KisDocument *document, QIODevice *io,  KisPropertiesConfigurationSP /*configuration*/)
0064 {
0065     KisImageSP image = document->savingImage();
0066     Q_CHECK_PTR(image);
0067     OraConverter oraConverter(document);
0068 
0069     KisImportExportErrorCode res = oraConverter.buildFile(io, image, {document->preActivatedNode()});
0070     return res;
0071 }
0072 
0073 void OraExport::initializeCapabilities()
0074 {
0075     addCapability(KisExportCheckRegistry::instance()->get("MultiLayerCheck")->create(KisExportCheckBase::SUPPORTED));
0076     addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGroupLayer")->create(KisExportCheckBase::SUPPORTED));
0077     addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisAdjustmentLayer")->create(KisExportCheckBase::SUPPORTED));
0078     addCapability(KisExportCheckRegistry::instance()->get("sRGBProfileCheck")->create(KisExportCheckBase::SUPPORTED));
0079     addCapability(KisExportCheckRegistry::instance()->get("ColorModelHomogenousCheck")->create(KisExportCheckBase::SUPPORTED));
0080     addCapability(KisExportCheckRegistry::instance()->get("LayerOpacityCheck")->create(KisExportCheckBase::SUPPORTED));
0081     QList<QPair<KoID, KoID> > supportedColorModels;
0082     supportedColorModels << QPair<KoID, KoID>()
0083             << QPair<KoID, KoID>(RGBAColorModelID, Integer8BitsColorDepthID)
0084             << QPair<KoID, KoID>(RGBAColorModelID, Integer16BitsColorDepthID)
0085             << QPair<KoID, KoID>(GrayAColorModelID, Integer8BitsColorDepthID)
0086             << QPair<KoID, KoID>(GrayAColorModelID, Integer16BitsColorDepthID);
0087     addSupportedColorModels(supportedColorModels, "OpenRaster");
0088 }
0089 
0090 QString OraExport::verify(const QString &fileName) const
0091 {
0092     QString error = KisImportExportFilter::verify(fileName);
0093     if (error.isEmpty()) {
0094         return KisImportExportFilter::verifyZiPBasedFiles(fileName,
0095                                                           QStringList()
0096                                                           << "mimetype"
0097                                                           << "stack.xml"
0098                                                           << "mergedimage.png");
0099     }
0100 
0101     return error;
0102 }
0103 
0104 
0105 
0106 #include <ora_export.moc>
0107