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 beginMoveContentInteraction ()
 
bool beginMoveSelectionInteraction ()
 
void beginPrimaryAction (KoPointerEvent *event) override
 
bool beginSelectInteraction ()
 
bool canBeginNewAction (KoPointerEvent *event, const QPointF &pos, CursorHit hit)
 
void cancelMoveSelectionStroke ()
 
CursorHit checkCursorHit (const QPointF &pos, Qt::KeyboardModifiers modifiers) const
 
QList< int > colorLabelsSelected () const
 
void commitMoveSelectionStroke ()
 
void commitMoveSelectionStrokeImpl (bool cancel)
 
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
 
bool disabledMoveContentWhileMovingContent () const
 
void endAlternateAction (KoPointerEvent *event, KisTool::AlternateAction action) override
 
bool endMoveContentInteraction ()
 
bool endMoveSelectionInteraction ()
 
void endPrimaryAction (KoPointerEvent *event) override
 
bool endSelectInteraction ()
 
void explicitUserStrokeEndRequest () override
 
int featherSelection () const
 
int growSelection () const
 
void initializeStrokeAttributes (const QPointF &pos, KisStrokeStrategy *strategy, bool moved)
 
bool isMovingContent () 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
 
bool moveSelectedContent () const
 
QMenu * popupActionsMenu () override
 
KisPopupWidgetInterface * popupWidget () override
 
void requestStrokeCancellation () override
 
void requestStrokeEnd () override
 
SampleLayersMode sampleLayersMode () const
 
SelectionAction selectionAction () const
 
bool selectionDidMove () const
 
SelectionMode selectionMode () const
 
KisSelectionOptions * selectionOptionWidget ()
 
virtual void setAlternateSelectionAction (SelectionAction action)
 
bool stopGrowingAtDarkestPixel () const
 
void updateActionShortcutToolTips ()
 
void updateCursor ()
 
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  CursorHit { CursorHit_None , CursorHit_Border , CursorHit_Inside , CursorHit_Outside }
 
enum  SampleLayersMode { SampleAllLayers , SampleCurrentGroup , 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::loadWithSize("tool_similar_selection_cursor.svg", 32, 32, 6, 6),
42 i18n("Similar Color Selection"))
43 , m_threshold(20)
44 , m_opacitySpread(100)
46{
47}
static QCursor loadWithSize(const QString &cursorName, int width, int height, 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() == SampleCurrentGroup) {
96 m_referencePaintDevice = currentNode()->parent()->projection();
97 } else if (sampleLayersMode() == SampleAllLayers) {
98 m_referencePaintDevice = currentImage()->projection();
100 if (!m_referenceNodeList) {
101 m_referencePaintDevice = KisMergeLabeledLayersCommand::createRefPaintDevice(image(), "Similar Colors Selection Tool Reference Result Paint Device");
103 }
104 KisPaintDeviceSP newReferencePaintDevice = KisMergeLabeledLayersCommand::createRefPaintDevice(image(), "Similar Colors Selection Tool Reference Result Paint Device");
106 const int currentTime = image()->animationInterface()->currentTime();
107
108 image()->addJob(
109 strokeId,
112 image(),
114 newReferenceNodeList,
116 newReferencePaintDevice,
119 m_previousTime != currentTime
120 )),
121 false,
124 )
125 );
126
127 m_referencePaintDevice = newReferencePaintDevice;
128 m_referenceNodeList = newReferenceNodeList;
129 m_previousTime = currentTime;
130 }
131
132 // Get the color of the pixel where the user clicked
134 const QPoint pos = convertToImagePixelCoordFloored(event);
135 QSharedPointer<KoColor> referenceColor = QSharedPointer<KoColor>(new KoColor(sourceDevice->colorSpace()));
136 // We need to obtain the reference color from the reference paint
137 // device, but it is produced in a stroke, so we must get the color
138 // after the device is ready. So we get it in the stroke
139 image()->addJob(
140 strokeId,
143 [sourceDevice, referenceColor, pos]() -> KUndo2Command*
144 {
145 *referenceColor = sourceDevice->pixel(pos);
146 return 0;
147 }
148 )),
149 false,
152 )
153 );
154
155 // Get the similar colors selection
156 KisFillPainter painter;
157 QRect bounds = currentImage()->bounds();
159 progressHelper(new KisProcessingVisitor::ProgressHelper(currentNode()));
160 KisPixelSelectionSP tmpSel = new KisPixelSelection(new KisSelectionDefaultBounds(currentNode()->projection()));
161
165 painter.setSizemod(growSelection());
167 painter.setFeather(featherSelection());
168
171 tmpSel, referenceColor, sourceDevice,
172 bounds, nullptr, progressHelper
173 );
174
175 for (KisStrokeJobData *job : jobs) {
176 image()->addJob(strokeId, job);
177 }
178
179 image()->addJob(
180 strokeId,
183 [tmpSel]() mutable -> KUndo2Command*
184 {
185 tmpSel->invalidateOutlineCache();
186 return 0;
187 }
188 )),
189 false,
192 )
193 );
194
195 image()->endStroke(strokeId);
196
197 // Apply selection
198 KisSelectionToolHelper helper(kisCanvas, kundo2_i18n("Select Similar Color"));
199 helper.selectPixelSelection(tmpSel, selectionAction());
200}
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 >::SampleCurrentGroup, 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 224 of file kis_tool_select_similar.cc.

