Rev 21222 | Rev 22630 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
12067 | fschmid | 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 | * Copyright (C) 2008 by Franz Schmid * |
||
9 | * franz.schmid@altmuehlnet.de * |
||
10 | * * |
||
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | * This program is distributed in the hope that it will be useful, * |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
19 | * GNU General Public License for more details. * |
||
20 | * * |
||
21 | * You should have received a copy of the GNU General Public License * |
||
22 | * along with this program; if not, write to the * |
||
23 | * Free Software Foundation, Inc., * |
||
18122 | mrdocs | 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
12067 | fschmid | 25 | ***************************************************************************/ |
26 | |||
27 | #include "meshdistortiondialog.h" |
||
28 | |||
22440 | jghali | 29 | #include <QGraphicsItem> |
30 | #include <QGraphicsSceneHoverEvent> |
||
31 | #include <QGraphicsSceneMouseEvent> |
||
12067 | fschmid | 32 | #include <QPainterPath> |
22440 | jghali | 33 | #include <QStyleOptionGraphicsItem> |
12519 | fschmid | 34 | |
12067 | fschmid | 35 | #include "commonstrings.h" |
36 | #include "fpointarray.h" |
||
22440 | jghali | 37 | #include "iconmanager.h" |
12067 | fschmid | 38 | #include "pageitem.h" |
16311 | fschmid | 39 | #include "pageitem_group.h" |
12067 | fschmid | 40 | #include "sccolorengine.h" |
41 | #include "scpattern.h" |
||
42 | #include "selection.h" |
||
43 | #include "util_math.h" |
||
44 | |||
45 | NodeItem::NodeItem(QRectF geom, uint num, MeshDistortionDialog *parent) : QGraphicsEllipseItem(geom) |
||
46 | { |
||
47 | dialog = parent; |
||
48 | handle = num; |
||
12519 | fschmid | 49 | setBrush(Qt::NoBrush); |
50 | setPen(QPen(Qt::red, 2.0)); |
||
12067 | fschmid | 51 | setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); |
52 | setZValue(9999999); |
||
18194 | fschmid | 53 | acceptHoverEvents(); |
12067 | fschmid | 54 | mouseMoving = false; |
55 | mousePressed = false; |
||
56 | } |
||
57 | |||
12519 | fschmid | 58 | void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
59 | { |
||
60 | Q_UNUSED(widget); |
||
61 | if (option->state & QStyle::State_Selected) |
||
62 | { |
||
63 | painter->setBrush(Qt::red); |
||
64 | painter->setPen(QPen(Qt::red, qMax(0.1, 1.0 / option->levelOfDetail))); |
||
65 | } |
||
66 | else |
||
67 | { |
||
68 | painter->setBrush(Qt::NoBrush); |
||
69 | painter->setPen(QPen(Qt::red, qMax(0.2, 2.0 / option->levelOfDetail))); |
||
70 | } |
||
71 | painter->drawEllipse(rect()); |
||
72 | } |
||
73 | |||
12067 | fschmid | 74 | void NodeItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
75 | { |
||
76 | mousePressed = true; |
||
77 | mouseMoving = false; |
||
78 | QGraphicsItem::mousePressEvent(event); |
||
79 | } |
||
80 | |||
81 | void NodeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
||
82 | { |
||
83 | mouseMoving = true; |
||
84 | if ((mouseMoving) && (mousePressed)) |
||
12511 | fschmid | 85 | dialog->updateMesh(true); |
12067 | fschmid | 86 | QGraphicsItem::mouseMoveEvent(event); |
87 | } |
||
88 | |||
89 | void NodeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
||
90 | { |
||
91 | if ((mouseMoving) && (mousePressed)) |
||
12511 | fschmid | 92 | dialog->updateMesh(false); |
12067 | fschmid | 93 | mouseMoving = false; |
94 | mousePressed = false; |
||
95 | QGraphicsItem::mouseReleaseEvent(event); |
||
96 | } |
||
97 | |||
12519 | fschmid | 98 | void NodeItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
99 | { |
||
100 | QPainterPath p; |
||
101 | p.addEllipse(rect()); |
||
102 | if (isSelected()) |
||
103 | qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor)); |
||
104 | else |
||
105 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
106 | } |
||
107 | |||
108 | void NodeItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) |
||
109 | { |
||
110 | QPainterPath p; |
||
111 | p.addEllipse(rect()); |
||
112 | if (isSelected()) |
||
113 | qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor)); |
||
114 | else |
||
115 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
116 | } |
||
117 | |||
118 | void NodeItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) |
||
119 | { |
||
120 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
121 | } |
||
122 | |||
12067 | fschmid | 123 | MeshDistortionDialog::MeshDistortionDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent) |
124 | { |
||
125 | setupUi(this); |
||
126 | setModal(true); |
||
20185 | craig | 127 | setWindowIcon(QIcon(IconManager::instance()->loadIcon("AppIcon.png"))); |
128 | buttonZoomOut->setIcon(QIcon(IconManager::instance()->loadIcon("16/zoom-out.png"))); |
||
129 | buttonZoomIn->setIcon(QIcon(IconManager::instance()->loadIcon("16/zoom-in.png"))); |
||
12067 | fschmid | 130 | m_doc = doc; |
16116 | fschmid | 131 | addItemsToScene(doc->m_Selection, doc, 0, 0); |
132 | for(unsigned dim = 0; dim < 2; dim++) |
||
133 | { |
||
134 | sb2[dim].us = 2; |
||
135 | sb2[dim].vs = 2; |
||
136 | const int depth = sb2[dim].us*sb2[dim].vs; |
||
137 | sb2[dim].resize(depth, Geom::Linear2d(0)); |
||
138 | } |
||
139 | handles.resize(sb2[0].vs*sb2[0].us*4); |
||
140 | origHandles.resize(sb2[0].vs*sb2[0].us*4); |
||
141 | unsigned ii = 0; |
||
142 | for(unsigned vi = 0; vi < sb2[0].vs; vi++) |
||
143 | { |
||
144 | for(unsigned ui = 0; ui < sb2[0].us; ui++) |
||
145 | { |
||
146 | for(unsigned iv = 0; iv < 2; iv++) |
||
147 | { |
||
148 | for(unsigned iu = 0; iu < 2; iu++) |
||
149 | { |
||
150 | handles[ii++] = Geom::Point((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | Geom::Point dir(1,-2); |
||
156 | for(unsigned dim = 0; dim < 2; dim++) |
||
157 | { |
||
158 | Geom::Point dir(0,0); |
||
159 | dir[dim] = 1; |
||
160 | for(unsigned vi = 0; vi < sb2[dim].vs; vi++) |
||
161 | { |
||
162 | for(unsigned ui = 0; ui < sb2[dim].us; ui++) |
||
163 | { |
||
164 | for(unsigned iv = 0; iv < 2; iv++) |
||
165 | { |
||
166 | for(unsigned iu = 0; iu < 2; iu++) |
||
167 | { |
||
168 | unsigned corner = iu + 2*iv; |
||
169 | unsigned i = ui + vi*sb2[dim].us; |
||
170 | Geom::Point base((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4); |
||
171 | if(vi == 0 && ui == 0) |
||
172 | base = Geom::Point(w4, w4); |
||
173 | double dl = dot((handles[corner+4*i] - base), dir)/dot(dir,dir); |
||
174 | sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0f,((int)(ui+vi))); |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | QPainterPath pathG; |
||
181 | D2sb2d2QPainterPath(&pathG, sb2, 9, ww); |
||
182 | pItemG = new QGraphicsPathItem(pathG); |
||
183 | pItemG->setPen(QPen(Qt::black)); |
||
184 | pItemG->setBrush(Qt::NoBrush); |
||
185 | pItemG->setZValue(8888888); |
||
186 | scene.addItem(pItemG); |
||
187 | for(unsigned i = 0; i < handles.size(); i++) |
||
188 | { |
||
189 | origHandles[i] = handles[i]; |
||
190 | double x = handles[i][Geom::X]; |
||
191 | double y = handles[i][Geom::Y]; |
||
192 | NodeItem* pItemN = new NodeItem(QRectF(x-4.0, y-4.0, 8.0, 8.0), i, this); |
||
193 | scene.addItem(pItemN); |
||
194 | nodeItems.append(pItemN); |
||
195 | } |
||
196 | previewLabel->setRenderHint(QPainter::Antialiasing); |
||
197 | previewLabel->setScene(&scene); |
||
198 | isFirst = true; |
||
199 | connect(buttonZoomIn, SIGNAL(clicked()), this, SLOT(doZoomIn())); |
||
200 | connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut())); |
||
201 | connect(resetButton, SIGNAL(clicked()), this, SLOT(doReset())); |
||
202 | } |
||
203 | |||
204 | void MeshDistortionDialog::addItemsToScene(Selection* itemSelection, ScribusDoc *doc, QGraphicsPathItem* parentItem, PageItem* parent) |
||
205 | { |
||
12067 | fschmid | 206 | PageItem *currItem; |
207 | double gx, gy, gh, gw; |
||
16116 | fschmid | 208 | itemSelection->setGroupRect(); |
209 | itemSelection->getGroupRect(&gx, &gy, &gw, &gh); |
||
210 | uint selectedItemCount = itemSelection->count(); |
||
16311 | fschmid | 211 | if (parentItem == 0) |
212 | { |
||
213 | w4 = qMax(gw, gh) / 2.0; |
||
214 | w2 = qMax(gw, gh); |
||
215 | ww = qMax(gw, gh) * 2.0; |
||
216 | } |
||
12067 | fschmid | 217 | for (uint i = 0; i < selectedItemCount; ++i) |
218 | { |
||
16116 | fschmid | 219 | currItem = itemSelection->itemAt(i); |
16311 | fschmid | 220 | if (currItem->isGroup()) |
221 | currItem->asGroupFrame()->adjustXYPosition(); |
||
12067 | fschmid | 222 | FPointArray path = currItem->PoLine; |
223 | deltaX = ((w2 - gw) / 2.0) + w4; |
||
224 | deltaY = ((w2 - gh) / 2.0) + w4; |
||
225 | QPainterPath pp; |
||
226 | if (currItem->itemType() == PageItem::PolyLine) |
||
227 | pp = path.toQPainterPath(false); |
||
228 | else |
||
229 | pp = path.toQPainterPath(true); |
||
16116 | fschmid | 230 | QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, parentItem); |
231 | if (parentItem == 0) |
||
12067 | fschmid | 232 | { |
233 | scene.addItem(pItem); |
||
234 | pItem->setPos(currItem->xPos() - gx + deltaX, currItem->yPos() - gy + deltaY); |
||
18194 | fschmid | 235 | pItem->setRotation(currItem->rotation()); |
12067 | fschmid | 236 | } |
237 | else |
||
238 | { |
||
16311 | fschmid | 239 | // QTransform mm; |
240 | // mm.rotate(-parent->rotation()); |
||
241 | // mm.translate(-parent->xPos(), -parent->yPos()); |
||
242 | // pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos()))); |
||
243 | pItem->setPos(QPointF(currItem->gXpos, currItem->gYpos)); |
||
18194 | fschmid | 244 | pItem->setRotation(currItem->rotation()); |
12067 | fschmid | 245 | } |
246 | QPainterPath pathO = pp; |
||
13951 | fschmid | 247 | QTransform mmO; |
12067 | fschmid | 248 | mmO.translate(-w4, -w4); |
249 | pathO = pItem->mapToScene(pathO); |
||
250 | pathO = mmO.map(pathO); |
||
15344 | fschmid | 251 | Geom::Piecewise<Geom::D2<Geom::SBasis> > path_a_pw; |
12067 | fschmid | 252 | if (currItem->itemType() == PageItem::PolyLine) |
253 | path_a_pw = QPainterPath2Piecewise(pathO, false); |
||
254 | else |
||
255 | path_a_pw = QPainterPath2Piecewise(pathO, true); |
||
256 | origPath.append(path_a_pw); |
||
257 | pItem->setZValue(i); |
||
258 | origPathItem.append(pItem); |
||
16116 | fschmid | 259 | origPageItem.append(currItem); |
260 | if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->isGroup())) |
||
12067 | fschmid | 261 | pItem->setBrush(Qt::NoBrush); |
262 | else |
||
263 | { |
||
264 | if (currItem->GrType != 0) |
||
265 | { |
||
266 | if (currItem->GrType != 8) |
||
267 | { |
||
268 | QGradient pat; |
||
269 | double x1 = currItem->GrStartX; |
||
270 | double y1 = currItem->GrStartY; |
||
271 | double x2 = currItem->GrEndX; |
||
272 | double y2 = currItem->GrEndY; |
||
273 | switch (currItem->GrType) |
||
274 | { |
||
275 | case 1: |
||
276 | case 2: |
||
277 | case 3: |
||
278 | case 4: |
||
279 | case 6: |
||
280 | pat = QLinearGradient(x1, y1, x2, y2); |
||
281 | break; |
||
282 | case 5: |
||
283 | case 7: |
||
284 | pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1); |
||
285 | break; |
||
286 | } |
||
287 | QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops(); |
||
288 | QColor qStopColor; |
||
289 | for( int offset = 0 ; offset < colorStops.count() ; offset++ ) |
||
290 | { |
||
291 | qStopColor = colorStops[ offset ]->color; |
||
292 | int h, s, v, sneu, vneu; |
||
293 | int shad = colorStops[offset]->shade; |
||
294 | qStopColor.getHsv(&h, &s, &v); |
||
295 | sneu = s * shad / 100; |
||
296 | vneu = 255 - ((255 - v) * shad / 100); |
||
297 | qStopColor.setHsv(h, sneu, vneu); |
||
298 | qStopColor.setAlphaF(colorStops[offset]->opacity); |
||
299 | pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor); |
||
300 | } |
||
301 | pItem->setBrush(pat); |
||
302 | } |
||
303 | else if ((currItem->GrType == 8) && (!currItem->pattern().isEmpty()) && (doc->docPatterns.contains(currItem->pattern()))) |
||
304 | { |
||
14260 | fschmid | 305 | double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY; |
306 | currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY); |
||
13951 | fschmid | 307 | QTransform qmatrix; |
12067 | fschmid | 308 | qmatrix.translate(patternOffsetX, patternOffsetY); |
309 | qmatrix.rotate(patternRotation); |
||
14260 | fschmid | 310 | qmatrix.shear(patternSkewX, patternSkewY); |
12067 | fschmid | 311 | qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0); |
14276 | fschmid | 312 | bool mirrorX, mirrorY; |
313 | currItem->patternFlip(mirrorX, mirrorY); |
||
314 | if (mirrorX) |
||
315 | qmatrix.scale(-1, 1); |
||
316 | if (mirrorY) |
||
317 | qmatrix.scale(1, -1); |
||
12067 | fschmid | 318 | QImage pat = *doc->docPatterns[currItem->pattern()].getPattern(); |
319 | QBrush brush = QBrush(pat); |
||
13951 | fschmid | 320 | brush.setTransform(qmatrix); |
12067 | fschmid | 321 | pItem->setBrush(brush); |
322 | } |
||
323 | } |
||
324 | else |
||
325 | { |
||
326 | QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->fillColor()], doc, currItem->fillShade()); |
||
327 | paint.setAlphaF(1.0 - currItem->fillTransparency()); |
||
328 | pItem->setBrush(paint); |
||
329 | } |
||
330 | } |
||
16116 | fschmid | 331 | if (currItem->isGroup()) |
12067 | fschmid | 332 | pItem->setPen(Qt::NoPen); |
14223 | fschmid | 333 | else if (currItem->NamedLStyle.isEmpty()) |
334 | { |
||
335 | if ((!currItem->strokePattern().isEmpty()) && (doc->docPatterns.contains(currItem->strokePattern()))) |
||
336 | { |
||
14398 | fschmid | 337 | double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY, patternSpace; |
338 | currItem->strokePatternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY, patternSpace); |
||
14223 | fschmid | 339 | QTransform qmatrix; |
340 | qmatrix.translate(-currItem->lineWidth() / 2.0, -currItem->lineWidth() / 2.0); |
||
341 | qmatrix.translate(patternOffsetX, patternOffsetY); |
||
342 | qmatrix.rotate(patternRotation); |
||
14260 | fschmid | 343 | qmatrix.shear(patternSkewX, patternSkewY); |
14223 | fschmid | 344 | qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0); |
14276 | fschmid | 345 | bool mirrorX, mirrorY; |
346 | currItem->strokePatternFlip(mirrorX, mirrorY); |
||
347 | if (mirrorX) |
||
348 | qmatrix.scale(-1, 1); |
||
349 | if (mirrorY) |
||
350 | qmatrix.scale(1, -1); |
||
14223 | fschmid | 351 | QImage pat = *doc->docPatterns[currItem->strokePattern()].getPattern(); |
352 | QBrush brush = QBrush(pat); |
||
353 | brush.setTransform(qmatrix); |
||
354 | pItem->setPen(QPen(brush, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin())); |
||
355 | } |
||
356 | else if (currItem->GrTypeStroke > 0) |
||
357 | { |
||
358 | QGradient pat; |
||
359 | double x1 = currItem->GrStrokeStartX; |
||
360 | double y1 = currItem->GrStrokeStartY; |
||
361 | double x2 = currItem->GrStrokeEndX; |
||
362 | double y2 = currItem->GrStrokeEndY; |
||
363 | if (currItem->GrTypeStroke == 6) |
||
364 | pat = QLinearGradient(x1, y1, x2, y2); |
||
365 | else |
||
366 | pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1); |
||
367 | QList<VColorStop*> colorStops = currItem->stroke_gradient.colorStops(); |
||
368 | QColor qStopColor; |
||
369 | for( int offset = 0 ; offset < colorStops.count() ; offset++ ) |
||
370 | { |
||
371 | qStopColor = colorStops[ offset ]->color; |
||
372 | int h, s, v, sneu, vneu; |
||
373 | int shad = colorStops[offset]->shade; |
||
374 | qStopColor.getHsv(&h, &s, &v); |
||
375 | sneu = s * shad / 100; |
||
376 | vneu = 255 - ((255 - v) * shad / 100); |
||
377 | qStopColor.setHsv(h, sneu, vneu); |
||
378 | qStopColor.setAlphaF(colorStops[offset]->opacity); |
||
379 | pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor); |
||
380 | } |
||
381 | pItem->setPen(QPen(pat, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin())); |
||
382 | } |
||
383 | else if (currItem->lineColor() != CommonStrings::None) |
||
384 | { |
||
385 | QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade()); |
||
386 | paint.setAlphaF(1.0 - currItem->lineTransparency()); |
||
387 | pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin())); |
||
388 | } |
||
389 | } |
||
12067 | fschmid | 390 | else |
391 | { |
||
14223 | fschmid | 392 | if (currItem->lineColor() != CommonStrings::None) |
393 | { |
||
394 | QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade()); |
||
395 | paint.setAlphaF(1.0 - currItem->lineTransparency()); |
||
396 | pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin())); |
||
397 | } |
||
12067 | fschmid | 398 | } |
16116 | fschmid | 399 | if (currItem->isGroup()) |
12067 | fschmid | 400 | { |
401 | pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
||
16116 | fschmid | 402 | Selection tmpSelection(this, false); |
403 | for (int a = 0; a < currItem->groupItemList.count(); a++) |
||
12067 | fschmid | 404 | { |
16116 | fschmid | 405 | tmpSelection.addItem(currItem->groupItemList.at(a)); |
12067 | fschmid | 406 | } |
16116 | fschmid | 407 | addItemsToScene(&tmpSelection, doc, pItem, currItem); |
12067 | fschmid | 408 | } |
409 | } |
||
410 | } |
||
411 | |||
412 | void MeshDistortionDialog::showEvent(QShowEvent *e) |
||
413 | { |
||
414 | QDialog::showEvent(e); |
||
415 | if (isFirst) |
||
416 | { |
||
417 | QRectF scR = scene.itemsBoundingRect().adjusted(-50, -50, 50, 50); |
||
418 | previewLabel->fitInView(scR, Qt::KeepAspectRatio); |
||
419 | scene.setSceneRect(scR); |
||
420 | adjustHandles(); |
||
421 | } |
||
422 | isFirst = false; |
||
423 | } |
||
424 | |||
425 | void MeshDistortionDialog::doZoomIn() |
||
426 | { |
||
427 | previewLabel->scale(2.0, 2.0); |
||
428 | adjustHandles(); |
||
429 | } |
||
430 | |||
431 | void MeshDistortionDialog::doZoomOut() |
||
432 | { |
||
433 | previewLabel->scale(0.5, 0.5); |
||
434 | adjustHandles(); |
||
435 | } |
||
436 | |||
12511 | fschmid | 437 | void MeshDistortionDialog::doReset() |
438 | { |
||
12519 | fschmid | 439 | bool found = false; |
440 | for(int n = 0; n < nodeItems.count(); n++) |
||
12511 | fschmid | 441 | { |
12519 | fschmid | 442 | if (nodeItems.at(n)->isSelected()) |
443 | { |
||
444 | found = true; |
||
445 | handles[nodeItems.at(n)->handle] = origHandles[nodeItems.at(n)->handle]; |
||
446 | } |
||
12511 | fschmid | 447 | } |
12519 | fschmid | 448 | if (!found) |
449 | { |
||
450 | for(unsigned i = 0; i < handles.size(); i++) |
||
451 | { |
||
452 | handles[i] = origHandles[i]; |
||
453 | } |
||
454 | } |
||
12511 | fschmid | 455 | adjustHandles(); |
456 | updateMesh(false); |
||
457 | } |
||
458 | |||
12067 | fschmid | 459 | void MeshDistortionDialog::adjustHandles() |
460 | { |
||
461 | double sc = previewLabel->matrix().m11(); |
||
462 | for(int n = 0; n < nodeItems.count(); n++) |
||
463 | { |
||
464 | double x = handles[n][Geom::X]; |
||
465 | double y = handles[n][Geom::Y]; |
||
12519 | fschmid | 466 | QPointF mm = nodeItems.at(n)->mapFromScene(QPointF(x - 4.0 / sc, y - 4.0 / sc)); |
467 | nodeItems.at(n)->setRect(QRectF(mm.x(), mm.y(), 8.0 / sc, 8.0 / sc)); |
||
12067 | fschmid | 468 | } |
469 | } |
||
470 | |||
12511 | fschmid | 471 | void MeshDistortionDialog::updateMesh(bool gridOnly) |
12067 | fschmid | 472 | { |
12511 | fschmid | 473 | for(int n = 0; n < nodeItems.count(); n++) |
474 | { |
||
475 | QPointF mm = nodeItems.at(n)->mapToScene(nodeItems.at(n)->rect().center()); |
||
476 | Geom::Point mouse(mm.x(), mm.y()); |
||
477 | handles[n] = mouse; |
||
478 | } |
||
12067 | fschmid | 479 | Geom::Point dir(1,-2); |
480 | for(unsigned dim = 0; dim < 2; dim++) |
||
481 | { |
||
482 | Geom::Point dir(0,0); |
||
483 | dir[dim] = 1; |
||
484 | for(unsigned vi = 0; vi < sb2[dim].vs; vi++) |
||
485 | { |
||
486 | for(unsigned ui = 0; ui < sb2[dim].us; ui++) |
||
487 | { |
||
488 | for(unsigned iv = 0; iv < 2; iv++) |
||
489 | { |
||
490 | for(unsigned iu = 0; iu < 2; iu++) |
||
491 | { |
||
492 | unsigned corner = iu + 2*iv; |
||
493 | unsigned i = ui + vi*sb2[dim].us; |
||
494 | Geom::Point base((2*(iu+ui)/(2.*ui+1)+1)*w4, (2*(iv+vi)/(2.*vi+1)+1)*w4); |
||
495 | if(vi == 0 && ui == 0) |
||
496 | base = Geom::Point(w4, w4); |
||
497 | double dl = dot((handles[corner+4*i] - base), dir)/dot(dir,dir); |
||
12731 | fschmid | 498 | sb2[dim][i][corner] = dl/(ww/2.0)*pow(4.0f,((int)(ui+vi))); |
12067 | fschmid | 499 | } |
500 | } |
||
501 | } |
||
502 | } |
||
503 | } |
||
504 | if ((!gridOnly) || (origPathItem.count() < 20)) |
||
505 | { |
||
506 | if (origPathItem.count() > 19) |
||
507 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
||
508 | for (int a = 0; a < origPathItem.count(); a++) |
||
509 | { |
||
510 | QGraphicsPathItem* pItem = origPathItem[a]; |
||
15344 | fschmid | 511 | Geom::Piecewise<Geom::D2<Geom::SBasis> > path_a_pw = origPath[a]; |
512 | Geom::Piecewise<Geom::D2<Geom::SBasis> > output; |
||
12067 | fschmid | 513 | for(unsigned i = 0; i < path_a_pw.size(); i++) |
514 | { |
||
15344 | fschmid | 515 | Geom::D2<Geom::SBasis> B = path_a_pw[i]; |
12067 | fschmid | 516 | B *= (2./ww); |
15344 | fschmid | 517 | Geom::D2<Geom::SBasis> tB = Geom::compose_each(sb2, B); |
12731 | fschmid | 518 | B = B*(ww/2.0) + Geom::Point(w4, w4); |
519 | tB = tB*(ww/2.0) + Geom::Point(w4, w4); |
||
15344 | fschmid | 520 | output.concat(Geom::Piecewise<Geom::D2<Geom::SBasis> >(tB)); |
12067 | fschmid | 521 | } |
522 | QPainterPath pathP; |
||
523 | Piecewise2QPainterPath(&pathP, output); |
||
524 | pathP = pItem->mapFromScene(pathP); |
||
525 | pItem->setPath(pathP); |
||
526 | } |
||
527 | if (origPathItem.count() > 19) |
||
528 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
529 | } |
||
530 | QPainterPath pathG; |
||
12731 | fschmid | 531 | D2sb2d2QPainterPath(&pathG, sb2, 9, ww); |
12067 | fschmid | 532 | pItemG->setPath(pathG); |
533 | } |
||
534 | |||
535 | void MeshDistortionDialog::updateAndExit() |
||
536 | { |
||
537 | qApp->changeOverrideCursor(QCursor(Qt::WaitCursor)); |
||
538 | for (int a = 0; a < origPathItem.count(); a++) |
||
539 | { |
||
15344 | fschmid | 540 | Geom::Piecewise<Geom::D2<Geom::SBasis> > path_a_pw; |
12067 | fschmid | 541 | QGraphicsPathItem* pItem = origPathItem[a]; |
542 | QPainterPath path = pItem->path(); |
||
543 | FPointArray outputPath; |
||
544 | outputPath.fromQPainterPath(path); |
||
16116 | fschmid | 545 | PageItem *currItem = origPageItem[a]; |
12067 | fschmid | 546 | currItem->PoLine = outputPath; |
547 | currItem->ClipEdited = true; |
||
548 | currItem->FrameType = 3; |
||
16118 | fschmid | 549 | double oW = currItem->width(); |
550 | double oH = currItem->height(); |
||
20694 | craig | 551 | m_doc->adjustItemSize(currItem, true); |
12067 | fschmid | 552 | currItem->OldB2 = currItem->width(); |
553 | currItem->OldH2 = currItem->height(); |
||
16118 | fschmid | 554 | if (currItem->isGroup()) |
555 | { |
||
556 | currItem->groupWidth = currItem->groupWidth * (currItem->OldB2 / oW); |
||
557 | currItem->groupHeight = currItem->groupHeight * (currItem->OldH2 / oH); |
||
21222 | fschmid | 558 | currItem->SetRectFrame(); |
16118 | fschmid | 559 | } |
12067 | fschmid | 560 | currItem->updateClip(); |
561 | currItem->ContourLine = currItem->PoLine.copy(); |
||
562 | } |
||
563 | qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor)); |
||
564 | } |