Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolSelectBase< BaseClass > Class Template Reference

#include <kis_tool_select_base.h>

+ Inheritance diagram for KisToolSelectBase< BaseClass >:

Public Types

enum  CursorHit { CursorHit_None , CursorHit_Border , CursorHit_Inside , CursorHit_Outside }
 
enum  SampleLayersMode { SampleAllLayers , SampleCurrentGroup , SampleCurrentLayer , SampleColorLabeledLayers }
 

Public Member Functions

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

virtual bool isPixelOnly () const
 
virtual bool usesColorLabels () const
 

Protected Attributes

SelectionAction m_selectionActionAlternate
 
KisSelectionToolConfigWidgetHelper m_widgetHelper
 

Private Types

enum  Interaction { Interaction_None , Interaction_Select , Interaction_MoveSelection , Interaction_MoveContent }
 

Private Member Functions

Interaction currentInteraction () const
 

Private Attributes

QPoint m_accumulatedOffset
 
Interaction m_currentInteraction {Interaction_None}
 
Qt::KeyboardModifiers m_currentModifiers
 
QPointF m_currentPos
 
bool m_didMove = false
 
QPoint m_dragStartOffset
 
QPointF m_dragStartPos
 
KisSignalAutoConnectionsStore m_modeConnections
 
KisStrokeId m_moveStrokeId
 

Detailed Description

template<class BaseClass>
class KisToolSelectBase< BaseClass >

This is a basic template to create selection tools from basic path based drawing tools.

The temmplate implements two principal modes of interaction: the "move selection" interaction and the "move content" interaction.

The move selection interaction is a series of actions. The user can create a selection region and move the region, as well as apply manipulations to the region, like inversion.

The move content interaction is a single series of actions, infinitely looping until the user explicitly terminates the interaction by pressing a key or switching tools. This allows for rapidly selecting and moving pixels across the canvas, but avoids creating numerous transactions each time the user finishes clicking on the canvas.

The template overrides the ability to execute alternate actions correctly. The default behavior for the modifier keys is as follows:

Shift: add to selection Alt: subtract from selection Shift+Alt: intersect current selection Ctrl+Alt: symmetric difference Ctrl: replace selection

The mapping itself is done in KisSelectionModifierMapper.

Certain tools also use modifier keys to alter their behavior, e.g. forcing square proportions with the rectangle tool. The template enables the following rules for forwarding keys:

1) If the user is not selecting, then changing the modifier combination changes the selection method.

2) If the user is selecting then the modifier keys are forwarded to the specific tool, so that it can do with them whatever it wants. The selection method is not changed in this stage and it will be the same as just before the user started selecting.

3) Once the user finishes selecting, the selection method is updated to reflect the current modifier combination

4) If the user is moving the selection, then changes the modifiers

Definition at line 74 of file kis_tool_select_base.h.

Member Enumeration Documentation

◆ CursorHit

template<class BaseClass >
enum KisToolSelectBase::CursorHit
Enumerator
CursorHit_None 
CursorHit_Border 
CursorHit_Inside 
CursorHit_Outside 

Definition at line 103 of file kis_tool_select_base.h.

◆ Interaction

template<class BaseClass >
enum KisToolSelectBase::Interaction
private
Enumerator
Interaction_None 
Interaction_Select 
Interaction_MoveSelection 
Interaction_MoveContent 

Definition at line 783 of file kis_tool_select_base.h.

◆ SampleLayersMode

template<class BaseClass >
enum KisToolSelectBase::SampleLayersMode
Enumerator
SampleAllLayers 
SampleCurrentGroup 
SampleCurrentLayer 
SampleColorLabeledLayers 

Definition at line 111 of file kis_tool_select_base.h.

Constructor & Destructor Documentation

◆ KisToolSelectBase() [1/3]

template<class BaseClass >
KisToolSelectBase< BaseClass >::KisToolSelectBase ( KoCanvasBase * canvas,
const QString toolName )
inline

Definition at line 79 of file kis_tool_select_base.h.

80 : BaseClass(canvas)
81 , m_widgetHelper(toolName)
83 {
85 }
@ SELECTION_DEFAULT
KisSelectionToolConfigWidgetHelper m_widgetHelper
SelectionAction m_selectionActionAlternate
static KisSelectionModifierMapper * instance()

References KisSelectionModifierMapper::instance().

◆ KisToolSelectBase() [2/3]

template<class BaseClass >
KisToolSelectBase< BaseClass >::KisToolSelectBase ( KoCanvasBase * canvas,
const QCursor cursor,
const QString toolName )
inline

Definition at line 87 of file kis_tool_select_base.h.

88 : BaseClass(canvas, cursor)
89 , m_widgetHelper(toolName)
91 {
93 }

