Rev 19454 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10532 | avox | 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 | #include "canvasmode_nodeedit.h" |
||
17 | |||
18 | #include <QMenu> |
||
19 | #include <QMouseEvent> |
||
20 | |||
21 | #include "canvas.h" |
||
10701 | avox | 22 | #include "canvasgesture_rectselect.h" |
10532 | avox | 23 | #include "fpoint.h" |
24 | #include "pageitem.h" |
||
25 | #include "pageselector.h" |
||
26 | #include "scraction.h" |
||
10862 | cbradney | 27 | #include "scrapbookpalette.h" |
10532 | avox | 28 | #include "scribus.h" |
29 | #include "scribusdoc.h" |
||
30 | #include "scribusview.h" |
||
31 | #include "scribusXml.h" |
||
32 | #include "selection.h" |
||
33 | #include "undomanager.h" |
||
34 | #include "util_icon.h" |
||
10701 | avox | 35 | #include "util_math.h" |
10532 | avox | 36 | |
37 | |||
10701 | avox | 38 | CanvasMode_NodeEdit::CanvasMode_NodeEdit(ScribusView* view) : CanvasMode(view), m_rectangleSelect(NULL) |
10532 | avox | 39 | { |
10701 | avox | 40 | Mxp = -1; // last mouse position |
10532 | avox | 41 | Myp = -1; |
10701 | avox | 42 | Dxp = -1; // last mouse press position for rectangle select |
10532 | avox | 43 | Dyp = -1; |
10701 | avox | 44 | GxM = -1; // guide position |
10532 | avox | 45 | GyM = -1; |
10560 | avox | 46 | MoveGX = MoveGY = false; |
10532 | avox | 47 | m_ScMW = m_view->m_ScMW; |
48 | } |
||
49 | |||
10701 | avox | 50 | void CanvasMode_NodeEdit::drawControls(QPainter* p) |
51 | { |
||
11076 | avox | 52 | double x, y; |
11153 | fschmid | 53 | if (m_doc->m_Selection->count() == 0) |
54 | return; |
||
11076 | avox | 55 | PageItem* currItem = m_doc->m_Selection->itemAt(0); |
56 | FPointArray cli; |
||
57 | |||
58 | p->save(); |
||
59 | p->scale(m_canvas->scale(), m_canvas->scale()); |
||
11172 | fschmid | 60 | p->translate(-m_doc->minCanvasCoordinate.x(), -m_doc->minCanvasCoordinate.y()); |
61 | p->translate(currItem->xPos(), currItem->yPos()); |
||
11076 | avox | 62 | p->rotate(currItem->rotation()); |
63 | p->setPen(QPen(Qt::blue, 1 / m_canvas->m_viewMode.scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); |
||
64 | p->setBrush(Qt::NoBrush); |
||
65 | |||
66 | if ((m_doc->nodeEdit.isContourLine) && (currItem->ContourLine.size() != 0)) |
||
67 | cli = currItem->ContourLine; |
||
68 | else |
||
69 | cli = currItem->PoLine; |
||
70 | // draw curve |
||
71 | const double scale = m_canvas->m_viewMode.scale; |
||
72 | const double onePerScale = 1 / scale; |
||
73 | if (cli.size() > 3) |
||
74 | { |
||
75 | for (uint poi=0; poi<cli.size()-3; poi += 4) |
||
76 | { |
||
77 | if (cli.point(poi).x() > 900000) |
||
78 | continue; |
||
79 | p->setPen(QPen(Qt::blue, onePerScale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); |
||
80 | FPoint a1 = cli.point(poi); |
||
81 | FPoint a2 = cli.point(poi+1); |
||
82 | FPoint a3 = cli.point(poi+3); |
||
83 | FPoint a4 = cli.point(poi+2); |
||
84 | QPainterPath Bez; |
||
85 | Bez.moveTo(a1.x(), a1.y()); |
||
86 | Bez.cubicTo(a2.x(), a2.y(), a3.x(), a3.y(), a4.x(), a4.y()); |
||
87 | p->drawPath(Bez); |
||
88 | p->setPen(QPen(Qt::blue, onePerScale, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin)); |
||
89 | p->drawLine(QPointF(a1.x(), a1.y()), QPointF(a2.x(), a2.y())); |
||
90 | p->drawLine(QPointF(a3.x(), a3.y()), QPointF(a4.x(), a4.y())); |
||
91 | } |
||
92 | } |
||
93 | // draw points |
||
94 | for (uint a=0; a<cli.size()-1; a += 2) |
||
95 | { |
||
96 | if (cli.point(a).x() > 900000) |
||
97 | continue; |
||
98 | if (m_doc->nodeEdit.EdPoints) |
||
99 | { |
||
100 | if (m_doc->nodeEdit.ClRe == static_cast<int>(a+1)) |
||
101 | p->setPen(QPen(Qt::red, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
102 | else |
||
103 | p->setPen(QPen(Qt::magenta, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
104 | cli.point(a+1, &x, &y); |
||
105 | p->drawPoint(QPointF(x, y)); |
||
106 | if (m_doc->nodeEdit.ClRe == static_cast<int>(a)) |
||
107 | p->setPen(QPen(Qt::red, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
108 | else |
||
109 | p->setPen(QPen(Qt::blue, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
110 | cli.point(a, &x, &y); |
||
111 | p->drawPoint(QPointF(x, y)); |
||
112 | } |
||
113 | else |
||
114 | { |
||
115 | if (m_doc->nodeEdit.ClRe == static_cast<int>(a)) |
||
116 | p->setPen(QPen(Qt::red, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
117 | else |
||
118 | p->setPen(QPen(Qt::blue, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
119 | cli.point(a, &x, &y); |
||
120 | p->drawPoint(QPointF(x, y)); |
||
121 | if (m_doc->nodeEdit.ClRe == static_cast<int>(a+1)) |
||
122 | p->setPen(QPen(Qt::red, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
123 | else |
||
124 | p->setPen(QPen(Qt::magenta, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
125 | cli.point(a+1, &x, &y); |
||
126 | p->drawPoint(QPointF(x, y)); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | if (m_doc->nodeEdit.ClRe != -1) |
||
131 | { |
||
132 | p->setPen(QPen(Qt::red, 8 / scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin)); |
||
133 | cli.point(m_doc->nodeEdit.ClRe, &x, &y); |
||
134 | p->drawPoint(QPointF(x, y)); |
||
135 | QList<int>::Iterator itm; |
||
136 | for (itm = m_doc->nodeEdit.SelNode.begin(); itm != m_doc->nodeEdit.SelNode.end(); ++itm) |
||
137 | { |
||
138 | cli.point((*itm), &x, &y); |
||
139 | p->drawPoint(QPointF(x, y)); |
||
140 | } |
||
19369 | jghali | 141 | } |
142 | |||
143 | bool havePoint = (m_doc->nodeEdit.ClRe != -1); |
||
144 | emit m_view->HavePoint(havePoint, m_doc->nodeEdit.MoveSym); |
||
145 | |||
146 | if (m_doc->nodeEdit.ClRe != -1) // May change when calling HavePoint() |
||
147 | { |
||
11089 | fschmid | 148 | cli.point(m_doc->nodeEdit.ClRe, &x, &y); |
149 | emit m_view->ClipPo(x, y); |
||
11076 | avox | 150 | } |
19369 | jghali | 151 | |
11076 | avox | 152 | p->restore(); |
10701 | avox | 153 | } |
10532 | avox | 154 | |
11076 | avox | 155 | |
10701 | avox | 156 | void CanvasMode_NodeEdit::activate(bool fromGesture) |
157 | { |
||
158 | if (fromGesture && m_rectangleSelect) |
||
159 | { |
||
10819 | avox | 160 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
10701 | avox | 161 | // handle rectangle select |
162 | PageItem* currItem = m_doc->m_Selection->itemAt(0); |
||
163 | m_doc->nodeEdit.SelNode.clear(); |
||
164 | QRectF Sele = m_rectangleSelect->result(); //QRect(Dxp, Dyp, SeRx-Dxp, SeRy-Dyp).normalized(); |
||
165 | FPointArray Clip; |
||
11395 | fschmid | 166 | bool firstPoint = false; |
10701 | avox | 167 | // m_canvas->setScale(1.0); |
168 | if (m_doc->nodeEdit.isContourLine) |
||
169 | Clip = currItem->ContourLine; |
||
170 | else |
||
171 | Clip = currItem->PoLine; |
||
172 | for (uint a = 0; a < Clip.size(); ++a) |
||
173 | { |
||
174 | if (Clip.point(a).x() > 900000) |
||
175 | continue; |
||
176 | FPoint np = Clip.point(a); |
||
177 | FPoint npf2 = np.transformPoint(currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0, false); |
||
178 | if ((Sele.contains(npf2.x(), npf2.y())) && ((a == 0) || (((a-2) % 4) == 0))) |
||
179 | { |
||
11395 | fschmid | 180 | if (a == 0) |
181 | firstPoint = true; |
||
182 | if ((firstPoint) && (a == Clip.size() - 2) && (!currItem->asPolyLine())) |
||
183 | continue; |
||
10701 | avox | 184 | m_doc->nodeEdit.ClRe = a; |
185 | m_doc->nodeEdit.SelNode.append(a); |
||
186 | m_doc->nodeEdit.update(Clip.pointQF(a)); |
||
187 | } |
||
188 | } |
||
189 | currItem->update(); |
||
190 | m_doc->nodeEdit.finishTransaction(currItem); |
||
191 | delete m_rectangleSelect; |
||
192 | m_rectangleSelect = NULL; |
||
193 | } |
||
10995 | avox | 194 | else |
195 | { |
||
196 | Mxp = -1; // last mouse position |
||
197 | Myp = -1; |
||
198 | Dxp = -1; // last mouse press position for rectangle select |
||
199 | Dyp = -1; |
||
200 | GxM = -1; // guide position |
||
201 | GyM = -1; |
||
202 | MoveGX = MoveGY = false; |
||
203 | } |
||
10701 | avox | 204 | } |
10532 | avox | 205 | |
206 | |||
10701 | avox | 207 | void CanvasMode_NodeEdit::deactivate(bool forGesture) |
208 | { |
||
11339 | avox | 209 | if (!forGesture && m_rectangleSelect) |
210 | { |
||
211 | m_rectangleSelect->clear(); |
||
212 | delete m_rectangleSelect; |
||
213 | m_rectangleSelect = NULL; |
||
214 | } |
||
10701 | avox | 215 | } |
216 | |||
217 | |||
10532 | avox | 218 | inline bool CanvasMode_NodeEdit::GetItem(PageItem** pi) |
219 | { |
||
220 | *pi = m_doc->m_Selection->itemAt(0); |
||
221 | return (*pi) != NULL; |
||
222 | } |
||
223 | |||
224 | |||
225 | |||
226 | void CanvasMode_NodeEdit::enterEvent(QEvent *) |
||
227 | { |
||
18921 | jghali | 228 | |
10532 | avox | 229 | } |
230 | |||
231 | |||
232 | void CanvasMode_NodeEdit::leaveEvent(QEvent *e) |
||
233 | { |
||
18921 | jghali | 234 | |
10532 | avox | 235 | } |
236 | |||
237 | |||
238 | |||
239 | void CanvasMode_NodeEdit::mouseDoubleClickEvent(QMouseEvent *m) |
||
240 | { |
||
241 | m->accept(); |
||
242 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
243 | m_canvas->resetRenderMode(); |
||
244 | m_view->requestMode(submodeEndNodeEdit); |
||
245 | } |
||
246 | |||
247 | |||
248 | void CanvasMode_NodeEdit::mouseMoveEvent(QMouseEvent *m) |
||
249 | { |
||
250 | PageItem *currItem; |
||
251 | QPoint np, np2, mop; |
||
252 | FPoint npf, npf2; |
||
253 | double sc = m_canvas->scale(); |
||
254 | m->accept(); |
||
10819 | avox | 255 | npf = m_canvas->globalToCanvas(m->globalPos()); |
10532 | avox | 256 | if (GetItem(&currItem)) |
257 | { |
||
258 | if (m_doc->DragP) |
||
259 | return; |
||
260 | //Operations run here: |
||
261 | //Item resize, esp after creating a new one |
||
262 | if (m_view->moveTimerElapsed() && m_canvas->m_viewMode.m_MouseButtonPressed |
||
10535 | cbradney | 263 | && (m->buttons() & Qt::LeftButton) && (!currItem->locked())) |
10532 | avox | 264 | { |
265 | handleNodeEditDrag(m, currItem); |
||
266 | } |
||
267 | else if (!m_canvas->m_viewMode.m_MouseButtonPressed) |
||
268 | { |
||
269 | if (!currItem->locked()) |
||
270 | { |
||
18969 | jghali | 271 | QMatrix p; |
272 | QRect mpo; |
||
10701 | avox | 273 | handleNodeEditMove(m, mpo, currItem, p); |
10532 | avox | 274 | } |
275 | } |
||
10819 | avox | 276 | |
10532 | avox | 277 | } |
10701 | avox | 278 | else // shouldnt be in nodeedit mode now, should it?? |
10532 | avox | 279 | { |
10701 | avox | 280 | npf = m_canvas->globalToCanvas(m->globalPos()); |
10535 | cbradney | 281 | if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton) && (GyM == -1) && (GxM == -1)) |
10532 | avox | 282 | { |
10701 | avox | 283 | if (!m_rectangleSelect) |
284 | { |
||
285 | m_rectangleSelect = new RectSelect(this); |
||
286 | } |
||
11339 | avox | 287 | m_rectangleSelect->prepare(m->globalPos()); |
288 | m_view->startGesture(m_rectangleSelect); |
||
10532 | avox | 289 | return; |
290 | } |
||
291 | if ((m_doc->guidesSettings.guidesShown) && (!m_doc->GuideLock) |
||
10701 | avox | 292 | && (m_doc->OnPage(npf.x(), npf.y()) != -1)) |
10532 | avox | 293 | { |
294 | Guides::iterator it; |
||
295 | Guides tmpGuides = m_doc->currentPage()->guides.horizontals(GuideManagerCore::Standard); |
||
296 | for (it = tmpGuides.begin(); it != tmpGuides.end(); ++it) |
||
297 | { |
||
10701 | avox | 298 | if ( (*it) + m_doc->currentPage()->yOffset() < npf.y() + m_doc->guidesSettings.grabRad * sc && |
299 | (*it) + m_doc->currentPage()->yOffset() > npf.y() - m_doc->guidesSettings.grabRad * sc ) |
||
10532 | avox | 300 | { |
301 | if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (GyM != -1)) |
||
10560 | avox | 302 | MoveGY = true; |
10701 | avox | 303 | if (npf.x() < m_doc->currentPage()->xOffset() || |
304 | npf.x() >= m_doc->currentPage()->xOffset() + m_doc->currentPage()->width() - 1) |
||
18921 | jghali | 305 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
10532 | avox | 306 | else |
18921 | jghali | 307 | m_view->setCursor(QCursor(Qt::SplitVCursor)); |
10532 | avox | 308 | return; |
309 | } |
||
310 | } |
||
311 | tmpGuides = m_doc->currentPage()->guides.verticals(GuideManagerCore::Standard); |
||
312 | for (it = tmpGuides.begin(); it!= tmpGuides.end(); ++it) |
||
313 | { |
||
10701 | avox | 314 | if ( (*it) + m_doc->currentPage()->xOffset() < npf.x() + m_doc->guidesSettings.grabRad * sc && |
315 | (*it) + m_doc->currentPage()->xOffset() > npf.x() - m_doc->guidesSettings.grabRad * sc) |
||
10532 | avox | 316 | { |
317 | if ((m_canvas->m_viewMode.m_MouseButtonPressed) && (GxM != -1)) |
||
10560 | avox | 318 | MoveGX = true; |
10701 | avox | 319 | if (npf.y() < m_doc->currentPage()->yOffset() || |
320 | npf.y() >= m_doc->currentPage()->yOffset() + m_doc->currentPage()->height() - 1) |
||
18921 | jghali | 321 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
10532 | avox | 322 | else |
18921 | jghali | 323 | m_view->setCursor(QCursor(Qt::SplitHCursor)); |
10532 | avox | 324 | return; |
325 | } |
||
326 | } |
||
18921 | jghali | 327 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
10532 | avox | 328 | } |
329 | } |
||
330 | } |
||
331 | |||
332 | void CanvasMode_NodeEdit::mousePressEvent(QMouseEvent *m) |
||
333 | { |
||
334 | m_canvas->m_viewMode.m_MouseButtonPressed = true; |
||
335 | m_canvas->m_viewMode.operItemMoving = false; |
||
336 | m_doc->DragP = false; |
||
337 | m_doc->leaveDrag = false; |
||
10560 | avox | 338 | MoveGX = MoveGY = false; |
10532 | avox | 339 | m->accept(); |
10978 | avox | 340 | m_view->registerMousePress(m->globalPos()); |
18969 | jghali | 341 | QRect mpo; |
10701 | avox | 342 | Mxp = m->x(); |
343 | Myp = m->y(); |
||
344 | |||
10532 | avox | 345 | if (m_doc->m_Selection->count() != 0) |
346 | { |
||
347 | handleNodeEditPress(m, mpo); |
||
348 | } |
||
349 | if ((m_doc->m_Selection->count() != 0) && (m->button() == Qt::RightButton)) |
||
350 | { |
||
351 | m_canvas->m_viewMode.m_MouseButtonPressed = true; |
||
352 | Dxp = Mxp; |
||
353 | Dyp = Myp; |
||
354 | } |
||
355 | } |
||
356 | |||
357 | |||
358 | |||
359 | void CanvasMode_NodeEdit::mouseReleaseEvent(QMouseEvent *m) |
||
360 | { |
||
361 | PageItem *currItem; |
||
362 | m_canvas->m_viewMode.m_MouseButtonPressed = false; |
||
363 | m_canvas->resetRenderMode(); |
||
364 | m->accept(); |
||
365 | if (m_view->moveTimerElapsed()) |
||
366 | { |
||
11076 | avox | 367 | if (m_doc->nodeEdit.SegP1 != -1 && m_doc->nodeEdit.SegP2 != -1) |
368 | { |
||
369 | m_doc->nodeEdit.deselect(); |
||
370 | m_doc->nodeEdit.SegP1 = -1; |
||
371 | m_doc->nodeEdit.SegP2 = -1; |
||
372 | } |
||
10532 | avox | 373 | currItem = m_doc->m_Selection->itemAt(0); |
374 | m_canvas->m_viewMode.operItemMoving = false; |
||
375 | double xposOrig = currItem->xPos(); |
||
376 | double yposOrig = currItem->yPos(); |
||
377 | |||
378 | ItemState<QPair<FPointArray, FPointArray> > *state = NULL; |
||
379 | state = m_doc->nodeEdit.finishTransaction1(currItem); |
||
380 | xposOrig = currItem->xPos(); |
||
381 | yposOrig = currItem->yPos(); |
||
11395 | fschmid | 382 | if (m_doc->nodeEdit.hasNodeSelected() && (m_doc->nodeEdit.SelNode.count() == 1)) |
10532 | avox | 383 | { |
10701 | avox | 384 | //FIXME:av |
385 | FPoint newP = m_canvas->globalToCanvas(m->globalPos()); |
||
10532 | avox | 386 | currItem->OldB2 = currItem->width(); |
387 | currItem->OldH2 = currItem->height(); |
||
388 | FPointArray Clip; |
||
389 | if (m_doc->nodeEdit.isContourLine) |
||
390 | Clip = currItem->ContourLine; |
||
391 | else |
||
392 | Clip = currItem->PoLine; |
||
10701 | avox | 393 | FPoint npf; |
394 | double nx = newP.x(); |
||
395 | double ny = newP.y(); |
||
10532 | avox | 396 | if (!m_doc->ApplyGuides(&nx, &ny)) |
397 | npf = m_doc->ApplyGridF(FPoint(nx, ny)); |
||
398 | else |
||
399 | npf = FPoint(nx, ny); |
||
10701 | avox | 400 | npf = FPoint(npf.x(), npf.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true); |
10532 | avox | 401 | m_doc->nodeEdit.moveClipPoint(currItem, npf); |
402 | } |
||
403 | |||
404 | m_doc->AdjustItemSize(currItem); |
||
405 | if (!m_doc->nodeEdit.isContourLine) |
||
406 | currItem->ContourLine.translate(xposOrig - currItem->xPos(), yposOrig - currItem->yPos()); |
||
11153 | fschmid | 407 | m_doc->regionsChanged()->update(QRectF()); |
10532 | avox | 408 | if (state) |
409 | { |
||
410 | m_doc->nodeEdit.finishTransaction2(currItem, state); |
||
411 | } |
||
412 | return; |
||
413 | } |
||
12837 | jghali | 414 | |
10532 | avox | 415 | m_canvas->setRenderModeUseBuffer(false); |
416 | m_doc->DragP = false; |
||
417 | m_doc->leaveDrag = false; |
||
418 | m_canvas->m_viewMode.operItemMoving = false; |
||
419 | m_canvas->m_viewMode.operItemResizing = false; |
||
420 | m_view->MidButt = false; |
||
11490 | avox | 421 | if (m_view->groupTransactionStarted()) |
10532 | avox | 422 | { |
10534 | cbradney | 423 | for (int i = 0; i < m_doc->m_Selection->count(); ++i) |
10532 | avox | 424 | m_doc->m_Selection->itemAt(i)->checkChanges(true); |
11490 | avox | 425 | m_view->endGroupTransaction(); |
10532 | avox | 426 | } |
427 | //Commit drag created items to undo manager. |
||
428 | if (m_doc->m_Selection->itemAt(0)!=NULL) |
||
429 | { |
||
430 | m_doc->itemAddCommit(m_doc->m_Selection->itemAt(0)->ItemNr); |
||
431 | } |
||
432 | //Make sure the Zoom spinbox and page selector dont have focus if we click on the canvas |
||
433 | m_view->zoomSpinBox->clearFocus(); |
||
434 | m_view->pageSelector->clearFocus(); |
||
435 | if (m_doc->m_Selection->itemAt(0) != 0) // is there the old clip stored for the undo action |
||
436 | { |
||
437 | currItem = m_doc->m_Selection->itemAt(0); |
||
438 | m_doc->nodeEdit.finishTransaction(currItem); |
||
439 | } |
||
440 | } |
||
441 | |||
442 | |||
443 | |||
10701 | avox | 444 | void CanvasMode_NodeEdit::handleNodeEditPress(QMouseEvent* m, QRect) |
10532 | avox | 445 | { |
10819 | avox | 446 | FPoint npf2; |
10532 | avox | 447 | |
448 | PageItem* currItem = m_doc->m_Selection->itemAt(0); |
||
449 | FPointArray Clip = m_doc->nodeEdit.beginTransaction(currItem); |
||
450 | bool edited = false; |
||
451 | bool pfound = false; |
||
10701 | avox | 452 | npf2 = m_canvas->globalToCanvas(m->globalPos()).transformPoint(currItem->xPos(), currItem->yPos(), currItem->rotation(), 1.0, 1.0, true); |
10819 | avox | 453 | QMatrix pm2 = currItem->getTransform(); |
10532 | avox | 454 | for (int a=0; a < signed(Clip.size()); ++a) |
455 | { |
||
456 | if (((m_doc->nodeEdit.EdPoints) && (a % 2 != 0)) || ((!m_doc->nodeEdit.EdPoints) && (a % 2 == 0))) |
||
18969 | jghali | 457 | continue; |
11089 | fschmid | 458 | QPointF npf = pm2.map(Clip.pointQF(a)); |
459 | if (m_canvas->hitsCanvasPoint(m->globalPos(), npf)) |
||
460 | { |
||
461 | m_doc->nodeEdit.ClRe = a; |
||
462 | if ((m_doc->nodeEdit.EdPoints) && (m_doc->nodeEdit.SelNode.contains(a) == 0)) |
||
463 | { |
||
464 | if (m->modifiers() == Qt::ShiftModifier) |
||
465 | m_doc->nodeEdit.SelNode.append(a); |
||
466 | else |
||
10532 | avox | 467 | { |
11089 | fschmid | 468 | m_doc->nodeEdit.SelNode.clear(); |
469 | m_doc->nodeEdit.SelNode.append(a); |
||
10532 | avox | 470 | } |
471 | } |
||
11089 | fschmid | 472 | m_doc->nodeEdit.update(Clip.pointQF(a)); |
473 | pfound = true; |
||
474 | edited = true; |
||
475 | break; |
||
10532 | avox | 476 | } |
11089 | fschmid | 477 | } |
478 | if ((!pfound) || (!m_doc->nodeEdit.EdPoints)) |
||
479 | m_doc->nodeEdit.SelNode.clear(); |
||
480 | |||
481 | if ((m_doc->nodeEdit.submode == NodeEditContext::MOVE_POINT) && (m_doc->nodeEdit.ClRe2 != -1) && !m_doc->nodeEdit.hasNodeSelected()) |
||
482 | { |
||
483 | m_doc->nodeEdit.SegP1 = m_doc->nodeEdit.ClRe2; |
||
484 | m_doc->nodeEdit.SegP2 = m_doc->nodeEdit.ClRe2+2; |
||
485 | m_doc->nodeEdit.ClRe = m_doc->nodeEdit.ClRe2; |
||
486 | } |
||
487 | FPointArray cli; |
||
488 | uint EndInd = Clip.size(); |
||
489 | uint StartInd = 0; |
||
490 | for (uint n = m_doc->nodeEdit.ClRe; n < Clip.size(); ++n) |
||
491 | { |
||
492 | if (Clip.point(n).x() > 900000) |
||
10532 | avox | 493 | { |
11089 | fschmid | 494 | EndInd = n; |
495 | break; |
||
10532 | avox | 496 | } |
11089 | fschmid | 497 | } |
498 | if (m_doc->nodeEdit.ClRe > 0) |
||
499 | { |
||
500 | for (uint n2 = m_doc->nodeEdit.ClRe; n2 > 0; n2--) |
||
10532 | avox | 501 | { |
11089 | fschmid | 502 | if (n2 == 0) |
503 | break; |
||
504 | if (Clip.point(n2).x() > 900000) |
||
10532 | avox | 505 | { |
11089 | fschmid | 506 | StartInd = n2 + 1; |
10532 | avox | 507 | break; |
508 | } |
||
509 | } |
||
11089 | fschmid | 510 | } |
511 | if (m_doc->nodeEdit.submode == NodeEditContext::SPLIT_PATH) |
||
512 | { |
||
513 | if (!m_doc->nodeEdit.EdPoints) |
||
514 | return; |
||
18971 | jghali | 515 | if ((!m_doc->nodeEdit.hasNodeSelected()) && (m_doc->nodeEdit.ClRe2 != -1)) // We don't have a Point, try to add one onto the current curve segment |
10532 | avox | 516 | { |
517 | bool foundP = false; |
||
518 | uint seg = 0; |
||
519 | double absDist = 9999999999.9; |
||
520 | FPoint point = FPoint(0, 0); |
||
521 | FPoint normal = FPoint(0, 0); |
||
522 | FPoint tangent = FPoint(0, 0); |
||
523 | FPoint nearPoint = FPoint(0, 0); |
||
524 | double nearT = 0.0; |
||
525 | QRect mpo2(0, 0, m_doc->guidesSettings.grabRad*3, m_doc->guidesSettings.grabRad*3); |
||
526 | mpo2.moveCenter(QPoint(qRound(npf2.x()), qRound(npf2.y()))); |
||
527 | for (uint poi=0; poi<Clip.size()-3; poi += 4) |
||
528 | { |
||
529 | FPoint a1 = Clip.point(poi); |
||
530 | FPoint a2 = Clip.point(poi+1); |
||
531 | FPoint a3 = Clip.point(poi+3); |
||
532 | FPoint a4 = Clip.point(poi+2); |
||
533 | QPainterPath Bez; |
||
534 | Bez.moveTo(a1.x(), a1.y()); |
||
535 | Bez.cubicTo(a2.x(), a2.y(), a3.x(), a3.y(), a4.x(), a4.y()); |
||
536 | QPolygon cli2 = Bez.toFillPolygon().toPolygon(); |
||
537 | for (int clp = 0; clp < cli2.size()-1; ++clp) |
||
538 | { |
||
539 | if (m_view->PointOnLine(cli2.point(clp), cli2.point(clp+1), mpo2)) |
||
540 | { |
||
541 | seg = poi; |
||
542 | double sp = 0.0; |
||
543 | double spadd = 1.0 / (Clip.lenPathSeg(seg) * m_canvas->scale()); |
||
544 | while (sp < 1.0) |
||
545 | { |
||
546 | Clip.pointTangentNormalAt(seg, sp, &point, &tangent, &normal ); |
||
547 | double d1 = fabs(sqrt(pow(point.x() - npf2.x(), 2) + pow(point.y() - npf2.y() ,2))); |
||
548 | if (d1 < absDist) |
||
549 | { |
||
550 | foundP = true; |
||
551 | nearPoint = point; |
||
552 | nearT = sp; |
||
553 | absDist = d1; |
||
554 | } |
||
555 | sp += spadd; |
||
556 | } |
||
557 | } |
||
558 | } |
||
559 | } |
||
560 | cli.putPoints(0, m_doc->nodeEdit.ClRe2+2, Clip); |
||
561 | if (foundP) |
||
562 | { |
||
563 | npf2 = nearPoint; |
||
564 | FPoint base = cli.point(cli.size()-2); |
||
565 | FPoint c1 = cli.point(cli.size()-1); |
||
566 | FPoint base2 = Clip.point(m_doc->nodeEdit.ClRe2+2); |
||
567 | FPoint c2 = Clip.point(m_doc->nodeEdit.ClRe2+3); |
||
568 | if ((base == c1) && (base2 == c2)) |
||
569 | { |
||
570 | cli.resize(cli.size()+4); |
||
571 | cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y()); |
||
11089 | fschmid | 572 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe2 + 2), Clip, m_doc->nodeEdit.ClRe2+2); |
10532 | avox | 573 | } |
574 | else |
||
575 | { |
||
576 | FPoint cn1 = (1.0 - nearT) * base + nearT * c1; |
||
577 | FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2); |
||
578 | FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2); |
||
579 | FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2; |
||
580 | cli.setPoint(cli.size()-1, cn1); |
||
581 | cli.resize(cli.size()+4); |
||
582 | uint basind = cli.size()+1; |
||
583 | cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), cn2.x(), cn2.y(), npf2.x(), npf2.y(), cn3.x(), cn3.y()); |
||
584 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe2 + 2), Clip, m_doc->nodeEdit.ClRe2+2); |
||
585 | cli.setPoint(basind, cn4); |
||
586 | } |
||
11089 | fschmid | 587 | Clip = cli.copy(); |
588 | cli.resize(0); |
||
589 | m_doc->nodeEdit.ClRe = m_doc->nodeEdit.ClRe2+2; |
||
590 | m_doc->nodeEdit.ClRe2 = -1; |
||
591 | EndInd = Clip.size(); |
||
592 | StartInd = 0; |
||
593 | for (uint n = m_doc->nodeEdit.ClRe; n < Clip.size(); ++n) |
||
594 | { |
||
595 | if (Clip.point(n).x() > 900000) |
||
596 | { |
||
597 | EndInd = n; |
||
598 | break; |
||
599 | } |
||
600 | } |
||
601 | if (m_doc->nodeEdit.ClRe > 0) |
||
602 | { |
||
603 | for (uint n2 = m_doc->nodeEdit.ClRe; n2 > 0; n2--) |
||
604 | { |
||
605 | if (n2 == 0) |
||
606 | break; |
||
607 | if (Clip.point(n2).x() > 900000) |
||
608 | { |
||
609 | StartInd = n2 + 1; |
||
610 | break; |
||
611 | } |
||
612 | } |
||
613 | } |
||
10532 | avox | 614 | } |
615 | else |
||
11089 | fschmid | 616 | m_doc->nodeEdit.deselect(); |
617 | } |
||
618 | if (m_doc->nodeEdit.hasNodeSelected()) |
||
619 | { |
||
620 | if (currItem->asPolygon()) |
||
10532 | avox | 621 | { |
11089 | fschmid | 622 | if ((m_doc->nodeEdit.ClRe != 0) && (m_doc->nodeEdit.ClRe != static_cast<int>(EndInd-2))) |
623 | { |
||
624 | if (currItem->Segments.count() == 0) |
||
625 | { |
||
626 | cli.putPoints(0, EndInd-(m_doc->nodeEdit.ClRe+2), Clip, m_doc->nodeEdit.ClRe+2); |
||
627 | cli.putPoints(cli.size(), m_doc->nodeEdit.ClRe+2, Clip); |
||
628 | } |
||
629 | else |
||
630 | { |
||
631 | cli.putPoints(0, EndInd-StartInd, Clip, StartInd); |
||
632 | int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, currItem->xPos(), currItem->yPos(), currItem->width(), currItem->height(), currItem->lineWidth(), currItem->fillColor(), currItem->lineColor(), true); |
||
633 | PageItem* bb = m_doc->Items->at(z); |
||
634 | if (m_doc->nodeEdit.isContourLine) |
||
635 | bb->ContourLine.resize(0); |
||
636 | else |
||
637 | bb->PoLine.resize(0); |
||
638 | if (StartInd != 0) |
||
639 | { |
||
640 | if (m_doc->nodeEdit.isContourLine) |
||
641 | { |
||
642 | bb->ContourLine.putPoints(0, StartInd - 4, Clip); |
||
643 | bb->ContourLine.putPoints(bb->ContourLine.size(), Clip.size()-EndInd, Clip, EndInd); |
||
644 | } |
||
645 | else |
||
646 | { |
||
647 | bb->PoLine.putPoints(0, StartInd - 4, Clip); |
||
648 | bb->PoLine.putPoints(bb->PoLine.size(), Clip.size()-EndInd, Clip, EndInd); |
||
649 | } |
||
650 | } |
||
651 | else |
||
652 | { |
||
653 | if (m_doc->nodeEdit.isContourLine) |
||
654 | bb->ContourLine.putPoints(0, Clip.size()-EndInd-4, Clip, EndInd+4); |
||
655 | else |
||
656 | bb->PoLine.putPoints(0, Clip.size()-EndInd-4, Clip, EndInd+4); |
||
657 | } |
||
658 | bb->setRotation(currItem->rotation()); |
||
659 | m_doc->AdjustItemSize(bb); |
||
660 | bb->ClipEdited = true; |
||
661 | PageItem *bx = m_doc->Items->takeAt(bb->ItemNr); |
||
662 | m_doc->Items->insert(bb->ItemNr-1, bx); |
||
663 | } |
||
664 | currItem->PoLine = cli.copy(); |
||
665 | } |
||
666 | m_doc->nodeEdit.deselect(); |
||
667 | currItem->ClipEdited = true; |
||
668 | edited = true; |
||
669 | m_doc->nodeEdit.submode = NodeEditContext::MOVE_POINT; |
||
670 | PageItem* newItem=m_doc->convertItemTo(currItem, PageItem::PolyLine); |
||
671 | currItem=newItem; |
||
672 | m_doc->m_Selection->clear(); |
||
673 | m_doc->m_Selection->addItem(currItem); |
||
674 | emit m_view->PolyOpen(); |
||
10532 | avox | 675 | } |
676 | else |
||
11089 | fschmid | 677 | { |
678 | if ((currItem->asPolyLine()) || (currItem->asPathText())) |
||
679 | { |
||
680 | if ((m_doc->nodeEdit.ClRe > 1) && (m_doc->nodeEdit.ClRe < static_cast<int>(Clip.size()-2))) |
||
681 | { |
||
682 | int z = m_doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, currItem->xPos(), currItem->yPos(), currItem->width(), currItem->height(), currItem->lineWidth(), currItem->fillColor(), currItem->lineColor(), true); |
||
683 | PageItem* bb = m_doc->Items->at(z); |
||
684 | if (m_doc->nodeEdit.isContourLine) |
||
685 | bb->ContourLine.putPoints(0, Clip.size()-(m_doc->nodeEdit.ClRe+2), Clip, m_doc->nodeEdit.ClRe+2); |
||
686 | else |
||
687 | bb->PoLine.putPoints(0, Clip.size()-(m_doc->nodeEdit.ClRe+2), Clip, m_doc->nodeEdit.ClRe+2); |
||
688 | bb->setRotation(currItem->rotation()); |
||
689 | m_doc->AdjustItemSize(bb); |
||
690 | bb->ClipEdited = true; |
||
13533 | jghali | 691 | bb->setFrameType(currItem->frameType()); |
11089 | fschmid | 692 | cli.resize(0); |
693 | cli.putPoints(0, m_doc->nodeEdit.ClRe+2, Clip); |
||
694 | currItem->PoLine = cli.copy(); |
||
695 | m_doc->m_Selection->clear(); |
||
696 | m_doc->m_Selection->addItem(currItem); |
||
697 | } |
||
698 | m_doc->nodeEdit.deselect(); |
||
699 | currItem->ClipEdited = true; |
||
700 | edited = true; |
||
701 | m_doc->nodeEdit.submode = NodeEditContext::MOVE_POINT; |
||
702 | currItem->setPolyClip(qRound(qMax(currItem->lineWidth() / 2.0, 1.0))); |
||
703 | emit m_view->PolyOpen(); |
||
704 | } |
||
705 | } |
||
10532 | avox | 706 | } |
11089 | fschmid | 707 | } |
708 | if ((m_doc->nodeEdit.submode == NodeEditContext::DEL_POINT) && m_doc->nodeEdit.hasNodeSelected()) |
||
709 | { |
||
710 | if (!m_doc->nodeEdit.EdPoints) |
||
711 | return; |
||
712 | if ((currItem->asPolygon()) || (currItem->asTextFrame()) || (currItem->asImageFrame())) |
||
10532 | avox | 713 | { |
11089 | fschmid | 714 | if ((currItem->Segments.count() == 0) && (Clip.size() <= 12)) // min. 3 points |
715 | return; |
||
10532 | avox | 716 | } |
11089 | fschmid | 717 | else |
10532 | avox | 718 | { |
11089 | fschmid | 719 | if (Clip.size() <= 4) |
720 | return; |
||
10532 | avox | 721 | } |
11089 | fschmid | 722 | if ((currItem->Segments.count() != 0) && ((EndInd - StartInd) <= 12)) |
723 | { |
||
724 | if (StartInd != 0) |
||
725 | cli.putPoints(0, StartInd-4, Clip); |
||
726 | cli.putPoints(cli.size(), Clip.size() - EndInd, Clip, EndInd); |
||
727 | } |
||
10532 | avox | 728 | else |
729 | { |
||
11089 | fschmid | 730 | if (m_doc->nodeEdit.ClRe == static_cast<int>(StartInd)) |
731 | { |
||
732 | if ((currItem->asPolygon()) || (currItem->asTextFrame()) || (currItem->asImageFrame())) |
||
733 | { |
||
734 | FPoint kp(Clip.point(EndInd-3)); |
||
735 | cli.putPoints(0, StartInd, Clip); |
||
736 | cli.putPoints(cli.size(), EndInd - StartInd - 4, Clip, StartInd); |
||
737 | cli.setPoint(StartInd, cli.point(cli.size()-2)); |
||
738 | cli.setPoint(StartInd + 1, kp); |
||
739 | cli.putPoints(cli.size(), Clip.size() - EndInd, Clip, EndInd); |
||
740 | } |
||
741 | else |
||
742 | { |
||
743 | cli.putPoints(0, StartInd, Clip); |
||
744 | cli.putPoints(cli.size(), EndInd - StartInd - 4, Clip, StartInd+4); |
||
745 | cli.putPoints(cli.size(), Clip.size() - EndInd, Clip, EndInd); |
||
746 | } |
||
747 | } |
||
20660 | jghali | 748 | else if (m_doc->nodeEdit.ClRe == static_cast<int>(EndInd - 2)) |
749 | { |
||
750 | cli.putPoints(0, m_doc->nodeEdit.ClRe - 2, Clip); |
||
751 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe + 2), Clip, m_doc->nodeEdit.ClRe+2); |
||
19454 | jghali | 752 | } |
11089 | fschmid | 753 | else |
754 | { |
||
755 | if (m_doc->nodeEdit.ClRe != 0) |
||
756 | cli.putPoints(0, m_doc->nodeEdit.ClRe, Clip); |
||
757 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe + 4), Clip, m_doc->nodeEdit.ClRe+4); |
||
758 | } |
||
10532 | avox | 759 | } |
11089 | fschmid | 760 | if (m_doc->nodeEdit.isContourLine) |
761 | currItem->ContourLine = cli.copy(); |
||
762 | else |
||
763 | currItem->PoLine = cli.copy(); |
||
764 | m_doc->nodeEdit.deselect(); |
||
765 | currItem->ClipEdited = true; |
||
766 | edited = true; |
||
767 | } |
||
768 | if ((m_doc->nodeEdit.submode == NodeEditContext::ADD_POINT) && (m_doc->nodeEdit.ClRe2 != -1)) |
||
769 | { |
||
770 | bool foundP = false; |
||
771 | uint seg = 0; |
||
772 | double absDist = 9999999999.9; |
||
773 | FPoint point = FPoint(0, 0); |
||
774 | FPoint normal = FPoint(0, 0); |
||
775 | FPoint tangent = FPoint(0, 0); |
||
776 | FPoint nearPoint = FPoint(0, 0); |
||
777 | double nearT = 0.0; |
||
778 | QRect mpo2(0, 0, m_doc->guidesSettings.grabRad*3, m_doc->guidesSettings.grabRad*3); |
||
779 | mpo2.moveCenter(QPoint(qRound(npf2.x()), qRound(npf2.y()))); |
||
780 | for (uint poi=0; poi<Clip.size()-3; poi += 4) |
||
781 | { |
||
782 | FPoint a1 = Clip.point(poi); |
||
783 | FPoint a2 = Clip.point(poi+1); |
||
784 | FPoint a3 = Clip.point(poi+3); |
||
785 | FPoint a4 = Clip.point(poi+2); |
||
786 | QPainterPath Bez; |
||
787 | Bez.moveTo(a1.x(), a1.y()); |
||
788 | Bez.cubicTo(a2.x(), a2.y(), a3.x(), a3.y(), a4.x(), a4.y()); |
||
789 | QPolygon cli2 = Bez.toFillPolygon().toPolygon(); |
||
790 | for (int clp = 0; clp < cli2.size()-1; ++clp) |
||
791 | { |
||
792 | if (m_view->PointOnLine(cli2.point(clp), cli2.point(clp+1), mpo2)) |
||
793 | { |
||
794 | seg = poi; |
||
795 | double sp = 0.0; |
||
796 | double spadd = 1.0 / (Clip.lenPathSeg(seg) * m_canvas->scale()); |
||
797 | while (sp < 1.0) |
||
798 | { |
||
799 | Clip.pointTangentNormalAt(seg, sp, &point, &tangent, &normal ); |
||
800 | double d1 = fabs(sqrt(pow(point.x() - npf2.x(), 2) + pow(point.y() - npf2.y() ,2))); |
||
801 | if (d1 < absDist) |
||
802 | { |
||
803 | foundP = true; |
||
804 | nearPoint = point; |
||
805 | nearT = sp; |
||
806 | absDist = d1; |
||
807 | } |
||
808 | sp += spadd; |
||
809 | } |
||
810 | } |
||
811 | } |
||
812 | } |
||
813 | cli.putPoints(0, m_doc->nodeEdit.ClRe2+2, Clip); |
||
814 | if (foundP) |
||
815 | { |
||
816 | npf2 = nearPoint; |
||
817 | FPoint base = cli.point(cli.size()-2); |
||
818 | FPoint c1 = cli.point(cli.size()-1); |
||
819 | FPoint base2 = Clip.point(m_doc->nodeEdit.ClRe2+2); |
||
820 | FPoint c2 = Clip.point(m_doc->nodeEdit.ClRe2+3); |
||
821 | if ((base == c1) && (base2 == c2)) |
||
822 | { |
||
823 | cli.resize(cli.size()+4); |
||
824 | cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y()); |
||
825 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe2 + 2), Clip, m_doc->nodeEdit.ClRe2+2); |
||
826 | } |
||
827 | else |
||
828 | { |
||
829 | FPoint cn1 = (1.0 - nearT) * base + nearT * c1; |
||
830 | FPoint cn2 = (1.0 - nearT) * cn1 + nearT * ((1.0 - nearT) * c1 + nearT * c2); |
||
831 | FPoint cn3 = (1.0 - nearT) * ((1.0 - nearT) * c1 + nearT * c2) + nearT * ((1.0 - nearT) * c2 + nearT * base2); |
||
832 | FPoint cn4 = (1.0 - nearT) * c2 + nearT * base2; |
||
833 | cli.setPoint(cli.size()-1, cn1); |
||
834 | cli.resize(cli.size()+4); |
||
835 | uint basind = cli.size()+1; |
||
836 | cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), cn2.x(), cn2.y(), npf2.x(), npf2.y(), cn3.x(), cn3.y()); |
||
837 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe2 + 2), Clip, m_doc->nodeEdit.ClRe2+2); |
||
838 | cli.setPoint(basind, cn4); |
||
839 | } |
||
840 | } |
||
841 | else |
||
842 | { |
||
843 | cli.resize(cli.size()+4); |
||
844 | cli.putPoints(cli.size()-4, 4, npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y(), npf2.x(), npf2.y()); |
||
845 | cli.putPoints(cli.size(), Clip.size()-(m_doc->nodeEdit.ClRe2 + 2), Clip, m_doc->nodeEdit.ClRe2+2); |
||
846 | } |
||
847 | if (m_doc->nodeEdit.isContourLine) |
||
848 | currItem->ContourLine = cli.copy(); |
||
849 | else |
||
850 | currItem->PoLine = cli.copy(); |
||
851 | m_doc->nodeEdit.ClRe2 = -1; |
||
852 | currItem->ClipEdited = true; |
||
853 | edited = true; |
||
854 | } |
||
855 | if (edited) |
||
856 | { |
||
857 | currItem->FrameType = 3; |
||
858 | m_doc->AdjustItemSize(currItem); |
||
859 | currItem->update(); |
||
19081 | jghali | 860 | emit m_view->PolyStatus(currItem->itemType(), currItem->PoLine.size()); |
11089 | fschmid | 861 | } |
862 | if ((m_doc->nodeEdit.SelNode.count() != 0) || ((m_doc->nodeEdit.SegP1 != -1) && (m_doc->nodeEdit.SegP2 != -1)) || (m_doc->nodeEdit.hasNodeSelected() && (!m_doc->nodeEdit.EdPoints))) |
||
863 | { |
||
864 | Mxp = m->x(); |
||
865 | Myp = m->y(); |
||
866 | m_canvas->setRenderModeFillBuffer(); |
||
867 | } |
||
868 | else |
||
869 | { |
||
870 | Mxp = m->x(); |
||
871 | Myp = m->y(); |
||
16886 | craig | 872 | Dxp = qRound(m->x()/m_canvas->scale()); |
873 | Dyp = qRound(m->y()/m_canvas->scale()); |
||
11339 | avox | 874 | if (!m_rectangleSelect) |
875 | m_rectangleSelect = new RectSelect(this); |
||
876 | m_rectangleSelect->prepare(m->globalPos()); |
||
11395 | fschmid | 877 | m_view->startGesture(m_rectangleSelect); |
11089 | fschmid | 878 | } |
10532 | avox | 879 | |
880 | } |
||
881 | |||
882 | |||
883 | |||
10701 | avox | 884 | bool CanvasMode_NodeEdit::handleNodeEditMove(QMouseEvent* m, QRect, PageItem* currItem, QMatrix) |
10532 | avox | 885 | { |
10701 | avox | 886 | QMatrix itemPos = currItem->getTransform(); |
10532 | avox | 887 | FPointArray Clip; |
888 | m_doc->nodeEdit.ClRe2 = -1; |
||
889 | m_doc->nodeEdit.SegP1 = -1; |
||
890 | m_doc->nodeEdit.SegP2 = -1; |
||
891 | if (m_doc->nodeEdit.isContourLine) |
||
892 | Clip = currItem->ContourLine; |
||
893 | else |
||
894 | Clip = currItem->PoLine; |
||
895 | if ((m_doc->nodeEdit.submode == NodeEditContext::DEL_POINT) || |
||
896 | (m_doc->nodeEdit.submode == NodeEditContext::MOVE_POINT) || |
||
897 | (m_doc->nodeEdit.submode == NodeEditContext::SPLIT_PATH)) |
||
898 | { |
||
899 | for (int a=0; a < signed(Clip.size()); ++a) |
||
900 | { |
||
901 | if (((m_doc->nodeEdit.EdPoints) && (a % 2 != 0)) || ((!m_doc->nodeEdit.EdPoints) && (a % 2 == 0))) |
||
902 | continue; |
||
10701 | avox | 903 | QPointF point = Clip.pointQF(a); |
904 | if (m_canvas->hitsCanvasPoint(m->globalPos(), itemPos.map(point))) |
||
10532 | avox | 905 | { |
906 | if (m_doc->nodeEdit.submode == NodeEditContext::MOVE_POINT) |
||
18921 | jghali | 907 | m_view->setCursor(QCursor(Qt::SizeAllCursor)); |
10532 | avox | 908 | if (m_doc->nodeEdit.submode == NodeEditContext::DEL_POINT) |
18921 | jghali | 909 | m_view->setCursor(QCursor(loadIcon("DelPoint.png"), 1, 1)); |
10532 | avox | 910 | if (m_doc->nodeEdit.submode == NodeEditContext::SPLIT_PATH) |
18921 | jghali | 911 | m_view->setCursor(QCursor(loadIcon("Split.png"), 1, 1)); |
10532 | avox | 912 | return true; |
913 | } |
||
914 | } |
||
915 | } |
||
916 | if ((m_doc->nodeEdit.submode == NodeEditContext::ADD_POINT) || |
||
917 | (m_doc->nodeEdit.submode == NodeEditContext::MOVE_POINT) || |
||
10550 | avox | 918 | (m_doc->nodeEdit.submode == NodeEditContext::SPLIT_PATH && m_doc->nodeEdit.EdPoints)) |
10532 | avox | 919 | { |
920 | for (uint poi=0; poi<Clip.size()-3; poi += 4) |
||
921 | { |
||
10701 | avox | 922 | // create bezier curve in canvas coords |
923 | QPointF a1 = itemPos.map(Clip.pointQF(poi)); |
||
924 | QPointF a2 = itemPos.map(Clip.pointQF(poi+1)); |
||
925 | QPointF a3 = itemPos.map(Clip.pointQF(poi+3)); |
||
926 | QPointF a4 = itemPos.map(Clip.pointQF(poi+2)); |
||
10532 | avox | 927 | QPainterPath Bez; |
10701 | avox | 928 | Bez.moveTo(a1); |
929 | Bez.cubicTo(a2, a3, a4); |
||
10867 | fschmid | 930 | double len = Bez.length(); |
931 | if (len > 0.0) |
||
10532 | avox | 932 | { |
10867 | fschmid | 933 | double delta = 2.0 / len; |
934 | for (double d = 0.0; d <= 1.0; d += delta) |
||
10532 | avox | 935 | { |
10867 | fschmid | 936 | QPointF pl = Bez.pointAtPercent(d); |
937 | if (m_canvas->hitsCanvasPoint(m->globalPos(), FPoint(pl.x(), pl.y()))) |
||
938 | { |
||
939 | if (m_doc->nodeEdit.submode == NodeEditContext::MOVE_POINT) |
||
18921 | jghali | 940 | m_view->setCursor(QCursor(loadIcon("HandC.xpm"))); |
11676 | avox | 941 | else if (m_doc->nodeEdit.submode == NodeEditContext::ADD_POINT) |
18921 | jghali | 942 | m_view->setCursor(QCursor(loadIcon("AddPoint.png"), 1, 1)); |
11676 | avox | 943 | else if (m_doc->nodeEdit.submode == NodeEditContext::SPLIT_PATH) |
18921 | jghali | 944 | m_view->setCursor(QCursor(loadIcon("Split.png"), 1, 1)); |
11676 | avox | 945 | else |
18921 | jghali | 946 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
10867 | fschmid | 947 | m_doc->nodeEdit.ClRe2 = poi; |
948 | return true; |
||
949 | } |
||
10532 | avox | 950 | } |
951 | } |
||
952 | } |
||
953 | } |
||
18921 | jghali | 954 | m_view->setCursor(QCursor(Qt::ArrowCursor)); |
10532 | avox | 955 | return false; |
956 | } |
||
957 | |||
958 | void CanvasMode_NodeEdit::handleNodeEditDrag(QMouseEvent* m, PageItem* currItem) |
||
959 | { |
||
11395 | fschmid | 960 | FPoint npf; |
10532 | avox | 961 | if ((m_canvas->m_viewMode.m_MouseButtonPressed) && !m_doc->nodeEdit.hasNodeSelected() && (m_doc->nodeEdit.SegP1 == -1) && (m_doc->nodeEdit.SegP2 == -1)) |
962 | { |
||
10701 | avox | 963 | if (!m_rectangleSelect) |
964 | { |
||
965 | m_rectangleSelect = new RectSelect(this); |
||
966 | } |
||
11339 | avox | 967 | m_rectangleSelect->prepare(m->globalPos()); |
11395 | fschmid | 968 | m_view->startGesture(m_rectangleSelect); |
10532 | avox | 969 | return; |
970 | } |
||
971 | int newX = m->x(); |
||
972 | int newY = m->y(); |
||
973 | FPoint np(newX-Mxp, newY-Myp, 0, 0, currItem->rotation(), 1, 1, true); |
||
11395 | fschmid | 974 | np = np * (1.0 / m_canvas->scale()); |
10532 | avox | 975 | m_canvas->m_viewMode.operItemMoving = true; |
976 | currItem = m_doc->m_Selection->itemAt(0); |
||
977 | if ((m_doc->nodeEdit.SegP1 != -1) && (m_doc->nodeEdit.SegP2 != -1)) |
||
978 | { |
||
11395 | fschmid | 979 | if (m_doc->nodeEdit.isContourLine) |
980 | npf = currItem->ContourLine.point(m_doc->nodeEdit.SegP2) + np; |
||
981 | else |
||
982 | npf = currItem->PoLine.point(m_doc->nodeEdit.SegP2) + np; |
||
10532 | avox | 983 | m_doc->nodeEdit.ClRe = m_doc->nodeEdit.SegP2; |
984 | m_doc->nodeEdit.moveClipPoint(currItem, npf); |
||
985 | if (m_doc->nodeEdit.isContourLine) |
||
11395 | fschmid | 986 | npf = currItem->ContourLine.point(m_doc->nodeEdit.SegP1) + np; |
10532 | avox | 987 | else |
11395 | fschmid | 988 | npf = currItem->PoLine.point(m_doc->nodeEdit.SegP1) + np; |
10532 | avox | 989 | m_doc->nodeEdit.ClRe = m_doc->nodeEdit.SegP1; |
11395 | fschmid | 990 | m_doc->nodeEdit.moveClipPoint(currItem, npf); |
10532 | avox | 991 | Mxp = newX; |
992 | Myp = newY; |
||
993 | } |
||
994 | else |
||
995 | { |
||
996 | if ((m_doc->nodeEdit.SelNode.count() != 0) && (m_doc->nodeEdit.EdPoints)) |
||
997 | { |
||
998 | int storedClRe = m_doc->nodeEdit.ClRe; |
||
11788 | fschmid | 999 | if (m_doc->nodeEdit.SelNode.count() == 1) |
10532 | avox | 1000 | { |
11788 | fschmid | 1001 | npf = m_canvas->globalToCanvas(m->globalPos()); |
1002 | double nx = npf.x(); |
||
1003 | double ny = npf.y(); |
||
1004 | if (!m_doc->ApplyGuides(&nx, &ny)) |
||
1005 | npf = m_doc->ApplyGridF(FPoint(nx, ny)); |
||
11395 | fschmid | 1006 | else |
11788 | fschmid | 1007 | npf = FPoint(nx, ny); |
1008 | npf = FPoint(npf.x(), npf.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true); |
||
1009 | m_doc->nodeEdit.moveClipPoint(currItem, npf); |
||
12656 | fschmid | 1010 | m_canvas->displayXYHUD(m->globalPos(), npf.x(), npf.y()); |
11788 | fschmid | 1011 | } |
1012 | else |
||
1013 | { |
||
1014 | for (int itm = 0; itm < m_doc->nodeEdit.SelNode.count(); ++itm) |
||
10532 | avox | 1015 | { |
11788 | fschmid | 1016 | m_doc->nodeEdit.ClRe = m_doc->nodeEdit.SelNode.at(itm); |
1017 | if (m_doc->nodeEdit.isContourLine) |
||
1018 | npf = currItem->ContourLine.point(m_doc->nodeEdit.ClRe) + np; |
||
11395 | fschmid | 1019 | else |
11788 | fschmid | 1020 | npf = currItem->PoLine.point(m_doc->nodeEdit.ClRe) + np; |
1021 | m_doc->nodeEdit.moveClipPoint(currItem, npf); |
||
10532 | avox | 1022 | } |
1023 | } |
||
1024 | m_doc->nodeEdit.ClRe = storedClRe; |
||
1025 | } |
||
1026 | else |
||
1027 | { |
||
13447 | jghali | 1028 | npf = m_canvas->globalToCanvas(m->globalPos()); |
10701 | avox | 1029 | double nx = npf.x(); |
1030 | double ny = npf.y(); |
||
1031 | if (!m_doc->ApplyGuides(&nx, &ny)) |
||
1032 | npf = m_doc->ApplyGridF(FPoint(nx, ny)); |
||
1033 | else |
||
1034 | npf = FPoint(nx, ny); |
||
11788 | fschmid | 1035 | npf = FPoint(npf.x(), npf.y(), currItem->xPos(), currItem->yPos(), currItem->rotation(), 1, 1, true); |
10532 | avox | 1036 | m_doc->nodeEdit.moveClipPoint(currItem, npf); |
12656 | fschmid | 1037 | m_canvas->displayXYHUD(m->globalPos(), npf.x(), npf.y()); |
10532 | avox | 1038 | } |
1039 | Mxp = newX; |
||
1040 | Myp = newY; |
||
1041 | } |
||
1042 | m_canvas->m_viewMode.operItemMoving = false; |
||
11153 | fschmid | 1043 | m_doc->regionsChanged()->update(QRectF()); |
10532 | avox | 1044 | } |
1045 |