2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-22 06:13:59 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-04-27 12:13:26 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QtTest/QSignalSpy>
|
2013-08-26 23:15:23 +00:00
|
|
|
#include <QtQuick/private/qquickdrag_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>
|
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 "../../shared/util.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>
|
|
|
|
|
|
|
|
// Initialize view, set Url, center in available geometry, move mouse away if desired
|
|
|
|
static bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage)
|
|
|
|
{
|
|
|
|
v.setBaseSize(QSize(240,320));
|
|
|
|
v.setSource(url);
|
|
|
|
while (v.status() == QQuickView::Loading)
|
|
|
|
QTest::qWait(10);
|
|
|
|
if (v.status() != QQuickView::Ready) {
|
|
|
|
foreach (const QQmlError &e, v.errors())
|
|
|
|
errorMessage->append(e.toString().toLocal8Bit() + '\n');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QRect screenGeometry = v.screen()->availableGeometry();
|
|
|
|
const QSize size = v.size();
|
|
|
|
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
|
|
|
|
v.setFramePosition(screenGeometry.center() - offset);
|
|
|
|
#ifndef QT_NO_CURSOR // Get the cursor out of the way.
|
|
|
|
if (moveMouseOut)
|
|
|
|
QCursor::setPos(v.geometry().topRight() + QPoint(100, 100));
|
|
|
|
#else
|
|
|
|
Q_UNUSED(moveMouseOut)
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-27 12:13:26 +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
|
|
|
|
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();
|
2014-05-07 17:01:19 +00:00
|
|
|
void dragSmoothed();
|
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();
|
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();
|
|
|
|
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();
|
2012-03-05 05:07:27 +00:00
|
|
|
void disableAfterPress();
|
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();
|
2012-07-25 04:04:47 +00:00
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
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();
|
2014-07-11 04:10:49 +00:00
|
|
|
void containsPress_data();
|
|
|
|
void containsPress();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private:
|
2012-06-21 05:49:10 +00:00
|
|
|
void acceptedButton_data();
|
|
|
|
void rejectedButton_data();
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragproperties.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
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());
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(rootItem != 0);
|
|
|
|
QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
|
|
|
|
drag->setTarget(rootItem);
|
|
|
|
QCOMPARE(targetSpy.count(),1);
|
|
|
|
drag->setTarget(rootItem);
|
|
|
|
QCOMPARE(targetSpy.count(),1);
|
|
|
|
|
|
|
|
// 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);
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(axisSpy.count(),1);
|
2011-10-14 08:51:42 +00:00
|
|
|
drag->setAxis(QQuickDrag::XAxis);
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(axisSpy.count(),1);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
QCOMPARE(xminSpy.count(),1);
|
|
|
|
QCOMPARE(xmaxSpy.count(),1);
|
|
|
|
QCOMPARE(yminSpy.count(),1);
|
|
|
|
QCOMPARE(ymaxSpy.count(),1);
|
|
|
|
|
|
|
|
drag->setXmin(10);
|
|
|
|
drag->setXmax(10);
|
|
|
|
drag->setYmin(10);
|
|
|
|
drag->setYmax(10);
|
|
|
|
|
|
|
|
QCOMPARE(xminSpy.count(),1);
|
|
|
|
QCOMPARE(xmaxSpy.count(),1);
|
|
|
|
QCOMPARE(yminSpy.count(),1);
|
|
|
|
QCOMPARE(ymaxSpy.count(),1);
|
|
|
|
|
|
|
|
// filterChildren
|
|
|
|
QSignalSpy filterChildrenSpy(drag, SIGNAL(filterChildrenChanged()));
|
|
|
|
|
|
|
|
drag->setFilterChildren(true);
|
|
|
|
|
|
|
|
QVERIFY(drag->filterChildren());
|
|
|
|
QCOMPARE(filterChildrenSpy.count(), 1);
|
|
|
|
|
|
|
|
drag->setFilterChildren(true);
|
|
|
|
QCOMPARE(filterChildrenSpy.count(), 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);
|
|
|
|
QCOMPARE(thresholdSpy.count(), 1);
|
|
|
|
drag->setThreshold(99);
|
|
|
|
QCOMPARE(thresholdSpy.count(), 2);
|
|
|
|
drag->setThreshold(99);
|
|
|
|
QCOMPARE(thresholdSpy.count(), 2);
|
|
|
|
drag->resetThreshold();
|
|
|
|
QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance());
|
|
|
|
QCOMPARE(thresholdSpy.count(), 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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
window.rootContext()->setContextProperty("haveTarget", QVariant(true));
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragreset.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
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());
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(rootItem != 0);
|
|
|
|
QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
|
|
|
|
QVERIFY(drag->target() != 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
window.rootContext()->setContextProperty("haveTarget", QVariant(false));
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(targetSpy.count(),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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
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");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, button, 0, QPoint(100,100));
|
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.
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(111,111), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(116,116), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(122,122), 50);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, button, 0, QPoint(122,122));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-01-11 13:48:32 +00:00
|
|
|
QTRY_VERIFY(!drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->x(), 61.0);
|
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 17:01:19 +00:00
|
|
|
void tst_QQuickMouseArea::dragSmoothed()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
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");
|
|
|
|
QVERIFY(blackRect != 0);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2014-05-07 17:01:19 +00:00
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
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);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100,122));
|
|
|
|
|
|
|
|
// reset rect position
|
|
|
|
blackRect->setX(50.0);
|
|
|
|
blackRect->setY(50.0);
|
|
|
|
|
|
|
|
// now try with smoothed disabled
|
|
|
|
drag->setSmoothed(false);
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
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);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 122));
|
|
|
|
}
|
2013-08-22 15:20:52 +00:00
|
|
|
|
|
|
|
void tst_QQuickMouseArea::dragThreshold()
|
|
|
|
{
|
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
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");
|
|
|
|
QVERIFY(blackRect != 0);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2013-08-22 15:20:52 +00:00
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
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);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122));
|
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
|
|
|
|
// Immediate drag threshold
|
|
|
|
drag->setThreshold(0);
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
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);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 124));
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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();
|
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(acceptedButtons);
|
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2012-06-21 05:49:10 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2012-06-21 05:49:10 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, button, 0, 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);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, button, 0, 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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(Qt::LeftButton);
|
|
|
|
|
|
|
|
// target
|
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
|
|
|
QVERIFY(blackRect != 0);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2013-11-25 22:55:22 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(111,111), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(116,116), 50);
|
|
|
|
QTest::mouseMove(&window, QPoint(122,122), 50);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122));
|
|
|
|
}
|
|
|
|
|
2012-05-11 01:01:33 +00:00
|
|
|
void tst_QQuickMouseArea::setDragOnPressed()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("setDragOnPressed.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
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.
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(111,102));
|
2012-05-11 01:01:33 +00:00
|
|
|
QTest::qWait(50);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(122,122));
|
2012-05-11 01:01:33 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
|
|
|
QVERIFY(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);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122));
|
2012-05-11 01:01:33 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
|
|
|
QVERIFY(!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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("updateMousePosOnClick.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickRectangle *rect = window.rootObject()->findChild<QQuickRectangle*>("ball");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(rect != 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-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent event(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &event);
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("updateMousePosOnResize.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseRegion = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickRectangle *rect = window.rootObject()->findChild<QQuickRectangle*>("brother");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(rect != 0);
|
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
|
|
|
|
2012-10-22 14:59:25 +00:00
|
|
|
QMouseEvent event(QEvent::MouseButtonPress, rect->position().toPoint(), Qt::LeftButton, Qt::LeftButton, 0);
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("clickandhold.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
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
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("noclickandhold.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
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
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("rejectEvent.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
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());
|
|
|
|
QVERIFY(window.rootObject()->property("mr2_canceled").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(200);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
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
|
|
|
QVERIFY(window.rootObject()->property("mr1_released").toBool());
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("pressedCanceled.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
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);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2014-09-03 18:42:04 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), expectedClicks);
|
|
|
|
|
|
|
|
if (doubleClick) {
|
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
|
|
|
QVERIFY(!window.rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(!window.rootObject()->property("canceled").toBool());
|
|
|
|
QCOMPARE(window.rootObject()->property("released").toInt(), ++expectedRelease);
|
|
|
|
QCOMPARE(window.rootObject()->property("clicked").toInt(), ++expectedClicks);
|
|
|
|
|
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
|
|
|
QMouseEvent pressEvent2(QEvent::MouseButtonDblClick, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent2);
|
|
|
|
|
|
|
|
QVERIFY(window.rootObject()->property("pressed").toBool());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QWindow *secondWindow = qvariant_cast<QWindow*>(window.rootObject()->property("secondWindow"));
|
2013-03-04 11:52:11 +00:00
|
|
|
secondWindow->setProperty("visible", true);
|
2013-03-27 08:57:59 +00:00
|
|
|
QTest::qWaitForWindowExposed(secondWindow);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
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
|
|
|
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
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
|
|
|
QVERIFY(window.rootObject()->property("pressed").toBool());
|
|
|
|
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
|
|
|
QTest::qWait(200);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
//release
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &releaseEvent);
|
|
|
|
QVERIFY(!window.rootObject()->property("pressed").toBool());
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("doubleclick.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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
|
2012-06-21 05:49:10 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), button, button, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-06-21 05:49:10 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), button, button, 0);
|
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);
|
2012-06-21 05:49:10 +00:00
|
|
|
pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), button, button, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("clicktwice.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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);
|
|
|
|
|
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), button, button, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-06-21 05:49:10 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), button, button, 0);
|
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);
|
2012-06-21 05:49:10 +00:00
|
|
|
pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), button, button, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("doubleclick.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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
|
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), button, button, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
2012-06-21 05:49:10 +00:00
|
|
|
|
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), button, button, 0);
|
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);
|
2012-06-21 05:49:10 +00:00
|
|
|
pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), button, button, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("pressedOrdering.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
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
|
|
|
|
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
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("value").toString(), QLatin1String("toggled"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &pressEvent);
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("preventstealing.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window.rootObject());
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(flickable != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mousearea");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseArea != 0);
|
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
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(80, 80));
|
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
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window,QPoint(69,69));
|
|
|
|
QTest::mouseMove(&window,QPoint(58,58));
|
|
|
|
QTest::mouseMove(&window,QPoint(47,47));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// We should have received all three move events
|
|
|
|
QCOMPARE(mousePositionSpy.count(), 3);
|
|
|
|
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
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(47, 47));
|
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
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(80, 80));
|
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
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window,QPoint(69,69));
|
|
|
|
QTest::mouseMove(&window,QPoint(58,58));
|
|
|
|
QTest::mouseMove(&window,QPoint(47,47));
|
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
|
|
|
|
QCOMPARE(mousePositionSpy.count(), 4);
|
|
|
|
// Our press should be taken away
|
|
|
|
QVERIFY(!mouseArea->pressed());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// Flickable content should have moved.
|
2011-09-08 14:46:54 +00:00
|
|
|
|
2013-03-12 04:05:32 +00:00
|
|
|
QCOMPARE(flickable->contentX(), 11.);
|
|
|
|
QCOMPARE(flickable->contentY(), 11.);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50));
|
2011-09-08 13:58:13 +00:00
|
|
|
}
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::clickThrough()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
|
|
|
//With no handlers defined click, doubleClick and PressAndHold should propagate to those with handlers
|
2013-08-23 08:38:08 +00:00
|
|
|
QScopedPointer<QQuickView> window(new QQuickView);
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(*window.data(), testFileUrl("clickThrough.qml"), true, &errorMessage), errorMessage.constData());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window->rootObject() != 0);
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QTRY_COMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 1);
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2012-04-21 02:45:58 +00:00
|
|
|
// to avoid generating a double click.
|
|
|
|
int doubleClickInterval = qApp->styleHints()->mouseDoubleClickInterval() + 10;
|
|
|
|
QTest::qWait(doubleClickInterval);
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QTRY_COMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 1);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 2);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
window.reset(new QQuickView);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
//With handlers defined click, doubleClick and PressAndHold should propagate only when explicitly ignored
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY2(initView(*window.data(), testFileUrl("clickThrough2.qml"), true, &errorMessage), errorMessage.constData());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2013-08-23 08:38:08 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window->rootObject() != 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("clicks").toInt(), 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-04-21 02:45:58 +00:00
|
|
|
QTest::qWait(doubleClickInterval); // to avoid generating a double click.
|
2011-09-29 03:55:36 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("clicks").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("clicks").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("doubleClicks").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 0);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("letThrough", QVariant(true));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-04-21 02:45:58 +00:00
|
|
|
QTest::qWait(doubleClickInterval); // to avoid generating a double click.
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-04-21 02:45:58 +00:00
|
|
|
QTest::qWait(doubleClickInterval); // to avoid generating a double click.
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(window->rootObject()->property("clicks").toInt(), 1);
|
|
|
|
QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 2);
|
|
|
|
QCOMPARE(window->rootObject()->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->rootObject()->setProperty("noPropagation", QVariant(true));
|
2011-11-15 01:51:50 +00:00
|
|
|
|
2012-04-21 02:45:58 +00:00
|
|
|
QTest::qWait(doubleClickInterval); // to avoid generating a double click.
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-11-15 01:51:50 +00:00
|
|
|
|
2012-04-21 02:45:58 +00:00
|
|
|
QTest::qWait(doubleClickInterval); // to avoid generating a double click.
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-11-15 01:51:50 +00:00
|
|
|
QTest::qWait(1000);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-11-15 01:51:50 +00:00
|
|
|
QTest::qWait(100);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseDClick(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
2011-11-15 01:51:50 +00:00
|
|
|
QTest::qWait(100);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(window->rootObject()->property("clicks").toInt(), 2);
|
|
|
|
QCOMPARE(window->rootObject()->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(window->rootObject()->property("pressAndHolds").toInt(), 1);
|
2013-11-04 21:29:12 +00:00
|
|
|
|
|
|
|
window.reset(new QQuickView);
|
|
|
|
|
|
|
|
//QTBUG-34368 - Shouldn't propagate to disabled mouse areas
|
|
|
|
QVERIFY2(initView(*window.data(), testFileUrl("qtbug34368.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
|
|
|
QVERIFY(window->rootObject() != 0);
|
|
|
|
|
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
|
|
|
|
QCOMPARE(window->rootObject()->property("clicksEnabled").toInt(), 1);
|
|
|
|
QCOMPARE(window->rootObject()->property("clicksDisabled").toInt(), 1); //Not disabled yet
|
|
|
|
|
|
|
|
window->rootObject()->setProperty("disableLower", QVariant(true));
|
|
|
|
|
|
|
|
QTest::qWait(doubleClickInterval); // to avoid generating a double click.
|
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
|
|
|
|
QCOMPARE(window->rootObject()->property("clicksEnabled").toInt(), 2);
|
|
|
|
QCOMPARE(window->rootObject()->property("clicksDisabled").toInt(), 1); //disabled, shouldn't increment
|
2015-11-26 06:37:17 +00:00
|
|
|
|
|
|
|
window.reset(new QQuickView);
|
|
|
|
|
|
|
|
//QTBUG-49100
|
|
|
|
QVERIFY2(initView(*window.data(), testFileUrl("qtbug49100.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window.data()));
|
|
|
|
QVERIFY(window->rootObject() != 0);
|
|
|
|
|
|
|
|
QTest::mousePress(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(window.data(), Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
|
|
|
|
QVERIFY(window->rootObject() != 0);
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("hoverPosition.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
QQuickItem *root = window.rootObject();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(root != 0);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
//QTBUG-18175, to behave like GV did.
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("hoverPropagation.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
QQuickItem *root = window.rootObject();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(root != 0);
|
|
|
|
|
|
|
|
QCOMPARE(root->property("point1").toBool(), false);
|
|
|
|
QCOMPARE(root->property("point2").toBool(), false);
|
|
|
|
|
|
|
|
QMouseEvent moveEvent(QEvent::MouseMove, QPoint(32, 32), Qt::NoButton, Qt::NoButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &moveEvent);
|
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);
|
|
|
|
|
|
|
|
QMouseEvent moveEvent2(QEvent::MouseMove, QPoint(232, 32), Qt::NoButton, Qt::NoButton, 0);
|
2013-08-23 08:38:08 +00:00
|
|
|
QGuiApplication::sendEvent(&window, &moveEvent2);
|
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()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("hoverVisible.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
QQuickItem *root = window.rootObject();
|
2012-02-15 06:27:36 +00:00
|
|
|
QVERIFY(root != 0);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseTracker = window.rootObject()->findChild<QQuickMouseArea*>("mousetracker");
|
2012-02-15 06:27:36 +00:00
|
|
|
QVERIFY(mouseTracker != 0);
|
|
|
|
|
|
|
|
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);
|
|
|
|
QCOMPARE(enteredSpy.count(), 0);
|
|
|
|
|
|
|
|
mouseTracker->setVisible(true);
|
|
|
|
|
|
|
|
QCOMPARE(mouseTracker->hovered(), true);
|
|
|
|
QCOMPARE(enteredSpy.count(), 1);
|
|
|
|
|
2012-03-28 06:46:31 +00:00
|
|
|
QCOMPARE(QPointF(mouseTracker->mouseX(), mouseTracker->mouseY()), QPointF(11,33));
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("hoverAfterPress.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
QQuickItem *root = window.rootObject();
|
2013-04-26 14:18:54 +00:00
|
|
|
QVERIFY(root != 0);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
2013-04-26 14:18:54 +00:00
|
|
|
QVERIFY(mouseArea != 0);
|
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);
|
|
|
|
}
|
|
|
|
|
2012-03-05 05:07:27 +00:00
|
|
|
void tst_QQuickMouseArea::disableAfterPress()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("dragging.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2012-03-05 05:07:27 +00:00
|
|
|
QQuickDrag *drag = mouseArea->drag();
|
|
|
|
QVERIFY(mouseArea != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
QSignalSpy mousePositionSpy(mouseArea, SIGNAL(positionChanged(QQuickMouseEvent*)));
|
|
|
|
QSignalSpy mousePressSpy(mouseArea, SIGNAL(pressed(QQuickMouseEvent*)));
|
|
|
|
QSignalSpy mouseReleaseSpy(mouseArea, SIGNAL(released(QQuickMouseEvent*)));
|
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = window.rootObject()->findChild<QQuickItem*>("blackrect");
|
2012-03-05 05:07:27 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(blackRect, drag->target());
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(mousePressSpy.count(), 1);
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
QTRY_COMPARE(mousePositionSpy.count(), 2);
|
|
|
|
|
|
|
|
QVERIFY(drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->x(), 61.0);
|
|
|
|
QCOMPARE(blackRect->y(), 61.0);
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
mouseArea->setEnabled(false);
|
|
|
|
|
|
|
|
// move should still be acted upon
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(133,133));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(144,144));
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(mousePositionSpy.count(), 4);
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(144,144));
|
2012-03-05 05:07:27 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(mouseReleaseSpy.count(), 1);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
QCOMPARE(mousePressSpy.count(), 0);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
QCOMPARE(mousePositionSpy.count(), 0);
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(122,122));
|
2012-03-05 05:07:27 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
|
|
|
QCOMPARE(mouseReleaseSpy.count(), 0);
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:19:26 +00:00
|
|
|
void tst_QQuickMouseArea::onWheel()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("wheel.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
QQuickItem *root = window.rootObject();
|
2012-01-05 18:19:26 +00:00
|
|
|
QVERIFY(root != 0);
|
|
|
|
|
|
|
|
QWheelEvent wheelEvent(QPoint(10, 32), QPoint(10, 32), QPoint(60, 20), QPoint(0, 120),
|
|
|
|
0, Qt::Vertical,Qt::NoButton, Qt::ControlModifier);
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("transformedMouseArea.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QVERIFY(window.rootObject() != 0);
|
2012-02-26 16:27:34 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea");
|
2012-02-26 16:27:34 +00:00
|
|
|
QVERIFY(mouseArea != 0);
|
|
|
|
|
|
|
|
foreach (const QPoint &point, points) {
|
|
|
|
// 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
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, 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
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, point);
|
2013-08-12 03:28:17 +00:00
|
|
|
QTRY_COMPARE(mouseArea->property("pressed").toBool(), false);
|
2012-02-26 16:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-10 06:40:06 +00:00
|
|
|
void tst_QQuickMouseArea::pressedMultipleButtons_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::MouseButtons>("accepted");
|
|
|
|
QTest::addColumn<QList<Qt::MouseButtons> >("buttons");
|
|
|
|
QTest::addColumn<QList<bool> >("pressed");
|
|
|
|
QTest::addColumn<QList<Qt::MouseButtons> >("pressedButtons");
|
|
|
|
QTest::addColumn<int>("changeCount");
|
|
|
|
|
|
|
|
QList<Qt::MouseButtons> buttons;
|
|
|
|
QList<bool> pressed;
|
|
|
|
QList<Qt::MouseButtons> pressedButtons;
|
|
|
|
buttons << Qt::LeftButton
|
|
|
|
<< (Qt::LeftButton | Qt::RightButton)
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< 0;
|
|
|
|
pressed << true
|
|
|
|
<< true
|
|
|
|
<< true
|
|
|
|
<< false;
|
|
|
|
pressedButtons << Qt::LeftButton
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< 0;
|
|
|
|
QTest::newRow("Accept Left - Press left, Press Right, Release Right")
|
|
|
|
<< Qt::MouseButtons(Qt::LeftButton) << buttons << pressed << pressedButtons << 2;
|
|
|
|
|
|
|
|
buttons.clear();
|
|
|
|
pressed.clear();
|
|
|
|
pressedButtons.clear();
|
|
|
|
buttons << Qt::LeftButton
|
|
|
|
<< (Qt::LeftButton | Qt::RightButton)
|
|
|
|
<< Qt::RightButton
|
|
|
|
<< 0;
|
|
|
|
pressed << true
|
|
|
|
<< true
|
|
|
|
<< false
|
|
|
|
<< false;
|
|
|
|
pressedButtons << Qt::LeftButton
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< 0
|
|
|
|
<< 0;
|
|
|
|
QTest::newRow("Accept Left - Press left, Press Right, Release Left")
|
|
|
|
<< Qt::MouseButtons(Qt::LeftButton) << buttons << pressed << pressedButtons << 2;
|
|
|
|
|
|
|
|
buttons.clear();
|
|
|
|
pressed.clear();
|
|
|
|
pressedButtons.clear();
|
|
|
|
buttons << Qt::LeftButton
|
|
|
|
<< (Qt::LeftButton | Qt::RightButton)
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< 0;
|
|
|
|
pressed << true
|
|
|
|
<< true
|
|
|
|
<< true
|
|
|
|
<< false;
|
|
|
|
pressedButtons << Qt::LeftButton
|
|
|
|
<< (Qt::LeftButton | Qt::RightButton)
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< 0;
|
|
|
|
QTest::newRow("Accept Left|Right - Press left, Press Right, Release Right")
|
|
|
|
<< (Qt::LeftButton | Qt::RightButton) << buttons << pressed << pressedButtons << 4;
|
|
|
|
|
|
|
|
buttons.clear();
|
|
|
|
pressed.clear();
|
|
|
|
pressedButtons.clear();
|
|
|
|
buttons << Qt::RightButton
|
|
|
|
<< (Qt::LeftButton | Qt::RightButton)
|
|
|
|
<< Qt::LeftButton
|
|
|
|
<< 0;
|
|
|
|
pressed << true
|
|
|
|
<< true
|
|
|
|
<< false
|
|
|
|
<< false;
|
|
|
|
pressedButtons << Qt::RightButton
|
|
|
|
<< Qt::RightButton
|
|
|
|
<< 0
|
|
|
|
<< 0;
|
|
|
|
QTest::newRow("Accept Right - Press Right, Press Left, Release Right")
|
|
|
|
<< Qt::MouseButtons(Qt::RightButton) << buttons << pressed << pressedButtons << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QQuickMouseArea::pressedMultipleButtons()
|
|
|
|
{
|
|
|
|
QFETCH(Qt::MouseButtons, accepted);
|
|
|
|
QFETCH(QList<Qt::MouseButtons>, buttons);
|
|
|
|
QFETCH(QList<bool>, pressed);
|
|
|
|
QFETCH(QList<Qt::MouseButtons>, pressedButtons);
|
|
|
|
QFETCH(int, changeCount);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView view;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(view, testFileUrl("simple.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
view.show();
|
|
|
|
QTest::qWaitForWindowExposed(&view);
|
|
|
|
QVERIFY(view.rootObject() != 0);
|
2012-07-10 06:40:06 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseArea = view.rootObject()->findChild<QQuickMouseArea *>("mousearea");
|
2012-07-10 06:40:06 +00:00
|
|
|
QVERIFY(mouseArea != 0);
|
|
|
|
|
|
|
|
QSignalSpy pressedSpy(mouseArea, SIGNAL(pressedChanged()));
|
|
|
|
QSignalSpy pressedButtonsSpy(mouseArea, SIGNAL(pressedButtonsChanged()));
|
|
|
|
mouseArea->setAcceptedMouseButtons(accepted);
|
|
|
|
|
|
|
|
QPoint point(10,10);
|
|
|
|
|
|
|
|
for (int i = 0; i < buttons.count(); ++i) {
|
|
|
|
int btns = buttons.at(i);
|
|
|
|
|
|
|
|
// The windowsysteminterface takes care of sending releases
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&view, (Qt::MouseButton)btns, 0, point);
|
2012-07-10 06:40:06 +00:00
|
|
|
|
|
|
|
QCOMPARE(mouseArea->pressed(), pressed.at(i));
|
|
|
|
QCOMPARE(mouseArea->pressedButtons(), pressedButtons.at(i));
|
|
|
|
}
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&view, Qt::NoButton, 0, point);
|
2012-07-10 06:40:06 +00:00
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
|
|
|
|
QCOMPARE(pressedSpy.count(), 2);
|
|
|
|
QCOMPARE(pressedButtonsSpy.count(), changeCount);
|
|
|
|
}
|
|
|
|
|
2012-07-05 14:10:34 +00:00
|
|
|
void tst_QQuickMouseArea::changeAxis()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView view;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(view, testFileUrl("changeAxis.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
view.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
|
|
|
QTRY_VERIFY(view.rootObject() != 0);
|
2012-07-05 14:10:34 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickMouseArea *mouseRegion = view.rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2012-07-05 14:10:34 +00:00
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
mouseRegion->setAcceptedButtons(Qt::LeftButton);
|
|
|
|
|
|
|
|
// target
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickItem *blackRect = view.rootObject()->findChild<QQuickItem*>("blackrect");
|
2012-07-05 14:10:34 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
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
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&view, Qt::LeftButton, 0, QPoint(100, 100));
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 50.0);
|
|
|
|
QCOMPARE(blackRect->y(), 50.0);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&view, QPoint(111, 111));
|
2012-07-05 14:10:34 +00:00
|
|
|
QTest::qWait(50);
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&view, QPoint(122, 122));
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(drag->active());
|
2013-03-14 02:36:20 +00:00
|
|
|
QCOMPARE(blackRect->x(), 61.0);
|
|
|
|
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. */
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&view, QPoint(144, 144));
|
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);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&view, QPoint(155, 155));
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(blackRect->y(), 94.0);
|
|
|
|
QCOMPARE(blackRect->x(), 83.0);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&view, Qt::LeftButton, 0, QPoint(155, 155));
|
2012-07-05 14:10:34 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(!drag->active());
|
|
|
|
QCOMPARE(blackRect->x(), 83.0);
|
|
|
|
QCOMPARE(blackRect->y(), 94.0);
|
|
|
|
}
|
|
|
|
|
2012-07-25 04:04:47 +00:00
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
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);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
mouseArea->setCursorShape(Qt::IBeamCursor);
|
|
|
|
QCOMPARE(spy.count(), 1);
|
|
|
|
|
|
|
|
mouseArea->setCursorShape(Qt::WaitCursor);
|
|
|
|
QCOMPARE(mouseArea->cursorShape(), Qt::WaitCursor);
|
|
|
|
QCOMPARE(mouseArea->cursor().shape(), Qt::WaitCursor);
|
|
|
|
QCOMPARE(spy.count(), 2);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 04:19:10 +00:00
|
|
|
void tst_QQuickMouseArea::moveAndReleaseWithoutPress()
|
|
|
|
{
|
2013-08-23 08:38:08 +00:00
|
|
|
QQuickView window;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("moveAndReleaseWithoutPress.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
2013-02-13 04:19:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QObject *root = window.rootObject();
|
2013-02-13 04:19:10 +00:00
|
|
|
QVERIFY(root);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100,100));
|
2013-02-13 04:19:10 +00:00
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseMove(&window, QPoint(110,110), 50);
|
2013-02-13 04:19:10 +00:00
|
|
|
QTRY_COMPARE(root->property("hadMove").toBool(), false);
|
|
|
|
|
2013-08-23 08:38:08 +00:00
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(110,110));
|
2013-02-13 04:19:10 +00:00
|
|
|
QTRY_COMPARE(root->property("hadRelease").toBool(), false);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
QQuickView view;
|
2013-08-23 08:38:08 +00:00
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(view, testFileUrl("nestedStopAtBounds.qml"), true, &errorMessage), errorMessage.constData());
|
2013-02-15 11:29:32 +00:00
|
|
|
view.show();
|
|
|
|
view.requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
|
|
|
QVERIFY(view.rootObject());
|
|
|
|
|
|
|
|
QQuickMouseArea *outer = view.rootObject()->findChild<QQuickMouseArea*>("outer");
|
|
|
|
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.
|
|
|
|
QTest::mousePress(&view, Qt::LeftButton, 0, position);
|
|
|
|
QTest::qWait(10);
|
|
|
|
axis += invert ? threshold * 2 : -threshold * 2;
|
|
|
|
QTest::mouseMove(&view, position);
|
|
|
|
axis += invert ? threshold : -threshold;
|
|
|
|
QTest::mouseMove(&view, position);
|
|
|
|
QCOMPARE(outer->drag()->active(), true);
|
|
|
|
QCOMPARE(inner->drag()->active(), false);
|
|
|
|
QTest::mouseRelease(&view, Qt::LeftButton, 0, position);
|
|
|
|
|
|
|
|
QVERIFY(!outer->drag()->active());
|
|
|
|
|
|
|
|
axis = 200;
|
|
|
|
outer->setX(50);
|
|
|
|
outer->setY(50);
|
|
|
|
|
|
|
|
// drag away from the aligned boundary. Inner mouse area dragged.
|
|
|
|
QTest::mousePress(&view, Qt::LeftButton, 0, position);
|
|
|
|
QTest::qWait(10);
|
|
|
|
axis += invert ? -threshold * 2 : threshold * 2;
|
|
|
|
QTest::mouseMove(&view, position);
|
|
|
|
axis += invert ? -threshold : threshold;
|
|
|
|
QTest::mouseMove(&view, position);
|
2013-08-12 03:28:17 +00:00
|
|
|
QTRY_COMPARE(outer->drag()->active(), false);
|
|
|
|
QTRY_COMPARE(inner->drag()->active(), true);
|
2013-02-15 11:29:32 +00:00
|
|
|
QTest::mouseRelease(&view, Qt::LeftButton, 0, position);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
QByteArray errorMessage;
|
|
|
|
QVERIFY2(initView(window, testFileUrl("containsPress.qml"), true, &errorMessage), errorMessage.constData());
|
|
|
|
window.show();
|
|
|
|
window.requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
QQuickItem *root = window.rootObject();
|
|
|
|
QVERIFY(root != 0);
|
|
|
|
|
|
|
|
QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea*>("mouseArea");
|
|
|
|
QVERIFY(mouseArea != 0);
|
|
|
|
|
|
|
|
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);
|
|
|
|
QCOMPARE(containsPressSpy.count(), 1);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(22,33));
|
|
|
|
QCOMPARE(mouseArea->hovered(), false);
|
|
|
|
QCOMPARE(mouseArea->pressed(), true);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), false);
|
|
|
|
QCOMPARE(containsPressSpy.count(), 2);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, QPoint(200,200));
|
|
|
|
QCOMPARE(mouseArea->hovered(), true);
|
|
|
|
QCOMPARE(mouseArea->pressed(), true);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), true);
|
|
|
|
QCOMPARE(containsPressSpy.count(), 3);
|
|
|
|
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200));
|
|
|
|
QCOMPARE(mouseArea->hovered(), hoverEnabled);
|
|
|
|
QCOMPARE(mouseArea->pressed(), false);
|
|
|
|
QCOMPARE(mouseArea->containsPress(), false);
|
|
|
|
QCOMPARE(containsPressSpy.count(), 4);
|
|
|
|
}
|
|
|
|
|
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"
|