Rev 23700 | Rev 24003 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20593 | jghali | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
7 | /*************************************************************************** |
||
8 | * * |
||
9 | * This program is free software; you can redistribute it and/or modify * |
||
10 | * it under the terms of the GNU General Public License as published by * |
||
11 | * the Free Software Foundation; either version 2 of the License, or * |
||
12 | * (at your option) any later version. * |
||
13 | * * |
||
14 | ***************************************************************************/ |
||
15 | /*************************************************************************** |
||
16 | canvasmode_editpolygon.cpp - description |
||
17 | ------------------- |
||
18 | begin : Wed Jan 12 2011 |
||
19 | copyright : (C) 2011 by Franz Schmid |
||
20 | email : Franz.Schmid@altmuehlnet.de |
||
21 | ***************************************************************************/ |
||
22 | |||
23 | |||
24 | #include "canvasmode_editpolygon.h" |
||
25 | |||
26 | #include <QApplication> |
||
27 | #include <QButtonGroup> |
||
28 | #include <QCheckBox> |
||
29 | #include <QCursor> |
||
30 | #include <QEvent> |
||
31 | #include <QMessageBox> |
||
32 | #include <QMouseEvent> |
||
33 | #include <QPainterPath> |
||
34 | #include <QPoint> |
||
35 | #include <QRect> |
||
36 | #include <QTimer> |
||
37 | #include <QWidgetAction> |
||
38 | #include <QDebug> |
||
39 | |||
40 | #include "appmodes.h" |
||
41 | #include "canvas.h" |
||
42 | #include "fpoint.h" |
||
43 | #include "fpointarray.h" |
||
44 | #include "pageitem_regularpolygon.h" |
||
45 | #include "prefscontext.h" |
||
46 | #include "prefsfile.h" |
||
47 | #include "prefsmanager.h" |
||
48 | #include "scribus.h" |
||
49 | #include "scribusXml.h" |
||
50 | #include "scribusdoc.h" |
||
51 | #include "scribusview.h" |
||
52 | #include "selection.h" |
||
53 | #include "ui/aligndistribute.h" |
||
54 | #include "ui/contextmenu.h" |
||
55 | #include "ui/pageselector.h" |
||
56 | #include "ui/polygonwidget.h" |
||
57 | #include "ui/propertiespalette.h" |
||
58 | #include "undomanager.h" |
||
59 | #include "units.h" |
||
60 | #include "util.h" |
||
61 | #include "util_math.h" |
||
62 | |||
63 | |||
23757 | craig | 64 | CanvasMode_EditPolygon::CanvasMode_EditPolygon(ScribusView* view) : |
65 | CanvasMode(view), |
||
66 | m_ScMW(view->m_ScMW) |
||
20593 | jghali | 67 | { |
68 | } |
||
69 | |||
70 | inline bool CanvasMode_EditPolygon::GetItem(PageItem** pi) |
||
71 | { |
||
72 | *pi = m_doc->m_Selection->itemAt(0); |
||
22519 | craig | 73 | return (*pi) != nullptr; |
20593 | jghali | 74 | } |
75 | |||
76 | void CanvasMode_EditPolygon::drawControls(QPainter* p) |
||
77 | { |
||
78 | p->save(); |
||
79 | if (m_canvas->m_viewMode.operItemMoving) |
||
80 | drawOutline(p); |
||
81 | else |
||
82 | drawSelection(p, false); |
||
83 | if (m_doc->appMode == modeEditPolygon) |
||
84 | drawControlsPolygon(p, m_doc->m_Selection->itemAt(0)); |
||
85 | p->restore(); |
||
86 | } |
||
87 | |||
88 | void CanvasMode_EditPolygon::drawControlsPolygon(QPainter* psx, PageItem* currItem) |
||
89 | { |
||
90 | QPen p1b = QPen(Qt::blue, 1.0 / m_canvas->m_viewMode.scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); |
||
91 | QPen p1bd = QPen(Qt::red, 1.0 / m_canvas->m_viewMode.scale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin); |
||
92 | QPen p8b = QPen(Qt::blue, 8.0 / m_canvas->m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin); |
||
93 | QPen p8r = QPen(Qt::red, 8.0 / m_canvas->m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin); |
||
94 | psx->setTransform(currItem->getTransform(), true); |
||
95 | psx->setPen(p1b); |
||
96 | psx->setBrush(Qt::NoBrush); |
||
97 | PageItem_RegularPolygon* item = currItem->asRegularPolygon(); |
||
23040 | jghali | 98 | QPainterPath path = regularPolygonPath(item->width(), item->height(), m_polyCorners, m_polyUseFactor, m_polyFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature); |
20593 | jghali | 99 | psx->drawPath(path); |
100 | psx->setPen(p1bd); |
||
101 | psx->drawLine(m_startPoint, m_endPoint); |
||
102 | if (m_polyUseFactor) |
||
103 | { |
||
104 | psx->drawLine(m_endPoint, m_innerCPoint); |
||
105 | psx->drawLine(m_startPoint, m_outerCPoint); |
||
106 | } |
||
107 | psx->setPen(p8b); |
||
108 | if (m_polygonPoint == useControlOuter) |
||
109 | psx->setPen(p8r); |
||
110 | else |
||
111 | psx->setPen(p8b); |
||
112 | psx->drawPoint(m_startPoint); |
||
113 | if (m_polygonPoint == useControlInner) |
||
114 | psx->setPen(p8r); |
||
115 | else |
||
116 | psx->setPen(p8b); |
||
117 | psx->drawPoint(m_endPoint); |
||
118 | if (m_polyUseFactor) |
||
119 | { |
||
120 | if (m_polygonPoint == useControlInnerCurve) |
||
121 | psx->setPen(p8r); |
||
122 | else |
||
123 | psx->setPen(p8b); |
||
124 | psx->drawPoint(m_innerCPoint); |
||
125 | if (m_polygonPoint == useControlOuterCurve) |
||
126 | psx->setPen(p8r); |
||
127 | else |
||
128 | psx->setPen(p8b); |
||
129 | psx->drawPoint(m_outerCPoint); |
||
130 | } |
||
131 | } |
||
132 | |||
23700 | craig | 133 | void CanvasMode_EditPolygon::enterEvent(QEvent *e) |
20593 | jghali | 134 | { |
135 | if (!m_canvas->m_viewMode.m_MouseButtonPressed) |
||
136 | setModeCursor(); |
||
137 | } |
||
138 | |||
139 | void CanvasMode_EditPolygon::leaveEvent(QEvent *e) |
||
140 | { |
||
141 | } |
||
142 | |||
143 | void CanvasMode_EditPolygon::updateFromItem() |
||
144 | { |
||
145 | if (updateFromItemBlocked()) |
||
146 | return; |
||
147 | PageItem *currItem = m_doc->m_Selection->itemAt(0); |
||
148 | PageItem_RegularPolygon* item = currItem->asRegularPolygon(); |
||
149 | m_centerPoint = QPointF(currItem->width() / 2.0, currItem->height() / 2.0); |
||
150 | m_startPoint = currItem->PoLine.pointQF(0); |
||
151 | m_endPoint = currItem->PoLine.pointQF(2); |
||
152 | m_polyCorners = item->polyCorners; |
||
153 | m_polyUseFactor = item->polyUseFactor; |
||
154 | m_polyFactor = item->polyFactor; |
||
155 | m_polyRotation = item->polyRotation; |
||
156 | m_polyCurvature = item->polyCurvature; |
||
157 | m_polyInnerRot = item->polyInnerRot; |
||
158 | m_polyOuterCurvature = item->polyOuterCurvature; |
||
159 | m_VectorDialog->polyWidget->blockSignals(true); |
||
160 | m_VectorDialog->setValues(m_polyCorners, m_polyFactor, m_polyUseFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature); |
||
161 | m_VectorDialog->polyWidget->blockSignals(false); |
||
162 | uint cx = m_polyUseFactor ? m_polyCorners * 2 : m_polyCorners; |
||
163 | double seg = 360.0 / cx; |
||
164 | double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (item->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (item->height() / 2.0) + (item->height()/2.0) - item->height(), 2)); |
||
165 | QLineF innerLine = QLineF(m_endPoint, m_centerPoint); |
||
166 | innerLine.setAngle(innerLine.angle() + 90); |
||
167 | innerLine.setLength(trueLength * m_polyCurvature); |
||
168 | m_innerCPoint = innerLine.p2(); |
||
169 | QLineF outerLine = QLineF(m_startPoint, currItem->PoLine.pointQF(6)); |
||
170 | outerLine.setLength(outerLine.length() * m_polyOuterCurvature); |
||
171 | m_outerCPoint = outerLine.p2(); |
||
172 | m_view->update(); |
||
173 | } |
||
174 | |||
175 | void CanvasMode_EditPolygon::activate(bool fromGesture) |
||
176 | { |
||
23613 | jghali | 177 | CanvasMode::activate(fromGesture); |
178 | |||
20593 | jghali | 179 | m_polygonPoint = noPointDefined; |
180 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
181 | m_canvas->resetRenderMode(); |
||
182 | m_doc->DragP = false; |
||
183 | m_doc->leaveDrag = false; |
||
184 | m_canvas->m_viewMode.operItemMoving = false; |
||
185 | m_canvas->m_viewMode.operItemResizing = false; |
||
186 | m_view->MidButt = false; |
||
187 | m_Mxp = m_Myp = -1; |
||
188 | PageItem *currItem = m_doc->m_Selection->itemAt(0); |
||
189 | PageItem_RegularPolygon* item = currItem->asRegularPolygon(); |
||
190 | m_centerPoint = QPointF(currItem->width() / 2.0, currItem->height() / 2.0); |
||
191 | m_startPoint = currItem->PoLine.pointQF(0); |
||
192 | m_endPoint = currItem->PoLine.pointQF(2); |
||
193 | m_polyCorners = item->polyCorners; |
||
194 | m_polyUseFactor = item->polyUseFactor; |
||
195 | m_polyFactor = item->polyFactor; |
||
196 | m_polyRotation = item->polyRotation; |
||
197 | m_polyCurvature = item->polyCurvature; |
||
198 | m_polyInnerRot = item->polyInnerRot; |
||
199 | m_polyOuterCurvature = item->polyOuterCurvature; |
||
200 | m_VectorDialog = new PolyVectorDialog(m_ScMW, m_polyCorners, m_polyFactor, m_polyUseFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature); |
||
201 | m_VectorDialog->show(); |
||
202 | uint cx = m_polyUseFactor ? m_polyCorners * 2 : m_polyCorners; |
||
203 | double seg = 360.0 / cx; |
||
204 | double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (item->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (item->height() / 2.0) + (item->height()/2.0) - item->height(), 2)); |
||
205 | QLineF innerLine = QLineF(m_endPoint, m_centerPoint); |
||
206 | innerLine.setAngle(innerLine.angle() + 90); |
||
207 | innerLine.setLength(trueLength * m_polyCurvature); |
||
208 | m_innerCPoint = innerLine.p2(); |
||
209 | QLineF outerLine = QLineF(m_startPoint, currItem->PoLine.pointQF(6)); |
||
210 | outerLine.setLength(outerLine.length() * m_polyOuterCurvature); |
||
211 | m_outerCPoint = outerLine.p2(); |
||
212 | setModeCursor(); |
||
213 | if (fromGesture) |
||
214 | m_view->update(); |
||
215 | connect(m_doc, SIGNAL(docChanged()), this, SLOT(updateFromItem())); |
||
216 | |||
217 | connect(m_VectorDialog, SIGNAL(NewVectors(int, double, bool, double, double, double, double)), this, SLOT(applyValues(int, double, bool, double, double, double, double))); |
||
218 | connect(m_VectorDialog, SIGNAL(endEdit()), this, SLOT(endEditing())); |
||
219 | connect(m_VectorDialog, SIGNAL(paletteShown(bool)), this, SLOT(endEditing(bool))); |
||
220 | } |
||
221 | |||
222 | void CanvasMode_EditPolygon::deactivate(bool forGesture) |
||
223 | { |
||
224 | disconnect(m_VectorDialog, SIGNAL(paletteShown(bool)), this, SLOT(endEditing(bool))); |
||
225 | m_VectorDialog->close(); |
||
226 | m_VectorDialog->deleteLater(); |
||
227 | m_view->setRedrawMarkerShown(false); |
||
228 | m_polygonPoint = noPointDefined; |
||
229 | disconnect(m_doc, SIGNAL(docChanged()), this, SLOT(updateFromItem())); |
||
23613 | jghali | 230 | |
231 | CanvasMode::deactivate(forGesture); |
||
20593 | jghali | 232 | } |
233 | |||
234 | void CanvasMode_EditPolygon::endEditing(bool active) |
||
235 | { |
||
236 | if (!active) |
||
237 | endEditing(); |
||
238 | } |
||
239 | |||
240 | void CanvasMode_EditPolygon::endEditing() |
||
241 | { |
||
242 | m_view->requestMode(modeNormal); |
||
243 | } |
||
244 | |||
245 | void CanvasMode_EditPolygon::applyValues(int polyC, double polyF, bool polyUseCF, double polyR, double polyCur, double polyIRot, double polyOCur) |
||
246 | { |
||
247 | PageItem *currItem = m_doc->m_Selection->itemAt(0); |
||
248 | PageItem_RegularPolygon* item = currItem->asRegularPolygon(); |
||
249 | QRectF oldRect = item->getBoundingRect(); |
||
250 | m_polyCorners = polyC; |
||
251 | m_polyFactor = polyF; |
||
252 | m_polyRotation = polyR; |
||
253 | m_polyCurvature = polyCur; |
||
254 | m_polyInnerRot = polyIRot; |
||
255 | m_polyOuterCurvature = polyOCur; |
||
256 | if (UndoManager::undoEnabled()) |
||
257 | { |
||
258 | SimpleState *ss = new SimpleState(Um::EditPolygon,"",Um::IPolygon); |
||
20799 | jghali | 259 | ss->set("POLYGON"); |
20593 | jghali | 260 | ss->set("NEW_CORNER",polyC); |
261 | ss->set("NEW_USEFACTOR",polyUseCF); |
||
262 | ss->set("NEW_FACTOR",m_polyFactor); |
||
263 | ss->set("NEW_ROTATION",m_polyRotation); |
||
264 | ss->set("NEW_CURV",m_polyCurvature); |
||
265 | ss->set("NEW_INNER",m_polyInnerRot); |
||
266 | ss->set("NEW_OUTER",m_polyOuterCurvature); |
||
267 | ss->set("OLD_CORNER",item->polyCorners); |
||
268 | ss->set("OLD_USEFACTOR",item->polyUseFactor); |
||
269 | ss->set("OLD_FACTOR",item->polyFactor); |
||
270 | ss->set("OLD_ROTATION",item->polyRotation); |
||
271 | ss->set("OLD_CURV",item->polyCurvature); |
||
272 | ss->set("OLD_INNER",item->polyInnerRot); |
||
273 | ss->set("OLD_OUTER",item->polyOuterCurvature); |
||
274 | undoManager->action(currItem,ss); |
||
275 | } |
||
276 | item->polyCorners = polyC; |
||
277 | item->polyUseFactor = polyUseCF; |
||
278 | item->polyFactor = m_polyFactor; |
||
279 | item->polyRotation = m_polyRotation; |
||
280 | item->polyCurvature = m_polyCurvature; |
||
281 | item->polyInnerRot = m_polyInnerRot; |
||
282 | item->polyOuterCurvature = m_polyOuterCurvature; |
||
283 | item->recalcPath(); |
||
284 | updateFromItem(); |
||
285 | QTransform itemMatrix = currItem->getTransform(); |
||
23040 | jghali | 286 | QPainterPath path = itemMatrix.map(regularPolygonPath(item->width(), item->height(), m_polyCorners, m_polyUseFactor, m_polyFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature)); |
20593 | jghali | 287 | QRectF updateRect = oldRect.united(path.boundingRect()); |
288 | m_doc->regionsChanged()->update(updateRect.adjusted(-5, -5, 10, 10)); |
||
289 | } |
||
290 | |||
291 | double CanvasMode_EditPolygon::getUserValFromFactor(double factor) |
||
292 | { |
||
293 | double userVal = 0.0; |
||
294 | double mi = GetZeroFactor(); |
||
295 | double ma = GetMaxFactor(); |
||
296 | if ((factor / mi * 100.0 - 100.0) > 0) |
||
297 | userVal = (factor - mi) / (ma - mi) * 100.0; |
||
298 | else |
||
299 | userVal = factor / mi * 100.0 - 100.0; |
||
300 | return userVal; |
||
301 | } |
||
302 | |||
303 | double CanvasMode_EditPolygon::GetZeroFactor() |
||
304 | { |
||
305 | return sqrt(pow(1.0,2.0)-pow(((sin((360.0/(m_polyCorners*2))/180* M_PI)* 2.0)/2.0),2.0)); |
||
306 | } |
||
307 | |||
308 | double CanvasMode_EditPolygon::GetMaxFactor() |
||
309 | { |
||
310 | double win = (360.0/(m_polyCorners*2)) / 180.0 * M_PI; |
||
311 | double ret; |
||
312 | if ((360.0/(m_polyCorners*2)) > 45) |
||
313 | ret = 1/sin(win); |
||
314 | else |
||
315 | ret = 1/cos(win); |
||
316 | return ret; |
||
317 | } |
||
318 | |||
319 | void CanvasMode_EditPolygon::mouseDoubleClickEvent(QMouseEvent *m) |
||
320 | { |
||
321 | m->accept(); |
||
322 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
323 | m_canvas->resetRenderMode(); |
||
324 | m_view->requestMode(modeNormal); |
||
325 | } |
||
326 | |||
327 | void CanvasMode_EditPolygon::mouseMoveEvent(QMouseEvent *m) |
||
328 | { |
||
329 | const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
||
330 | m->accept(); |
||
331 | double newX = mousePointDoc.x(); |
||
332 | double newY = mousePointDoc.y(); |
||
333 | if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed()) |
||
334 | { |
||
335 | PageItem *currItem = m_doc->m_Selection->itemAt(0); |
||
336 | QTransform itemMatrix = currItem->getTransform(); |
||
337 | QPointF cPoint = itemMatrix.map(m_centerPoint); |
||
338 | QLineF stLinA = QLineF(cPoint, QPointF(newX, newY)); |
||
339 | |||
340 | uint cx = m_polyUseFactor ? m_polyCorners * 2 : m_polyCorners; |
||
341 | double seg = 360.0 / cx; |
||
342 | double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (currItem->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (currItem->height() / 2.0) + (currItem->height()/2.0) - currItem->height(), 2)); |
||
343 | |||
344 | if (m_polygonPoint == useControlInner) |
||
345 | { |
||
346 | m_polyInnerRot = stLinA.angle() - 90 - m_polyRotation - seg; |
||
347 | double factor = stLinA.length() / sqrt(pow(sin(stLinA.angle() * M_PI / 180.0) * currItem->height() / 2.0, 2) + pow(cos(stLinA.angle() * M_PI / 180.0) * currItem->width() / 2.0, 2)); |
||
348 | int maxF = qRound(getUserValFromFactor(factor)); |
||
349 | if (maxF <= 100) |
||
350 | m_polyFactor = factor; |
||
351 | } |
||
352 | if (m_polygonPoint == useControlOuter) |
||
353 | { |
||
354 | m_polyRotation = stLinA.angle() - 90; |
||
355 | if (m_polyRotation < -180) |
||
356 | m_polyRotation += 360; |
||
357 | if (m_polyRotation > 180) |
||
358 | m_polyRotation -= 360; |
||
359 | } |
||
360 | if (m_polygonPoint == useControlInnerCurve) |
||
361 | { |
||
362 | QPointF ePoint = itemMatrix.map(m_endPoint); |
||
363 | QLineF stLinC = QLineF(ePoint, QPointF(newX, newY)); |
||
364 | m_polyCurvature = stLinC.length() / trueLength; |
||
365 | } |
||
366 | if (m_polygonPoint == useControlOuterCurve) |
||
367 | { |
||
368 | QPointF sPoint = itemMatrix.map(m_startPoint); |
||
369 | QPointF sPoint2 = itemMatrix.map(currItem->PoLine.pointQF(6)); |
||
370 | QLineF stLinCo = QLineF(sPoint, QPointF(newX, newY)); |
||
371 | QLineF stLinCo2 = QLineF(sPoint, sPoint2); |
||
372 | m_polyOuterCurvature = stLinCo.length() / stLinCo2.length(); |
||
373 | } |
||
23040 | jghali | 374 | QPainterPath path = regularPolygonPath(currItem->width(), currItem->height(), m_polyCorners, m_polyUseFactor, m_polyFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature); |
20593 | jghali | 375 | FPointArray ar; |
376 | ar.fromQPainterPath(path); |
||
377 | m_endPoint = ar.pointQF(2); |
||
378 | m_startPoint = ar.pointQF(0); |
||
379 | QLineF innerLine = QLineF(m_endPoint, m_centerPoint); |
||
380 | innerLine.setAngle(innerLine.angle() + 90); |
||
381 | innerLine.setLength(trueLength * m_polyCurvature); |
||
382 | m_innerCPoint = innerLine.p2(); |
||
383 | QLineF outerLine = QLineF(m_startPoint, ar.pointQF(6)); |
||
384 | outerLine.setLength(outerLine.length() * m_polyOuterCurvature); |
||
385 | m_outerCPoint = outerLine.p2(); |
||
386 | m_VectorDialog->setValues(m_polyCorners, m_polyFactor, m_polyUseFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature); |
||
387 | blockUpdateFromItem(true); |
||
388 | currItem->update(); |
||
389 | blockUpdateFromItem(false); |
||
390 | path = itemMatrix.map(path); |
||
391 | m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10)); |
||
392 | } |
||
393 | m_Mxp = newX; |
||
394 | m_Myp = newY; |
||
395 | } |
||
396 | |||
397 | void CanvasMode_EditPolygon::mousePressEvent(QMouseEvent *m) |
||
398 | { |
||
399 | const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
||
400 | |||
401 | m_canvas->PaintSizeRect(QRect()); |
||
402 | m_canvas->m_viewMode.m_MouseButtonPressed = true; |
||
403 | m_canvas->m_viewMode.operItemMoving = false; |
||
404 | m_view->HaveSelRect = false; |
||
405 | m_doc->DragP = false; |
||
406 | m_doc->leaveDrag = false; |
||
407 | m->accept(); |
||
408 | m_view->registerMousePress(m->globalPos()); |
||
409 | m_Mxp = mousePointDoc.x(); //m->x(); |
||
410 | m_Myp = mousePointDoc.y(); //m->y(); |
||
411 | if (m->button() == Qt::MidButton) |
||
412 | { |
||
413 | m_view->MidButt = true; |
||
414 | if (m->modifiers() & Qt::ControlModifier) |
||
415 | m_view->DrawNew(); |
||
416 | return; |
||
417 | } |
||
418 | PageItem *currItem = m_doc->m_Selection->itemAt(0); |
||
419 | QTransform itemMatrix = currItem->getTransform(); |
||
420 | QPointF stPoint = m_startPoint; |
||
421 | stPoint = itemMatrix.map(stPoint); |
||
422 | QPointF swPoint = m_endPoint; |
||
423 | swPoint = itemMatrix.map(swPoint); |
||
424 | QPointF shPoint = m_innerCPoint; |
||
425 | shPoint = itemMatrix.map(shPoint); |
||
426 | QPointF sPoint = m_outerCPoint; |
||
427 | sPoint = itemMatrix.map(sPoint); |
||
428 | bool useOuter = m_canvas->hitsCanvasPoint(m->globalPos(), stPoint); |
||
429 | bool useInner = m_canvas->hitsCanvasPoint(m->globalPos(), swPoint); |
||
430 | bool useInnerC = m_canvas->hitsCanvasPoint(m->globalPos(), shPoint); |
||
431 | bool useOuterC = m_canvas->hitsCanvasPoint(m->globalPos(), sPoint); |
||
432 | if (useOuter && useOuterC) |
||
433 | { |
||
434 | if (m->modifiers() == Qt::ShiftModifier) |
||
435 | m_polygonPoint = useControlOuterCurve; |
||
436 | else |
||
437 | m_polygonPoint = useControlOuter; |
||
438 | } |
||
439 | else if (useOuter || useOuterC) |
||
440 | { |
||
441 | if (useOuterC) |
||
442 | m_polygonPoint = useControlOuterCurve; |
||
443 | else |
||
444 | m_polygonPoint = useControlOuter; |
||
445 | } |
||
446 | else if (useInner && useInnerC) |
||
447 | { |
||
448 | if (m->modifiers() == Qt::ShiftModifier) |
||
449 | m_polygonPoint = useControlInnerCurve; |
||
450 | else |
||
451 | m_polygonPoint = useControlInner; |
||
452 | } |
||
453 | else if (useInner || useInnerC) |
||
454 | { |
||
455 | if (useInnerC) |
||
456 | m_polygonPoint = useControlInnerCurve; |
||
457 | else |
||
458 | m_polygonPoint = useControlInner; |
||
459 | } |
||
460 | else |
||
461 | m_polygonPoint = noPointDefined; |
||
462 | if (m_polygonPoint != noPointDefined && UndoManager::undoEnabled()) |
||
463 | m_transaction = undoManager->beginTransaction(Um::Polygon, Um::IPolygon, Um::EditPolygon, "", Um::IPolygon); |
||
464 | m_view->setCursor(QCursor(Qt::CrossCursor)); |
||
23040 | jghali | 465 | QPainterPath path = itemMatrix.map(regularPolygonPath(currItem->width(), currItem->height(), m_polyCorners, m_polyUseFactor, m_polyFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature)); |
20593 | jghali | 466 | m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10)); |
467 | } |
||
468 | |||
469 | void CanvasMode_EditPolygon::mouseReleaseEvent(QMouseEvent *m) |
||
470 | { |
||
471 | const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); |
||
472 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
473 | m_canvas->resetRenderMode(); |
||
474 | m->accept(); |
||
475 | PageItem *currItem = m_doc->m_Selection->itemAt(0); |
||
476 | PageItem_RegularPolygon* item = currItem->asRegularPolygon(); |
||
477 | QTransform itemMatrix = currItem->getTransform(); |
||
478 | if ((m_polygonPoint == useControlInner) || (m_polygonPoint == useControlOuter) || (m_polygonPoint == useControlInnerCurve) || (m_polygonPoint == useControlOuterCurve)) |
||
479 | { |
||
480 | double newX = mousePointDoc.x(); |
||
481 | double newY = mousePointDoc.y(); |
||
482 | QPointF cPoint = itemMatrix.map(m_centerPoint); |
||
483 | QLineF stLinA = QLineF(cPoint, QPointF(newX, newY)); |
||
484 | uint cx = m_polyUseFactor ? m_polyCorners * 2 : m_polyCorners; |
||
485 | double seg = 360.0 / cx; |
||
486 | double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (currItem->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (currItem->height() / 2.0) + (currItem->height()/2.0) - currItem->height(), 2)); |
||
487 | if (m_polygonPoint == useControlInner) |
||
488 | { |
||
489 | m_polyInnerRot = stLinA.angle() - 90 - m_polyRotation - seg; |
||
490 | m_polyFactor = stLinA.length() / sqrt(pow(sin(stLinA.angle() * M_PI / 180.0) * currItem->height() / 2.0, 2) + pow(cos(stLinA.angle() * M_PI / 180.0) * currItem->width() / 2.0, 2)); |
||
491 | } |
||
492 | if (m_polygonPoint == useControlOuter) |
||
493 | m_polyRotation = stLinA.angle() - 90; |
||
494 | if (m_polygonPoint == useControlInnerCurve) |
||
495 | { |
||
496 | QPointF ePoint = itemMatrix.map(m_endPoint); |
||
497 | QLineF stLinC = QLineF(ePoint, QPointF(newX, newY)); |
||
498 | m_polyCurvature = stLinC.length() / trueLength; |
||
499 | } |
||
500 | if (m_polygonPoint == useControlOuterCurve) |
||
501 | { |
||
502 | QPointF sPoint = itemMatrix.map(m_startPoint); |
||
503 | QPointF sPoint2 = itemMatrix.map(currItem->PoLine.pointQF(6)); |
||
504 | QLineF stLinCo = QLineF(sPoint, QPointF(newX, newY)); |
||
505 | QLineF stLinCo2 = QLineF(sPoint, sPoint2); |
||
506 | m_polyOuterCurvature = stLinCo.length() / stLinCo2.length(); |
||
507 | } |
||
508 | item->polyFactor = m_polyFactor; |
||
509 | item->polyRotation = m_polyRotation; |
||
510 | item->polyCurvature = m_polyCurvature; |
||
511 | item->polyInnerRot = m_polyInnerRot; |
||
512 | item->polyOuterCurvature = m_polyOuterCurvature; |
||
513 | item->recalcPath(); |
||
514 | m_VectorDialog->setValues(m_polyCorners, m_polyFactor, m_polyUseFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature); |
||
515 | if (m_transaction) |
||
516 | { |
||
517 | m_transaction.commit(); |
||
518 | m_transaction.reset(); |
||
519 | } |
||
520 | } |
||
23040 | jghali | 521 | QPainterPath path = itemMatrix.map(regularPolygonPath(item->width(), item->height(), m_polyCorners, m_polyUseFactor, m_polyFactor, m_polyRotation, m_polyCurvature, m_polyInnerRot, m_polyOuterCurvature)); |
20593 | jghali | 522 | m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10)); |
523 | } |