References KisSelectionModifierMapper::instance().

◆ KisToolSelectBase() [3/3]

template<class BaseClass >
KisToolSelectBase< BaseClass >::KisToolSelectBase ( KoCanvasBase * canvas,
QCursor cursor,
QString toolName,
KoToolBase * delegateTool )
inline

Definition at line 95 of file kis_tool_select_base.h.

96 : BaseClass(canvas, cursor, delegateTool)
97 , m_widgetHelper(toolName)
99 {
101 }

References KisSelectionModifierMapper::instance().

Member Function Documentation

◆ activate()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::activate ( const QSet< KoShape * > & shapes)
inlineoverride

Definition at line 137 of file kis_tool_select_base.h.

138 {
139 BaseClass::activate(shapes);
140
142 this->action("selection_tool_mode_replace"), SIGNAL(triggered()),
143 &m_widgetHelper, SLOT(slotReplaceModeRequested()));
144
146 this->action("selection_tool_mode_add"), SIGNAL(triggered()),
147 &m_widgetHelper, SLOT(slotAddModeRequested()));
148
150 this->action("selection_tool_mode_subtract"), SIGNAL(triggered()),
151 &m_widgetHelper, SLOT(slotSubtractModeRequested()));
152
154 this->action("selection_tool_mode_intersect"), SIGNAL(triggered()),
155 &m_widgetHelper, SLOT(slotIntersectModeRequested()));
156
158
160 if (isPixelOnly()) {
163 true);
164 }
167 }
168 }
void setModeSectionVisible(bool visible)
void setAdjustmentsSectionVisible(bool visible)
void setReferenceSectionVisible(bool visible)
void addUniqueConnection(Sender sender, Signal signal, Receiver receiver, Method method)
virtual bool isPixelOnly() const
virtual bool usesColorLabels() const
KisSignalAutoConnectionsStore m_modeConnections

References KisSignalAutoConnectionsStore::addUniqueConnection(), KisToolSelectBase< BaseClass >::isPixelOnly(), KisToolSelectBase< BaseClass >::m_modeConnections, KisToolSelectBase< BaseClass >::m_widgetHelper, KisSelectionToolConfigWidgetHelper::optionWidget(), KisSelectionOptions::setAdjustmentsSectionVisible(), KisSelectionOptions::setModeSectionVisible(), KisSelectionOptions::setReferenceSectionVisible(), KisToolSelectBase< BaseClass >::updateActionShortcutToolTips(), and KisToolSelectBase< BaseClass >::usesColorLabels().

◆ activateAlternateAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::activateAlternateAction ( KisTool::AlternateAction action)
inlineoverride

Definition at line 278 of file kis_tool_select_base.h.

279 {
280 Q_UNUSED(action);
281 BaseClass::activatePrimaryAction();
282 }

◆ alternateSelectionAction()

template<class BaseClass >
SelectionAction KisToolSelectBase< BaseClass >::alternateSelectionAction ( ) const
inline

◆ antiAliasSelection()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::antiAliasSelection ( ) const
inline

◆ beginAlternateAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::beginAlternateAction ( KoPointerEvent * event,
KisTool::AlternateAction action )
inlineoverride

Definition at line 290 of file kis_tool_select_base.h.

292 {
293 Q_UNUSED(action);
294 beginPrimaryAction(event);
295 }
void beginPrimaryAction(KoPointerEvent *event) override

References KisToolSelectBase< BaseClass >::beginPrimaryAction().

◆ beginMoveContentInteraction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::beginMoveContentInteraction ( )
inline

◆ beginMoveSelectionInteraction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::beginMoveSelectionInteraction ( )
inline

◆ beginPrimaryAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::beginPrimaryAction ( KoPointerEvent * event)
inlineoverride

Definition at line 516 of file kis_tool_select_base.h.

