-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.cpp
93 lines (80 loc) · 2.19 KB
/
tracker.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
88
89
90
91
92
93
#include "tracker.h"
#include "interactionsource.h"
#include <QDebug>
Tracker::Tracker(InteractionSource *source, QObject *parent) :
QObject(parent), _source(source)
{
connect(source, &InteractionSource::userDragged, this, &Tracker::_setUserDragged);
connect(source, &InteractionSource::userDwelled, this, &Tracker::_autoAction);
connect(source, &InteractionSource::userClicked, this, &Tracker::_cancelTimer);
connect(source, &InteractionSource::dragShortcutPressed, this, &Tracker::_toggleDragDrop);
_clickSound.setSource(QUrl("qrc:/openergo/click.wav"));
qDebug() << _clickSound.supportedMimeTypes();
}
void
Tracker::_autoAction()
{
if (_paused)
return;
qDebug() << "User dwelled.";
if (_inDrag) {
qDebug() << "In drag mode.";
return;
}
if (_userDragged) {
qDebug() << "Ignoring first dwell after user drag.";
_userDragged = false;
return;
}
if (_source->isLeftButtonDown()) {
qDebug() << "User is dragging.";
return;
}
if (_source->isBlockClicksDown()) {
qDebug() << "User blocked click.";
return;
}
if (_source->isDoubleClickDown()) {
qDebug() << "Requesting double click.";
_source->simulateClick(Qt::LeftButton, ButtonDoubleClick);
_clickSound.play();
return;
}
Qt::MouseButton button;
if (_source->isRightClickDown()) {
button = Qt::RightButton;
qDebug() << "Requesting right click.";
} else {
button = Qt::LeftButton;
qDebug() << "Requesting left click.";
}
_source->simulateClick(button, ButtonClick);
_clickSound.play();
}
void
Tracker::_toggleDragDrop()
{
if (!_inDrag) {
qDebug() << "Request drag start";
_source->simulateClick(Qt::LeftButton, ButtonDown);
_inDrag = true;
} else {
qDebug() << "Request end drag";
_source->simulateClick(Qt::LeftButton, ButtonUp);
_inDrag = false;
}
}
void
Tracker::_setUserDragged()
{
qDebug() << "User initiated drag.";
_userDragged = true;
}
void
Tracker::_cancelTimer()
{
if (_inDrag) {
qDebug() << "Click canceling drag.";
_inDrag = false;
}
}