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

#include <kis_tool_colorsampler.h>

+ Inheritance diagram for KisToolColorSampler:

Public Slots

void slotChangeBlend (int)
 
void slotChangeRadius (int)
 
void slotSetAddPalette (bool)
 
void slotSetColorSource (int value)
 
void slotSetNormaliseValues (bool)
 
void slotSetUpdateColor (bool)
 
- Public Slots inherited from KisTool
void activate (const QSet< KoShape * > &shapes) override
 
void canvasResourceChanged (int key, const QVariant &res) override
 
void deactivate () override
 
virtual void updateSettingsViews ()
 
- Public Slots inherited from KoToolBase
virtual void canvasResourceChanged (int key, const QVariant &res)
 
virtual void documentResourceChanged (int key, const QVariant &res)
 
virtual void repaintDecorations ()
 
virtual void requestRedoDuringStroke ()
 
virtual void requestStrokeCancellation ()
 
virtual void requestStrokeEnd ()
 
virtual void requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 

Public Member Functions

void activatePrimaryAction () override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
void deactivatePrimaryAction () override
 
void endPrimaryAction (KoPointerEvent *event) override
 
 KisToolColorSampler (KoCanvasBase *canvas)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
void requestUpdateOutline (const QPointF &outlineDocPoint, const KoPointerEvent *event)
 
 ~KisToolColorSampler () override
 
- Public Member Functions inherited from KisTool
virtual void activateAlternateAction (AlternateAction action)
 
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginPrimaryDoubleClickAction (KoPointerEvent *event)
 
virtual void continueAlternateAction (KoPointerEvent *event, AlternateAction action)
 
virtual void deactivateAlternateAction (AlternateAction action)
 
void deleteSelection () override
 
virtual void endAlternateAction (KoPointerEvent *event, AlternateAction action)
 
virtual int flags () const
 
