4423
|
1 |
#include <QDebug>
|
|
2 |
#include <QGraphicsSceneMouseEvent>
|
|
3 |
|
|
4 |
#include "drawmapscene.h"
|
|
5 |
|
|
6 |
DrawMapScene::DrawMapScene(QObject *parent) :
|
4424
|
7 |
QGraphicsScene(parent),
|
|
8 |
m_pen(Qt::black),
|
|
9 |
m_brush(Qt::black)
|
4423
|
10 |
{
|
|
11 |
setSceneRect(0, 0, 4096, 2048);
|
4424
|
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;
|
4423
|
19 |
}
|
|
20 |
|
|
21 |
void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
|
22 |
{
|
|
23 |
|
|
24 |
qDebug() << "move" << mouseEvent->scenePos();
|
4424
|
25 |
|
|
26 |
if(mouseEvent->buttons() && Qt::LeftButton)
|
|
27 |
drawFigure(mouseEvent->scenePos());
|
4423
|
28 |
}
|
|
29 |
|
|
30 |
void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
|
31 |
{
|
|
32 |
qDebug() << "press" << mouseEvent->scenePos();
|
4424
|
33 |
|
|
34 |
drawFigure(mouseEvent->scenePos());
|
4423
|
35 |
}
|
|
36 |
|
|
37 |
void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent)
|
|
38 |
{
|
|
39 |
qDebug() << "release" << mouseEvent->scenePos();
|
|
40 |
}
|
4424
|
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 |
}
|