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

#include <kis_tool_select_similar.h>

+ Inheritance diagram for KisToolSelectSimilar:

Public Slots

void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
void slotSetOpacitySpread (int)
 
void slotSetThreshold (int)
 

Public Member Functions

void beginPrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
void endPrimaryAction (KoPointerEvent *event) override
 
 KisToolSelectSimilar (KoCanvasBase *canvas)
 
void paint (QPainter &, const KoViewConverter &) override
 
void resetCursorStyle () override
 
- Public Member Functions inherited from KisToolSelectBase< BaseClass >
void activate (const QSet< KoShape * > &shapes) override
 
void activateAlternateAction (KisTool::AlternateAction action) override
 
SelectionAction alternateSelectionAction () const
 
bool antiAliasSelection () const
 
void beginAlternateAction (KoPointerEvent *event, KisTool::AlternateAction action) override
 
bool beginMoveSelectionInteraction ()
 
void beginPrimaryAction (KoPointerEvent *event) override
 
bool beginSelectInteraction ()
 
QList< int > colorLabelsSelected () const
 
void continueAlternateAction (KoPointerEvent *event, KisTool::AlternateAction action) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
void deactivate () override
 
void deactivateAlternateAction (KisTool::AlternateAction action) override
 
void endAlternateAction (KoPointerEvent *event, KisTool::AlternateAction action) override
 
bool endMoveSelectionInteraction ()
 
void endPrimaryAction (KoPointerEvent *event) override
 
bool endSelectInteraction ()
 
int featherSelection () const
 
int growSelection () const
 
bool isMovingSelection () const
 
bool isSelecting () const
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
 KisToolSelectBase (KoCanvasBase *canvas, const QCursor cursor, const QString toolName)
 
 KisToolSelectBase (KoCanvasBase *canvas, const QString toolName)
 
 KisToolSelectBase (KoCanvasBase *canvas, QCursor cursor, QString toolName, KoToolBase *delegateTool)
 
KisNodeSP locateSelectionMaskUnderCursor (const QPointF &pos, Qt::KeyboardModifiers modifiers)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
QMenu * popupActionsMenu () override
 
KisPopupWidgetInterfacepopupWidget () override
 
SampleLayersMode sampleLayersMode () const
 
SelectionAction selectionAction () const
 
bool selectionDidMove () const
 
SelectionMode selectionMode () const
 
KisSelectionOptionsselectionOptionWidget ()
 
virtual void setAlternateSelectionAction (SelectionAction action)
 
bool stopGrowingAtDarkestPixel () const
 
void updateActionShortcutToolTips ()
 
void updateCursorDelayed ()
 

Protected Member Functions

bool isPixelOnly () const override
 
bool usesColorLabels () const override
 

Protected Attributes

KisSelectionToolConfigWidgetHelper m_widgetHelper
 
- Protected Attributes inherited from KisToolSelectBase< BaseClass >
SelectionAction m_selectionActionAlternate
 
KisSelectionToolConfigWidgetHelper m_widgetHelper
 

Private Attributes

KConfigGroup m_configGroup
 
int m_opacitySpread
 
int m_previousTime
 
KisMergeLabeledLayersCommand::ReferenceNodeInfoListSP m_referenceNodeList
 
KisPaintDeviceSP m_referencePaintDevice
 
int m_threshold
 

Additional Inherited Members

- Public Types inherited from KisToolSelectBase< BaseClass >
enum  SampleLayersMode { SampleAllLayers , SampleCurrentLayer , SampleColorLabeledLayers }
 

Detailed Description

Definition at line 20 of file kis_tool_select_similar.h.

Constructor & Destructor Documentation

◆ KisToolSelectSimilar()

KisToolSelectSimilar::KisToolSelectSimilar ( KoCanvasBase * canvas)

Definition at line 39 of file kis_tool_select_similar.cc.

40 : KisToolSelect(canvas,
41 KisCursor::load("tool_similar_selection_cursor.png", 6, 6),
42 i18n("Similar Color Selection"))
43 , m_threshold(20)
44 , m_opacitySpread(100)
46{
47}
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
KisToolSelectBase< FakeBaseTool > KisToolSelect

