All Classes Namespaces Functions Variables Enumerations Properties Pages
overlaymanager.cpp
1 #include "editor.h"
2 #include "scribblearea.h"
3 #include "overlaymanager.h"
4 #include "overlaypainter.h"
5 
6 OverlayManager::OverlayManager(Editor *editor): BaseManager(editor, __FUNCTION__)
7 {
8  mEditor = editor;
9 }
10 
11 OverlayManager::~OverlayManager()
12 {
13 }
14 
15 bool OverlayManager::init()
16 {
17  mActivePerspOverlays.clear();
18  return true;
19 }
20 
21 Status OverlayManager::load(Object*)
22 {
23  return Status::OK;
24 }
25 
26 Status OverlayManager::save(Object*)
27 {
28  return Status::OK;
29 }
30 
31 void OverlayManager::workingLayerChanged(Layer *)
32 {
33 }
34 
35 MoveMode OverlayManager::getMoveModeForOverlayAnchor(const QPointF& pos)
36 {
37  const double calculatedSelectionTol = selectionTolerance();
38  MoveMode mode = MoveMode::NONE;
39 
40  if (QLineF(pos, op.getSinglePoint()).length() < calculatedSelectionTol)
41  {
42  mode = MoveMode::PERSP_SINGLE;
43  }
44  else if (QLineF(pos, op.getLeftPoint()).length() < calculatedSelectionTol)
45  {
46  mode = MoveMode::PERSP_LEFT;
47  }
48  else if (QLineF(pos, op.getRightPoint()).length() < calculatedSelectionTol)
49  {
50  mode = MoveMode::PERSP_RIGHT;
51  }
52  else if (QLineF(pos, op.getMiddlePoint()).length() < calculatedSelectionTol)
53  {
54  mode = MoveMode::PERSP_MIDDLE;
55  }
56 
57  return mode;
58 }
59 
60 double OverlayManager::selectionTolerance()
61 {
62  return qAbs(mSelectionTolerance * mEditor->viewScaleInversed());
63 }
64 
65 // Must only be called at startup!
66 void OverlayManager::initPerspOverlay()
67 {
68  setSinglePerspPoint(QPointF(0.1, 0.1));
69  setLeftPerspPoint(QPointF(-300.0, 0.0));
70  setRightPerspPoint(QPointF(300.0, 0.0));
71  setMiddlePerspPoint(QPointF(0.0, 200.0));
72 }
73 
74 void OverlayManager::updatePerspOverlay(int persp)
75 {
76  switch (persp) {
77  case 1:
78  setMoveMode(MoveMode::PERSP_SINGLE);
79  break;
80  case 2:
81  setMoveMode(MoveMode::PERSP_LEFT);
82  break;
83  case 3:
84  setMoveMode(MoveMode::PERSP_LEFT);
85  break;
86  default:
87  break;
88  }
89 
90  mEditor->getScribbleArea()->prepOverlays();
91  mEditor->getScribbleArea()->renderOverlays();
92 }
93 
94 void OverlayManager::updatePerspOverlay(const QPointF& point)
95 {
96  MoveMode mode = op.getMoveMode();
97 
98  switch (mode) {
99  case MoveMode::PERSP_SINGLE:
100  setSinglePerspPoint(point);
101  break;
102  case MoveMode::PERSP_LEFT:
103  setLeftPerspPoint(point);
104  setRightPerspPoint(QPointF(op.getRightPoint().x(), point.y()));
105  break;
106  case MoveMode::PERSP_RIGHT:
107  setRightPerspPoint(point);
108  setLeftPerspPoint(QPointF(op.getLeftPoint().x(), point.y()));
109  break;
110  case MoveMode::PERSP_MIDDLE:
111  setMiddlePerspPoint(point);
112  break;
113  default:
114  break;
115  }
116  mEditor->getScribbleArea()->prepOverlays();
117  mEditor->getScribbleArea()->renderOverlays();
118 }
119 
120 void OverlayManager::setOverlayCenter(bool b)
121 {
122  if (b != mOverlayCenter)
123  mOverlayCenter = b;
124 }
125 
126 void OverlayManager::setOverlayThirds(bool b)
127 {
128  if (b != mOverlayThirds)
129  mOverlayThirds = b;
130 }
131 
132 void OverlayManager::setOverlayGoldenRatio(bool b)
133 {
134  if (b != mOverlayGoldenRatio)
135  mOverlayGoldenRatio = b;
136 }
137 
138 void OverlayManager::setOverlaySafeAreas(bool b)
139 {
140  if (b != mOverlaySafeAreas)
141  mOverlaySafeAreas = b;
142 }
143 
144 void OverlayManager::setOverlayPerspective1(bool b)
145 {
146  if (b != mOverlayPerspective1)
147  {
148  mOverlayPerspective1 = b;
149  updatePerspOverlayActiveList();
150  }
151 }
152 
153 void OverlayManager::setOverlayPerspective2(bool b)
154 {
155  if (b != mOverlayPerspective2)
156  {
157  mOverlayPerspective2 = b;
158  updatePerspOverlayActiveList();
159  }
160 }
161 
162 void OverlayManager::setOverlayPerspective3(bool b)
163 {
164  if (b != mOverlayPerspective3)
165  {
166  mOverlayPerspective3 = b;
167  updatePerspOverlayActiveList();
168  }
169 }
170 
171 void OverlayManager::setMoveMode(MoveMode mode)
172 {
173  op.setMoveMode(mode);
174 
175  switch (mode) {
176  case MoveMode::PERSP_LEFT:
177  mLastRightPoint = op.getRightPoint();
178  mLastMiddlePoint = op.getMiddlePoint();
179  break;
180  case MoveMode::PERSP_RIGHT:
181  mLastLeftPoint = op.getLeftPoint();
182  mLastMiddlePoint = op.getMiddlePoint();
183  break;
184  case MoveMode::PERSP_MIDDLE:
185  mLastRightPoint = op.getRightPoint();
186  mLastLeftPoint = op.getLeftPoint();
187  break;
188  default:
189  break;
190  }
191 }
192 
193 void OverlayManager::setSinglePerspPoint(QPointF point)
194 {
195  op.setSinglePoint(point.toPoint());
196 }
197 
198 QPointF OverlayManager::getSinglePerspPoint() const
199 {
200  return op.getSinglePoint();
201 }
202 
203 void OverlayManager::setLeftPerspPoint(QPointF point)
204 {
205  op.setLeftPoint(point.toPoint());
206 }
207 
208 QPointF OverlayManager::getLeftPerspPoint() const
209 {
210  return op.getLeftPoint();
211 }
212 
213 void OverlayManager::setRightPerspPoint(QPointF point)
214 {
215  op.setRightPoint(point.toPoint());
216 }
217 
218 QPointF OverlayManager::getRightPerspPoint() const
219 {
220  return op.getRightPoint();
221 }
222 
223 void OverlayManager::setMiddlePerspPoint(QPointF point)
224 {
225  op.setMiddlePoint(point.toPoint());
226 }
227 
228 QPointF OverlayManager::getMiddlePerspPoint() const
229 {
230  return op.getMiddlePoint();
231 }
232 
233 void OverlayManager::updatePerspOverlayActiveList()
234 {
235  mActivePerspOverlays.clear();
236  if (mOverlayPerspective1)
237  mActivePerspOverlays.append(1);
238  if (mOverlayPerspective2)
239  mActivePerspOverlays.append(2);
240  if (mOverlayPerspective3)
241  mActivePerspOverlays.append(3);
242 }
void clear()
int x() const const
qreal y() const const
void append(const T &value)
Definition: layer.h:38
QPoint toPoint() const const
Definition: object.h:41
Definition: editor.h:55