Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAsyncColorSamplerHelper Class Reference

#include <KisAsyncColorSamplerHelper.h>

+ Inheritance diagram for KisAsyncColorSamplerHelper:

Classes

struct  Private
 

Signals

void sigColorSelected (const KoColor &color)
 
void sigFinalColorSelected (const KoColor &color)
 
void sigRawColorSelected (const KoColor &color)
 
void sigRequestCursor (const QCursor &cursor)
 
void sigRequestCursorReset ()
 
void sigRequestUpdateOutline ()
 

Public Member Functions

void activate (bool sampleCurrentLayer, bool pickFgColor)
 
QRectF colorPreviewDocRect (const QPointF &docPoint)
 
void continueAction (const QPointF &docPoint)
 
void deactivate ()
 
void endAction ()
 
bool isActive () const
 
 KisAsyncColorSamplerHelper (KisCanvas2 *canvas)
 
void paint (QPainter &gc, const KoViewConverter &converter)
 
void setUpdateGlobalColor (bool value)
 
void startAction (const QPointF &docPoint, int radius, int blend)
 
void updateCursor (bool sampleCurrentLayer, bool pickFgColor)
 
bool updateGlobalColor () const
 
 ~KisAsyncColorSamplerHelper () override
 

Private Slots

void activateDelayedPreview ()
 
void slotAddSamplingJob (const QPointF &docPoint)
 
void slotColorSamplingFinished (const KoColor &rawColor)
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 23 of file KisAsyncColorSamplerHelper.h.

Constructor & Destructor Documentation

◆ KisAsyncColorSamplerHelper()

KisAsyncColorSamplerHelper::KisAsyncColorSamplerHelper ( KisCanvas2 * canvas)

Definition at line 86 of file KisAsyncColorSamplerHelper.cpp.

87 : m_d(new Private(canvas))
88{
89 using namespace std::placeholders; // For _1 placeholder
90 std::function<void(QPointF)> callback =
92 m_d->samplingCompressor.reset(
94
95 m_d->activationDelayTimer.setInterval(100);
96 m_d->activationDelayTimer.setSingleShot(true);
97 connect(&m_d->activationDelayTimer, SIGNAL(timeout()), this, SLOT(activateDelayedPreview()));
98}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotAddSamplingJob(const QPointF &docPoint)
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)
KisSignalCompressorWithParam< QPointF > SamplingCompressor

References activateDelayedPreview(), connect(), KisSignalCompressor::FIRST_ACTIVE, m_d, slotAddSamplingJob(), and void().

◆ ~KisAsyncColorSamplerHelper()

KisAsyncColorSamplerHelper::~KisAsyncColorSamplerHelper ( )
override

Definition at line 100 of file KisAsyncColorSamplerHelper.cpp.

101{
103}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP, and m_d.

Member Function Documentation

◆ activate()

void KisAsyncColorSamplerHelper::activate ( bool sampleCurrentLayer,
bool pickFgColor )

Definition at line 110 of file KisAsyncColorSamplerHelper.cpp.

111{
113 m_d->isActive = true;
114
115 m_d->sampleResourceId =
116 pickFgColor ?
119
120 m_d->sampleCurrentLayer = sampleCurrentLayer;
121 m_d->showComparePlate = false;
122
123 m_d->activationDelayTimer.start();
124}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.

References KoCanvasResource::BackgroundColor, KoCanvasResource::ForegroundColor, KIS_SAFE_ASSERT_RECOVER_RETURN, and m_d.

◆ activateDelayedPreview

void KisAsyncColorSamplerHelper::activateDelayedPreview ( )
privateslot

Definition at line 126 of file KisAsyncColorSamplerHelper.cpp.

127{
128 // the event may come after we have finished color
129 // picking if the user is quick
130 if (!m_d->isActive) return;
131
132 m_d->showPreview = true;
133
134 const KoColor currentColor =
135 m_d->canvas->resourceManager()->koColorResource(m_d->sampleResourceId);
136 const QColor previewColor = m_d->canvas->displayColorConverter()->toQColor(currentColor);
137
138 m_d->currentColor = previewColor;
139 m_d->baseColor = previewColor;
140
141 updateCursor(m_d->sampleCurrentLayer, m_d->sampleResourceId == KoCanvasResource::ForegroundColor);
142
144}
void updateCursor(bool sampleCurrentLayer, bool pickFgColor)
void toQColor(QColor *c) const
a convenience method for the above.
Definition KoColor.cpp:198
KoColor currentColor(ResourceProvider *provider, ColorRole role)

References KoCanvasResource::ForegroundColor, m_d, sigRequestUpdateOutline(), KoColor::toQColor(), and updateCursor().

◆ colorPreviewDocRect()

QRectF KisAsyncColorSamplerHelper::colorPreviewDocRect ( const QPointF & docPoint)