Member Function Documentation

◆ activate

void KisToolSelectSimilar::activate ( const QSet< KoShape * > & shapes)
overrideslot

Definition at line 49 of file kis_tool_select_similar.cc.

50{
52 m_configGroup = KSharedConfig::openConfig()->group(toolId());
53}
void activate(const QSet< KoShape * > &shapes) override

References KisToolSelectBase< BaseClass >::activate(), and m_configGroup.

◆ beginPrimaryAction()

void KisToolSelectSimilar::beginPrimaryAction ( KoPointerEvent * event)
override

Definition at line 62 of file kis_tool_select_similar.cc.

63{
65 if (isMovingSelection()) {
66 return;
67 }
68
70
71 if (!currentNode() ||
72 !(currentNode()->projection()) ||
73 !selectionEditable()) {
74
75 event->ignore();
76 return;
77 }
78
79 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
81
83
84 KisCursorOverrideLock cursorLock(KisCursor::waitCursor());
85
86 // Create the stroke
88 new KisStrokeStrategyUndoCommandBased(kundo2_i18n("Select Similar Color"), false, image().data());
89 strategy->setSupportsWrapAroundMode(false);
90 KisStrokeId strokeId = image()->startStroke(strategy);
91
92 // Construct the reference device
94 m_referencePaintDevice = currentNode()->projection();
95 } else if (sampleLayersMode() == SampleAllLayers) {
96 m_referencePaintDevice = currentImage()->projection();
99 m_referencePaintDevice = KisMergeLabeledLayersCommand::createRefPaintDevice(image(), "Similar Colors Selection Tool Reference Result Paint Device");
101 }
102 KisPaintDeviceSP newReferencePaintDevice = KisMergeLabeledLayersCommand::createRefPaintDevice(image(), "Similar Colors Selection Tool Reference Result Paint Device");
104 const int currentTime = image()->animationInterface()->currentTime();
105
106 image()->addJob(
107 strokeId,
110 image(),
112 newReferenceNodeList,
114 newReferencePaintDevice,
117 m_previousTime != currentTime
118 )),
119 false,
122 )
123 );
124
125 m_referencePaintDevice = newReferencePaintDevice;
126 m_referenceNodeList = newReferenceNodeList;
127 m_previousTime = currentTime;
128 }
129
130 // Get the color of the pixel where the user clicked
132 const QPoint pos = convertToImagePixelCoordFloored(event);
133 QSharedPointer<KoColor> referenceColor = QSharedPointer<KoColor>(new KoColor(sourceDevice->colorSpace()));
134 // We need to obtain the reference color from the reference paint
135 // device, but it is produced in a stroke, so we must get the color
136 // after the device is ready. So we get it in the stroke
137 image()->addJob(
138 strokeId,
141 [sourceDevice, referenceColor, pos]() -> KUndo2Command*
142 {
143 *referenceColor = sourceDevice->pixel(pos);
144 return 0;
145 }
146 )),
147 false,
150 )
151 );
152
153 // Get the similar colors selection
154 KisFillPainter painter;
155 QRect bounds = currentImage()->bounds();
157 progressHelper(new KisProcessingVisitor::ProgressHelper(currentNode()));
158 KisPixelSelectionSP tmpSel = new KisPixelSelection(new KisSelectionDefaultBounds(currentNode()->projection()));
159
163 painter.setSizemod(growSelection());
165 painter.setFeather(featherSelection());
166
169 tmpSel, referenceColor, sourceDevice,
170 bounds, nullptr, progressHelper
171 );
172
173 for (KisStrokeJobData *job : jobs) {
174 image()->addJob(strokeId, job);
175 }
176
177 image()->addJob(
178 strokeId,
181 [tmpSel]() mutable -> KUndo2Command*
182 {
183 tmpSel->invalidateOutlineCache();
184 return 0;
185 }
186 )),
187 false,
190 )
191 );
192
193 image()->endStroke(strokeId);
194
195 // Apply selection
196 KisSelectionToolHelper helper(kisCanvas, kundo2_i18n("Select Similar Color"));
197 helper.selectPixelSelection(tmpSel, selectionAction());
198}
static QCursor waitCursor()
Definition kis_cursor.cc:54
void setSizemod(int sizemod)
void setFillThreshold(int threshold)
void setFeather(int feather)
QVector< KisStrokeJobData * > createSimilarColorsSelectionJobs(KisPixelSelectionSP outSelection, const QSharedPointer< KoColor > referenceColor, KisPaintDeviceSP referenceDevice, const QRect &rect, KisPixelSelectionSP mask, QSharedPointer< KisProcessingVisitor::ProgressHelper > progressHelper=nullptr)
void setAntiAlias(bool antiAlias)
void setStopGrowingAtDarkestPixel(bool stopGrowingAtDarkestPixel)
void setOpacitySpread(int opacitySpread)
static KisPaintDeviceSP createRefPaintDevice(KisImageSP originalImage, QString name="Merge Labeled Layers Reference Paint Device")
@ GroupSelectionPolicy_SelectIfColorLabeled
Groups will be taken into account only if they have set an explicit color label. This ignores groups ...
const KoColorSpace * colorSpace() const
bool pixel(qint32 x, qint32 y, QColor *c) const
SampleLayersMode sampleLayersMode() const
SelectionAction selectionAction() const
void beginPrimaryAction(KoPointerEvent *event) override
QList< int > colorLabelsSelected() const
bool stopGrowingAtDarkestPixel() const
bool antiAliasSelection() const
KisMergeLabeledLayersCommand::ReferenceNodeInfoListSP m_referenceNodeList
KisPaintDeviceSP m_referencePaintDevice
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define bounds(x, a, b)
QSharedPointer< KUndo2Command > KUndo2CommandSP
Definition kis_types.h:262
KUndo2MagicString kundo2_i18n(const char *text)
The LambdaCommand struct is a shorthand for creation of AggregateCommand commands using C++ lambda fe...

