2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
** All rights reserved.
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-07-07 12:52:03 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-07-07 12:52:03 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 12:13:26 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-07-07 12:52:03 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
2011-07-07 12:52:03 +00:00
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
#include <QtTest/QSignalSpy>
|
2011-10-14 08:51:42 +00:00
|
|
|
#include <private/qquickmousearea_p.h>
|
|
|
|
#include <private/qquickrectangle_p.h>
|
|
|
|
#include <private/qquickflickable_p.h>
|
|
|
|
#include <QtDeclarative/qquickview.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
#include <QtDeclarative/qdeclarativecontext.h>
|
|
|
|
#include <QtDeclarative/qdeclarativeengine.h>
|
2011-05-16 03:49:56 +00:00
|
|
|
#include <QtOpenGL/QGLShaderProgram>
|
2011-10-12 03:46:02 +00:00
|
|
|
#include "../shared/util.h"
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:35:51 +00:00
|
|
|
//#define OLDWAY
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
class tst_QQuickMouseArea: public QObject
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
2011-05-16 03:49:56 +00:00
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
2011-09-08 13:58:13 +00:00
|
|
|
void dragProperties();
|
|
|
|
void resetDrag();
|
|
|
|
void dragging();
|
|
|
|
void updateMouseAreaPosOnClick();
|
|
|
|
void updateMouseAreaPosOnResize();
|
|
|
|
void noOnClickedWithPressAndHold();
|
|
|
|
void onMousePressRejected();
|
|
|
|
void pressedCanceledOnWindowDeactivate();
|
|
|
|
void doubleClick();
|
|
|
|
void clickTwice();
|
|
|
|
void pressedOrdering();
|
|
|
|
void preventStealing();
|
|
|
|
void clickThrough();
|
|
|
|
void testQtQuick11Attributes();
|
|
|
|
void testQtQuick11Attributes_data();
|
|
|
|
void hoverPosition();
|
|
|
|
void hoverPropagation();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private:
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::initTestCase()
|
2011-05-16 03:49:56 +00:00
|
|
|
{
|
2011-09-06 15:33:55 +00:00
|
|
|
|
2011-05-16 03:49:56 +00:00
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::cleanupTestCase()
|
2011-05-16 03:49:56 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::dragProperties()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragproperties.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickMouseArea *mouseRegion = canvas->rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
// target
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *blackRect = canvas->rootObject()->findChild<QQuickItem*>("blackrect");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
|
|
|
QVERIFY(blackRect == drag->target());
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem*>(canvas->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
|
2011-10-14 08:51:42 +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);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::resetDrag()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
canvas->rootContext()->setContextProperty("haveTarget", QVariant(true));
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragreset.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickMouseArea *mouseRegion = canvas->rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
// target
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *blackRect = canvas->rootObject()->findChild<QQuickItem*>("blackrect");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
|
|
|
QVERIFY(blackRect == drag->target());
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem*>(canvas->rootObject());
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(rootItem != 0);
|
|
|
|
QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
|
|
|
|
QVERIFY(drag->target() != 0);
|
|
|
|
canvas->rootContext()->setContextProperty("haveTarget", QVariant(false));
|
|
|
|
QCOMPARE(targetSpy.count(),1);
|
|
|
|
QVERIFY(drag->target() == 0);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragging.qml")));
|
2011-04-27 12:13:26 +00:00
|
|
|
canvas->show();
|
2011-09-06 15:33:55 +00:00
|
|
|
canvas->requestActivateWindow();
|
2011-09-08 13:35:51 +00:00
|
|
|
QTest::qWait(20);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickMouseArea *mouseRegion = canvas->rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
|
|
|
QQuickDrag *drag = mouseRegion->drag();
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
|
|
|
QVERIFY(drag != 0);
|
|
|
|
|
|
|
|
// target
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *blackRect = canvas->rootObject()->findChild<QQuickItem*>("blackrect");
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(blackRect != 0);
|
|
|
|
QVERIFY(blackRect == drag->target());
|
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
|
|
|
|
2011-09-08 13:35:51 +00:00
|
|
|
#ifdef OLDWAY
|
2011-04-27 12:13:26 +00:00
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-09-08 13:35:51 +00:00
|
|
|
#else
|
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
#endif
|
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.
|
2011-09-08 13:35:51 +00:00
|
|
|
|
|
|
|
QTest::mouseMove(canvas, QPoint(111,111));
|
|
|
|
QTest::qWait(50);
|
|
|
|
QTest::mouseMove(canvas, QPoint(122,122));
|
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(drag->active());
|
2011-09-08 13:35:51 +00:00
|
|
|
QCOMPARE(blackRect->x(), 72.0);
|
|
|
|
QCOMPARE(blackRect->y(), 72.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:35:51 +00:00
|
|
|
#ifdef OLDWAY
|
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-09-08 13:35:51 +00:00
|
|
|
#else
|
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(122,122));
|
|
|
|
QTest::qWait(50);
|
|
|
|
#endif
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
QVERIFY(!drag->active());
|
2011-09-08 13:35:51 +00:00
|
|
|
QCOMPARE(blackRect->x(), 72.0);
|
|
|
|
QCOMPARE(blackRect->y(), 72.0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *tst_QQuickMouseArea::createView()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = new QQuickView(0);
|
2011-09-06 15:33:55 +00:00
|
|
|
canvas->setBaseSize(QSize(240,320));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::updateMouseAreaPosOnClick()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("updateMousePosOnClick.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickMouseArea *mouseRegion = canvas->rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
2011-07-29 00:38:35 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *rect = canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &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-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("updateMousePosOnResize.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickMouseArea *mouseRegion = canvas->rootObject()->findChild<QQuickMouseArea*>("mouseregion");
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(mouseRegion != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickRectangle *rect = canvas->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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QMouseEvent event(QEvent::MouseButtonPress, rect->pos().toPoint(), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QApplication::sendEvent(canvas, &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-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(mouseRegion->property("x1").toInt(), 0);
|
|
|
|
QCOMPARE(mouseRegion->property("y1").toInt(), 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
// XXX: is it on purpose that mouseX is real and mouse.x is int?
|
|
|
|
QCOMPARE(mouseRegion->property("x2").toInt(), (int) rect->x());
|
|
|
|
QCOMPARE(mouseRegion->property("y2").toInt(), (int) 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-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("clickandhold.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("held").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);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(!canvas->rootObject()->property("clicked").toBool());
|
|
|
|
QVERIFY(canvas->rootObject()->property("held").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("noclickandhold.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(!canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(canvas->rootObject()->property("clicked").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("rejectEvent.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
|
|
|
QVERIFY(canvas->rootObject()->property("enabled").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(!canvas->rootObject()->property("mr1_pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr1_released").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr2_pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr2_released").toBool());
|
|
|
|
QVERIFY(!canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(canvas->rootObject()->property("mr1_pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr1_released").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool());
|
|
|
|
QVERIFY(canvas->rootObject()->property("mr2_pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr2_released").toBool());
|
|
|
|
QVERIFY(canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(canvas->rootObject()->property("mr1_released").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("mr2_released").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::pressedCanceledOnWindowDeactivate()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pressedCanceled.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
|
|
|
QVERIFY(!canvas->rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("canceled").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("released").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);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(canvas->rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("canceled").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("released").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
|
|
|
QEvent windowDeactivateEvent(QEvent::WindowDeactivate);
|
|
|
|
QApplication::sendEvent(canvas, &windowDeactivateEvent);
|
|
|
|
QVERIFY(!canvas->rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(canvas->rootObject()->property("canceled").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("released").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
|
|
|
//press again
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
|
|
|
QVERIFY(canvas->rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("canceled").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("released").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
|
|
|
//release
|
|
|
|
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
|
|
|
QVERIFY(!canvas->rootObject()->property("pressed").toBool());
|
|
|
|
QVERIFY(!canvas->rootObject()->property("canceled").toBool());
|
|
|
|
QVERIFY(canvas->rootObject()->property("released").toBool());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::doubleClick()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("doubleclick.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
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);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("released").toInt(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 1);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("doubleClicked").toInt(), 1);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("released").toInt(), 2);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("clicktwice.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
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);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("pressed").toInt(), 1);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("released").toInt(), 1);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 1);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("pressed").toInt(), 2);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("released").toInt(), 2);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 2);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::pressedOrdering()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("pressedOrdering.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("base"));
|
|
|
|
|
|
|
|
QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
|
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &releaseEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("toggled"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QApplication::sendEvent(canvas, &pressEvent);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("pressed"));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("preventstealing.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(canvas->rootObject());
|
2011-09-08 13:58:13 +00:00
|
|
|
QVERIFY(flickable != 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickMouseArea *mouseArea = canvas->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
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::mousePress(canvas, 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
|
|
|
|
2011-09-08 14:46:54 +00:00
|
|
|
QTest::mouseMove(canvas,QPoint(69,69));
|
|
|
|
QTest::mouseMove(canvas,QPoint(58,58));
|
|
|
|
QTest::mouseMove(canvas,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
|
|
|
|
2011-09-08 14:46:54 +00:00
|
|
|
QTest::mouseRelease(canvas, 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.
|
|
|
|
canvas->rootObject()->setProperty("stealing", false);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::mousePress(canvas, 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
|
|
|
|
2011-09-08 14:46:54 +00:00
|
|
|
QTest::mouseMove(canvas,QPoint(69,69));
|
|
|
|
QTest::mouseMove(canvas,QPoint(58,58));
|
|
|
|
QTest::mouseMove(canvas,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
|
|
|
|
|
|
|
QCOMPARE(flickable->contentX(), 11.);
|
|
|
|
QCOMPARE(flickable->contentY(), 11.);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 50));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
delete canvas;
|
|
|
|
}
|
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
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("clickThrough.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(800); // to avoid generating a double click.
|
2011-08-01 06:20:26 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
|
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
2011-09-29 03:55:36 +00:00
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 2);
|
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
|
|
|
|
//With handlers defined click, doubleClick and PressAndHold should propagate only when explicitly ignored
|
|
|
|
canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("clickThrough2.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
canvas->show();
|
|
|
|
canvas->requestActivateWindow();
|
|
|
|
QVERIFY(canvas->rootObject() != 0);
|
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 0);
|
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(800); // to avoid generating a double click.
|
|
|
|
|
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 0);
|
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 0);
|
|
|
|
|
|
|
|
canvas->rootObject()->setProperty("letThrough", QVariant(true));
|
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(800); // to avoid generating a double click.
|
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
2011-09-29 03:55:36 +00:00
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::qWait(800); // to avoid generating a double click.
|
|
|
|
QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
2011-09-08 13:58:13 +00:00
|
|
|
QTest::qWait(1000);
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
|
|
|
|
|
2011-09-29 03:55:36 +00:00
|
|
|
QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
|
|
|
|
QTest::qWait(100);
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
|
2011-09-29 03:55:36 +00:00
|
|
|
QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 2);
|
2011-09-08 13:58:13 +00:00
|
|
|
QCOMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 1);
|
|
|
|
QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::testQtQuick11Attributes()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
|
|
|
QFETCH(QString, code);
|
|
|
|
QFETCH(QString, warning);
|
|
|
|
QFETCH(QString, error);
|
|
|
|
|
|
|
|
QDeclarativeEngine engine;
|
|
|
|
QObject *obj;
|
|
|
|
|
|
|
|
QDeclarativeComponent valid(&engine);
|
|
|
|
valid.setData("import QtQuick 1.1; MouseArea { " + code.toUtf8() + " }", QUrl(""));
|
|
|
|
obj = valid.create();
|
|
|
|
QVERIFY(obj);
|
|
|
|
QVERIFY(valid.errorString().isEmpty());
|
|
|
|
delete obj;
|
|
|
|
|
|
|
|
QDeclarativeComponent invalid(&engine);
|
|
|
|
invalid.setData("import QtQuick 1.0; MouseArea { " + code.toUtf8() + " }", QUrl(""));
|
|
|
|
QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
|
|
|
|
obj = invalid.create();
|
|
|
|
QCOMPARE(invalid.errorString(), error);
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::testQtQuick11Attributes_data()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("code");
|
|
|
|
QTest::addColumn<QString>("warning");
|
|
|
|
QTest::addColumn<QString>("error");
|
|
|
|
|
|
|
|
QTest::newRow("preventStealing") << "preventStealing: true"
|
|
|
|
<< "QDeclarativeComponent: Component is not ready"
|
|
|
|
<< ":1 \"MouseArea.preventStealing\" is not available in QtQuick 1.0.\n";
|
|
|
|
}
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
void tst_QQuickMouseArea::hoverPosition()
|
2011-09-08 13:58:13 +00:00
|
|
|
{
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("hoverPosition.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *root = canvas->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));
|
|
|
|
|
2011-09-08 14:46:54 +00:00
|
|
|
QTest::mouseMove(canvas,QPoint(10,32));
|
|
|
|
|
2011-09-08 13:58:13 +00:00
|
|
|
|
|
|
|
QCOMPARE(root->property("mouseX").toReal(), qreal(10));
|
|
|
|
QCOMPARE(root->property("mouseY").toReal(), qreal(32));
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
|
|
|
|
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.
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView *canvas = createView();
|
2011-10-12 03:46:02 +00:00
|
|
|
canvas->setSource(QUrl::fromLocalFile(TESTDATA("hoverPropagation.qml")));
|
2011-09-08 13:58:13 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *root = canvas->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);
|
|
|
|
QApplication::sendEvent(canvas, &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);
|
|
|
|
QApplication::sendEvent(canvas, &moveEvent2);
|
|
|
|
QCOMPARE(root->property("point1").toBool(), false);
|
|
|
|
QCOMPARE(root->property("point2").toBool(), true);
|
|
|
|
|
|
|
|
delete canvas;
|
|
|
|
}
|
2011-08-01 06:20:26 +00:00
|
|
|
|
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"
|