517 {
518 const QPointF pos = this->convertToPixelCoord(event->point);
519 const CursorHit hit = checkCursorHit(pos, event->modifiers());
520
521 if (!canBeginNewAction(event, pos, hit)) {
522 return;
523 }
524
525 KisCanvas2* canvas = dynamic_cast<KisCanvas2*>(this->canvas());
527
528 if (hit == CursorHit_Inside && this->moveSelectedContent()) {
529 KisSelectionSP selection = canvas->viewManager()->selection();
530 KisPaintLayerSP layer = dynamic_cast<KisPaintLayer*>(this->currentNode().data());
531 if (this->beginMoveContentInteraction() && selection && layer) {
532 KisStrokeStrategy *strategy =
533 new MoveSelectionStrokeStrategy(layer, selection, this->image().data(), this->image().data());
534 initializeStrokeAttributes(pos, strategy, true);
535 updateCursor();
536 }
537 return;
538 }
539
541 (hit == CursorHit_Inside || hit == CursorHit_Border)) {
542 // we shouldn't pass the control to the parent tool
543 // when we have the already started the move content action
544 return;
545 }
546
547 KisNodeSP selectionMask = locateSelectionMaskUnderCursor(pos, event->modifiers());
548 if (selectionMask) {
549 if (this->beginMoveSelectionInteraction()) {
550 KisStrokeStrategy *strategy =
551 new MoveStrokeStrategy({selectionMask}, this->image().data(), this->image().data());
552 initializeStrokeAttributes(pos, strategy, true);
553 updateCursor();
554 return;
555 }
556 }
557
558 m_didMove = false;
559 BaseClass::beginPrimaryAction(event);
560 }
KisViewManager * viewManager() const
void initializeStrokeAttributes(const QPointF &pos, KisStrokeStrategy *strategy, bool moved)
CursorHit checkCursorHit(const QPointF &pos, Qt::KeyboardModifiers modifiers) const
KisNodeSP locateSelectionMaskUnderCursor(const QPointF &pos, Qt::KeyboardModifiers modifiers)
bool moveSelectedContent() const
bool canBeginNewAction(KoPointerEvent *event, const QPointF &pos, CursorHit hit)
KisSelectionSP selection()
Qt::KeyboardModifiers modifiers() const
QPointF point
The point in document coordinates.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KisToolSelectBase< BaseClass >::beginMoveContentInteraction(), KisToolSelectBase< BaseClass >::beginMoveSelectionInteraction(), KisToolSelectBase< BaseClass >::canBeginNewAction(), KisToolSelectBase< BaseClass >::checkCursorHit(), KisToolSelectBase< BaseClass >::CursorHit_Border, KisToolSelectBase< BaseClass >::CursorHit_Inside, KisSharedPtr< T >::data(), KisToolSelectBase< BaseClass >::initializeStrokeAttributes(), KisToolSelectBase< BaseClass >::Interaction_MoveContent, KIS_SAFE_ASSERT_RECOVER_RETURN, KisToolSelectBase< BaseClass >::locateSelectionMaskUnderCursor(), KisToolSelectBase< BaseClass >::m_currentInteraction, KisToolSelectBase< BaseClass >::m_didMove, KoPointerEvent::modifiers(), KisToolSelectBase< BaseClass >::moveSelectedContent(), KoPointerEvent::point, KisViewManager::selection(), KisToolSelectBase< BaseClass >::updateCursor(), and KisCanvas2::viewManager().

◆ beginSelectInteraction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::beginSelectInteraction ( )
inline

◆ canBeginNewAction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::canBeginNewAction ( KoPointerEvent * event,
const QPointF & pos,
CursorHit hit )
inline

Definition at line 491 of file kis_tool_select_base.h.

492 {
493 /* Prevent interrupting while selecting a region */
494 if (isSelecting()) {
495 BaseClass::beginPrimaryAction(event);
496 return false;
497 }
498
499 /* Prevent interrupting while moving */
500 if (isMovingContent()) {
501 /* We must update the offsets here, so the offset is sane later */
502 m_dragStartPos = pos;
504 /* User clicked outside? Commit changes and start a new stroke */
505 /* This eliminates extra keystrokes to start a new transaction */
506 if (hit == CursorHit_Outside) {
508 BaseClass::beginPrimaryAction(event);
509 return false;
510 }
511 }
512
513 return true;
514 }

References KisToolSelectBase< BaseClass >::commitMoveSelectionStroke(), KisToolSelectBase< BaseClass >::CursorHit_Outside, KisToolSelectBase< BaseClass >::isMovingContent(), KisToolSelectBase< BaseClass >::isSelecting(), KisToolSelectBase< BaseClass >::m_accumulatedOffset, KisToolSelectBase< BaseClass >::m_dragStartOffset, and KisToolSelectBase< BaseClass >::m_dragStartPos.

◆ cancelMoveSelectionStroke()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::cancelMoveSelectionStroke ( )
inline

◆ checkCursorHit()

template<class BaseClass >
CursorHit KisToolSelectBase< BaseClass >::checkCursorHit ( const QPointF & pos,
Qt::KeyboardModifiers modifiers ) const
inline

Definition at line 456 of file kis_tool_select_base.h.

