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

#include <KoShapeRubberSelectStrategy.h>

+ Inheritance diagram for KoShapeRubberSelectStrategy:

Public Member Functions

KUndo2CommandcreateCommand () override
 
void handleMouseMove (const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
 
 KoShapeRubberSelectStrategy (KoToolBase *tool, const QPointF &clicked, bool useSnapToGrid=false)
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
- Public Member Functions inherited from KoInteractionStrategy
virtual void cancelInteraction ()
 
virtual void finishInteraction (Qt::KeyboardModifiers modifiers)=0
 
 KoInteractionStrategy (KoToolBase *parent)
 constructor
 
KoToolBasetool () const
 
virtual ~KoInteractionStrategy ()
 Destructor.
 

Protected Types

enum  SelectionMode { CrossingSelection , CoveringSelection }
 

Protected Member Functions

virtual SelectionMode currentMode () const
 
 KoShapeRubberSelectStrategy (KoShapeRubberSelectStrategyPrivate &)
 constructor
 
QRectF selectedRectangle () const
 
- Protected Member Functions inherited from KoInteractionStrategy
uint decorationThickness () const
 
uint grabSensitivity () const
 Convenience function to get the global grab sensitivity.
 
uint handleRadius () const
 Convenience function to get the global handle radius.
 
 KoInteractionStrategy (KoInteractionStrategyPrivate &)
 constructor
 

Additional Inherited Members

- Protected Attributes inherited from KoInteractionStrategy
KoInteractionStrategyPrivated_ptr
 

Detailed Description

This is a base class for interactions based on dragging a rectangular area on the canvas, such as selection, zooming or shape creation.

When the user selects stuff in left-to-right way, selection is in "covering" (or "containing") mode, when in "left-to-right" in "crossing" mode

Definition at line 28 of file KoShapeRubberSelectStrategy.h.

Member Enumeration Documentation

◆ SelectionMode

Enumerator
CrossingSelection 
CoveringSelection 

Definition at line 52 of file KoShapeRubberSelectStrategy.h.

Constructor & Destructor Documentation

◆ KoShapeRubberSelectStrategy() [1/2]

KoShapeRubberSelectStrategy::KoShapeRubberSelectStrategy ( KoToolBase * tool,
const QPointF & clicked,
bool useSnapToGrid = false )

Constructor that initiates the rubber select. A rubber select is basically rectangle area that the user drags out from clicked to a point later provided in the handleMouseMove() continuously showing a semi-transparent 'rubber-mat' over the objects it is about to select.

Parameters
toolthe parent tool which controls this strategy
clickedthe initial point that the user depressed (in pt).
useSnapToGriduse the snap-to-grid settings while doing the rubberstamp.

Definition at line 19 of file KoShapeRubberSelectStrategy.cpp.

21{
23 d->snapGuide->enableSnapStrategies(KoSnapGuide::GridSnapping);
24 d->snapGuide->enableSnapping(useSnapToGrid);
25
26 d->selectRect = QRectF(d->snapGuide->snap(clicked, QFlags<Qt::KeyboardModifier>()), QSizeF(0, 0));
27}
KoInteractionStrategy(KoToolBase *parent)
constructor

References KoSnapGuide::GridSnapping.

◆ KoShapeRubberSelectStrategy() [2/2]

KoShapeRubberSelectStrategy::KoShapeRubberSelectStrategy ( KoShapeRubberSelectStrategyPrivate & )
protected

constructor

Member Function Documentation

◆ createCommand()

KUndo2Command * KoShapeRubberSelectStrategy::createCommand ( )
overridevirtual

For interactions that are undo-able this method should be implemented to return such a command. Implementations should return 0 otherwise.

Returns
a command, or 0.

Implements KoInteractionStrategy.

Definition at line 103 of file KoShapeRubberSelectStrategy.cpp.

104{
105 return 0;
106}

◆ currentMode()

KoShapeRubberSelectStrategy::SelectionMode KoShapeRubberSelectStrategy::currentMode ( ) const
protectedvirtual

Reimplemented in KoZoomStrategy.

Definition at line 97 of file KoShapeRubberSelectStrategy.cpp.

98{
100 return d->selectRect.left() < d->selectRect.right() ? CoveringSelection : CrossingSelection;
101}

References CoveringSelection, and CrossingSelection.

◆ handleMouseMove()

void KoShapeRubberSelectStrategy::handleMouseMove ( const QPointF & mouseLocation,
Qt::KeyboardModifiers modifiers )
overridevirtual

Extending classes should implement this method to update the selectedShapes based on the new mouse position.

Parameters
mouseLocationthe new location in pt
modifiersOR-ed set of keys pressed.

Implements KoInteractionStrategy.

Definition at line 56 of file KoShapeRubberSelectStrategy.cpp.

57{
59 QPointF point = d->snapGuide->snap(p, modifiers);
60 if (modifiers & Qt::ControlModifier) {
61 const QRectF oldDirtyRect = d->selectedRect();
62 d->selectRect.moveTopLeft(d->selectRect.topLeft() - (d->lastPos - point));
63 d->lastPos = point;
64 d->tool->canvas()->updateCanvas(oldDirtyRect | d->selectedRect());
65 return;
66 }
67 d->lastPos = point;
68 QPointF old = d->selectRect.bottomRight();
69 d->selectRect.setBottomRight(point);
70 /*
71 +---------------|--+
72 | | | We need to figure out rects A and B based on the two points. BUT
73 | old | A| we need to do that even if the points are switched places
74 | \ | | (i.e. the rect got smaller) and even if the rect is mirrored
75 +---------------+ | in either the horizontal or vertical axis.
76 | B |
77 +------------------+
78 `- point
79 */
80 QPointF x1 = old;
81 x1.setY(d->selectRect.topLeft().y());
82 qreal h1 = point.y() - x1.y();
83 qreal h2 = old.y() - x1.y();
84 QRectF A(x1, QSizeF(point.x() - x1.x(), point.y() < d->selectRect.top() ? qMin(h1, h2) : qMax(h1, h2)));
85 A = A.normalized();
86 d->tool->canvas()->updateCanvas(A);
87
88 QPointF x2 = old;
89 x2.setX(d->selectRect.topLeft().x());
90 qreal w1 = point.x() - x2.x();
91 qreal w2 = old.x() - x2.x();
92 QRectF B(x2, QSizeF(point.x() < d->selectRect.left() ? qMin(w1, w2) : qMax(w1, w2), point.y() - x2.y()));
93 B = B.normalized();
94 d->tool->canvas()->updateCanvas(B);
95}
const Params2D p

References A, B, and p.

◆ paint()

void KoShapeRubberSelectStrategy::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Reimplement this if the action needs to draw a "blob" on the canvas; that is, a transient decoration like a rubber band.

Reimplemented from KoInteractionStrategy.

Reimplemented in SelectionInteractionStrategy.

Definition at line 29 of file KoShapeRubberSelectStrategy.cpp.

30{
32 painter.setRenderHint(QPainter::Antialiasing, false);
33
34 const QColor crossingColor(80,130,8);
35 const QColor coveringColor(8,60,167);
36
37 QColor selectColor(
39 crossingColor : coveringColor);
40
41 selectColor.setAlphaF(0.8);
42 QPen select(selectColor, decorationThickness());
43 select.setCosmetic(true);
44 painter.setPen(select);
45
46 selectColor.setAlphaF(0.4);
47 const QBrush fillBrush(selectColor);
48 painter.setBrush(fillBrush);
49
50 QRectF paintRect = converter.documentToView(d->selectedRect());
51 paintRect = paintRect.normalized();
52
53 painter.drawRect(paintRect);
54}
virtual SelectionMode currentMode() const
virtual QPointF documentToView(const QPointF &documentPoint) const

References CrossingSelection, currentMode(), KoInteractionStrategy::decorationThickness(), and KoViewConverter::documentToView().

◆ selectedRectangle()

QRectF KoShapeRubberSelectStrategy::selectedRectangle ( ) const
protected

Definition at line 108 of file KoShapeRubberSelectStrategy.cpp.

108 {
110 return d->selectedRect();
111}

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