bool isActive () const
 
 KisTool (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
void mouseTripleClickEvent (KoPointerEvent *event) override
 
virtual void newActivationWithExternalSource (KisPaintDeviceSP externalSource)
 newActivationWithExternalSource Makes sure that the tool is active and starts a new stroke, which will be able to access the pixels from the specified external source.
 
KisTool::NodePaintAbility nodePaintAbility ()
 
virtual bool primaryActionSupportsHiResEvents () const
 
virtual bool supportsPaintingAssistants () const
 
 ~KisTool () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoToolBase
QAction * action (const QString &name) const
 
KoCanvasBase * canvas () const
 Returns the canvas the tool is working on.
 
virtual void copy () const
 
QCursor cursor () const
 return the last emitted cursor
 
virtual void customMoveEvent (KoPointerEvent *event)
 
virtual void customPressEvent (KoPointerEvent *event)
 
virtual void customReleaseEvent (KoPointerEvent *event)
 
virtual void cut ()
 
virtual QRectF decorationsRect () const
 
int decorationThickness () const
 decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen magnification, thus the HiDPI settings. Note: to use this effectively, also set the pen to isCosmetic(true);
 
virtual void deselect ()
 deselect the tool should clear the selection if it has one.
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 
virtual void dropEvent (QDropEvent *event, const QPointF &point)
 
virtual void explicitUserStrokeEndRequest ()
 explicitUserStrokeEndRequest is called by the input manager when the user presses the Enter key or any equivalent key. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBase * factory () const
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual bool hasSelection ()
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
bool isInTextMode () const
 
bool isOpacityPresetMode () const
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
virtual KisPopupWidgetInterface * popupWidget ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelection * selection ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Protected Member Functions

void activate (const QSet< KoShape * > &) override
 
void deactivate () override
 
- Protected Member Functions inherited from KisTool
bool blockUntilOperationsFinished ()
 
void blockUntilOperationsFinishedForced ()
 
QPointF convertDocumentToWidget (const QPointF &pt)
 
QPoint convertToImagePixelCoordFloored (KoPointerEvent *e)
 
QPointF convertToPixelCoord (const QPointF &pt)
 
QPointF convertToPixelCoord (KoPointerEvent *e)
 
QPointF convertToPixelCoordAndAlignOnWidget (const QPointF &pt)
 
QPointF convertToPixelCoordAndSnap (const QPointF &pt, const QPointF &offset=QPointF())
 
QPointF convertToPixelCoordAndSnap (KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
 
QRectF convertToPt (const QRectF &rect)
 
qreal convertToPt (qreal value)
 
KoColor currentBgColor ()
 
KoColor currentFgColor ()
 
KisFilterConfigurationSP currentGenerator ()
 
KoAbstractGradientSP currentGradient ()
 
KisImageWSP currentImage ()
 
KisNodeSP currentNode () const
 
KisPaintOpPresetSP currentPaintOpPreset ()
 
KoPatternSP currentPattern ()
 
QCursor cursor () const
 
KisImageWSP image () const
 
virtual bool listeningToModifiers ()
 
virtual void listenToModifiers (bool listen)
 
virtual ToolMode mode () const
 
bool nodeEditable ()
 Checks checks if the current node is editable.
 
bool overrideCursorIfNotEditable ()
 Override the cursor appropriately if current node is not editable.
 
void paintToolOutline (QPainter *painter, const KisOptimizedBrushOutline &path)
 
KisOptimizedBrushOutline pixelToView (const KisOptimizedBrushOutline &path) const
 
QPainterPath pixelToView (const QPainterPath &pixelPath) const
 Convert a pixel path into a view path.
 
QPointF pixelToView (const QPoint &pixelCoord) const
 
QPointF pixelToView (const QPointF &pixelCoord) const
 Convert a floating point pixel coordinate into a view coordinate.
 
QPolygonF pixelToView (const QPolygonF &pixelPolygon) const
 Convert a pixel polygon into a view path.
 
QRectF pixelToView (const QRectF &pixelRect) const
 Convert a pixel rectangle into a view rectangle.
 
KisNodeList selectedNodes () const
 
bool selectionEditable ()
 Checks checks if the selection is editable, only applies to local selection as global selection is always editable.
 
void setCursor (const QCursor &cursor)
 
virtual void setMode (ToolMode mode)
 
void updateCanvasPixelRect (const QRectF &pixelRect)
 Update the canvas for the given rectangle in image pixel coordinates.
 
void updateCanvasViewRect (const QRectF &viewRect)
 Update the canvas for the given rectangle in view coordinates.
 
QPointF viewToPixel (const QPointF &viewCoord) const
 
QPointF widgetCenterInWidgetPixels ()
 
- Protected Member Functions inherited from KoToolBase
virtual QList< QPointer< QWidget > > createOptionWidgets ()
 
int grabSensitivity () const
 Convenience function to get the current grab sensitivity.
 
qreal handleDocRadius () const
 
QRectF handleGrabRect (const QPointF &position) const
 
QRectF handlePaintRect (const QPointF &position) const
 
int handleRadius () const
 Convenience function to get the current handle radius.
 
bool isActivated () const
 
 KoToolBase (KoToolBasePrivate &dd)
 
KoPointerEvent * lastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSP > toolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSP > toolConverters ()
 
void useCursor (const QCursor &cursor)
 

Private Slots

void slotChangePalette (int)
 
void slotColorPickerRequestedCursor (const QCursor &cursor)
 
void slotColorPickerRequestedCursorReset ()
 
void slotColorPickerRequestedOutlineUpdate ()
 
void slotColorPickerSelectedColor (const KoColor &color)
 
void slotColorPickerSelectionFinished (const KoColor &color)
 
void slotSetPreviewStyleComboBoxFromConfig ()
 
void slotSetPreviewStyleConfigFromComboBox ()
 

Private Member Functions

void displaySampledColor (const KoColor &color)
 
void updateOptionWidget ()
 

Private Attributes

QScopedPointer< KisToolUtils::ColorSamplerConfig > m_config
 
KisAsyncColorSamplerHelper m_helper
 
bool m_isActivated {false}
 
QRectF m_oldColorPreviewUpdateRect
 
ColorSamplerOptionsWidget * m_optionsWidget {0}
 
QPointF m_outlineDocPoint
 
KoColor m_sampledColor
 
KisTagFilterResourceProxyModel * m_tagFilterProxyModel {0}
 

Additional Inherited Members

- Public Types inherited from KisTool
enum  { FLAG_USES_CUSTOM_PRESET =0x01 , FLAG_USES_CUSTOM_COMPOSITEOP =0x02 , FLAG_USES_CUSTOM_SIZE =0x04 }
 
enum  AlternateAction {
  ChangeSize = AlternateChangeSize , ChangeSizeSnap = AlternateChangeSizeSnap , SampleFgNode = AlternateSampleFgNode , SampleBgNode = AlternateSampleBgNode ,
  SampleFgGroup = AlternateSampleFgGroup , SampleBgGroup = AlternateSampleBgGroup , SampleFgImage = AlternateSampleFgImage , SampleBgImage = AlternateSampleBgImage ,
  Secondary = AlternateSecondary , Third = AlternateThird , Fourth = AlternateFourth , Fifth = AlternateFifth ,
  NONE = 10000
}
 
enum  NodePaintAbility {
  VECTOR , CLONE , PAINT , UNPAINTABLE ,
  MYPAINTBRUSH_UNPAINTABLE
}
 
enum  ToolAction {
  Primary , AlternateChangeSize , AlternateChangeSizeSnap , AlternateSampleFgNode ,
  AlternateSampleBgNode , AlternateSampleFgGroup , AlternateSampleBgGroup , AlternateSampleFgImage ,
  AlternateSampleBgImage , AlternateSecondary , AlternateThird , AlternateFourth ,
  AlternateFifth , Alternate_NONE = 10000
}
 
- Signals inherited from KisTool
void isActiveChanged (bool isActivated)
 
- Signals inherited from KoToolBase
void activateTool (const QString &id)
 
void cursorChanged (const QCursor &cursor)
 
void selectionChanged (bool hasSelection)
 
void statusTextChanged (const QString &statusText)
 
void textModeChanged (bool inTextMode)
 
- Static Public Member Functions inherited from KisTool
static AlternateAction actionToAlternateAction (ToolAction action)
 
- Public Attributes inherited from KisTool
KoColor currentBgColor
 
float currentExposure {1.0}
 
KoColor currentFgColor
 
KisFilterConfigurationSP currentGenerator
 
KoAbstractGradientSP currentGradient
 
KoPatternSP currentPattern
 
QCursor cursor
 
bool m_isActive {false}
 
ToolMode m_mode {HOVER_MODE}
 
QWidget * optionWidget {0}
 
- Public Attributes inherited from Private
KisCanvas2 * canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Types inherited from KisTool
enum  ToolMode : int {
  HOVER_MODE , PAINT_MODE , SECONDARY_PAINT_MODE , MIRROR_AXIS_SETUP_MODE ,
  GESTURE_MODE , PAN_MODE , OTHER , OTHER_1
}
 
- Protected Slots inherited from KisTool
virtual void resetCursorStyle ()
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivate * d_ptr
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 37 of file kis_tool_colorsampler.h.

Constructor & Destructor Documentation

◆ KisToolColorSampler()

KisToolColorSampler::KisToolColorSampler ( KoCanvasBase * canvas)

Definition at line 29 of file kis_tool_colorsampler.cc.

32 m_helper(dynamic_cast<KisCanvas2*>(canvas))
33{
34 setObjectName("tool_colorsampler");
35 connect(&m_helper, SIGNAL(sigRequestCursor(QCursor)), this, SLOT(slotColorPickerRequestedCursor(QCursor)));
36 connect(&m_helper, SIGNAL(sigRequestCursorReset()), this, SLOT(slotColorPickerRequestedCursorReset()));
37 connect(&m_helper, SIGNAL(sigRequestUpdateOutline()), this, SLOT(slotColorPickerRequestedOutlineUpdate()));
38 connect(&m_helper, SIGNAL(sigRawColorSelected(KoColor)), this, SLOT(slotColorPickerSelectedColor(KoColor)));
39 connect(&m_helper, SIGNAL(sigFinalColorSelected(KoColor)), this, SLOT(slotColorPickerSelectionFinished(KoColor)));
40}
static QCursor samplerCursor()
void slotColorPickerRequestedCursor(const QCursor &cursor)
void slotColorPickerSelectedColor(const KoColor &color)
QScopedPointer< KisToolUtils::ColorSamplerConfig > m_config
KisAsyncColorSamplerHelper m_helper
void slotColorPickerSelectionFinished(const KoColor &color)
KisTool(KoCanvasBase *canvas, const QCursor &cursor)
Definition kis_tool.cc:78
KisCanvas2 * canvas

References m_helper, slotColorPickerRequestedCursor(), slotColorPickerRequestedCursorReset(), slotColorPickerRequestedOutlineUpdate(), slotColorPickerSelectedColor(), and slotColorPickerSelectionFinished().

◆ ~KisToolColorSampler()

KisToolColorSampler::~KisToolColorSampler ( )
override

Definition at line 42 of file kis_tool_colorsampler.cc.

43{
44 if (m_isActivated) {
45 m_config->save();
46 }
47}

References m_config, and m_isActivated.

Member Function Documentation

◆ activate()

void KisToolColorSampler::activate ( const QSet< KoShape * > & shapes)
overrideprotectedvirtual

This method is called when this tool instance is activated. For any main window there is only one tool active at a time, which then gets all user input. Switching between tools will call deactivate on one and activate on the new tool allowing the tool to flush items (like a selection) when it is not in use.

Parameters
shapesthe set of shapes that are selected or suggested for editing by a selected shape for the tool to work on. Not all shapes will be meant for this tool.
See also
deactivate()

Reimplemented from KoToolBase.

Definition at line 121 of file kis_tool_colorsampler.cc.

122{
123
124 m_isActivated = true;
125 m_config->load();
126
128
129 KisTool::activate(shapes);
130}
void activate(const QSet< KoShape * > &shapes) override
Definition kis_tool.cc:93

References KisTool::activate(), m_config, m_isActivated, and updateOptionWidget().

◆ activatePrimaryAction()

void KisToolColorSampler::activatePrimaryAction ( )
overridevirtual

Called by KisToolProxy when the primary action of the tool is going to be started now, that is when all the modifiers are pressed and the only thing left is just to press the mouse button. On coming of this callback the tool is supposed to prepare the cursor and/or the outline to show the user shat is going to happen next

We explicitly avoid calling KisTool::activatePrimaryAction() here, because it resets the cursor, causing cursor blinking

Reimplemented from KisTool.

Definition at line 174 of file kis_tool_colorsampler.cc.

175{
180 bool useOtherColor = canvas()->resourceManager()->boolResource(KoCanvasResource::UsingOtherColor);
181 // if useOtherColor is true, apply to the other color than that configured in the tool options
182 m_helper.updateCursor(m_config->sampleSource, m_config->toForegroundColor != useOtherColor);
183}
void updateCursor(KisToolUtils::ColorSamplerSource sampleSource, bool pickFgColor)
QPointer< KoCanvasResourceProvider > resourceManager

References Private::canvas, m_config, m_helper, KoCanvasBase::resourceManager, KisAsyncColorSamplerHelper::updateCursor(), and KoCanvasResource::UsingOtherColor.

◆ beginPrimaryAction()

void KisToolColorSampler::beginPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when a primary action for the tool is started. The event stores the original event that started the stroke. The event is accepted by default. If the tool decides to ignore this particular action (e.g. when the node is not editable), it should call event->ignore(). Then no further continuePrimaryAction() or endPrimaryAction() will be called until the next user action.

Reimplemented from KisTool.

Definition at line 140 of file kis_tool_colorsampler.cc.

141{
143
144 bool useOtherColor = canvas()->resourceManager()->boolResource(KoCanvasResource::UsingOtherColor);
145 // if useOtherColor is true, apply to the other color than that configured in the tool options
146 m_helper.activate(m_config->sampleSource, m_config->toForegroundColor != useOtherColor);
147 m_helper.startAction(event->point, m_config->radius, m_config->blend);
148 requestUpdateOutline(event->point, event);
149
151}
void startAction(const QPointF &docPoint, int radius, int blend)
void activate(KisToolUtils::ColorSamplerSource sampleSource, bool pickFgColor)
void requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event)
QPointF point
The point in document coordinates.
@ PAINT_MODE
Definition kis_tool.h:304
virtual void setMode(ToolMode mode)
Definition kis_tool.cc:403

References KisAsyncColorSamplerHelper::activate(), Private::canvas, m_config, m_helper, KisTool::PAINT_MODE, KoPointerEvent::point, requestUpdateOutline(), KoCanvasBase::resourceManager, KisTool::setMode(), KisAsyncColorSamplerHelper::setUpdateGlobalColor(), KisAsyncColorSamplerHelper::startAction(), and KoCanvasResource::UsingOtherColor.

◆ continuePrimaryAction()

void KisToolColorSampler::continuePrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is in progress of pointer movement. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 157 of file kis_tool_colorsampler.cc.

158{
160
162 requestUpdateOutline(event->point, event);
163}
void continueAction(const QPointF &docPoint)
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27

References CHECK_MODE_SANITY_OR_RETURN, KisAsyncColorSamplerHelper::continueAction(), m_helper, KisTool::PAINT_MODE, KoPointerEvent::point, and requestUpdateOutline().

◆ createOptionWidget()

QWidget * KisToolColorSampler::createOptionWidget ( )
overridevirtual

Reimplement this if your tool actually has an option widget. Sets the option widget to 0 by default.

Reimplemented from KisTool.

Definition at line 284 of file kis_tool_colorsampler.cc.

285{
287 m_optionsWidget->setObjectName(toolId() + " option widget");
288 m_optionsWidget->listViewChannels->setSortingEnabled(false);
289
290 // See https://bugs.kde.org/show_bug.cgi?id=316896
291 QWidget *specialSpacer = new QWidget(m_optionsWidget);
292 specialSpacer->setObjectName("SpecialSpacer");
293 specialSpacer->setFixedSize(0, 0);
294 m_optionsWidget->layout()->addWidget(specialSpacer);
295
299 this,
301 connect(m_optionsWidget->cmbPreviewStyle,
302 QOverload<int>::of(&QComboBox::activated),
303 this,
305
306 // Initialize blend KisSliderSpinBox
307 m_optionsWidget->blend->setRange(0,100);
309 i18nc("{n} is the number value, % is the percent sign", "{n}%"));
310
312
313 connect(m_optionsWidget->cbUpdateCurrentColor, SIGNAL(toggled(bool)), SLOT(slotSetUpdateColor(bool)));
314 connect(m_optionsWidget->cbNormaliseValues, SIGNAL(toggled(bool)), SLOT(slotSetNormaliseValues(bool)));
315 connect(m_optionsWidget->cbPalette, SIGNAL(toggled(bool)),
316 SLOT(slotSetAddPalette(bool)));
317 connect(m_optionsWidget->radius, SIGNAL(valueChanged(int)),
318 SLOT(slotChangeRadius(int)));
319 connect(m_optionsWidget->blend, SIGNAL(valueChanged(int)),
320 SLOT(slotChangeBlend(int)));
321 connect(m_optionsWidget->cmbSources, SIGNAL(currentIndexChanged(int)),
322 SLOT(slotSetColorSource(int)));
323
325 m_optionsWidget->cmbPalette->setModel(m_tagFilterProxyModel);
326 m_optionsWidget->cmbPalette->setModelColumn(KisAbstractResourceModel::Name);
327 m_tagFilterProxyModel->sort(Qt::DisplayRole);
328
329
330 KConfigGroup config = KSharedConfig::openConfig()->group(toolId());
331 QString paletteName = config.readEntry("ColorSamplerPalette", "");
332 if (!paletteName.isEmpty()) {
333 for (int i = 0; i < m_tagFilterProxyModel->rowCount(); i++) {
334 QModelIndex idx = m_tagFilterProxyModel->index(i, 0);
335 QString name = m_tagFilterProxyModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Name).toString();
336 if (name == paletteName) {
337 m_optionsWidget->cmbPalette->setCurrentIndex(i);
338 break;
339 }
340 }
341 }
342
343 connect(m_optionsWidget->cmbPalette, SIGNAL(currentIndexChanged(int)), SLOT(slotChangePalette(int)));
344
345 return m_optionsWidget;
346}
static void setColorSamplerPreviewStyleItems(QComboBox *cmb)
static KisConfigNotifier * instance()
void sigColorSamplerPreviewStyleChanged()
The KisTagFilterResourceProxyModel class filters the resources by tag or resource name.
void slotSetColorSource(int value)
KisTagFilterResourceProxyModel * m_tagFilterProxyModel
ColorSamplerOptionsWidget * m_optionsWidget
Q_INVOKABLE QString toolId() const
const char * name(StandardAction id)
void setText(QSpinBox *spinBox, const QStringView textTemplate)
const QString Palettes