Definition at line 233 of file KisAsyncColorSamplerHelper.cpp.

234{
235 if (!m_d->showPreview) return QRectF();
236
237 std::tie(m_d->currentColorDocRect, m_d->baseColorDocRect) =
238 colorPreviewDocRectImpl(docPoint, m_d->showComparePlate, &m_d->converter());
239
240 return m_d->currentColorDocRect | m_d->baseColorDocRect;
241}

References m_d.

◆ continueAction()

void KisAsyncColorSamplerHelper::continueAction ( const QPointF & docPoint)

Definition at line 216 of file KisAsyncColorSamplerHelper.cpp.

217{
219 m_d->samplingCompressor->start(docPoint);
220}

References KIS_SAFE_ASSERT_RECOVER_RETURN, and m_d.

◆ deactivate()

void KisAsyncColorSamplerHelper::deactivate ( )

Definition at line 182 of file KisAsyncColorSamplerHelper.cpp.

183{
184 KIS_SAFE_ASSERT_RECOVER(!m_d->strokeId) {
185 endAction();
186 }
187
188 m_d->activationDelayTimer.stop();
189
190 m_d->showPreview = false;
191 m_d->showComparePlate = false;
192
193 m_d->currentColorDocRect = QRectF();
194 m_d->currentColor = QColor();
195 m_d->baseColor = QColor();
196 m_d->baseColorDocRect = QRectF();
197
198 m_d->isActive = false;
199
200 Q_EMIT sigRequestCursorReset();
202}
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References endAction(), KIS_SAFE_ASSERT_RECOVER, m_d, sigRequestCursorReset(), and sigRequestUpdateOutline().

◆ endAction()

void KisAsyncColorSamplerHelper::endAction ( )

Definition at line 222 of file KisAsyncColorSamplerHelper.cpp.

