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
32class SelectionManager : public BaseManager
33{
34 Q_OBJECT
35public:
36 explicit SelectionManager(Editor* editor);
37 ~SelectionManager() override;
38
39 bool init() override;
40 Status load(Object*) override;
41 Status save(Object*) override;
42 void workingLayerChanged(Layer*) override;
43
44 void flipSelection(bool flipVertical);
45
46 void setSelection(QRectF rect, bool roundPixels=false);
47
48 void translate(QPointF point);
49 void rotate(qreal angle, qreal lockedAngle);
50 void scale(qreal sX, qreal sY);
51 void maintainAspectRatio(bool state) { mAspectRatioFixed = state; }
52
55 void alignPositionToAxis(bool state) { mLockAxis = state; }
56
57 void setMoveModeForAnchorInRange(const QPointF& point);
58 MoveMode getMoveMode() const { return mMoveMode; }
59 void setMoveMode(const MoveMode moveMode) { mMoveMode = moveMode; }
60
61 bool somethingSelected() const { return mOriginalRect.isValid(); }
62
63 void adjustSelection(const QPointF& currentPoint, const QPointF& offset, qreal rotationOffset, int rotationIncrement = 0);
64
65 QTransform selectionTransform() const { return mSelectionTransform; }
66 void setSelectionTransform(const QTransform& transform) { mSelectionTransform = transform; }
67 void resetSelectionTransform();
68
73 void resetSelectionTransformProperties();
74
75 void resetSelectionProperties();
76 void deleteSelection();
77
78 bool isOutsideSelectionArea(const QPointF& point) const;
79
80 qreal selectionTolerance() const;
81
82 qreal selectionWidth() const { return (mSelectionPolygon[1] - mSelectionPolygon[0]).x(); }
83 qreal selectionHeight() const { return (mSelectionPolygon[3] - mSelectionPolygon[0]).y(); }
84
85 QPointF currentTransformAnchor() const { return mAnchorPoint; }
86 QPointF getSelectionAnchorPoint() const;
87
88 void setTransformAnchor(const QPointF& point);
89
90 const QRectF& mySelectionRect() const { return mOriginalRect; }
91 const qreal& myRotation() const { return mRotatedAngle; }
92 const qreal& myScaleX() const { return mScaleX; }
93 const qreal& myScaleY() const { return mScaleY; }
94 const QPointF& myTranslation() const { return mTranslation; }
95
96 void setRotation(const qreal& rotation) { mRotatedAngle = rotation; }
97 void setScale(const qreal scaleX, const qreal scaleY) { mScaleX = scaleX; mScaleY = scaleY; }
98 void setTranslation(const QPointF& translation) { mTranslation = translation; }
99
100 qreal angleFromPoint(const QPointF& point, const QPointF& anchorPoint) const;
101
102 QPointF mapToSelection(const QPointF& point) const { return mSelectionTransform.map(point); };
103 QPointF mapFromLocalSpace(const QPointF& point) const { return mSelectionTransform.inverted().map(point); }
104 QPolygonF mapToSelection(const QPolygonF& polygon) const { return mSelectionTransform.map(polygon); }
105 QPolygonF mapFromLocalSpace(const QPolygonF& polygon) const { return mSelectionTransform.inverted().map(polygon); }
106
107 // Vector selection
108 VectorSelection vectorSelection;
109
110 void setCurves(const QList<int>& curves) { mClosestCurves = curves; }
111 void setVertices(const QList<VertexRef>& vertices) { mClosestVertices = vertices; }
112
113 void clearCurves() { mClosestCurves.clear(); };
114 void clearVertices() { mClosestVertices.clear(); };
115
118 void setDragOrigin(const QPointF point) { mDragOrigin = point; }
119
120 const QList<int> closestCurves() const { return mClosestCurves; }
121 const QList<VertexRef> closestVertices() const { return mClosestVertices; }
122
124 void calculateSelectionTransformation();
125
126signals:
127 void selectionChanged();
128 void selectionReset();
129 void needDeleteSelection();
130
131private:
137 QPointF alignPositionToAxis(QPointF currentPoint) const;
138 int constrainRotationToAngle(const qreal rotatedAngle, const int rotationIncrement) const;
139
140 bool mAspectRatioFixed = false;
141 bool mLockAxis = false;
142 QPolygonF mSelectionPolygon;
143 QRectF mOriginalRect;
144
145 qreal mScaleX;
146 qreal mScaleY;
147 QPointF mTranslation;
148 qreal mRotatedAngle = 0.0;
149
150 QList<int> mClosestCurves;
151 QList<VertexRef> mClosestVertices;
152
153 QPointF mDragOrigin;
154
155 MoveMode mMoveMode = MoveMode::NONE;
156 QTransform mSelectionTransform;
157 const qreal mSelectionTolerance = 10.0;
158
159 QPointF mAnchorPoint;
160};
161
162#endif // SELECTIONMANAGER_H
BaseManager
Definition: basemanager.h:29
Editor
Definition: editor.h:71
Layer
Definition: layer.h:33
Object
Definition: object.h:42
SelectionManager
Definition: selectionmanager.h:33
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:118
SelectionManager::alignPositionToAxis
void alignPositionToAxis(bool state)
Locks movement either horizontally or vertically depending on drag direction.
Definition: selectionmanager.h:55
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 Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39