2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** 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
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 12:13:26 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <qtest.h>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QTouchEvent>
|
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/QQuickItem>
|
2012-07-11 07:32:16 +00:00
|
|
|
#include <QtQuick/QQuickWindow>
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/QQmlEngine>
|
|
|
|
#include <QtQml/QQmlComponent>
|
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/qquickrectangle_p.h>
|
|
|
|
#include "../../shared/util.h"
|
2012-01-04 13:50:52 +00:00
|
|
|
#include <QSignalSpy>
|
2012-07-11 07:32:16 +00:00
|
|
|
#include <private/qquickwindow_p.h>
|
2012-06-26 16:00:59 +00:00
|
|
|
#include <private/qguiapplication_p.h>
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
struct TouchEventData {
|
|
|
|
QEvent::Type type;
|
|
|
|
QWidget *widget;
|
2011-09-06 11:14:37 +00:00
|
|
|
QWindow *window;
|
2011-04-27 12:13:26 +00:00
|
|
|
Qt::TouchPointStates states;
|
|
|
|
QList<QTouchEvent::TouchPoint> touchPoints;
|
|
|
|
};
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
static QTouchEvent::TouchPoint makeTouchPoint(QQuickItem *item, const QPointF &p, const QPointF &lastPoint = QPointF())
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
QPointF last = lastPoint.isNull() ? p : lastPoint;
|
|
|
|
|
|
|
|
QTouchEvent::TouchPoint tp;
|
2011-09-06 11:14:37 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
tp.setPos(p);
|
|
|
|
tp.setLastPos(last);
|
|
|
|
tp.setScenePos(item->mapToScene(p));
|
|
|
|
tp.setLastScenePos(item->mapToScene(last));
|
2012-07-11 07:32:16 +00:00
|
|
|
tp.setScreenPos(item->window()->mapToGlobal(tp.scenePos().toPoint()));
|
|
|
|
tp.setLastScreenPos(item->window()->mapToGlobal(tp.lastScenePos().toPoint()));
|
2011-04-27 12:13:26 +00:00
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:43:00 +00:00
|
|
|
static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states = 0,
|
|
|
|
const QList<QTouchEvent::TouchPoint>& touchPoints = QList<QTouchEvent::TouchPoint>())
|
2011-09-06 11:14:37 +00:00
|
|
|
{
|
|
|
|
TouchEventData d = { type, 0, w, states, touchPoints };
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPointStates states, const QTouchEvent::TouchPoint &touchPoint)
|
|
|
|
{
|
|
|
|
QList<QTouchEvent::TouchPoint> points;
|
|
|
|
points << touchPoint;
|
|
|
|
return makeTouchData(type, w, states, points);
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
#define COMPARE_TOUCH_POINTS(tp1, tp2) \
|
|
|
|
{ \
|
|
|
|
QCOMPARE(tp1.pos(), tp2.pos()); \
|
|
|
|
QCOMPARE(tp1.lastPos(), tp2.lastPos()); \
|
|
|
|
QCOMPARE(tp1.scenePos(), tp2.scenePos()); \
|
|
|
|
QCOMPARE(tp1.lastScenePos(), tp2.lastScenePos()); \
|
|
|
|
QCOMPARE(tp1.screenPos(), tp2.screenPos()); \
|
|
|
|
QCOMPARE(tp1.lastScreenPos(), tp2.lastScreenPos()); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define COMPARE_TOUCH_DATA(d1, d2) \
|
|
|
|
{ \
|
|
|
|
QCOMPARE((int)d1.type, (int)d2.type); \
|
|
|
|
QCOMPARE(d1.widget, d2.widget); \
|
|
|
|
QCOMPARE((int)d1.states, (int)d2.states); \
|
|
|
|
QCOMPARE(d1.touchPoints.count(), d2.touchPoints.count()); \
|
|
|
|
for (int i=0; i<d1.touchPoints.count(); i++) { \
|
|
|
|
COMPARE_TOUCH_POINTS(d1.touchPoints[i], d2.touchPoints[i]); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2012-04-17 06:47:33 +00:00
|
|
|
|
|
|
|
class RootItemAccessor : public QQuickItem
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
RootItemAccessor()
|
|
|
|
: m_rootItemDestroyed(false)
|
|
|
|
, m_rootItem(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Q_INVOKABLE QQuickItem *rootItem()
|
|
|
|
{
|
|
|
|
if (!m_rootItem) {
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindowPrivate *c = QQuickWindowPrivate::get(window());
|
2012-04-17 06:47:33 +00:00
|
|
|
m_rootItem = c->rootItem;
|
|
|
|
QObject::connect(m_rootItem, SIGNAL(destroyed()), this, SLOT(rootItemDestroyed()));
|
|
|
|
}
|
|
|
|
return m_rootItem;
|
|
|
|
}
|
|
|
|
bool isRootItemDestroyed() {return m_rootItemDestroyed;}
|
|
|
|
public slots:
|
|
|
|
void rootItemDestroyed() {
|
|
|
|
m_rootItemDestroyed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_rootItemDestroyed;
|
|
|
|
QQuickItem *m_rootItem;
|
|
|
|
};
|
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
class TestTouchItem : public QQuickRectangle
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2011-10-14 08:51:42 +00:00
|
|
|
TestTouchItem(QQuickItem *parent = 0)
|
2012-06-26 16:00:59 +00:00
|
|
|
: QQuickRectangle(parent), acceptTouchEvents(true), acceptMouseEvents(true),
|
|
|
|
mousePressId(0),
|
2012-04-24 07:51:59 +00:00
|
|
|
spinLoopWhenPressed(false), touchEventCount(0)
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
border()->setWidth(1);
|
2011-10-03 00:59:16 +00:00
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
setFiltersChildMouseEvents(true);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2012-06-26 16:00:59 +00:00
|
|
|
acceptTouchEvents = acceptMouseEvents = true;
|
2011-04-27 12:13:26 +00:00
|
|
|
setEnabled(true);
|
2012-07-03 02:29:57 +00:00
|
|
|
setVisible(true);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
lastEvent = makeTouchData(QEvent::None, window(), 0, QList<QTouchEvent::TouchPoint>());//CHECK_VALID
|
2012-06-26 16:00:59 +00:00
|
|
|
|
|
|
|
lastVelocity = lastVelocityFromMouseMove = QVector2D();
|
|
|
|
lastMousePos = QPointF();
|
|
|
|
lastMouseCapabilityFlags = 0;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 15:58:47 +00:00
|
|
|
static void clearMousePressCounter()
|
|
|
|
{
|
2012-06-26 16:00:59 +00:00
|
|
|
mousePressNum = mouseMoveNum = mouseReleaseNum = 0;
|
2012-01-13 15:58:47 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:51:59 +00:00
|
|
|
void clearTouchEventCounter()
|
|
|
|
{
|
|
|
|
touchEventCount = 0;
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:00:59 +00:00
|
|
|
bool acceptTouchEvents;
|
|
|
|
bool acceptMouseEvents;
|
2011-04-27 12:13:26 +00:00
|
|
|
TouchEventData lastEvent;
|
2011-10-03 00:59:16 +00:00
|
|
|
int mousePressId;
|
2012-04-24 07:51:59 +00:00
|
|
|
bool spinLoopWhenPressed;
|
|
|
|
int touchEventCount;
|
2012-06-26 16:00:59 +00:00
|
|
|
QVector2D lastVelocity;
|
|
|
|
QVector2D lastVelocityFromMouseMove;
|
|
|
|
QPointF lastMousePos;
|
|
|
|
int lastMouseCapabilityFlags;
|
2012-04-24 07:51:59 +00:00
|
|
|
|
2012-06-26 16:00:59 +00:00
|
|
|
void touchEvent(QTouchEvent *event) {
|
|
|
|
if (!acceptTouchEvents) {
|
2011-04-27 12:13:26 +00:00
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-24 07:51:59 +00:00
|
|
|
++touchEventCount;
|
2011-12-08 10:46:47 +00:00
|
|
|
lastEvent = makeTouchData(event->type(), event->window(), event->touchPointStates(), event->touchPoints());
|
2012-06-26 16:00:59 +00:00
|
|
|
if (event->device()->capabilities().testFlag(QTouchDevice::Velocity) && !event->touchPoints().isEmpty()) {
|
|
|
|
lastVelocity = event->touchPoints().first().velocity();
|
|
|
|
} else {
|
|
|
|
lastVelocity = QVector2D();
|
|
|
|
}
|
2012-04-24 07:51:59 +00:00
|
|
|
if (spinLoopWhenPressed && event->touchPointStates().testFlag(Qt::TouchPointPressed)) {
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
2011-10-03 00:59:16 +00:00
|
|
|
|
2012-06-26 16:00:59 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (!acceptMouseEvents) {
|
|
|
|
e->ignore();
|
|
|
|
return;
|
|
|
|
}
|
2011-10-03 00:59:16 +00:00
|
|
|
mousePressId = ++mousePressNum;
|
2012-06-26 16:00:59 +00:00
|
|
|
lastMousePos = e->pos();
|
|
|
|
lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
if (!acceptMouseEvents) {
|
|
|
|
e->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mouseMoveNum;
|
|
|
|
lastVelocityFromMouseMove = QGuiApplicationPrivate::mouseEventVelocity(e);
|
|
|
|
lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
|
|
|
|
lastMousePos = e->pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
if (!acceptMouseEvents) {
|
|
|
|
e->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++mouseReleaseNum;
|
|
|
|
lastMousePos = e->pos();
|
|
|
|
lastMouseCapabilityFlags = QGuiApplicationPrivate::mouseEventCaps(e);
|
2011-10-03 00:59:16 +00:00
|
|
|
}
|
|
|
|
|
2011-08-23 03:30:38 +00:00
|
|
|
bool childMouseEventFilter(QQuickItem *, QEvent *event) {
|
2012-06-26 16:00:59 +00:00
|
|
|
// TODO Is it a bug if a QTouchEvent comes here?
|
2011-08-23 03:30:38 +00:00
|
|
|
if (event->type() == QEvent::MouseButtonPress)
|
|
|
|
mousePressId = ++mousePressNum;
|
2011-10-03 00:59:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:00:59 +00:00
|
|
|
static int mousePressNum, mouseMoveNum, mouseReleaseNum;
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
2011-10-03 00:59:16 +00:00
|
|
|
int TestTouchItem::mousePressNum = 0;
|
2012-06-26 16:00:59 +00:00
|
|
|
int TestTouchItem::mouseMoveNum = 0;
|
|
|
|
int TestTouchItem::mouseReleaseNum = 0;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2011-10-14 08:51:42 +00:00
|
|
|
class ConstantUpdateItem : public QQuickItem
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2011-10-14 08:51:42 +00:00
|
|
|
ConstantUpdateItem(QQuickItem *parent = 0) : QQuickItem(parent), iterations(0) {setFlag(ItemHasContents);}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
int iterations;
|
|
|
|
protected:
|
|
|
|
QSGNode* updatePaintNode(QSGNode *, UpdatePaintNodeData *){
|
|
|
|
iterations++;
|
|
|
|
update();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
class tst_qquickwindow : public QQmlDataTest
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
|
|
|
private slots:
|
2012-01-13 15:58:47 +00:00
|
|
|
void initTestCase()
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDataTest::initTestCase();
|
2012-06-26 16:00:59 +00:00
|
|
|
touchDevice = new QTouchDevice;
|
2012-01-13 15:58:47 +00:00
|
|
|
touchDevice->setType(QTouchDevice::TouchScreen);
|
|
|
|
QWindowSystemInterface::registerTouchDevice(touchDevice);
|
2012-06-26 16:00:59 +00:00
|
|
|
touchDeviceWithVelocity = new QTouchDevice;
|
|
|
|
touchDeviceWithVelocity->setType(QTouchDevice::TouchScreen);
|
|
|
|
touchDeviceWithVelocity->setCapabilities(QTouchDevice::Position | QTouchDevice::Velocity);
|
|
|
|
QWindowSystemInterface::registerTouchDevice(touchDeviceWithVelocity);
|
2012-01-13 15:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
void constantUpdates();
|
2012-01-13 15:58:47 +00:00
|
|
|
void mouseFiltering();
|
|
|
|
void headless();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
void touchEvent_basic();
|
|
|
|
void touchEvent_propagation();
|
|
|
|
void touchEvent_propagation_data();
|
2012-02-10 11:43:00 +00:00
|
|
|
void touchEvent_cancel();
|
2012-04-24 07:51:59 +00:00
|
|
|
void touchEvent_reentrant();
|
2012-06-26 16:00:59 +00:00
|
|
|
void touchEvent_velocity();
|
|
|
|
|
|
|
|
void mouseFromTouch_basic();
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void clearWindow();
|
2011-11-18 09:32:56 +00:00
|
|
|
|
|
|
|
void qmlCreation();
|
|
|
|
void clearColor();
|
2011-12-07 09:16:20 +00:00
|
|
|
|
|
|
|
void grab();
|
|
|
|
void multipleWindows();
|
|
|
|
|
|
|
|
void animationsWhileHidden();
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-01-20 13:38:51 +00:00
|
|
|
void focusObject();
|
|
|
|
|
2012-02-03 13:41:17 +00:00
|
|
|
void ignoreUnhandledMouseEvents();
|
|
|
|
|
2012-04-17 06:47:33 +00:00
|
|
|
void ownershipRootItem();
|
2012-01-13 15:58:47 +00:00
|
|
|
private:
|
|
|
|
QTouchDevice *touchDevice;
|
2012-06-26 16:00:59 +00:00
|
|
|
QTouchDevice *touchDeviceWithVelocity;
|
2011-04-27 12:13:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//If the item calls update inside updatePaintNode, it should schedule another update
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::constantUpdates()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow window;
|
|
|
|
window.resize(250, 250);
|
|
|
|
ConstantUpdateItem item(window.rootItem());
|
|
|
|
window.show();
|
2011-04-27 12:13:26 +00:00
|
|
|
QTRY_VERIFY(item.iterations > 60);
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::touchEvent_basic()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-01-13 15:58:47 +00:00
|
|
|
TestTouchItem::clearMousePressCounter();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *bottomItem = new TestTouchItem(window->rootItem());
|
2011-04-27 12:13:26 +00:00
|
|
|
bottomItem->setObjectName("Bottom Item");
|
|
|
|
bottomItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *middleItem = new TestTouchItem(bottomItem);
|
|
|
|
middleItem->setObjectName("Middle Item");
|
|
|
|
middleItem->setPos(QPointF(50, 50));
|
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *topItem = new TestTouchItem(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
|
|
|
topItem->setPos(QPointF(50, 50));
|
|
|
|
topItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
QPointF pos(10, 10);
|
|
|
|
|
|
|
|
// press single point
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
|
2011-09-06 11:14:37 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
|
2012-07-11 07:32:16 +00:00
|
|
|
// At one point this was failing with kwin (KDE window manager) because window->setPos(100, 100)
|
|
|
|
// would put the decorated window at that position rather than the window itself.
|
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(topItem, pos)));
|
2011-04-27 12:13:26 +00:00
|
|
|
topItem->reset();
|
|
|
|
|
|
|
|
// press multiple points
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window)
|
|
|
|
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(topItem, pos)));
|
|
|
|
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(bottomItem, pos)));
|
2011-04-27 12:13:26 +00:00
|
|
|
topItem->reset();
|
|
|
|
bottomItem->reset();
|
|
|
|
|
|
|
|
// touch point on top item moves to bottom item, but top item should still receive the event
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos)));
|
|
|
|
topItem->reset();
|
|
|
|
|
|
|
|
// touch point on bottom item moves to top item, but bottom item should still receive the event
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).move(0, topItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos), pos)));
|
|
|
|
bottomItem->reset();
|
|
|
|
|
|
|
|
// a single stationary press on an item shouldn't cause an event
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).stationary(0)
|
|
|
|
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); // received press only, not stationary
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(topItem, pos)));
|
|
|
|
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(bottomItem, pos)));
|
2011-04-27 12:13:26 +00:00
|
|
|
topItem->reset();
|
|
|
|
bottomItem->reset();
|
2012-06-26 16:00:59 +00:00
|
|
|
// cleanup: what is pressed must be released
|
|
|
|
// Otherwise you will get an assertion failure:
|
2012-07-11 07:32:16 +00:00
|
|
|
// ASSERT: "itemForTouchPointId.isEmpty()" in file items/qquickwindow.cpp
|
|
|
|
QTest::touchEvent(window, touchDevice).release(0, pos.toPoint(), window).release(1, pos.toPoint(), window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// move touch point from top item to bottom, and release
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(),window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, window, Qt::TouchPointReleased,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos)));
|
|
|
|
topItem->reset();
|
|
|
|
|
|
|
|
// release while another point is pressed
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window)
|
|
|
|
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window)
|
2011-04-27 12:13:26 +00:00
|
|
|
.stationary(1);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, window, Qt::TouchPointReleased,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos))));
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(bottomItem, pos)));
|
2011-04-27 12:13:26 +00:00
|
|
|
topItem->reset();
|
|
|
|
bottomItem->reset();
|
|
|
|
|
|
|
|
delete topItem;
|
|
|
|
delete middleItem;
|
|
|
|
delete bottomItem;
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::touchEvent_propagation()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-01-13 15:58:47 +00:00
|
|
|
TestTouchItem::clearMousePressCounter();
|
|
|
|
|
2012-06-26 16:00:59 +00:00
|
|
|
QFETCH(bool, acceptTouchEvents);
|
|
|
|
QFETCH(bool, acceptMouseEvents);
|
2011-04-27 12:13:26 +00:00
|
|
|
QFETCH(bool, enableItem);
|
2012-07-03 02:29:57 +00:00
|
|
|
QFETCH(bool, showItem);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *bottomItem = new TestTouchItem(window->rootItem());
|
2011-04-27 12:13:26 +00:00
|
|
|
bottomItem->setObjectName("Bottom Item");
|
|
|
|
bottomItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *middleItem = new TestTouchItem(bottomItem);
|
|
|
|
middleItem->setObjectName("Middle Item");
|
|
|
|
middleItem->setPos(QPointF(50, 50));
|
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *topItem = new TestTouchItem(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
|
|
|
topItem->setPos(QPointF(50, 50));
|
|
|
|
topItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
QPointF pos(10, 10);
|
|
|
|
QPoint pointInBottomItem = bottomItem->mapToScene(pos).toPoint(); // (10, 10)
|
|
|
|
QPoint pointInMiddleItem = middleItem->mapToScene(pos).toPoint(); // (60, 60) overlaps with bottomItem
|
|
|
|
QPoint pointInTopItem = topItem->mapToScene(pos).toPoint(); // (110, 110) overlaps with bottom & top items
|
|
|
|
|
|
|
|
// disable topItem
|
2012-06-26 16:00:59 +00:00
|
|
|
topItem->acceptTouchEvents = acceptTouchEvents;
|
|
|
|
topItem->acceptMouseEvents = acceptMouseEvents;
|
2011-04-27 12:13:26 +00:00
|
|
|
topItem->setEnabled(enableItem);
|
2012-07-03 02:29:57 +00:00
|
|
|
topItem->setVisible(showItem);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// single touch to top item, should be received by middle item
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(middleItem->lastEvent.touchPoints.count(), 1);
|
|
|
|
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos))));
|
|
|
|
|
|
|
|
// touch top and middle items, middle item should get both events
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
|
|
|
|
.press(1, pointInMiddleItem, window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(middleItem->lastEvent.touchPoints.count(), 2);
|
|
|
|
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
|
2011-09-06 11:14:37 +00:00
|
|
|
(QList<QTouchEvent::TouchPoint>() << makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos))
|
2011-04-27 12:13:26 +00:00
|
|
|
<< makeTouchPoint(middleItem, pos) )));
|
|
|
|
middleItem->reset();
|
|
|
|
|
|
|
|
// disable middleItem as well
|
2012-06-26 16:00:59 +00:00
|
|
|
middleItem->acceptTouchEvents = acceptTouchEvents;
|
|
|
|
middleItem->acceptMouseEvents = acceptMouseEvents;
|
2011-04-27 12:13:26 +00:00
|
|
|
middleItem->setEnabled(enableItem);
|
2012-07-03 02:29:57 +00:00
|
|
|
middleItem->setVisible(showItem);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// touch top and middle items, bottom item should get all events
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
|
|
|
|
.press(1, pointInMiddleItem, window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 2);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
|
2011-04-27 12:13:26 +00:00
|
|
|
(QList<QTouchEvent::TouchPoint>() << makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos))
|
|
|
|
<< makeTouchPoint(bottomItem, bottomItem->mapFromItem(middleItem, pos)) )));
|
|
|
|
bottomItem->reset();
|
|
|
|
|
|
|
|
// disable bottom item as well
|
2012-06-26 16:00:59 +00:00
|
|
|
bottomItem->acceptTouchEvents = acceptTouchEvents;
|
2011-04-27 12:13:26 +00:00
|
|
|
bottomItem->setEnabled(enableItem);
|
2012-07-03 02:29:57 +00:00
|
|
|
bottomItem->setVisible(showItem);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// no events should be received
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
|
|
|
|
.press(1, pointInMiddleItem, window)
|
|
|
|
.press(2, pointInBottomItem, window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2011-04-27 12:13:26 +00:00
|
|
|
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
|
|
|
|
topItem->reset();
|
|
|
|
middleItem->reset();
|
|
|
|
bottomItem->reset();
|
|
|
|
|
|
|
|
// disable middle item, touch on top item
|
2012-06-26 16:00:59 +00:00
|
|
|
middleItem->acceptTouchEvents = acceptTouchEvents;
|
2011-04-27 12:13:26 +00:00
|
|
|
middleItem->setEnabled(enableItem);
|
2012-07-03 02:29:57 +00:00
|
|
|
middleItem->setVisible(showItem);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window);
|
2011-09-06 11:14:37 +00:00
|
|
|
QTest::qWait(50);
|
2012-07-03 02:29:57 +00:00
|
|
|
if (!enableItem || !showItem) {
|
2011-04-27 12:13:26 +00:00
|
|
|
// middle item is disabled or has 0 opacity, bottom item receives the event
|
|
|
|
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos))));
|
|
|
|
} else {
|
|
|
|
// middle item ignores event, sends it to the top item (top-most child)
|
|
|
|
QCOMPARE(topItem->lastEvent.touchPoints.count(), 1);
|
|
|
|
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
|
|
|
|
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
|
2012-07-11 07:32:16 +00:00
|
|
|
COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
|
2011-04-27 12:13:26 +00:00
|
|
|
makeTouchPoint(topItem, pos)));
|
|
|
|
}
|
|
|
|
|
|
|
|
delete topItem;
|
|
|
|
delete middleItem;
|
|
|
|
delete bottomItem;
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::touchEvent_propagation_data()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-06-26 16:00:59 +00:00
|
|
|
QTest::addColumn<bool>("acceptTouchEvents");
|
|
|
|
QTest::addColumn<bool>("acceptMouseEvents");
|
2011-04-27 12:13:26 +00:00
|
|
|
QTest::addColumn<bool>("enableItem");
|
2012-07-03 02:29:57 +00:00
|
|
|
QTest::addColumn<bool>("showItem");
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-03 02:29:57 +00:00
|
|
|
QTest::newRow("disable events") << false << false << true << true;
|
|
|
|
QTest::newRow("disable item") << true << true << false << true;
|
|
|
|
QTest::newRow("hide item") << true << true << true << false;
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::touchEvent_cancel()
|
2012-02-10 11:43:00 +00:00
|
|
|
{
|
|
|
|
TestTouchItem::clearMousePressCounter();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-02-10 11:43:00 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->rootItem());
|
2012-02-10 11:43:00 +00:00
|
|
|
item->setPos(QPointF(50, 50));
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
QPointF pos(10, 10);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, item->mapToScene(pos).toPoint(),window);
|
2012-02-10 11:43:00 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
QTRY_COMPARE(item->lastEvent.touchPoints.count(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
TouchEventData d = makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(item,pos));
|
2012-02-10 11:43:00 +00:00
|
|
|
COMPARE_TOUCH_DATA(item->lastEvent, d);
|
|
|
|
item->reset();
|
|
|
|
|
|
|
|
QWindowSystemInterface::handleTouchCancelEvent(0, touchDevice);
|
|
|
|
QCoreApplication::processEvents();
|
2012-07-11 07:32:16 +00:00
|
|
|
d = makeTouchData(QEvent::TouchCancel, window);
|
2012-02-10 11:43:00 +00:00
|
|
|
COMPARE_TOUCH_DATA(item->lastEvent, d);
|
|
|
|
|
|
|
|
delete item;
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2012-02-10 11:43:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::touchEvent_reentrant()
|
2012-04-24 07:51:59 +00:00
|
|
|
{
|
|
|
|
TestTouchItem::clearMousePressCounter();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-04-24 07:51:59 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->rootItem());
|
2012-04-24 07:51:59 +00:00
|
|
|
|
|
|
|
item->spinLoopWhenPressed = true; // will call processEvents() from the touch handler
|
|
|
|
|
|
|
|
item->setPos(QPointF(50, 50));
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
QPointF pos(60, 60);
|
|
|
|
|
|
|
|
// None of these should commit from the dtor.
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::QTouchEventSequence press = QTest::touchEvent(window, touchDevice, false).press(0, pos.toPoint(), window);
|
2012-04-24 07:51:59 +00:00
|
|
|
pos += QPointF(2, 2);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::QTouchEventSequence move = QTest::touchEvent(window, touchDevice, false).move(0, pos.toPoint(), window);
|
|
|
|
QTest::QTouchEventSequence release = QTest::touchEvent(window, touchDevice, false).release(0, pos.toPoint(), window);
|
2012-04-24 07:51:59 +00:00
|
|
|
|
|
|
|
// Now commit (i.e. call QWindowSystemInterface::handleTouchEvent), but do not process the events yet.
|
|
|
|
press.commit(false);
|
|
|
|
move.commit(false);
|
|
|
|
release.commit(false);
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
QTRY_COMPARE(item->touchEventCount, 3);
|
|
|
|
|
|
|
|
delete item;
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2012-04-24 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::touchEvent_velocity()
|
2012-06-26 16:00:59 +00:00
|
|
|
{
|
|
|
|
TestTouchItem::clearMousePressCounter();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-06-26 16:00:59 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->rootItem());
|
2012-06-26 16:00:59 +00:00
|
|
|
item->setPos(QPointF(50, 50));
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
QList<QWindowSystemInterface::TouchPoint> points;
|
|
|
|
QWindowSystemInterface::TouchPoint tp;
|
|
|
|
tp.id = 1;
|
|
|
|
tp.state = Qt::TouchPointPressed;
|
2012-07-11 07:32:16 +00:00
|
|
|
QPoint pos = window->mapToGlobal(item->mapToScene(QPointF(10, 10)).toPoint());
|
2012-06-26 16:00:59 +00:00
|
|
|
tp.area = QRectF(pos, QSizeF(4, 4));
|
|
|
|
points << tp;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
points[0].state = Qt::TouchPointMoved;
|
|
|
|
points[0].area.adjust(5, 5, 5, 5);
|
|
|
|
QVector2D velocity(1.5, 2.5);
|
|
|
|
points[0].velocity = velocity;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(item->touchEventCount, 2);
|
|
|
|
QCOMPARE(item->lastEvent.touchPoints.count(), 1);
|
|
|
|
QCOMPARE(item->lastVelocity, velocity);
|
|
|
|
|
|
|
|
// Now have a transformation on the item and check if velocity and position are transformed accordingly.
|
|
|
|
item->setRotation(90); // clockwise
|
|
|
|
QMatrix4x4 transformMatrix;
|
|
|
|
transformMatrix.rotate(-90, 0, 0, 1); // counterclockwise
|
|
|
|
QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D();
|
|
|
|
points[0].area.adjust(5, 5, 5, 5);
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QCOMPARE(item->lastVelocity, transformedVelocity);
|
2012-07-11 07:32:16 +00:00
|
|
|
QPoint itemLocalPos = item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint();
|
2012-06-26 16:00:59 +00:00
|
|
|
QPoint itemLocalPosFromEvent = item->lastEvent.touchPoints[0].pos().toPoint();
|
|
|
|
QCOMPARE(itemLocalPos, itemLocalPosFromEvent);
|
|
|
|
|
|
|
|
points[0].state = Qt::TouchPointReleased;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
delete item;
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2012-06-26 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::mouseFromTouch_basic()
|
2012-06-26 16:00:59 +00:00
|
|
|
{
|
|
|
|
// Turn off accepting touch events with acceptTouchEvents. This
|
|
|
|
// should result in sending mouse events generated from the touch
|
|
|
|
// with the new event propagation system.
|
|
|
|
|
|
|
|
TestTouchItem::clearMousePressCounter();
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-06-26 16:00:59 +00:00
|
|
|
QTest::qWait(10);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->rootItem());
|
2012-06-26 16:00:59 +00:00
|
|
|
item->setPos(QPointF(50, 50));
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
item->acceptTouchEvents = false;
|
|
|
|
|
|
|
|
QList<QWindowSystemInterface::TouchPoint> points;
|
|
|
|
QWindowSystemInterface::TouchPoint tp;
|
|
|
|
tp.id = 1;
|
|
|
|
tp.state = Qt::TouchPointPressed;
|
2012-07-11 07:32:16 +00:00
|
|
|
QPoint pos = window->mapToGlobal(item->mapToScene(QPointF(10, 10)).toPoint());
|
2012-06-26 16:00:59 +00:00
|
|
|
tp.area = QRectF(pos, QSizeF(4, 4));
|
|
|
|
points << tp;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
points[0].state = Qt::TouchPointMoved;
|
|
|
|
points[0].area.adjust(5, 5, 5, 5);
|
|
|
|
QVector2D velocity(1.5, 2.5);
|
|
|
|
points[0].velocity = velocity;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
points[0].state = Qt::TouchPointReleased;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
// The item should have received a mouse press, move, and release.
|
|
|
|
QCOMPARE(item->mousePressNum, 1);
|
|
|
|
QCOMPARE(item->mouseMoveNum, 1);
|
|
|
|
QCOMPARE(item->mouseReleaseNum, 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint());
|
2012-06-26 16:00:59 +00:00
|
|
|
QCOMPARE(item->lastVelocityFromMouseMove, velocity);
|
|
|
|
QVERIFY((item->lastMouseCapabilityFlags & QTouchDevice::Velocity) != 0);
|
|
|
|
|
|
|
|
// Now the same with a transformation.
|
|
|
|
item->setRotation(90); // clockwise
|
|
|
|
QMatrix4x4 transformMatrix;
|
|
|
|
transformMatrix.rotate(-90, 0, 0, 1); // counterclockwise
|
|
|
|
QVector2D transformedVelocity = transformMatrix.mapVector(velocity).toVector2D();
|
|
|
|
points[0].state = Qt::TouchPointPressed;
|
|
|
|
points[0].velocity = velocity;
|
|
|
|
points[0].area = QRectF(pos, QSizeF(4, 4));
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
points[0].state = Qt::TouchPointMoved;
|
|
|
|
points[0].area.adjust(5, 5, 5, 5);
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(item->lastMousePos.toPoint(), item->mapFromScene(window->mapFromGlobal(points[0].area.center().toPoint())).toPoint());
|
2012-06-26 16:00:59 +00:00
|
|
|
QCOMPARE(item->lastVelocityFromMouseMove, transformedVelocity);
|
|
|
|
|
|
|
|
points[0].state = Qt::TouchPointReleased;
|
2012-07-11 07:32:16 +00:00
|
|
|
QWindowSystemInterface::handleTouchEvent(window, touchDeviceWithVelocity, points);
|
2012-06-26 16:00:59 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
delete item;
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2012-06-26 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::clearWindow()
|
2011-04-27 12:13:26 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2012-07-11 07:32:16 +00:00
|
|
|
item->setParentItem(window->rootItem());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(item->window() == window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(item->window() == 0);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::mouseFiltering()
|
2011-10-03 00:59:16 +00:00
|
|
|
{
|
2012-01-13 15:58:47 +00:00
|
|
|
TestTouchItem::clearMousePressCounter();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2011-10-03 00:59:16 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
TestTouchItem *bottomItem = new TestTouchItem(window->rootItem());
|
2011-10-03 00:59:16 +00:00
|
|
|
bottomItem->setObjectName("Bottom Item");
|
|
|
|
bottomItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *middleItem = new TestTouchItem(bottomItem);
|
|
|
|
middleItem->setObjectName("Middle Item");
|
|
|
|
middleItem->setPos(QPointF(50, 50));
|
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *topItem = new TestTouchItem(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
|
|
|
topItem->setPos(QPointF(50, 50));
|
|
|
|
topItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
QPoint pos(100, 100);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::mousePress(window, Qt::LeftButton, 0, pos);
|
2011-10-03 00:59:16 +00:00
|
|
|
|
|
|
|
// Mouse filtering propagates down the stack, so the
|
|
|
|
// correct order is
|
|
|
|
// 1. middleItem filters event
|
|
|
|
// 2. bottomItem filters event
|
|
|
|
// 3. topItem receives event
|
2012-01-13 15:58:47 +00:00
|
|
|
QTRY_COMPARE(middleItem->mousePressId, 1);
|
|
|
|
QTRY_COMPARE(bottomItem->mousePressId, 2);
|
|
|
|
QTRY_COMPARE(topItem->mousePressId, 3);
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-10-03 00:59:16 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::qmlCreation()
|
2011-11-18 09:32:56 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
2011-12-21 08:06:26 +00:00
|
|
|
component.loadUrl(testFileUrl("window.qml"));
|
2011-11-18 09:32:56 +00:00
|
|
|
QObject* created = component.create();
|
|
|
|
QVERIFY(created);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow* window = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(window);
|
|
|
|
QCOMPARE(window->color(), QColor(Qt::green));
|
2011-11-18 09:32:56 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickItem* item = window->findChild<QQuickItem*>("item");
|
2011-11-18 09:32:56 +00:00
|
|
|
QVERIFY(item);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(item->window(), window);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-11-18 09:32:56 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::clearColor()
|
2011-11-18 09:32:56 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
//::grab examines rendering to make sure it works visually
|
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
window->resize(250, 250);
|
|
|
|
window->setPos(100, 100);
|
|
|
|
window->setColor(Qt::blue);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(window->color(), QColor(Qt::blue));
|
|
|
|
delete window;
|
2011-11-18 09:32:56 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::grab()
|
2011-12-07 09:16:20 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow window;
|
|
|
|
window.setColor(Qt::red);
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window.resize(250, 250);
|
|
|
|
window.show();
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::qWaitForWindowShown(&window);
|
2012-01-30 09:34:55 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QImage content = window.grabWindow();
|
|
|
|
QCOMPARE(content.width(), window.width());
|
|
|
|
QCOMPARE(content.height(), window.height());
|
2011-12-07 09:16:20 +00:00
|
|
|
QCOMPARE((uint) content.convertToFormat(QImage::Format_RGB32).pixel(0, 0), (uint) 0xffff0000);
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::multipleWindows()
|
2011-12-07 09:16:20 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
QList<QQuickWindow *> windows;
|
2011-12-07 09:16:20 +00:00
|
|
|
for (int i=0; i<6; ++i) {
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *c = new QQuickWindow();
|
|
|
|
c->setColor(Qt::GlobalColor(Qt::red + i));
|
2011-12-07 09:16:20 +00:00
|
|
|
c->resize(300, 200);
|
|
|
|
c->setPos(100 + i * 30, 100 + i * 20);
|
|
|
|
c->show();
|
|
|
|
windows << c;
|
2012-04-16 14:14:00 +00:00
|
|
|
QVERIFY(c->isVisible());
|
2011-12-07 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// move them
|
|
|
|
for (int i=0; i<windows.size(); ++i) {
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *c = windows.at(i);
|
2011-12-07 09:16:20 +00:00
|
|
|
c->setPos(c->x() - 10, c->y() - 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// resize them
|
|
|
|
for (int i=0; i<windows.size(); ++i) {
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *c = windows.at(i);
|
2011-12-07 09:16:20 +00:00
|
|
|
c->resize(200, 150);
|
|
|
|
}
|
|
|
|
|
|
|
|
qDeleteAll(windows);
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::animationsWhileHidden()
|
2011-12-07 09:16:20 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
2011-12-21 08:06:26 +00:00
|
|
|
component.loadUrl(testFileUrl("AnimationsWhileHidden.qml"));
|
2011-12-07 09:16:20 +00:00
|
|
|
QObject* created = component.create();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow* window = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(window);
|
|
|
|
QVERIFY(window->isVisible());
|
2011-12-07 09:16:20 +00:00
|
|
|
|
|
|
|
// Now hide the window and verify that it went off screen
|
2012-07-11 07:32:16 +00:00
|
|
|
window->hide();
|
2011-12-07 09:16:20 +00:00
|
|
|
QTest::qWait(10);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(!window->isVisible());
|
2011-12-07 09:16:20 +00:00
|
|
|
|
|
|
|
// Running animaiton should cause it to become visible again shortly.
|
2012-07-11 07:32:16 +00:00
|
|
|
QTRY_VERIFY(window->isVisible());
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-12-08 12:24:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::headless()
|
2011-12-08 12:24:17 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
2011-12-21 08:06:26 +00:00
|
|
|
component.loadUrl(testFileUrl("Headless.qml"));
|
2011-12-08 12:24:17 +00:00
|
|
|
QObject* created = component.create();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow* window = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(window);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window->isVisible());
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QSignalSpy initialized(window, SIGNAL(sceneGraphInitialized()));
|
|
|
|
QSignalSpy invalidated(window, SIGNAL(sceneGraphInvalidated()));
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
// Verify that the window is alive and kicking
|
|
|
|
QVERIFY(window->openglContext() != 0);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
|
|
|
// Store the visual result
|
2012-07-11 07:32:16 +00:00
|
|
|
QImage originalContent = window->grabWindow();
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
// Hide the window and verify signal emittion and GL context deletion
|
|
|
|
window->hide();
|
|
|
|
window->releaseResources();
|
2012-02-15 10:32:02 +00:00
|
|
|
|
|
|
|
QTRY_COMPARE(invalidated.size(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window->openglContext() == 0);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
|
|
|
// Destroy the native windowing system buffers
|
2012-07-11 07:32:16 +00:00
|
|
|
window->destroy();
|
|
|
|
QVERIFY(window->handle() == 0);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
|
|
|
// Show and verify that we are back and running
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2012-03-19 07:27:38 +00:00
|
|
|
QTRY_COMPARE(initialized.size(), 1);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window->openglContext() != 0);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
|
|
|
// Verify that the visual output is the same
|
2012-07-11 07:32:16 +00:00
|
|
|
QImage newContent = window->grabWindow();
|
2011-12-08 12:24:17 +00:00
|
|
|
|
|
|
|
QCOMPARE(originalContent, newContent);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2011-12-07 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::focusObject()
|
2012-01-20 13:38:51 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
2012-01-20 13:38:51 +00:00
|
|
|
component.loadUrl(testFileUrl("focus.qml"));
|
|
|
|
QObject *created = component.create();
|
|
|
|
QVERIFY(created);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(window);
|
2012-01-20 13:38:51 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickItem *item1 = window->findChild<QQuickItem*>("item1");
|
2012-01-20 13:38:51 +00:00
|
|
|
QVERIFY(item1);
|
|
|
|
item1->setFocus(true);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(item1, window->focusObject());
|
2012-01-20 13:38:51 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickItem *item2 = window->findChild<QQuickItem*>("item2");
|
2012-01-20 13:38:51 +00:00
|
|
|
QVERIFY(item2);
|
|
|
|
item2->setFocus(true);
|
2012-07-11 07:32:16 +00:00
|
|
|
QCOMPARE(item2, window->focusObject());
|
2012-01-20 13:38:51 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2012-01-20 13:38:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::ignoreUnhandledMouseEvents()
|
2012-02-03 13:41:17 +00:00
|
|
|
{
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow* window = new QQuickWindow;
|
|
|
|
window->resize(100, 100);
|
|
|
|
window->show();
|
2012-07-19 12:13:14 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-02-03 13:41:17 +00:00
|
|
|
|
|
|
|
QQuickItem* item = new QQuickItem;
|
|
|
|
item->setSize(QSizeF(100, 100));
|
2012-07-11 07:32:16 +00:00
|
|
|
item->setParentItem(window->rootItem());
|
2012-02-03 13:41:17 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QMouseEvent me(QEvent::MouseButtonPress, QPointF(50, 50), Qt::LeftButton, Qt::LeftButton,
|
|
|
|
Qt::NoModifier);
|
|
|
|
me.setAccepted(true);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(QCoreApplication::sendEvent(window, &me));
|
2012-02-03 13:41:17 +00:00
|
|
|
QVERIFY(!me.isAccepted());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QMouseEvent me(QEvent::MouseMove, QPointF(51, 51), Qt::LeftButton, Qt::LeftButton,
|
|
|
|
Qt::NoModifier);
|
|
|
|
me.setAccepted(true);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(QCoreApplication::sendEvent(window, &me));
|
2012-02-03 13:41:17 +00:00
|
|
|
QVERIFY(!me.isAccepted());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
QMouseEvent me(QEvent::MouseButtonRelease, QPointF(51, 51), Qt::LeftButton, Qt::LeftButton,
|
|
|
|
Qt::NoModifier);
|
|
|
|
me.setAccepted(true);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(QCoreApplication::sendEvent(window, &me));
|
2012-02-03 13:41:17 +00:00
|
|
|
QVERIFY(!me.isAccepted());
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
delete window;
|
2012-02-03 13:41:17 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 06:47:33 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::ownershipRootItem()
|
2012-04-17 06:47:33 +00:00
|
|
|
{
|
|
|
|
qmlRegisterType<RootItemAccessor>("QtQuick", 2, 0, "RootItemAccessor");
|
|
|
|
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("ownershipRootItem.qml"));
|
|
|
|
QObject* created = component.create();
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow* window = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(window);
|
2012-07-19 12:13:14 +00:00
|
|
|
window->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
2012-04-17 06:47:33 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
RootItemAccessor* accessor = window->findChild<RootItemAccessor*>("accessor");
|
2012-04-17 06:47:33 +00:00
|
|
|
QVERIFY(accessor);
|
|
|
|
engine.collectGarbage();
|
|
|
|
|
|
|
|
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
QVERIFY(!accessor->isRootItemDestroyed());
|
|
|
|
}
|
2012-07-11 07:32:16 +00:00
|
|
|
QTEST_MAIN(tst_qquickwindow)
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
#include "tst_qquickwindow.moc"
|