2011-04-27 12:13:26 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 12:13:26 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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>
|
2014-08-07 11:57:50 +00:00
|
|
|
#include <QtQuick/QQuickView>
|
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>
|
2013-09-17 13:05:04 +00:00
|
|
|
#include <QtQuick/private/qquickloader_p.h>
|
Say hello to QtQuick module
This change moves the QtQuick 2 types and C++ API (including
SceneGraph) to a new module (AKA library), QtQuick.
99% of this change is moving files from src/declarative to
src/quick, and from tests/auto/declarative to
tests/auto/qtquick2.
The loading of QtQuick 2 ("import QtQuick 2.0") is now delegated to
a plugin, src/imports/qtquick2, just like it's done for QtQuick 1.
All tools, examples, and tests that use QtQuick C++ API have gotten
"QT += quick" or "QT += quick-private" added to their .pro file.
A few additional internal QtDeclarative classes had to be exported
(via Q_DECLARATIVE_PRIVATE_EXPORT) since they're needed by the
QtQuick 2 implementation.
The old header locations (e.g. QtDeclarative/qquickitem.h) will
still be supported for some time, but will produce compile-time
warnings. (To avoid the QtQuick implementation using the
compatibility headers (since QtDeclarative's includepath comes
first), a few include statements were modified, e.g. from
"#include <qsgnode.h>" to "#include <QtQuick/qsgnode.h>".)
There's a change in qtbase that automatically adds QtQuick to the
module list if QtDeclarative is used. Together with the compatibility
headers, this should help reduce the migration pain for existing
projects.
In theory, simply getting an existing QtDeclarative-based project
to compile and link shouldn't require any changes for now -- but
porting to the new scheme is of course recommended, and will
eventually become mandatory.
Task-number: QTBUG-22889
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Change-Id: Ia52be9373172ba2f37e7623231ecb060316c96a7
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
2011-11-23 14:14:07 +00:00
|
|
|
#include "../../shared/util.h"
|
2013-04-18 07:36:28 +00:00
|
|
|
#include "../shared/visualtestutil.h"
|
2014-04-03 11:16:42 +00:00
|
|
|
#include "../shared/viewtestutil.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>
|
2014-07-04 21:50:50 +00:00
|
|
|
#include <QRunnable>
|
2016-04-11 12:49:12 +00:00
|
|
|
#include <QOpenGLFunctions>
|
2016-05-07 13:33:47 +00:00
|
|
|
#include <QSGRendererInterface>
|
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)
|
|
|
|
{
|
|
|
|
}
|
2012-08-07 01:26:37 +00:00
|
|
|
Q_INVOKABLE QQuickItem *contentItem()
|
2012-04-17 06:47:33 +00:00
|
|
|
{
|
|
|
|
if (!m_rootItem) {
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindowPrivate *c = QQuickWindowPrivate::get(window());
|
2012-08-07 01:26:37 +00:00
|
|
|
m_rootItem = c->contentItem;
|
2012-04-17 06:47:33 +00:00
|
|
|
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;
|
2016-07-31 21:31:56 +00:00
|
|
|
touchEventCount = 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
|
|
|
|
2013-11-12 13:47:32 +00:00
|
|
|
class EventFilter : public QObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool eventFilter(QObject *watched, QEvent *event) {
|
|
|
|
Q_UNUSED(watched);
|
|
|
|
events.append(event->type());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> events;
|
|
|
|
};
|
|
|
|
|
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:
|
2015-10-15 13:21:17 +00:00
|
|
|
tst_qquickwindow()
|
2016-07-13 12:42:47 +00:00
|
|
|
: touchDevice(QTest::createTouchDevice())
|
|
|
|
, touchDeviceWithVelocity(QTest::createTouchDevice())
|
2015-10-15 13:21:17 +00:00
|
|
|
{
|
|
|
|
QQuickWindow::setDefaultAlphaBuffer(true);
|
2016-07-13 12:42:47 +00:00
|
|
|
touchDeviceWithVelocity->setCapabilities(QTouchDevice::Position | QTouchDevice::Velocity);
|
2015-10-15 13:21:17 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
private slots:
|
2015-06-03 12:27:27 +00:00
|
|
|
void cleanup();
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2014-02-10 14:51:16 +00:00
|
|
|
void openglContextCreatedSignal();
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2014-02-10 14:51:16 +00:00
|
|
|
void aboutToStopSignal();
|
2012-01-13 15:58:47 +00:00
|
|
|
|
2011-04-27 12:13:26 +00:00
|
|
|
void constantUpdates();
|
2013-02-15 14:35:04 +00:00
|
|
|
void constantUpdatesOnWindow_data();
|
|
|
|
void constantUpdatesOnWindow();
|
2012-01-13 15:58:47 +00:00
|
|
|
void mouseFiltering();
|
|
|
|
void headless();
|
2013-02-15 14:35:04 +00:00
|
|
|
void noUpdateWhenNothingChanges();
|
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();
|
|
|
|
|
2016-07-12 14:16:28 +00:00
|
|
|
void mergeTouchPointLists_data();
|
|
|
|
void mergeTouchPointLists();
|
|
|
|
|
2012-06-26 16:00:59 +00:00
|
|
|
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();
|
2013-11-27 16:57:25 +00:00
|
|
|
void defaultState();
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2013-04-18 15:02:24 +00:00
|
|
|
void grab_data();
|
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();
|
2014-04-30 18:33:07 +00:00
|
|
|
void focusReason();
|
2012-01-20 13:38:51 +00:00
|
|
|
|
2012-02-03 13:41:17 +00:00
|
|
|
void ignoreUnhandledMouseEvents();
|
|
|
|
|
2012-04-17 06:47:33 +00:00
|
|
|
void ownershipRootItem();
|
2012-07-25 04:04:47 +00:00
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
void hideThenDelete_data();
|
|
|
|
void hideThenDelete();
|
|
|
|
|
|
|
|
void showHideAnimate();
|
|
|
|
|
2013-02-20 18:39:11 +00:00
|
|
|
void testExpose();
|
|
|
|
|
2013-04-18 07:36:28 +00:00
|
|
|
void requestActivate();
|
|
|
|
|
2014-01-18 15:45:33 +00:00
|
|
|
void testWindowVisibilityOrder();
|
|
|
|
|
2013-05-06 12:40:28 +00:00
|
|
|
void blockClosing();
|
2014-11-07 11:54:16 +00:00
|
|
|
void blockCloseMethod();
|
2013-05-06 12:40:28 +00:00
|
|
|
|
2013-08-01 22:51:03 +00:00
|
|
|
void crashWhenHoverItemDeleted();
|
|
|
|
|
2013-09-17 13:05:04 +00:00
|
|
|
void unloadSubWindow();
|
2016-04-14 15:49:11 +00:00
|
|
|
void changeVisibilityInCompleted();
|
2013-09-17 13:05:04 +00:00
|
|
|
|
2013-11-12 13:47:32 +00:00
|
|
|
void qobjectEventFilter_touch();
|
|
|
|
void qobjectEventFilter_key();
|
|
|
|
void qobjectEventFilter_mouse();
|
|
|
|
|
2012-07-25 04:04:47 +00:00
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
void cursor();
|
|
|
|
#endif
|
|
|
|
|
2014-02-19 11:20:20 +00:00
|
|
|
void animatingSignal();
|
|
|
|
|
2014-02-21 14:04:21 +00:00
|
|
|
void contentItemSize();
|
|
|
|
|
2014-03-19 14:43:49 +00:00
|
|
|
void defaultSurfaceFormat();
|
|
|
|
|
2014-08-07 11:57:50 +00:00
|
|
|
void attachedProperty();
|
|
|
|
|
2014-07-04 21:50:50 +00:00
|
|
|
void testRenderJob();
|
|
|
|
|
2015-01-14 08:41:23 +00:00
|
|
|
void testHoverChildMouseEventFilter();
|
2016-07-13 12:55:50 +00:00
|
|
|
|
|
|
|
void pointerEventTypeAndPointCount();
|
|
|
|
|
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
|
|
|
};
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2014-02-10 14:51:16 +00:00
|
|
|
Q_DECLARE_METATYPE(QOpenGLContext *);
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2015-06-03 12:27:27 +00:00
|
|
|
void tst_qquickwindow::cleanup()
|
|
|
|
{
|
|
|
|
QVERIFY(QGuiApplication::topLevelWindows().isEmpty());
|
|
|
|
}
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2014-02-10 14:51:16 +00:00
|
|
|
void tst_qquickwindow::openglContextCreatedSignal()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<QOpenGLContext *>();
|
|
|
|
|
|
|
|
QQuickWindow window;
|
2014-03-02 10:32:29 +00:00
|
|
|
QSignalSpy spy(&window, SIGNAL(openglContextCreated(QOpenGLContext*)));
|
2014-02-10 14:51:16 +00:00
|
|
|
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2014-02-10 14:51:16 +00:00
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
|
2016-06-01 07:58:27 +00:00
|
|
|
if (window.rendererInterface()->graphicsApi() != QSGRendererInterface::OpenGL)
|
2016-05-07 13:33:47 +00:00
|
|
|
QSKIP("Skipping OpenGL context test due to not running with OpenGL");
|
|
|
|
|
2014-02-10 14:51:16 +00:00
|
|
|
QVERIFY(spy.size() > 0);
|
|
|
|
|
|
|
|
QVariant ctx = spy.at(0).at(0);
|
2015-08-24 12:11:03 +00:00
|
|
|
QCOMPARE(qvariant_cast<QOpenGLContext *>(ctx), window.openglContext());
|
2014-02-10 14:51:16 +00:00
|
|
|
}
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2014-02-10 14:51:16 +00:00
|
|
|
void tst_qquickwindow::aboutToStopSignal()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2014-02-10 14:51:16 +00:00
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
|
|
|
|
QSignalSpy spy(&window, SIGNAL(sceneGraphAboutToStop()));
|
|
|
|
|
|
|
|
window.hide();
|
|
|
|
|
2014-03-17 12:45:59 +00:00
|
|
|
QTRY_VERIFY(spy.count() > 0);
|
2014-02-10 14:51:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//If the item calls update inside updatePaintNode, it should schedule another sync pass
|
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);
|
2012-08-07 01:26:37 +00:00
|
|
|
ConstantUpdateItem item(window.contentItem());
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
window.show();
|
2013-10-10 07:41:43 +00:00
|
|
|
|
2014-02-10 14:51:16 +00:00
|
|
|
QSignalSpy beforeSpy(&window, SIGNAL(beforeSynchronizing()));
|
|
|
|
QSignalSpy afterSpy(&window, SIGNAL(afterSynchronizing()));
|
2013-10-10 07:41:43 +00:00
|
|
|
|
|
|
|
QTRY_VERIFY(item.iterations > 10);
|
2014-02-10 14:51:16 +00:00
|
|
|
QTRY_VERIFY(beforeSpy.count() > 10);
|
|
|
|
QTRY_VERIFY(afterSpy.count() > 10);
|
2011-04-27 12:13:26 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 14:35:04 +00:00
|
|
|
void tst_qquickwindow::constantUpdatesOnWindow_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("blockedGui");
|
|
|
|
QTest::addColumn<QByteArray>("signal");
|
|
|
|
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-02-15 14:35:04 +00:00
|
|
|
window.setGeometry(100, 100, 300, 200);
|
|
|
|
window.show();
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
2016-05-07 13:33:47 +00:00
|
|
|
const bool threaded = QQuickWindowPrivate::get(&window)->context->thread() != QGuiApplication::instance()->thread();
|
2013-02-15 14:35:04 +00:00
|
|
|
if (threaded) {
|
|
|
|
QTest::newRow("blocked, beforeRender") << true << QByteArray(SIGNAL(beforeRendering()));
|
|
|
|
QTest::newRow("blocked, afterRender") << true << QByteArray(SIGNAL(afterRendering()));
|
|
|
|
QTest::newRow("blocked, swapped") << true << QByteArray(SIGNAL(frameSwapped()));
|
|
|
|
}
|
|
|
|
QTest::newRow("unblocked, beforeRender") << false << QByteArray(SIGNAL(beforeRendering()));
|
|
|
|
QTest::newRow("unblocked, afterRender") << false << QByteArray(SIGNAL(afterRendering()));
|
|
|
|
QTest::newRow("unblocked, swapped") << false << QByteArray(SIGNAL(frameSwapped()));
|
|
|
|
}
|
|
|
|
|
2013-10-10 07:41:43 +00:00
|
|
|
class FrameCounter : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public slots:
|
|
|
|
void incr() { QMutexLocker locker(&m_mutex); ++m_counter; }
|
|
|
|
public:
|
|
|
|
FrameCounter() : m_counter(0) {}
|
|
|
|
int count() { QMutexLocker locker(&m_mutex); int x = m_counter; return x; }
|
|
|
|
private:
|
|
|
|
int m_counter;
|
|
|
|
QMutex m_mutex;
|
|
|
|
};
|
|
|
|
|
2013-02-15 14:35:04 +00:00
|
|
|
void tst_qquickwindow::constantUpdatesOnWindow()
|
|
|
|
{
|
|
|
|
QFETCH(bool, blockedGui);
|
|
|
|
QFETCH(QByteArray, signal);
|
|
|
|
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-02-15 14:35:04 +00:00
|
|
|
window.setGeometry(100, 100, 300, 200);
|
|
|
|
|
2013-10-10 07:41:43 +00:00
|
|
|
bool ok = connect(&window, signal.constData(), &window, SLOT(update()), Qt::DirectConnection);
|
|
|
|
Q_ASSERT(ok);
|
2013-02-15 14:35:04 +00:00
|
|
|
window.show();
|
2013-10-10 07:41:43 +00:00
|
|
|
QTest::qWaitForWindowExposed(&window);
|
2013-02-15 14:35:04 +00:00
|
|
|
|
2013-10-10 07:41:43 +00:00
|
|
|
FrameCounter counter;
|
|
|
|
connect(&window, SIGNAL(frameSwapped()), &counter, SLOT(incr()), Qt::DirectConnection);
|
|
|
|
|
|
|
|
int frameCount = 10;
|
|
|
|
QElapsedTimer timer;
|
|
|
|
timer.start();
|
|
|
|
if (blockedGui) {
|
|
|
|
while (counter.count() < frameCount)
|
|
|
|
QTest::qSleep(100);
|
|
|
|
QVERIFY(counter.count() >= frameCount);
|
|
|
|
} else {
|
2013-02-15 14:35:04 +00:00
|
|
|
window.update();
|
2013-10-10 07:41:43 +00:00
|
|
|
QTRY_VERIFY(counter.count() > frameCount);
|
2013-02-15 14:35:04 +00:00
|
|
|
}
|
|
|
|
window.hide();
|
|
|
|
}
|
|
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-08-17 08:00:06 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *bottomItem = new TestTouchItem(window->contentItem());
|
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");
|
2012-10-22 14:59:25 +00:00
|
|
|
middleItem->setPosition(QPointF(50, 50));
|
2011-04-27 12:13:26 +00:00
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *topItem = new TestTouchItem(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
2012-10-22 14:59:25 +00:00
|
|
|
topItem->setPosition(QPointF(50, 50));
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
2016-07-31 21:20:27 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
|
|
|
QTRY_COMPARE(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-10-22 15:09:06 +00:00
|
|
|
// At one point this was failing with kwin (KDE window manager) because window->setPosition(100, 100)
|
2012-07-11 07:32:16 +00:00
|
|
|
// 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();
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, topItem->mapToScene(pos).toPoint(), window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// press multiple points
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window)
|
2012-07-11 07:32:16 +00:00
|
|
|
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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();
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, topItem->mapToScene(pos).toPoint(), window).release(1, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// 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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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();
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// 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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).move(0, topItem->mapToScene(pos).toPoint(), window);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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();
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// 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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).stationary(0)
|
|
|
|
.press(1, bottomItem->mapToScene(pos).toPoint(), window);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(),window);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
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
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window));
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2012-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *bottomItem = new TestTouchItem(window->contentItem());
|
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");
|
2012-10-22 14:59:25 +00:00
|
|
|
middleItem->setPosition(QPointF(50, 50));
|
2011-04-27 12:13:26 +00:00
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *topItem = new TestTouchItem(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
2012-10-22 14:59:25 +00:00
|
|
|
topItem->setPosition(QPointF(50, 50));
|
2011-04-27 12:13:26 +00:00
|
|
|
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))));
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
// 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) )));
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window)
|
|
|
|
.release(1, pointInMiddleItem, window);
|
2011-04-27 12:13:26 +00:00
|
|
|
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);
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window)
|
|
|
|
.release(1, pointInMiddleItem, window);
|
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());
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window)
|
|
|
|
.release(1, pointInMiddleItem, window)
|
|
|
|
.release(2, pointInBottomItem, window);
|
2011-04-27 12:13:26 +00:00
|
|
|
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)));
|
|
|
|
}
|
2016-07-26 21:30:21 +00:00
|
|
|
QTest::touchEvent(window, touchDevice).release(0, pointInTopItem, window);
|
2011-04-27 12:13:26 +00:00
|
|
|
|
|
|
|
delete topItem;
|
|
|
|
delete middleItem;
|
|
|
|
delete bottomItem;
|
|
|
|
}
|
|
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window));
|
2012-02-10 11:43:00 +00:00
|
|
|
|
2012-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->contentItem());
|
2012-10-22 14:59:25 +00:00
|
|
|
item->setPosition(QPointF(50, 50));
|
2012-02-10 11:43:00 +00:00
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
|
2015-05-13 15:28:44 +00:00
|
|
|
QPointF pos(50, 50);
|
|
|
|
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);
|
2015-05-13 15:28:44 +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
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window));
|
2012-04-24 07:51:59 +00:00
|
|
|
|
2012-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->contentItem());
|
2012-04-24 07:51:59 +00:00
|
|
|
|
|
|
|
item->spinLoopWhenPressed = true; // will call processEvents() from the touch handler
|
|
|
|
|
2012-10-22 14:59:25 +00:00
|
|
|
item->setPosition(QPointF(50, 50));
|
2012-04-24 07:51:59 +00:00
|
|
|
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
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
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-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->contentItem());
|
2012-10-22 14:59:25 +00:00
|
|
|
item->setPosition(QPointF(50, 50));
|
2012-06-26 16:00:59 +00:00
|
|
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
2016-07-31 21:16:46 +00:00
|
|
|
QCOMPARE(item->touchEventCount, 1);
|
|
|
|
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
2012-06-26 16:00:59 +00:00
|
|
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
2012-06-26 16:00:59 +00:00
|
|
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
2012-06-26 16:00:59 +00:00
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
2016-07-12 14:16:28 +00:00
|
|
|
void tst_qquickwindow::mergeTouchPointLists_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QVector<QQuickItem*>>("list1");
|
|
|
|
QTest::addColumn<QVector<QQuickItem*>>("list2");
|
|
|
|
QTest::addColumn<QVector<QQuickItem*>>("expected");
|
|
|
|
QTest::addColumn<bool>("showItem");
|
|
|
|
|
|
|
|
// FIXME: do not leak all these items
|
|
|
|
auto item1 = new QQuickItem();
|
|
|
|
auto item2 = new QQuickItem();
|
|
|
|
auto item3 = new QQuickItem();
|
|
|
|
auto item4 = new QQuickItem();
|
|
|
|
auto item5 = new QQuickItem();
|
|
|
|
|
|
|
|
QTest::newRow("empty") << QVector<QQuickItem*>() << QVector<QQuickItem*>() << QVector<QQuickItem*>();
|
|
|
|
QTest::newRow("single list left")
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3)
|
|
|
|
<< QVector<QQuickItem*>()
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3);
|
|
|
|
QTest::newRow("single list right")
|
|
|
|
<< QVector<QQuickItem*>()
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3);
|
|
|
|
QTest::newRow("two lists identical")
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3);
|
|
|
|
QTest::newRow("two lists 1")
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item5)
|
|
|
|
<< (QVector<QQuickItem*>() << item3 << item4 << item5)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
|
|
|
|
QTest::newRow("two lists 2")
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item5)
|
|
|
|
<< (QVector<QQuickItem*>() << item3 << item4 << item5)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
|
|
|
|
QTest::newRow("two lists 3")
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item4 << item5)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
|
2016-08-01 13:55:02 +00:00
|
|
|
QTest::newRow("two lists 4")
|
2016-07-12 14:16:28 +00:00
|
|
|
<< (QVector<QQuickItem*>() << item1 << item3 << item4)
|
|
|
|
<< (QVector<QQuickItem*>() << item2 << item3 << item5)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3 << item4 << item5);
|
2016-08-01 13:55:02 +00:00
|
|
|
QTest::newRow("two lists 5")
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item4)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item3 << item4)
|
|
|
|
<< (QVector<QQuickItem*>() << item1 << item2 << item3 << item4);
|
2016-07-12 14:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_qquickwindow::mergeTouchPointLists()
|
|
|
|
{
|
|
|
|
QFETCH(QVector<QQuickItem*>, list1);
|
|
|
|
QFETCH(QVector<QQuickItem*>, list2);
|
|
|
|
QFETCH(QVector<QQuickItem*>, expected);
|
|
|
|
|
|
|
|
QQuickWindow win;
|
|
|
|
auto windowPrivate = QQuickWindowPrivate::get(&win);
|
|
|
|
auto targetList = windowPrivate->mergePointerTargets(list1, list2);
|
|
|
|
QCOMPARE(targetList, expected);
|
|
|
|
}
|
|
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
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-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *item = new TestTouchItem(window->contentItem());
|
2012-10-22 14:59:25 +00:00
|
|
|
item->setPosition(QPointF(50, 50));
|
2012-06-26 16:00:59 +00:00
|
|
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
2012-06-26 16:00:59 +00:00
|
|
|
|
|
|
|
// 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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
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);
|
2014-04-03 11:16:42 +00:00
|
|
|
QGuiApplication::processEvents();
|
|
|
|
QQuickTouchUtils::flush(window);
|
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();
|
2014-04-03 11:16:42 +00:00
|
|
|
QQuickTouchUtils::flush(window);
|
2012-06-26 16:00:59 +00:00
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
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;
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2012-08-07 01:26:37 +00:00
|
|
|
item->setParentItem(window->contentItem());
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(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
|
|
|
|
2015-07-24 13:32:22 +00:00
|
|
|
QVERIFY(!item->window());
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
window->show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window));
|
2011-10-03 00:59:16 +00:00
|
|
|
|
2012-08-07 01:26:37 +00:00
|
|
|
TestTouchItem *bottomItem = new TestTouchItem(window->contentItem());
|
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");
|
2012-10-22 14:59:25 +00:00
|
|
|
middleItem->setPosition(QPointF(50, 50));
|
2011-10-03 00:59:16 +00:00
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
TestTouchItem *topItem = new TestTouchItem(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
2012-10-22 14:59:25 +00:00
|
|
|
topItem->setPosition(QPointF(50, 50));
|
2011-10-03 00:59:16 +00:00
|
|
|
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);
|
2013-11-12 13:47:32 +00:00
|
|
|
|
|
|
|
// clean up mouse press state for the next tests
|
|
|
|
QTest::mouseRelease(window, Qt::LeftButton, 0, pos);
|
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"));
|
2013-08-14 05:23:39 +00:00
|
|
|
QObject *created = component.create();
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QObject> cleanup(created);
|
2011-11-18 09:32:56 +00:00
|
|
|
QVERIFY(created);
|
|
|
|
|
2013-08-14 05:23:39 +00:00
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
|
|
|
QCOMPARE(window->color(), QColor(Qt::green));
|
2011-11-18 09:32:56 +00:00
|
|
|
|
2013-08-14 05:23:39 +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-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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->resize(250, 250);
|
2012-10-22 15:09:06 +00:00
|
|
|
window->setPosition(100, 100);
|
2012-07-11 07:32:16 +00:00
|
|
|
window->setColor(Qt::blue);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
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));
|
2011-11-18 09:32:56 +00:00
|
|
|
}
|
2011-04-27 12:13:26 +00:00
|
|
|
|
2013-11-27 16:57:25 +00:00
|
|
|
void tst_qquickwindow::defaultState()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.setData("import QtQuick 2.0; import QtQuick.Window 2.1; Window { }", QUrl());
|
|
|
|
QObject *created = component.create();
|
|
|
|
QScopedPointer<QObject> cleanup(created);
|
|
|
|
QVERIFY(created);
|
|
|
|
|
|
|
|
QQuickWindow *qmlWindow = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(qmlWindow);
|
2015-06-03 12:27:27 +00:00
|
|
|
qmlWindow->setTitle(QTest::currentTestFunction());
|
2013-11-27 16:57:25 +00:00
|
|
|
|
|
|
|
QQuickWindow cppWindow;
|
|
|
|
cppWindow.show();
|
|
|
|
QTest::qWaitForWindowExposed(&cppWindow);
|
|
|
|
|
|
|
|
QCOMPARE(qmlWindow->windowState(), cppWindow.windowState());
|
|
|
|
}
|
|
|
|
|
2013-04-18 15:02:24 +00:00
|
|
|
void tst_qquickwindow::grab_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("visible");
|
2015-10-15 13:21:17 +00:00
|
|
|
QTest::addColumn<bool>("alpha");
|
|
|
|
QTest::newRow("visible,opaque") << true << false;
|
|
|
|
QTest::newRow("invisible,opaque") << false << false;
|
|
|
|
QTest::newRow("visible,transparent") << true << true;
|
|
|
|
QTest::newRow("invisible,transparent") << false << true;
|
2013-04-18 15:02:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::grab()
|
2011-12-07 09:16:20 +00:00
|
|
|
{
|
2013-04-18 15:02:24 +00:00
|
|
|
QFETCH(bool, visible);
|
2015-10-15 13:21:17 +00:00
|
|
|
QFETCH(bool, alpha);
|
2013-04-18 15:02:24 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(' ') + QLatin1String(QTest::currentDataTag()));
|
2015-10-15 13:21:17 +00:00
|
|
|
if (alpha) {
|
|
|
|
window.setColor(QColor(0, 0, 0, 0));
|
|
|
|
} else {
|
|
|
|
window.setColor(Qt::red);
|
|
|
|
}
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
window.resize(250, 250);
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2013-04-18 15:02:24 +00:00
|
|
|
if (visible) {
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
} else {
|
|
|
|
window.create();
|
|
|
|
}
|
2012-01-30 09:34:55 +00:00
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QImage content = window.grabWindow();
|
2015-10-15 13:21:17 +00:00
|
|
|
QCOMPARE(content.width(), int(window.width() * window.devicePixelRatio()));
|
|
|
|
QCOMPARE(content.height(), int(window.height() * window.devicePixelRatio()));
|
|
|
|
|
|
|
|
if (alpha) {
|
|
|
|
QCOMPARE((uint) content.convertToFormat(QImage::Format_ARGB32_Premultiplied).pixel(0, 0), (uint) 0x00000000);
|
|
|
|
} else {
|
|
|
|
QCOMPARE((uint) content.convertToFormat(QImage::Format_RGB32).pixel(0, 0), (uint) 0xffff0000);
|
|
|
|
}
|
2011-12-07 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup[6];
|
|
|
|
|
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();
|
2015-06-03 12:27:27 +00:00
|
|
|
c->setTitle(QLatin1String(QTest::currentTestFunction()) + QString::number(i));
|
2012-07-11 07:32:16 +00:00
|
|
|
c->setColor(Qt::GlobalColor(Qt::red + i));
|
2011-12-07 09:16:20 +00:00
|
|
|
c->resize(300, 200);
|
2012-10-22 15:09:06 +00:00
|
|
|
c->setPosition(100 + i * 30, 100 + i * 20);
|
2011-12-07 09:16:20 +00:00
|
|
|
c->show();
|
|
|
|
windows << c;
|
2012-08-17 08:00:06 +00:00
|
|
|
cleanup[i].reset(c);
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(c));
|
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);
|
2012-10-22 15:09:06 +00:00
|
|
|
c->setPosition(100 + i * 30, 100 + i * 20 + 100);
|
2011-12-07 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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"));
|
2013-08-14 05:23:39 +00:00
|
|
|
QObject *created = component.create();
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QObject> cleanup(created);
|
2011-12-07 09:16:20 +00:00
|
|
|
|
2013-08-14 05:23:39 +00:00
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-03-17 14:54:44 +00:00
|
|
|
// When running on native Nvidia graphics cards on linux, the
|
|
|
|
// distance field glyph pixels have a measurable, but not visible
|
|
|
|
// pixel error. Use a custom compare function to avoid
|
|
|
|
//
|
|
|
|
// This was GT-216 with the ubuntu "nvidia-319" driver package.
|
|
|
|
// llvmpipe does not show the same issue.
|
|
|
|
//
|
|
|
|
bool compareImages(const QImage &ia, const QImage &ib)
|
|
|
|
{
|
|
|
|
if (ia.size() != ib.size())
|
|
|
|
qDebug() << "images are of different size" << ia.size() << ib.size();
|
|
|
|
Q_ASSERT(ia.size() == ib.size());
|
|
|
|
Q_ASSERT(ia.format() == ib.format());
|
|
|
|
|
|
|
|
int w = ia.width();
|
|
|
|
int h = ia.height();
|
|
|
|
const int tolerance = 5;
|
|
|
|
for (int y=0; y<h; ++y) {
|
|
|
|
const uint *as= (const uint *) ia.constScanLine(y);
|
|
|
|
const uint *bs= (const uint *) ib.constScanLine(y);
|
|
|
|
for (int x=0; x<w; ++x) {
|
|
|
|
uint a = as[x];
|
|
|
|
uint b = bs[x];
|
|
|
|
|
|
|
|
// No tolerance for error in the alpha.
|
|
|
|
if ((a & 0xff000000) != (b & 0xff000000))
|
|
|
|
return false;
|
|
|
|
if (qAbs(qRed(a) - qRed(b)) > tolerance)
|
|
|
|
return false;
|
|
|
|
if (qAbs(qRed(a) - qRed(b)) > tolerance)
|
|
|
|
return false;
|
|
|
|
if (qAbs(qRed(a) - qRed(b)) > tolerance)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
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"));
|
2013-08-14 05:23:39 +00:00
|
|
|
QObject *created = component.create();
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QObject> cleanup(created);
|
2011-12-08 12:24:17 +00:00
|
|
|
|
2013-08-14 05:23:39 +00:00
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
|
2012-12-05 14:27:47 +00:00
|
|
|
window->setPersistentOpenGLContext(false);
|
|
|
|
window->setPersistentSceneGraph(false);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-08-17 08:00:06 +00:00
|
|
|
window->show();
|
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());
|
2016-05-07 13:33:47 +00:00
|
|
|
const bool threaded = QQuickWindowPrivate::get(window)->context->thread() != QThread::currentThread();
|
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
|
2016-05-07 13:33:47 +00:00
|
|
|
QVERIFY(window->isSceneGraphInitialized());
|
|
|
|
|
2016-06-01 07:58:27 +00:00
|
|
|
const bool isGL = window->rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL;
|
2016-05-07 13:33:47 +00:00
|
|
|
|
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
|
|
|
|
2014-09-19 07:52:25 +00:00
|
|
|
if (threaded) {
|
2016-05-07 13:33:47 +00:00
|
|
|
QTRY_VERIFY(invalidated.size() >= 1);
|
|
|
|
if (isGL)
|
|
|
|
QVERIFY(!window->isSceneGraphInitialized());
|
2014-09-19 07:52:25 +00:00
|
|
|
}
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2014-12-01 09:45:00 +00:00
|
|
|
if (QGuiApplication::platformName() == QLatin1String("windows")
|
|
|
|
&& QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
|
|
|
|
QSKIP("Crashes on Windows/ANGLE, QTBUG-42967");
|
|
|
|
}
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2011-12-08 12:24:17 +00:00
|
|
|
// Destroy the native windowing system buffers
|
2012-07-11 07:32:16 +00:00
|
|
|
window->destroy();
|
2015-07-24 13:32:22 +00:00
|
|
|
QVERIFY(!window->handle());
|
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
|
|
|
|
2014-09-19 07:52:25 +00:00
|
|
|
if (threaded)
|
|
|
|
QTRY_COMPARE(initialized.size(), 1);
|
2016-05-07 13:33:47 +00:00
|
|
|
|
|
|
|
QVERIFY(window->isSceneGraphInitialized());
|
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();
|
2014-03-17 14:54:44 +00:00
|
|
|
QVERIFY(compareImages(newContent, originalContent));
|
2011-12-07 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 14:35:04 +00:00
|
|
|
void tst_qquickwindow::noUpdateWhenNothingChanges()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-02-15 14:35:04 +00:00
|
|
|
window.setGeometry(100, 100, 300, 200);
|
|
|
|
|
|
|
|
QQuickRectangle rect(window.contentItem());
|
|
|
|
|
2013-07-24 22:17:11 +00:00
|
|
|
window.showNormal();
|
2013-10-17 12:53:33 +00:00
|
|
|
QTest::qWaitForWindowExposed(&window);
|
|
|
|
// Many platforms are broken in the sense that that they follow up
|
|
|
|
// the initial expose with a second expose or more. Let these go
|
|
|
|
// through before we let the test continue.
|
|
|
|
QTest::qWait(100);
|
2016-05-07 13:33:47 +00:00
|
|
|
if (QQuickWindowPrivate::get(&window)->context->thread() == QGuiApplication::instance()->thread()) {
|
2013-02-15 14:35:04 +00:00
|
|
|
QSKIP("Only threaded renderloop implements this feature");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSignalSpy spy(&window, SIGNAL(frameSwapped()));
|
|
|
|
rect.update();
|
2013-10-17 12:53:33 +00:00
|
|
|
// Wait a while and verify that no more frameSwapped come our way.
|
|
|
|
QTest::qWait(100);
|
2013-02-15 14:35:04 +00:00
|
|
|
|
|
|
|
QCOMPARE(spy.size(), 0);
|
|
|
|
}
|
|
|
|
|
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();
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QObject> cleanup(created);
|
|
|
|
|
2012-01-20 13:38:51 +00:00
|
|
|
QVERIFY(created);
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
|
|
|
|
QVERIFY(window);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-01-20 13:38:51 +00:00
|
|
|
|
2013-12-05 17:35:44 +00:00
|
|
|
QSignalSpy focusObjectSpy(window, SIGNAL(focusObjectChanged(QObject*)));
|
|
|
|
|
2013-01-11 11:35:01 +00:00
|
|
|
window->show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
|
|
|
window->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(window));
|
|
|
|
|
2013-12-05 17:35:44 +00:00
|
|
|
QCOMPARE(window->contentItem(), window->focusObject());
|
|
|
|
QCOMPARE(focusObjectSpy.count(), 1);
|
|
|
|
|
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());
|
2013-12-05 17:35:44 +00:00
|
|
|
QCOMPARE(focusObjectSpy.count(), 2);
|
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());
|
2013-12-05 17:35:44 +00:00
|
|
|
QCOMPARE(focusObjectSpy.count(), 3);
|
|
|
|
|
|
|
|
// set focus for item in non-focused focus scope and
|
|
|
|
// ensure focusObject does not change and signal is not emitted
|
|
|
|
QQuickItem *item3 = window->findChild<QQuickItem*>("item3");
|
|
|
|
QVERIFY(item3);
|
|
|
|
item3->setFocus(true);
|
|
|
|
QCOMPARE(item2, window->focusObject());
|
|
|
|
QCOMPARE(focusObjectSpy.count(), 3);
|
2012-01-20 13:38:51 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 18:33:07 +00:00
|
|
|
void tst_qquickwindow::focusReason()
|
|
|
|
{
|
|
|
|
QQuickWindow *window = new QQuickWindow;
|
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
|
|
|
window->resize(200, 200);
|
|
|
|
window->show();
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2014-04-30 18:33:07 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(window));
|
|
|
|
|
|
|
|
QQuickItem *firstItem = new QQuickItem;
|
|
|
|
firstItem->setSize(QSizeF(100, 100));
|
|
|
|
firstItem->setParentItem(window->contentItem());
|
|
|
|
|
|
|
|
QQuickItem *secondItem = new QQuickItem;
|
|
|
|
secondItem->setSize(QSizeF(100, 100));
|
|
|
|
secondItem->setParentItem(window->contentItem());
|
|
|
|
|
|
|
|
firstItem->forceActiveFocus(Qt::OtherFocusReason);
|
|
|
|
QCOMPARE(QQuickWindowPrivate::get(window)->lastFocusReason, Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
secondItem->forceActiveFocus(Qt::TabFocusReason);
|
|
|
|
QCOMPARE(QQuickWindowPrivate::get(window)->lastFocusReason, Qt::TabFocusReason);
|
|
|
|
|
|
|
|
firstItem->forceActiveFocus(Qt::BacktabFocusReason);
|
|
|
|
QCOMPARE(QQuickWindowPrivate::get(window)->lastFocusReason, Qt::BacktabFocusReason);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-11 07:32:16 +00:00
|
|
|
void tst_qquickwindow::ignoreUnhandledMouseEvents()
|
2012-02-03 13:41:17 +00:00
|
|
|
{
|
2013-08-14 05:23:39 +00:00
|
|
|
QQuickWindow *window = new QQuickWindow;
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QQuickWindow> cleanup(window);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2012-07-11 07:32:16 +00:00
|
|
|
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
|
|
|
|
2013-08-14 05:23:39 +00:00
|
|
|
QQuickItem *item = new QQuickItem;
|
2012-02-03 13:41:17 +00:00
|
|
|
item->setSize(QSizeF(100, 100));
|
2012-08-07 01:26:37 +00:00
|
|
|
item->setParentItem(window->contentItem());
|
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-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
|
|
|
{
|
2012-07-25 06:59:17 +00:00
|
|
|
qmlRegisterType<RootItemAccessor>("Test", 1, 0, "RootItemAccessor");
|
2012-04-17 06:47:33 +00:00
|
|
|
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("ownershipRootItem.qml"));
|
2013-08-14 05:23:39 +00:00
|
|
|
QObject *created = component.create();
|
2012-08-17 08:00:06 +00:00
|
|
|
QScopedPointer<QObject> cleanup(created);
|
2012-04-17 06:47:33 +00:00
|
|
|
|
2013-08-14 05:23:39 +00:00
|
|
|
QQuickWindow *window = qobject_cast<QQuickWindow*>(created);
|
2012-07-11 07:32:16 +00:00
|
|
|
QVERIFY(window);
|
2015-06-03 12:27:27 +00:00
|
|
|
window->setTitle(QTest::currentTestFunction());
|
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-25 04:04:47 +00:00
|
|
|
|
|
|
|
#ifndef QT_NO_CURSOR
|
|
|
|
void tst_qquickwindow::cursor()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
|
|
|
window.setFramePosition(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(50, 50));
|
|
|
|
window.resize(320, 290);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
QQuickItem parentItem;
|
2012-10-22 14:59:25 +00:00
|
|
|
parentItem.setPosition(QPointF(0, 0));
|
2012-07-25 04:04:47 +00:00
|
|
|
parentItem.setSize(QSizeF(180, 180));
|
2012-08-07 01:26:37 +00:00
|
|
|
parentItem.setParentItem(window.contentItem());
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
QQuickItem childItem;
|
2012-10-22 14:59:25 +00:00
|
|
|
childItem.setPosition(QPointF(60, 90));
|
2012-07-25 04:04:47 +00:00
|
|
|
childItem.setSize(QSizeF(120, 120));
|
|
|
|
childItem.setParentItem(&parentItem);
|
|
|
|
|
|
|
|
QQuickItem clippingItem;
|
2012-10-22 14:59:25 +00:00
|
|
|
clippingItem.setPosition(QPointF(120, 120));
|
2012-07-25 04:04:47 +00:00
|
|
|
clippingItem.setSize(QSizeF(180, 180));
|
|
|
|
clippingItem.setClip(true);
|
2012-08-07 01:26:37 +00:00
|
|
|
clippingItem.setParentItem(window.contentItem());
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
QQuickItem clippedItem;
|
2012-10-22 14:59:25 +00:00
|
|
|
clippedItem.setPosition(QPointF(-30, -30));
|
2012-07-25 04:04:47 +00:00
|
|
|
clippedItem.setSize(QSizeF(120, 120));
|
|
|
|
clippedItem.setParentItem(&clippingItem);
|
|
|
|
|
|
|
|
window.show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window));
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
// Position the cursor over the parent and child item and the clipped section of clippedItem.
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 100));
|
|
|
|
|
|
|
|
// No items cursors, window cursor is the default arrow.
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
|
|
|
|
// The section of clippedItem under the cursor is clipped, and so doesn't affect the window cursor.
|
|
|
|
clippedItem.setCursor(Qt::ForbiddenCursor);
|
|
|
|
QCOMPARE(clippedItem.cursor().shape(), Qt::ForbiddenCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
|
|
|
|
// parentItem is under the cursor, so the window cursor is changed.
|
|
|
|
parentItem.setCursor(Qt::IBeamCursor);
|
|
|
|
QCOMPARE(parentItem.cursor().shape(), Qt::IBeamCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
|
|
|
|
|
|
|
|
// childItem is under the cursor and is in front of its parent, so the window cursor is changed.
|
|
|
|
childItem.setCursor(Qt::WaitCursor);
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::WaitCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
|
|
|
|
|
|
|
|
childItem.setCursor(Qt::PointingHandCursor);
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::PointingHandCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor);
|
|
|
|
|
|
|
|
// childItem is the current cursor item, so this has no effect on the window cursor.
|
|
|
|
parentItem.unsetCursor();
|
|
|
|
QCOMPARE(parentItem.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor);
|
|
|
|
|
|
|
|
parentItem.setCursor(Qt::IBeamCursor);
|
|
|
|
QCOMPARE(parentItem.cursor().shape(), Qt::IBeamCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor);
|
|
|
|
|
|
|
|
// With the childItem cursor cleared, parentItem is now foremost.
|
|
|
|
childItem.unsetCursor();
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
|
|
|
|
|
|
|
|
// Setting the childItem cursor to the default still takes precedence over parentItem.
|
|
|
|
childItem.setCursor(Qt::ArrowCursor);
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
|
|
|
|
childItem.setCursor(Qt::WaitCursor);
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::WaitCursor);
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
|
|
|
|
|
|
|
|
// Move the cursor so it is over just parentItem.
|
|
|
|
QTest::mouseMove(&window, QPoint(20, 20));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
|
|
|
|
|
|
|
|
// Move the cursor so that is over all items, clippedItem wins because its a child of
|
|
|
|
// clippingItem which is in from of parentItem in painting order.
|
|
|
|
QTest::mouseMove(&window, QPoint(125, 125));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ForbiddenCursor);
|
|
|
|
|
|
|
|
// Over clippingItem only, so no cursor.
|
|
|
|
QTest::mouseMove(&window, QPoint(200, 280));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
|
|
|
|
// Over no item, so no cursor.
|
|
|
|
QTest::mouseMove(&window, QPoint(10, 280));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
|
|
|
|
// back to the start.
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 100));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
|
|
|
|
|
|
|
|
// Try with the mouse pressed.
|
|
|
|
QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(100, 100));
|
|
|
|
QTest::mouseMove(&window, QPoint(20, 20));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
|
|
|
|
QTest::mouseMove(&window, QPoint(125, 125));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ForbiddenCursor);
|
|
|
|
QTest::mouseMove(&window, QPoint(200, 280));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
QTest::mouseMove(&window, QPoint(10, 280));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
|
|
|
QTest::mouseMove(&window, QPoint(100, 100));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::WaitCursor);
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 100));
|
|
|
|
|
|
|
|
// Remove the cursor item from the scene. Theoretically this should make parentItem the
|
2013-08-09 19:04:41 +00:00
|
|
|
// cursorItem, but given the situation will correct itself after the next mouse move it
|
|
|
|
// simply unsets the window cursor for now.
|
2012-07-25 04:04:47 +00:00
|
|
|
childItem.setParentItem(0);
|
2013-08-09 19:04:41 +00:00
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
parentItem.setCursor(Qt::SizeAllCursor);
|
|
|
|
QCOMPARE(parentItem.cursor().shape(), Qt::SizeAllCursor);
|
2013-08-09 19:04:41 +00:00
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
// Changing the cursor of an un-parented item doesn't affect the window's cursor.
|
|
|
|
childItem.setCursor(Qt::ClosedHandCursor);
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::ClosedHandCursor);
|
2013-08-09 19:04:41 +00:00
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
childItem.unsetCursor();
|
|
|
|
QCOMPARE(childItem.cursor().shape(), Qt::ArrowCursor);
|
2013-08-09 19:04:41 +00:00
|
|
|
QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
|
2012-07-25 04:04:47 +00:00
|
|
|
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(100, 101));
|
|
|
|
QCOMPARE(window.cursor().shape(), Qt::SizeAllCursor);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
void tst_qquickwindow::hideThenDelete_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("persistentSG");
|
|
|
|
QTest::addColumn<bool>("persistentGL");
|
|
|
|
|
|
|
|
QTest::newRow("persistent:SG=false,GL=false") << false << false;
|
|
|
|
QTest::newRow("persistent:SG=true,GL=false") << true << false;
|
|
|
|
QTest::newRow("persistent:SG=false,GL=true") << false << true;
|
|
|
|
QTest::newRow("persistent:SG=true,GL=true") << true << true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_qquickwindow::hideThenDelete()
|
|
|
|
{
|
|
|
|
QFETCH(bool, persistentSG);
|
|
|
|
QFETCH(bool, persistentGL);
|
|
|
|
|
|
|
|
QSignalSpy *openglDestroyed = 0;
|
|
|
|
QSignalSpy *sgInvalidated = 0;
|
|
|
|
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(' ')
|
|
|
|
+ QLatin1String(QTest::currentDataTag()));
|
2012-12-05 14:27:47 +00:00
|
|
|
window.setColor(Qt::red);
|
|
|
|
|
|
|
|
window.setPersistentSceneGraph(persistentSG);
|
|
|
|
window.setPersistentOpenGLContext(persistentGL);
|
|
|
|
|
|
|
|
window.resize(400, 300);
|
|
|
|
window.show();
|
|
|
|
|
|
|
|
QTest::qWaitForWindowExposed(&window);
|
2016-05-07 13:33:47 +00:00
|
|
|
const bool threaded = QQuickWindowPrivate::get(&window)->context->thread() != QGuiApplication::instance()->thread();
|
2016-06-01 07:58:27 +00:00
|
|
|
const bool isGL = window.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL;
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2016-05-07 13:33:47 +00:00
|
|
|
if (isGL)
|
|
|
|
openglDestroyed = new QSignalSpy(window.openglContext(), SIGNAL(aboutToBeDestroyed()));
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2016-05-07 13:33:47 +00:00
|
|
|
|
2012-12-05 14:27:47 +00:00
|
|
|
sgInvalidated = new QSignalSpy(&window, SIGNAL(sceneGraphInvalidated()));
|
|
|
|
|
|
|
|
window.hide();
|
|
|
|
|
|
|
|
QTRY_VERIFY(!window.isExposed());
|
2016-05-07 13:33:47 +00:00
|
|
|
|
2014-09-19 07:52:25 +00:00
|
|
|
if (threaded) {
|
2016-05-07 13:33:47 +00:00
|
|
|
if (!isGL)
|
|
|
|
QSKIP("Skipping persistency verification due to not running with OpenGL");
|
|
|
|
|
2014-09-19 07:52:25 +00:00
|
|
|
if (!persistentSG) {
|
|
|
|
QVERIFY(sgInvalidated->size() > 0);
|
|
|
|
if (!persistentGL)
|
|
|
|
QVERIFY(openglDestroyed->size() > 0);
|
|
|
|
else
|
2015-07-24 13:32:22 +00:00
|
|
|
QCOMPARE(openglDestroyed->size(), 0);
|
2014-09-19 07:52:25 +00:00
|
|
|
} else {
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(sgInvalidated->size(), 0);
|
|
|
|
QCOMPARE(openglDestroyed->size(), 0);
|
2014-09-19 07:52:25 +00:00
|
|
|
}
|
2012-12-05 14:27:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(sgInvalidated->size() > 0);
|
2016-04-26 09:49:52 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2016-05-07 13:33:47 +00:00
|
|
|
if (openglDestroyed)
|
|
|
|
QVERIFY(openglDestroyed->size() > 0);
|
2016-04-26 09:49:52 +00:00
|
|
|
#endif
|
2012-12-05 14:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_qquickwindow::showHideAnimate()
|
|
|
|
{
|
|
|
|
// This test tries to mimick a bug triggered in the qquickanimatedimage test
|
|
|
|
// A window is shown, then removed again before it is exposed. This left
|
|
|
|
// traces in the render loop which prevent other animations from running
|
|
|
|
// later on.
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
|
|
|
window.resize(400, 300);
|
|
|
|
window.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("showHideAnimate.qml"));
|
|
|
|
QQuickItem* created = qobject_cast<QQuickItem *>(component.create());
|
|
|
|
|
|
|
|
QVERIFY(created);
|
|
|
|
|
|
|
|
QTRY_VERIFY(created->opacity() > 0.5);
|
|
|
|
QTRY_VERIFY(created->opacity() < 0.5);
|
|
|
|
}
|
|
|
|
|
2013-02-20 18:39:11 +00:00
|
|
|
void tst_qquickwindow::testExpose()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-02-20 18:39:11 +00:00
|
|
|
window.setGeometry(100, 100, 300, 200);
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
QTRY_VERIFY(window.isExposed());
|
|
|
|
|
|
|
|
QSignalSpy swapSpy(&window, SIGNAL(frameSwapped()));
|
|
|
|
|
|
|
|
// exhaust pending exposes, as some platforms send us plenty
|
|
|
|
// while showing the first time
|
|
|
|
QTest::qWait(1000);
|
|
|
|
while (swapSpy.size() != 0) {
|
|
|
|
swapSpy.clear();
|
|
|
|
QTest::qWait(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWindowSystemInterface::handleExposeEvent(&window, QRegion(10, 10, 20, 20));
|
|
|
|
QTRY_COMPARE(swapSpy.size(), 1);
|
|
|
|
}
|
|
|
|
|
2013-04-18 07:36:28 +00:00
|
|
|
void tst_qquickwindow::requestActivate()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("active.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
QScopedPointer<QQuickWindow> window1(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window1.isNull());
|
|
|
|
window1->setTitle(QTest::currentTestFunction());
|
2013-04-18 07:36:28 +00:00
|
|
|
|
|
|
|
QWindowList windows = QGuiApplication::topLevelWindows();
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(windows.size(), 2);
|
2013-04-18 07:36:28 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < windows.size(); ++i) {
|
|
|
|
if (windows.at(i)->objectName() == window1->objectName()) {
|
|
|
|
windows.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(windows.size(), 1);
|
|
|
|
QCOMPARE(windows.at(0)->objectName(), QLatin1String("window2"));
|
2013-04-18 07:36:28 +00:00
|
|
|
|
|
|
|
window1->show();
|
2014-01-18 15:45:33 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(windows.at(0))); //We wait till window 2 comes up
|
|
|
|
window1->requestActivate(); // and then transfer the focus to window1
|
2013-04-18 07:36:28 +00:00
|
|
|
|
2015-06-03 12:27:27 +00:00
|
|
|
QTRY_COMPARE(QGuiApplication::focusWindow(), window1.data());
|
2015-07-24 11:39:05 +00:00
|
|
|
QVERIFY(window1->isActive());
|
2013-04-18 07:36:28 +00:00
|
|
|
|
|
|
|
QQuickItem *item = QQuickVisualTestUtil::findItem<QQuickItem>(window1->contentItem(), "item1");
|
|
|
|
QVERIFY(item);
|
|
|
|
|
|
|
|
//copied from src/qmltest/quicktestevent.cpp
|
|
|
|
QPoint pos = item->mapToScene(QPointF(item->width()/2, item->height()/2)).toPoint();
|
|
|
|
|
|
|
|
QMouseEvent me(QEvent::MouseButtonPress, pos, window1->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
|
|
|
QSpontaneKeyEvent::setSpontaneous(&me);
|
2015-06-03 12:27:27 +00:00
|
|
|
if (!qApp->notify(window1.data(), &me)) {
|
2013-04-18 07:36:28 +00:00
|
|
|
QString warning = QString::fromLatin1("Mouse event MousePress not accepted by receiving window");
|
|
|
|
QWARN(warning.toLatin1().data());
|
|
|
|
}
|
|
|
|
me = QMouseEvent(QEvent::MouseButtonPress, pos, window1->mapToGlobal(pos), Qt::LeftButton, 0, Qt::NoModifier);
|
|
|
|
QSpontaneKeyEvent::setSpontaneous(&me);
|
2015-06-03 12:27:27 +00:00
|
|
|
if (!qApp->notify(window1.data(), &me)) {
|
2013-04-18 07:36:28 +00:00
|
|
|
QString warning = QString::fromLatin1("Mouse event MouseRelease not accepted by receiving window");
|
|
|
|
QWARN(warning.toLatin1().data());
|
|
|
|
}
|
|
|
|
|
2015-06-03 12:27:27 +00:00
|
|
|
QTRY_COMPARE(QGuiApplication::focusWindow(), windows.at(0));
|
2013-04-18 07:36:28 +00:00
|
|
|
QVERIFY(windows.at(0)->isActive());
|
2014-01-18 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_qquickwindow::testWindowVisibilityOrder()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("windoworder.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
QScopedPointer<QQuickWindow> window1(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window1.isNull());
|
|
|
|
window1->setTitle(QTest::currentTestFunction());
|
2014-01-18 15:45:33 +00:00
|
|
|
QQuickWindow *window2 = window1->property("win2").value<QQuickWindow*>();
|
|
|
|
QQuickWindow *window3 = window1->property("win3").value<QQuickWindow*>();
|
|
|
|
QQuickWindow *window4 = window1->property("win4").value<QQuickWindow*>();
|
|
|
|
QQuickWindow *window5 = window1->property("win5").value<QQuickWindow*>();
|
|
|
|
QVERIFY(window2);
|
|
|
|
QVERIFY(window3);
|
|
|
|
|
|
|
|
QTest::qWaitForWindowExposed(window3);
|
|
|
|
|
|
|
|
QWindowList windows = QGuiApplication::topLevelWindows();
|
|
|
|
QTRY_COMPARE(windows.size(), 5);
|
|
|
|
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(window3, QGuiApplication::focusWindow());
|
2014-01-18 15:45:33 +00:00
|
|
|
QVERIFY(window1->isActive());
|
|
|
|
QVERIFY(window2->isActive());
|
|
|
|
QVERIFY(window3->isActive());
|
|
|
|
|
|
|
|
//Test if window4 is shown 2 seconds after the application startup
|
|
|
|
//with window4 visible window5 (transient child) should also become visible
|
|
|
|
QVERIFY(!window4->isVisible());
|
|
|
|
QVERIFY(!window5->isVisible());
|
|
|
|
|
|
|
|
window4->setVisible(true);
|
|
|
|
|
|
|
|
QTest::qWaitForWindowExposed(window5);
|
|
|
|
QVERIFY(window4->isVisible());
|
|
|
|
QVERIFY(window5->isVisible());
|
2013-04-18 07:36:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 12:40:28 +00:00
|
|
|
void tst_qquickwindow::blockClosing()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("ucantclosethis.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window.isNull());
|
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2013-05-06 12:40:28 +00:00
|
|
|
window->show();
|
2015-06-03 12:27:27 +00:00
|
|
|
QTest::qWaitForWindowExposed(window.data());
|
2013-05-06 12:40:28 +00:00
|
|
|
QVERIFY(window->isVisible());
|
2015-06-03 12:27:27 +00:00
|
|
|
QWindowSystemInterface::handleCloseEvent(window.data());
|
2013-05-06 12:40:28 +00:00
|
|
|
QVERIFY(window->isVisible());
|
2015-06-03 12:27:27 +00:00
|
|
|
QWindowSystemInterface::handleCloseEvent(window.data());
|
2013-05-06 12:40:28 +00:00
|
|
|
QVERIFY(window->isVisible());
|
|
|
|
window->setProperty("canCloseThis", true);
|
2015-06-03 12:27:27 +00:00
|
|
|
QWindowSystemInterface::handleCloseEvent(window.data());
|
2013-05-06 12:40:28 +00:00
|
|
|
QTRY_VERIFY(!window->isVisible());
|
|
|
|
}
|
|
|
|
|
2014-11-07 11:54:16 +00:00
|
|
|
void tst_qquickwindow::blockCloseMethod()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("ucantclosethis.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window.isNull());
|
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2014-11-07 11:54:16 +00:00
|
|
|
window->show();
|
2015-06-03 12:27:27 +00:00
|
|
|
QTest::qWaitForWindowExposed(window.data());
|
2014-11-07 11:54:16 +00:00
|
|
|
QVERIFY(window->isVisible());
|
2015-06-03 12:27:27 +00:00
|
|
|
QVERIFY(QMetaObject::invokeMethod(window.data(), "close", Qt::DirectConnection));
|
2014-11-07 11:54:16 +00:00
|
|
|
QVERIFY(window->isVisible());
|
2015-06-03 12:27:27 +00:00
|
|
|
QVERIFY(QMetaObject::invokeMethod(window.data(), "close", Qt::DirectConnection));
|
2014-11-07 11:54:16 +00:00
|
|
|
QVERIFY(window->isVisible());
|
|
|
|
window->setProperty("canCloseThis", true);
|
2015-06-03 12:27:27 +00:00
|
|
|
QVERIFY(QMetaObject::invokeMethod(window.data(), "close", Qt::DirectConnection));
|
2014-11-07 11:54:16 +00:00
|
|
|
QTRY_VERIFY(!window->isVisible());
|
|
|
|
}
|
|
|
|
|
2013-08-01 22:51:03 +00:00
|
|
|
void tst_qquickwindow::crashWhenHoverItemDeleted()
|
|
|
|
{
|
|
|
|
// QTBUG-32771
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("hoverCrash.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window.isNull());
|
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2013-08-01 22:51:03 +00:00
|
|
|
window->show();
|
2015-06-04 08:24:46 +00:00
|
|
|
QTest::qWaitForWindowActive(window.data());
|
2013-08-01 22:51:03 +00:00
|
|
|
|
|
|
|
// Simulate a move from the first rectangle to the second. Crash will happen in here
|
|
|
|
// Moving instantaneously from (0, 99) to (0, 102) does not cause the crash
|
2013-08-14 05:23:39 +00:00
|
|
|
for (int i = 99; i < 102; ++i) {
|
2015-06-03 12:27:27 +00:00
|
|
|
QTest::mouseMove(window.data(), QPoint(0, i));
|
2013-08-01 22:51:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-17 13:05:04 +00:00
|
|
|
// QTBUG-33436
|
|
|
|
void tst_qquickwindow::unloadSubWindow()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("unloadSubWindow.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window.isNull());
|
|
|
|
window->setTitle(QTest::currentTestFunction());
|
2013-09-17 13:05:04 +00:00
|
|
|
window->show();
|
2015-06-03 12:27:27 +00:00
|
|
|
QTest::qWaitForWindowExposed(window.data());
|
2014-08-06 13:18:08 +00:00
|
|
|
QPointer<QQuickWindow> transient;
|
2013-09-17 13:05:04 +00:00
|
|
|
QTRY_VERIFY(transient = window->property("transientWindow").value<QQuickWindow*>());
|
|
|
|
QTest::qWaitForWindowExposed(transient);
|
|
|
|
|
|
|
|
// Unload the inner window (in nested Loaders) and make sure it doesn't crash
|
|
|
|
QQuickLoader *loader = window->property("loader1").value<QQuickLoader*>();
|
|
|
|
loader->setActive(false);
|
2014-08-06 13:18:08 +00:00
|
|
|
QTRY_VERIFY(transient.isNull() || !transient->isVisible());
|
2013-09-17 13:05:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 15:49:11 +00:00
|
|
|
// QTBUG-52573
|
|
|
|
void tst_qquickwindow::changeVisibilityInCompleted()
|
|
|
|
{
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.loadUrl(testFileUrl("changeVisibilityInCompleted.qml"));
|
|
|
|
QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create()));
|
|
|
|
QVERIFY(!window.isNull());
|
|
|
|
window->setTitle(QTest::currentTestFunction());
|
|
|
|
window->show();
|
|
|
|
QTest::qWaitForWindowExposed(window.data());
|
|
|
|
QPointer<QQuickWindow> winVisible;
|
|
|
|
QTRY_VERIFY(winVisible = window->property("winVisible").value<QQuickWindow*>());
|
|
|
|
QPointer<QQuickWindow> winVisibility;
|
|
|
|
QTRY_VERIFY(winVisibility = window->property("winVisibility").value<QQuickWindow*>());
|
|
|
|
QTest::qWaitForWindowExposed(winVisible);
|
|
|
|
QTest::qWaitForWindowExposed(winVisibility);
|
|
|
|
|
|
|
|
QVERIFY(winVisible->isVisible());
|
|
|
|
QCOMPARE(winVisibility->visibility(), QWindow::Windowed);
|
|
|
|
}
|
|
|
|
|
2013-11-12 13:47:32 +00:00
|
|
|
// QTBUG-32004
|
|
|
|
void tst_qquickwindow::qobjectEventFilter_touch()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
|
|
|
|
|
|
|
window.resize(250, 250);
|
|
|
|
window.setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-11-12 13:47:32 +00:00
|
|
|
window.show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window));
|
2013-11-12 13:47:32 +00:00
|
|
|
|
|
|
|
TestTouchItem *item = new TestTouchItem(window.contentItem());
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
EventFilter eventFilter;
|
|
|
|
item->installEventFilter(&eventFilter);
|
|
|
|
|
|
|
|
QPointF pos(10, 10);
|
|
|
|
|
|
|
|
// press single point
|
|
|
|
QTest::touchEvent(&window, touchDevice).press(0, item->mapToScene(pos).toPoint(), &window);
|
|
|
|
|
|
|
|
QCOMPARE(eventFilter.events.count(), 1);
|
|
|
|
QCOMPARE(eventFilter.events.first(), (int)QEvent::TouchBegin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// QTBUG-32004
|
|
|
|
void tst_qquickwindow::qobjectEventFilter_key()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
|
|
|
|
|
|
|
window.resize(250, 250);
|
|
|
|
window.setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-11-12 13:47:32 +00:00
|
|
|
window.show();
|
2015-05-27 13:04:48 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window));
|
2013-11-12 13:47:32 +00:00
|
|
|
|
|
|
|
TestTouchItem *item = new TestTouchItem(window.contentItem());
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
item->setFocus(true);
|
|
|
|
|
|
|
|
EventFilter eventFilter;
|
|
|
|
item->installEventFilter(&eventFilter);
|
|
|
|
|
|
|
|
QTest::keyPress(&window, Qt::Key_A);
|
|
|
|
|
|
|
|
// NB: It may also receive some QKeyEvent(ShortcutOverride) which we're not interested in
|
|
|
|
QVERIFY(eventFilter.events.contains((int)QEvent::KeyPress));
|
|
|
|
eventFilter.events.clear();
|
|
|
|
|
|
|
|
QTest::keyRelease(&window, Qt::Key_A);
|
|
|
|
|
|
|
|
QVERIFY(eventFilter.events.contains((int)QEvent::KeyRelease));
|
|
|
|
}
|
|
|
|
|
|
|
|
// QTBUG-32004
|
|
|
|
void tst_qquickwindow::qobjectEventFilter_mouse()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
|
|
|
|
|
|
|
window.resize(250, 250);
|
|
|
|
window.setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2013-11-12 13:47:32 +00:00
|
|
|
window.show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window));
|
2013-11-12 13:47:32 +00:00
|
|
|
|
|
|
|
TestTouchItem *item = new TestTouchItem(window.contentItem());
|
|
|
|
item->setSize(QSizeF(150, 150));
|
|
|
|
|
|
|
|
EventFilter eventFilter;
|
|
|
|
item->installEventFilter(&eventFilter);
|
|
|
|
|
|
|
|
QPoint point = item->mapToScene(QPointF(10, 10)).toPoint();
|
2015-05-27 14:43:04 +00:00
|
|
|
QTest::mouseMove(&window, point);
|
2013-11-12 13:47:32 +00:00
|
|
|
QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point);
|
|
|
|
|
|
|
|
QVERIFY(eventFilter.events.contains((int)QEvent::MouseButtonPress));
|
|
|
|
|
|
|
|
// clean up mouse press state for the next tests
|
|
|
|
QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, point);
|
|
|
|
}
|
|
|
|
|
2014-02-19 11:20:20 +00:00
|
|
|
void tst_qquickwindow::animatingSignal()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2014-02-19 11:20:20 +00:00
|
|
|
window.setGeometry(100, 100, 300, 200);
|
|
|
|
|
|
|
|
QSignalSpy spy(&window, SIGNAL(afterAnimating()));
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
QTRY_VERIFY(window.isExposed());
|
|
|
|
|
|
|
|
QTRY_VERIFY(spy.count() > 1);
|
|
|
|
}
|
|
|
|
|
2014-02-21 14:04:21 +00:00
|
|
|
// QTBUG-36938
|
|
|
|
void tst_qquickwindow::contentItemSize()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2014-02-21 14:04:21 +00:00
|
|
|
QQuickItem *contentItem = window.contentItem();
|
|
|
|
QVERIFY(contentItem);
|
|
|
|
QCOMPARE(QSize(contentItem->width(), contentItem->height()), window.size());
|
|
|
|
|
|
|
|
QSizeF size(300, 200);
|
|
|
|
window.resize(size.toSize());
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
|
|
|
|
QCOMPARE(window.size(), size.toSize());
|
|
|
|
QCOMPARE(QSizeF(contentItem->width(), contentItem->height()), size);
|
|
|
|
|
|
|
|
QQmlEngine engine;
|
|
|
|
QQmlComponent component(&engine);
|
|
|
|
component.setData(QByteArray("import QtQuick 2.1\n Rectangle { anchors.fill: parent }"), QUrl());
|
|
|
|
QQuickItem *rect = qobject_cast<QQuickItem *>(component.create());
|
|
|
|
QVERIFY(rect);
|
|
|
|
rect->setParentItem(window.contentItem());
|
|
|
|
QCOMPARE(QSizeF(rect->width(), rect->height()), size);
|
|
|
|
|
|
|
|
size.transpose();
|
|
|
|
window.resize(size.toSize());
|
|
|
|
QCOMPARE(window.size(), size.toSize());
|
|
|
|
// wait for resize event
|
|
|
|
QTRY_COMPARE(QSizeF(contentItem->width(), contentItem->height()), size);
|
|
|
|
QCOMPARE(QSizeF(rect->width(), rect->height()), size);
|
|
|
|
}
|
|
|
|
|
2014-03-19 14:43:49 +00:00
|
|
|
void tst_qquickwindow::defaultSurfaceFormat()
|
|
|
|
{
|
|
|
|
// It is quite difficult to verify anything for real since the resulting format after
|
|
|
|
// surface/context creation can be anything, depending on the platform and drivers,
|
|
|
|
// and many options and settings may fail in various configurations, but test at
|
|
|
|
// least using some harmless settings to check that the global, static format is
|
|
|
|
// taken into account in the requested format.
|
|
|
|
|
2014-08-07 15:19:50 +00:00
|
|
|
QSurfaceFormat savedDefaultFormat = QSurfaceFormat::defaultFormat();
|
2014-03-19 14:43:49 +00:00
|
|
|
|
|
|
|
// Verify that depth and stencil are set, as they should be, unless they are disabled
|
|
|
|
// via environment variables.
|
|
|
|
|
|
|
|
QSurfaceFormat format = savedDefaultFormat;
|
|
|
|
format.setSwapInterval(0);
|
|
|
|
format.setRedBufferSize(8);
|
|
|
|
format.setGreenBufferSize(8);
|
|
|
|
format.setBlueBufferSize(8);
|
|
|
|
format.setProfile(QSurfaceFormat::CompatibilityProfile);
|
|
|
|
format.setOption(QSurfaceFormat::DebugContext);
|
2014-08-07 15:19:50 +00:00
|
|
|
// Will not set depth and stencil. That should be added automatically,
|
|
|
|
// unless the are disabled (but they aren't).
|
|
|
|
QSurfaceFormat::setDefaultFormat(format);
|
2014-03-19 14:43:49 +00:00
|
|
|
|
|
|
|
QQuickWindow window;
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2014-03-19 14:43:49 +00:00
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
|
2016-06-01 07:58:27 +00:00
|
|
|
if (window.rendererInterface()->graphicsApi() != QSGRendererInterface::OpenGL)
|
2016-05-07 13:33:47 +00:00
|
|
|
QSKIP("Skipping OpenGL context test due to not running with OpenGL");
|
|
|
|
|
2014-03-19 14:43:49 +00:00
|
|
|
const QSurfaceFormat reqFmt = window.requestedFormat();
|
|
|
|
QCOMPARE(format.swapInterval(), reqFmt.swapInterval());
|
|
|
|
QCOMPARE(format.redBufferSize(), reqFmt.redBufferSize());
|
|
|
|
QCOMPARE(format.greenBufferSize(), reqFmt.greenBufferSize());
|
|
|
|
QCOMPARE(format.blueBufferSize(), reqFmt.blueBufferSize());
|
|
|
|
QCOMPARE(format.profile(), reqFmt.profile());
|
|
|
|
QCOMPARE(int(format.options()), int(reqFmt.options()));
|
|
|
|
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2014-08-07 15:19:50 +00:00
|
|
|
// Depth and stencil should be >= what has been requested. For real. But use
|
|
|
|
// the context since the window's surface format is only partially updated
|
|
|
|
// on most platforms.
|
|
|
|
QVERIFY(window.openglContext()->format().depthBufferSize() >= 16);
|
|
|
|
QVERIFY(window.openglContext()->format().stencilBufferSize() >= 8);
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2014-08-07 15:19:50 +00:00
|
|
|
QSurfaceFormat::setDefaultFormat(savedDefaultFormat);
|
2014-03-19 14:43:49 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 11:57:50 +00:00
|
|
|
void tst_qquickwindow::attachedProperty()
|
|
|
|
{
|
|
|
|
QQuickView view(testFileUrl("windowattached.qml"));
|
2015-06-03 12:27:27 +00:00
|
|
|
view.setTitle(QTest::currentTestFunction());
|
2014-08-07 11:57:50 +00:00
|
|
|
view.show();
|
|
|
|
view.requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&view));
|
|
|
|
QVERIFY(view.rootObject()->property("windowActive").toBool());
|
2014-11-03 16:23:11 +00:00
|
|
|
QCOMPARE(view.rootObject()->property("contentItem").value<QQuickItem*>(), view.contentItem());
|
2015-01-05 20:00:40 +00:00
|
|
|
QCOMPARE(view.rootObject()->property("windowWidth").toInt(), view.width());
|
|
|
|
QCOMPARE(view.rootObject()->property("windowHeight").toInt(), view.height());
|
2016-01-31 08:39:34 +00:00
|
|
|
QCOMPARE(view.rootObject()->property("window").value<QQuickView*>(), &view);
|
2014-08-07 11:57:50 +00:00
|
|
|
|
|
|
|
QQuickWindow *innerWindow = view.rootObject()->findChild<QQuickWindow*>("extraWindow");
|
|
|
|
QVERIFY(innerWindow);
|
|
|
|
innerWindow->requestActivate();
|
|
|
|
QVERIFY(QTest::qWaitForWindowActive(innerWindow));
|
|
|
|
|
|
|
|
QQuickText *text = view.rootObject()->findChild<QQuickText*>("extraWindowText");
|
|
|
|
QVERIFY(text);
|
|
|
|
QCOMPARE(text->text(), QLatin1String("active\nvisibility: 2"));
|
2014-11-03 16:23:11 +00:00
|
|
|
QCOMPARE(text->property("contentItem").value<QQuickItem*>(), innerWindow->contentItem());
|
2015-01-05 20:00:40 +00:00
|
|
|
QCOMPARE(text->property("windowWidth").toInt(), innerWindow->width());
|
|
|
|
QCOMPARE(text->property("windowHeight").toInt(), innerWindow->height());
|
2016-01-31 08:39:34 +00:00
|
|
|
QCOMPARE(text->property("window").value<QQuickWindow*>(), innerWindow);
|
2016-01-31 09:42:11 +00:00
|
|
|
|
|
|
|
text->setParentItem(0);
|
|
|
|
QVERIFY(!text->property("contentItem").value<QQuickItem*>());
|
|
|
|
QCOMPARE(text->property("windowWidth").toInt(), 0);
|
|
|
|
QCOMPARE(text->property("windowHeight").toInt(), 0);
|
2016-01-31 08:39:34 +00:00
|
|
|
QVERIFY(!text->property("window").value<QQuickWindow*>());
|
2014-08-07 11:57:50 +00:00
|
|
|
}
|
|
|
|
|
2014-07-04 21:50:50 +00:00
|
|
|
class RenderJob : public QRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RenderJob(QQuickWindow::RenderStage s, QList<QQuickWindow::RenderStage> *l) : stage(s), list(l) { }
|
|
|
|
~RenderJob() { ++deleted; }
|
|
|
|
QQuickWindow::RenderStage stage;
|
|
|
|
QList<QQuickWindow::RenderStage> *list;
|
|
|
|
void run() {
|
|
|
|
list->append(stage);
|
|
|
|
}
|
|
|
|
static int deleted;
|
|
|
|
};
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2015-03-18 12:13:10 +00:00
|
|
|
class GlRenderJob : public QRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GlRenderJob(GLubyte *buf) : readPixel(buf), mutex(0), condition(0) {}
|
|
|
|
~GlRenderJob() {}
|
|
|
|
void run() {
|
|
|
|
QOpenGLContext::currentContext()->functions()->glClearColor(1.0f, 0, 0, 1.0f);
|
|
|
|
QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
QOpenGLContext::currentContext()->functions()->glReadPixels(0, 0, 1, 1, GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
(void *)readPixel);
|
|
|
|
if (mutex) {
|
|
|
|
mutex->lock();
|
|
|
|
condition->wakeOne();
|
|
|
|
mutex->unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GLubyte *readPixel;
|
|
|
|
QMutex *mutex;
|
|
|
|
QWaitCondition *condition;
|
|
|
|
};
|
2016-04-25 10:09:44 +00:00
|
|
|
#endif
|
2014-07-04 21:50:50 +00:00
|
|
|
int RenderJob::deleted = 0;
|
|
|
|
|
|
|
|
void tst_qquickwindow::testRenderJob()
|
|
|
|
{
|
|
|
|
QList<QQuickWindow::RenderStage> completedJobs;
|
|
|
|
|
|
|
|
QQuickWindow::RenderStage stages[] = {
|
|
|
|
QQuickWindow::BeforeSynchronizingStage,
|
|
|
|
QQuickWindow::AfterSynchronizingStage,
|
|
|
|
QQuickWindow::BeforeRenderingStage,
|
|
|
|
QQuickWindow::AfterRenderingStage,
|
2015-03-18 12:13:10 +00:00
|
|
|
QQuickWindow::AfterSwapStage,
|
|
|
|
QQuickWindow::NoStage
|
2014-07-04 21:50:50 +00:00
|
|
|
};
|
|
|
|
|
2015-03-18 12:13:10 +00:00
|
|
|
const int numJobs = 6;
|
2014-07-04 21:50:50 +00:00
|
|
|
|
2015-03-18 12:13:10 +00:00
|
|
|
{
|
|
|
|
QQuickWindow window;
|
2015-06-04 08:24:46 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2015-03-18 12:13:10 +00:00
|
|
|
RenderJob::deleted = 0;
|
|
|
|
|
|
|
|
// Schedule the jobs
|
|
|
|
for (int i = 0; i < numJobs; ++i)
|
|
|
|
window.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]);
|
|
|
|
window.show();
|
|
|
|
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
|
|
|
|
|
|
|
// All jobs should be deleted
|
|
|
|
QTRY_COMPARE(RenderJob::deleted, numJobs);
|
|
|
|
|
|
|
|
// The NoStage job is not completed, if it is issued when there is no context,
|
|
|
|
// but the rest will be queued and completed once relevant render stage is hit.
|
|
|
|
QCOMPARE(completedJobs.size(), numJobs - 1);
|
|
|
|
|
|
|
|
// Verify jobs were completed in correct order
|
|
|
|
for (int i = 0; i < numJobs - 1; ++i)
|
|
|
|
QCOMPARE(completedJobs.at(i), stages[i]);
|
|
|
|
|
|
|
|
|
|
|
|
// Check that NoStage job gets executed if it is scheduled when window is exposed
|
|
|
|
completedJobs.clear();
|
|
|
|
RenderJob::deleted = 0;
|
|
|
|
window.scheduleRenderJob(new RenderJob(QQuickWindow::NoStage, &completedJobs),
|
|
|
|
QQuickWindow::NoStage);
|
|
|
|
QTRY_COMPARE(RenderJob::deleted, 1);
|
|
|
|
QCOMPARE(completedJobs.size(), 1);
|
|
|
|
|
2016-04-25 10:09:44 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
2016-06-01 07:58:27 +00:00
|
|
|
if (window.rendererInterface()->graphicsApi() == QSGRendererInterface::OpenGL) {
|
2016-05-07 13:33:47 +00:00
|
|
|
// Do a synchronized GL job.
|
|
|
|
GLubyte readPixel[4] = {0, 0, 0, 0};
|
|
|
|
GlRenderJob *glJob = new GlRenderJob(readPixel);
|
|
|
|
if (window.openglContext()->thread() != QThread::currentThread()) {
|
|
|
|
QMutex mutex;
|
|
|
|
QWaitCondition condition;
|
|
|
|
glJob->mutex = &mutex;
|
|
|
|
glJob->condition = &condition;
|
|
|
|
mutex.lock();
|
|
|
|
window.scheduleRenderJob(glJob, QQuickWindow::NoStage);
|
|
|
|
condition.wait(&mutex);
|
|
|
|
mutex.unlock();
|
|
|
|
} else {
|
|
|
|
window.scheduleRenderJob(glJob, QQuickWindow::NoStage);
|
|
|
|
}
|
|
|
|
QCOMPARE(int(readPixel[0]), 255);
|
|
|
|
QCOMPARE(int(readPixel[1]), 0);
|
|
|
|
QCOMPARE(int(readPixel[2]), 0);
|
|
|
|
QCOMPARE(int(readPixel[3]), 255);
|
2015-03-18 12:13:10 +00:00
|
|
|
}
|
2016-05-07 13:33:47 +00:00
|
|
|
#endif
|
2016-05-08 18:17:35 +00:00
|
|
|
}
|
2016-05-07 13:33:47 +00:00
|
|
|
|
2015-03-18 12:13:10 +00:00
|
|
|
// Verify that jobs are deleted when window is not rendered at all
|
2014-07-04 21:50:50 +00:00
|
|
|
completedJobs.clear();
|
|
|
|
RenderJob::deleted = 0;
|
|
|
|
{
|
|
|
|
QQuickWindow window2;
|
2015-03-18 12:13:10 +00:00
|
|
|
for (int i = 0; i < numJobs; ++i) {
|
2014-07-04 21:50:50 +00:00
|
|
|
window2.scheduleRenderJob(new RenderJob(stages[i], &completedJobs), stages[i]);
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 12:13:10 +00:00
|
|
|
QTRY_COMPARE(RenderJob::deleted, numJobs);
|
2014-07-04 21:50:50 +00:00
|
|
|
QCOMPARE(completedJobs.size(), 0);
|
|
|
|
}
|
|
|
|
|
2015-01-14 08:41:23 +00:00
|
|
|
class EventCounter : public QQuickRectangle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EventCounter(QQuickItem *parent = 0)
|
|
|
|
: QQuickRectangle(parent)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void addFilterEvent(QEvent::Type type)
|
|
|
|
{
|
|
|
|
m_returnTrueForType.append(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
int childMouseEventFilterEventCount(QEvent::Type type)
|
|
|
|
{
|
|
|
|
return m_childMouseEventFilterEventCount.value(type, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int eventCount(QEvent::Type type)
|
|
|
|
{
|
|
|
|
return m_eventCount.value(type, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
m_eventCount.clear();
|
|
|
|
m_childMouseEventFilterEventCount.clear();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
bool childMouseEventFilter(QQuickItem *, QEvent *event) Q_DECL_OVERRIDE
|
|
|
|
{
|
|
|
|
m_childMouseEventFilterEventCount[event->type()]++;
|
|
|
|
return m_returnTrueForType.contains(event->type());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool event(QEvent *event) Q_DECL_OVERRIDE
|
|
|
|
{
|
|
|
|
m_eventCount[event->type()]++;
|
|
|
|
return QQuickRectangle::event(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<QEvent::Type> m_returnTrueForType;
|
|
|
|
QMap<QEvent::Type, int> m_childMouseEventFilterEventCount;
|
|
|
|
QMap<QEvent::Type, int> m_eventCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_qquickwindow::testHoverChildMouseEventFilter()
|
|
|
|
{
|
|
|
|
QQuickWindow window;
|
|
|
|
|
|
|
|
window.resize(250, 250);
|
|
|
|
window.setPosition(100, 100);
|
2015-06-03 12:27:27 +00:00
|
|
|
window.setTitle(QTest::currentTestFunction());
|
2015-01-14 08:41:23 +00:00
|
|
|
window.show();
|
2015-04-21 08:48:29 +00:00
|
|
|
QVERIFY(QTest::qWaitForWindowActive(&window));
|
2015-01-14 08:41:23 +00:00
|
|
|
|
|
|
|
EventCounter *bottomItem = new EventCounter(window.contentItem());
|
|
|
|
bottomItem->setObjectName("Bottom Item");
|
|
|
|
bottomItem->setSize(QSizeF(150, 150));
|
|
|
|
bottomItem->setAcceptHoverEvents(true);
|
|
|
|
|
|
|
|
EventCounter *middleItem = new EventCounter(bottomItem);
|
|
|
|
middleItem->setObjectName("Middle Item");
|
|
|
|
middleItem->setPosition(QPointF(50, 50));
|
|
|
|
middleItem->setSize(QSizeF(150, 150));
|
|
|
|
middleItem->setAcceptHoverEvents(true);
|
|
|
|
|
|
|
|
EventCounter *topItem = new EventCounter(middleItem);
|
|
|
|
topItem->setObjectName("Top Item");
|
|
|
|
topItem->setPosition(QPointF(50, 50));
|
|
|
|
topItem->setSize(QSizeF(150, 150));
|
|
|
|
topItem->setAcceptHoverEvents(true);
|
|
|
|
|
|
|
|
QPoint pos(10, 10);
|
|
|
|
|
|
|
|
QTest::mouseMove(&window, pos);
|
|
|
|
|
|
|
|
QTRY_VERIFY(bottomItem->eventCount(QEvent::HoverEnter) > 0);
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter), 0);
|
|
|
|
QCOMPARE(middleItem->eventCount(QEvent::HoverEnter), 0);
|
|
|
|
QCOMPARE(topItem->eventCount(QEvent::HoverEnter), 0);
|
2015-01-14 08:41:23 +00:00
|
|
|
bottomItem->reset();
|
|
|
|
|
|
|
|
pos = QPoint(60, 60);
|
|
|
|
QTest::mouseMove(&window, pos);
|
|
|
|
QTRY_VERIFY(middleItem->eventCount(QEvent::HoverEnter) > 0);
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter), 0);
|
2015-01-14 08:41:23 +00:00
|
|
|
middleItem->reset();
|
|
|
|
|
|
|
|
pos = QPoint(70,70);
|
|
|
|
bottomItem->setFiltersChildMouseEvents(true);
|
|
|
|
QTest::mouseMove(&window, pos);
|
|
|
|
QTRY_VERIFY(middleItem->eventCount(QEvent::HoverMove) > 0);
|
|
|
|
QVERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverMove) > 0);
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(topItem->eventCount(QEvent::HoverEnter), 0);
|
2015-01-14 08:41:23 +00:00
|
|
|
bottomItem->reset();
|
|
|
|
middleItem->reset();
|
|
|
|
|
|
|
|
pos = QPoint(110,110);
|
|
|
|
bottomItem->addFilterEvent(QEvent::HoverEnter);
|
|
|
|
QTest::mouseMove(&window, pos);
|
|
|
|
QTRY_VERIFY(bottomItem->childMouseEventFilterEventCount(QEvent::HoverEnter) > 0);
|
2015-06-03 12:27:27 +00:00
|
|
|
QCOMPARE(topItem->eventCount(QEvent::HoverEnter), 0);
|
|
|
|
QCOMPARE(middleItem->eventCount(QEvent::HoverEnter), 0);
|
2015-01-14 08:41:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 12:55:50 +00:00
|
|
|
void tst_qquickwindow::pointerEventTypeAndPointCount()
|
|
|
|
{
|
|
|
|
QMouseEvent me(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
|
|
|
QTouchEvent te(QEvent::TouchBegin, touchDevice, Qt::NoModifier, Qt::TouchPointPressed,
|
|
|
|
QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(1));
|
|
|
|
|
2016-07-15 14:24:34 +00:00
|
|
|
QQuickPointerMouseEvent pme;
|
|
|
|
pme.reset(&me);
|
|
|
|
QVERIFY(pme.isValid());
|
2016-07-21 09:35:42 +00:00
|
|
|
QCOMPARE(pme.asMouseEvent(), &me);
|
|
|
|
QVERIFY(pme.asPointerMouseEvent());
|
|
|
|
QVERIFY(!pme.asPointerTouchEvent());
|
|
|
|
QVERIFY(!pme.asPointerTabletEvent());
|
2016-07-15 14:24:34 +00:00
|
|
|
// QVERIFY(!pe->asTabletEvent()); // TODO
|
|
|
|
QCOMPARE(pme.pointCount(), 1);
|
|
|
|
|
|
|
|
QQuickPointerTouchEvent pte;
|
|
|
|
pte.reset(&te);
|
|
|
|
QVERIFY(pte.isValid());
|
2016-07-21 09:35:42 +00:00
|
|
|
QCOMPARE(pte.asTouchEvent(), &te);
|
|
|
|
QVERIFY(!pte.asPointerMouseEvent());
|
|
|
|
QVERIFY(pte.asPointerTouchEvent());
|
|
|
|
QVERIFY(!pte.asPointerTabletEvent());
|
2016-07-15 14:24:34 +00:00
|
|
|
QVERIFY(pte.asTouchEvent());
|
|
|
|
// QVERIFY(!pte.asTabletEvent()); // TODO
|
|
|
|
QCOMPARE(pte.pointCount(), 1);
|
|
|
|
QCOMPARE(pte.touchPointById(1)->id(), 1);
|
|
|
|
QVERIFY(!pte.touchPointById(0));
|
2016-07-13 12:55:50 +00:00
|
|
|
|
|
|
|
te.setTouchPoints(QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(1) << QTouchEvent::TouchPoint(2));
|
2016-07-15 14:24:34 +00:00
|
|
|
pte.reset(&te);
|
|
|
|
QCOMPARE(pte.pointCount(), 2);
|
|
|
|
QCOMPARE(pte.touchPointById(1)->id(), 1);
|
|
|
|
QCOMPARE(pte.touchPointById(2)->id(), 2);
|
|
|
|
QVERIFY(!pte.touchPointById(0));
|
2016-07-13 12:55:50 +00:00
|
|
|
|
|
|
|
te.setTouchPoints(QList<QTouchEvent::TouchPoint>() << QTouchEvent::TouchPoint(2));
|
2016-07-15 14:24:34 +00:00
|
|
|
pte.reset(&te);
|
|
|
|
QCOMPARE(pte.pointCount(), 1);
|
|
|
|
QCOMPARE(pte.touchPointById(2)->id(), 2);
|
|
|
|
QVERIFY(!pte.touchPointById(1));
|
|
|
|
QVERIFY(!pte.touchPointById(0));
|
2016-07-13 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
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"
|