2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QtTest/QSignalSpy>
|
2013-08-26 23:15:23 +00:00
|
|
|
#include <QtQuick/private/qquickdrag_p.h>
|
2016-06-20 09:57:43 +00:00
|
|
|
#include <QtQuick/private/qquickitem_p.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/private/qquickmousearea_p.h>
|
|
|
|
#include <QtQuick/private/qquickrectangle_p.h>
|
2011-10-14 08:51:42 +00:00
|
|
|
#include <private/qquickflickable_p.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include <QtQuick/qquickview.h>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqmlcontext.h>
|
|
|
|
#include <QtQml/qqmlengine.h>
|
2021-08-06 10:27:35 +00:00
|
|
|
#include <QtQuickTestUtils/private/qmlutils_p.h>
|
|
|
|
#include <QtQuickTestUtils/private/viewtestutils_p.h>
|
2012-04-21 02:45:58 +00:00
|
|
|
#include <QtGui/qstylehints.h>
|
2013-08-23 08:38:08 +00:00
|
|
|
#include <QtGui/QCursor>
|
|
|
|
#include <QtGui/QScreen>
|
2022-02-06 16:57:33 +00:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QQmlComponent>
|
2016-03-04 10:02:54 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2022-07-05 21:05:32 +00:00
|
|
|
#include <qpa/qwindowsysteminterface_p.h>
|
2013-08-23 08:38:08 +00:00
|
|
|
|
2020-11-19 15:29:20 +00:00
|
|
|
Q_LOGGING_CATEGORY(lcTests, "qt.quick.tests")
|
|
|
|
|
2017-09-22 16:46:36 +00:00
|
|
|
class CircleMask : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~CircleMask() {}
|
|
|
|
qreal radius() const { return m_radius; }
|
|
|
|
void setRadius(qreal radius)
|
|
|
|
{
|
|
|
|
if (m_radius == radius)
|
|
|
|
return;
|
|
|
|
m_radius = radius;
|
|
|
|
emit radiusChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_INVOKABLE bool contains(const QPointF &point) const
|
|
|
|
{
|
|
|
|
QPointF center(m_radius, m_radius);
|
|
|
|
QLineF line(center, point);
|
|
|
|
return line.length() <= m_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void radiusChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
qreal m_radius;
|
|
|
|
};
|
|
|
|
|
2018-10-03 15:09:40 +00:00
|
|
|
class EventSender : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-11-19 16:22:37 +00:00
|
|
|
Q_INVOKABLE void sendMouseClick(QWindow* w ,qreal x , qreal y) {
|
|
|
|
QTest::mouseClick(w, Qt::LeftButton, {}, QPointF(x, y).toPoint());
|
2018-10-03 15:09:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class tst_QQuickMouseArea: public QQmlDataTest
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2016-03-04 10:02:54 +00:00
|
|
|
public:
|
|
|
|
tst_QQuickMouseArea()
|
2021-08-06 10:27:35 +00:00
|
|
|
: QQmlDataTest(QT_QMLTEST_DATADIR)
|
2017-09-22 16:46:36 +00:00
|
|
|
{
|
|
|
|
qmlRegisterType<CircleMask>("Test", 1, 0, "CircleMask");
|
2018-10-03 15:09:40 +00:00
|
|
|
qmlRegisterType<EventSender>("Test", 1, 0, "EventSender");
|
2017-09-22 16:46:36 +00:00
|
|
|
}
|
2016-03-04 10:02:54 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
private slots:
|
2011-09-08 13:58:13 +00:00
|
|
|
void dragProperties();
|
|
|
|
void resetDrag();
|
2012-06-21 05:49:10 +00:00
|
|
|
void dragging_data() { acceptedButton_data(); }
|
2011-09-08 13:58:13 +00:00
|
|
|
void dragging();
|
2020-06-29 08:48:27 +00:00
|
|
|
void selfDrag();
|
2014-05-07 17:01:19 +00:00
|
|
|
void dragSmoothed();
|
2016-06-02 19:49:37 +00:00
|
|
|
void dragThreshold_data();
|
2013-08-22 15:20:52 +00:00
|
|
|
void dragThreshold();
|
2012-06-21 05:49:10 +00:00
|
|
|
void invalidDrag_data() { rejectedButton_data(); }
|
|
|
|
void invalidDrag();
|
2013-11-25 22:55:22 +00:00
|
|
|
void cancelDragging();
|
2017-01-25 00:39:28 +00:00
|
|
|
void availableDistanceLessThanDragThreshold();
|
2012-05-11 01:01:33 +00:00
|
|
|
void setDragOnPressed();
|
2011-09-08 13:58:13 +00:00
|
|
|
void updateMouseAreaPosOnClick();
|
|
|
|
void updateMouseAreaPosOnResize();
|
|
|
|
void noOnClickedWithPressAndHold();
|
|
|
|
void onMousePressRejected();
|
2014-09-03 18:42:04 +00:00
|
|
|
void pressedCanceledOnWindowDeactivate_data();
|
2011-09-08 13:58:13 +00:00
|
|
|
void pressedCanceledOnWindowDeactivate();
|
2012-06-21 05:49:10 +00:00
|
|
|
void doubleClick_data() { acceptedButton_data(); }
|
2011-09-08 13:58:13 +00:00
|
|
|
void doubleClick();
|
2012-06-21 05:49:10 +00:00
|
|
|
void clickTwice_data() { acceptedButton_data(); }
|
2011-09-08 13:58:13 +00:00
|
|
|
void clickTwice();
|
2012-06-21 05:49:10 +00:00
|
|
|
void invalidClick_data() { rejectedButton_data(); }
|
|
|
|
void invalidClick();
|
2011-09-08 13:58:13 +00:00
|
|
|
void pressedOrdering();
|
|
|
|
void preventStealing();
|
2022-05-18 11:21:05 +00:00
|
|
|
void preventStealingListViewChild();
|
2011-09-08 13:58:13 +00:00
|
|
|
void clickThrough();
|
|
|
|
void hoverPosition();
|
|
|
|
void hoverPropagation();
|
2012-02-15 06:27:36 +00:00
|
|
|
void hoverVisible();
|
2013-04-26 14:18:54 +00:00
|
|
|
void hoverAfterPress();
|
2016-06-20 09:57:43 +00:00
|
|
|
void subtreeHoverEnabled();
|
2022-09-16 11:13:00 +00:00
|
|
|
void hoverWhenDisabled();
|
2012-03-05 05:07:27 +00:00
|
|
|
void disableAfterPress();
|
2022-10-18 11:28:52 +00:00
|
|
|
void disableParentOnPress_data();
|
|
|
|
void disableParentOnPress();
|
2012-01-05 18:19:26 +00:00
|
|
|
void onWheel();
|
2012-02-26 16:27:34 +00:00
|
|
|
void transformedMouseArea_data();
|
|
|
|
void transformedMouseArea();
|
2012-07-10 06:40:06 +00:00
|
|
|
void pressedMultipleButtons_data();
|
|
|
|
void pressedMultipleButtons();
|
2012-07-05 14:10:34 +00:00
|
|
|
void changeAxis();
|
2016-11-16 13:22:36 +00:00
|
|
|
#if QT_CONFIG(cursor)
|
2012-07-25 04:04:47 +00:00
|
|
|
void cursorShape();
|
|
|
|
#endif
|
2013-02-13 04:19:10 +00:00
|
|
|
void moveAndReleaseWithoutPress();
|
2013-02-15 11:29:32 +00:00
|
|
|
void nestedStopAtBounds();
|
|
|
|
void nestedStopAtBounds_data();
|
2016-09-16 07:32:58 +00:00
|
|
|
void nestedFlickableStopAtBounds();
|
2014-07-11 04:10:49 +00:00
|
|
|
void containsPress_data();
|
|
|
|
void containsPress();
|
2016-03-04 10:02:54 +00:00
|
|
|
void ignoreBySource();
|
2016-08-24 10:40:23 +00:00
|
|
|
void notPressedAfterStolenGrab();
|
2016-12-07 17:57:03 +00:00
|
|
|
void pressAndHold_data();
|
|
|
|
void pressAndHold();
|
2017-11-30 13:12:17 +00:00
|
|
|
void pressOneAndTapAnother_data();
|
|
|
|
void pressOneAndTapAnother();
|
2017-09-22 16:46:36 +00:00
|
|
|
void mask();
|
2018-10-03 15:09:40 +00:00
|
|
|
void nestedEventDelivery();
|
2020-03-28 14:14:41 +00:00
|
|
|
void settingHiddenInPressUngrabs();
|
2019-08-16 12:32:22 +00:00
|
|
|
void negativeZStackingOrder();
|
MouseArea: fix containsMouse behavior during visibility changes
QQuickItem returns whether it contains QGuiApplicationPrivate's
lastCursorPosition. Since that position stores the coordinate last seen
by Qt (the window border), it will always be within the window, and
within an item that covers that part of the window's border.
However, QQuickWindow stores the lastMousePosition as well, and resets
that value when it receives a QEvent::Leave. We can use that to test
whether the window that contains the item has seen a Leave event, in
which case the item is definitely not under the mouse.
Notes on the test: That we use QPointF() as the "reset" value leave the
small possibility that the cursor might be at position 0,0 of the window
(ie inside the window), and the QQuickItem there will not be under the
mouse. We can't confirm this (through an expected failure test), as
QTest::mouseMove interprets a QPoint(0, 0) as "center of the window".
And since we can't simulate mouse moves outside a window's boundary
using QTest::mouseMove, the test needs to explicitly synthesize a
QEvent::Leave for the window.
Fixes: QTBUG-87197
Pick-to: 6.1 6.0 5.15
Change-Id: I04870d6e914092275d9d790312fc702fb99f2935
Done-with: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-02-12 16:11:47 +00:00
|
|
|
void containsMouseAndVisibility();
|
2022-04-29 13:18:08 +00:00
|
|
|
void doubleClickToHide();
|
2022-05-24 13:01:37 +00:00
|
|
|
void releaseFirstTouchAfterSecond();
|
2022-07-05 21:05:32 +00:00
|
|
|
#if QT_CONFIG(tabletevent)
|
|
|
|
void tabletStylusTap();
|
|
|
|
#endif
|
2022-10-20 14:50:39 +00:00
|
|
|
void syntheticRightClick();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private:
|
2016-07-02 11:33:34 +00:00
|
|
|
int startDragDistance() const {
|
|
|
|
return QGuiApplication::styleHints()->startDragDistance();
|
|
|
|
}
|
2012-06-21 05:49:10 +00:00
|
|
|
void acceptedButton_data();
|
|
|
|
void rejectedButton_data();
|
2022-10-23 08:09:55 +00:00
|
|
|
QPointingDevice *device = QTest::createTouchDevice(); // TODO const after fixing QTBUG-107864
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 05:49:10 +00:00
|
|
|
Q_DECLARE_METATYPE(Qt::MouseButton)
|
|
|
|
Q_DECLARE_METATYPE(Qt::MouseButtons)
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::acceptedButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::MouseButtons>("acceptedButtons");
|
|
|
|
QTest::addColumn<Qt::MouseButton>("button");
|
|
|
|
|
|
|
|
QTest::newRow("left") << Qt::MouseButtons(Qt::LeftButton) << Qt::LeftButton;
|
|
|
|
QTest::newRow("right") << Qt::MouseButtons(Qt::RightButton) << Qt::RightButton;
|
|
|
|
QTest::newRow("middle") << Qt::MouseButtons(Qt::MiddleButton) << Qt::MiddleButton;
|
|
|
|
|
|
|
|
QTest::newRow("left (left|right)") << Qt::MouseButtons(Qt::LeftButton | Qt::RightButton) << Qt::LeftButton;
|
|
|
|
QTest::newRow("right (right|middle)") << Qt::MouseButtons(Qt::RightButton | Qt::MiddleButton) << Qt::RightButton;
|
|
|
|
QTest::newRow("middle (left|middle)") << Qt::MouseButtons(Qt::LeftButton | Qt::MiddleButton) << Qt::MiddleButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::rejectedButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::MouseButtons>("acceptedButtons");
|
|
|
|
QTest::addColumn<Qt::MouseButton>("button");
|
|
|
|
|
|
|
|
QTest::newRow("middle (left|right)") << Qt::MouseButtons(Qt::LeftButton | Qt::RightButton) << Qt::MiddleButton;
|
|
|
|
QTest::newRow("left (right|middle)") << Qt::MouseButtons(Qt::RightButton | Qt::MiddleButton) << Qt::LeftButton;
|
|
|
|
QTest::newRow("right (left|middle)") << Qt::MouseButtons(Qt::LeftButton | Qt::MiddleButton) << Qt::RightButton;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::dragProperties()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragproperties.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem*>(window.rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(rootItem != nullptr);
|
2011-09-08 13:58:13 +00:00
|
|
|
QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
|
|
|
|
drag->setTarget(rootItem);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(targetSpy.size(),1);
|
2011-09-08 13:58:13 +00:00
|
|
|
drag->setTarget(rootItem);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(targetSpy.size(),1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
// axis
|
2012-03-01 10:09:52 +00:00
|
|
|
QCOMPARE(drag->axis(), QQuickDrag::XAndYAxis);
|
2011-09-08 13:58:13 +00:00
|
|
|
QSignalSpy axisSpy(drag, SIGNAL(axisChanged()));
|
2011-10-14 08:51:42 +00:00
|
|
|
drag->setAxis(QQuickDrag::XAxis);
|
|
|
|
QCOMPARE(drag->axis(), QQuickDrag::XAxis);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(axisSpy.size(),1);
|
2011-10-14 08:51:42 +00:00
|
|
|
drag->setAxis(QQuickDrag::XAxis);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(axisSpy.size(),1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
// minimum and maximum properties
|
|
|
|
QSignalSpy xminSpy(drag, SIGNAL(minimumXChanged()));
|
|
|
|
QSignalSpy xmaxSpy(drag, SIGNAL(maximumXChanged()));
|
|
|
|
QSignalSpy yminSpy(drag, SIGNAL(minimumYChanged()));
|
|
|
|
QSignalSpy ymaxSpy(drag, SIGNAL(maximumYChanged()));
|
|
|
|
|
|
|
|
QCOMPARE(drag->xmin(), 0.0);
|
|
|
|
QCOMPARE(drag->xmax(), rootItem->width()-blackRect->width());
|
|
|
|
QCOMPARE(drag->ymin(), 0.0);
|
|
|
|
QCOMPARE(drag->ymax(), rootItem->height()-blackRect->height());
|
|
|
|
|
|
|
|
drag->setXmin(10);
|
|
|
|
drag->setXmax(10);
|
|
|
|
drag->setYmin(10);
|
|
|
|
drag->setYmax(10);
|
|
|
|
|
|
|
|
QCOMPARE(drag->xmin(), 10.0);
|
|
|
|
QCOMPARE(drag->xmax(), 10.0);
|
|
|
|
QCOMPARE(drag->ymin(), 10.0);
|
|
|
|
QCOMPARE(drag->ymax(), 10.0);
|
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(xminSpy.size(),1);
|
|
|
|
QCOMPARE(xmaxSpy.size(),1);
|
|
|
|
QCOMPARE(yminSpy.size(),1);
|
|
|
|
QCOMPARE(ymaxSpy.size(),1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
drag->setXmin(10);
|
|
|
|
drag->setXmax(10);
|
|
|
|
drag->setYmin(10);
|
|
|
|
drag->setYmax(10);
|
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(xminSpy.size(),1);
|
|
|
|
QCOMPARE(xmaxSpy.size(),1);
|
|
|
|
QCOMPARE(yminSpy.size(),1);
|
|
|
|
QCOMPARE(ymaxSpy.size(),1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
// filterChildren
|
|
|
|
QSignalSpy filterChildrenSpy(drag, SIGNAL(filterChildrenChanged()));
|
|
|
|
|
|
|
|
drag->setFilterChildren(true);
|
|
|
|
|
|
|
|
QVERIFY(drag->filterChildren());
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(filterChildrenSpy.size(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
drag->setFilterChildren(true);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(filterChildrenSpy.size(), 1);
|
2013-08-22 15:20:52 +00:00
|
|
|
|
|
|
|
// threshold
|
|
|
|
QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance());
|
|
|
|
QSignalSpy thresholdSpy(drag, SIGNAL(thresholdChanged()));
|
|
|
|
drag->setThreshold(0.0);
|
|
|
|
QCOMPARE(drag->threshold(), 0.0);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(thresholdSpy.size(), 1);
|
2013-08-22 15:20:52 +00:00
|
|
|
drag->setThreshold(99);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(thresholdSpy.size(), 2);
|
2013-08-22 15:20:52 +00:00
|
|
|
drag->setThreshold(99);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(thresholdSpy.size(), 2);
|
2013-08-22 15:20:52 +00:00
|
|
|
drag->resetThreshold();
|
|
|
|
QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance());
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(thresholdSpy.size(), 3);
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::resetDrag()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2019-10-04 12:53:31 +00:00
|
|
|
window.setInitialProperties({{"haveTarget", true}});
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragreset.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem*>(window.rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(rootItem != nullptr);
|
2011-09-08 13:58:13 +00:00
|
|
|
QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(drag->target() != nullptr);
|
2019-10-04 12:53:31 +00:00
|
|
|
auto root = window.rootObject();
|
|
|
|
QQmlProperty haveTarget {root, "haveTarget"};
|
|
|
|
haveTarget.write(false);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(targetSpy.size(),1);
|
2015-07-24 13:32:22 +00:00
|
|
|
QVERIFY(!drag->target());
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::dragging()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-06-21 05:49:10 +00:00
|
|
|
QFETCH(Qt::MouseButtons, acceptedButtons);
|
|
|
|
QFETCH(Qt::MouseButton, button);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragging.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-06-21 05:49:10 +00:00
|
|
|
mouseRegion->setAcceptedButtons(acceptedButtons);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2016-07-02 11:23:25 +00:00
|
|
|
QPoint p = QPoint(100,100);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, button, Qt::NoModifier, p);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
|
|
|
// First move event triggers drag, second is acted upon.
|
|
|
|
// This is due to possibility of higher stacked area taking precedence.
|
2013-03-14 02:36:20 +00:00
|
|
|
// The item is moved relative to the position of the mouse when the drag
|
|
|
|
// was triggered, this prevents a sudden change in position when the drag
|
|
|
|
// threshold is exceeded.
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:23:25 +00:00
|
|
|
int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
|
|
|
|
|
|
|
|
// move the minimum distance to activate drag
|
|
|
|
p += QPoint(dragThreshold + 1, dragThreshold + 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
|
|
|
// from here on move the item
|
|
|
|
p += QPoint(1, 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
// on macOS the cursor movement is going through a native event which
|
|
|
|
// means that it can actually take some time to show
|
|
|
|
QTRY_COMPARE(blackRect->x(), 50.0 + 1);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0 + 1);
|
|
|
|
|
|
|
|
p += QPoint(10, 10);
|
|
|
|
QTest::mouseMove(&window, p);
|
2013-01-11 13:48:32 +00:00
|
|
|
QTRY_VERIFY(drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QTRY_COMPARE(blackRect->x(), 61.0);
|
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2019-05-25 07:10:03 +00:00
|
|
|
qreal relativeX = mouseRegion->mouseX();
|
|
|
|
qreal relativeY = mouseRegion->mouseY();
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
p += QPoint(1, 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
2020-06-29 08:48:27 +00:00
|
|
|
QTRY_COMPARE(mouseRegion->mouseX(), relativeX);
|
|
|
|
QCOMPARE(mouseRegion->mouseY(), relativeY);
|
2019-05-25 07:10:03 +00:00
|
|
|
}
|
2020-06-29 08:48:27 +00:00
|
|
|
QVERIFY(drag->active());
|
2019-05-25 07:10:03 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, button, Qt::NoModifier, p);
|
2013-01-11 13:48:32 +00:00
|
|
|
QTRY_VERIFY(!drag->active());
|
2019-05-25 07:10:03 +00:00
|
|
|
QTRY_COMPARE(blackRect->x(), 81.0);
|
|
|
|
QCOMPARE(blackRect->y(), 81.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 08:48:27 +00:00
|
|
|
void tst_QQuickMouseArea::selfDrag() // QTBUG-85111
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("selfDrag.qml")));
|
2020-06-29 08:48:27 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *ma = window.rootObject()->findChild<QQuickMouseArea*>("ma");
|
|
|
|
QVERIFY(ma != nullptr);
|
|
|
|
QQuickDrag *drag = ma->drag();
|
|
|
|
QVERIFY(drag != nullptr);
|
|
|
|
QCOMPARE(ma, drag->target());
|
|
|
|
|
|
|
|
QQuickItem *fillRect = window.rootObject()->findChild<QQuickItem*>("fill");
|
|
|
|
QVERIFY(fillRect != nullptr);
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
|
|
|
QPoint p = QPoint(100,100);
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(ma->x(), 0);
|
|
|
|
QCOMPARE(ma->y(), 0);
|
|
|
|
|
|
|
|
int dragThreshold = QGuiApplication::styleHints()->startDragDistance();
|
|
|
|
|
|
|
|
// First move event triggers drag, second is acted upon.
|
|
|
|
// move the minimum distance to activate drag
|
|
|
|
p += QPoint(dragThreshold + 1, dragThreshold + 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
|
|
|
// from here on move the item
|
|
|
|
p += QPoint(1, 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(ma->x(), 1);
|
|
|
|
QCOMPARE(ma->y(), 1);
|
|
|
|
|
|
|
|
p += QPoint(10, 10);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(ma->x(), 11);
|
|
|
|
QCOMPARE(ma->y(), 11);
|
|
|
|
|
|
|
|
qreal relativeX = ma->mouseX();
|
|
|
|
qreal relativeY = ma->mouseY();
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
p += QPoint(1, 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QVERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(ma->mouseX(), relativeX);
|
|
|
|
QCOMPARE(ma->mouseY(), relativeY);
|
|
|
|
}
|
|
|
|
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
QTRY_COMPARE(ma->x(), 31);
|
|
|
|
QCOMPARE(ma->y(), 31);
|
|
|
|
}
|
|
|
|
|
2014-05-07 17:01:19 +00:00
|
|
|
void tst_QQuickMouseArea::dragSmoothed()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragging.qml")));
|
2014-05-07 17:01:19 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
|
|
|
drag->setThreshold(5);
|
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(Qt::LeftButton);
|
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2014-05-07 17:01:19 +00:00
|
|
|
QVERIFY(!drag->active());
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2014-05-07 17:01:19 +00:00
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 102), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 106), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 122), 50);
|
|
|
|
QTRY_COMPARE(blackRect->x(), 50.0);
|
|
|
|
QTRY_COMPARE(blackRect->y(), 66.0);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,122));
|
2014-05-07 17:01:19 +00:00
|
|
|
|
|
|
|
// reset rect position
|
|
|
|
blackRect->setX(50.0);
|
|
|
|
blackRect->setY(50.0);
|
|
|
|
|
|
|
|
// now try with smoothed disabled
|
|
|
|
drag->setSmoothed(false);
|
|
|
|
QVERIFY(!drag->active());
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2014-05-07 17:01:19 +00:00
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 102), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 106), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 122), 50);
|
|
|
|
QTRY_COMPARE(blackRect->x(), 50.0);
|
|
|
|
QTRY_COMPARE(blackRect->y(), 72.0);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 122));
|
2014-05-07 17:01:19 +00:00
|
|
|
}
|
2013-08-22 15:20:52 +00:00
|
|
|
|
2016-06-02 19:49:37 +00:00
|
|
|
void tst_QQuickMouseArea::dragThreshold_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("preventStealing");
|
|
|
|
QTest::newRow("without preventStealing") << false;
|
|
|
|
QTest::newRow("with preventStealing") << true;
|
|
|
|
}
|
|
|
|
|
2013-08-22 15:20:52 +00:00
|
|
|
void tst_QQuickMouseArea::dragThreshold()
|
|
|
|
{
|
2016-06-02 19:49:37 +00:00
|
|
|
QFETCH(bool, preventStealing);
|
|
|
|
|
2013-08-22 15:20:52 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragging.qml")));
|
2013-08-22 15:20:52 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2016-06-02 19:49:37 +00:00
|
|
|
mouseRegion->setPreventStealing(preventStealing);
|
2013-08-22 15:20:52 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
|
|
|
|
|
|
|
drag->setThreshold(5);
|
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(Qt::LeftButton);
|
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2013-08-22 15:20:52 +00:00
|
|
|
QVERIFY(!drag->active());
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2013-08-22 15:20:52 +00:00
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 102), 50);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 100), 50);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 104), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 105), 50);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 106), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 108), 50);
|
|
|
|
QVERIFY(drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 116), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 122), 50);
|
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(blackRect->x(), 50.0);
|
|
|
|
QTRY_COMPARE(blackRect->y(), 66.0);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(122,122));
|
2013-08-22 15:20:52 +00:00
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
|
|
|
|
// Immediate drag threshold
|
|
|
|
drag->setThreshold(0);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2013-08-22 15:20:52 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(100, 122), 50);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 123), 50);
|
|
|
|
QVERIFY(drag->active());
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 124), 50);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 124));
|
2013-08-22 15:20:52 +00:00
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
drag->resetThreshold();
|
|
|
|
}
|
2012-06-21 05:49:10 +00:00
|
|
|
void tst_QQuickMouseArea::invalidDrag()
|
|
|
|
{
|
|
|
|
QFETCH(Qt::MouseButtons, acceptedButtons);
|
|
|
|
QFETCH(Qt::MouseButton, button);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragging.qml")));
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2012-06-21 05:49:10 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2012-06-21 05:49:10 +00:00
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(acceptedButtons);
|
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2012-06-21 05:49:10 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, button, Qt::NoModifier, QPoint(100,100));
|
2012-06-21 05:49:10 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
|
|
|
// First move event triggers drag, second is acted upon.
|
|
|
|
// This is due to possibility of higher stacked area taking precedence.
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(111,111));
|
2012-06-21 05:49:10 +00:00
|
|
|
QTest::qWait(50);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(122,122));
|
2012-06-21 05:49:10 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, button, Qt::NoModifier, QPoint(122,122));
|
2012-06-21 05:49:10 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
}
|
|
|
|
|
2013-11-25 22:55:22 +00:00
|
|
|
void tst_QQuickMouseArea::cancelDragging()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragging.qml")));
|
2013-11-25 22:55:22 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2013-11-25 22:55:22 +00:00
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(Qt::LeftButton);
|
|
|
|
|
|
|
|
// target
|
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2013-11-25 22:55:22 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2016-07-02 11:33:34 +00:00
|
|
|
QPoint p = QPoint(100,100);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2013-11-25 22:55:22 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
2016-07-02 11:33:34 +00:00
|
|
|
p += QPoint(startDragDistance() + 1, 0);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
|
|
|
|
p += QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
2013-11-25 22:55:22 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(blackRect->x(), 61.0);
|
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
|
|
|
|
|
|
|
mouseRegion->QQuickItem::ungrabMouse();
|
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 61.0);
|
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(132,132), 50);
|
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 61.0);
|
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(122,122));
|
2013-11-25 22:55:22 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 00:39:28 +00:00
|
|
|
// QTBUG-58347
|
|
|
|
void tst_QQuickMouseArea::availableDistanceLessThanDragThreshold()
|
|
|
|
{
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("availableDistanceLessThanDragThreshold.qml")));
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
2017-01-25 00:39:28 +00:00
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
QPoint position(100, 100);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2017-01-25 00:39:28 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
position.setX(301);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2017-01-25 00:39:28 +00:00
|
|
|
position.setX(501);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2017-01-25 00:39:28 +00:00
|
|
|
QVERIFY(mouseArea->drag()->active());
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2017-01-25 00:39:28 +00:00
|
|
|
|
|
|
|
QVERIFY(!mouseArea->drag()->active());
|
|
|
|
QCOMPARE(mouseArea->x(), 200.0);
|
|
|
|
}
|
|
|
|
|
2012-05-11 01:01:33 +00:00
|
|
|
void tst_QQuickMouseArea::setDragOnPressed()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("setDragOnPressed.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = qobject_cast<QQuickMouseArea *>(window.rootObject());
|
2012-05-11 01:01:33 +00:00
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
// target
|
|
|
|
QQuickItem *target = mouseArea->findChild<QQuickItem*>("target");
|
|
|
|
QVERIFY(target);
|
|
|
|
|
2016-07-02 11:39:12 +00:00
|
|
|
QPoint p = QPoint(100, 100);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2012-05-11 01:01:33 +00:00
|
|
|
|
|
|
|
QQuickDrag *drag = mouseArea->drag();
|
|
|
|
QVERIFY(drag);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
|
|
|
QCOMPARE(target->x(), 50.0);
|
|
|
|
QCOMPARE(target->y(), 50.0);
|
|
|
|
|
|
|
|
// First move event triggers drag, second is acted upon.
|
|
|
|
// This is due to possibility of higher stacked area taking precedence.
|
|
|
|
|
2016-07-02 11:39:12 +00:00
|
|
|
p += QPoint(startDragDistance() + 1, 0);
|
|
|
|
QTest::mouseMove(&window, p);
|
2012-05-11 01:01:33 +00:00
|
|
|
|
2016-07-02 11:39:12 +00:00
|
|
|
p += QPoint(11, 0);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(target->x(), 61.0);
|
2012-05-11 01:01:33 +00:00
|
|
|
QCOMPARE(target->y(), 50.0);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2016-07-02 11:39:12 +00:00
|
|
|
QTRY_VERIFY(!drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(target->x(), 61.0);
|
2012-05-11 01:01:33 +00:00
|
|
|
QCOMPARE(target->y(), 50.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::updateMouseAreaPosOnClick()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("updateMousePosOnClick.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickRectangle *rect = window.rootObject()->findChild<QQuickRectangle*>("ball");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(rect != nullptr);
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(mouseRegion->mouseX(), rect->x());
|
|
|
|
QCOMPARE(mouseRegion->mouseY(), rect->y());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(mouseRegion->mouseX(), 100.0);
|
|
|
|
QCOMPARE(mouseRegion->mouseY(), 100.0);
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(mouseRegion->mouseX(), rect->x());
|
|
|
|
QCOMPARE(mouseRegion->mouseY(), rect->y());
|
|
|
|
}
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::updateMouseAreaPosOnResize()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("updateMousePosOnResize.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickRectangle *rect = window.rootObject()->findChild<QQuickRectangle*>("brother");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(rect != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(mouseRegion->mouseX(), 0.0);
|
|
|
|
QCOMPARE(mouseRegion->mouseY(), 0.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent event(QEvent::MouseButtonPress, rect->position().toPoint(),
|
|
|
|
window.mapToGlobal(rect->position().toPoint()),
|
|
|
|
Qt::LeftButton, Qt::LeftButton, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &event);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(!mouseRegion->property("emitPositionChanged").toBool());
|
|
|
|
QVERIFY(mouseRegion->property("mouseMatchesPos").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-11-25 05:22:09 +00:00
|
|
|
QCOMPARE(mouseRegion->property("x1").toReal(), 0.0);
|
|
|
|
QCOMPARE(mouseRegion->property("y1").toReal(), 0.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-11-25 05:22:09 +00:00
|
|
|
QCOMPARE(mouseRegion->property("x2").toReal(), rect->x());
|
|
|
|
QCOMPARE(mouseRegion->property("y2").toReal(), rect->y());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(mouseRegion->mouseX(), rect->x());
|
|
|
|
QCOMPARE(mouseRegion->mouseY(), rect->y());
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::noOnClickedWithPressAndHold()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
// We handle onPressAndHold, therefore no onClicked
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("clickandhold.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = qobject_cast<QQuickMouseArea*>(window.rootObject()->children().first());
|
2013-01-11 13:48:32 +00:00
|
|
|
QVERIFY(mouseArea);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(mouseArea->pressedButtons(), Qt::LeftButton);
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("clicked").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("held").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-01-11 13:48:32 +00:00
|
|
|
// timeout is 800 (in qquickmousearea.cpp)
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2013-01-11 13:48:32 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("clicked").toBool());
|
|
|
|
QVERIFY(window.rootObject()->property("held").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTRY_VERIFY(window.rootObject()->property("held").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("clicked").toBool());
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
|
|
|
// We do not handle onPressAndHold, therefore we get onClicked
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("noclickandhold.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("clicked").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(window.rootObject()->property("clicked").toBool());
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::onMousePressRejected()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("rejectEvent.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(window.rootObject()->property("enabled").toBool());
|
|
|
|
|
|
|
|
QVERIFY(!window.rootObject()->property("mr1_pressed").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr1_released").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr1_canceled").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr2_pressed").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr2_released").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr2_canceled").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(window.rootObject()->property("mr1_pressed").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr1_released").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr1_canceled").toBool());
|
|
|
|
QVERIFY(window.rootObject()->property("mr2_pressed").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr2_released").toBool());
|
2016-07-26 23:00:28 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("mr2_canceled").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTRY_VERIFY(window.rootObject()->property("mr1_released").toBool());
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("mr1_canceled").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("mr2_released").toBool());
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2014-09-03 18:42:04 +00:00
|
|
|
|
|
|
|
void tst_QQuickMouseArea::pressedCanceledOnWindowDeactivate_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("doubleClick");
|
|
|
|
QTest::newRow("simple click") << false;
|
|
|
|
QTest::newRow("double click") << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::pressedCanceledOnWindowDeactivate()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2014-09-03 18:42:04 +00:00
|
|
|
QFETCH(bool, doubleClick);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("pressedCanceled.qml")));
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
|
|
|
|
int expectedRelease = 0;
|
|
|
|
int expectedClicks = 0;
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), expectedClicks);
|
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), Qt::LeftButton, Qt::LeftButton, {});
|
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), Qt::LeftButton, Qt::LeftButton, {});
|
2014-09-03 18:42:04 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-04 21:36:39 +00:00
|
|
|
QTRY_VERIFY(window.rootObject()->property("pressed").toBool());
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), expectedClicks);
|
|
|
|
|
|
|
|
if (doubleClick) {
|
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2016-07-04 21:36:39 +00:00
|
|
|
QTRY_VERIFY(!window.rootObject()->property("pressed").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), ++expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), ++expectedClicks);
|
|
|
|
|
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent2(QEvent::MouseButtonDblClick, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), Qt::LeftButton, Qt::LeftButton, {});
|
2014-09-03 18:42:04 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent2);
|
|
|
|
|
2016-07-04 21:36:39 +00:00
|
|
|
QTRY_VERIFY(window.rootObject()->property("pressed").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), expectedClicks);
|
|
|
|
QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 1);
|
|
|
|
}
|
|
|
|
|
2020-11-18 22:11:37 +00:00
|
|
|
QEvent windowDeactivateEvent(QEvent::WindowDeactivate);
|
|
|
|
QGuiApplication::sendEvent(&window, &windowDeactivateEvent);
|
2016-07-04 21:36:39 +00:00
|
|
|
QTRY_VERIFY(!window.rootObject()->property("pressed").toBool());
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(window.rootObject()->property("canceled").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), expectedClicks);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
//press again
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2016-07-04 21:36:39 +00:00
|
|
|
QTRY_VERIFY(window.rootObject()->property("pressed").toBool());
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), expectedClicks);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
//release
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2016-07-04 21:36:39 +00:00
|
|
|
QTRY_VERIFY(!window.rootObject()->property("pressed").toBool());
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
2014-09-03 18:42:04 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), ++expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), ++expectedClicks);
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::doubleClick()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2012-06-21 05:49:10 +00:00
|
|
|
QFETCH(Qt::MouseButtons, acceptedButtons);
|
|
|
|
QFETCH(Qt::MouseButton, button);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("doubleclick.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mousearea");
|
2012-06-21 05:49:10 +00:00
|
|
|
QVERIFY(mouseArea);
|
|
|
|
mouseArea->setAcceptedButtons(acceptedButtons);
|
|
|
|
|
2012-03-12 06:40:52 +00:00
|
|
|
// The sequence for a double click is:
|
|
|
|
// press, release, (click), press, double click, release
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent2 = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2020-11-11 12:51:35 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent2);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 2);
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// QTBUG-14832
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::clickTwice()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2012-06-21 05:49:10 +00:00
|
|
|
QFETCH(Qt::MouseButtons, acceptedButtons);
|
|
|
|
QFETCH(Qt::MouseButton, button);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("clicktwice.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mousearea");
|
2012-06-21 05:49:10 +00:00
|
|
|
QVERIFY(mouseArea);
|
|
|
|
mouseArea->setAcceptedButtons(acceptedButtons);
|
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("pressed").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2020-11-11 12:51:35 +00:00
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent2 = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2020-11-11 12:51:35 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent2);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("pressed").toInt(), 2);
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 2);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 2);
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-06-21 05:49:10 +00:00
|
|
|
void tst_QQuickMouseArea::invalidClick()
|
|
|
|
{
|
|
|
|
QFETCH(Qt::MouseButtons, acceptedButtons);
|
|
|
|
QFETCH(Qt::MouseButton, button);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("doubleclick.qml")));
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mousearea");
|
2012-06-21 05:49:10 +00:00
|
|
|
QVERIFY(mouseArea);
|
|
|
|
mouseArea->setAcceptedButtons(acceptedButtons);
|
|
|
|
|
|
|
|
// The sequence for a double click is:
|
|
|
|
// press, release, (click), press, double click, release
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 0);
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2022-01-31 20:05:39 +00:00
|
|
|
QMouseEvent pressEvent2 = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100),
|
|
|
|
window.mapToGlobal(QPoint(100, 100)), button, button, {});
|
2020-11-11 12:51:35 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent2);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
2012-06-21 05:49:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 0);
|
|
|
|
QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 0);
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 0);
|
2012-06-21 05:49:10 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::pressedOrdering()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("pressedOrdering.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("base"));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("pressed"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("toggled"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, {100, 100});
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QCOMPARE(window.rootObject()->property("value").toString(), QLatin1String("pressed"));
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::preventStealing()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("preventstealing.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
|
|
|
|
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window.rootObject());
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(flickable != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mousearea");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QSignalSpy mousePositionSpy(mouseArea, SIGNAL(positionChanged(QQuickMouseEvent*)));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:53:39 +00:00
|
|
|
QPoint p = QPoint(80, 80);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// Without preventStealing, mouse movement over MouseArea would
|
|
|
|
// cause the Flickable to steal mouse and trigger content movement.
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:53:39 +00:00
|
|
|
p += QPoint(-startDragDistance() * 2, -startDragDistance() * 2);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(-10, -10);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(-10, -10);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(-10, -10);
|
|
|
|
QTest::mouseMove(&window, p);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:53:39 +00:00
|
|
|
// We should have received all four move events
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(mousePositionSpy.size(), 4);
|
2016-07-02 11:53:39 +00:00
|
|
|
mousePositionSpy.clear();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseArea->pressed());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// Flickable content should not have moved.
|
|
|
|
QCOMPARE(flickable->contentX(), 0.);
|
|
|
|
QCOMPARE(flickable->contentY(), 0.);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// Now allow stealing and confirm Flickable does its thing.
|
2013-08-23 08:38:08 +00:00
|
|
|
window.rootObject()->setProperty("stealing", false);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:53:39 +00:00
|
|
|
p = QPoint(80, 80);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// Without preventStealing, mouse movement over MouseArea would
|
|
|
|
// cause the Flickable to steal mouse and trigger content movement.
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:53:39 +00:00
|
|
|
p += QPoint(-startDragDistance() * 2, -startDragDistance() * 2);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(-10, -10);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(-10, -10);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(-10, -10);
|
|
|
|
QTest::mouseMove(&window, p);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// We should only have received the first move event
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(mousePositionSpy.size(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
// Our press should be taken away
|
|
|
|
QVERIFY(!mouseArea->pressed());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2016-07-02 11:53:39 +00:00
|
|
|
// Flickable swallows the first move, then moves 2*10 px
|
|
|
|
QTRY_COMPARE(flickable->contentX(), 20.);
|
|
|
|
QCOMPARE(flickable->contentY(), 20.);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2022-05-18 11:21:05 +00:00
|
|
|
// QTBUG-103522
|
|
|
|
void tst_QQuickMouseArea::preventStealingListViewChild()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("preventStealingListViewChild.qml")));
|
|
|
|
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window.rootObject());
|
|
|
|
QVERIFY(flickable);
|
|
|
|
QQuickMouseArea *mouseArea = flickable->findChild<QQuickMouseArea*>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
QPoint p = mouseArea->mapToScene(mouseArea->boundingRect().center()).toPoint();
|
|
|
|
const int threshold = qApp->styleHints()->startDragDistance();
|
|
|
|
|
|
|
|
flickable->flick(0, -10000);
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
QVERIFY(flickable->isMovingVertically());
|
|
|
|
QTest::touchEvent(&window, device).press(0, p);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
for (int j = 0; j < 4 && !mouseArea->drag()->active(); ++j) {
|
|
|
|
p += QPoint(0, threshold);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
}
|
|
|
|
// MouseArea should be dragged because of preventStealing; ListView does not steal the grab.
|
|
|
|
QVERIFY(mouseArea->drag()->active());
|
|
|
|
QCOMPARE(flickable->isDragging(), false);
|
|
|
|
QTest::touchEvent(&window, device).release(0, p);
|
|
|
|
QCOMPARE(mouseArea->drag()->active(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::clickThrough()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2020-11-19 16:22:37 +00:00
|
|
|
// timestamp delay to avoid generating a double click
|
2016-08-12 11:38:54 +00:00
|
|
|
const int doubleClickInterval = qApp->styleHints()->mouseDoubleClickInterval() + 10;
|
2020-11-19 16:22:37 +00:00
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("clickThrough.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
2016-08-12 11:38:54 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
// With no handlers defined, click, doubleClick and PressAndHold should propagate to those with handlers
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTRY_COMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(root->property("clicks").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("doubleClicks").toInt(), 0);
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::qWait(1000);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTRY_COMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(root->property("clicks").toInt(), 1);
|
|
|
|
QTRY_COMPARE(root->property("pressAndHolds").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(root->property("clicks").toInt(), 2);
|
|
|
|
QTRY_COMPARE(root->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(root->property("pressAndHolds").toInt(), 1);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("clickThrough2.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
// With handlers defined, click, doubleClick and PressAndHold should propagate only when explicitly ignored
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("clicks").toInt(), 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::qWait(1000);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("clicks").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("pressAndHolds").toInt(), 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("clicks").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("doubleClicks").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("pressAndHolds").toInt(), 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
root->setProperty("letThrough", QVariant(true));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(root->property("clicks").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::qWait(1000);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-11-15 01:51:50 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(root->property("clicks").toInt(), 1);
|
|
|
|
QCOMPARE(root->property("pressAndHolds").toInt(), 1);
|
2011-11-15 01:51:50 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-11-15 01:51:50 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(root->property("clicks").toInt(), 2);
|
|
|
|
QCOMPARE(root->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(root->property("pressAndHolds").toInt(), 1);
|
2011-11-15 01:51:50 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
root->setProperty("noPropagation", QVariant(true));
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::qWait(1000);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(root->property("clicks").toInt(), 2);
|
|
|
|
QCOMPARE(root->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(root->property("pressAndHolds").toInt(), 1);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("qtbug34368.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
// QTBUG-34368 - Shouldn't propagate to disabled mouse areas
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("clicksEnabled").toInt(), 1);
|
|
|
|
QCOMPARE(root->property("clicksDisabled").toInt(), 1); //Not disabled yet
|
2013-11-04 21:29:12 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
root->setProperty("disableLower", QVariant(true));
|
2015-11-26 06:37:17 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100), doubleClickInterval);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2015-11-26 06:37:17 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(root->property("clicksEnabled").toInt(), 2);
|
|
|
|
QCOMPARE(root->property("clicksDisabled").toInt(), 1); //disabled, shouldn't increment
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("qtbug49100.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
2015-11-26 06:37:17 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
// QTBUG-49100
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2015-11-26 06:37:17 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(window.rootObject());
|
|
|
|
}
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::hoverPosition()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("hoverPosition.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(root->property("mouseX").toReal(), qreal(0));
|
|
|
|
QCOMPARE(root->property("mouseY").toReal(), qreal(0));
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window,QPoint(10,32));
|
2011-09-08 14:46:54 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(root->property("mouseX").toReal(), qreal(10));
|
|
|
|
QCOMPARE(root->property("mouseY").toReal(), qreal(32));
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::hoverPropagation()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("hoverPropagation.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
// QTBUG-18175, to behave like GV did.
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(root->property("point1").toBool(), false);
|
|
|
|
QCOMPARE(root->property("point2").toBool(), false);
|
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, {32, 32});
|
2011-09-08 14:46:54 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(root->property("point1").toBool(), true);
|
|
|
|
QCOMPARE(root->property("point2").toBool(), false);
|
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, {232, 32});
|
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(root->property("point1").toBool(), false);
|
|
|
|
QCOMPARE(root->property("point2").toBool(), true);
|
|
|
|
}
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2012-02-15 06:27:36 +00:00
|
|
|
void tst_QQuickMouseArea::hoverVisible()
|
|
|
|
{
|
2022-02-06 23:16:22 +00:00
|
|
|
if (QGuiApplication::platformName() == QLatin1String("minimal"))
|
|
|
|
QSKIP("Skipping due to grabWindow not functional on minimal platforms");
|
2017-08-30 12:39:28 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("hoverVisible.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2012-02-15 06:27:36 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickMouseArea *mouseTracker = root->findChild<QQuickMouseArea*>("mousetracker");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseTracker != nullptr);
|
2012-02-15 06:27:36 +00:00
|
|
|
|
|
|
|
QSignalSpy enteredSpy(mouseTracker, SIGNAL(entered()));
|
|
|
|
|
2012-03-12 06:40:52 +00:00
|
|
|
// Note: We need to use a position that is different from the position in the last event
|
|
|
|
// generated in the previous test case. Otherwise it is not interpreted as a move.
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window,QPoint(11,33));
|
2012-02-15 06:27:36 +00:00
|
|
|
|
|
|
|
QCOMPARE(mouseTracker->hovered(), false);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(enteredSpy.size(), 0);
|
2012-02-15 06:27:36 +00:00
|
|
|
|
|
|
|
mouseTracker->setVisible(true);
|
|
|
|
|
|
|
|
QCOMPARE(mouseTracker->hovered(), true);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(enteredSpy.size(), 1);
|
2012-02-15 06:27:36 +00:00
|
|
|
|
2012-03-28 06:46:31 +00:00
|
|
|
QCOMPARE(QPointF(mouseTracker->mouseX(), mouseTracker->mouseY()), QPointF(11,33));
|
2019-09-19 10:04:55 +00:00
|
|
|
|
|
|
|
// QTBUG-77983
|
|
|
|
mouseTracker->setVisible(false);
|
|
|
|
mouseTracker->setEnabled(false);
|
|
|
|
|
|
|
|
QCOMPARE(mouseTracker->hovered(), false);
|
|
|
|
mouseTracker->setVisible(true);
|
|
|
|
// if the enabled property is false, the containsMouse property shouldn't become true
|
|
|
|
// when an invisible mousearea become visible
|
|
|
|
QCOMPARE(mouseTracker->hovered(), false);
|
|
|
|
|
|
|
|
mouseTracker->parentItem()->setEnabled(false);
|
|
|
|
mouseTracker->setVisible(false);
|
|
|
|
mouseTracker->setEnabled(true);
|
|
|
|
|
|
|
|
QCOMPARE(mouseTracker->hovered(), false);
|
|
|
|
mouseTracker->setVisible(true);
|
|
|
|
// if the parent item is not enabled, the containsMouse property will be false, even if
|
|
|
|
// the mousearea is enabled
|
|
|
|
QCOMPARE(mouseTracker->hovered(), false);
|
|
|
|
|
|
|
|
mouseTracker->parentItem()->setEnabled(true);
|
|
|
|
mouseTracker->setVisible(false);
|
|
|
|
mouseTracker->setEnabled(true);
|
|
|
|
|
|
|
|
QCOMPARE(mouseTracker->hovered(), false);
|
|
|
|
mouseTracker->setVisible(true);
|
|
|
|
QCOMPARE(mouseTracker->hovered(), true);
|
2012-02-15 06:27:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 14:18:54 +00:00
|
|
|
void tst_QQuickMouseArea::hoverAfterPress()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("hoverAfterPress.qml")));
|
2013-04-26 14:18:54 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(22,33));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(200,200));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(22,33));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(200,200));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(22,33));
|
2013-04-26 14:18:54 +00:00
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
|
|
|
}
|
|
|
|
|
2016-06-20 09:57:43 +00:00
|
|
|
void tst_QQuickMouseArea::subtreeHoverEnabled()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("qtbug54019.qml")));
|
2016-06-20 09:57:43 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2016-06-20 09:57:43 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>();
|
|
|
|
QQuickItemPrivate *rootPrivate = QQuickItemPrivate::get(root);
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
2016-06-20 09:57:43 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(10, 160));
|
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
|
|
|
QVERIFY(rootPrivate->subtreeHoverEnabled);
|
|
|
|
QTest::mouseMove(&window, QPoint(10, 10));
|
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
|
|
|
QTest::mouseMove(&window, QPoint(160, 10));
|
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
|
|
|
}
|
|
|
|
|
2022-09-16 11:13:00 +00:00
|
|
|
void tst_QQuickMouseArea::hoverWhenDisabled()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("hoverVisible.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
mouseArea->setVisible(true);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(50, 50));
|
|
|
|
QVERIFY(mouseArea->hovered());
|
|
|
|
|
|
|
|
mouseArea->setEnabled(false);
|
|
|
|
QTest::mouseMove(&window, QPoint(51, 50));
|
|
|
|
QVERIFY(!mouseArea->hovered());
|
|
|
|
|
|
|
|
mouseArea->setEnabled(true);
|
|
|
|
QTest::mouseMove(&window, QPoint(50, 50));
|
|
|
|
QVERIFY(mouseArea->hovered());
|
|
|
|
|
|
|
|
mouseArea->setHoverEnabled(false);
|
|
|
|
QTest::mouseMove(&window, QPoint(51, 50));
|
|
|
|
QVERIFY(!mouseArea->hovered());
|
|
|
|
|
|
|
|
mouseArea->setHoverEnabled(true);
|
|
|
|
QTest::mouseMove(&window, QPoint(50, 50));
|
|
|
|
QVERIFY(mouseArea->hovered());
|
|
|
|
}
|
|
|
|
|
2012-03-05 05:07:27 +00:00
|
|
|
void tst_QQuickMouseArea::disableAfterPress()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("dragging.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
2013-08-23 08:38:08 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>("mouseregion");
|
2012-03-05 05:07:27 +00:00
|
|
|
QQuickDrag *drag = mouseArea->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QSignalSpy mousePositionSpy(mouseArea, SIGNAL(positionChanged(QQuickMouseEvent*)));
|
|
|
|
QSignalSpy mousePressSpy(mouseArea, SIGNAL(pressed(QQuickMouseEvent*)));
|
|
|
|
QSignalSpy mouseReleaseSpy(mouseArea, SIGNAL(released(QQuickMouseEvent*)));
|
|
|
|
|
|
|
|
// target
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickItem *blackRect = root->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
2016-07-02 12:16:34 +00:00
|
|
|
QPoint p = QPoint(100,100);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(mousePressSpy.size(), 1);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
|
|
|
// First move event triggers drag, second is acted upon.
|
|
|
|
// This is due to possibility of higher stacked area taking precedence.
|
|
|
|
|
2016-07-02 12:16:34 +00:00
|
|
|
p += QPoint(startDragDistance() + 1, 0);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(mousePositionSpy.size(), 2);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
2016-07-02 12:16:34 +00:00
|
|
|
QTRY_VERIFY(drag->active());
|
|
|
|
QTRY_COMPARE(blackRect->x(), 61.0);
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
mouseArea->setEnabled(false);
|
|
|
|
|
|
|
|
// move should still be acted upon
|
2016-07-02 12:16:34 +00:00
|
|
|
p += QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p += QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(mousePositionSpy.size(), 4);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->x(), 83.0);
|
|
|
|
QCOMPARE(blackRect->y(), 83.0);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(mouseArea->pressed());
|
|
|
|
QVERIFY(mouseArea->hovered());
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(mouseReleaseSpy.size(), 1);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->x(), 83.0);
|
|
|
|
QCOMPARE(blackRect->y(), 83.0);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(!mouseArea->pressed());
|
|
|
|
QVERIFY(!mouseArea->hovered()); // since hover is not enabled
|
|
|
|
|
|
|
|
// Next press will be ignored
|
|
|
|
blackRect->setX(50);
|
|
|
|
blackRect->setY(50);
|
|
|
|
|
|
|
|
mousePressSpy.clear();
|
|
|
|
mousePositionSpy.clear();
|
|
|
|
mouseReleaseSpy.clear();
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(mousePressSpy.size(), 0);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(111,111));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(122,122));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(mousePositionSpy.size(), 0);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(122,122));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(mouseReleaseSpy.size(), 0);
|
2012-03-05 05:07:27 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 11:28:52 +00:00
|
|
|
void tst_QQuickMouseArea::disableParentOnPress_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<const QPointingDevice *>("device");
|
|
|
|
|
|
|
|
QTest::newRow("core pointer") << QPointingDevice::primaryPointingDevice();
|
2022-10-23 08:09:55 +00:00
|
|
|
QTest::newRow("touch") << static_cast<const QPointingDevice *>(device); // TODO QTBUG-107864
|
2022-10-18 11:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::disableParentOnPress() // QTBUG-39806 and QTBUG-103788
|
|
|
|
{
|
|
|
|
QFETCH(const QPointingDevice *, device);
|
|
|
|
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("disableParentOnPress.qml")));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
|
|
|
QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
QSignalSpy pressedChangedSpy(mouseArea, &QQuickMouseArea::pressedChanged);
|
|
|
|
QSignalSpy canceledSpy(mouseArea, &QQuickMouseArea::canceled);
|
|
|
|
QSignalSpy enabledSpy(mouseArea, &QQuickMouseArea::enabledChanged);
|
|
|
|
QSignalSpy parentEnabledSpy(root, &QQuickItem::enabledChanged);
|
|
|
|
const QPoint p(100, 100);
|
|
|
|
|
|
|
|
QQuickTest::pointerPress(device, &window, 0, p);
|
|
|
|
QTRY_COMPARE(parentEnabledSpy.size(), 1);
|
|
|
|
QCOMPARE(root->isEnabled(), false);
|
|
|
|
QCOMPARE(mouseArea->isEnabled(), true); // enabled is independent, unfortunately (inverse of QTBUG-38364)
|
|
|
|
QCOMPARE(QQuickItemPrivate::get(mouseArea)->effectiveEnable, false);
|
|
|
|
// bug fix: it knows it got effectively disabled, so now it's no longer pressed
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(canceledSpy.size(), 1); // ...because the press was canceled
|
|
|
|
QCOMPARE(pressedChangedSpy.size(), 2); // kerchunk
|
|
|
|
QQuickTest::pointerRelease(device, &window, 0, p);
|
|
|
|
|
|
|
|
// now re-enable it and try again
|
|
|
|
root->setEnabled(true);
|
|
|
|
QQuickTest::pointerPress(device, &window, 0, p);
|
|
|
|
QTRY_COMPARE(root->isEnabled(), false);
|
|
|
|
QCOMPARE(QQuickItemPrivate::get(mouseArea)->effectiveEnable, false);
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(canceledSpy.size(), 2);
|
|
|
|
QCOMPARE(pressedChangedSpy.size(), 4);
|
|
|
|
QQuickTest::pointerRelease(device, &window, 0, p);
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:19:26 +00:00
|
|
|
void tst_QQuickMouseArea::onWheel()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("wheel.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2012-01-05 18:19:26 +00:00
|
|
|
|
|
|
|
QWheelEvent wheelEvent(QPoint(10, 32), QPoint(10, 32), QPoint(60, 20), QPoint(0, 120),
|
2019-08-02 12:41:10 +00:00
|
|
|
Qt::NoButton, Qt::ControlModifier, Qt::NoScrollPhase, false);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &wheelEvent);
|
2012-01-05 18:19:26 +00:00
|
|
|
|
|
|
|
QCOMPARE(root->property("angleDeltaY").toInt(), 120);
|
|
|
|
QCOMPARE(root->property("mouseX").toReal(), qreal(10));
|
|
|
|
QCOMPARE(root->property("mouseY").toReal(), qreal(32));
|
|
|
|
QCOMPARE(root->property("controlPressed").toBool(), true);
|
|
|
|
}
|
|
|
|
|
2012-02-26 16:27:34 +00:00
|
|
|
void tst_QQuickMouseArea::transformedMouseArea_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("insideTarget");
|
|
|
|
QTest::addColumn<QList<QPoint> >("points");
|
|
|
|
|
|
|
|
QList<QPoint> pointsInside;
|
|
|
|
pointsInside << QPoint(200, 140)
|
|
|
|
<< QPoint(140, 200)
|
|
|
|
<< QPoint(200, 200)
|
|
|
|
<< QPoint(260, 200)
|
|
|
|
<< QPoint(200, 260);
|
|
|
|
QTest::newRow("checking points inside") << true << pointsInside;
|
|
|
|
|
|
|
|
QList<QPoint> pointsOutside;
|
|
|
|
pointsOutside << QPoint(140, 140)
|
|
|
|
<< QPoint(260, 140)
|
|
|
|
<< QPoint(120, 200)
|
|
|
|
<< QPoint(280, 200)
|
|
|
|
<< QPoint(140, 260)
|
|
|
|
<< QPoint(260, 260);
|
|
|
|
QTest::newRow("checking points outside") << false << pointsOutside;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::transformedMouseArea()
|
|
|
|
{
|
|
|
|
QFETCH(bool, insideTarget);
|
|
|
|
QFETCH(QList<QPoint>, points);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("transformedMouseArea.qml")));
|
2012-02-26 16:27:34 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea");
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(mouseArea);
|
2012-02-26 16:27:34 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
for (const QPoint &point : points) {
|
2012-02-26 16:27:34 +00:00
|
|
|
// check hover
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, point);
|
2013-08-12 03:28:17 +00:00
|
|
|
QTRY_COMPARE(mouseArea->property("containsMouse").toBool(), insideTarget);
|
2012-02-26 16:27:34 +00:00
|
|
|
|
|
|
|
// check mouse press
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point);
|
2013-08-12 03:28:17 +00:00
|
|
|
QTRY_COMPARE(mouseArea->property("pressed").toBool(), insideTarget);
|
2012-02-26 16:27:34 +00:00
|
|
|
|
|
|
|
// check mouse release
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, point);
|
2013-08-12 03:28:17 +00:00
|
|
|
QTRY_COMPARE(mouseArea->property("pressed").toBool(), false);
|
2012-02-26 16:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 15:54:51 +00:00
|
|
|
struct MouseEvent {
|
|
|
|
QEvent::Type type;
|
|
|
|
Qt::MouseButton button;
|
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(MouseEvent)
|
|
|
|
|
2012-07-10 06:40:06 +00:00
|
|
|
void tst_QQuickMouseArea::pressedMultipleButtons_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::MouseButtons>("accepted");
|
2018-02-26 15:54:51 +00:00
|
|
|
QTest::addColumn<QList<MouseEvent> >("mouseEvents");
|
2012-07-10 06:40:06 +00:00
|
|
|
QTest::addColumn<QList<bool> >("pressed");
|
|
|
|
QTest::addColumn<QList<Qt::MouseButtons> >("pressedButtons");
|
|
|
|
QTest::addColumn<int>("changeCount");
|
|
|
|
|
2018-02-26 15:54:51 +00:00
|
|
|
Qt::MouseButtons accepted;
|
|
|
|
QList<MouseEvent> mouseEvents;
|
2012-07-10 06:40:06 +00:00
|
|
|
QList<bool> pressed;
|
|
|
|
QList<Qt::MouseButtons> pressedButtons;
|
2018-02-26 15:54:51 +00:00
|
|
|
int changeCount;
|
|
|
|
|
|
|
|
MouseEvent leftPress = { QEvent::MouseButtonPress, Qt::LeftButton };
|
|
|
|
MouseEvent leftRelease = { QEvent::MouseButtonRelease, Qt::LeftButton };
|
|
|
|
MouseEvent rightPress = { QEvent::MouseButtonPress, Qt::RightButton };
|
|
|
|
MouseEvent rightRelease = { QEvent::MouseButtonRelease, Qt::RightButton };
|
|
|
|
|
|
|
|
auto addRowWithFormattedTitleAndReset = [&]() {
|
|
|
|
QByteArray title;
|
|
|
|
title.append("Accept:");
|
|
|
|
if (accepted & Qt::LeftButton)
|
|
|
|
title.append(" LeftButton");
|
|
|
|
if (accepted & Qt::RightButton)
|
|
|
|
title.append(" RightButton");
|
|
|
|
title.append(" | Events:");
|
|
|
|
for (MouseEvent event : mouseEvents) {
|
|
|
|
title.append(event.type == QEvent::MouseButtonPress ? " Press" : " Release");
|
|
|
|
title.append(event.button == Qt::LeftButton ? " Left," : " Right,");
|
|
|
|
}
|
|
|
|
title.chop(1); // remove last comma
|
|
|
|
QTest::newRow(title) << accepted << mouseEvents << pressed << pressedButtons << changeCount;
|
|
|
|
|
|
|
|
mouseEvents.clear();
|
|
|
|
pressed.clear();
|
|
|
|
pressedButtons.clear();
|
|
|
|
};
|
|
|
|
|
|
|
|
accepted = Qt::LeftButton;
|
|
|
|
changeCount = 2;
|
|
|
|
mouseEvents << leftPress << rightPress << rightRelease << leftRelease;
|
|
|
|
pressed << true << true << true << false;
|
|
|
|
pressedButtons << Qt::LeftButton << Qt::LeftButton << Qt::LeftButton << Qt::NoButton;
|
|
|
|
addRowWithFormattedTitleAndReset();
|
|
|
|
|
|
|
|
accepted = Qt::LeftButton;
|
|
|
|
changeCount = 2;
|
|
|
|
mouseEvents << leftPress << rightPress << leftRelease << rightRelease;
|
|
|
|
pressed << true << true << false << false;
|
|
|
|
pressedButtons << Qt::LeftButton << Qt::LeftButton << Qt::NoButton << Qt::NoButton;
|
|
|
|
addRowWithFormattedTitleAndReset();
|
|
|
|
|
|
|
|
accepted = Qt::LeftButton | Qt::RightButton;
|
|
|
|
changeCount = 4;
|
|
|
|
mouseEvents << leftPress << rightPress << rightRelease << leftRelease;
|
|
|
|
pressed << true << true << true << false;
|
|
|
|
pressedButtons << Qt::LeftButton << (Qt::LeftButton | Qt::RightButton) << Qt::LeftButton
|
|
|
|
<< Qt::NoButton;
|
|
|
|
addRowWithFormattedTitleAndReset();
|
|
|
|
|
|
|
|
accepted = Qt::RightButton;
|
|
|
|
changeCount = 2;
|
|
|
|
mouseEvents << rightPress << leftPress << rightRelease << leftRelease;
|
|
|
|
pressed << true << true << false << false;
|
|
|
|
pressedButtons << Qt::RightButton << Qt::RightButton << Qt::NoButton << Qt::NoButton;
|
|
|
|
addRowWithFormattedTitleAndReset();
|
2012-07-10 06:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::pressedMultipleButtons()
|
|
|
|
{
|
|
|
|
QFETCH(Qt::MouseButtons, accepted);
|
2018-02-26 15:54:51 +00:00
|
|
|
QFETCH(QList<MouseEvent>, mouseEvents);
|
2012-07-10 06:40:06 +00:00
|
|
|
QFETCH(QList<bool>, pressed);
|
|
|
|
QFETCH(QList<Qt::MouseButtons>, pressedButtons);
|
|
|
|
QFETCH(int, changeCount);
|
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("simple.qml")));
|
2012-07-10 06:40:06 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mousearea");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
2012-07-10 06:40:06 +00:00
|
|
|
|
|
|
|
QSignalSpy pressedSpy(mouseArea, SIGNAL(pressedChanged()));
|
|
|
|
QSignalSpy pressedButtonsSpy(mouseArea, SIGNAL(pressedButtonsChanged()));
|
|
|
|
mouseArea->setAcceptedMouseButtons(accepted);
|
|
|
|
|
2018-02-26 15:54:51 +00:00
|
|
|
QPoint point(10, 10);
|
2022-10-05 05:29:16 +00:00
|
|
|
for (int i = 0; i < mouseEvents.size(); ++i) {
|
2018-02-26 15:54:51 +00:00
|
|
|
const MouseEvent mouseEvent = mouseEvents.at(i);
|
|
|
|
if (mouseEvent.type == QEvent::MouseButtonPress)
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, mouseEvent.button, Qt::NoModifier, point);
|
2018-02-26 15:54:51 +00:00
|
|
|
else
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, mouseEvent.button, Qt::NoModifier, point);
|
2012-07-10 06:40:06 +00:00
|
|
|
QCOMPARE(mouseArea->pressed(), pressed.at(i));
|
|
|
|
QCOMPARE(mouseArea->pressedButtons(), pressedButtons.at(i));
|
|
|
|
}
|
|
|
|
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(pressedSpy.size(), 2);
|
|
|
|
QCOMPARE(pressedButtonsSpy.size(), changeCount);
|
2012-07-10 06:40:06 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 14:10:34 +00:00
|
|
|
void tst_QQuickMouseArea::changeAxis()
|
|
|
|
{
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("changeAxis.qml")));
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2012-07-05 14:10:34 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseRegion != nullptr);
|
|
|
|
QVERIFY(drag != nullptr);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(Qt::LeftButton);
|
|
|
|
|
|
|
|
// target
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(blackRect != nullptr);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
|
|
|
// Start a diagonal drag
|
2016-07-02 12:16:34 +00:00
|
|
|
QPoint p = QPoint(100, 100);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
2016-07-02 12:16:34 +00:00
|
|
|
p += QPoint(startDragDistance() + 1, startDragDistance() + 1);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, p);
|
2016-07-02 12:16:34 +00:00
|
|
|
p += QPoint(11, 11);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, p);
|
2012-07-05 14:10:34 +00:00
|
|
|
QTRY_VERIFY(drag->active());
|
2016-07-02 12:16:34 +00:00
|
|
|
QTRY_COMPARE(blackRect->x(), 61.0);
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
2012-03-01 10:09:52 +00:00
|
|
|
QCOMPARE(drag->axis(), QQuickDrag::XAndYAxis);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
/* When blackRect.x becomes bigger than 75, the drag axis is changed to
|
|
|
|
* Drag.YAxis by the QML code. Verify that this happens, and that the drag
|
|
|
|
* movement is effectively constrained to the Y axis. */
|
2016-07-02 12:16:34 +00:00
|
|
|
p += QPoint(22, 22);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, p);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(blackRect->x(), 83.0);
|
|
|
|
QTRY_COMPARE(blackRect->y(), 83.0);
|
|
|
|
QTRY_COMPARE(drag->axis(), QQuickDrag::YAxis);
|
|
|
|
|
2016-07-02 12:16:34 +00:00
|
|
|
p += QPoint(11, 11);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, p);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(blackRect->y(), 94.0);
|
|
|
|
QCOMPARE(blackRect->x(), 83.0);
|
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 83.0);
|
|
|
|
QCOMPARE(blackRect->y(), 94.0);
|
|
|
|
}
|
|
|
|
|
2016-11-16 13:22:36 +00:00
|
|
|
#if QT_CONFIG(cursor)
|
2012-07-25 04:04:47 +00:00
|
|
|
void tst_QQuickMouseArea::cursorShape()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.setData("import QtQuick 2.0\n MouseArea {}", QUrl());
|
|
|
|
QScopedPointer<QObject> object(component.create());
|
|
|
|
QQuickMouseArea *mouseArea = qobject_cast<QQuickMouseArea *>(object.data());
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
QSignalSpy spy(mouseArea, SIGNAL(cursorShapeChanged()));
|
|
|
|
|
|
|
|
QCOMPARE(mouseArea->cursorShape(), Qt::ArrowCursor);
|
|
|
|
QCOMPARE(mouseArea->cursor().shape(), Qt::ArrowCursor);
|
|
|
|
|
|
|
|
mouseArea->setCursorShape(Qt::IBeamCursor);
|
|
|
|
QCOMPARE(mouseArea->cursorShape(), Qt::IBeamCursor);
|
|
|
|
QCOMPARE(mouseArea->cursor().shape(), Qt::IBeamCursor);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(spy.size(), 1);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
mouseArea->setCursorShape(Qt::IBeamCursor);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(spy.size(), 1);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
mouseArea->setCursorShape(Qt::WaitCursor);
|
|
|
|
QCOMPARE(mouseArea->cursorShape(), Qt::WaitCursor);
|
|
|
|
QCOMPARE(mouseArea->cursor().shape(), Qt::WaitCursor);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(spy.size(), 2);
|
2012-07-25 04:04:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 04:19:10 +00:00
|
|
|
void tst_QQuickMouseArea::moveAndReleaseWithoutPress()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("moveAndReleaseWithoutPress.qml")));
|
2013-08-23 08:38:08 +00:00
|
|
|
QObject *root = window.rootObject();
|
2013-02-13 04:19:10 +00:00
|
|
|
QVERIFY(root);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2013-02-13 04:19:10 +00:00
|
|
|
|
2016-07-08 08:57:25 +00:00
|
|
|
// the press was not accepted, make sure there is no move or release event
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(110,110), 50);
|
2016-07-08 08:57:25 +00:00
|
|
|
|
|
|
|
// use qwait here because we want to make sure an event does NOT happen
|
|
|
|
// the test fails if the default state changes, while it shouldn't
|
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(root->property("hadMove").toBool(), false);
|
2013-02-13 04:19:10 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(110,110));
|
2016-07-08 08:57:25 +00:00
|
|
|
QTest::qWait(100);
|
|
|
|
QCOMPARE(root->property("hadRelease").toBool(), false);
|
2013-02-13 04:19:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 11:29:32 +00:00
|
|
|
void tst_QQuickMouseArea::nestedStopAtBounds_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("transpose");
|
|
|
|
QTest::addColumn<bool>("invert");
|
|
|
|
|
|
|
|
QTest::newRow("left") << false << false;
|
|
|
|
QTest::newRow("right") << false << true;
|
|
|
|
QTest::newRow("top") << true << false;
|
|
|
|
QTest::newRow("bottom") << true << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::nestedStopAtBounds()
|
|
|
|
{
|
|
|
|
QFETCH(bool, transpose);
|
|
|
|
QFETCH(bool, invert);
|
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("nestedStopAtBounds.qml")));
|
2013-02-15 11:29:32 +00:00
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickMouseArea *outer = window.rootObject()->findChild<QQuickMouseArea*>("outer");
|
2013-02-15 11:29:32 +00:00
|
|
|
QVERIFY(outer);
|
|
|
|
|
|
|
|
QQuickMouseArea *inner = outer->findChild<QQuickMouseArea*>("inner");
|
|
|
|
QVERIFY(inner);
|
|
|
|
inner->drag()->setAxis(transpose ? QQuickDrag::YAxis : QQuickDrag::XAxis);
|
|
|
|
inner->setX(invert ? 100 : 0);
|
|
|
|
inner->setY(invert ? 100 : 0);
|
|
|
|
|
|
|
|
const int threshold = qApp->styleHints()->startDragDistance();
|
|
|
|
|
|
|
|
QPoint position(200, 200);
|
|
|
|
int &axis = transpose ? position.ry() : position.rx();
|
|
|
|
|
|
|
|
// drag toward the aligned boundary. Outer mouse area dragged.
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2013-02-15 11:29:32 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
axis += invert ? threshold * 2 : -threshold * 2;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2013-02-15 11:29:32 +00:00
|
|
|
axis += invert ? threshold : -threshold;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2022-10-18 08:48:22 +00:00
|
|
|
|
|
|
|
// outer drag will not receive mouse event, when the focus has been stolen.
|
|
|
|
// => try to regain and time out if it fails.
|
|
|
|
while (!QTest::qWaitFor([&outer]() { return outer->drag()->active(); }))
|
|
|
|
window.raise();
|
|
|
|
|
2013-02-15 11:29:32 +00:00
|
|
|
QCOMPARE(inner->drag()->active(), false);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2013-02-15 11:29:32 +00:00
|
|
|
|
|
|
|
QVERIFY(!outer->drag()->active());
|
|
|
|
|
|
|
|
axis = 200;
|
|
|
|
outer->setX(50);
|
|
|
|
outer->setY(50);
|
|
|
|
|
|
|
|
// drag away from the aligned boundary. Inner mouse area dragged.
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2013-02-15 11:29:32 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
axis += invert ? -threshold * 2 : threshold * 2;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2013-02-15 11:29:32 +00:00
|
|
|
axis += invert ? -threshold : threshold;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2013-08-12 03:28:17 +00:00
|
|
|
QTRY_COMPARE(outer->drag()->active(), false);
|
|
|
|
QTRY_COMPARE(inner->drag()->active(), true);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2013-02-15 11:29:32 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 07:32:58 +00:00
|
|
|
void tst_QQuickMouseArea::nestedFlickableStopAtBounds()
|
|
|
|
{
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("nestedFlickableStopAtBounds.qml")));
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
2016-09-16 07:32:58 +00:00
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
QQuickFlickable *flickable = mouseArea->findChild<QQuickFlickable*>("flickable");
|
|
|
|
QVERIFY(flickable);
|
|
|
|
|
|
|
|
const int threshold = qApp->styleHints()->startDragDistance();
|
|
|
|
|
|
|
|
QPoint position(200, 280);
|
|
|
|
int &pos = position.ry();
|
|
|
|
|
|
|
|
// Drag up - should move the Flickable to end
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos -= threshold * 2;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
pos -= threshold * 2;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos -= 150;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QVERIFY(flickable->isDragging());
|
|
|
|
QVERIFY(!mouseArea->drag()->active());
|
|
|
|
QCOMPARE(flickable->isAtYEnd(), true);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(!flickable->isMoving());
|
|
|
|
|
|
|
|
pos = 280;
|
|
|
|
|
|
|
|
// Drag up again - should activate MouseArea drag
|
|
|
|
QVERIFY(!mouseArea->drag()->active());
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos -= threshold * 2;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
pos -= threshold * 2;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos -= 20;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QVERIFY(mouseArea->drag()->active());
|
|
|
|
QCOMPARE(flickable->isAtYEnd(), true);
|
|
|
|
QVERIFY(!flickable->isDragging());
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
|
|
|
|
// Drag to the top and verify that the MouseArea doesn't steal the grab when we drag back (QTBUG-56036)
|
|
|
|
pos = 50;
|
|
|
|
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos += threshold;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
pos += threshold;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos += 150;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QVERIFY(flickable->isDragging());
|
|
|
|
QVERIFY(!mouseArea->drag()->active());
|
|
|
|
QCOMPARE(flickable->isAtYBeginning(), true);
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(!flickable->isMoving());
|
|
|
|
|
|
|
|
pos = 280;
|
|
|
|
|
|
|
|
// Drag up again - should not activate MouseArea drag
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos -= threshold;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
pos -= threshold;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
pos -= 100;
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseMove(&window, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
QVERIFY(flickable->isDragging());
|
|
|
|
QVERIFY(!mouseArea->drag()->active());
|
2020-11-19 16:22:37 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, position);
|
2016-09-16 07:32:58 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 04:10:49 +00:00
|
|
|
void tst_QQuickMouseArea::containsPress_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("hoverEnabled");
|
|
|
|
|
|
|
|
QTest::newRow("hover enabled") << true;
|
|
|
|
QTest::newRow("hover disaabled") << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::containsPress()
|
|
|
|
{
|
|
|
|
QFETCH(bool, hoverEnabled);
|
|
|
|
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("containsPress.qml")));
|
2014-07-11 04:10:49 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2014-07-11 04:10:49 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
2014-07-11 04:10:49 +00:00
|
|
|
|
|
|
|
QSignalSpy containsPressSpy(mouseArea, SIGNAL(containsPressChanged()));
|
|
|
|
|
|
|
|
mouseArea->setHoverEnabled(hoverEnabled);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(22,33));
|
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), false);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(200,200));
|
|
|
|
QCOMPARE(mouseArea->hovered(), hoverEnabled);
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), false);
|
|
|
|
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200));
|
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
|
|
|
QTRY_COMPARE(mouseArea->pressed(), true);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), true);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(containsPressSpy.size(), 1);
|
2014-07-11 04:10:49 +00:00
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(22,33));
|
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
|
|
|
QCOMPARE(mouseArea->pressed(), true);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), false);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(containsPressSpy.size(), 2);
|
2014-07-11 04:10:49 +00:00
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(200,200));
|
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
|
|
|
QCOMPARE(mouseArea->pressed(), true);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), true);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(containsPressSpy.size(), 3);
|
2014-07-11 04:10:49 +00:00
|
|
|
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200));
|
|
|
|
QCOMPARE(mouseArea->hovered(), hoverEnabled);
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), false);
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(containsPressSpy.size(), 4);
|
2014-07-11 04:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 10:02:54 +00:00
|
|
|
void tst_QQuickMouseArea::ignoreBySource()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("ignoreBySource.qml")));
|
|
|
|
|
|
|
|
auto mouseDevPriv = QPointingDevicePrivate::get(QPointingDevice::primaryPointingDevice());
|
|
|
|
auto touchDevPriv = QPointingDevicePrivate::get(device);
|
2016-03-04 10:02:54 +00:00
|
|
|
|
|
|
|
QQuickItem *root = qobject_cast<QQuickItem*>(window.rootObject());
|
|
|
|
QVERIFY(root);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>("mousearea");
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
QQuickFlickable *flickable = root->findChild<QQuickFlickable*>("flickable");
|
|
|
|
QVERIFY(flickable);
|
|
|
|
|
|
|
|
// MouseArea should grab the press because it's interested in non-synthesized mouse events
|
2016-07-02 12:16:34 +00:00
|
|
|
QPoint p = QPoint(80, 80);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(mouseDevPriv->firstPointExclusiveGrabber(), mouseArea);
|
2016-03-04 10:02:54 +00:00
|
|
|
// That was a real mouse event
|
2016-07-28 16:26:54 +00:00
|
|
|
QCOMPARE(root->property("lastEventSource").toInt(), int(Qt::MouseEventNotSynthesized));
|
2016-03-04 10:02:54 +00:00
|
|
|
|
|
|
|
// Flickable content should not move
|
2016-07-02 12:16:34 +00:00
|
|
|
p -= QPoint(startDragDistance() + 1, startDragDistance() + 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
2016-03-04 10:02:54 +00:00
|
|
|
QCOMPARE(flickable->contentX(), 0.);
|
|
|
|
QCOMPARE(flickable->contentY(), 0.);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(mouseDevPriv->firstPointExclusiveGrabber(), nullptr);
|
2016-03-04 10:02:54 +00:00
|
|
|
|
|
|
|
// Now try touch events and confirm that MouseArea ignores them, while Flickable does its thing
|
2016-07-02 12:16:34 +00:00
|
|
|
p = QPoint(80, 80);
|
|
|
|
QTest::touchEvent(&window, device).press(0, p, &window);
|
2016-03-04 10:02:54 +00:00
|
|
|
QQuickTouchUtils::flush(&window);
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(touchDevPriv->firstPointExclusiveGrabber(), flickable);
|
2016-07-28 16:26:54 +00:00
|
|
|
|
2016-03-04 10:02:54 +00:00
|
|
|
// That was a fake mouse event
|
|
|
|
QCOMPARE(root->property("lastEventSource").toInt(), int(Qt::MouseEventSynthesizedByQt));
|
2016-07-02 12:16:34 +00:00
|
|
|
p -= QPoint(startDragDistance() + 1, startDragDistance() + 1);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p, &window);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p, &window);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p, &window);
|
|
|
|
|
2016-03-04 10:02:54 +00:00
|
|
|
QQuickTouchUtils::flush(&window);
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(touchDevPriv->firstPointExclusiveGrabber(), flickable);
|
2016-07-02 12:16:34 +00:00
|
|
|
QTest::touchEvent(&window, device).release(0, p, &window);
|
2016-03-04 10:02:54 +00:00
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
|
|
|
|
// Flickable content should have moved
|
|
|
|
QTRY_VERIFY(flickable->contentX() > 1);
|
|
|
|
QVERIFY(flickable->contentY() > 1);
|
|
|
|
|
|
|
|
// Now tell the MouseArea to accept only synthesized events, and repeat the tests
|
|
|
|
root->setProperty("allowedSource", Qt::MouseEventSynthesizedByQt);
|
|
|
|
flickable->setContentX(0);
|
|
|
|
flickable->setContentY(0);
|
|
|
|
|
|
|
|
// MouseArea should ignore the press because it's interested in synthesized mouse events
|
2016-07-02 12:16:34 +00:00
|
|
|
p = QPoint(80, 80);
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p);
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(mouseDevPriv->firstPointExclusiveGrabber() != mouseArea);
|
2016-03-04 10:02:54 +00:00
|
|
|
// That was a real mouse event
|
|
|
|
QVERIFY(root->property("lastEventSource").toInt() == Qt::MouseEventNotSynthesized);
|
|
|
|
|
|
|
|
// Flickable content should move
|
2016-07-02 12:16:34 +00:00
|
|
|
p -= QPoint(startDragDistance() + 1, startDragDistance() + 1);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::mouseMove(&window, p);
|
2016-03-04 10:02:54 +00:00
|
|
|
QTRY_VERIFY(flickable->contentX() > 1);
|
|
|
|
QVERIFY(flickable->contentY() > 1);
|
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(47, 47));
|
2016-03-04 10:02:54 +00:00
|
|
|
flickable->setContentX(0);
|
|
|
|
flickable->setContentY(0);
|
|
|
|
|
|
|
|
// Now try touch events and confirm that MouseArea gets them, while Flickable doesn't
|
2016-07-02 12:16:34 +00:00
|
|
|
p = QPoint(80, 80);
|
|
|
|
QTest::touchEvent(&window, device).press(0, p, &window);
|
2016-03-04 10:02:54 +00:00
|
|
|
QQuickTouchUtils::flush(&window);
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(touchDevPriv->firstPointExclusiveGrabber(), mouseArea);
|
2016-07-02 12:16:34 +00:00
|
|
|
p -= QPoint(startDragDistance() + 1, startDragDistance() + 1);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p, &window);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p, &window);
|
|
|
|
p -= QPoint(11, 11);
|
|
|
|
QTest::touchEvent(&window, device).move(0, p, &window);
|
2016-03-04 10:02:54 +00:00
|
|
|
QQuickTouchUtils::flush(&window);
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(touchDevPriv->firstPointExclusiveGrabber(), mouseArea);
|
2016-03-04 10:02:54 +00:00
|
|
|
QTest::touchEvent(&window, device).release(0, QPoint(47,47), &window);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
|
|
|
|
// Flickable content should not have moved
|
2020-11-19 16:22:37 +00:00
|
|
|
QCOMPARE(flickable->contentX(), 0);
|
|
|
|
QCOMPARE(flickable->contentY(), 0);
|
2016-03-04 10:02:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 15:29:20 +00:00
|
|
|
void tst_QQuickMouseArea::notPressedAfterStolenGrab() // QTBUG-55325
|
2016-08-24 10:40:23 +00:00
|
|
|
{
|
|
|
|
QQuickWindow window;
|
|
|
|
window.resize(200, 200);
|
|
|
|
window.show();
|
2018-02-21 08:16:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
2016-08-24 10:40:23 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *ma = new QQuickMouseArea(window.contentItem());
|
|
|
|
ma->setSize(window.size());
|
|
|
|
QObject::connect(ma,
|
|
|
|
static_cast<void (QQuickMouseArea::*)(QQuickMouseEvent*)>(&QQuickMouseArea::pressed),
|
2020-11-19 15:29:20 +00:00
|
|
|
[&]() { qCDebug(lcTests) << "stealing grab now"; window.contentItem()->grabMouse(); });
|
2016-08-24 10:40:23 +00:00
|
|
|
|
|
|
|
QTest::mouseClick(&window, Qt::LeftButton);
|
|
|
|
QVERIFY(!ma->pressed());
|
|
|
|
}
|
|
|
|
|
2016-12-07 17:57:03 +00:00
|
|
|
void tst_QQuickMouseArea::pressAndHold_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<int>("pressAndHoldInterval");
|
|
|
|
QTest::addColumn<int>("waitTime");
|
|
|
|
|
|
|
|
QTest::newRow("default") << -1 << QGuiApplication::styleHints()->mousePressAndHoldInterval();
|
|
|
|
QTest::newRow("short") << 500 << 500;
|
|
|
|
QTest::newRow("long") << 1000 << 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::pressAndHold()
|
|
|
|
{
|
|
|
|
QFETCH(int, pressAndHoldInterval);
|
|
|
|
QFETCH(int, waitTime);
|
|
|
|
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("pressAndHold.qml")));
|
2016-12-07 17:57:03 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2016-12-07 17:57:03 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
2018-02-21 09:41:54 +00:00
|
|
|
QVERIFY(mouseArea != nullptr);
|
2016-12-07 17:57:03 +00:00
|
|
|
|
|
|
|
QSignalSpy pressAndHoldSpy(mouseArea, &QQuickMouseArea::pressAndHold);
|
|
|
|
|
|
|
|
if (pressAndHoldInterval > -1)
|
|
|
|
mouseArea->setPressAndHoldInterval(pressAndHoldInterval);
|
|
|
|
else
|
|
|
|
mouseArea->resetPressAndHoldInterval();
|
|
|
|
|
|
|
|
QElapsedTimer t;
|
|
|
|
t.start();
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(50, 50));
|
|
|
|
QVERIFY(pressAndHoldSpy.wait());
|
|
|
|
// should be off by no more than 20% of waitTime
|
|
|
|
QVERIFY(qAbs(t.elapsed() - waitTime) < (waitTime * 0.2));
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(50, 50));
|
|
|
|
}
|
|
|
|
|
2017-11-30 13:12:17 +00:00
|
|
|
void tst_QQuickMouseArea::pressOneAndTapAnother_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("pressMouseFirst");
|
|
|
|
QTest::addColumn<bool>("releaseMouseFirst");
|
|
|
|
|
|
|
|
QTest::newRow("press mouse, tap touch, release mouse") << true << false; // QTBUG-64249 as written
|
|
|
|
QTest::newRow("press touch, press mouse, release touch, release mouse") << false << false;
|
|
|
|
QTest::newRow("press mouse, press touch, release mouse, release touch") << true << true;
|
2017-12-12 09:35:21 +00:00
|
|
|
// TODO fix in a separate patch after the 5.9->5.10 merge
|
|
|
|
// QTest::newRow("press touch, click mouse, release touch") << false << true;
|
2017-11-30 13:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::pressOneAndTapAnother()
|
|
|
|
{
|
|
|
|
QFETCH(bool, pressMouseFirst);
|
|
|
|
QFETCH(bool, releaseMouseFirst);
|
|
|
|
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("twoMouseAreas.qml")));
|
2017-11-30 13:12:17 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root);
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickMouseArea *bottomMA = root->findChild<QQuickMouseArea*>("bottom");
|
2017-11-30 13:12:17 +00:00
|
|
|
QVERIFY(bottomMA);
|
2020-11-19 16:22:37 +00:00
|
|
|
QQuickMouseArea *topMA = root->findChild<QQuickMouseArea*>("top");
|
2017-11-30 13:12:17 +00:00
|
|
|
QVERIFY(topMA);
|
|
|
|
|
|
|
|
QPoint upper(32, 32);
|
|
|
|
QPoint lower(32, window.height() - 32);
|
|
|
|
|
|
|
|
// press them both
|
|
|
|
if (pressMouseFirst) {
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, lower);
|
|
|
|
QTRY_COMPARE(bottomMA->pressed(), true);
|
|
|
|
|
|
|
|
QTest::touchEvent(&window, device).press(0, lower, &window);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
QTRY_COMPARE(bottomMA->pressed(), true);
|
|
|
|
} else {
|
|
|
|
QTest::touchEvent(&window, device).press(0, lower, &window);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
QTRY_COMPARE(bottomMA->pressed(), true);
|
|
|
|
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, lower);
|
|
|
|
QTRY_COMPARE(bottomMA->pressed(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// release them both and make sure neither one gets stuck
|
|
|
|
if (releaseMouseFirst) {
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, lower);
|
|
|
|
QTRY_COMPARE(bottomMA->pressed(), false);
|
|
|
|
|
|
|
|
QTest::touchEvent(&window, device).release(0, upper, &window);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
QTRY_COMPARE(topMA->pressed(), false);
|
|
|
|
} else {
|
|
|
|
QTest::touchEvent(&window, device).release(0, upper, &window);
|
|
|
|
QQuickTouchUtils::flush(&window);
|
|
|
|
|
|
|
|
QTRY_COMPARE(topMA->pressed(), false);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, lower);
|
|
|
|
QTRY_COMPARE(bottomMA->pressed(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 16:46:36 +00:00
|
|
|
void tst_QQuickMouseArea::mask()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("mask.qml")));
|
2017-09-22 16:46:36 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2017-09-22 16:46:36 +00:00
|
|
|
|
|
|
|
// click inside the mask, and verify it registers
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100));
|
2017-09-22 16:46:36 +00:00
|
|
|
|
|
|
|
QCOMPARE(window.rootObject()->property("pressed").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
|
|
|
|
|
|
|
|
// click outside the mask (but inside the MouseArea), and verify it doesn't register
|
2018-02-21 09:41:54 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(10,10));
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(10,10));
|
2017-09-22 16:46:36 +00:00
|
|
|
|
|
|
|
QCOMPARE(window.rootObject()->property("pressed").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
|
|
|
|
}
|
|
|
|
|
2018-10-03 15:09:40 +00:00
|
|
|
void tst_QQuickMouseArea::nestedEventDelivery() // QTBUG-70898
|
|
|
|
{
|
2020-10-02 08:00:23 +00:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
QSKIP("this test currently crashes on MacOS 10.14 in CI. See QTBUG-86729");
|
|
|
|
#endif
|
2018-10-03 15:09:40 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("nestedSendEvent.qml"));
|
|
|
|
QScopedPointer<QQuickWindow> window(qmlobject_cast<QQuickWindow *>(c.create()));
|
|
|
|
QVERIFY(window.data());
|
|
|
|
|
|
|
|
// Click each MouseArea and verify that it doesn't crash
|
|
|
|
QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50,50));
|
|
|
|
QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50,150));
|
|
|
|
}
|
|
|
|
|
2020-03-28 14:14:41 +00:00
|
|
|
void tst_QQuickMouseArea::settingHiddenInPressUngrabs()
|
|
|
|
{
|
|
|
|
// When an item sets itself hidden, while handling pressed, it doesn't receive the grab.
|
|
|
|
// But that in turn means it doesn't see any release events, so we need to make sure it
|
|
|
|
// receives an ungrab event.
|
|
|
|
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent c(&engine, testFileUrl("settingHiddenInPressUngrabs.qml"));
|
|
|
|
QScopedPointer<QQuickWindow> window(qmlobject_cast<QQuickWindow *>(c.create()));
|
|
|
|
QVERIFY(window.data());
|
|
|
|
window->show();
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
|
|
|
|
|
|
|
QQuickMouseArea *catArea = window->findChild<QQuickMouseArea*>("cat");
|
|
|
|
QVERIFY(catArea != nullptr);
|
|
|
|
auto pointOnCatArea = catArea->mapToScene(QPointF(5.0, 5.0)).toPoint();
|
|
|
|
QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, pointOnCatArea);
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
// The click hides the cat area
|
|
|
|
QTRY_VERIFY(!catArea->isVisible());
|
|
|
|
// The cat area is not stuck in pressed state.
|
|
|
|
QVERIFY(!catArea->pressed());
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window->findChild<QQuickMouseArea*>("mouse");
|
|
|
|
QVERIFY(mouseArea != nullptr);
|
|
|
|
auto pointOnMouseArea = mouseArea->mapToScene(QPointF(5.0, 5.0)).toPoint();
|
|
|
|
QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, pointOnMouseArea);
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
// The click disables the mouse area
|
|
|
|
QTRY_VERIFY(!mouseArea->isEnabled());
|
|
|
|
// The mouse area is not stuck in pressed state.
|
|
|
|
QVERIFY(!mouseArea->pressed());
|
|
|
|
}
|
|
|
|
|
2019-08-16 12:32:22 +00:00
|
|
|
void tst_QQuickMouseArea::negativeZStackingOrder() // QTBUG-83114
|
|
|
|
{
|
|
|
|
QQuickView window;
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("mouseAreasOverlapped.qml")));
|
2019-08-16 12:32:22 +00:00
|
|
|
QQuickItem *root = window.rootObject();
|
2020-11-19 16:22:37 +00:00
|
|
|
QVERIFY(root);
|
2019-08-16 12:32:22 +00:00
|
|
|
|
|
|
|
QQuickMouseArea *parentMouseArea = root->findChild<QQuickMouseArea*>("parentMouseArea");
|
|
|
|
QVERIFY(parentMouseArea != nullptr);
|
|
|
|
QSignalSpy clickSpyParent(parentMouseArea, &QQuickMouseArea::clicked);
|
|
|
|
QQuickMouseArea *childMouseArea = root->findChild<QQuickMouseArea*>("childMouseArea");
|
|
|
|
QVERIFY(childMouseArea != nullptr);
|
|
|
|
QSignalSpy clickSpyChild(childMouseArea, &QQuickMouseArea::clicked);
|
|
|
|
|
|
|
|
QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100));
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(clickSpyChild.size(), 1);
|
|
|
|
QCOMPARE(clickSpyParent.size(), 0);
|
2019-08-16 12:32:22 +00:00
|
|
|
auto order = root->property("clicks").toList();
|
|
|
|
QVERIFY(order.at(0) == "childMouseArea");
|
|
|
|
|
|
|
|
// Now change stacking order and try again.
|
|
|
|
childMouseArea->parentItem()->setZ(-1);
|
|
|
|
root->setProperty("clicks", QVariantList());
|
|
|
|
QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100));
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(clickSpyChild.size(), 1);
|
|
|
|
QCOMPARE(clickSpyParent.size(), 1);
|
2019-08-16 12:32:22 +00:00
|
|
|
order = root->property("clicks").toList();
|
|
|
|
QVERIFY(order.at(0) == "parentMouseArea");
|
|
|
|
}
|
|
|
|
|
MouseArea: fix containsMouse behavior during visibility changes
QQuickItem returns whether it contains QGuiApplicationPrivate's
lastCursorPosition. Since that position stores the coordinate last seen
by Qt (the window border), it will always be within the window, and
within an item that covers that part of the window's border.
However, QQuickWindow stores the lastMousePosition as well, and resets
that value when it receives a QEvent::Leave. We can use that to test
whether the window that contains the item has seen a Leave event, in
which case the item is definitely not under the mouse.
Notes on the test: That we use QPointF() as the "reset" value leave the
small possibility that the cursor might be at position 0,0 of the window
(ie inside the window), and the QQuickItem there will not be under the
mouse. We can't confirm this (through an expected failure test), as
QTest::mouseMove interprets a QPoint(0, 0) as "center of the window".
And since we can't simulate mouse moves outside a window's boundary
using QTest::mouseMove, the test needs to explicitly synthesize a
QEvent::Leave for the window.
Fixes: QTBUG-87197
Pick-to: 6.1 6.0 5.15
Change-Id: I04870d6e914092275d9d790312fc702fb99f2935
Done-with: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-02-12 16:11:47 +00:00
|
|
|
// QTBUG-87197
|
|
|
|
void tst_QQuickMouseArea::containsMouseAndVisibility()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("containsMouse.qml")));
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
|
|
|
QVERIFY(mouseArea != nullptr);
|
|
|
|
QVERIFY(!mouseArea->isVisible());
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(10, 10));
|
|
|
|
QTRY_VERIFY(!mouseArea->hovered());
|
|
|
|
|
|
|
|
mouseArea->setVisible(true);
|
|
|
|
QVERIFY(mouseArea->isVisible());
|
|
|
|
QTRY_VERIFY(mouseArea->hovered());
|
|
|
|
|
|
|
|
/* we (ab-)use QPointF() as the 'reset' value in QQuickWindow's leave-event handling,
|
|
|
|
but can't verify that this leaves an invalid interpretation of states for position
|
|
|
|
QPoint(0, 0) as QTest::mouseMove interprets a null-position as "center of the window".
|
|
|
|
|
|
|
|
So instead, verify the current (unexpectedly expected) behavior as far as testing is
|
|
|
|
concern.
|
|
|
|
*/
|
|
|
|
QTest::mouseMove(&window, QPoint(0, 0));
|
|
|
|
QTRY_VERIFY(mouseArea->hovered());
|
|
|
|
QTRY_VERIFY(mouseArea->isUnderMouse());
|
|
|
|
|
|
|
|
// move to the edge (can't move outside)
|
|
|
|
QTest::mouseMove(&window, QPoint(window.width() - 1, window.height() / 2));
|
|
|
|
// then pretend we left
|
|
|
|
QEvent event(QEvent::Leave);
|
|
|
|
QGuiApplication::sendEvent(&window, &event);
|
|
|
|
QVERIFY(!mouseArea->hovered());
|
|
|
|
|
|
|
|
// toggle mouse area visibility - the hover state should not change
|
|
|
|
mouseArea->setVisible(false);
|
|
|
|
QVERIFY(!mouseArea->isVisible());
|
|
|
|
QVERIFY(!mouseArea->hovered());
|
|
|
|
|
|
|
|
mouseArea->setVisible(true);
|
|
|
|
QVERIFY(mouseArea->isVisible());
|
|
|
|
QVERIFY(!mouseArea->hovered());
|
|
|
|
}
|
|
|
|
|
2022-04-29 13:18:08 +00:00
|
|
|
// QTBUG-35995 and QTBUG-102158
|
|
|
|
void tst_QQuickMouseArea::doubleClickToHide()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("doubleClickToHide.qml")));
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
|
|
|
|
QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, {10, 10});
|
|
|
|
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
|
|
|
|
QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 1);
|
|
|
|
QCOMPARE(mouseArea->isVisible(), false);
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(mouseArea->pressedButtons(), Qt::NoButton);
|
|
|
|
|
|
|
|
mouseArea->setVisible(true);
|
|
|
|
|
|
|
|
QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, {10, 10});
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), 2);
|
|
|
|
}
|
|
|
|
|
2022-05-24 13:01:37 +00:00
|
|
|
void tst_QQuickMouseArea::releaseFirstTouchAfterSecond() // QTBUG-103766
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("simple.qml")));
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
QSignalSpy pressSpy(mouseArea, SIGNAL(pressed(QQuickMouseEvent*)));
|
|
|
|
QSignalSpy releaseSpy(mouseArea, &QQuickMouseArea::released);
|
|
|
|
|
|
|
|
QTest::touchEvent(&window, device).press(0, {20, 20});
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(pressSpy.size(), 1);
|
2022-05-24 13:01:37 +00:00
|
|
|
QTest::touchEvent(&window, device).stationary(0).press(1, {100, 20});
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(pressSpy.size(), 1); // touchpoint 0 is the touchmouse, touchpoint 1 is ignored
|
2022-05-24 13:01:37 +00:00
|
|
|
QTest::touchEvent(&window, device).stationary(0).release(1, {100, 20});
|
2022-10-05 05:29:16 +00:00
|
|
|
QCOMPARE(releaseSpy.size(), 0); // touchpoint 0 is the touchmouse, and remains pressed
|
2022-05-24 13:01:37 +00:00
|
|
|
QTest::touchEvent(&window, device).release(0, {20, 20});
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(releaseSpy.size(), 1);
|
2022-05-24 13:01:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 21:05:32 +00:00
|
|
|
#if QT_CONFIG(tabletevent)
|
|
|
|
void tst_QQuickMouseArea::tabletStylusTap()
|
|
|
|
{
|
|
|
|
QVERIFY(qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)); // MouseArea depends on it
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("simple.qml")));
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
QSignalSpy pressSpy(mouseArea, SIGNAL(pressed(QQuickMouseEvent*)));
|
|
|
|
QSignalSpy releaseSpy(mouseArea, &QQuickMouseArea::released);
|
|
|
|
QSignalSpy clickSpy(mouseArea, &QQuickMouseArea::clicked);
|
|
|
|
const qint64 stylusId = 1234567890;
|
|
|
|
|
|
|
|
const QPoint point(100,100);
|
|
|
|
QWindowSystemInterface::handleTabletEvent(&window, point, window.mapToGlobal(point),
|
|
|
|
int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen),
|
|
|
|
Qt::LeftButton, 0.5, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier);
|
|
|
|
if (QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse)
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point); // simulate what the platform does
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(pressSpy.size(), 1);
|
2022-07-05 21:05:32 +00:00
|
|
|
QWindowSystemInterface::handleTabletEvent(&window, point, window.mapToGlobal(point),
|
|
|
|
int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen),
|
|
|
|
Qt::NoButton, 0.5, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier);
|
|
|
|
if (QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse)
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, point);
|
2022-10-05 05:29:16 +00:00
|
|
|
QTRY_COMPARE(releaseSpy.size(), 1);
|
|
|
|
QCOMPARE(clickSpy.size(), 1);
|
|
|
|
QCOMPARE(pressSpy.size(), 1);
|
2022-07-05 21:05:32 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-10-20 14:50:39 +00:00
|
|
|
void tst_QQuickMouseArea::syntheticRightClick()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QVERIFY(QQuickTest::showView(window, testFileUrl("simple.qml")));
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>();
|
|
|
|
QVERIFY(mouseArea);
|
|
|
|
mouseArea->setAcceptedButtons(Qt::RightButton);
|
|
|
|
|
|
|
|
QSignalSpy clickSpy(mouseArea, &QQuickMouseArea::clicked);
|
|
|
|
const QPointF p(20, 20);
|
|
|
|
quint64 timestamp = 10;
|
|
|
|
|
|
|
|
// The right-click is probably synthesized from a touch long-press IRL, but it doesn't matter for the DA's logic.
|
|
|
|
// We could set QT_QUICK_ALLOW_SYNTHETIC_RIGHT_CLICK=0 to opt out, but otherwise it's allowed.
|
|
|
|
QMouseEvent press(QEvent::MouseButtonPress, p, mouseArea->mapToScene(p), mouseArea->mapToGlobal(p),
|
|
|
|
Qt::RightButton, Qt::RightButton, Qt::NoModifier, Qt::MouseEventSynthesizedBySystem);
|
|
|
|
press.setTimestamp(timestamp++);
|
|
|
|
QGuiApplication::sendEvent(&window, &press);
|
|
|
|
QCOMPARE(mouseArea->pressedButtons(), Qt::RightButton);
|
|
|
|
|
|
|
|
QMouseEvent release(QEvent::MouseButtonRelease, p, mouseArea->mapToScene(p), mouseArea->mapToGlobal(p),
|
|
|
|
Qt::RightButton, Qt::RightButton, Qt::NoModifier, Qt::MouseEventSynthesizedBySystem);
|
|
|
|
release.setTimestamp(timestamp);
|
|
|
|
QGuiApplication::sendEvent(&window, &release);
|
|
|
|
QCOMPARE(mouseArea->pressedButtons(), Qt::NoButton);
|
|
|
|
QCOMPARE(clickSpy.size(), 1);
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QTEST_MAIN(tst_QQuickMouseArea)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
#include "tst_qquickmousearea.moc"
|