References KisConfigNotifier::instance(), m_optionsWidget, m_tagFilterProxyModel, KisAbstractResourceModel::Name, ResourceType::Palettes, GeneralTab::setColorSamplerPreviewStyleItems(), KisSpinBoxI18nHelper::setText(), KisConfigNotifier::sigColorSamplerPreviewStyleChanged(), slotChangeBlend(), slotChangePalette(), slotChangeRadius(), slotSetAddPalette(), slotSetColorSource(), slotSetNormaliseValues(), slotSetPreviewStyleComboBoxFromConfig(), slotSetPreviewStyleConfigFromComboBox(), slotSetUpdateColor(), KoToolBase::toolId(), and updateOptionWidget().

◆ deactivate()

void KisToolColorSampler::deactivate ( )
overrideprotectedvirtual

This method is called whenever this tool is no longer the active tool

See also
activate()

Reimplemented from KoToolBase.

Definition at line 132 of file kis_tool_colorsampler.cc.

133{
134 m_config->save();
135
136 m_isActivated = false;
138}
void deactivate() override
Definition kis_tool.cc:131

References KisTool::deactivate(), m_config, and m_isActivated.

◆ deactivatePrimaryAction()

void KisToolColorSampler::deactivatePrimaryAction ( )
overridevirtual