457 {
458 /* User still drawing selection? Then there's really nothing to "hit" per se */
459 if (isSelecting()) {
460 return CursorHit_None;
461 }
462
463 KisCanvas2 *canvas = dynamic_cast<KisCanvas2*>(this->canvas());
465 KisSelectionSP selection = canvas->viewManager()->selection();
466
467 if (!selection || !selection->outlineCacheValid()) {
468 return CursorHit_Outside;
469 }
470
471 const QPainterPath selectionPath = selection->outlineCache();
472
473 if (modifiers == Qt::NoModifier) {
474 const qreal handleRadius = qreal(this->handleRadius()) / canvas->coordinatesConverter()->effectiveZoom();
475
476 QPainterPath samplePath;
477 samplePath.addEllipse(pos, handleRadius, handleRadius);
478
479 if (selectionPath.intersects(samplePath) && !selectionPath.contains(samplePath)) {
480 return CursorHit_Border;
481 }
482 }
483
484 if (selectionPath.contains(pos)) {
485 return CursorHit_Inside;
486 }
487
488 return CursorHit_Outside;
489 }
KisCoordinatesConverter * coordinatesConverter
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
bool outlineCacheValid() const
QPainterPath outlineCache() const

References KisCanvas2::coordinatesConverter, KisToolSelectBase< BaseClass >::CursorHit_Border, KisToolSelectBase< BaseClass >::CursorHit_Inside, KisToolSelectBase< BaseClass >::CursorHit_None, KisToolSelectBase< BaseClass >::CursorHit_Outside, KisCoordinatesConverter::effectiveZoom(), KisToolSelectBase< BaseClass >::isSelecting(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KisSelection::outlineCache(), KisSelection::outlineCacheValid(), KisViewManager::selection(), and KisCanvas2::viewManager().

◆ colorLabelsSelected()

template<class BaseClass >
QList< int > KisToolSelectBase< BaseClass >::colorLabelsSelected ( ) const
inline

◆ commitMoveSelectionStroke()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::commitMoveSelectionStroke ( )
inline

◆ commitMoveSelectionStrokeImpl()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::commitMoveSelectionStrokeImpl ( bool cancel)
inline

◆ continueAlternateAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::continueAlternateAction ( KoPointerEvent * event,
KisTool::AlternateAction action )
inlineoverride

Definition at line 297 of file kis_tool_select_base.h.

299 {
300 Q_UNUSED(action);
302 }
void continuePrimaryAction(KoPointerEvent *event) override

References KisToolSelectBase< BaseClass >::continuePrimaryAction().

◆ continuePrimaryAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::continuePrimaryAction ( KoPointerEvent * event)
inlineoverride

Definition at line 562 of file kis_tool_select_base.h.

563 {
565 const QPointF pos = this->convertToPixelCoord(event->point);
566 const QPoint delta = (pos - m_dragStartPos).toPoint();
567 const QPoint offset = m_dragStartOffset + delta;
568 m_accumulatedOffset = offset;
569 this->image()->addJob(m_moveStrokeId, new MoveStrokeStrategy::Data(offset));
570 return;
571 }
572
573 BaseClass::continuePrimaryAction(event);
574 }

References KisToolSelectBase< BaseClass >::isMovingContent(), KisToolSelectBase< BaseClass >::isMovingSelection(), KisToolSelectBase< BaseClass >::m_accumulatedOffset, KisToolSelectBase< BaseClass >::m_dragStartOffset, KisToolSelectBase< BaseClass >::m_dragStartPos, KisToolSelectBase< BaseClass >::m_moveStrokeId, and KoPointerEvent::point.

◆ createOptionWidget()

template<class BaseClass >
QWidget * KisToolSelectBase< BaseClass >::createOptionWidget ( )
inlineoverride

Definition at line 177 of file kis_tool_select_base.h.

178 {
179 m_widgetHelper.createOptionWidget(this->toolId());
181
182 this->connect(this, SIGNAL(isActiveChanged(bool)), &m_widgetHelper, SLOT(slotToolActivatedChanged(bool)));
183 this->connect(&m_widgetHelper,
184 SIGNAL(selectionActionChanged(SelectionAction)),
185 this,
186 SLOT(resetCursorStyle()));
187
190 m_widgetHelper.optionWidget()->setContentsMargins(0, 10, 0, 10);
191 if (isPixelOnly()) {
194 true);
195 }
198 }
199
201 }
SelectionAction

References KisSelectionToolConfigWidgetHelper::createOptionWidget(), KisToolSelectBase< BaseClass >::isPixelOnly(), KisToolSelectBase< BaseClass >::m_widgetHelper, KisSelectionToolConfigWidgetHelper::optionWidget(), KisSelectionOptions::setAdjustmentsSectionVisible(), KisSelectionToolConfigWidgetHelper::setConfigGroupForExactTool(), KisSelectionOptions::setModeSectionVisible(), KisSelectionOptions::setReferenceSectionVisible(), KisToolSelectBase< BaseClass >::updateActionShortcutToolTips(), and KisToolSelectBase< BaseClass >::usesColorLabels().

◆ currentInteraction()

template<class BaseClass >
Interaction KisToolSelectBase< BaseClass >::currentInteraction ( ) const
inlineprivate

