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

#include <ShapeRotateStrategy.h>

+ Inheritance diagram for ShapeRotateStrategy:

Public Member Functions

KUndo2CommandcreateCommand () override
 
void finishInteraction (Qt::KeyboardModifiers modifiers) override
 
void handleMouseMove (const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
 ShapeRotateStrategy (KoToolBase *tool, KoSelection *selection, const QPointF &clicked, Qt::MouseButtons buttons)
 
 ~ShapeRotateStrategy () override
 
- Public Member Functions inherited from KoInteractionStrategy
virtual void cancelInteraction ()
 
 KoInteractionStrategy (KoToolBase *parent)
 constructor
 
KoToolBasetool () const
 
virtual ~KoInteractionStrategy ()
 Destructor.
 

Private Member Functions

void rotateBy (qreal angle)
 

Private Attributes

QList< QTransform > m_oldTransforms
 
QPointF m_rotationCenter
 
QTransform m_rotationMatrix
 
QPointF m_start
 
QList< KoShape * > m_transformedShapesAndSelection
 

Additional Inherited Members

- 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
 
- Protected Attributes inherited from KoInteractionStrategy
KoInteractionStrategyPrivated_ptr
 

Detailed Description

A strategy for the KoInteractionTool. This strategy is invoked when the user starts a rotate of a selection of objects, the strategy will then rotate the objects interactively and provide a command afterwards.

Definition at line 26 of file ShapeRotateStrategy.h.

Constructor & Destructor Documentation

◆ ShapeRotateStrategy()

ShapeRotateStrategy::ShapeRotateStrategy ( KoToolBase * tool,
KoSelection * selection,
const QPointF & clicked,
Qt::MouseButtons buttons )

Constructor that starts to rotate the objects.

Parameters
toolthe parent tool which controls this strategy
clickedthe initial point that the user depressed (in pt).

The outline of the selection should look as if it is also rotated, so we add it to the transformed shapes list.

Definition at line 23 of file ShapeRotateStrategy.cpp.

25 , m_start(clicked)
26{
33
34 Q_FOREACH (KoShape *shape, m_transformedShapesAndSelection) {
36 }
37
38 KoFlake::AnchorPosition anchor = !(buttons & Qt::RightButton) ?
40 KoFlake::AnchorPosition(tool->canvas()->resourceManager()->resource(KoFlake::HotPosition).toInt());
41
42 m_rotationCenter = selection->absolutePosition(anchor);
43
44 tool->setStatusText(i18n("Press ALT to rotate in 45 degree steps."));
45}
KoInteractionStrategy(KoToolBase *parent)
constructor
const QList< KoShape * > selectedEditableShapes() const
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
void setStatusText(const QString &statusText)
QList< QTransform > m_oldTransforms
QList< KoShape * > m_transformedShapesAndSelection
QString buttons(const T &ev)
int toInt(const QString &str, bool *ok=nullptr)
AnchorPosition
Definition KoFlake.h:85
@ Center
Definition KoFlake.h:90
@ HotPosition
Definition KoFlake.h:102

References KoShape::absolutePosition(), buttons(), KoToolBase::canvas(), KoFlake::Center, KoFlake::HotPosition, m_oldTransforms, m_rotationCenter, m_transformedShapesAndSelection, KoCanvasBase::resourceManager, KoSelection::selectedEditableShapes(), KoToolBase::setStatusText(), KoInteractionStrategy::tool(), and KoShape::transformation().

◆ ~ShapeRotateStrategy()

ShapeRotateStrategy::~ShapeRotateStrategy ( )
inlineoverride

Definition at line 35 of file ShapeRotateStrategy.h.

35{}

Member Function Documentation

◆ createCommand()

KUndo2Command * ShapeRotateStrategy::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 95 of file ShapeRotateStrategy.cpp.

96{
97 QList<QTransform> newTransforms;
98 Q_FOREACH (KoShape *shape, m_transformedShapesAndSelection) {
99 newTransforms << shape->transformation();
100 }
101
103 cmd->setText(kundo2_i18n("Rotate"));
104 return cmd;
105}
void setText(const KUndo2MagicString &text)
KUndo2MagicString kundo2_i18n(const char *text)

References kundo2_i18n(), m_oldTransforms, m_transformedShapesAndSelection, KUndo2Command::setText(), and KoShape::transformation().

◆ finishInteraction()

void ShapeRotateStrategy::finishInteraction ( Qt::KeyboardModifiers modifiers)
inlineoverridevirtual

Override to make final changes to the data on the end of an interaction.

Implements KoInteractionStrategy.

Definition at line 39 of file ShapeRotateStrategy.h.

40 {
41 Q_UNUSED(modifiers);
42 }

◆ handleMouseMove()

void ShapeRotateStrategy::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 47 of file ShapeRotateStrategy.cpp.

48{
49 qreal angle = atan2(point.y() - m_rotationCenter.y(), point.x() - m_rotationCenter.x()) -
51 angle = angle / M_PI * 180; // convert to degrees.
52 if (modifiers & (Qt::AltModifier | Qt::ControlModifier)) {
53 // limit to 45 degree angles
54 qreal modula = qAbs(angle);
55 while (modula > 45.0) {
56 modula -= 45.0;
57 }
58 if (modula > 22.5) {
59 modula -= 45.0;
60 }
61 angle += (angle > 0 ? -1 : 1) * modula;
62 }
63
64 rotateBy(angle);
65}
void rotateBy(qreal angle)
#define M_PI
Definition kis_global.h:111
KRITAIMAGE_EXPORT qreal atan2(qreal y, qreal x)
atan2 replacement

References M_PI, m_rotationCenter, m_start, and rotateBy().

◆ paint()

void ShapeRotateStrategy::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.

Definition at line 84 of file ShapeRotateStrategy.cpp.

85{
86 // paint the rotation center
87 painter.setPen(QPen(Qt::red));
88 painter.setBrush(QBrush(Qt::red));
89 painter.setRenderHint(QPainter::Antialiasing, true);
90 QRectF circle(0, 0, handleRadius(), handleRadius());
91 circle.moveCenter(converter.documentToView(m_rotationCenter));
92 painter.drawEllipse(circle);
93}
uint handleRadius() const
Convenience function to get the global handle radius.
virtual QPointF documentToView(const QPointF &documentPoint) const

References KoViewConverter::documentToView(), KoInteractionStrategy::handleRadius(), and m_rotationCenter.

◆ rotateBy()

void ShapeRotateStrategy::rotateBy ( qreal angle)
private

Definition at line 67 of file ShapeRotateStrategy.cpp.

68{
69 QTransform matrix;
70 matrix.translate(m_rotationCenter.x(), m_rotationCenter.y());
71 matrix.rotate(angle);
72 matrix.translate(-m_rotationCenter.x(), -m_rotationCenter.y());
73
74 QTransform applyMatrix = matrix * m_rotationMatrix.inverted();
75 m_rotationMatrix = matrix;
76 Q_FOREACH (KoShape *shape, m_transformedShapesAndSelection) {
77 QRectF dirtyRect = shape->boundingRect();
78 shape->applyAbsoluteTransformation(applyMatrix);
79 dirtyRect |= shape->boundingRect();
80 shape->updateAbsolute(dirtyRect);
81 }
82}
void applyAbsoluteTransformation(const QTransform &matrix)
Definition KoShape.cpp:400
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:616

References KoShape::applyAbsoluteTransformation(), KoShape::boundingRect(), m_rotationCenter, m_rotationMatrix, m_transformedShapesAndSelection, and KoShape::updateAbsolute().

Member Data Documentation

◆ m_oldTransforms

QList<QTransform> ShapeRotateStrategy::m_oldTransforms
private

Definition at line 50 of file ShapeRotateStrategy.h.

◆ m_rotationCenter

QPointF ShapeRotateStrategy::m_rotationCenter
private

Definition at line 51 of file ShapeRotateStrategy.h.

◆ m_rotationMatrix

QTransform ShapeRotateStrategy::m_rotationMatrix
private

Definition at line 49 of file ShapeRotateStrategy.h.

◆ m_start

QPointF ShapeRotateStrategy::m_start
private

Definition at line 48 of file ShapeRotateStrategy.h.

◆ m_transformedShapesAndSelection

QList<KoShape *> ShapeRotateStrategy::m_transformedShapesAndSelection
private

Definition at line 52 of file ShapeRotateStrategy.h.


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