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() const;
46 
47  void updatePolygons();
48  void updateTransformedSelection() { mTransformedSelection = mTempTransformedSelection; }
49 
50  QPointF whichAnchorPoint(QPointF currentPoint) const;
51  QPointF getTransformOffset() const { return mOffset; }
52  QPointF offsetFromAspectRatio(qreal offsetX, qreal offsetY) const;
53 
54  void flipSelection(bool flipVertical);
55 
56  void setSelection(QRectF rect, bool roundPixels=false);
57 
58  void translate(QPointF point);
59 
60  MoveMode getMoveModeForSelectionAnchor(const QPointF pos) const;
61  MoveMode validateMoveMode(const QPointF pos);
62  MoveMode getMoveMode() const { return mMoveMode; }
63  void setMoveMode(const MoveMode moveMode) { mMoveMode = moveMode; }
64 
65  bool somethingSelected() const { return mSomethingSelected; }
66 
67  void calculateSelectionTransformation();
68  void adjustSelection(const QPointF& currentPoint, qreal offsetX, qreal offsetY, qreal rotationOffset, int rotationIncrement);
69  MoveMode moveModeForAnchorInRange(const QPointF lastPos);
70  void setCurves(const QList<int>& curves) { mClosestCurves = curves; }
71  void setVertices(const QList<VertexRef>& vertices) { mClosestVertices = vertices; }
72 
73  void clearCurves();
74  void clearVertices();
75 
76  const QList<int> closestCurves() const { return mClosestCurves; }
77  const QList<VertexRef> closestVertices() const { return mClosestVertices; }
78 
79  QTransform selectionTransform() const { return mSelectionTransform; }
80  void setSelectionTransform(const QTransform& transform) { mSelectionTransform = transform; }
81  void resetSelectionTransform();
82 
83  bool transformHasBeenModified() const;
84  bool rotationHasBeenModified() const;
85 
91 
92  void resetSelectionProperties();
93  void deleteSelection();
94 
95  bool isOutsideSelectionArea(const QPointF point);
96 
97  qreal selectionTolerance() const;
98 
99 
100  QPolygonF currentSelectionPolygonF() const { return mCurrentSelectionPolygonF; }
101  QPolygonF lastSelectionPolygonF() const { return mLastSelectionPolygonF; }
102 
103  void setSomethingSelected(bool selected) { mSomethingSelected = selected; }
104 
105  VectorSelection vectorSelection;
106 
107  const QRectF& mySelectionRect() { return mSelection; }
108  const QRectF& myTempTransformedSelectionRect() { return mTempTransformedSelection; }
109  const QRectF& myTransformedSelectionRect() { return mTransformedSelection; }
110  const qreal& myRotation() { return mRotatedAngle; }
111 
112  void setSelectionRect(const QRectF& rect) { mSelection = rect; }
113  void setTempTransformedSelectionRect(const QRectF& rect) { mTempTransformedSelection = rect; }
114  void setTransformedSelectionRect(const QRectF& rect) { mTransformedSelection = rect; }
115  void setRotation(const qreal& rotation) { mRotatedAngle = rotation; }
116 
117 signals:
118  void selectionChanged();
119  void selectionReset();
120  void needPaintAndApply();
121  void needDeleteSelection();
122 
123 private:
124  int constrainRotationToAngle(const qreal rotatedAngle, const int rotationIncrement) const;
125 
126  QRectF mSelection;
127  QRectF mTempTransformedSelection;
128  QRectF mTransformedSelection;
129  qreal mRotatedAngle = 0.0;
130 
131  bool mSomethingSelected = false;
132  QPolygonF mLastSelectionPolygonF;
133  QPolygonF mCurrentSelectionPolygonF;
134  QPointF mOffset;
135 
136  QList<int> mClosestCurves;
137  QList<VertexRef> mClosestVertices;
138 
139  MoveMode mMoveMode = MoveMode::NONE;
140  QTransform mSelectionTransform;
141  const qreal mSelectionTolerance = 8.0;
142 };
143 
144 #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:38
Definition: object.h:41
void flipSelection(bool flipVertical)
ScribbleArea::flipSelection flip selection along the X or Y axis.
Definition: editor.h:55