References KisToolSelectBase< BaseClass >::antiAliasSelection(), KisToolSelectBase< BaseClass >::beginPrimaryAction(), KisToolSelectBase< BaseClass >::beginSelectInteraction(), bounds, KisToolSelectBase< BaseClass >::colorLabelsSelected(), KisPaintDevice::colorSpace(), KisMergeLabeledLayersCommand::createRefPaintDevice(), KisFillPainter::createSimilarColorsSelectionJobs(), KisStrokeJobData::EXCLUSIVE, KisToolSelectBase< BaseClass >::featherSelection(), KisMergeLabeledLayersCommand::GroupSelectionPolicy_SelectIfColorLabeled, KisToolSelectBase< BaseClass >::growSelection(), KisPixelSelection::invalidateOutlineCache(), KisToolSelectBase< BaseClass >::isMovingSelection(), KIS_SAFE_ASSERT_RECOVER_RETURN, kundo2_i18n(), m_opacitySpread, m_previousTime, m_referenceNodeList, m_referencePaintDevice, m_threshold, KisPaintDevice::pixel(), KisToolSelectBase< BaseClass >::SampleAllLayers, KisToolSelectBase< BaseClass >::SampleColorLabeledLayers, KisToolSelectBase< BaseClass >::SampleCurrentLayer, KisToolSelectBase< BaseClass >::sampleLayersMode(), KisToolSelectBase< BaseClass >::selectionAction(), KisSelectionToolHelper::selectPixelSelection(), KisStrokeJobData::SEQUENTIAL, KisFillPainter::setAntiAlias(), KisFillPainter::setFeather(), KisFillPainter::setFillThreshold(), KisFillPainter::setOpacitySpread(), KisFillPainter::setSizemod(), KisFillPainter::setStopGrowingAtDarkestPixel(), KisStrokeStrategyUndoCommandBased::setSupportsWrapAroundMode(), KisToolSelectBase< BaseClass >::stopGrowingAtDarkestPixel(), and KisCursor::waitCursor().

◆ createOptionWidget()

QWidget * KisToolSelectSimilar::createOptionWidget ( )
override

Definition at line 222 of file kis_tool_select_similar.cc.

