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 CHECKIMAGESIZE_H 0008 #define CHECKIMAGESIZE_H 0009 0010 #include "KisExportCheckRegistry.h" 0011 #include <KoID.h> 0012 #include <klocalizedstring.h> 0013 #include <kis_image.h> 0014 #include "kritaimpex_export.h" 0015 0016 class KRITAIMPEX_EXPORT ImageSizeCheck : public KisExportCheckBase 0017 { 0018 public: 0019 0020 ImageSizeCheck(int maxWidth, int maxHeight, const QString &id, Level level, const QString &customWarning = QString()) 0021 : KisExportCheckBase(id, level, customWarning, true) 0022 , m_maxW(maxWidth) 0023 , m_maxH(maxHeight) 0024 { 0025 if (customWarning.isEmpty()) { 0026 m_warning = i18nc("image conversion warning", "This image is larger than <b>%1 x %2</b>. Images this size cannot be saved to this format.", m_maxW, m_maxH); 0027 } 0028 } 0029 0030 bool checkNeeded(KisImageSP image) const override 0031 { 0032 return image->width() >= m_maxW && image->height() >= m_maxH; 0033 } 0034 0035 Level check(KisImageSP /*image*/) const override 0036 { 0037 return m_level; 0038 } 0039 0040 int m_maxW; 0041 int m_maxH; 0042 }; 0043 0044 class KRITAIMPEX_EXPORT ImageSizeCheckFactory : public KisExportCheckFactory 0045 { 0046 public: 0047 0048 ImageSizeCheckFactory() {} 0049 0050 ~ImageSizeCheckFactory() override {} 0051 0052 KisExportCheckBase *create( KisExportCheckBase::Level level, const QString &customWarning = QString()) override 0053 { 0054 return new ImageSizeCheck(100000000, 100000000, id(), level, customWarning); 0055 } 0056 0057 KisExportCheckBase *create(int maxWidth, int maxHeight, KisExportCheckBase::Level level, const QString &customWarning = QString()) 0058 { 0059 return new ImageSizeCheck(maxWidth, maxHeight, id(), level, customWarning); 0060 } 0061 0062 QString id() const override { 0063 return "ImageSizeCheck"; 0064 } 0065 }; 0066 0067 0068 #endif // CHECKIMAGESIZE_H