Definition at line 793 of file kis_tool_select_base.h.

793 {
795 }

References KisToolSelectBase< BaseClass >::m_currentInteraction.

◆ deactivate()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::deactivate ( )
inlineoverride

◆ deactivateAlternateAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::deactivateAlternateAction ( KisTool::AlternateAction action)
inlineoverride

Definition at line 284 of file kis_tool_select_base.h.

285 {
286 Q_UNUSED(action);
287 BaseClass::deactivatePrimaryAction();
288 }

◆ disabledMoveContentWhileMovingContent()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::disabledMoveContentWhileMovingContent ( ) const
inline

Definition at line 690 of file kis_tool_select_base.h.

690 {
691 /* User could disable the option in the middle of an action */
693 }

References KisToolSelectBase< BaseClass >::isMovingContent(), and KisToolSelectBase< BaseClass >::moveSelectedContent().

◆ endAlternateAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::endAlternateAction ( KoPointerEvent * event,
KisTool::AlternateAction action )
inlineoverride

Definition at line 304 of file kis_tool_select_base.h.

306 {
307 Q_UNUSED(action);
308 endPrimaryAction(event);
309 }
void endPrimaryAction(KoPointerEvent *event) override

References KisToolSelectBase< BaseClass >::endPrimaryAction().

◆ endMoveContentInteraction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::endMoveContentInteraction ( )
inline

◆ endMoveSelectionInteraction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::endMoveSelectionInteraction ( )
inline

◆ endPrimaryAction()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::endPrimaryAction ( KoPointerEvent * event)
inlineoverride

Definition at line 576 of file kis_tool_select_base.h.

577 {
578 if (isMovingContent()) {
579 const QPointF pos = this->convertToPixelCoord(event->point);
580 const QPoint delta = (pos - m_dragStartPos).toPoint();
582 return;
583 }
584 if (isMovingSelection()) {
585 this->image()->endStroke(m_moveStrokeId);
586 m_moveStrokeId.clear();
588 return;
589 }
590
591 BaseClass::endPrimaryAction(event);
592 }

References KisToolSelectBase< BaseClass >::endMoveSelectionInteraction(), KisToolSelectBase< BaseClass >::isMovingContent(), KisToolSelectBase< BaseClass >::isMovingSelection(), KisToolSelectBase< BaseClass >::m_accumulatedOffset, KisToolSelectBase< BaseClass >::m_dragStartOffset, KisToolSelectBase< BaseClass >::m_dragStartPos, KisToolSelectBase< BaseClass >::m_moveStrokeId, and KoPointerEvent::point.

◆ endSelectInteraction()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::endSelectInteraction ( )
inline

◆ explicitUserStrokeEndRequest()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::explicitUserStrokeEndRequest ( )
inlineoverride

◆ featherSelection()

template<class BaseClass >
int KisToolSelectBase< BaseClass >::featherSelection ( ) const
inline

◆ growSelection()

template<class BaseClass >
int KisToolSelectBase< BaseClass >::growSelection ( ) const
inline

◆ initializeStrokeAttributes()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::initializeStrokeAttributes ( const QPointF & pos,
KisStrokeStrategy * strategy,
bool moved )
inline

◆ isMovingContent()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::isMovingContent ( ) const
inline

◆ isMovingSelection()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::isMovingSelection ( ) const
inline

◆ isPixelOnly()

template<class BaseClass >
virtual bool KisToolSelectBase< BaseClass >::isPixelOnly ( ) const
inlineprotectedvirtual

Reimplemented in KisToolSelectContiguous, and KisToolSelectSimilar.

Definition at line 774 of file kis_tool_select_base.h.

774 {
775 return false;
776 }

◆ isSelecting()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::isSelecting ( ) const
inline

◆ keyPressEvent()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::keyPressEvent ( QKeyEvent * event)
inlineoverride

Definition at line 376 of file kis_tool_select_base.h.

377 {
378 /* Moving content is one, continuous stroke. Attempting to manipulate
379 * anything mid-stroke wouldn't make sense. */
380 if (isMovingContent()) {
381 return;
382 }
383
385 // Assume all the modifiers were unpressed...
386 m_currentModifiers = Qt::NoModifier;
387 // ...and add those which are right now
388 if (key == Qt::Key_Control || event->modifiers().testFlag(Qt::ControlModifier)) {
389 m_currentModifiers.setFlag(Qt::ControlModifier);
390 }
391 if (key == Qt::Key_Shift || event->modifiers().testFlag(Qt::ShiftModifier)) {
392 m_currentModifiers.setFlag(Qt::ShiftModifier);
393 }
394 if (key == Qt::Key_Alt || event->modifiers().testFlag(Qt::AltModifier)) {
395 m_currentModifiers.setFlag(Qt::AltModifier);
396 }
397
398 // Avoid changing the cursor if the user is interacting
399 if (isSelecting()) {
400 BaseClass::keyPressEvent(event);
401 return;
402 }
403
405 updateCursor();
406 }
static Qt::Key workaroundShiftAltMetaHell(const QKeyEvent *keyEvent)
virtual void setAlternateSelectionAction(SelectionAction action)
Qt::KeyboardModifiers m_currentModifiers
SelectionAction map(Qt::KeyboardModifiers m)