Called by KisToolProxy when the primary is no longer possible to be started now, e.g. when its modifiers and released. The tool is supposed to revert all the preparations it has done in activatePrimaryAction().

We explicitly avoid calling KisTool::endPrimaryAction() here, because it resets the cursor, causing cursor blinking

Reimplemented from KisTool.

Definition at line 185 of file kis_tool_colorsampler.cc.

186{
191}

◆ displaySampledColor()

void KisToolColorSampler::displaySampledColor ( const KoColor & color)
private

Definition at line 232 of file kis_tool_colorsampler.cc.

233{
234 if (color.data() && m_optionsWidget) {
235
236 const QList<KoChannelInfo *> channels = color.colorSpace()->channels();
237 m_optionsWidget->listViewChannels->clear();
238
239 QVector<SampledChannel> sampledChannels;
240 for (int i = 0; i < channels.count(); ++i) {
241 sampledChannels.append(SampledChannel());
242 }
243
244 for (int i = 0; i < channels.count(); ++i) {
245
247 pc.name = channels[i]->name();
248
249 if (m_config->normaliseValues) {
250 pc.valueText = color.colorSpace()->normalisedChannelValueText(color.data(), i);
251 } else {
252 pc.valueText = color.colorSpace()->channelValueText(color.data(), i);
253 }
254
255 sampledChannels[channels[i]->displayPosition()] = pc;
256
257 }
258
259 Q_FOREACH (const SampledChannel &pc, sampledChannels) {
260 QTreeWidgetItem *item = new QTreeWidgetItem(m_optionsWidget->listViewChannels);
261 item->setText(0, pc.name);
262 item->setText(1, pc.valueText);
263 }
264
265
266 if (qEnvironmentVariableIsSet("KRITA_DEBUG_DISPLAY_COLOR")) {
267 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
268 KIS_ASSERT(kritaCanvas);
271
272 QVector<float> values(4);
273 newColor.colorSpace()->normalisedChannelsValue(newColor.data(), values);
274
275 for (int i = 0; i < values.size(); i++) {
276 QTreeWidgetItem *item = new QTreeWidgetItem(m_optionsWidget->listViewChannels);
277 item->setText(0, QString("DisplayCh%1").arg(i));
278 item->setText(1, QString::number(values[i]));
279 }
280 }
281 }
282}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
KisDisplayColorConverter displayColorConverter
KoColor applyDisplayFiltering(const KoColor &srcColor, const KoID &bitDepthId) const
virtual QString channelValueText(const quint8 *pixel, quint32 channelIndex) const =0
QList< KoChannelInfo * > channels
virtual KoID colorModelId() const =0
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
virtual QString normalisedChannelValueText(const quint8 *pixel, quint32 channelIndex) const =0
quint8 * data()
Definition KoColor.h:144
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References KisDisplayColorConverter::applyDisplayFiltering(), Private::canvas, KoColorSpace::channels, KoColorSpace::channelValueText(), KoColorSpace::colorModelId(), KoColor::colorSpace(), KoColor::data(), KisCanvas2::displayColorConverter, Float32BitsColorDepthID, KIS_ASSERT, KIS_SAFE_ASSERT_RECOVER_RETURN, m_config, m_optionsWidget, SampledChannel::name, KoColorSpace::normalisedChannelsValue(), KoColorSpace::normalisedChannelValueText(), RGBAColorModelID, and SampledChannel::valueText.

