5
5
#include < qproperty.h>
6
6
#include < qqmlintegration.h>
7
7
#include < qqmlparserstatus.h>
8
+ #include < qrect.h>
8
9
#include < qrunnable.h>
9
10
#include < qtmetamacros.h>
10
11
#include < qtypes.h>
@@ -16,7 +17,7 @@ class ColorQuantizerOperation
16
17
Q_OBJECT;
17
18
18
19
public:
19
- explicit ColorQuantizerOperation (QUrl* source, qreal depth, qreal rescaleSize);
20
+ explicit ColorQuantizerOperation (QUrl* source, qreal depth, QRect imageRect, qreal rescaleSize);
20
21
21
22
void run () override ;
22
23
void tryCancel ();
@@ -44,6 +45,7 @@ private slots:
44
45
QList<QColor> colors;
45
46
QUrl* source;
46
47
qreal maxDepth;
48
+ QRect imageRect;
47
49
qreal rescaleSize;
48
50
};
49
51
@@ -78,6 +80,9 @@ class ColorQuantizer
78
80
// / binary split of the color space
79
81
Q_PROPERTY (qreal depth READ depth WRITE setDepth NOTIFY depthChanged);
80
82
83
+ // / Rectangle that the source image is cropped to.
84
+ Q_PROPERTY (QRect imageRect READ imageRect WRITE setImageRect NOTIFY imageRectChanged);
85
+
81
86
// / The size to rescale the image to, when rescaleSize is 0 then no scaling will be done.
82
87
// / > [!NOTE] Results from color quantization doesn't suffer much when rescaling, it's
83
88
// / > reccommended to rescale, otherwise the quantization process will take much longer.
@@ -97,13 +102,17 @@ class ColorQuantizer
97
102
[[nodiscard]] qreal depth () const { return mDepth ; }
98
103
void setDepth (qreal depth);
99
104
105
+ [[nodiscard]] QRect imageRect () const { return mImageRect ; }
106
+ void setImageRect (QRect imageRect);
107
+
100
108
[[nodiscard]] qreal rescaleSize () const { return mRescaleSize ; }
101
109
void setRescaleSize (int rescaleSize);
102
110
103
111
signals:
104
112
void colorsChanged ();
105
113
void sourceChanged ();
106
114
void depthChanged ();
115
+ void imageRectChanged ();
107
116
void rescaleSizeChanged ();
108
117
109
118
public slots:
@@ -117,6 +126,7 @@ public slots:
117
126
ColorQuantizerOperation* liveOperation = nullptr ;
118
127
QUrl mSource ;
119
128
qreal mDepth = 0 ;
129
+ QRect mImageRect = QRect();
120
130
qreal mRescaleSize = 0 ;
121
131
122
132
Q_OBJECT_BINDABLE_PROPERTY (
0 commit comments