2 #include <QGraphicsSceneMouseEvent> |
2 #include <QGraphicsSceneMouseEvent> |
3 |
3 |
4 #include "drawmapscene.h" |
4 #include "drawmapscene.h" |
5 |
5 |
6 DrawMapScene::DrawMapScene(QObject *parent) : |
6 DrawMapScene::DrawMapScene(QObject *parent) : |
7 QGraphicsScene(parent) |
7 QGraphicsScene(parent), |
|
8 m_pen(Qt::black), |
|
9 m_brush(Qt::black) |
8 { |
10 { |
9 setSceneRect(0, 0, 4096, 2048); |
11 setSceneRect(0, 0, 4096, 2048); |
|
12 |
|
13 QLinearGradient gradient(0, 0, 0, 2048); |
|
14 gradient.setColorAt(0, QColor(160, 160, 255)); |
|
15 gradient.setColorAt(1, QColor(255, 255, 160)); |
|
16 setBackgroundBrush(QBrush(gradient)); |
|
17 |
|
18 m_halfWidth = 67; |
10 } |
19 } |
11 |
20 |
12 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
21 void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) |
13 { |
22 { |
14 |
23 |
15 qDebug() << "move" << mouseEvent->scenePos(); |
24 qDebug() << "move" << mouseEvent->scenePos(); |
|
25 |
|
26 if(mouseEvent->buttons() && Qt::LeftButton) |
|
27 drawFigure(mouseEvent->scenePos()); |
16 } |
28 } |
17 |
29 |
18 void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) |
30 void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) |
19 { |
31 { |
20 qDebug() << "press" << mouseEvent->scenePos(); |
32 qDebug() << "press" << mouseEvent->scenePos(); |
|
33 |
|
34 drawFigure(mouseEvent->scenePos()); |
21 } |
35 } |
22 |
36 |
23 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
37 void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) |
24 { |
38 { |
25 qDebug() << "release" << mouseEvent->scenePos(); |
39 qDebug() << "release" << mouseEvent->scenePos(); |
26 } |
40 } |
|
41 |
|
42 void DrawMapScene::drawFigure(const QPointF & point) |
|
43 { |
|
44 addEllipse( |
|
45 point.x() - m_halfWidth, |
|
46 point.y() - m_halfWidth, |
|
47 m_halfWidth * 2, |
|
48 m_halfWidth * 2, |
|
49 m_pen, |
|
50 m_brush |
|
51 ); |
|
52 } |