23 #include <QTransform> |
23 #include <QTransform> |
24 #include <math.h> |
24 #include <math.h> |
25 |
25 |
26 #include "drawmapscene.h" |
26 #include "drawmapscene.h" |
27 |
27 |
|
28 #define DRAWN_MAP_COLOR_LAND (Qt::yellow) |
|
29 #define DRAWN_MAP_COLOR_CURSOR_PEN (Qt::green) |
|
30 #define DRAWN_MAP_COLOR_CURSOR_ERASER (Qt::red) |
|
31 |
28 template <class T> T sqr(const T & x) |
32 template <class T> T sqr(const T & x) |
29 { |
33 { |
30 return x*x; |
34 return x*x; |
31 } |
35 } |
32 |
36 |
33 DrawMapScene::DrawMapScene(QObject *parent) : |
37 DrawMapScene::DrawMapScene(QObject *parent) : |
34 QGraphicsScene(parent), |
38 QGraphicsScene(parent), |
35 m_pen(Qt::yellow), |
39 m_pen(DRAWN_MAP_COLOR_LAND), |
36 m_brush(Qt::yellow), |
40 m_brush(DRAWN_MAP_COLOR_LAND), |
37 m_cursor(new QGraphicsEllipseItem(-5, -5, 5, 5)) |
41 m_cursor(new QGraphicsEllipseItem(-5, -5, 5, 5)) |
38 { |
42 { |
39 setSceneRect(0, 0, 4096, 2048); |
43 setSceneRect(0, 0, 4096, 2048); |
40 |
44 |
41 QLinearGradient gradient(0, 0, 0, 2048); |
45 QLinearGradient gradient(0, 0, 0, 2048); |
52 m_pen.setJoinStyle(Qt::RoundJoin); |
56 m_pen.setJoinStyle(Qt::RoundJoin); |
53 m_pen.setCapStyle(Qt::RoundCap); |
57 m_pen.setCapStyle(Qt::RoundCap); |
54 m_currPath = 0; |
58 m_currPath = 0; |
55 |
59 |
56 m_isCursorShown = false; |
60 m_isCursorShown = false; |
57 QPen cursorPen = QPen(Qt::green); |
61 QPen cursorPen = QPen(DRAWN_MAP_COLOR_CURSOR_PEN); |
58 cursorPen.setJoinStyle(Qt::RoundJoin); |
62 cursorPen.setJoinStyle(Qt::RoundJoin); |
59 cursorPen.setCapStyle(Qt::RoundCap); |
63 cursorPen.setCapStyle(Qt::RoundCap); |
60 cursorPen.setWidth(m_pen.width()); |
64 cursorPen.setWidth(m_pen.width()); |
61 m_cursor->setPen(cursorPen); |
65 m_cursor->setPen(cursorPen); |
62 m_cursor->setZValue(1); |
66 m_cursor->setZValue(1); |
269 |
273 |
270 |
274 |
271 void DrawMapScene::setErasing(bool erasing) |
275 void DrawMapScene::setErasing(bool erasing) |
272 { |
276 { |
273 m_isErasing = erasing; |
277 m_isErasing = erasing; |
274 if(erasing) |
278 QPen cursorPen = m_cursor->pen(); |
|
279 if(erasing) { |
275 m_pen.setBrush(m_eraser); |
280 m_pen.setBrush(m_eraser); |
276 else |
281 cursorPen.setColor(DRAWN_MAP_COLOR_CURSOR_ERASER); |
|
282 } else { |
277 m_pen.setBrush(m_brush); |
283 m_pen.setBrush(m_brush); |
|
284 cursorPen.setColor(DRAWN_MAP_COLOR_CURSOR_PEN); |
|
285 } |
|
286 m_cursor->setPen(cursorPen); |
278 } |
287 } |
279 |
288 |
280 QByteArray DrawMapScene::encode() |
289 QByteArray DrawMapScene::encode() |
281 { |
290 { |
282 QByteArray b(m_specialPoints); |
291 QByteArray b(m_specialPoints); |