author | Wuzzy <Wuzzy2@mail.ru> |
Sat, 03 Nov 2018 15:27:27 +0100 | |
changeset 14118 | 589a752c01ca |
parent 13910 | 6c8d4e140f27 |
permissions | -rw-r--r-- |
4976 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10002
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 17 |
*/ |
18 |
||
4423 | 19 |
#include <QGraphicsSceneMouseEvent> |
4426 | 20 |
#include <QGraphicsPathItem> |
4427 | 21 |
#include <QtEndian> |
4937 | 22 |
#include <QDebug> |
9555 | 23 |
#include <QTransform> |
9551 | 24 |
#include <math.h> |
4423 | 25 |
|
26 |
#include "drawmapscene.h" |
|
27 |
||
13204
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
28 |
#define DRAWN_MAP_COLOR_LAND (Qt::yellow) |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
29 |
#define DRAWN_MAP_COLOR_CURSOR_PEN (Qt::green) |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
30 |
#define DRAWN_MAP_COLOR_CURSOR_ERASER (Qt::red) |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
31 |
|
13910 | 32 |
#ifndef M_PI |
33 |
#define M_PI 3.14159265358979323846 |
|
34 |
#endif |
|
35 |
||
4434 | 36 |
template <class T> T sqr(const T & x) |
37 |
{ |
|
38 |
return x*x; |
|
39 |
} |
|
40 |
||
4423 | 41 |
DrawMapScene::DrawMapScene(QObject *parent) : |
4424 | 42 |
QGraphicsScene(parent), |
13204
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
43 |
m_pen(DRAWN_MAP_COLOR_LAND), |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
44 |
m_brush(DRAWN_MAP_COLOR_LAND), |
13203
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
45 |
m_cursor(new QGraphicsEllipseItem(-5, -5, 5, 5)) |
4423 | 46 |
{ |
47 |
setSceneRect(0, 0, 4096, 2048); |
|
4424 | 48 |
|
49 |
QLinearGradient gradient(0, 0, 0, 2048); |
|
4426 | 50 |
gradient.setColorAt(0, QColor(60, 60, 155)); |
51 |
gradient.setColorAt(1, QColor(155, 155, 60)); |
|
6873 | 52 |
|
53 |
m_eraser = QBrush(gradient); |
|
54 |
setBackgroundBrush(m_eraser); |
|
55 |
m_isErasing = false; |
|
4424 | 56 |
|
9551 | 57 |
m_pathType = Polyline; |
58 |
||
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
59 |
m_pen.setWidth(DRAWN_MAP_BRUSH_SIZE_START); |
4426 | 60 |
m_pen.setJoinStyle(Qt::RoundJoin); |
61 |
m_pen.setCapStyle(Qt::RoundCap); |
|
62 |
m_currPath = 0; |
|
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
63 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
64 |
m_isCursorShown = false; |
13204
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
65 |
QPen cursorPen = QPen(DRAWN_MAP_COLOR_CURSOR_PEN); |
13203
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
66 |
cursorPen.setJoinStyle(Qt::RoundJoin); |
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
67 |
cursorPen.setCapStyle(Qt::RoundCap); |
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
68 |
cursorPen.setWidth(brushSize()); |
13203
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
69 |
m_cursor->setPen(cursorPen); |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
70 |
m_cursor->setZValue(1); |
4423 | 71 |
} |
72 |
||
73 |
void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
|
74 |
{ |
|
4426 | 75 |
if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton)) |
76 |
{ |
|
77 |
QPainterPath path = m_currPath->path(); |
|
9555 | 78 |
QPointF currentPos = mouseEvent->scenePos(); |
79 |
||
80 |
if(mouseEvent->modifiers() & Qt::ControlModifier) |
|
81 |
currentPos = putSomeConstraints(paths.first().initialPoint, currentPos); |
|
4937 | 82 |
|
9551 | 83 |
switch (m_pathType) |
4937 | 84 |
{ |
9551 | 85 |
case Polyline: |
86 |
if(mouseEvent->modifiers() & Qt::ControlModifier) |
|
87 |
{ |
|
88 |
int c = path.elementCount(); |
|
9555 | 89 |
path.setElementPositionAt(c - 1, currentPos.x(), currentPos.y()); |
4937 | 90 |
|
9551 | 91 |
} |
92 |
else |
|
93 |
{ |
|
9555 | 94 |
path.lineTo(currentPos); |
9551 | 95 |
paths.first().points.append(mouseEvent->scenePos().toPoint()); |
96 |
} |
|
97 |
break; |
|
98 |
case Rectangle: { |
|
99 |
path = QPainterPath(); |
|
100 |
QPointF p1 = paths.first().initialPoint; |
|
9555 | 101 |
QPointF p2 = currentPos; |
9551 | 102 |
path.moveTo(p1); |
103 |
path.lineTo(p1.x(), p2.y()); |
|
104 |
path.lineTo(p2); |
|
105 |
path.lineTo(p2.x(), p1.y()); |
|
106 |
path.lineTo(p1); |
|
107 |
break; |
|
108 |
} |
|
109 |
case Ellipse: { |
|
110 |
path = QPainterPath(); |
|
9555 | 111 |
QList<QPointF> points = makeEllipse(paths.first().initialPoint, currentPos); |
9551 | 112 |
path.addPolygon(QPolygonF(QVector<QPointF>::fromList(points))); |
113 |
break; |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
114 |
} |
4937 | 115 |
} |
9551 | 116 |
|
4426 | 117 |
m_currPath->setPath(path); |
4427 | 118 |
|
119 |
emit pathChanged(); |
|
4426 | 120 |
} |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
121 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
122 |
if(!m_isCursorShown) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
123 |
showCursor(); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
124 |
m_cursor->setPos(mouseEvent->scenePos()); |
4423 | 125 |
} |
126 |
||
127 |
void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) |
|
128 |
{ |
|
4426 | 129 |
m_currPath = addPath(QPainterPath(), m_pen); |
130 |
||
131 |
QPainterPath path = m_currPath->path(); |
|
132 |
QPointF p = mouseEvent->scenePos(); |
|
133 |
p += QPointF(0.01, 0.01); |
|
134 |
path.moveTo(p); |
|
135 |
path.lineTo(mouseEvent->scenePos()); |
|
6873 | 136 |
|
137 |
PathParams params; |
|
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
138 |
params.width = serializePenWidth(brushSize()); |
6873 | 139 |
params.erasing = m_isErasing; |
9551 | 140 |
params.initialPoint = mouseEvent->scenePos().toPoint(); |
141 |
params.points = QList<QPoint>() << params.initialPoint; |
|
6873 | 142 |
paths.prepend(params); |
4426 | 143 |
m_currPath->setPath(path); |
144 |
||
4427 | 145 |
emit pathChanged(); |
4423 | 146 |
} |
147 |
||
148 |
void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
|
149 |
{ |
|
5108
b7483e29ea8c
Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents:
5040
diff
changeset
|
150 |
if (m_currPath) |
b7483e29ea8c
Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents:
5040
diff
changeset
|
151 |
{ |
9555 | 152 |
QPointF currentPos = mouseEvent->scenePos(); |
153 |
||
154 |
if(mouseEvent->modifiers() & Qt::ControlModifier) |
|
155 |
currentPos = putSomeConstraints(paths.first().initialPoint, currentPos); |
|
156 |
||
9551 | 157 |
switch (m_pathType) |
158 |
{ |
|
159 |
case Polyline: { |
|
160 |
QPainterPath path = m_currPath->path(); |
|
161 |
path.lineTo(mouseEvent->scenePos()); |
|
9555 | 162 |
paths.first().points.append(currentPos.toPoint()); |
9551 | 163 |
m_currPath->setPath(path); |
9553 | 164 |
simplifyLast(); |
9551 | 165 |
break; |
166 |
} |
|
167 |
case Rectangle: { |
|
168 |
QPoint p1 = paths.first().initialPoint; |
|
9555 | 169 |
QPoint p2 = currentPos.toPoint(); |
9551 | 170 |
QList<QPoint> rpoints; |
171 |
rpoints << p1 << QPoint(p1.x(), p2.y()) << p2 << QPoint(p2.x(), p1.y()) << p1; |
|
172 |
paths.first().points = rpoints; |
|
173 |
break; |
|
174 |
} |
|
175 |
case Ellipse: |
|
176 |
QPoint p1 = paths.first().initialPoint; |
|
9555 | 177 |
QPoint p2 = currentPos.toPoint(); |
9551 | 178 |
QList<QPointF> points = makeEllipse(p1, p2); |
179 |
QList<QPoint> epoints; |
|
180 |
foreach(const QPointF & p, points) |
|
181 |
epoints.append(p.toPoint()); |
|
182 |
paths.first().points = epoints; |
|
183 |
break; |
|
184 |
} |
|
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
185 |
|
9553 | 186 |
m_currPath = 0; |
4439 | 187 |
|
9553 | 188 |
emit pathChanged(); |
5108
b7483e29ea8c
Fixing issue 211. Check to see if m_currPath is NULL before doing anything in mouseReleaseEvent. Multiple mouse release events can occur after a mouse press and before the next mouse press if you mouse-click really fast.
Zorg <zorgiepoo@gmail.com>
parents:
5040
diff
changeset
|
189 |
} |
4423 | 190 |
} |
4424 | 191 |
|
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
192 |
void DrawMapScene::setBrushSize(int newBrushSize) |
6781 | 193 |
{ |
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
194 |
if(newBrushSize > DRAWN_MAP_BRUSH_SIZE_MAX) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
195 |
newBrushSize = DRAWN_MAP_BRUSH_SIZE_MAX; |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
196 |
if(newBrushSize < DRAWN_MAP_BRUSH_SIZE_MIN) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
197 |
newBrushSize = DRAWN_MAP_BRUSH_SIZE_MIN; |
6781 | 198 |
|
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
199 |
m_pen.setWidth(newBrushSize); |
13203
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
200 |
QPen cursorPen = m_cursor->pen(); |
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
201 |
cursorPen.setWidth(m_pen.width()); |
eaa494f0b19e
Fix cursor circle being too large in drawn map editor
Wuzzy <Wuzzy2@mail.ru>
parents:
11046
diff
changeset
|
202 |
m_cursor->setPen(cursorPen); |
6781 | 203 |
if(m_currPath) |
204 |
{ |
|
205 |
m_currPath->setPen(m_pen); |
|
6873 | 206 |
paths.first().width = serializePenWidth(m_pen.width()); |
6781 | 207 |
} |
13209
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
208 |
|
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
209 |
emit brushSizeChanged(newBrushSize); |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
210 |
} |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
211 |
|
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
212 |
int DrawMapScene::brushSize() |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
213 |
{ |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
214 |
return m_pen.width(); |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
215 |
} |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
216 |
|
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
217 |
void DrawMapScene::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
218 |
{ |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
219 |
int b = brushSize(); |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
220 |
if(wheelEvent->delta() > 0) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
221 |
setBrushSize(b + DRAWN_MAP_BRUSH_SIZE_STEP); |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
222 |
else if(wheelEvent->delta() < 0 && b >= DRAWN_MAP_BRUSH_SIZE_MIN) |
f5d36be88c61
Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents:
13204
diff
changeset
|
223 |
setBrushSize(b - DRAWN_MAP_BRUSH_SIZE_STEP); |
6781 | 224 |
} |
225 |
||
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
226 |
void DrawMapScene::showCursor() |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
227 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
228 |
if(!m_isCursorShown) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
229 |
addItem(m_cursor); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
230 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
231 |
m_isCursorShown = true; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
232 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
233 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
234 |
void DrawMapScene::hideCursor() |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
235 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
236 |
if(m_isCursorShown) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
237 |
removeItem(m_cursor); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
238 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
239 |
m_isCursorShown = false; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
240 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
241 |
|
4426 | 242 |
void DrawMapScene::undo() |
4424 | 243 |
{ |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
244 |
// cursor is a part of items() |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
245 |
if(m_isCursorShown) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
246 |
return; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
247 |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
248 |
if(paths.size()) |
4427 | 249 |
{ |
4426 | 250 |
removeItem(items().first()); |
4439 | 251 |
paths.removeFirst(); |
4427 | 252 |
|
253 |
emit pathChanged(); |
|
254 |
} |
|
5858
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
255 |
else if(oldItems.size()) |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
256 |
{ |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
257 |
while(oldItems.size()) |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
258 |
addItem(oldItems.takeFirst()); |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
259 |
paths = oldPaths; |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
260 |
|
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
261 |
emit pathChanged(); |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
262 |
} |
4424 | 263 |
} |
4427 | 264 |
|
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
265 |
void DrawMapScene::clearMap() |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
266 |
{ |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
267 |
// cursor is a part of items() |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
268 |
if(m_isCursorShown) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
269 |
return; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
270 |
|
5858
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
271 |
// don't clear if already cleared |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
272 |
if(!items().size()) |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
273 |
return; |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
274 |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
275 |
m_specialPoints.clear(); |
5858
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
276 |
oldItems.clear(); |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
277 |
|
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
278 |
// do this since clear() would _destroy_ all items |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
279 |
for(int i = paths.size() - 1; i >= 0; --i) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
280 |
{ |
5858
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
281 |
oldItems.push_front(items().first()); |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
282 |
removeItem(items().first()); |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
283 |
} |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
284 |
|
9483
14ad1ac00ac9
Modify Racer script so it could work with special points
unc0rr
parents:
9472
diff
changeset
|
285 |
items().clear(); |
14ad1ac00ac9
Modify Racer script so it could work with special points
unc0rr
parents:
9472
diff
changeset
|
286 |
|
5858
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
287 |
oldPaths = paths; |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
288 |
|
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
289 |
paths.clear(); |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
290 |
|
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
291 |
emit pathChanged(); |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
292 |
} |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
293 |
|
6873 | 294 |
|
295 |
void DrawMapScene::setErasing(bool erasing) |
|
296 |
{ |
|
297 |
m_isErasing = erasing; |
|
13204
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
298 |
QPen cursorPen = m_cursor->pen(); |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
299 |
if(erasing) { |
6873 | 300 |
m_pen.setBrush(m_eraser); |
13204
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
301 |
cursorPen.setColor(DRAWN_MAP_COLOR_CURSOR_ERASER); |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
302 |
} else { |
6873 | 303 |
m_pen.setBrush(m_brush); |
13204
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
304 |
cursorPen.setColor(DRAWN_MAP_COLOR_CURSOR_PEN); |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
305 |
} |
9565569e410c
Drawn map page: Enable antialiasing, turn eraser cursor red
Wuzzy <Wuzzy2@mail.ru>
parents:
13203
diff
changeset
|
306 |
m_cursor->setPen(cursorPen); |
6873 | 307 |
} |
308 |
||
4427 | 309 |
QByteArray DrawMapScene::encode() |
310 |
{ |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
311 |
QByteArray b(m_specialPoints); |
4427 | 312 |
|
4666 | 313 |
for(int i = paths.size() - 1; i >= 0; --i) |
4427 | 314 |
{ |
315 |
int cnt = 0; |
|
6873 | 316 |
PathParams params = paths.at(i); |
317 |
foreach(QPoint point, params.points) |
|
4427 | 318 |
{ |
319 |
qint16 px = qToBigEndian((qint16)point.x()); |
|
320 |
qint16 py = qToBigEndian((qint16)point.y()); |
|
6781 | 321 |
quint8 flags = 0; |
7298
a5f2fa95e711
Don't set erasing flag when it is unnecessary so hwmap could compress better
unc0rr
parents:
7146
diff
changeset
|
322 |
if(!cnt) |
a5f2fa95e711
Don't set erasing flag when it is unnecessary so hwmap could compress better
unc0rr
parents:
7146
diff
changeset
|
323 |
{ |
a5f2fa95e711
Don't set erasing flag when it is unnecessary so hwmap could compress better
unc0rr
parents:
7146
diff
changeset
|
324 |
flags = 0x80 + params.width; |
a5f2fa95e711
Don't set erasing flag when it is unnecessary so hwmap could compress better
unc0rr
parents:
7146
diff
changeset
|
325 |
if(params.erasing) flags |= 0x40; |
a5f2fa95e711
Don't set erasing flag when it is unnecessary so hwmap could compress better
unc0rr
parents:
7146
diff
changeset
|
326 |
} |
4427 | 327 |
b.append((const char *)&px, 2); |
328 |
b.append((const char *)&py, 2); |
|
4457 | 329 |
b.append((const char *)&flags, 1); |
4427 | 330 |
|
331 |
++cnt; |
|
332 |
} |
|
333 |
||
334 |
} |
|
335 |
||
336 |
return b; |
|
337 |
} |
|
4434 | 338 |
|
4442 | 339 |
void DrawMapScene::decode(QByteArray data) |
340 |
{ |
|
10235 | 341 |
hideCursor(); |
342 |
||
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
343 |
// Remember erasing mode |
6873 | 344 |
bool erasing = m_isErasing; |
345 |
||
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
346 |
// Use seperate for decoding the map, don't mess with the user pen |
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
347 |
QPen load_pen = QPen(m_pen); |
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
348 |
|
5858
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
349 |
oldItems.clear(); |
1f4a8cf9efcb
hand drawn map editor: allow "undo" after "clear"
sheepluva
parents:
5108
diff
changeset
|
350 |
oldPaths.clear(); |
4442 | 351 |
clear(); |
352 |
paths.clear(); |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
353 |
m_specialPoints.clear(); |
4442 | 354 |
|
6873 | 355 |
PathParams params; |
4442 | 356 |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
357 |
bool isSpecial = true; |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
358 |
|
4442 | 359 |
while(data.size() >= 5) |
360 |
{ |
|
361 |
qint16 px = qFromBigEndian(*(qint16 *)data.data()); |
|
362 |
data.remove(0, 2); |
|
363 |
qint16 py = qFromBigEndian(*(qint16 *)data.data()); |
|
364 |
data.remove(0, 2); |
|
4457 | 365 |
quint8 flags = *(quint8 *)data.data(); |
366 |
data.remove(0, 1); |
|
10235 | 367 |
//qDebug() << px << py; |
6781 | 368 |
if(flags & 0x80) |
4442 | 369 |
{ |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
370 |
isSpecial = false; |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
371 |
|
6873 | 372 |
if(params.points.size()) |
6781 | 373 |
{ |
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
374 |
addPath(pointsToPath(params.points), load_pen); |
6781 | 375 |
|
6873 | 376 |
paths.prepend(params); |
4666 | 377 |
|
6873 | 378 |
params.points.clear(); |
6781 | 379 |
} |
380 |
||
6873 | 381 |
quint8 penWidth = flags & 0x3f; |
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
382 |
load_pen.setWidth(deserializePenWidth(penWidth)); |
7146 | 383 |
params.erasing = flags & 0x40; |
384 |
if(params.erasing) |
|
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
385 |
load_pen.setBrush(m_eraser); |
6873 | 386 |
else |
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
387 |
load_pen.setBrush(m_brush); |
6873 | 388 |
params.width = penWidth; |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
389 |
} else |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
390 |
if(isSpecial) |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
391 |
{ |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
392 |
QPainterPath path; |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
393 |
path.addEllipse(QPointF(px, py), 10, 10); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
394 |
|
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
395 |
addPath(path); |
4442 | 396 |
|
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
397 |
qint16 x = qToBigEndian(px); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
398 |
qint16 y = qToBigEndian(py); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
399 |
m_specialPoints.append((const char *)&x, 2); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
400 |
m_specialPoints.append((const char *)&y, 2); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
401 |
m_specialPoints.append((const char *)&flags, 1); |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
402 |
} |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
403 |
|
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
404 |
if(!isSpecial) |
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9080
diff
changeset
|
405 |
params.points.append(QPoint(px, py)); |
4666 | 406 |
} |
407 |
||
6873 | 408 |
if(params.points.size()) |
4666 | 409 |
{ |
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
410 |
addPath(pointsToPath(params.points), load_pen); |
6873 | 411 |
paths.prepend(params); |
4442 | 412 |
} |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
413 |
|
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
414 |
emit pathChanged(); |
6873 | 415 |
|
13236
ef1393c6bd12
Draw map page: Fix pen size being changed after loading a map
Wuzzy <Wuzzy2@mail.ru>
parents:
13209
diff
changeset
|
416 |
// Restore erasing mode |
6873 | 417 |
setErasing(erasing); |
4442 | 418 |
} |
419 |
||
4439 | 420 |
void DrawMapScene::simplifyLast() |
4434 | 421 |
{ |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
422 |
if(!paths.size()) return; |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4520
diff
changeset
|
423 |
|
6873 | 424 |
QList<QPoint> points = paths.at(0).points; |
4439 | 425 |
|
426 |
QPoint prevPoint = points.first(); |
|
427 |
int i = 1; |
|
428 |
while(i < points.size()) |
|
4434 | 429 |
{ |
10223
b6b98dfa3807
Optimize out path closing point for one point paths
unc0rr
parents:
10108
diff
changeset
|
430 |
if( ((i != points.size() - 1) || (prevPoint == points[i])) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
431 |
&& (sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000) |
4471 | 432 |
) |
4439 | 433 |
points.removeAt(i); |
434 |
else |
|
435 |
{ |
|
436 |
prevPoint = points[i]; |
|
437 |
++i; |
|
438 |
} |
|
439 |
} |
|
4434 | 440 |
|
6873 | 441 |
paths[0].points = points; |
4439 | 442 |
|
443 |
||
444 |
// redraw path |
|
445 |
{ |
|
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
446 |
QGraphicsPathItem * pathItem = static_cast<QGraphicsPathItem *>(items()[m_isCursorShown ? 1 : 0]); |
6873 | 447 |
pathItem->setPath(pointsToPath(paths[0].points)); |
4434 | 448 |
} |
449 |
} |
|
4442 | 450 |
|
6935 | 451 |
int DrawMapScene::pointsCount() |
452 |
{ |
|
453 |
int cnt = 0; |
|
454 |
foreach(PathParams p, paths) |
|
455 |
cnt += p.points.size(); |
|
456 |
||
457 |
return cnt; |
|
458 |
} |
|
459 |
||
4442 | 460 |
QPainterPath DrawMapScene::pointsToPath(const QList<QPoint> points) |
461 |
{ |
|
462 |
QPainterPath path; |
|
463 |
||
464 |
if(points.size()) |
|
465 |
{ |
|
466 |
QPointF p = points[0] + QPointF(0.01, 0.01); |
|
467 |
path.moveTo(p); |
|
468 |
||
469 |
foreach(QPoint p, points) |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
5858
diff
changeset
|
470 |
path.lineTo(p); |
4442 | 471 |
} |
472 |
||
473 |
return path; |
|
474 |
} |
|
6781 | 475 |
|
476 |
quint8 DrawMapScene::serializePenWidth(int width) |
|
477 |
{ |
|
478 |
return (width - 6) / 10; |
|
479 |
} |
|
480 |
||
481 |
int DrawMapScene::deserializePenWidth(quint8 width) |
|
482 |
{ |
|
483 |
return width * 10 + 6; |
|
484 |
} |
|
9551 | 485 |
|
486 |
void DrawMapScene::setPathType(PathType pathType) |
|
487 |
{ |
|
488 |
m_pathType = pathType; |
|
489 |
} |
|
490 |
||
491 |
QList<QPointF> DrawMapScene::makeEllipse(const QPointF ¢er, const QPointF &corner) |
|
492 |
{ |
|
493 |
QList<QPointF> l; |
|
494 |
qreal rx = qAbs(center.x() - corner.x()); |
|
495 |
qreal ry = qAbs(center.y() - corner.y()); |
|
9553 | 496 |
qreal r = qMax(rx, ry); |
9551 | 497 |
|
498 |
if(r < 4) |
|
499 |
{ |
|
500 |
l.append(center); |
|
501 |
} else |
|
502 |
{ |
|
9949
2aa9cf5badfc
Added cast to qreal, avoiding ftbfs due to issue #758
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9555
diff
changeset
|
503 |
qreal angleDelta = qMax(static_cast<qreal> (0.1), qMin(static_cast<qreal> (0.7), 120 / r)); |
9551 | 504 |
for(qreal angle = 0.0; angle < 2*M_PI; angle += angleDelta) |
505 |
l.append(center + QPointF(rx * cos(angle), ry * sin(angle))); |
|
506 |
l.append(l.first()); |
|
507 |
} |
|
508 |
||
509 |
return l; |
|
510 |
} |
|
9555 | 511 |
|
512 |
QPointF DrawMapScene::putSomeConstraints(const QPointF &initialPoint, const QPointF &point) |
|
513 |
{ |
|
514 |
QPointF vector = point - initialPoint; |
|
515 |
||
516 |
for(int angle = 0; angle < 180; angle += 15) |
|
517 |
{ |
|
518 |
QTransform transform; |
|
519 |
transform.rotate(angle); |
|
520 |
||
521 |
QPointF rotated = transform.map(vector); |
|
522 |
||
523 |
if(rotated.x() == 0) return point; |
|
524 |
if(qAbs(rotated.y() / rotated.x()) < 0.05) return initialPoint + transform.inverted().map(QPointF(rotated.x(), 0)); |
|
525 |
} |
|
526 |
||
527 |
return point; |
|
528 |
} |
|
10235 | 529 |
|
530 |
void DrawMapScene::optimize() |
|
531 |
{ |
|
532 |
if(!paths.size()) return; |
|
533 |
||
534 |
// break paths into segments |
|
535 |
Paths pth; |
|
536 |
||
537 |
foreach(const PathParams & pp, paths) |
|
538 |
{ |
|
539 |
int l = pp.points.size(); |
|
540 |
||
541 |
if(l == 1) |
|
542 |
{ |
|
543 |
pth.prepend(pp); |
|
544 |
} else |
|
545 |
{ |
|
546 |
for(int i = l - 2; i >= 0; --i) |
|
547 |
{ |
|
548 |
PathParams p = pp; |
|
549 |
p.points = QList<QPoint>() << p.points[i] << p.points[i + 1]; |
|
550 |
pth.prepend(pp); |
|
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
||
555 |
// clear the scene |
|
556 |
oldItems.clear(); |
|
557 |
oldPaths.clear(); |
|
558 |
clear(); |
|
559 |
paths.clear(); |
|
560 |
m_specialPoints.clear(); |
|
561 |
||
562 |
// render the result |
|
563 |
foreach(const PathParams & p, pth) |
|
564 |
{ |
|
565 |
if(p.erasing) |
|
566 |
m_pen.setBrush(m_eraser); |
|
567 |
else |
|
568 |
m_pen.setBrush(m_brush); |
|
569 |
||
570 |
m_pen.setWidth(deserializePenWidth(p.width)); |
|
571 |
||
572 |
addPath(pointsToPath(p.points), m_pen); |
|
573 |
} |
|
574 |
||
575 |
emit pathChanged(); |
|
576 |
} |