equal
deleted
inserted
replaced
1 #include <QDebug> |
1 #include <QDebug> |
2 #include <QGraphicsSceneMouseEvent> |
2 #include <QGraphicsSceneMouseEvent> |
3 #include <QGraphicsPathItem> |
3 #include <QGraphicsPathItem> |
|
4 #include <QtEndian> |
4 |
5 |
5 #include "drawmapscene.h" |
6 #include "drawmapscene.h" |
6 |
7 |
7 DrawMapScene::DrawMapScene(QObject *parent) : |
8 DrawMapScene::DrawMapScene(QObject *parent) : |
8 QGraphicsScene(parent), |
9 QGraphicsScene(parent), |
29 |
30 |
30 if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton)) |
31 if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton)) |
31 { |
32 { |
32 QPainterPath path = m_currPath->path(); |
33 QPainterPath path = m_currPath->path(); |
33 path.lineTo(mouseEvent->scenePos()); |
34 path.lineTo(mouseEvent->scenePos()); |
|
35 paths.last().append(mouseEvent->scenePos().toPoint()); |
34 m_currPath->setPath(path); |
36 m_currPath->setPath(path); |
35 //drawFigure(mouseEvent->scenePos()); |
37 |
|
38 emit pathChanged(); |
36 } |
39 } |
37 } |
40 } |
38 |
41 |
39 void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) |
42 void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) |
40 { |
43 { |
45 QPainterPath path = m_currPath->path(); |
48 QPainterPath path = m_currPath->path(); |
46 QPointF p = mouseEvent->scenePos(); |
49 QPointF p = mouseEvent->scenePos(); |
47 p += QPointF(0.01, 0.01); |
50 p += QPointF(0.01, 0.01); |
48 path.moveTo(p); |
51 path.moveTo(p); |
49 path.lineTo(mouseEvent->scenePos()); |
52 path.lineTo(mouseEvent->scenePos()); |
|
53 paths.append(QList<QPoint>() << mouseEvent->scenePos().toPoint()); |
50 m_currPath->setPath(path); |
54 m_currPath->setPath(path); |
51 |
55 |
52 //drawFigure(mouseEvent->scenePos()); |
56 emit pathChanged(); |
53 } |
57 } |
54 |
58 |
55 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
59 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
56 { |
60 { |
57 qDebug() << "release" << mouseEvent->scenePos(); |
61 qDebug() << "release" << mouseEvent->scenePos(); |
60 } |
64 } |
61 |
65 |
62 void DrawMapScene::undo() |
66 void DrawMapScene::undo() |
63 { |
67 { |
64 if(items().size()) |
68 if(items().size()) |
|
69 { |
65 removeItem(items().first()); |
70 removeItem(items().first()); |
|
71 paths.removeLast(); |
|
72 |
|
73 emit pathChanged(); |
|
74 } |
66 } |
75 } |
|
76 |
|
77 QByteArray DrawMapScene::encode() |
|
78 { |
|
79 QByteArray b; |
|
80 |
|
81 foreach(QList<QPoint> points, paths) |
|
82 { |
|
83 int cnt = 0; |
|
84 foreach(QPoint point, points) |
|
85 { |
|
86 qint16 px = qToBigEndian((qint16)point.x()); |
|
87 qint16 py = qToBigEndian((qint16)point.y()); |
|
88 quint8 flags = 2; |
|
89 if(cnt) flags |= 0x80; |
|
90 b.append((const char *)&flags, 1); |
|
91 b.append((const char *)&px, 2); |
|
92 b.append((const char *)&py, 2); |
|
93 |
|
94 ++cnt; |
|
95 } |
|
96 |
|
97 } |
|
98 |
|
99 return b; |
|
100 } |