References KisToolSelectBase< BaseClass >::isMovingContent(), KisToolSelectBase< BaseClass >::isSelecting(), KisToolSelectBase< BaseClass >::m_currentModifiers, KisSelectionModifierMapper::map(), KisToolSelectBase< BaseClass >::setAlternateSelectionAction(), KisToolSelectBase< BaseClass >::updateCursor(), and KisExtendedModifiersMapper::workaroundShiftAltMetaHell().

◆ keyReleaseEvent()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::keyReleaseEvent ( QKeyEvent * event)
inlineoverride

Definition at line 408 of file kis_tool_select_base.h.

409 {
411 // Assume all the modifiers were pressed...
412 m_currentModifiers = Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier;
413 // ...and remove those which aren't right now
414 if (key == Qt::Key_Control || !event->modifiers().testFlag(Qt::ControlModifier)) {
415 m_currentModifiers.setFlag(Qt::ControlModifier, false);
416 }
417 if (key == Qt::Key_Shift || !event->modifiers().testFlag(Qt::ShiftModifier)) {
418 m_currentModifiers.setFlag(Qt::ShiftModifier, false);
419 }
420 if (key == Qt::Key_Alt || !event->modifiers().testFlag(Qt::AltModifier)) {
421 m_currentModifiers.setFlag(Qt::AltModifier, false);
422 }
423
424 // Avoid changing the selection mode and cursor if the user is interacting
425 if (isSelecting()) {
426 BaseClass::keyReleaseEvent(event);
427 return;
428 }
429 if (isMovingSelection()) {
430 return;
431 }
432
434 if (m_currentModifiers == Qt::NoModifier) {
435 updateCursor();
436 }
437 else {
438 this->resetCursorStyle();
439 }
440 }

References KisToolSelectBase< BaseClass >::isMovingSelection(), KisToolSelectBase< BaseClass >::isSelecting(), KisToolSelectBase< BaseClass >::m_currentModifiers, KisSelectionModifierMapper::map(), KisToolSelectBase< BaseClass >::setAlternateSelectionAction(), KisToolSelectBase< BaseClass >::updateCursor(), and KisExtendedModifiersMapper::workaroundShiftAltMetaHell().

◆ locateSelectionMaskUnderCursor()

template<class BaseClass >
KisNodeSP KisToolSelectBase< BaseClass >::locateSelectionMaskUnderCursor ( const QPointF & pos,
Qt::KeyboardModifiers modifiers )
inline

Definition at line 349 of file kis_tool_select_base.h.

349 {
350 if (modifiers != Qt::NoModifier) return 0;
351
352 KisCanvas2* canvas = dynamic_cast<KisCanvas2*>(this->canvas());
354
355 KisSelectionSP selection = canvas->viewManager()->selection();
356 if (selection &&
357 selection->outlineCacheValid()) {
358
359 const qreal handleRadius = qreal(this->handleRadius()) / canvas->coordinatesConverter()->effectiveZoom();
360 QPainterPath samplePath;
361 samplePath.addEllipse(pos, handleRadius, handleRadius);
362
363 const QPainterPath selectionPath = selection->outlineCache();
364
365 if (selectionPath.intersects(samplePath) && !selectionPath.contains(samplePath)) {
366 KisNodeSP parent = selection->parentNode();
367 if (parent && parent->isEditable()) {
368 return parent;
369 }
370 }
371 }
372
373 return 0;
374 }
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327
KisNodeWSP parentNode

References KisCanvas2::coordinatesConverter, KisCoordinatesConverter::effectiveZoom(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KisSelection::outlineCache(), KisSelection::outlineCacheValid(), KisSelection::parentNode, KisViewManager::selection(), and KisCanvas2::viewManager().

◆ mouseMoveEvent()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::mouseMoveEvent ( KoPointerEvent * event)
inlineoverride

Definition at line 442 of file kis_tool_select_base.h.

443 {
444 m_currentPos = this->convertToPixelCoord(event->point);
445 m_currentModifiers = event->modifiers();
446
448 /* User disabled option while actively moving content? Commit and end */
450 }
451
452 updateCursor();
453 BaseClass::mouseMoveEvent(event);
454 }
bool disabledMoveContentWhileMovingContent() const