223{
225
226 m_d->strokesFacade()->addJob(m_d->strokeId,
228
229 m_d->strokesFacade()->endStroke(m_d->strokeId);
230 m_d->strokeId.clear();
231}

References KIS_SAFE_ASSERT_RECOVER_RETURN, and m_d.

◆ isActive()

bool KisAsyncColorSamplerHelper::isActive ( ) const

Definition at line 105 of file KisAsyncColorSamplerHelper.cpp.

106{
107 return m_d->isActive;
108}

References m_d.

◆ paint()

void KisAsyncColorSamplerHelper::paint ( QPainter & gc,
const KoViewConverter & converter )

Definition at line 243 of file KisAsyncColorSamplerHelper.cpp.

244{
245 if (!m_d->showPreview) return;
246
247 const QRectF viewRect = converter.documentToView(m_d->currentColorDocRect);
248 gc.fillRect(viewRect, m_d->currentColor);
249
250 if (m_d->showComparePlate) {
251 const QRectF baseColorRect = converter.documentToView(m_d->baseColorDocRect);
252 gc.fillRect(baseColorRect, m_d->baseColor);
253 }
254}
virtual QPointF documentToView(const QPointF &documentPoint) const

References KoViewConverter::documentToView(), and m_d.

◆ setUpdateGlobalColor()

void KisAsyncColorSamplerHelper::setUpdateGlobalColor ( bool value)

Definition at line 172 of file KisAsyncColorSamplerHelper.cpp.

173{
174 m_d->updateGlobalColor = value;
175}
float value(const T *src, size_t ch)

References m_d, and value().

◆ sigColorSelected

void KisAsyncColorSamplerHelper::sigColorSelected ( const KoColor & color)
signal

Notifies about the "palette" color picked from the layer, that is, with the alpha channel set to OPACITY_OPAQUE.

◆ sigFinalColorSelected

void KisAsyncColorSamplerHelper::sigFinalColorSelected ( const KoColor & color)
signal

Notifies about the "palette" color picked from the layer, that is, with the alpha channel set to OPACITY_OPAQUE.

This notification is emitted only once at the very end of the color picking stroke.

◆ sigRawColorSelected

void KisAsyncColorSamplerHelper::sigRawColorSelected ( const KoColor & color)
signal

Notifies about the raw color picked from the layer, including its alpha channel.

◆ sigRequestCursor

void KisAsyncColorSamplerHelper::sigRequestCursor ( const QCursor & cursor)
signal

◆ sigRequestCursorReset

void KisAsyncColorSamplerHelper::sigRequestCursorReset ( )
signal

◆ sigRequestUpdateOutline

void KisAsyncColorSamplerHelper::sigRequestUpdateOutline ( )
signal

◆ slotAddSamplingJob

void KisAsyncColorSamplerHelper::slotAddSamplingJob ( const QPointF & docPoint)
privateslot

The actual sampling is delayed by a compressor, so we can get this event when the stroke is already closed

Definition at line 256 of file KisAsyncColorSamplerHelper.cpp.

257{
262 if (!m_d->strokeId) return;
263
264 KisImageSP image = m_d->canvas->image();
265
266 const QPoint imagePoint = image->documentToImagePixelFloored(docPoint);
267
268 if (!m_d->sampleCurrentLayer) {
269 KisSharedPtr<KisReferenceImagesLayer> referencesLayer = m_d->canvas->imageView()->document()->referenceImagesLayer();
270 if (referencesLayer && m_d->canvas->referenceImagesDecoration()->visible()) {
271 QColor color = referencesLayer->getPixel(imagePoint);
272 if (color.isValid() && color.alpha() != 0) {
274 return;
275 }
276 }
277 }
278
279 KisPaintDeviceSP device = m_d->sampleCurrentLayer ?
280 m_d->canvas->imageView()->currentNode()->colorSampleSourceDevice() :
281 image->projection();
282
283 if (device) {
284 // Used for color sampler blending.
285 const KoColor currentColor =
286 m_d->canvas->resourceManager()->koColorResource(m_d->sampleResourceId);
287
288 m_d->strokesFacade()->addJob(m_d->strokeId,
289 new KisColorSamplerStrokeStrategy::Data(device, imagePoint, currentColor));
290 } else {
291 QString message = i18n("Color sampler does not work on this layer.");
292 m_d->canvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
293 }
294}
void slotColorSamplingFinished(const KoColor &rawColor)
KisImageWSP image() const
const KoColorSpace * colorSpace() const
KisPaintDeviceSP projection() const
QPoint documentToImagePixelFloored(const QPointF &documentCoord) const
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
KisCanvas2 * canvas

References Private::canvas, KisImage::colorSpace(), KisImage::documentToImagePixelFloored(), KisCanvas2::image(), koIcon, m_d, KisImage::projection(), and slotColorSamplingFinished().

◆ slotColorSamplingFinished

void KisAsyncColorSamplerHelper::slotColorSamplingFinished ( const KoColor & rawColor)
privateslot

Definition at line 296 of file KisAsyncColorSamplerHelper.cpp.

297{
298 KoColor color(rawColor);
299
300 color.setOpacity(OPACITY_OPAQUE_U8);
301
302 if (m_d->updateGlobalColor) {
303 m_d->canvas->resourceManager()->setResource(m_d->sampleResourceId, color);
304 }
305
306 Q_EMIT sigRawColorSelected(rawColor);
307 Q_EMIT sigColorSelected(color);
308
309 if (!m_d->showPreview) return;
310
311 const QColor previewColor = m_d->canvas->displayColorConverter()->toQColor(color);
312
313 m_d->showComparePlate = true;
314 m_d->currentColor = previewColor;
315
317}
const quint8 OPACITY_OPAQUE_U8
void sigColorSelected(const KoColor &color)
void sigRawColorSelected(const KoColor &color)

References m_d, OPACITY_OPAQUE_U8, KoColor::setOpacity(), sigColorSelected(), sigRawColorSelected(), and sigRequestUpdateOutline().

◆ startAction()

void KisAsyncColorSamplerHelper::startAction ( const QPointF & docPoint,
int radius,
int blend )

◆ updateCursor()

void KisAsyncColorSamplerHelper::updateCursor ( bool sampleCurrentLayer,
bool pickFgColor )

Definition at line 146 of file KisAsyncColorSamplerHelper.cpp.

147{
148 const int sampleResourceId =
149 pickFgColor ?
152
153 QCursor cursor;
154
155 if (sampleCurrentLayer) {
156 if (sampleResourceId == KoCanvasResource::ForegroundColor) {
158 } else {
160 }
161 } else {
162 if (sampleResourceId == KoCanvasResource::ForegroundColor) {
164 } else {
166 }
167 }
168
169 Q_EMIT sigRequestCursor(cursor);
170}
void sigRequestCursor(const QCursor &cursor)
static QCursor samplerImageBackgroundCursor()
static QCursor samplerLayerBackgroundCursor()
static QCursor samplerLayerForegroundCursor()
static QCursor samplerImageForegroundCursor()

References KoCanvasResource::BackgroundColor, KoCanvasResource::ForegroundColor, KisCursor::samplerImageBackgroundCursor(), KisCursor::samplerImageForegroundCursor(), KisCursor::samplerLayerBackgroundCursor(), KisCursor::samplerLayerForegroundCursor(), and sigRequestCursor().

◆ updateGlobalColor()

bool KisAsyncColorSamplerHelper::updateGlobalColor ( ) const

Definition at line 177 of file KisAsyncColorSamplerHelper.cpp.

178{
179 return m_d->updateGlobalColor;
180}

References m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisAsyncColorSamplerHelper::m_d
private

Definition at line 79 of file KisAsyncColorSamplerHelper.h.


The documentation for this class was generated from the following files: