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)
 
void slotSetPreviewStyleComboBoxFromConfig ()
 
void slotSetPreviewStyleConfigFromComboBox ()
 

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

38 m_helper(dynamic_cast<KisCanvas2*>(canvas))
39{
40 setObjectName("tool_colorsampler");
41 connect(&m_helper, SIGNAL(sigRequestCursor(QCursor)), this, SLOT(slotColorPickerRequestedCursor(QCursor)));
42 connect(&m_helper, SIGNAL(sigRequestCursorReset()), this, SLOT(slotColorPickerRequestedCursorReset()));
43 connect(&m_helper, SIGNAL(sigRequestUpdateOutline()), this, SLOT(slotColorPickerRequestedOutlineUpdate()));
44 connect(&m_helper, SIGNAL(sigRawColorSelected(KoColor)), this, SLOT(slotColorPickerSelectedColor(KoColor)));
45 connect(&m_helper, SIGNAL(sigFinalColorSelected(KoColor)), this, SLOT(slotColorPickerSelectionFinished(KoColor)));
46}
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 48 of file kis_tool_colorsampler.cc.

49{
50 if (m_isActivated) {
51 m_config->save();
52 }
53}

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

128{
129
130 m_isActivated = true;
131 m_config->load();
132
134
135 KisTool::activate(shapes);
136}
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 180 of file kis_tool_colorsampler.cc.

181{
186 bool useOtherColor = canvas()->resourceManager()->boolResource(KoCanvasResource::UsingOtherColor);
187 // if useOtherColor is true, apply to the other color than that configured in the tool options
188 m_helper.updateCursor(!m_config->sampleMerged, m_config->toForegroundColor != useOtherColor);
189}
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 146 of file kis_tool_colorsampler.cc.

147{
149
150 bool useOtherColor = canvas()->resourceManager()->boolResource(KoCanvasResource::UsingOtherColor);
151 // if useOtherColor is true, apply to the other color than that configured in the tool options
152 m_helper.activate(!m_config->sampleMerged, m_config->toForegroundColor != useOtherColor);
153 m_helper.startAction(event->point, m_config->radius, m_config->blend);
154 requestUpdateOutline(event->point, event);
155
157}
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 163 of file kis_tool_colorsampler.cc.

164{
166
168 requestUpdateOutline(event->point, event);
169}
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 290 of file kis_tool_colorsampler.cc.

291{
293 m_optionsWidget->setObjectName(toolId() + " option widget");
294 m_optionsWidget->listViewChannels->setSortingEnabled(false);
295
296 // See https://bugs.kde.org/show_bug.cgi?id=316896
297 QWidget *specialSpacer = new QWidget(m_optionsWidget);
298 specialSpacer->setObjectName("SpecialSpacer");
299 specialSpacer->setFixedSize(0, 0);
300 m_optionsWidget->layout()->addWidget(specialSpacer);
301
305 this,
307 connect(m_optionsWidget->cmbPreviewStyle,
308 QOverload<int>::of(&QComboBox::activated),
309 this,
311
312 // Initialize blend KisSliderSpinBox
313 m_optionsWidget->blend->setRange(0,100);
315 i18nc("{n} is the number value, % is the percent sign", "{n}%"));
316
318
319 connect(m_optionsWidget->cbUpdateCurrentColor, SIGNAL(toggled(bool)), SLOT(slotSetUpdateColor(bool)));
320 connect(m_optionsWidget->cbNormaliseValues, SIGNAL(toggled(bool)), SLOT(slotSetNormaliseValues(bool)));
321 connect(m_optionsWidget->cbPalette, SIGNAL(toggled(bool)),
322 SLOT(slotSetAddPalette(bool)));
323 connect(m_optionsWidget->radius, SIGNAL(valueChanged(int)),
324 SLOT(slotChangeRadius(int)));
325 connect(m_optionsWidget->blend, SIGNAL(valueChanged(int)),
326 SLOT(slotChangeBlend(int)));
327 connect(m_optionsWidget->cmbSources, SIGNAL(currentIndexChanged(int)),
328 SLOT(slotSetColorSource(int)));
329
331 m_optionsWidget->cmbPalette->setModel(m_tagFilterProxyModel);
332 m_optionsWidget->cmbPalette->setModelColumn(KisAbstractResourceModel::Name);
333 m_tagFilterProxyModel->sort(Qt::DisplayRole);
334
335
336 KConfigGroup config = KSharedConfig::openConfig()->group(toolId());
337 QString paletteName = config.readEntry("ColorSamplerPalette", "");
338 if (!paletteName.isEmpty()) {
339 for (int i = 0; i < m_tagFilterProxyModel->rowCount(); i++) {
340 QModelIndex idx = m_tagFilterProxyModel->index(i, 0);
341 QString name = m_tagFilterProxyModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Name).toString();
342 if (name == paletteName) {
343 m_optionsWidget->cmbPalette->setCurrentIndex(i);
344 break;
345 }
346 }
347 }
348
349 connect(m_optionsWidget->cmbPalette, SIGNAL(currentIndexChanged(int)), SLOT(slotChangePalette(int)));
350
351 return m_optionsWidget;
352}
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 138 of file kis_tool_colorsampler.cc.

