This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
qamousesensor.cpp
114 lines (92 loc) · 2.06 KB
/
qamousesensor.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Quick Android Project
Author: Ben Lau
License: Apache-2.0
Web: https://github.com/benlau/quickandroid
*/
#include <QtQml>
#include <QEvent>
#include "qamousesensor.h"
/*!
* \brief QAMouseSensor::QAMouseSensor
* \param parent
*/
QAMouseSensor::QAMouseSensor(QQuickItem* parent) : QQuickItem(parent)
{
timerId = 0;
m_filter = 0;
}
void QAMouseSensor::mousePressEvent(QMouseEvent *event)
{
if (timerId != 0) {
killTimer(timerId);
timerId = 0;
}
timerId = startTimer(800,Qt::CoarseTimer);
return QQuickItem::mousePressEvent(event);
}
void QAMouseSensor::mouseMoveEvent(QMouseEvent *event)
{
QQuickItem::mouseMoveEvent(event);
}
void QAMouseSensor::mouseReleaseEvent(QMouseEvent *event)
{
if (timerId != 0) {
killTimer(timerId);
timerId = 0;
}
QQuickItem::mouseReleaseEvent(event);
}
void QAMouseSensor::timerEvent(QTimerEvent *event)
{
killTimer(timerId);
Q_UNUSED(event);
timerId = 0;
emit pressAndHold();
}
bool QAMouseSensor::eventFilter(QObject *, QEvent *event)
{
if (!isEnabled())
return false;
switch (event->type()) {
case QEvent::MouseButtonPress:
mousePressEvent((QMouseEvent*) event);
break;
case QEvent::MouseMove:
mouseMoveEvent((QMouseEvent*) event);
break;
case QEvent::MouseButtonRelease:
mouseReleaseEvent((QMouseEvent*) event);
break;
case QEvent::Timer:
break;
default:
break;
}
return false;
}
void QAMouseSensor::search(QObject *object, bool installFilter)
{
if (installFilter) {
object->installEventFilter(this);
} else {
object->removeEventFilter(this);
}
QObjectList children = object->children();
Q_FOREACH(QObject* child,children) {
search(child,installFilter);
}
}
QObject *QAMouseSensor::filter() const
{
return m_filter;
}
void QAMouseSensor::setFilter(QObject *listenOn)
{
if (m_filter) {
search(m_filter,false);
}
m_filter = listenOn;
if (m_filter) {
search(m_filter,true);
}
}