◆ endPrimaryAction()

void KisToolColorSampler::endPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is being finished, that is while mouseRelease or tabletRelease event. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 165 of file kis_tool_colorsampler.cc.

References CHECK_MODE_SANITY_OR_RETURN, KisAsyncColorSamplerHelper::deactivate(), KisAsyncColorSamplerHelper::endAction(), m_helper, KisTool::PAINT_MODE, KoPointerEvent::point, and requestUpdateOutline().

◆ mouseMoveEvent()

void KisToolColorSampler::mouseMoveEvent ( KoPointerEvent * event)
overridevirtual

Called when the mouse or stylus moved over the canvas. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus move

Reimplemented from KisTool.

Definition at line 153 of file kis_tool_colorsampler.cc.

153 {
155}
void mouseMoveEvent(KoPointerEvent *event) override
Definition kis_tool.cc:520

References KisTool::mouseMoveEvent().

◆ paint()

void KisToolColorSampler::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Called by the canvas to paint any decorations that the tool deems needed. The painter has the top left of the canvas as its origin.

Parameters
painterused for painting the shape
converterto convert between internal and view coordinates.

Implements KoToolBase.

Definition at line 116 of file kis_tool_colorsampler.cc.

117{
118 m_helper.paint(gc, converter);
119}
void paint(QPainter &gc, const KoViewConverter &converter)