139{
140 m_config->save();
141
142 m_isActivated = false;
144}
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 191 of file kis_tool_colorsampler.cc.

192{
197}

◆ displaySampledColor()

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

Definition at line 238 of file kis_tool_colorsampler.cc.

239{
240 if (color.data() && m_optionsWidget) {
241
242 const QList<KoChannelInfo *> channels = color.colorSpace()->channels();
243 m_optionsWidget->listViewChannels->clear();
244
245 QVector<SampledChannel> sampledChannels;
246 for (int i = 0; i < channels.count(); ++i) {
247 sampledChannels.append(SampledChannel());
248 }
249
250 for (int i = 0; i < channels.count(); ++i) {
251
253 pc.name = channels[i]->name();
254
255 if (m_config->normaliseValues) {
256 pc.valueText = color.colorSpace()->normalisedChannelValueText(color.data(), i);
257 } else {
258 pc.valueText = color.colorSpace()->channelValueText(color.data(), i);
259 }
260
261 sampledChannels[channels[i]->displayPosition()] = pc;
262
263 }
264
265 Q_FOREACH (const SampledChannel &pc, sampledChannels) {
266 QTreeWidgetItem *item = new QTreeWidgetItem(m_optionsWidget->listViewChannels);
267 item->setText(0, pc.name);
268 item->setText(1, pc.valueText);
269 }
270
271
272 if (qEnvironmentVariableIsSet("KRITA_DEBUG_DISPLAY_COLOR")) {
273 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
274 KIS_ASSERT(kritaCanvas);
277
278 QVector<float> values(4);
279 newColor.colorSpace()->normalisedChannelsValue(newColor.data(), values);
280
281 for (int i = 0; i < values.size(); i++) {
282 QTreeWidgetItem *item = new QTreeWidgetItem(m_optionsWidget->listViewChannels);
283 item->setText(0, QString("DisplayCh%1").arg(i));
284 item->setText(1, QString::number(values[i]));
285 }
286 }
287 }
288}
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 171 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 159 of file kis_tool_colorsampler.cc.

159 {
161}
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 122 of file kis_tool_colorsampler.cc.

123{
124 m_helper.paint(gc, converter);
125}
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 199 of file kis_tool_colorsampler.cc.

200{
201 Q_UNUSED(event);
202
203 KisConfig cfg(true);
204
205 QRectF colorPreviewDocUpdateRect;
206
207 qreal zoomX;
208 qreal zoomY;
209 canvas()->viewConverter()->zoom(&zoomX, &zoomY);
210 qreal xoffset = 2.0/zoomX;
211 qreal yoffset = 2.0/zoomY;
212
213 m_outlineDocPoint = outlineDocPoint;
214
215 colorPreviewDocUpdateRect = m_helper.colorPreviewDocRect(m_outlineDocPoint);
216
217 if (!colorPreviewDocUpdateRect.isEmpty()) {
218 colorPreviewDocUpdateRect = colorPreviewDocUpdateRect.adjusted(-xoffset,-yoffset,xoffset,yoffset);
219 }
220
221 if (!m_oldColorPreviewUpdateRect.isEmpty()){
223 }
224
225 if (!colorPreviewDocUpdateRect.isEmpty()){
226 canvas()->updateCanvas(colorPreviewDocUpdateRect);
227 }
228
229 m_oldColorPreviewUpdateRect = colorPreviewDocUpdateRect;
230}
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 389 of file kis_tool_colorsampler.cc.

390{
391 m_config->blend = value;
392}
float value(const T *src, size_t ch)

References m_config, and value().

◆ slotChangePalette

void KisToolColorSampler::slotChangePalette ( int )
privateslot

Definition at line 399 of file kis_tool_colorsampler.cc.

400{
401 QString paletteName = m_optionsWidget->cmbPalette->currentData(Qt::UserRole + KisAbstractResourceModel::Name).toString();
402 KConfigGroup config = KSharedConfig::openConfig()->group(toolId());
403 config.writeEntry("ColorSamplerPalette", paletteName);
404}

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

◆ slotChangeRadius

void KisToolColorSampler::slotChangeRadius ( int value)
slot

Definition at line 384 of file kis_tool_colorsampler.cc.

385{
386 m_config->radius = value;
387}

References m_config, and value().

◆ slotColorPickerRequestedCursor

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

Definition at line 55 of file kis_tool_colorsampler.cc.

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

61{
64}

◆ slotColorPickerRequestedOutlineUpdate

void KisToolColorSampler::slotColorPickerRequestedOutlineUpdate ( )
privateslot

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

72{
77 m_sampledColor = color;
79}
void displaySampledColor(const KoColor &color)

References displaySampledColor(), and m_sampledColor.