References KisToolSelectBase< BaseClass >::commitMoveSelectionStroke(), KisToolSelectBase< BaseClass >::disabledMoveContentWhileMovingContent(), KisToolSelectBase< BaseClass >::m_currentModifiers, KisToolSelectBase< BaseClass >::m_currentPos, KoPointerEvent::point, and KisToolSelectBase< BaseClass >::updateCursor().

◆ moveSelectedContent()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::moveSelectedContent ( ) const
inline

◆ popupActionsMenu()

template<class BaseClass >
QMenu * KisToolSelectBase< BaseClass >::popupActionsMenu ( )
inlineoverride

Definition at line 599 of file kis_tool_select_base.h.

600 {
601 if (isSelecting()) {
602 return BaseClass::popupActionsMenu();
603 }
604
605 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
607
609 }
static QMenu * getSelectionContextMenu(KisCanvas2 *canvas)

References KisSelectionToolHelper::getSelectionContextMenu(), KisToolSelectBase< BaseClass >::isSelecting(), and KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE.

◆ popupWidget()

template<class BaseClass >
KisPopupWidgetInterface * KisToolSelectBase< BaseClass >::popupWidget ( )
inlineoverride

Definition at line 611 of file kis_tool_select_base.h.

612 {
613 if (isSelecting()) {
614 return BaseClass::popupWidget();
615 }
616 return nullptr;
617 }

References KisToolSelectBase< BaseClass >::isSelecting().

◆ requestStrokeCancellation()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::requestStrokeCancellation ( )
inlineoverride

◆ requestStrokeEnd()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::requestStrokeEnd ( )
inlineoverride

◆ sampleLayersMode()

template<class BaseClass >
SampleLayersMode KisToolSelectBase< BaseClass >::sampleLayersMode ( ) const
inline

Definition at line 246 of file kis_tool_select_base.h.

References KisSelectionOptions::AllLayers, KisSelectionOptions::ColorLabeledLayers, KisSelectionOptions::CurrentGroup, KisSelectionOptions::CurrentLayer, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KisToolSelectBase< BaseClass >::m_widgetHelper, KisSelectionToolConfigWidgetHelper::referenceLayers(), KisToolSelectBase< BaseClass >::SampleAllLayers, KisToolSelectBase< BaseClass >::SampleColorLabeledLayers, KisToolSelectBase< BaseClass >::SampleCurrentGroup, and KisToolSelectBase< BaseClass >::SampleCurrentLayer.

◆ selectionAction()

◆ selectionDidMove()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::selectionDidMove ( ) const
inline

Definition at line 594 of file kis_tool_select_base.h.

595 {
596 return m_didMove;
597 }

References KisToolSelectBase< BaseClass >::m_didMove.

◆ selectionMode()

template<class BaseClass >
SelectionMode KisToolSelectBase< BaseClass >::selectionMode ( ) const
inline

◆ selectionOptionWidget()

template<class BaseClass >
KisSelectionOptions * KisToolSelectBase< BaseClass >::selectionOptionWidget ( )
inline

◆ setAlternateSelectionAction()

template<class BaseClass >
virtual void KisToolSelectBase< BaseClass >::setAlternateSelectionAction ( SelectionAction action)
inlinevirtual

◆ stopGrowingAtDarkestPixel()

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::stopGrowingAtDarkestPixel ( ) const
inline

◆ updateActionShortcutToolTips()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::updateActionShortcutToolTips ( )
inline

Definition at line 119 of file kis_tool_select_base.h.

119 {
121 if (widget) {
124 this->action("selection_tool_mode_replace")->shortcut());
127 this->action("selection_tool_mode_add")->shortcut());
130 this->action("selection_tool_mode_subtract")->shortcut());
133 this->action("selection_tool_mode_intersect")->shortcut());
134 }
135 }
@ SELECTION_REPLACE
@ SELECTION_INTERSECT
@ SELECTION_SUBTRACT
@ SELECTION_ADD
void updateActionButtonToolTip(SelectionAction action, const QKeySequence &shortcut)

References KisToolSelectBase< BaseClass >::m_widgetHelper, KisSelectionToolConfigWidgetHelper::optionWidget(), SELECTION_ADD, SELECTION_INTERSECT, SELECTION_REPLACE, SELECTION_SUBTRACT, and KisSelectionOptions::updateActionButtonToolTip().

◆ updateCursor()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::updateCursor ( )
inline

Definition at line 695 of file kis_tool_select_base.h.

