-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepliagevue2d.cpp
87 lines (80 loc) · 2.52 KB
/
depliagevue2d.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "depliagevue2d.h"
#include <qgraphicsitem.h>
DepliageVue2d::DepliageVue2d () {}
DepliageVue2d::DepliageVue2d (QWidget *parent) : QGraphicsView(parent) {
setFrameStyle(QFrame::Panel);
it = nullptr;
git = nullptr;
}
void DepliageVue2d::mousePressEvent (QMouseEvent *event) {
if (event->button() == Qt::LeftButton) {
git = itemAt(event->position().x(), event->position().y());
if (git) {
while(git->parentItem()) {
git = git->parentItem();
}
event->accept();
//return;
}
} else
if (event->button() == Qt::MiddleButton) {
_pan = true;
_panStartX = event->position().x();
_panStartY = event->position().y();
setCursor(Qt::ClosedHandCursor);
event->accept();
it = itemAt(event->position().x(), event->position().y());
if (it) {
while(it->parentItem()) {
it = it->parentItem();
}
}
return;
}
QGraphicsView::mousePressEvent (event);
}
void DepliageVue2d::mouseReleaseEvent (QMouseEvent *event) {
if (event->button() == Qt::MiddleButton) {
_pan = false;
setCursor(Qt::ArrowCursor);
event->accept();
it = nullptr;
return;
}
QGraphicsView::mouseReleaseEvent (event);
}
void DepliageVue2d::mouseMoveEvent (QMouseEvent *event) {
if (_pan) {
qreal dx = event->position().x() - _panStartX;
qreal dy = event->position().y() - _panStartY;
qreal adx = qFabs(dx);
qreal ady = qFabs(dy);
if (adx > 4 || ady > 3) {
if (adx < 20 && ady < 15) {
//qreal dZ = dx;
//qreal dX = dy/18;
if (it) {
emit tourne2D (dx, it);
//emit tourne2D (dX);
_panStartX = event->position().x();
_panStartY = event->position().y();
event->accept();
return;
}
}
}
}
QGraphicsView::mouseMoveEvent (event);
}
/*void DepliageVue2d::wheelEvent (QWheelEvent *event) {
if (event->buttons().testFlag(Qt::RightButton)) {
int d = event->angleDelta().y();
if (d < 0)
this->scale(0.9f, 0.9f);
else if (d>0)
this->scale(1.1f, 1.1f);
return;
} else
event->ignore();
QGraphicsView::wheelEvent(event);
}*/