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

#include <kis_tool_colorsampler.h>

+ Inheritance diagram for KisToolColorSampler:

Classes

struct  Configuration
 

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
 
KoCanvasBasecanvas () 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 Enter key or any equivalent. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBasefactory () 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 KisPopupWidgetInterfacepopupWidget ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelectionselection ()
 
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)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSPtoolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSPtoolConverters ()
 
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)
 

Private Member Functions

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

Private Attributes

QScopedPointer< KisToolUtils::ColorSamplerConfigm_config
 
KisAsyncColorSamplerHelper m_helper
 
bool m_isActivated {false}
 
QRectF m_oldColorPreviewUpdateRect
 
ColorSamplerOptionsWidgetm_optionsWidget {0}
 
QPointF m_outlineDocPoint
 
KoColor m_sampledColor
 
KisTagFilterResourceProxyModelm_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 ,
  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 , 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
KisCanvas2canvas
 
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
KoToolBasePrivated_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 31 of file kis_tool_colorsampler.cc.

34 m_helper(dynamic_cast<KisCanvas2*>(canvas))
35{
36 setObjectName("tool_colorsampler");
37 connect(&m_helper, SIGNAL(sigRequestCursor(QCursor)), this, SLOT(slotColorPickerRequestedCursor(QCursor)));
38 connect(&m_helper, SIGNAL(sigRequestCursorReset()), this, SLOT(slotColorPickerRequestedCursorReset()));
39 connect(&m_helper, SIGNAL(sigRequestUpdateOutline()), this, SLOT(slotColorPickerRequestedOutlineUpdate()));
40 connect(&m_helper, SIGNAL(sigRawColorSelected(KoColor)), this, SLOT(slotColorPickerSelectedColor(KoColor)));
41 connect(&m_helper, SIGNAL(sigFinalColorSelected(KoColor)), this, SLOT(slotColorPickerSelectionFinished(KoColor)));
42}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
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 connect(), m_helper, slotColorPickerRequestedCursor(), slotColorPickerRequestedCursorReset(), slotColorPickerRequestedOutlineUpdate(), slotColorPickerSelectedColor(), and slotColorPickerSelectionFinished().

◆ ~KisToolColorSampler()

KisToolColorSampler::~KisToolColorSampler ( )
override

Definition at line 44 of file kis_tool_colorsampler.cc.

45{
46 if (m_isActivated) {
47 m_config->save();
48 }
49}

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 105 of file kis_tool_colorsampler.cc.

106{
107
108 m_isActivated = true;
109 m_config->load();
110
112
113 KisTool::activate(shapes);
114}
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 158 of file kis_tool_colorsampler.cc.

159{
164 bool useOtherColor = canvas()->resourceManager()->boolResource(KoCanvasResource::UsingOtherColor);
165 // if useOtherColor is true, apply to the other color than that configured in the tool options
166 m_helper.updateCursor(!m_config->sampleMerged, m_config->toForegroundColor != useOtherColor);
167}
void updateCursor(bool sampleCurrentLayer, 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 124 of file kis_tool_colorsampler.cc.

125{
127
128 bool useOtherColor = canvas()->resourceManager()->boolResource(KoCanvasResource::UsingOtherColor);
129 // if useOtherColor is true, apply to the other color than that configured in the tool options
130 m_helper.activate(!m_config->sampleMerged, m_config->toForegroundColor != useOtherColor);
131 m_helper.startAction(event->point, m_config->radius, m_config->blend);
132 requestUpdateOutline(event->point, event);
133
135}
void activate(bool sampleCurrentLayer, bool pickFgColor)
void startAction(const QPointF &docPoint, int radius, int blend)
void requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event)
QPointF point
The point in document coordinates.
@ PAINT_MODE
Definition kis_tool.h:300
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 141 of file kis_tool_colorsampler.cc.

142{
144
146 requestUpdateOutline(event->point, event);
147}
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 268 of file kis_tool_colorsampler.cc.

