-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphicsscene.cpp
54 lines (45 loc) · 1.15 KB
/
graphicsscene.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
#include "graphicsscene.h"
#include <QGraphicsSceneMouseEvent>
GraphicsScene::GraphicsScene(int width, int height, QObject *parent) :
QGraphicsScene(parent)
{
setSceneRect(0, 0, width, height);
}
QPointF GraphicsScene::getPos() const
{
return position;
}
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (pressed) {
position = event->scenePos();
emit mousemove(event->scenePos());
}
QGraphicsScene::mouseMoveEvent(event);
}
void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
position = event->scenePos();
pressed = true;
emit mousepressed();
}
QGraphicsScene::mousePressEvent(event);
}
void GraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (pressed && event->button() == Qt::LeftButton) {
update();
position = event->scenePos();
pressed = false;
emit clicked();
emit mousereleased();
} else if (event->button() == Qt::LeftButton) {
emit mousereleased();
}
QGraphicsScene::mouseReleaseEvent(event);
}
void GraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsScene::mouseDoubleClickEvent(event);
}