Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • managers
selectionmanager.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#ifndef SELECTIONMANAGER_H
18#define SELECTIONMANAGER_H
19
20#include "basemanager.h"
21#include "movemode.h"
22#include "vertexref.h"
23#include "vectorselection.h"
24
25#include <QPointF>
26#include <QRectF>
27#include <QPolygonF>
28#include <QTransform>
29
30class Editor;
31
50class SelectionManager : public BaseManager
51{
52 Q_OBJECT
53public:
54 explicit SelectionManager(Editor* editor);
55 ~SelectionManager() override;
56
57 bool init() override;
58 Status load(Object*) override;
59 Status save(Object*) override;
60 void workingLayerChanged(Layer*) override;
61
62 void flipSelection(bool flipVertical);
63
66 void setSelection(QRectF rect, bool roundPixels=false);
67
68 void translate(QPointF point);
69 void rotate(qreal angle, qreal lockedAngle);
70 void scale(qreal sX, qreal sY);
71 void maintainAspectRatio(bool state) { mAspectRatioFixed = state; }
72
75 void alignPositionToAxis(bool state) { mLockAxis = state; }
76
78 void setMoveModeForAnchorInRange(const QPointF& point);
79 MoveMode getMoveMode() const { return mMoveMode; }
80 void setMoveMode(const MoveMode moveMode) { mMoveMode = moveMode; }
81
82 bool somethingSelected() const { return mOriginalRect.isValid() || mMoveMode != MoveMode::NONE; }
83
86 void adjustSelection(const QPointF& currentPoint, const QPointF& offset, qreal rotationOffset, int rotationIncrement = 0);
87
88 QTransform selectionTransform() const { return mSelectionTransform; }
89 void setSelectionTransform(const QTransform& transform) { mSelectionTransform = transform; }
90 void resetSelectionTransform();
91
96 void resetSelectionTransformProperties();
97
98 void resetSelectionProperties();
99 void deleteSelection();
100
101 bool isOutsideSelectionArea(const QPointF& point) const;
102
103 qreal selectionTolerance() const;
104
105 qreal selectionWidth() const { return (mSelectionPolygon[1] - mSelectionPolygon[0]).x(); }
106 qreal selectionHeight() const { return (mSelectionPolygon[3] - mSelectionPolygon[0]).y(); }
107
108 QPointF currentTransformAnchor() const { return mAnchorPoint; }
109 QPointF getSelectionAnchorPoint() const;
110
111 void setTransformAnchor(const QPointF& point);
112
113 const QRectF& mySelectionRect() const { return mOriginalRect; }
114 const qreal& myRotation() const { return mRotatedAngle; }
115 const qreal& myScaleX() const { return mScaleX; }
116 const qreal& myScaleY() const { return mScaleY; }
117 const QPointF& myTranslation() const { return mTranslation; }
118
119 void setRotation(const qreal& rotation) { mRotatedAngle = rotation; }
120 void setScale(const qreal scaleX, const qreal scaleY) { mScaleX = scaleX; mScaleY = scaleY; }
121 void setTranslation(const QPointF& translation) { mTranslation = translation; }
122
123 qreal angleFromPoint(const QPointF& point, const QPointF& anchorPoint) const;
124
125 // Coordinate Space Conversions
126 // "Local Space" = The Layer/Canvas coordinate system.
127 // "Selection Space" = The local coordinate system of the selection itself (0,0 is usually top-left of un-transformed rect).
128
130 QPointF mapToSelection(const QPointF& point) const { return mSelectionTransform.map(point); };
131
133 QPointF mapFromLocalSpace(const QPointF& point) const { return mSelectionTransform.inverted().map(point); }
134
135 QPolygonF mapToSelection(const QPolygonF& polygon) const { return mSelectionTransform.map(polygon); }
136 QPolygonF mapFromLocalSpace(const QPolygonF& polygon) const { return mSelectionTransform.inverted().map(polygon); }
137
138 // Vector selection
139 VectorSelection vectorSelection;
140
141 void setCurves(const QList<int>& curves) { mClosestCurves = curves; }
142 void setVertices(const QList<VertexRef>& vertices) { mClosestVertices = vertices; }
143
144 void clearCurves() { mClosestCurves.clear(); };
145 void clearVertices() { mClosestVertices.clear(); };
146
149 void setDragOrigin(const QPointF point) { mDragOrigin = point; }
150
151 const QList<int> closestCurves() const { return mClosestCurves; }
152 const QList<VertexRef> closestVertices() const { return mClosestVertices; }
153
155 void calculateSelectionTransformation();
156
157signals:
158 void selectionChanged();
159 void selectionReset();
160 void needDeleteSelection();
161
162private:
168 QPointF alignPositionToAxis(QPointF currentPoint) const;
169 int constrainRotationToAngle(const qreal rotatedAngle, const int rotationIncrement) const;
170
171 bool mAspectRatioFixed = false;
172 bool mLockAxis = false;
173 QPolygonF mSelectionPolygon;
174 QRectF mOriginalRect;
175
176 qreal mScaleX;
177 qreal mScaleY;
178 QPointF mTranslation;
179 qreal mRotatedAngle = 0.0;
180
181 QList<int> mClosestCurves;
182 QList<VertexRef> mClosestVertices;
183
184 QPointF mDragOrigin;
185
186 MoveMode mMoveMode = MoveMode::NONE;
187 QTransform mSelectionTransform;
188 const qreal mSelectionTolerance = 10.0;
189
190 QPointF mAnchorPoint;
191};
192
193#endif // SELECTIONMANAGER_H
BaseManager
Definition: basemanager.h:29
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
Object
Definition: object.h:42
SelectionManager
The SelectionManager class acts as the "Brain" of the selection system.
Definition: selectionmanager.h:51
SelectionManager::flipSelection
void flipSelection(bool flipVertical)
ScribbleArea::flipSelection flip selection along the X or Y axis.
Definition: selectionmanager.cpp:328
SelectionManager::resetSelectionTransformProperties
void resetSelectionTransformProperties()
SelectionManager::resetSelectionTransformProperties should be used whenever translate,...
Definition: selectionmanager.cpp:55
SelectionManager::setDragOrigin
void setDragOrigin(const QPointF point)
The point from where the dragging will be based of inside the selection area.
Definition: selectionmanager.h:149
SelectionManager::mapFromLocalSpace
QPointF mapFromLocalSpace(const QPointF &point) const
Maps a point FROM the Selection's transformed space BACK to Canvas/Layer space.
Definition: selectionmanager.h:133
SelectionManager::alignPositionToAxis
void alignPositionToAxis(bool state)
Locks movement either horizontally or vertically depending on drag direction.
Definition: selectionmanager.h:75
SelectionManager::setMoveModeForAnchorInRange
void setMoveModeForAnchorInRange(const QPointF &point)
Checks if the point is over a handle (corner) or body and sets the MoveMode accordingly.
Definition: selectionmanager.cpp:112
SelectionManager::mapToSelection
QPointF mapToSelection(const QPointF &point) const
Maps a point from Canvas/Layer space INTO the Selection's transformed space.
Definition: selectionmanager.h:130
SelectionManager::setSelection
void setSelection(QRectF rect, bool roundPixels=false)
Defines the selection area.
Definition: selectionmanager.cpp:273
SelectionManager::adjustSelection
void adjustSelection(const QPointF &currentPoint, const QPointF &offset, qreal rotationOffset, int rotationIncrement=0)
Updates the selection transform (move, scale, rotate) based on input delta.
Definition: selectionmanager.cpp:150
SelectionManager::calculateSelectionTransformation
void calculateSelectionTransformation()
This should be called to update the selection transform.
Definition: selectionmanager.cpp:299
Status
Definition: pencilerror.h:40
VectorSelection
Definition: vectorselection.h:26
QList
QList::clear
void clear()
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QPointF
QPolygonF
QRectF
QRectF::isValid
bool isValid() const const
QTransform
QTransform::inverted
QTransform inverted(bool *invertible) const const
QTransform::map
QPoint map(const QPoint &point) const const
Generated on Tue Jan 6 2026 11:38:51 for Pencil2D by doxygen 1.9.6 based on revision f91a96748ec6712509b9b0ff47979db9c34d556f