-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplansscene.cpp
63 lines (44 loc) · 1.58 KB
/
plansscene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "plansscene.h"
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsItem>
PlansScene::PlansScene()
{
VertLineCount = 40;
SceneH = 600;
SceneW = 800;
StepLine = round(SceneW/VertLineCount);
RadiusPoint = StepLine/4;
// Рисуем сетку с zValue = -1
for (int i = 0; i <= VertLineCount; i++)
{
this->addLine(i * StepLine, 0, i * StepLine, SceneH, QPen(Qt::gray))->setZValue(-1);
}
for (int i = 0; i <= SceneH/StepLine; i++)
{
this->addLine(0, i * StepLine, SceneW, i * StepLine, QPen(Qt::gray))->setZValue(-1);
}
}
void PlansScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
}
void PlansScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (StartPoint != mouseEvent->scenePos())
{
StartPoint = mouseEvent->scenePos();
addEllipse((round(StartPoint.QPointF::x()/StepLine)*StepLine - RadiusPoint),
(round(StartPoint.QPointF::y()/StepLine)*StepLine - RadiusPoint),
RadiusPoint * 2, RadiusPoint * 2, QPen(Qt::red));
//addLine(StartPoint.x(), StartPoint.y(), EndPoint.x(), EndPoint.y(), QPen(Qt::black));
}
else
{
EndPoint = StartPoint;
StartPoint = mouseEvent->scenePos();
StartPoint.setX((round(StartPoint.QPointF::x()/StepLine)*StepLine - RadiusPoint));
StartPoint.setY((round(StartPoint.QPointF::y()/StepLine)*StepLine - RadiusPoint));
}
}
void PlansScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
}