◆ slotColorPickerSelectionFinished

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

Definition at line 81 of file kis_tool_colorsampler.cc.

82{
83 Q_UNUSED(color);
84
85 if (m_config->addColorToCurrentPalette) {
86 KisSwatch swatch;
87 swatch.setColor(color);
88 // We don't ask for a name, too intrusive here
89
90 QModelIndex idx = m_tagFilterProxyModel->index(m_optionsWidget->cmbPalette->currentIndex(), 0);
91 KoColorSetSP palette = qSharedPointerDynamicCast<KoColorSet>(m_tagFilterProxyModel->resourceForIndex(idx));
92
93 if (palette) {
94 KisSwatchGroup::SwatchInfo info =
95 palette->getClosestSwatchInfo(color);
96
97 if (info.swatch.color() != color) {
98 palette->addSwatch(swatch);
99 }
100 }
101 }
102}
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 379 of file kis_tool_colorsampler.cc.

380{
381 m_config->addColorToCurrentPalette = state;
382}

References m_config.

◆ slotSetColorSource

void KisToolColorSampler::slotSetColorSource ( int value)
slot

Definition at line 394 of file kis_tool_colorsampler.cc.

395{
396 m_config->sampleMerged = value == SAMPLE_MERGED;
397}

References m_config, and value().

◆ slotSetNormaliseValues

void KisToolColorSampler::slotSetNormaliseValues ( bool state)
slot

Definition at line 373 of file kis_tool_colorsampler.cc.

374{
375 m_config->normaliseValues = state;
377}

References displaySampledColor(), m_config, and m_sampledColor.

◆ slotSetPreviewStyleComboBoxFromConfig

void KisToolColorSampler::slotSetPreviewStyleComboBoxFromConfig ( )
privateslot

Definition at line 104 of file kis_tool_colorsampler.cc.

105{
106 if (m_optionsWidget) {
107 QSignalBlocker blocker(m_optionsWidget->cmbPreviewStyle);
109 KisConfig(true).colorSamplerPreviewStyle());
110 }
111}
static void setColorSamplerPreviewStyleIndexByValue(QComboBox *cmb, KisConfig::ColorSamplerPreviewStyle style)

References m_optionsWidget, and GeneralTab::setColorSamplerPreviewStyleIndexByValue().

◆ slotSetPreviewStyleConfigFromComboBox

void KisToolColorSampler::slotSetPreviewStyleConfigFromComboBox ( )
privateslot

Definition at line 113 of file kis_tool_colorsampler.cc.

114{
115 if (m_optionsWidget) {
119 }
120}
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 368 of file kis_tool_colorsampler.cc.

369{
370 m_config->updateColor = state;
371}

References m_config.

◆ updateOptionWidget()

void KisToolColorSampler::updateOptionWidget ( )
private

Definition at line 354 of file kis_tool_colorsampler.cc.

355{
356 if (!m_optionsWidget) return;
357
358 m_optionsWidget->cbNormaliseValues->setChecked(m_config->normaliseValues);
359 m_optionsWidget->cbUpdateCurrentColor->setChecked(m_config->updateColor);
360 m_optionsWidget->cmbSources->setCurrentIndex(SAMPLE_MERGED + !m_config->sampleMerged);
361 m_optionsWidget->cbPalette->setChecked(m_config->addColorToCurrentPalette);
362 m_optionsWidget->radius->setValue(m_config->radius);
363 m_optionsWidget->blend->setValue(m_config->blend);
364
366}

References m_config, m_optionsWidget, and slotSetPreviewStyleComboBoxFromConfig().

Member Data Documentation

◆ m_config

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

Definition at line 104 of file kis_tool_colorsampler.h.

◆ m_helper

KisAsyncColorSamplerHelper KisToolColorSampler::m_helper
private

Definition at line 113 of file kis_tool_colorsampler.h.

◆ m_isActivated

bool KisToolColorSampler::m_isActivated {false}
private

Definition at line 106 of file kis_tool_colorsampler.h.

106{false};

◆ m_oldColorPreviewUpdateRect

QRectF KisToolColorSampler::m_oldColorPreviewUpdateRect
private

Definition at line 109 of file kis_tool_colorsampler.h.

◆ m_optionsWidget

ColorSamplerOptionsWidget* KisToolColorSampler::m_optionsWidget {0}
private

Definition at line 115 of file kis_tool_colorsampler.h.

115{0};

◆ m_outlineDocPoint

QPointF KisToolColorSampler::m_outlineDocPoint
private

Definition at line 107 of file kis_tool_colorsampler.h.

◆ m_sampledColor

KoColor KisToolColorSampler::m_sampledColor
private

Definition at line 111 of file kis_tool_colorsampler.h.

◆ m_tagFilterProxyModel

KisTagFilterResourceProxyModel* KisToolColorSampler::m_tagFilterProxyModel {0}
private

Definition at line 116 of file kis_tool_colorsampler.h.

116{0};

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