-
Notifications
You must be signed in to change notification settings - Fork 0
/
vegrabberdot.cpp
74 lines (66 loc) · 1.67 KB
/
vegrabberdot.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
#include "vegrabberdot.h"
VeGrabberDot::VeGrabberDot(QObject *parent, QGraphicsItem *parent_item,
bool p_visible, bool p_active, bool p_highlight)
: QObject(parent)
, is_active_(p_active)
, is_action_in_progress_(false)
{
setParentItem(parent_item);
setAcceptHoverEvents(true);
setBrush(QBrush(Qt::white));
setPen(QPen(Qt::black, 1));
if (p_visible) {
show();
} else {
hide();
}
if (p_visible && p_highlight && p_active) {
highlight(true);
}
setRect(-3, -3, 6, 6);
}
int VeGrabberDot::type() const
{
return Type;
}
void VeGrabberDot::highlight(bool p_state)
{
if (p_state) {
setBrush(QBrush(Qt::red));
setPen(QPen(Qt::red, 1));
} else {
setBrush(QBrush(Qt::white));
setPen(QPen(Qt::black, 1));
}
}
void VeGrabberDot::itemUnderCursorEvent(const QGraphicsItem *p_item)
{
is_active_ = dynamic_cast<QGraphicsItem *>(this) == p_item;
if (is_active_) {
highlight(true);
}
}
void VeGrabberDot::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (is_active_) {
start_delta_pos_ = event->pos() - rect().center();
is_action_in_progress_ = true;
}
}
void VeGrabberDot::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (is_action_in_progress_) {
emit itemMoved(this, event->scenePos() - start_delta_pos_, event->buttons());
}
}
void VeGrabberDot::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event);
emit itemRelease(this);
is_action_in_progress_ = false;
}
void VeGrabberDot::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event)
highlight(false);
}