269{
271 m_optionsWidget->setObjectName(toolId() + " option widget");
272 m_optionsWidget->listViewChannels->setSortingEnabled(false);
273
274 // See https://bugs.kde.org/show_bug.cgi?id=316896
275 QWidget *specialSpacer = new QWidget(m_optionsWidget);
276 specialSpacer->setObjectName("SpecialSpacer");
277 specialSpacer->setFixedSize(0, 0);
278 m_optionsWidget->layout()->addWidget(specialSpacer);
279
280 // Initialize blend KisSliderSpinBox
281 m_optionsWidget->blend->setRange(0,100);
283 i18nc("{n} is the number value, % is the percent sign", "{n}%"));
284
286
287 connect(m_optionsWidget->cbUpdateCurrentColor, SIGNAL(toggled(bool)), SLOT(slotSetUpdateColor(bool)));
288 connect(m_optionsWidget->cbNormaliseValues, SIGNAL(toggled(bool)), SLOT(slotSetNormaliseValues(bool)));
289 connect(m_optionsWidget->cbPalette, SIGNAL(toggled(bool)),
290 SLOT(slotSetAddPalette(bool)));
291 connect(m_optionsWidget->radius, SIGNAL(valueChanged(int)),
292 SLOT(slotChangeRadius(int)));
293 connect(m_optionsWidget->blend, SIGNAL(valueChanged(int)),
294 SLOT(slotChangeBlend(int)));
295 connect(m_optionsWidget->cmbSources, SIGNAL(currentIndexChanged(int)),
296 SLOT(slotSetColorSource(int)));
297
299 m_optionsWidget->cmbPalette->setModel(m_tagFilterProxyModel);
300 m_optionsWidget->cmbPalette->setModelColumn(KisAbstractResourceModel::Name);
301 m_tagFilterProxyModel->sort(Qt::DisplayRole);
302
303
304 KConfigGroup config = KSharedConfig::openConfig()->group(toolId());
305 QString paletteName = config.readEntry("ColorSamplerPalette", "");
306 if (!paletteName.isEmpty()) {
307 for (int i = 0; i < m_tagFilterProxyModel->rowCount(); i++) {
308 QModelIndex idx = m_tagFilterProxyModel->index(i, 0);
309 QString name = m_tagFilterProxyModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Name).toString();
310 if (name == paletteName) {
311 m_optionsWidget->cmbPalette->setCurrentIndex(i);
312 break;
313 }
314 }
315 }
316
317 connect(m_optionsWidget->cmbPalette, SIGNAL(currentIndexChanged(int)), SLOT(slotChangePalette(int)));
318
319 return m_optionsWidget;
320}
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 connect(), m_optionsWidget, m_tagFilterProxyModel, KisAbstractResourceModel::Name, ResourceType::Palettes, KisSpinBoxI18nHelper::setText(), slotChangeBlend(), slotChangePalette(), slotChangeRadius(), slotSetAddPalette(), slotSetColorSource(), slotSetNormaliseValues(), 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 116 of file kis_tool_colorsampler.cc.

117{
118 m_config->save();
119
120 m_isActivated = false;
122}
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 169 of file kis_tool_colorsampler.cc.

170{
175}

◆ displaySampledColor()

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

Definition at line 216 of file kis_tool_colorsampler.cc.