225{
227 KisSelectionOptions *selectionWidget = selectionOptionWidget();
228
229 selectionWidget->setStopGrowingAtDarkestPixelButtonVisible(true);
230
231 // Create widgets
232 KisSliderSpinBox *sliderThreshold = new KisSliderSpinBox;
233 sliderThreshold->setPrefix(i18nc(
234 "The 'threshold' spinbox prefix in similar selection tool options",
235 "Threshold: "));
236 sliderThreshold->setRange(1, 100);
237 sliderThreshold->setSingleStep(1);
238 sliderThreshold->setToolTip(
239 i18n("Set the color similarity tolerance of the selection. "
240 "Increasing threshold increases the range of similar colors to be selected."));
241
242 KisSliderSpinBox *sliderSpread = new KisSliderSpinBox;
243 sliderSpread->setRange(0, 100);
245 i18nc("The 'spread' spinbox in similar color selection tool options; {n} is the "
246 "number value, % is the percent sign",
247 "Spread: {n}%"));
248
249 // Set the tooltips
250 sliderThreshold->setToolTip(
251 i18n("Set the color similarity tolerance of the selection. "
252 "Increasing threshold increases the range of similar colors to be selected."));
253 sliderSpread->setToolTip(
254 i18n("Set the extent of the opaque portion of the selection. "
255 "Decreasing spread decreases opacity of selection areas depending on color similarity."));
256
257 // Construct the option widget
258 KisOptionCollectionWidgetWithHeader *sectionSelectionExtent =
260 i18nc("The 'selection extent' section label in similar selection "
261 "tool options",
262 "Selection extent"));
263 sectionSelectionExtent->appendWidget("sliderThreshold", sliderThreshold);
264 sectionSelectionExtent->appendWidget("sliderSpread", sliderSpread);
265 selectionWidget->insertWidget(3, "sectionSelectionExtent", sectionSelectionExtent);
266
267 // load setting from config
268 if (m_configGroup.hasKey("threshold")) {
269 m_threshold = m_configGroup.readEntry("threshold", 20);
270 } else {
271 m_threshold = m_configGroup.readEntry("fuzziness", 20);
272 }
273 sliderThreshold->setValue(m_threshold);
274
275 m_opacitySpread = m_configGroup.readEntry("opacitySpread", 100);
276 sliderSpread->setValue(m_opacitySpread);
277
278 // Make connections
279 connect(sliderThreshold,
280 SIGNAL(valueChanged(int)),
281 this,
282 SLOT(slotSetThreshold(int)));
283 connect(sliderSpread,
284 SIGNAL(valueChanged(int)),
285 this,
286 SLOT(slotSetOpacitySpread(int)));
287
288 return selectionWidget;
289}
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(), 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 291 of file kis_tool_select_similar.cc.

292{
294 useCursor(KisCursor::loadWithSize("tool_similar_selection_cursor_add.svg", 32, 32, 6, 6));
295 } else if (selectionAction() == SELECTION_SUBTRACT) {
296 useCursor(KisCursor::loadWithSize("tool_similar_selection_cursor_sub.svg", 32, 32, 6, 6));
297 } else if (selectionAction() == SELECTION_INTERSECT) {
298 useCursor(KisCursor::loadWithSize("tool_similar_selection_cursor_inter.svg", 32, 32, 6, 6));
300 useCursor(KisCursor::loadWithSize("tool_similar_selection_cursor_symdiff.svg", 32, 32, 6, 6));
301 } else {
302 KisToolSelect::resetCursorStyle();
303 }
304}
@ SELECTION_INTERSECT
@ SELECTION_SYMMETRICDIFFERENCE
@ SELECTION_SUBTRACT
@ SELECTION_ADD

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

◆ slotSetOpacitySpread

void KisToolSelectSimilar::slotSetOpacitySpread ( int opacitySpread)
slot

Definition at line 218 of file kis_tool_select_similar.cc.

219{
220 m_opacitySpread = opacitySpread;
221 m_configGroup.writeEntry("opacitySpread", opacitySpread);
222}

References m_configGroup, and m_opacitySpread.

◆ slotSetThreshold

void KisToolSelectSimilar::slotSetThreshold ( int threshold)
slot

Definition at line 212 of file kis_tool_select_similar.cc.

213{
214 m_threshold = threshold;
215 m_configGroup.writeEntry("threshold", threshold);
216}

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 771 of file kis_tool_select_base.h.


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