223{
225 KisSelectionOptions *selectionWidget = selectionOptionWidget();
226
227 selectionWidget->setStopGrowingAtDarkestPixelButtonVisible(true);
228
229 // Create widgets
230 KisSliderSpinBox *sliderThreshold = new KisSliderSpinBox;
231 sliderThreshold->setPrefix(i18nc(
232 "The 'threshold' spinbox prefix in similar selection tool options",
233 "Threshold: "));
234 sliderThreshold->setRange(1, 100);
235 sliderThreshold->setSingleStep(1);
236 sliderThreshold->setToolTip(
237 i18n("Set the color similarity tolerance of the selection. "
238 "Increasing threshold increases the range of similar colors to be selected."));
239
240 KisSliderSpinBox *sliderSpread = new KisSliderSpinBox;
241 sliderSpread->setRange(0, 100);
243 i18nc("The 'spread' spinbox in similar color selection tool options; {n} is the "
244 "number value, % is the percent sign",
245 "Spread: {n}%"));
246
247 // Set the tooltips
248 sliderThreshold->setToolTip(
249 i18n("Set the color similarity tolerance of the selection. "
250 "Increasing threshold increases the range of similar colors to be selected."));
251 sliderSpread->setToolTip(
252 i18n("Set the extent of the opaque portion of the selection. "
253 "Decreasing spread decreases opacity of selection areas depending on color similarity."));
254
255 // Construct the option widget
256 KisOptionCollectionWidgetWithHeader *sectionSelectionExtent =
258 i18nc("The 'selection extent' section label in similar selection "
259 "tool options",
260 "Selection extent"));
261 sectionSelectionExtent->appendWidget("sliderThreshold", sliderThreshold);
262 sectionSelectionExtent->appendWidget("sliderSpread", sliderSpread);
263 selectionWidget->insertWidget(3, "sectionSelectionExtent", sectionSelectionExtent);
264
265 // load setting from config
266 if (m_configGroup.hasKey("threshold")) {
267 m_threshold = m_configGroup.readEntry("threshold", 20);
268 } else {
269 m_threshold = m_configGroup.readEntry("fuzziness", 20);
270 }
271 sliderThreshold->setValue(m_threshold);
272
273 m_opacitySpread = m_configGroup.readEntry("opacitySpread", 100);
274 sliderSpread->setValue(m_opacitySpread);
275
276 // Make connections
277 connect(sliderThreshold,
278 SIGNAL(valueChanged(int)),
279 this,
280 SLOT(slotSetThreshold(int)));
281 connect(sliderSpread,
282 SIGNAL(valueChanged(int)),
283 this,
284 SLOT(slotSetOpacitySpread(int)));
285
286 return selectionWidget;
287}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an...
void appendWidget(const QString &id, QWidget *widget)
Insert the given widget with the given id at the end of the list. The list widget takes ownership of ...
void insertWidget(int index, const QString &id, QWidget *widget)
Insert the given widget with the given id at the given position. The list widget takes ownership of t...
void setStopGrowingAtDarkestPixelButtonVisible(bool visible)
This class is a spinbox in which you can click and drag to set the value. A slider like bar is displa...
void setValue(int newValue)
void setRange(int newMinimum, int newMaximum, bool computeNewFastSliderStep=true)
Set the minimum and the maximum values of the range, computing a new "fast slider step" based on the ...
KisSelectionOptions * selectionOptionWidget()
QWidget * createOptionWidget() override
void setText(QSpinBox *spinBox, const QStringView textTemplate)

References KisOptionCollectionWidgetWithHeader::appendWidget(), connect(), KisToolSelectBase< BaseClass >::createOptionWidget(), KisOptionCollectionWidget::insertWidget(), m_configGroup, m_opacitySpread, m_threshold, KisToolSelectBase< BaseClass >::selectionOptionWidget(), KisSliderSpinBox::setRange(), KisSelectionOptions::setStopGrowingAtDarkestPixelButtonVisible(), KisSpinBoxI18nHelper::setText(), KisSliderSpinBox::setValue(), slotSetOpacitySpread(), and slotSetThreshold().

◆ deactivate