217{
218 if (color.data() && m_optionsWidget) {
219
220 const QList<KoChannelInfo *> channels = color.colorSpace()->channels();
221 m_optionsWidget->listViewChannels->clear();
222
223 QVector<SampledChannel> sampledChannels;
224 for (int i = 0; i < channels.count(); ++i) {
225 sampledChannels.append(SampledChannel());
226 }
227
228 for (int i = 0; i < channels.count(); ++i) {
229
231 pc.name = channels[i]->name();
232
233 if (m_config->normaliseValues) {
234 pc.valueText = color.colorSpace()->normalisedChannelValueText(color.data(), i);
235 } else {
236 pc.valueText = color.colorSpace()->channelValueText(color.data(), i);
237 }
238
239 sampledChannels[channels[i]->displayPosition()] = pc;
240
241 }
242
243 Q_FOREACH (const SampledChannel &pc, sampledChannels) {
244 QTreeWidgetItem *item = new QTreeWidgetItem(m_optionsWidget->listViewChannels);
245 item->setText(0, pc.name);
246 item->setText(1, pc.valueText);
247 }
248
249
250 if (qEnvironmentVariableIsSet("KRITA_DEBUG_DISPLAY_COLOR")) {
251 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
252 KIS_ASSERT(kritaCanvas);
255
256 QVector<float> values(4);
257 newColor.colorSpace()->normalisedChannelsValue(newColor.data(), values);
258
259 for (int i = 0; i < values.size(); i++) {
260 QTreeWidgetItem *item = new QTreeWidgetItem(m_optionsWidget->listViewChannels);
261 item->setText(0, QString("DisplayCh%1").arg(i));
262 item->setText(1, QString::number(values[i]));
263 }
264 }
265 }
266}
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 149 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 137 of file kis_tool_colorsampler.cc.

137 {
139}
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 100 of file kis_tool_colorsampler.cc.

101{
102 m_helper.paint(gc, converter);
103}
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 177 of file kis_tool_colorsampler.cc.

178{
179 Q_UNUSED(event);
180
181 KisConfig cfg(true);
182
183 QRectF colorPreviewDocUpdateRect;
184
185 qreal zoomX;
186 qreal zoomY;
187 canvas()->viewConverter()->zoom(&zoomX, &zoomY);
188 qreal xoffset = 2.0/zoomX;
189 qreal yoffset = 2.0/zoomY;
190
191 m_outlineDocPoint = outlineDocPoint;
192
193 colorPreviewDocUpdateRect = m_helper.colorPreviewDocRect(m_outlineDocPoint);
194
195 if (!colorPreviewDocUpdateRect.isEmpty()) {
196 colorPreviewDocUpdateRect = colorPreviewDocUpdateRect.adjusted(-xoffset,-yoffset,xoffset,yoffset);
197 }
198
199 if (!m_oldColorPreviewUpdateRect.isEmpty()){
201 }
202
203 if (!colorPreviewDocUpdateRect.isEmpty()){
204 canvas()->updateCanvas(colorPreviewDocUpdateRect);
205 }
206
207 m_oldColorPreviewUpdateRect = colorPreviewDocUpdateRect;
208}
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 355 of file kis_tool_colorsampler.cc.

356{
357 m_config->blend = value;
358}
float value(const T *src, size_t ch)

References m_config, and value().

◆ slotChangePalette

void KisToolColorSampler::slotChangePalette ( int )
privateslot

Definition at line 365 of file kis_tool_colorsampler.cc.

366{
367 QString paletteName = m_optionsWidget->cmbPalette->currentData(Qt::UserRole + KisAbstractResourceModel::Name).toString();
368 KConfigGroup config = KSharedConfig::openConfig()->group(toolId());
369 config.writeEntry("ColorSamplerPalette", paletteName);
370}

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

◆ slotChangeRadius

void KisToolColorSampler::slotChangeRadius ( int value)
slot

Definition at line 350 of file kis_tool_colorsampler.cc.

351{
352 m_config->radius = value;
353}

References m_config, and value().

◆ slotColorPickerRequestedCursor

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

Definition at line 51 of file kis_tool_colorsampler.cc.

52{
54}
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 56 of file kis_tool_colorsampler.cc.

57{
60}

◆ slotColorPickerRequestedOutlineUpdate

void KisToolColorSampler::slotColorPickerRequestedOutlineUpdate ( )
privateslot

Definition at line 62 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 67 of file kis_tool_colorsampler.cc.

68{
73 m_sampledColor = color;
75}
void displaySampledColor(const KoColor &color)

References displaySampledColor(), and m_sampledColor.

◆ slotColorPickerSelectionFinished

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

Definition at line 77 of file kis_tool_colorsampler.cc.

