All Classes Namespaces Functions Variables Enumerations Properties Pages
selectionmanager.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #ifndef SELECTIONMANAGER_H
18 #define SELECTIONMANAGER_H
19 
20 #include "pencildef.h"
21 #include "basemanager.h"
22 #include "movemode.h"
23 #include "vertexref.h"
24 #include "vectorselection.h"
25 
26 #include <QPointF>
27 #include <QRectF>
28 #include <QPolygonF>
29 #include <QTransform>
30 
31 class Editor;
32 
34 {
35  Q_OBJECT
36 public:
37  explicit SelectionManager(Editor* editor);
38  ~SelectionManager() override;
39 
40  bool init() override;
41  Status load(Object*) override;
42  Status save(Object*) override;
43  void workingLayerChanged(Layer*) override;
44 
45  QVector<QPointF> calcSelectionCenterPoints();
46 
47  void updatePolygons();
48  void updateTransformedSelection() { mTransformedSelection = mTempTransformedSelection; }
49 
50  QRectF mappedSelection();
51 
52  QPointF whichAnchorPoint(QPointF currentPoint);
53  QPointF getTransformOffset() { return mOffset; }
54  QPointF offsetFromAspectRatio(qreal offsetX, qreal offsetY);
55 
56  void flipSelection(bool flipVertical);
57 
58  void setSelection(QRectF rect, bool roundPixels=false);
59 
60  void translate(QPointF point);
61 
62  MoveMode getMoveModeForSelectionAnchor(QPointF pos);
63  MoveMode validateMoveMode(QPointF pos);
64  MoveMode getMoveMode() const { return mMoveMode; }
65  void setMoveMode(MoveMode moveMode) { mMoveMode = moveMode; }
66 
67  bool somethingSelected() const { return mSomethingSelected; }
68 
69  void calculateSelectionTransformation();
70  void adjustSelection(const QPointF& currentPoint, qreal offsetX, qreal offsetY, qreal rotationOffset, int rotationIncrement=0);
71  MoveMode moveModeForAnchorInRange(QPointF lastPos);
72  void setCurves(QList<int> curves) { mClosestCurves = curves; }
73  void setVertices(QList<VertexRef> vertices) { mClosestVertices = vertices; }
74 
75  void clearCurves();
76  void clearVertices();
77 
78  const QList<int> closestCurves() { return mClosestCurves; }
79  const QList<VertexRef> closestVertices() { return mClosestVertices; }
80 
81  QTransform selectionTransform() { return mSelectionTransform; }
82  void setSelectionTransform(QTransform transform) { mSelectionTransform = transform; }
83  void resetSelectionTransform();
84 
85  bool transformHasBeenModified();
86  bool rotationHasBeenModified();
87 
93 
94  void resetSelectionProperties();
95  void deleteSelection();
96 
97  bool isOutsideSelectionArea(QPointF point);
98 
99  qreal selectionTolerance() const;
100 
101 
102  QPolygonF currentSelectionPolygonF() const { return mCurrentSelectionPolygonF; }
103  QPolygonF lastSelectionPolygonF() const { return mLastSelectionPolygonF; }
104 
105  void setSomethingSelected(bool selected) { mSomethingSelected = selected; }
106 
107  VectorSelection vectorSelection;
108 
109  const QRectF& mySelectionRect() { return mSelection; }
110  const QRectF& myTempTransformedSelectionRect() { return mTempTransformedSelection; }
111  const QRectF& myTransformedSelectionRect() { return mTransformedSelection; }
112  const qreal& myRotation() { return mRotatedAngle; }
113 
114  void setSelectionRect(const QRectF& rect) { mSelection = rect; }
115  void setTempTransformedSelectionRect(const QRectF& rect) { mTempTransformedSelection = rect; }
116  void setTransformedSelectionRect(const QRectF& rect) { mTransformedSelection = rect; }
117  void setRotation(const qreal& rotation) { mRotatedAngle = rotation; }
118 
119 
120 signals:
121  void selectionChanged();
122  void needPaintAndApply();
123  void needDeleteSelection();
124 
125 private:
126  int constrainRotationToAngle(const qreal& rotatedAngle, const int& rotationIncrement) const;
127 
128  QRectF mSelection;
129  QRectF mTempTransformedSelection;
130  QRectF mTransformedSelection;
131  qreal mRotatedAngle = 0.0;
132 
133  bool mSomethingSelected = false;
134  QPolygonF mLastSelectionPolygonF;
135  QPolygonF mCurrentSelectionPolygonF;
136  QPointF mOffset;
137 
138  QList<int> mClosestCurves;
139  QList<VertexRef> mClosestVertices;
140 
141  MoveMode mMoveMode = MoveMode::NONE;
142  QTransform mSelectionTransform;
143  const qreal mSelectionTolerance = 8.0;
144 };
145 
146 #endif // SELECTIONMANAGER_H
void resetSelectionTransformProperties()
SelectionManager::resetSelectionTransformProperties should be used whenever translate, rotate, transform, scale has been applied to a selection, but don't want to reset size nor position.
Q_OBJECTQ_OBJECT
Definition: layer.h:39
Definition: object.h:54
void flipSelection(bool flipVertical)
ScribbleArea::flipSelection flip selection along the X or Y axis.
Definition: editor.h:51