void KisToolSelectSimilar::deactivate ( )
overrideslot

◆ endPrimaryAction()

void KisToolSelectSimilar::endPrimaryAction ( KoPointerEvent * event)
override

◆ isPixelOnly()

bool KisToolSelectSimilar::isPixelOnly ( ) const
inlineoverrideprotectedvirtual

Reimplemented from KisToolSelectBase< BaseClass >.

Definition at line 40 of file kis_tool_select_similar.h.

40{ return true; }

◆ paint()

void KisToolSelectSimilar::paint ( QPainter & ,
const KoViewConverter &  )
inlineoverride

Definition at line 28 of file kis_tool_select_similar.h.

28{}

◆ resetCursorStyle()

void KisToolSelectSimilar::resetCursorStyle ( )
override

Definition at line 289 of file kis_tool_select_similar.cc.

290{
292 useCursor(KisCursor::load("tool_similar_selection_cursor_add.png", 6, 6));
293 } else if (selectionAction() == SELECTION_SUBTRACT) {
294 useCursor(KisCursor::load("tool_similar_selection_cursor_sub.png", 6, 6));
295 } else if (selectionAction() == SELECTION_INTERSECT) {
296 useCursor(KisCursor::load("tool_similar_selection_cursor_inter.png", 6, 6));
298 useCursor(KisCursor::load("tool_similar_selection_cursor_symdiff.png", 6, 6));
299 } else {
300 KisToolSelect::resetCursorStyle();
301 }
302}
@ SELECTION_INTERSECT
@ SELECTION_SYMMETRICDIFFERENCE
@ SELECTION_SUBTRACT
@ SELECTION_ADD

References KisCursor::load(), SELECTION_ADD, SELECTION_INTERSECT, SELECTION_SUBTRACT, SELECTION_SYMMETRICDIFFERENCE, and KisToolSelectBase< BaseClass >::selectionAction().

◆ slotSetOpacitySpread

void KisToolSelectSimilar::slotSetOpacitySpread ( int opacitySpread)
slot

Definition at line 216 of file kis_tool_select_similar.cc.

217{
218 m_opacitySpread = opacitySpread;
219 m_configGroup.writeEntry("opacitySpread", opacitySpread);
220}

References m_configGroup, and m_opacitySpread.

◆ slotSetThreshold

void KisToolSelectSimilar::slotSetThreshold ( int threshold)
slot

Definition at line 210 of file kis_tool_select_similar.cc.

211{
212 m_threshold = threshold;
213 m_configGroup.writeEntry("threshold", threshold);
214}

References m_configGroup, and m_threshold.

◆ usesColorLabels()

bool KisToolSelectSimilar::usesColorLabels ( ) const
inlineoverrideprotectedvirtual

Reimplemented from KisToolSelectBase< BaseClass >.

Definition at line 41 of file kis_tool_select_similar.h.

41{ return true; }

Member Data Documentation

◆ m_configGroup

KConfigGroup KisToolSelectSimilar::m_configGroup
private

Definition at line 46 of file kis_tool_select_similar.h.

◆ m_opacitySpread

int KisToolSelectSimilar::m_opacitySpread
private

Definition at line 45 of file kis_tool_select_similar.h.

◆ m_previousTime

int KisToolSelectSimilar::m_previousTime
private

Definition at line 49 of file kis_tool_select_similar.h.

◆ m_referenceNodeList

KisMergeLabeledLayersCommand::ReferenceNodeInfoListSP KisToolSelectSimilar::m_referenceNodeList
private

Definition at line 48 of file kis_tool_select_similar.h.

◆ m_referencePaintDevice

KisPaintDeviceSP KisToolSelectSimilar::m_referencePaintDevice
private

Definition at line 47 of file kis_tool_select_similar.h.

◆ m_threshold

int KisToolSelectSimilar::m_threshold
private

Definition at line 44 of file kis_tool_select_similar.h.

◆ m_widgetHelper

KisSelectionToolConfigWidgetHelper KisToolSelectBase< BaseClass >::m_widgetHelper
protected

Definition at line 535 of file kis_tool_select_base.h.


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