78{
79 Q_UNUSED(color);
80
81 if (m_config->addColorToCurrentPalette) {
82 KisSwatch swatch;
83 swatch.setColor(color);
84 // We don't ask for a name, too intrusive here
85
86 QModelIndex idx = m_tagFilterProxyModel->index(m_optionsWidget->cmbPalette->currentIndex(), 0);
87 KoColorSetSP palette = qSharedPointerDynamicCast<KoColorSet>(m_tagFilterProxyModel->resourceForIndex(idx));
88
89 if (palette) {
90 KisSwatchGroup::SwatchInfo info =
91 palette->getClosestSwatchInfo(color);
92
93 if (info.swatch.color() != color) {
94 palette->addSwatch(swatch);
95 }
96 }
97 }
98}
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
rgba palette[MAX_PALETTE]
Definition palette.c:35

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

◆ slotSetAddPalette

void KisToolColorSampler::slotSetAddPalette ( bool state)
slot

Definition at line 345 of file kis_tool_colorsampler.cc.

346{
347 m_config->addColorToCurrentPalette = state;
348}

References m_config.

◆ slotSetColorSource

void KisToolColorSampler::slotSetColorSource ( int value)
slot

Definition at line 360 of file kis_tool_colorsampler.cc.

361{
362 m_config->sampleMerged = value == SAMPLE_MERGED;
363}

References m_config, and value().

◆ slotSetNormaliseValues

void KisToolColorSampler::slotSetNormaliseValues ( bool state)
slot

Definition at line 339 of file kis_tool_colorsampler.cc.

340{
341 m_config->normaliseValues = state;
343}

References displaySampledColor(), m_config, and m_sampledColor.

◆ slotSetUpdateColor

void KisToolColorSampler::slotSetUpdateColor ( bool state)
slot

Definition at line 334 of file kis_tool_colorsampler.cc.

335{
336 m_config->updateColor = state;
337}

References m_config.

◆ updateOptionWidget()

void KisToolColorSampler::updateOptionWidget ( )
private

Definition at line 322 of file kis_tool_colorsampler.cc.

323{
324 if (!m_optionsWidget) return;
325
326 m_optionsWidget->cbNormaliseValues->setChecked(m_config->normaliseValues);
327 m_optionsWidget->cbUpdateCurrentColor->setChecked(m_config->updateColor);
328 m_optionsWidget->cmbSources->setCurrentIndex(SAMPLE_MERGED + !m_config->sampleMerged);
329 m_optionsWidget->cbPalette->setChecked(m_config->addColorToCurrentPalette);
330 m_optionsWidget->radius->setValue(m_config->radius);
331 m_optionsWidget->blend->setValue(m_config->blend);
332}

References m_config, and m_optionsWidget.

Member Data Documentation

◆ m_config

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

Definition at line 101 of file kis_tool_colorsampler.h.

◆ m_helper

KisAsyncColorSamplerHelper KisToolColorSampler::m_helper
private

Definition at line 110 of file kis_tool_colorsampler.h.

◆ m_isActivated

bool KisToolColorSampler::m_isActivated {false}
private

Definition at line 103 of file kis_tool_colorsampler.h.

103{false};

◆ m_oldColorPreviewUpdateRect

QRectF KisToolColorSampler::m_oldColorPreviewUpdateRect
private

Definition at line 106 of file kis_tool_colorsampler.h.

◆ m_optionsWidget

ColorSamplerOptionsWidget* KisToolColorSampler::m_optionsWidget {0}
private

Definition at line 112 of file kis_tool_colorsampler.h.

112{0};

◆ m_outlineDocPoint

QPointF KisToolColorSampler::m_outlineDocPoint
private

Definition at line 104 of file kis_tool_colorsampler.h.

◆ m_sampledColor

KoColor KisToolColorSampler::m_sampledColor
private

Definition at line 108 of file kis_tool_colorsampler.h.

◆ m_tagFilterProxyModel

KisTagFilterResourceProxyModel* KisToolColorSampler::m_tagFilterProxyModel {0}
private

Definition at line 113 of file kis_tool_colorsampler.h.

113{0};

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