File indexing completed on 2024-05-12 15:59:02

0001 /*
0002  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef MultiLayerCheck_H
0008 #define MultiLayerCheck_H
0009 
0010 #include "KisExportCheckRegistry.h"
0011 #include <KoID.h>
0012 #include <klocalizedstring.h>
0013 #include <kis_image.h>
0014 #include <kis_group_layer.h>
0015 
0016 class MultiLayerCheck : public KisExportCheckBase
0017 {
0018 public:
0019 
0020     MultiLayerCheck(const QString &id, Level level, const QString &customWarning = QString())
0021         : KisExportCheckBase(id, level, customWarning)
0022     {
0023         if (customWarning.isEmpty()) {
0024             m_warning = i18nc("image conversion warning", "The image has <b>more than one layer or a mask or an active selection</b>. Only the flattened image will be saved.");
0025         }
0026     }
0027 
0028     bool checkNeeded(KisImageSP image) const override
0029     {
0030         return (image->rootLayer()->childCount() > 1);
0031     }
0032 
0033     Level check(KisImageSP /*image*/) const override
0034     {
0035         return m_level;
0036     }
0037 
0038 };
0039 
0040 class MultiLayerCheckFactory : public KisExportCheckFactory
0041 {
0042 public:
0043 
0044     MultiLayerCheckFactory() {}
0045 
0046     ~MultiLayerCheckFactory() override {}
0047 
0048     KisExportCheckBase *create(KisExportCheckBase::Level level, const QString &customWarning) override
0049     {
0050         return new MultiLayerCheck(id(), level, customWarning);
0051     }
0052 
0053     QString id() const override {
0054         return "MultiLayerCheck";
0055     }
0056 };
0057 
0058 #endif // MultiLayerCheck_H