aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquickevents.cpp12
-rw-r--r--src/quick/items/qquickevents_p_p.h9
-rw-r--r--src/quick/items/qquickmousearea.cpp10
-rw-r--r--src/quick/items/qquickmousearea_p_p.h1
-rw-r--r--tests/manual/mousearea/main.cpp55
-rw-r--r--tests/manual/mousearea/main.qml46
-rw-r--r--tests/manual/mousearea/mousearea.pro7
-rw-r--r--tests/manual/mousearea/plainMouseArea.qml52
-rw-r--r--tests/manual/mousearea/qml.qrc6
9 files changed, 192 insertions, 6 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 4a786d5569..260b302121 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -326,6 +326,18 @@ Item {
*/
/*!
+ \qmlproperty int QtQuick::MouseEvent::flags
+ \since 5.11
+
+ This property holds the flags that provide additional information about the
+ mouse event.
+
+ \value Qt.MouseEventCreatedDoubleClick Indicates that Qt has created a
+ double click event from this event. This flag is set in the event originating
+ from a button press, and not in the resulting double click event.
+*/
+
+/*!
\qmltype WheelEvent
\instantiates QQuickWheelEvent
\inqmlmodule QtQuick
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index af5857cf63..0f7e44e0e2 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -131,15 +131,18 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseEvent : public QObject
Q_PROPERTY(bool wasHeld READ wasHeld)
Q_PROPERTY(bool isClick READ isClick)
Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
+ Q_REVISION(11) Q_PROPERTY(int flags READ flags)
public:
QQuickMouseEvent()
: _x(0), _y(0), _button(Qt::NoButton), _buttons(Qt::NoButton), _modifiers(Qt::NoModifier)
, _source(Qt::MouseEventNotSynthesized), _wasHeld(false), _isClick(false), _accepted(false)
+ , _flags(Qt::MouseEventFlags(0))
{}
void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false)
+ Qt::KeyboardModifiers modifiers, bool isClick = false, bool wasHeld = false,
+ Qt::MouseEventFlags flags = 0)
{
_x = x;
_y = y;
@@ -150,6 +153,7 @@ public:
_wasHeld = wasHeld;
_isClick = isClick;
_accepted = true;
+ _flags = flags;
}
qreal x() const { return _x; }
@@ -169,7 +173,7 @@ public:
bool isAccepted() { return _accepted; }
void setAccepted(bool accepted) { _accepted = accepted; }
-
+ int flags() const { return _flags; }
private:
qreal _x;
qreal _y;
@@ -180,6 +184,7 @@ private:
bool _wasHeld : 1;
bool _isClick : 1;
bool _accepted : 1;
+ Qt::MouseEventFlags _flags;
};
class QQuickWheelEvent : public QObject
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 96f34ef276..cea8293ceb 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -99,6 +99,7 @@ void QQuickMouseAreaPrivate::saveEvent(QMouseEvent *event)
lastButton = event->button();
lastButtons = event->buttons();
lastModifiers = event->modifiers();
+ lastFlags = event->flags();
}
bool QQuickMouseAreaPrivate::isPressAndHoldConnected()
@@ -784,7 +785,7 @@ void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event)
#endif
QQuickMouseEvent &me = d->quickMouseEvent;
- me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
+ me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress, event->flags());
me.setSource(event->source());
emit mouseXChanged(&me);
me.setPosition(d->lastPos);
@@ -827,7 +828,8 @@ void QQuickMouseArea::mouseDoubleClickEvent(QMouseEvent *event)
if (d->enabled) {
d->saveEvent(event);
QQuickMouseEvent &me = d->quickMouseEvent;
- me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true, false);
+ me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, true,
+ false, event->flags());
me.setSource(event->source());
me.setAccepted(d->isDoubleClickConnected());
emit this->doubleClicked(&me);
@@ -1028,7 +1030,7 @@ void QQuickMouseArea::timerEvent(QTimerEvent *event)
if (d->pressed && dragged == false && d->hovered == true) {
d->longPress = true;
QQuickMouseEvent &me = d->quickMouseEvent;
- me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress);
+ me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress, d->lastFlags);
me.setSource(Qt::MouseEventSynthesizedByQt);
me.setAccepted(d->isPressAndHoldConnected());
emit pressAndHold(&me);
@@ -1207,7 +1209,7 @@ bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p, Qt::MouseEventS
if (wasPressed != p) {
QQuickMouseEvent &me = d->quickMouseEvent;
- me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress);
+ me.reset(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress, d->lastFlags);
me.setSource(source);
if (p) {
d->pressed |= button;
diff --git a/src/quick/items/qquickmousearea_p_p.h b/src/quick/items/qquickmousearea_p_p.h
index 2fa5f7cd44..34cda9e193 100644
--- a/src/quick/items/qquickmousearea_p_p.h
+++ b/src/quick/items/qquickmousearea_p_p.h
@@ -112,6 +112,7 @@ public:
#endif
QQuickMouseEvent quickMouseEvent;
QQuickWheelEvent quickWheelEvent;
+ Qt::MouseEventFlags lastFlags;
};
QT_END_NAMESPACE
diff --git a/tests/manual/mousearea/main.cpp b/tests/manual/mousearea/main.cpp
new file mode 100644
index 0000000000..ea41cb521a
--- /dev/null
+++ b/tests/manual/mousearea/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QQuickItem>
+#include <QQuickWindow>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QGuiApplication app(argc, argv);
+
+ QQmlApplicationEngine engine;
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+ if (!app.arguments().isEmpty()) {
+ QQuickWindow *win = static_cast<QQuickWindow *>(engine.rootObjects().first());
+ auto lastArg = app.arguments().last();
+ if (lastArg.endsWith(QLatin1String(".qml"))) {
+ auto root = win->findChild<QQuickItem *>("LauncherList");
+ int showExampleIdx = -1;
+ for (int i = root->metaObject()->methodCount(); showExampleIdx < 0 && i >= 0; --i)
+ if (root->metaObject()->method(i).name() == QByteArray("showExample"))
+ showExampleIdx = i;
+ QMetaMethod showExampleFn = root->metaObject()->method(showExampleIdx);
+ showExampleFn.invoke(root, Q_ARG(QVariant, QVariant(QLatin1String("../../") + lastArg)));
+ }
+ }
+
+ return app.exec();
+}
diff --git a/tests/manual/mousearea/main.qml b/tests/manual/mousearea/main.qml
new file mode 100644
index 0000000000..6c284c3586
--- /dev/null
+++ b/tests/manual/mousearea/main.qml
@@ -0,0 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.8
+import QtQuick.Window 2.2
+import Qt.labs.handlers 1.0
+import "qrc:/quick/shared/" as Examples
+
+Window {
+ width: 800
+ height: 600
+ visible: true
+ Examples.LauncherList {
+ id: ll
+ objectName: "LauncherList"
+ anchors.fill: parent
+ Component.onCompleted: {
+ addExample("plain mouse area", "Plain mouse area for testing flags passed from mouse event", Qt.resolvedUrl("plainMouseArea.qml"))
+ }
+ }
+}
diff --git a/tests/manual/mousearea/mousearea.pro b/tests/manual/mousearea/mousearea.pro
new file mode 100644
index 0000000000..3705d41df0
--- /dev/null
+++ b/tests/manual/mousearea/mousearea.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+
+QT += qml quick
+
+SOURCES += main.cpp
+
+RESOURCES += qml.qrc ../../../examples/quick/shared/quick_shared.qrc
diff --git a/tests/manual/mousearea/plainMouseArea.qml b/tests/manual/mousearea/plainMouseArea.qml
new file mode 100644
index 0000000000..4f37b0635f
--- /dev/null
+++ b/tests/manual/mousearea/plainMouseArea.qml
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the manual tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.11
+
+Rectangle {
+ id: root
+ width: 480
+ height: 480
+ color: "white"
+ Text {
+ id: pressedLabel
+ x: 0
+ y: 0
+ width: 480
+ height: 50
+ font.pointSize: 18
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onPressed: {
+ pressedLabel.text = "Pressed - " + (mouse.flags === Qt.MouseEventCreatedDoubleClick ?
+ "Press from double click" : "No flags")
+ }
+ }
+}
diff --git a/tests/manual/mousearea/qml.qrc b/tests/manual/mousearea/qml.qrc
new file mode 100644
index 0000000000..870b50ae92
--- /dev/null
+++ b/tests/manual/mousearea/qml.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>plainMouseArea.qml</file>
+ </qresource>
+</RCC>