4423
|
1 |
#include <QDebug>
|
|
2 |
#include <QGraphicsSceneMouseEvent>
|
4426
|
3 |
#include <QGraphicsPathItem>
|
4423
|
4 |
|
|
5 |
#include "drawmapscene.h"
|
|
6 |
|
|
7 |
DrawMapScene::DrawMapScene(QObject *parent) :
|
4424
|
8 |
QGraphicsScene(parent),
|
4426
|
9 |
m_pen(Qt::yellow),
|
|
10 |
m_brush(Qt::yellow)
|
4423
|
11 |
{
|
|
12 |
setSceneRect(0, 0, 4096, 2048);
|
4424
|
13 |
|
|
14 |
QLinearGradient gradient(0, 0, 0, 2048);
|
4426
|
15 |
gradient.setColorAt(0, QColor(60, 60, 155));
|
|
16 |
gradient.setColorAt(1, QColor(155, 155, 60));
|
4424
|
17 |
setBackgroundBrush(QBrush(gradient));
|
|
18 |
|
4426
|
19 |
m_pen.setWidth(67);
|
|
20 |
m_pen.setJoinStyle(Qt::RoundJoin);
|
|
21 |
m_pen.setCapStyle(Qt::RoundCap);
|
|
22 |
m_currPath = 0;
|
4423
|
23 |
}
|
|
24 |
|
|
25 |
void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
|
26 |
{
|
|
27 |
|
|
28 |
qDebug() << "move" << mouseEvent->scenePos();
|
4424
|
29 |
|
4426
|
30 |
if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton))
|
|
31 |
{
|
|
32 |
QPainterPath path = m_currPath->path();
|
|
33 |
path.lineTo(mouseEvent->scenePos());
|
|
34 |
m_currPath->setPath(path);
|
|
35 |
//drawFigure(mouseEvent->scenePos());
|
|
36 |
}
|
4423
|
37 |
}
|
|
38 |
|
|
39 |
void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
|
40 |
{
|
|
41 |
qDebug() << "press" << mouseEvent->scenePos();
|
4424
|
42 |
|
4426
|
43 |
m_currPath = addPath(QPainterPath(), m_pen);
|
|
44 |
|
|
45 |
QPainterPath path = m_currPath->path();
|
|
46 |
QPointF p = mouseEvent->scenePos();
|
|
47 |
p += QPointF(0.01, 0.01);
|
|
48 |
path.moveTo(p);
|
|
49 |
path.lineTo(mouseEvent->scenePos());
|
|
50 |
m_currPath->setPath(path);
|
|
51 |
|
|
52 |
//drawFigure(mouseEvent->scenePos());
|
4423
|
53 |
}
|
|
54 |
|
|
55 |
void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
|
56 |
{
|
|
57 |
qDebug() << "release" << mouseEvent->scenePos();
|
4426
|
58 |
|
|
59 |
m_currPath = 0;
|
4423
|
60 |
}
|
4424
|
61 |
|
4426
|
62 |
void DrawMapScene::undo()
|
4424
|
63 |
{
|
4426
|
64 |
if(items().size())
|
|
65 |
removeItem(items().first());
|
4424
|
66 |
}
|