File indexing completed on 2024-05-19 04:26:42
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KISIMAGERESOLUTIONPROXY_H 0008 #define KISIMAGERESOLUTIONPROXY_H 0009 0010 #include <kis_types.h> 0011 #include <kritaimage_export.h> 0012 0013 class KisImageResolutionProxy; 0014 using KisImageResolutionProxySP = QSharedPointer<KisImageResolutionProxy>; 0015 0016 0017 /** 0018 * KisImageResolutionProxy is a simple interface class that 0019 * keeps a link to the resolution of KisImage. When KisImage 0020 * is destroyed, the proxy still stores the "last known" image 0021 * resolution and returns that to the user. 0022 * 0023 * The proxy may also be in a detached state, that is, unconnected 0024 * to any image. Then is stored the "last known image resolution 0025 * value". 0026 */ 0027 class KRITAIMAGE_EXPORT KisImageResolutionProxy : public QObject 0028 { 0029 Q_OBJECT 0030 public: 0031 KisImageResolutionProxy(); 0032 KisImageResolutionProxy(KisImageWSP image); 0033 KisImageResolutionProxy(const KisImageResolutionProxy &rhs); 0034 ~KisImageResolutionProxy(); 0035 0036 qreal xRes() const; 0037 qreal yRes() const; 0038 0039 /** 0040 * Compare resolution of (*this) and \p rhs 0041 */ 0042 bool compareResolution(const KisImageResolutionProxy &rhs) const; 0043 0044 /** 0045 * Returns a copy of this proxy that stores the 0046 * same resolution, but is detached from the image. 0047 * That is, when the image changes its resolution 0048 * any time in the future, this proxy will no react 0049 * on that. 0050 */ 0051 KisImageResolutionProxySP cloneDetached() const; 0052 0053 /** 0054 * Helper function that checks if the passed image is 0055 * not null and creates a resolution proxy for that. 0056 * If the passed image is null, then a detached clone 0057 * of (*this) is returned. 0058 * 0059 * The function is used in layers, when they are detached 0060 * from the image (layer->setImage(nullptr)). In such a 0061 * case it is useful to keep the old resolution stored 0062 * in a detached proxy, other than resetting it to default. 0063 * It allows avoiding unnecessary updates. 0064 */ 0065 KisImageResolutionProxySP createOrCloneDetached(KisImageWSP image) const; 0066 0067 /** 0068 * Return an identity resolution proxy that returns 1.0 for both, 0069 * xRes() and yRes(). Used as a fallback proxy mostly. 0070 */ 0071 static KisImageResolutionProxySP identity(); 0072 0073 private: 0074 struct Private; 0075 QScopedPointer<Private> m_d; 0076 }; 0077 0078 0079 0080 #endif // KISIMAGERESOLUTIONPROXY_H