Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtCore/private/qobject_p.h>
7#include <QtGui/qguiapplication.h>
8#include <QtGui/qstylehints.h>
9#include <QtQuick/qquickitem.h>
10#include <QtQuick/private/qquickevents_p_p.h>
11#include <QtQuickTemplates2/private/qquicktextarea_p.h>
12#include <QtQuickTemplates2/private/qquicktextfield_p.h>
13
15
17{
18 longPress = false;
19 pressPos = event->position();
20 if (Qt::LeftButton == (event->buttons() & Qt::LeftButton)) {
21 timer.start(QGuiApplication::styleHints()->mousePressAndHoldInterval(), control);
22 delayedMousePressEvent = std::make_unique<QMouseEvent>(event->type(), event->position().toPoint(), event->globalPosition().toPoint(),
23 event->button(), event->buttons(), event->modifiers(), event->pointingDevice());
24 } else {
25 timer.stop();
26 }
27
28 if (isSignalConnected(control, "pressed(QQuickMouseEvent*)", pressedSignalIndex)) {
30 mev.reset(pressPos.x(), pressPos.y(), event->button(), event->buttons(),
31 event->modifiers(), false/*isClick*/, false/*wasHeld*/);
32 mev.setAccepted(true);
33 QQuickMouseEvent *mevPtr = &mev;
34 void *args[] = { nullptr, &mevPtr };
36 event->setAccepted(mev.isAccepted());
37 }
38}
39
41{
42 if (qAbs(int(event->position().x() - pressPos.x())) > QGuiApplication::styleHints()->startDragDistance())
43 timer.stop();
44}
45
47{
48 if (!longPress) {
49 timer.stop();
50
51 if (isSignalConnected(control, "released(QQuickMouseEvent*)", releasedSignalIndex)) {
53 mev.reset(pressPos.x(), pressPos.y(), event->button(), event->buttons(),
54 event->modifiers(), false/*isClick*/, false/*wasHeld*/);
55 mev.setAccepted(true);
56 QQuickMouseEvent *mevPtr = &mev;
57 void *args[] = { nullptr, &mevPtr };
59 event->setAccepted(mev.isAccepted());
60 }
61 }
62}
63
65{
66 timer.stop();
68
69 longPress = isSignalConnected(control, "pressAndHold(QQuickMouseEvent*)", pressAndHoldSignalIndex);
70 if (longPress) {
75 QGuiApplication::keyboardModifiers(), false/*isClick*/, true/*wasHeld*/);
77 mev.setAccepted(true);
78 // Use fast signal invocation since we already got its index
79 QQuickMouseEvent *mevPtr = &mev;
80 void *args[] = { nullptr, &mevPtr };
82 if (!mev.isAccepted())
83 longPress = false;
84 }
85}
86
91
93{
94 return !(timer.isActive() || longPress);
95}
96
98{
99 if (signalIndex == -1)
100 signalIndex = item->metaObject()->indexOfSignal(signalName);
101 Q_ASSERT(signalIndex != -1);
102 const auto signalMetaMethod = item->metaObject()->method(signalIndex);
103 if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea*>(item)) {
104 return textArea->isSignalConnected(signalMetaMethod);
105 } else if (QQuickTextField *textField = qobject_cast<QQuickTextField*>(item)) {
106 return textField->isSignalConnected(signalMetaMethod);
107 }
108 qFatal("Unhandled control type for signal name: %s", signalName);
109 return false;
110}
111
void start(int msec, QObject *obj)
\obsolete Use chrono overload instead.
void stop()
Stops the timer.
bool isActive() const noexcept
Returns true if the timer is running and has not been stopped; otherwise returns false.
Definition qbasictimer.h:34
static QStyleHints * styleHints()
Returns the application's style hints.
static Qt::KeyboardModifiers keyboardModifiers()
Returns the current state of the modifier keys on the keyboard.
\inmodule QtGui
Definition qevent.h:196
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
\qmlproperty int QtQuick::KeyEvent::key
void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, bool isClick=false, bool wasHeld=false, Qt::MouseEventFlags flags={ })
\inmodule QtCore
Definition qcoreevent.h:366
auto signalIndex
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:58
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define QT_WARNING_PUSH
#define qFatal
Definition qlogging.h:168
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
struct _cl_event * event
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QGraphicsItem * item
QJSValueList args
static int metacall(QObject *, Call, int, void **)
void mousePressEvent(QMouseEvent *event)
void timerEvent(QTimerEvent *event)
void mouseMoveEvent(QMouseEvent *event)
void mouseReleaseEvent(QMouseEvent *event)
std::unique_ptr< QMouseEvent > delayedMousePressEvent
static bool isSignalConnected(QQuickItem *item, const char *signalName, int &signalIndex)