Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickpresshandler.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qquickpresshandler_p_p.h"
6
7
#
include
<
QtCore
/
private
/
qobject_p
.
h
>
8
#
include
<
QtGui
/
qguiapplication
.
h
>
9
#
include
<
QtGui
/
qstylehints
.
h
>
10
#
include
<
QtQuick
/
qquickitem
.
h
>
11
#
include
<
QtQuick
/
private
/
qquickevents_p_p
.
h
>
12
#
include
<
QtQuickTemplates2
/
private
/
qquicktextarea_p
.
h
>
13
#
include
<
QtQuickTemplates2
/
private
/
qquicktextfield_p
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
void
QQuickPressHandler
::
mousePressEvent
(QMouseEvent *event)
18
{
19
longPress
=
false
;
20
pressPos = event->position();
21
if
(Qt::LeftButton == (event->buttons() & Qt::LeftButton)) {
22
timer.start(QGuiApplication::styleHints()->mousePressAndHoldInterval(), control);
23
delayedMousePressEvent = std::make_unique<QMouseEvent>(event->type(), event->position().toPoint(), event->globalPosition().toPoint(),
24
event->button(), event->buttons(), event->modifiers(), event->pointingDevice());
25
}
else
{
26
timer.stop();
27
}
28
29
if
(
isSignalConnected
(
control
,
"pressed(QQuickMouseEvent*)"
,
pressedSignalIndex
)
) {
30
QQuickMouseEvent mev;
31
mev.reset(pressPos.x(), pressPos.y(), event->button(), event->buttons(),
32
event->modifiers(),
false
/*isClick*/
,
false
/*wasHeld*/
);
33
mev.setAccepted(
true
);
34
QQuickMouseEvent *mevPtr = &mev;
35
void
*args[] = {
nullptr
, &mevPtr };
36
QMetaObject::metacall(control, QMetaObject::InvokeMetaMethod, pressedSignalIndex, args);
37
event->setAccepted(mev.isAccepted());
38
}
39
}
40
41
void
QQuickPressHandler
::
mouseMoveEvent
(QMouseEvent *event)
42
{
43
if
(qAbs(event->position().x() - pressPos.x()) > QGuiApplication::styleHints()->startDragDistance())
44
timer.stop();
45
}
46
47
void
QQuickPressHandler
::
mouseReleaseEvent
(QMouseEvent *event)
48
{
49
if
(!longPress)
50
timer.stop();
51
52
if
(
isSignalConnected
(
control
,
"released(QQuickMouseEvent*)"
,
releasedSignalIndex
)
) {
53
QQuickMouseEvent mev;
54
mev.reset(pressPos.x(), pressPos.y(), event->button(), event->buttons(),
55
event->modifiers(),
false
/*isClick*/
,
false
/*wasHeld*/
);
56
mev.setAccepted(
true
);
57
QQuickMouseEvent *mevPtr = &mev;
58
void
*args[] = {
nullptr
, &mevPtr };
59
QMetaObject::metacall(control, QMetaObject::InvokeMetaMethod, releasedSignalIndex, args);
60
event->setAccepted(mev.isAccepted());
61
}
62
63
}
64
65
void
QQuickPressHandler
::
timerEvent
(QTimerEvent *)
66
{
67
timer.stop();
68
clearDelayedMouseEvent
(
)
;
69
70
longPress
=
isSignalConnected
(
control
,
"pressAndHold(QQuickMouseEvent*)"
,
pressAndHoldSignalIndex
)
;
71
if
(
longPress
) {
72
QQuickMouseEvent mev;
73
QT_WARNING_PUSH
74
QT_WARNING_DISABLE_DEPRECATED
75
mev.reset(pressPos.x(), pressPos.y(), Qt::LeftButton, Qt::LeftButton,
76
QGuiApplication::keyboardModifiers(),
false
/*isClick*/
,
true
/*wasHeld*/
);
77
QT_WARNING_POP
78
mev.setAccepted(
true
);
79
// Use fast signal invocation since we already got its index
80
QQuickMouseEvent *mevPtr = &mev;
81
void
*args[] = {
nullptr
, &mevPtr };
82
QMetaObject::metacall(control, QMetaObject::InvokeMetaMethod, pressAndHoldSignalIndex, args);
83
if
(!mev.isAccepted())
84
longPress
=
false
;
85
}
86
}
87
88
void
QQuickPressHandler
::
clearDelayedMouseEvent
()
89
{
90
delayedMousePressEvent.reset();
91
}
92
93
bool
QQuickPressHandler
::
isActive
()
94
{
95
return
!(timer.isActive() || longPress);
96
}
97
98
bool
QQuickPressHandler
::
isSignalConnected
(QQuickItem *item,
const
char
*signalName,
int
&signalIndex)
99
{
100
if
(signalIndex == -1)
101
signalIndex = item->metaObject()->indexOfSignal(signalName);
102
Q_ASSERT(signalIndex != -1);
103
const
auto
signalMetaMethod = item->metaObject()->method(signalIndex);
104
if
(QQuickTextArea *textArea = qobject_cast<QQuickTextArea*>(item)) {
105
return
textArea->isSignalConnected(signalMetaMethod);
106
}
else
if
(QQuickTextField *textField = qobject_cast<QQuickTextField*>(item)) {
107
return
textField->isSignalConnected(signalMetaMethod);
108
}
109
qFatal(
"Unhandled control type for signal name: %s"
, signalName);
110
return
false
;
111
}
112
113
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QQuickPressHandler
Definition
qquickpresshandler_p_p.h:32
QQuickPressHandler::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition
qquickpresshandler.cpp:17
QQuickPressHandler::pressAndHoldSignalIndex
int pressAndHoldSignalIndex
Definition
qquickpresshandler_p_p.h:47
QQuickPressHandler::timerEvent
void timerEvent(QTimerEvent *event)
Definition
qquickpresshandler.cpp:65
QQuickPressHandler::isActive
bool isActive()
Definition
qquickpresshandler.cpp:93
QQuickPressHandler::clearDelayedMouseEvent
void clearDelayedMouseEvent()
Definition
qquickpresshandler.cpp:88
QQuickPressHandler::control
QQuickItem * control
Definition
qquickpresshandler_p_p.h:43
QQuickPressHandler::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Definition
qquickpresshandler.cpp:41
QQuickPressHandler::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event)
Definition
qquickpresshandler.cpp:47
QQuickPressHandler::longPress
bool longPress
Definition
qquickpresshandler_p_p.h:46
QQuickPressHandler::pressedSignalIndex
int pressedSignalIndex
Definition
qquickpresshandler_p_p.h:48
QQuickPressHandler::isSignalConnected
static bool isSignalConnected(QQuickItem *item, const char *signalName, int &signalIndex)
Definition
qquickpresshandler.cpp:98
QQuickPressHandler::releasedSignalIndex
int releasedSignalIndex
Definition
qquickpresshandler_p_p.h:49
qtdeclarative
src
quicktemplates
qquickpresshandler.cpp
Generated on
for Qt by
1.18.0