References m_helper, and KisAsyncColorSamplerHelper::paint().

◆ requestUpdateOutline()

void KisToolColorSampler::requestUpdateOutline ( const QPointF & outlineDocPoint,
const KoPointerEvent * event )

Definition at line 193 of file kis_tool_colorsampler.cc.

194{
195 Q_UNUSED(event);
196
197 KisConfig cfg(true);
198
199 QRectF colorPreviewDocUpdateRect;
200
201 qreal zoomX;
202 qreal zoomY;
203 canvas()->viewConverter()->zoom(&zoomX, &zoomY);
204 qreal xoffset = 2.0/zoomX;
205 qreal yoffset = 2.0/zoomY;
206
207 m_outlineDocPoint = outlineDocPoint;
208
209 colorPreviewDocUpdateRect = m_helper.colorPreviewDocRect(m_outlineDocPoint);
210
211 if (!colorPreviewDocUpdateRect.isEmpty()) {
212 colorPreviewDocUpdateRect = colorPreviewDocUpdateRect.adjusted(-xoffset,-yoffset,xoffset,yoffset);
213 }
214
215 if (!m_oldColorPreviewUpdateRect.isEmpty()){
217 }
218
219 if (!colorPreviewDocUpdateRect.isEmpty()){
220 canvas()->updateCanvas(colorPreviewDocUpdateRect);
221 }
222
223 m_oldColorPreviewUpdateRect = colorPreviewDocUpdateRect;
224}
QRectF colorPreviewDocRect(const QPointF &docPoint)
void updateCanvas(const QRectF &rc) override
const KoViewConverter * viewConverter() const override
virtual void zoom(qreal *zoomX, qreal *zoomY) const

References Private::canvas, KisAsyncColorSamplerHelper::colorPreviewDocRect(), m_helper, m_oldColorPreviewUpdateRect, m_outlineDocPoint, KisCanvas2::updateCanvas(), KisCanvas2::viewConverter(), and KoViewConverter::zoom().

◆ slotChangeBlend

void KisToolColorSampler::slotChangeBlend ( int value)
slot

Definition at line 383 of file kis_tool_colorsampler.cc.

384{
385 m_config->blend = value;
386}
float value(const T *src, size_t ch)

References m_config, and value().

◆ slotChangePalette

void KisToolColorSampler::slotChangePalette ( int )
privateslot

Definition at line 393 of file kis_tool_colorsampler.cc.

394{
395 QString paletteName = m_optionsWidget->cmbPalette->currentData(Qt::UserRole + KisAbstractResourceModel::Name).toString();
396 KConfigGroup config = KSharedConfig::openConfig()->group(toolId());
397 config.writeEntry("ColorSamplerPalette", paletteName);
398}

References m_optionsWidget, KisAbstractResourceModel::Name, and KoToolBase::toolId().

◆ slotChangeRadius

void KisToolColorSampler::slotChangeRadius ( int value)
slot

Definition at line 378 of file kis_tool_colorsampler.cc.

379{
380 m_config->radius = value;
381}

References m_config, and value().

◆ slotColorPickerRequestedCursor

void KisToolColorSampler::slotColorPickerRequestedCursor ( const QCursor & cursor)
privateslot

Definition at line 49 of file kis_tool_colorsampler.cc.

50{
52}
void useCursor(const QCursor &cursor)
QCursor cursor
Definition kis_tool.cc:64

References KisTool::cursor, and KoToolBase::useCursor().

◆ slotColorPickerRequestedCursorReset

void KisToolColorSampler::slotColorPickerRequestedCursorReset ( )
privateslot

we explicitly avoid resetting the cursor style to avoid blinking of the cursor

Definition at line 54 of file kis_tool_colorsampler.cc.

55{
58}

◆ slotColorPickerRequestedOutlineUpdate

void KisToolColorSampler::slotColorPickerRequestedOutlineUpdate ( )
privateslot

Definition at line 60 of file kis_tool_colorsampler.cc.

References m_outlineDocPoint, and requestUpdateOutline().

◆ slotColorPickerSelectedColor

void KisToolColorSampler::slotColorPickerSelectedColor ( const KoColor & color)
privateslot

Please remember that m_sampledColor also have the alpha of the picked color!

Definition at line 65 of file kis_tool_colorsampler.cc.

66{
71 m_sampledColor = color;
73}
void displaySampledColor(const KoColor &color)

References displaySampledColor(), and m_sampledColor.

◆ slotColorPickerSelectionFinished

void KisToolColorSampler::slotColorPickerSelectionFinished ( const KoColor & color)
privateslot

Definition at line 75 of file kis_tool_colorsampler.cc.

76{
77 Q_UNUSED(color);
78
79 if (m_config->addColorToCurrentPalette) {
80 KisSwatch swatch;
81 swatch.setColor(color);
82 // We don't ask for a name, too intrusive here
83
84 QModelIndex idx = m_tagFilterProxyModel->index(m_optionsWidget->cmbPalette->currentIndex(), 0);
85 KoColorSetSP palette = qSharedPointerDynamicCast<KoColorSet>(m_tagFilterProxyModel->resourceForIndex(idx));
86
87 if (palette) {
88 KisSwatchGroup::SwatchInfo info =
89 palette->getClosestSwatchInfo(color);
90
91 if (info.swatch.color() != color) {
92 palette->addSwatch(swatch);
93 }
94 }
95 }
96}
void setColor(const KoColor &color)
Definition KisSwatch.cpp:32
KoResourceSP resourceForIndex(QModelIndex index=QModelIndex()) const override
resourceForIndex returns a properly versioned and id'ed resource object

References m_config, m_optionsWidget, m_tagFilterProxyModel, KisTagFilterResourceProxyModel::resourceForIndex(), and KisSwatch::setColor().

◆ slotSetAddPalette

void KisToolColorSampler::slotSetAddPalette ( bool state)
slot

