Krita Source Code Documentation
Loading...
Searching...
No Matches
KisImageResolutionProxy.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <kis_image.h>
10#include "kis_pointer_utils.h"
12
13namespace {
14
15struct IdentityResolutionProxyHolder
16{
17 IdentityResolutionProxyHolder()
18 : identity(new KisImageResolutionProxy())
19 {
20 }
21
23};
24
25Q_GLOBAL_STATIC(IdentityResolutionProxyHolder, s_holder)
26}
27
35
36 Private(const Private &rhs)
39 {
40 setImage(rhs.image);
41 }
42
49 if (imageConnection) {
50 QObject::disconnect(imageConnection);
51 }
52 }
53
57 QMetaObject::Connection imageConnection;
58
60 void slotImageResolutionChanged(qreal xRes, qreal yRes);
61};
62
67
72
74 : QObject(nullptr)
75 , m_d(new Private(*rhs.m_d))
76{
77}
78
82
84{
85 return m_d->image ? m_d->image->xRes() : m_d->lastKnownXRes;
86}
87
89{
90 return m_d->image ? m_d->image->yRes() : m_d->lastKnownYRes;
91}
92
94{
95 return qFuzzyCompare(xRes(), rhs.xRes()) &&
96 qFuzzyCompare(yRes(), rhs.yRes());
97
98}
99
101{
103 proxy->m_d->setImage(nullptr);
104 return proxy;
105}
106
111
113{
114 return s_holder->identity;
115}
116
122
124{
125 QObject::disconnect(imageConnection);
126
127 if (image) {
136 this->image = image;
137 lastKnownXRes = image->xRes();
138 lastKnownYRes = image->yRes();
139
140 imageConnection = connect(image.data(), &KisImage::sigResolutionChanged,
142 std::placeholders::_1, std::placeholders::_2));
143 } else {
148 this->image = nullptr;
149 }
150}
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QScopedPointer< Private > m_d
bool compareResolution(const KisImageResolutionProxy &rhs) const
KisImageResolutionProxySP cloneDetached() const
static KisImageResolutionProxySP identity()
KisImageResolutionProxySP createOrCloneDetached(KisImageWSP image) const
void sigResolutionChanged(double xRes, double yRes)
double xRes() const
double yRes() const
static bool qFuzzyCompare(half p1, half p2)
QSharedPointer< T > toQShared(T *ptr)
void slotImageResolutionChanged(qreal xRes, qreal yRes)