/****************************************************************************
**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
+** 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
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
#include <qtest.h>
#include <QtQuick/qquickitem.h>
-#include <QtQuick/qquickcanvas.h>
+#include <QtQuick/qquickwindow.h>
#include <QtQuick/qquickview.h>
#include <QtWidgets/QGraphicsSceneMouseEvent>
#include "private/qquickfocusscope_p.h"
#include "private/qquickitem_p.h"
+#include <qpa/qwindowsysteminterface.h>
#include <QDebug>
#include <QTimer>
#include "../../shared/util.h"
virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; }
};
-class TestCanvas: public QQuickCanvas
+class TestWindow: public QQuickWindow
{
public:
- TestCanvas()
- : QQuickCanvas()
+ TestWindow()
+ : QQuickWindow()
{}
virtual bool event(QEvent *event)
{
- return QQuickCanvas::event(event);
+ return QQuickWindow::event(event);
}
};
private slots:
void initTestCase();
- void noCanvas();
+ void noWindow();
void simpleFocus();
void scopedFocus();
- void addedToCanvas();
+ void addedToWindow();
void changeParent();
void multipleFocusClears();
void focusSubItemInNonFocusScope();
void parentItemWithFocus();
+ void reparentFocusedItem();
void constructor();
void setParentItem();
void paintOrder_data();
void paintOrder();
+ void acceptedMouseButtons();
+
private:
enum PaintOrderOp {
void ensureFocus(QWindow *w) {
w->show();
- w->requestActivateWindow();
- qApp->processEvents();
+ w->requestActivate();
+ QTest::qWaitForWindowActive(w);
}
};
qmlRegisterType<TestPolishItem>("Qt.test", 1, 0, "TestPolishItem");
}
-// Focus still updates when outside a canvas
-void tst_qquickitem::noCanvas()
+// Focus still updates when outside a window
+void tst_qquickitem::noWindow()
{
QQuickItem *root = new TestItem;
QQuickItem *child = new TestItem(root);
root->setFocus(true);
scope->setFocus(true);
scopedChild2->setFocus(true);
- QCOMPARE(root->hasFocus(), true);
+ QCOMPARE(root->hasFocus(), false);
QCOMPARE(child->hasFocus(), false);
QCOMPARE(scope->hasFocus(), false);
QCOMPARE(scopedChild->hasFocus(), false);
#define FVERIFY() \
do { \
if (focusState.activeFocusItem) { \
- QCOMPARE(canvas.activeFocusItem(), focusState.activeFocusItem); \
- if (qobject_cast<TestItem *>(canvas.activeFocusItem())) \
- QCOMPARE(qobject_cast<TestItem *>(canvas.activeFocusItem())->focused, true); \
- else if (qobject_cast<TestFocusScope *>(canvas.activeFocusItem())) \
- QCOMPARE(qobject_cast<TestFocusScope *>(canvas.activeFocusItem())->focused, true); \
+ QCOMPARE(window.activeFocusItem(), focusState.activeFocusItem); \
+ if (qobject_cast<TestItem *>(window.activeFocusItem())) \
+ QCOMPARE(qobject_cast<TestItem *>(window.activeFocusItem())->focused, true); \
+ else if (qobject_cast<TestFocusScope *>(window.activeFocusItem())) \
+ QCOMPARE(qobject_cast<TestFocusScope *>(window.activeFocusItem())->focused, true); \
} else { \
- QCOMPARE(canvas.activeFocusItem(), canvas.rootItem()); \
+ QCOMPARE(window.activeFocusItem(), window.contentItem()); \
} \
for (QHash<QQuickItem *, FocusData>::Iterator iter = focusState.begin(); \
iter != focusState.end(); \
// Tests a simple set of top-level scoped items
void tst_qquickitem::simpleFocus()
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
#ifdef Q_OS_MAC
QSKIP("QTBUG-24094: fails on Mac OS X 10.7");
#endif
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
- QQuickItem *l1c1 = new TestItem(canvas.rootItem());
- QQuickItem *l1c2 = new TestItem(canvas.rootItem());
- QQuickItem *l1c3 = new TestItem(canvas.rootItem());
+ QQuickItem *l1c1 = new TestItem(window.contentItem());
+ QQuickItem *l1c2 = new TestItem(window.contentItem());
+ QQuickItem *l1c3 = new TestItem(window.contentItem());
QQuickItem *l2c1 = new TestItem(l1c1);
QQuickItem *l2c2 = new TestItem(l1c1);
// Items with a focus scope
void tst_qquickitem::scopedFocus()
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
- QQuickItem *l1c1 = new TestItem(canvas.rootItem());
- QQuickItem *l1c2 = new TestItem(canvas.rootItem());
- QQuickItem *l1c3 = new TestItem(canvas.rootItem());
+ QQuickItem *l1c1 = new TestItem(window.contentItem());
+ QQuickItem *l1c2 = new TestItem(window.contentItem());
+ QQuickItem *l1c3 = new TestItem(window.contentItem());
QQuickItem *l2c1 = new TestItem(l1c1);
QQuickItem *l2c2 = new TestItem(l1c1);
FVERIFY();
}
-// Tests focus corrects itself when a tree is added to a canvas for the first time
-void tst_qquickitem::addedToCanvas()
+// Tests focus corrects itself when a tree is added to a window for the first time
+void tst_qquickitem::addedToWindow()
{
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
QQuickItem *item = new TestItem;
focusState[item].set(true, false);
FVERIFY();
- item->setParentItem(canvas.rootItem());
+ item->setParentItem(window.contentItem());
focusState[item].set(true, true);
focusState.active(item);
FVERIFY();
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
- QQuickItem *item = new TestItem(canvas.rootItem());
+ QQuickItem *item = new TestItem(window.contentItem());
QQuickItem *tree = new TestItem;
QQuickItem *c1 = new TestItem(tree);
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
QQuickItem *tree = new TestItem;
QQuickItem *c1 = new TestItem(tree);
focusState[c2].set(true, false);
FVERIFY();
- tree->setParentItem(canvas.rootItem());
+ tree->setParentItem(window.contentItem());
focusState[c1].set(false, false);
focusState[c2].set(true, true);
focusState.active(c2);
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
QQuickItem *tree = new TestFocusScope;
QQuickItem *c1 = new TestItem(tree);
QQuickItem *c2 = new TestItem(tree);
focusState[c2].set(true, false);
FVERIFY();
- tree->setParentItem(canvas.rootItem());
+ tree->setParentItem(window.contentItem());
focusState[c1].set(false, false);
focusState[c2].set(true, false);
FVERIFY();
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
QQuickItem *tree = new TestFocusScope;
QQuickItem *c1 = new TestItem(tree);
QQuickItem *c2 = new TestItem(tree);
focusState[c2].set(true, false);
FVERIFY();
- tree->setParentItem(canvas.rootItem());
+ tree->setParentItem(window.contentItem());
focusState[tree].set(true, true);
focusState[c1].set(false, false);
focusState[c2].set(true, true);
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *child = new TestItem(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *child = new TestItem(window.contentItem());
QQuickItem *tree = new TestFocusScope;
QQuickItem *c1 = new TestItem(tree);
QQuickItem *c2 = new TestItem(tree);
focusState.active(child);
FVERIFY();
- tree->setParentItem(canvas.rootItem());
+ tree->setParentItem(window.contentItem());
focusState[tree].set(false, false);
focusState[c1].set(false, false);
focusState[c2].set(true, false);
{
// Parent to no parent
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *child = new TestItem(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *child = new TestItem(window.contentItem());
FocusState focusState;
focusState << child;
// Different parent, same focus scope
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *child = new TestItem(canvas.rootItem());
- QQuickItem *child2 = new TestItem(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *child = new TestItem(window.contentItem());
+ QQuickItem *child2 = new TestItem(window.contentItem());
FocusState focusState;
focusState << child << child2;
// Different parent, different focus scope
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *child = new TestItem(canvas.rootItem());
- QQuickItem *child2 = new TestFocusScope(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *child = new TestItem(window.contentItem());
+ QQuickItem *child2 = new TestFocusScope(window.contentItem());
QQuickItem *item = new TestItem(child);
FocusState focusState;
FVERIFY();
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *child = new TestItem(canvas.rootItem());
- QQuickItem *child2 = new TestFocusScope(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *child = new TestItem(window.contentItem());
+ QQuickItem *child2 = new TestFocusScope(window.contentItem());
QQuickItem *item = new TestItem(child2);
FocusState focusState;
FVERIFY();
}
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *child = new TestItem(canvas.rootItem());
- QQuickItem *child2 = new TestFocusScope(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *child = new TestItem(window.contentItem());
+ QQuickItem *child2 = new TestFocusScope(window.contentItem());
QQuickItem *item = new TestItem(child2);
FocusState focusState;
// child has active focus, then its fs parent changes parent to 0, then
// child is deleted, then its parent changes again to a valid parent
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
- QQuickItem *item = new TestFocusScope(canvas.rootItem());
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+ QQuickItem *item = new TestFocusScope(window.contentItem());
QQuickItem *child = new TestItem(item);
QQuickItem *child2 = new TestItem;
focusState.remove(child);
delete child;
- item->setParentItem(canvas.rootItem());
+ item->setParentItem(window.contentItem());
focusState[item].set(true, true);
focusState.active(item);
FVERIFY();
+ delete child2;
}
}
void tst_qquickitem::parentItemWithFocus()
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
- QTRY_VERIFY(QGuiApplication::focusWindow() == &canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
{
QQuickItem parent;
QQuickItem child;
focusState[&child].set(false, false);
FVERIFY();
- parent.setParentItem(canvas.rootItem());
+ parent.setParentItem(window.contentItem());
focusState[&parent].set(true, true);
focusState[&child].set(false, false);
focusState.active(&parent);
focusState[&grandchild].set(false, false);
FVERIFY();
- parent.setParentItem(canvas.rootItem());
+ parent.setParentItem(window.contentItem());
focusState[&parent].set(true, true);
focusState[&child].set(false, false);
focusState[&grandchild].set(false, false);
focusState.active(&grandchild);
FVERIFY();
}
+
+ {
+ QQuickItem parent;
+ QQuickItem child1;
+ QQuickItem child2;
+
+ FocusState focusState;
+ focusState << &parent << &child1 << &child2;
+ parent.setFocus(true);
+ child1.setParentItem(&parent);
+ child2.setParentItem(&parent);
+ focusState[&parent].set(true, false);
+ focusState[&child1].set(false, false);
+ focusState[&child2].set(false, false);
+ FVERIFY();
+
+ child1.setFocus(true);
+ focusState[&parent].set(false, false);
+ focusState[&child1].set(true, false);
+ FVERIFY();
+
+ parent.setFocus(true);
+ focusState[&parent].set(true, false);
+ focusState[&child1].set(false, false);
+ FVERIFY();
+ }
+}
+
+void tst_qquickitem::reparentFocusedItem()
+{
+ QQuickWindow window;
+ ensureFocus(&window);
+ QTRY_VERIFY(QGuiApplication::focusWindow() == &window);
+
+ QQuickItem parent(window.contentItem());
+ QQuickItem child(&parent);
+ QQuickItem sibling(&parent);
+ QQuickItem grandchild(&child);
+
+ FocusState focusState;
+ focusState << &parent << &child << &sibling << &grandchild;
+ FVERIFY();
+
+ grandchild.setFocus(true);
+ focusState[&parent].set(false, false);
+ focusState[&child].set(false, false);
+ focusState[&sibling].set(false, false);
+ focusState[&grandchild].set(true, true);
+ focusState.active(&grandchild);
+ FVERIFY();
+
+ // Parenting the item to another item within the same focus scope shouldn't change it's focus.
+ child.setParentItem(&sibling);
+ FVERIFY();
}
void tst_qquickitem::constructor()
void tst_qquickitem::enabledFocus()
{
- QQuickCanvas canvas;
- ensureFocus(&canvas);
+ QQuickWindow window;
+ ensureFocus(&window);
QQuickFocusScope root;
QCOMPARE(root.hasFocus(), true);
QCOMPARE(root.hasActiveFocus(), false);
- root.setParentItem(canvas.rootItem());
+ root.setParentItem(window.contentItem());
QCOMPARE(root.isEnabled(), false);
QCOMPARE(root.hasFocus(), true);
QCOMPARE(root.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+ QCOMPARE(window.activeFocusItem(), window.contentItem());
root.setEnabled(true);
QCOMPARE(root.isEnabled(), true);
QCOMPARE(root.hasFocus(), true);
QCOMPARE(root.hasActiveFocus(), true);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&root));
QQuickItem child1;
child1.setParentItem(&root);
QCOMPARE(child1.isEnabled(), true);
QCOMPARE(child1.hasFocus(), false);
QCOMPARE(child1.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&root));
QQuickItem child2;
child2.setFocus(true);
QCOMPARE(child2.isEnabled(), true);
QCOMPARE(child2.hasFocus(), true);
QCOMPARE(child2.hasActiveFocus(), true);
- QCOMPARE(canvas.activeFocusItem(), &child2);
+ QCOMPARE(window.activeFocusItem(), &child2);
child2.setEnabled(false);
QCOMPARE(child2.isEnabled(), false);
QCOMPARE(child2.hasFocus(), true);
QCOMPARE(child2.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&root));
child1.setEnabled(false);
QCOMPARE(child1.isEnabled(), false);
QCOMPARE(child2.isEnabled(), false);
QCOMPARE(child2.hasFocus(), false);
QCOMPARE(child2.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&root));
child1.setEnabled(true);
QCOMPARE(child1.isEnabled(), true);
QCOMPARE(child1.hasFocus(), true);
QCOMPARE(child1.hasActiveFocus(), true);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&child1));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&child1));
root.setFocus(false);
QCOMPARE(root.isEnabled(), true);
QCOMPARE(child1.isEnabled(), true);
QCOMPARE(child1.hasFocus(), true);
QCOMPARE(child1.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+ QCOMPARE(window.activeFocusItem(), window.contentItem());
child2.forceActiveFocus();
QCOMPARE(root.isEnabled(), true);
QCOMPARE(child2.isEnabled(), false);
QCOMPARE(child2.hasFocus(), true);
QCOMPARE(child2.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&root));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&root));
root.setEnabled(false);
QCOMPARE(root.isEnabled(), false);
QCOMPARE(child2.isEnabled(), false);
QCOMPARE(child2.hasFocus(), true);
QCOMPARE(child2.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+ QCOMPARE(window.activeFocusItem(), window.contentItem());
child1.forceActiveFocus();
QCOMPARE(root.isEnabled(), false);
QCOMPARE(child2.isEnabled(), false);
QCOMPARE(child2.hasFocus(), false);
QCOMPARE(child2.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), canvas.rootItem());
+ QCOMPARE(window.activeFocusItem(), window.contentItem());
root.setEnabled(true);
QCOMPARE(root.isEnabled(), true);
QCOMPARE(child2.isEnabled(), false);
QCOMPARE(child2.hasFocus(), false);
QCOMPARE(child2.hasActiveFocus(), false);
- QCOMPARE(canvas.activeFocusItem(), static_cast<QQuickItem *>(&child1));
+ QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&child1));
}
void tst_qquickitem::mouseGrab()
{
- QQuickCanvas *canvas = new QQuickCanvas;
- canvas->resize(200, 200);
- canvas->show();
+ QQuickWindow *window = new QQuickWindow;
+ window->resize(200, 200);
+ window->show();
TestItem *child1 = new TestItem;
child1->setAcceptedMouseButtons(Qt::LeftButton);
child1->setSize(QSizeF(200, 100));
- child1->setParentItem(canvas->rootItem());
+ child1->setParentItem(window->contentItem());
TestItem *child2 = new TestItem;
child2->setAcceptedMouseButtons(Qt::LeftButton);
child2->setY(51);
child2->setSize(QSizeF(200, 100));
- child2->setParentItem(canvas->rootItem());
+ child2->setParentItem(window->contentItem());
- QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(100);
- QVERIFY(canvas->mouseGrabberItem() == child1);
+ QVERIFY(window->mouseGrabberItem() == child1);
QTest::qWait(100);
QCOMPARE(child1->pressCount, 1);
- QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
- QVERIFY(canvas->mouseGrabberItem() == 0);
+ QVERIFY(window->mouseGrabberItem() == 0);
QCOMPARE(child1->releaseCount, 1);
- QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
- QVERIFY(canvas->mouseGrabberItem() == child1);
+ QVERIFY(window->mouseGrabberItem() == child1);
QCOMPARE(child1->pressCount, 2);
child1->setEnabled(false);
- QVERIFY(canvas->mouseGrabberItem() == 0);
- QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QVERIFY(window->mouseGrabberItem() == 0);
+ QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
QCOMPARE(child1->releaseCount, 1);
child1->setEnabled(true);
- QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
- QVERIFY(canvas->mouseGrabberItem() == child1);
+ QVERIFY(window->mouseGrabberItem() == child1);
QCOMPARE(child1->pressCount, 3);
child1->setVisible(false);
- QVERIFY(canvas->mouseGrabberItem() == 0);
- QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QVERIFY(window->mouseGrabberItem() == 0);
+ QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50));
QCOMPARE(child1->releaseCount, 1);
child1->setVisible(true);
- QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
- QVERIFY(canvas->mouseGrabberItem() == child1);
+ QVERIFY(window->mouseGrabberItem() == child1);
QCOMPARE(child1->pressCount, 4);
child2->grabMouse();
- QVERIFY(canvas->mouseGrabberItem() == child2);
- QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QVERIFY(window->mouseGrabberItem() == child2);
+ QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
QCOMPARE(child1->releaseCount, 1);
QCOMPARE(child2->releaseCount, 1);
child2->grabMouse();
- QVERIFY(canvas->mouseGrabberItem() == child2);
- QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QVERIFY(window->mouseGrabberItem() == child2);
+ QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
QCOMPARE(child1->pressCount, 4);
QCOMPARE(child2->pressCount, 1);
- QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50,50));
+ QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50));
QTest::qWait(50);
QCOMPARE(child1->releaseCount, 1);
QCOMPARE(child2->releaseCount, 2);
delete child1;
delete child2;
- delete canvas;
+ delete window;
}
void tst_qquickitem::touchEventAcceptIgnore_data()
{
QFETCH(bool, itemSupportsTouch);
- TestCanvas *canvas = new TestCanvas;
- canvas->resize(100, 100);
- canvas->show();
+ TestWindow *window = new TestWindow;
+ window->resize(100, 100);
+ window->show();
TestItem *item = new TestItem;
item->setSize(QSizeF(100, 100));
- item->setParentItem(canvas->rootItem());
+ item->setParentItem(window->contentItem());
item->acceptIncomingTouchEvents = itemSupportsTouch;
static QTouchDevice* device = 0;
item->touchEventReached = false;
- bool accepted = canvas->event(&event);
+ bool accepted = window->event(&event);
QVERIFY(item->touchEventReached);
QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch);
item->touchEventReached = false;
- bool accepted = canvas->event(&event);
+ bool accepted = window->event(&event);
QCOMPARE(item->touchEventReached, itemSupportsTouch);
QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch);
item->touchEventReached = false;
- bool accepted = canvas->event(&event);
+ bool accepted = window->event(&event);
QCOMPARE(item->touchEventReached, itemSupportsTouch);
QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch);
}
delete item;
- delete canvas;
+ delete window;
}
void tst_qquickitem::polishOutsideAnimation()
{
- QQuickCanvas *canvas = new QQuickCanvas;
- canvas->resize(200, 200);
- canvas->show();
+ QQuickWindow *window = new QQuickWindow;
+ window->resize(200, 200);
+ window->show();
- TestPolishItem *item = new TestPolishItem(canvas->rootItem());
+ TestPolishItem *item = new TestPolishItem(window->contentItem());
item->setSize(QSizeF(200, 100));
QTest::qWait(50);
QTRY_VERIFY(item->wasPolished);
delete item;
- delete canvas;
+ delete window;
}
void tst_qquickitem::polishOnCompleted()
TestPolishItem *item = qobject_cast<TestPolishItem*>(view->rootObject());
QVERIFY(item);
-#ifdef Q_OS_MAC
- QSKIP("QTBUG-21590 view does not reliably receive polish without a running animation");
-#endif
-
QTRY_VERIFY(item->wasPolished);
delete view;
const bool shouldReceiveWheelEvents = visible && enabled;
- QQuickCanvas *canvas = new QQuickCanvas;
- canvas->resize(200, 200);
- canvas->show();
+ QQuickWindow *window = new QQuickWindow;
+ window->resize(200, 200);
+ window->show();
TestItem *item = new TestItem;
item->setSize(QSizeF(200, 100));
- item->setParentItem(canvas->rootItem());
+ item->setParentItem(window->contentItem());
item->setEnabled(enabled);
item->setVisible(visible);
QWheelEvent event(QPoint(100, 50), -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical);
event.setAccepted(false);
- QGuiApplication::sendEvent(canvas, &event);
+ QGuiApplication::sendEvent(window, &event);
if (shouldReceiveWheelEvents) {
QVERIFY(event.isAccepted());
QCOMPARE(item->wheelCount, 0);
}
- delete canvas;
+ delete window;
}
class HoverItem : public QQuickItem
QFETCH(bool, enabled);
QFETCH(bool, acceptHoverEvents);
- QQuickCanvas *canvas = new QQuickCanvas();
- canvas->resize(200, 200);
- canvas->show();
+ QQuickWindow *window = new QQuickWindow();
+ window->resize(200, 200);
+ window->show();
HoverItem *item = new HoverItem;
item->setSize(QSizeF(100, 100));
- item->setParentItem(canvas->rootItem());
+ item->setParentItem(window->contentItem());
item->setEnabled(enabled);
item->setVisible(visible);
const QPoint inside(50, 50);
const QPoint anotherInside(51, 51);
- sendMouseMove(canvas, outside);
+ sendMouseMove(window, outside);
item->resetCounters();
// Enter, then move twice inside, then leave.
- sendMouseMove(canvas, inside);
- sendMouseMove(canvas, anotherInside);
- sendMouseMove(canvas, inside);
- sendMouseMove(canvas, outside);
+ sendMouseMove(window, inside);
+ sendMouseMove(window, anotherInside);
+ sendMouseMove(window, inside);
+ sendMouseMove(window, outside);
const bool shouldReceiveHoverEvents = visible && enabled && acceptHoverEvents;
if (shouldReceiveHoverEvents) {
QCOMPARE(item->hoverLeaveCount, 0);
}
- delete canvas;
+ delete window;
}
void tst_qquickitem::hoverEventInParent()
{
- QQuickCanvas *canvas = new QQuickCanvas();
- canvas->resize(200, 200);
- canvas->show();
+ QQuickWindow *window = new QQuickWindow();
+ window->resize(200, 200);
+ window->show();
- HoverItem *parentItem = new HoverItem(canvas->rootItem());
+ HoverItem *parentItem = new HoverItem(window->contentItem());
parentItem->setSize(QSizeF(200, 200));
parentItem->setAcceptHoverEvents(true);
const QPoint insideLeft(50, 100);
const QPoint insideRight(150, 100);
- sendMouseMove(canvas, insideLeft);
+ sendMouseMove(window, insideLeft);
parentItem->resetCounters();
leftItem->resetCounters();
rightItem->resetCounters();
- sendMouseMove(canvas, insideRight);
+ sendMouseMove(window, insideRight);
QCOMPARE(parentItem->hoverEnterCount, 0);
QCOMPARE(parentItem->hoverLeaveCount, 0);
QCOMPARE(leftItem->hoverEnterCount, 0);
QCOMPARE(rightItem->hoverEnterCount, 1);
QCOMPARE(rightItem->hoverLeaveCount, 0);
- sendMouseMove(canvas, insideLeft);
+ sendMouseMove(window, insideLeft);
QCOMPARE(parentItem->hoverEnterCount, 0);
QCOMPARE(parentItem->hoverLeaveCount, 0);
QCOMPARE(leftItem->hoverEnterCount, 1);
QCOMPARE(rightItem->hoverEnterCount, 1);
QCOMPARE(rightItem->hoverLeaveCount, 1);
- delete canvas;
+ delete window;
}
void tst_qquickitem::paintOrder_data()
QCOMPARE(items, expected);
}
+void tst_qquickitem::acceptedMouseButtons()
+{
+ TestItem item;
+ QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::NoButton));
+
+ QQuickWindow window;
+ item.setSize(QSizeF(200,100));
+ item.setParentItem(window.contentItem());
+
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 0);
+ QCOMPARE(item.releaseCount, 0);
+
+ QTest::mousePress(&window, Qt::RightButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::RightButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 0);
+ QCOMPARE(item.releaseCount, 0);
+
+ QTest::mousePress(&window, Qt::MiddleButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::MiddleButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 0);
+ QCOMPARE(item.releaseCount, 0);
+
+ item.setAcceptedMouseButtons(Qt::LeftButton);
+ QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::LeftButton));
+
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 1);
+ QCOMPARE(item.releaseCount, 1);
+
+ QTest::mousePress(&window, Qt::RightButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::RightButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 1);
+ QCOMPARE(item.releaseCount, 1);
+
+ QTest::mousePress(&window, Qt::MiddleButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::MiddleButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 1);
+ QCOMPARE(item.releaseCount, 1);
+
+ item.setAcceptedMouseButtons(Qt::RightButton | Qt::MiddleButton);
+ QCOMPARE(item.acceptedMouseButtons(), Qt::MouseButtons(Qt::RightButton | Qt::MiddleButton));
+
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 1);
+ QCOMPARE(item.releaseCount, 1);
+
+ QTest::mousePress(&window, Qt::RightButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::RightButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 2);
+ QCOMPARE(item.releaseCount, 2);
+
+ QTest::mousePress(&window, Qt::MiddleButton, 0, QPoint(50, 50));
+ QTest::mouseRelease(&window, Qt::MiddleButton, 0, QPoint(50, 50));
+ QCOMPARE(item.pressCount, 3);
+ QCOMPARE(item.releaseCount, 3);
+}
+
QTEST_MAIN(tst_qquickitem)