Definition at line 373 of file kis_tool_colorsampler.cc.

374{
375 m_config->addColorToCurrentPalette = state;
376}

References m_config.

◆ slotSetColorSource

void KisToolColorSampler::slotSetColorSource ( int value)
slot

Definition at line 388 of file kis_tool_colorsampler.cc.

389{
390 m_config->sampleSource = static_cast<KisToolUtils::ColorSamplerSource>(value);
391}

References m_config, and value().

◆ slotSetNormaliseValues

void KisToolColorSampler::slotSetNormaliseValues ( bool state)
slot

Definition at line 367 of file kis_tool_colorsampler.cc.

368{
369 m_config->normaliseValues = state;
371}

References displaySampledColor(), m_config, and m_sampledColor.

◆ slotSetPreviewStyleComboBoxFromConfig

void KisToolColorSampler::slotSetPreviewStyleComboBoxFromConfig ( )
privateslot

Definition at line 98 of file kis_tool_colorsampler.cc.

99{
100 if (m_optionsWidget) {
101 QSignalBlocker blocker(m_optionsWidget->cmbPreviewStyle);
103 KisConfig(true).colorSamplerPreviewStyle());
104 }
105}
static void setColorSamplerPreviewStyleIndexByValue(QComboBox *cmb, KisConfig::ColorSamplerPreviewStyle style)

References m_optionsWidget, and GeneralTab::setColorSamplerPreviewStyleIndexByValue().

◆ slotSetPreviewStyleConfigFromComboBox

void KisToolColorSampler::slotSetPreviewStyleConfigFromComboBox ( )
privateslot

Definition at line 107 of file kis_tool_colorsampler.cc.

108{
109 if (m_optionsWidget) {
113 }
114}
static KisConfig::ColorSamplerPreviewStyle getColorSamplerPreviewStyleValue(const QComboBox *cmb)
ColorSamplerPreviewStyle
Definition kis_config.h:138
void setColorSamplerPreviewStyle(ColorSamplerPreviewStyle style)

References GeneralTab::getColorSamplerPreviewStyleValue(), m_optionsWidget, and KisConfig::setColorSamplerPreviewStyle().

◆ slotSetUpdateColor

void KisToolColorSampler::slotSetUpdateColor ( bool state)
slot

Definition at line 362 of file kis_tool_colorsampler.cc.

363{
364 m_config->updateColor = state;
365}

References m_config.

◆ updateOptionWidget()

void KisToolColorSampler::updateOptionWidget ( )
private

Definition at line 348 of file kis_tool_colorsampler.cc.

349{
350 if (!m_optionsWidget) return;
351
352 m_optionsWidget->cbNormaliseValues->setChecked(m_config->normaliseValues);
353 m_optionsWidget->cbUpdateCurrentColor->setChecked(m_config->updateColor);
354 m_optionsWidget->cmbSources->setCurrentIndex(static_cast<int>(m_config->sampleSource));
355 m_optionsWidget->cbPalette->setChecked(m_config->addColorToCurrentPalette);
356 m_optionsWidget->radius->setValue(m_config->radius);
357 m_optionsWidget->blend->setValue(m_config->blend);
358
360}

References m_config, m_optionsWidget, and slotSetPreviewStyleComboBoxFromConfig().

Member Data Documentation

◆ m_config

QScopedPointer<KisToolUtils::ColorSamplerConfig> KisToolColorSampler::m_config
private

Definition at line 88 of file kis_tool_colorsampler.h.

◆ m_helper

KisAsyncColorSamplerHelper KisToolColorSampler::m_helper
private

Definition at line 97 of file kis_tool_colorsampler.h.

◆ m_isActivated

bool KisToolColorSampler::m_isActivated {false}
private

Definition at line 90 of file kis_tool_colorsampler.h.

90{false};

◆ m_oldColorPreviewUpdateRect

QRectF KisToolColorSampler::m_oldColorPreviewUpdateRect
private

Definition at line 93 of file kis_tool_colorsampler.h.

◆ m_optionsWidget

ColorSamplerOptionsWidget* KisToolColorSampler::m_optionsWidget {0}
private

Definition at line 99 of file kis_tool_colorsampler.h.

99{0};

◆ m_outlineDocPoint

QPointF KisToolColorSampler::m_outlineDocPoint
private

Definition at line 91 of file kis_tool_colorsampler.h.

◆ m_sampledColor

KoColor KisToolColorSampler::m_sampledColor
private

Definition at line 95 of file kis_tool_colorsampler.h.

◆ m_tagFilterProxyModel

KisTagFilterResourceProxyModel* KisToolColorSampler::m_tagFilterProxyModel {0}
private

Definition at line 100 of file kis_tool_colorsampler.h.

100{0};

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