696 {
697
698 const Interaction interaction = currentInteraction();
700
701 switch (interaction)
702 {
704 switch (hit)
705 {
706 case CursorHit_Border:
707 this->useCursor(KisCursor::moveCursor());
708 break;
709 case CursorHit_Inside:
710 this->useCursor(KisCursor::moveCursor());
711 break;
713 this->resetCursorStyle();
714 break;
715 case CursorHit_None:
716 default:
717 this->resetCursorStyle();
718 break;
719 }
720 break;
722 switch (hit)
723 {
724 case CursorHit_Border:
725 this->useCursor(KisCursor::moveSelectionCursor());
726 break;
727 case CursorHit_Inside:
728 this->resetCursorStyle();
729 break;
731 this->resetCursorStyle();
732 break;
733 case CursorHit_None:
734 default:
735 this->resetCursorStyle();
736 break;
737 }
738 break;
740 this->resetCursorStyle();
741 break;
742 case Interaction_None:
743 if (hit == CursorHit_Border){
744 this->useCursor(KisCursor::moveSelectionCursor());
745 }
746 else if (hit == CursorHit_Inside && this->moveSelectedContent()) {
747 this->useCursor(KisCursor::moveCursor());
748 } else {
749 this->resetCursorStyle();
750 }
751 break;
752 default:
753 this->resetCursorStyle();
754 break;
755 }
756 }
static QCursor moveSelectionCursor()
static QCursor moveCursor()
Interaction currentInteraction() const

References KisToolSelectBase< BaseClass >::checkCursorHit(), KisToolSelectBase< BaseClass >::currentInteraction(), KisToolSelectBase< BaseClass >::CursorHit_Border, KisToolSelectBase< BaseClass >::CursorHit_Inside, KisToolSelectBase< BaseClass >::CursorHit_None, KisToolSelectBase< BaseClass >::CursorHit_Outside, KisToolSelectBase< BaseClass >::Interaction_MoveContent, KisToolSelectBase< BaseClass >::Interaction_MoveSelection, KisToolSelectBase< BaseClass >::Interaction_None, KisToolSelectBase< BaseClass >::Interaction_Select, KisToolSelectBase< BaseClass >::m_currentModifiers, KisToolSelectBase< BaseClass >::m_currentPos, KisCursor::moveCursor(), KisToolSelectBase< BaseClass >::moveSelectedContent(), and KisCursor::moveSelectionCursor().

◆ updateCursorDelayed()

template<class BaseClass >
void KisToolSelectBase< BaseClass >::updateCursorDelayed ( )
inline

◆ usesColorLabels()

template<class BaseClass >
virtual bool KisToolSelectBase< BaseClass >::usesColorLabels ( ) const
inlineprotectedvirtual

Reimplemented in KisToolSelectContiguous, and KisToolSelectSimilar.

Definition at line 778 of file kis_tool_select_base.h.

778 {
779 return false;
780 }

Member Data Documentation

◆ m_accumulatedOffset

template<class BaseClass >
QPoint KisToolSelectBase< BaseClass >::m_accumulatedOffset
private

Definition at line 801 of file kis_tool_select_base.h.

◆ m_currentInteraction

template<class BaseClass >
Interaction KisToolSelectBase< BaseClass >::m_currentInteraction {Interaction_None}
private

Definition at line 791 of file kis_tool_select_base.h.

◆ m_currentModifiers

template<class BaseClass >
Qt::KeyboardModifiers KisToolSelectBase< BaseClass >::m_currentModifiers
private

Definition at line 797 of file kis_tool_select_base.h.

◆ m_currentPos

template<class BaseClass >
QPointF KisToolSelectBase< BaseClass >::m_currentPos
private

Definition at line 800 of file kis_tool_select_base.h.

◆ m_didMove

template<class BaseClass >
bool KisToolSelectBase< BaseClass >::m_didMove = false
private

Definition at line 804 of file kis_tool_select_base.h.

◆ m_dragStartOffset

template<class BaseClass >
QPoint KisToolSelectBase< BaseClass >::m_dragStartOffset
private

Definition at line 802 of file kis_tool_select_base.h.

◆ m_dragStartPos

template<class BaseClass >
QPointF KisToolSelectBase< BaseClass >::m_dragStartPos
private

Definition at line 799 of file kis_tool_select_base.h.

◆ m_modeConnections

template<class BaseClass >
KisSignalAutoConnectionsStore KisToolSelectBase< BaseClass >::m_modeConnections
private

Definition at line 806 of file kis_tool_select_base.h.

◆ m_moveStrokeId

template<class BaseClass >
KisStrokeId KisToolSelectBase< BaseClass >::m_moveStrokeId
private

Definition at line 803 of file kis_tool_select_base.h.

◆ m_selectionActionAlternate

template<class BaseClass >
SelectionAction KisToolSelectBase< BaseClass >::m_selectionActionAlternate
protected

Definition at line 772 of file kis_tool_select_base.h.

◆ m_widgetHelper

template<class BaseClass >
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 file: