diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-07-22 18:23:00 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-07-22 18:24:30 +0200 |
commit | 6d36375fe3559f420a15b8240ed32679358a19e7 (patch) | |
tree | 16d20788d187dcd1c5de343955b867a10a22f378 | |
parent | 8b60bfd13f80588adab2c4778bc8de08832ecb7b (diff) | |
parent | 92032bee2923024d126bc20929f79abd459cae49 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Change-Id: I82c2b8d97d639e24147118a2ca6276ae70195b45
-rw-r--r-- | src/quicktemplates2/qquickdrawer.cpp | 6 | ||||
-rw-r--r-- | src/quicktemplates2/qquickoverlay.cpp | 75 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpopup.cpp | 5 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_popup.qml | 11 | ||||
-rw-r--r-- | tests/auto/drawer/data/hover.qml | 72 | ||||
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 64 | ||||
-rw-r--r-- | tests/auto/popup/data/applicationwindow.qml | 11 | ||||
-rw-r--r-- | tests/auto/popup/data/hover.qml | 69 | ||||
-rw-r--r-- | tests/auto/popup/tst_popup.cpp | 99 | ||||
-rw-r--r-- | tests/manual/testbench/main.qml | 7 |
10 files changed, 380 insertions, 39 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp index 2cc76947..fbc871f7 100644 --- a/src/quicktemplates2/qquickdrawer.cpp +++ b/src/quicktemplates2/qquickdrawer.cpp @@ -431,8 +431,12 @@ void QQuickDrawer::setPosition(qreal position) d->position = position; if (isComponentComplete()) d->reposition(); - if (d->dimmer) + if (d->dimmer) { d->dimmer->setOpacity(position); + // TODO: check QStyleHints::useHoverEffects in Qt 5.8 + d->dimmer->setAcceptHoverEvents(d->modal && position > 0.0); + // d->dimmer->setAcceptHoverEvents(d->modal && position > 0.0 && QGuiApplication::styleHints()->useHoverEffects()); + } emit positionChanged(); } diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index 67eb3ceb..efbc2ce5 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -53,12 +53,13 @@ public: void popupAboutToShow(); void popupAboutToHide(); - void popupClosed(); void createOverlay(QQuickPopup *popup); void destroyOverlay(QQuickPopup *popup); void resizeOverlay(QQuickPopup *popup); + QVector<QQuickPopup *> stackingOrderPopups() const; + QQmlComponent *modal; QQmlComponent *modeless; QVector<QQuickDrawer *> drawers; @@ -74,8 +75,6 @@ void QQuickOverlayPrivate::popupAboutToShow() if (!popup || !popup->dim()) return; - createOverlay(popup); - // use QQmlProperty instead of QQuickItem::setOpacity() to trigger QML Behaviors QQuickPopupPrivate *p = QQuickPopupPrivate::get(popup); if (p->dimmer) @@ -95,16 +94,6 @@ void QQuickOverlayPrivate::popupAboutToHide() QQmlProperty::write(p->dimmer, QStringLiteral("opacity"), 0.0); } -void QQuickOverlayPrivate::popupClosed() -{ - Q_Q(QQuickOverlay); - QQuickPopup *popup = qobject_cast<QQuickPopup *>(q->sender()); - if (!popup || !popup->dim()) - return; - - destroyOverlay(popup); -} - static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQuickItem *parent) { if (!component) @@ -121,6 +110,12 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ item->setParentItem(parent); item->stackBefore(popup->popupItem()); item->setZ(popup->z()); + if (popup->isModal() && !qobject_cast<QQuickDrawer *>(popup)) { + // TODO: switch to QStyleHints::useHoverEffects in Qt 5.8 + item->setAcceptHoverEvents(true); + // item->setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects()); + // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, item, &QQuickItem::setAcceptHoverEvents); + } component->completeCreate(); } return item; @@ -139,6 +134,7 @@ void QQuickOverlayPrivate::destroyOverlay(QQuickPopup *popup) { QQuickPopupPrivate *p = QQuickPopupPrivate::get(popup); if (p->dimmer) { + p->dimmer->setParentItem(nullptr); p->dimmer->deleteLater(); p->dimmer = nullptr; } @@ -154,6 +150,22 @@ void QQuickOverlayPrivate::resizeOverlay(QQuickPopup *popup) } } +QVector<QQuickPopup *> QQuickOverlayPrivate::stackingOrderPopups() const +{ + const QList<QQuickItem *> children = paintOrderChildItems(); + + QVector<QQuickPopup *> popups; + popups.reserve(children.count()); + + for (auto it = children.crbegin(), end = children.crend(); it != end; ++it) { + QQuickPopup *popup = qobject_cast<QQuickPopup *>((*it)->parent()); + if (popup) + popups += popup; + } + + return popups; +} + QQuickOverlayPrivate::QQuickOverlayPrivate() : modal(nullptr), modeless(nullptr), @@ -218,33 +230,32 @@ void QQuickOverlay::itemChange(ItemChange change, const ItemChangeData &data) if (change == ItemChildAddedChange) { d->popups.append(popup); + if (popup->dim()) + d->createOverlay(popup); QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(popup); if (drawer) { d->drawers.append(drawer); - d->createOverlay(drawer); } else { if (popup->isModal()) ++d->modalPopups; QObjectPrivate::connect(popup, &QQuickPopup::aboutToShow, d, &QQuickOverlayPrivate::popupAboutToShow); QObjectPrivate::connect(popup, &QQuickPopup::aboutToHide, d, &QQuickOverlayPrivate::popupAboutToHide); - QObjectPrivate::connect(popup, &QQuickPopup::closed, d, &QQuickOverlayPrivate::popupClosed); } } else if (change == ItemChildRemovedChange) { d->popups.removeOne(popup); + d->destroyOverlay(popup); QQuickDrawer *drawer = qobject_cast<QQuickDrawer *>(popup); if (drawer) { d->drawers.removeOne(drawer); - d->destroyOverlay(drawer); } else { if (popup->isModal()) --d->modalPopups; QObjectPrivate::disconnect(popup, &QQuickPopup::aboutToShow, d, &QQuickOverlayPrivate::popupAboutToShow); QObjectPrivate::disconnect(popup, &QQuickPopup::aboutToHide, d, &QQuickOverlayPrivate::popupAboutToHide); - QObjectPrivate::disconnect(popup, &QQuickPopup::closed, d, &QQuickOverlayPrivate::popupClosed); } } } @@ -261,22 +272,25 @@ bool QQuickOverlay::event(QEvent *event) { Q_D(QQuickOverlay); switch (event->type()) { - case QEvent::MouseButtonPress: + case QEvent::MouseButtonPress: { emit pressed(); - for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) { - if ((*it)->overlayEvent(this, event)) { - d->mouseGrabberPopup = *it; + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->overlayEvent(this, event)) { + d->mouseGrabberPopup = popup; return true; } } break; + } case QEvent::MouseMove: if (d->mouseGrabberPopup) { if (d->mouseGrabberPopup->overlayEvent(this, event)) return true; } else { - for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) { - if ((*it)->overlayEvent(this, event)) + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->overlayEvent(this, event)) return true; } } @@ -289,8 +303,9 @@ bool QQuickOverlay::event(QEvent *event) if (grabber->overlayEvent(this, event)) return true; } else { - for (auto it = d->popups.crbegin(), end = d->popups.crend(); it != end; ++it) { - if ((*it)->overlayEvent(this, event)) + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->overlayEvent(this, event)) return true; } } @@ -313,14 +328,12 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) while (item->parentItem() != this) item = item->parentItem(); - const QList<QQuickItem *> sortedChildren = d->paintOrderChildItems(); - for (auto it = sortedChildren.rbegin(), end = sortedChildren.rend(); it != end; ++it) { - QQuickItem *popupItem = *it; - if (popupItem == item) + const auto popups = d->stackingOrderPopups(); + for (QQuickPopup *popup : popups) { + if (popup->popupItem() == item) break; - QQuickPopup *popup = qobject_cast<QQuickPopup *>(popupItem->parent()); - if (popup && popup->overlayEvent(item, event)) + if (popup->overlayEvent(item, event)) return true; } diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index 5c415fbb..a5cc09a1 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -364,6 +364,11 @@ QQuickPopupItem::QQuickPopupItem(QQuickPopup *popup) : setVisible(false); setFlag(ItemIsFocusScope); setAcceptedMouseButtons(Qt::AllButtons); + + // TODO: switch to QStyleHints::useHoverEffects in Qt 5.8 + setAcceptHoverEvents(true); + // setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects()); + // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, this, &QQuickItem::setAcceptHoverEvents); } bool QQuickPopupItem::childMouseEventFilter(QQuickItem *child, QEvent *event) diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml index 6217bb1d..7933bd9a 100644 --- a/tests/auto/controls/data/tst_popup.qml +++ b/tests/auto/controls/data/tst_popup.qml @@ -1068,7 +1068,9 @@ TestCase { window.requestActivate() tryCompare(window, "active", true) - compare(window.overlay.children.length, 6) // 3 drawers + 3 overlays + + var countBefore = window.overlay.children.length + compare(countBefore, 6) // 3 drawers + 3 overlays var firstOverlay = findOverlay(window, window.firstDrawer) verify(firstOverlay) @@ -1122,6 +1124,7 @@ TestCase { compare(modalOverlay.z, window.modalPopup.z) compare(window.modalPopup.visible, true) tryCompare(modalOverlay, "opacity", 1.0) + compare(window.overlay.children.length, countBefore + 2) // 1 popup + 1 overlay var modelessOverlay = findOverlay(window, window.modelessPopup) verify(!modelessOverlay) @@ -1131,23 +1134,23 @@ TestCase { compare(modelessOverlay.z, window.modelessPopup.z) compare(window.modelessPopup.visible, true) tryCompare(modelessOverlay, "opacity", 1.0) + compare(window.overlay.children.length, countBefore + 4) // 2 popups + 2 overlays window.modelessPopup.close() - tryCompare(modelessOverlay, "opacity", 0.0) tryCompare(window.modelessPopup, "visible", false) modelessOverlay = findOverlay(window, window.modelessPopup) verify(!modelessOverlay) + compare(window.overlay.children.length, countBefore + 2) // 1 popup + 1 overlay compare(window.modalPopup.visible, true) compare(modalOverlay.opacity, 1.0) window.modalPopup.close() - tryCompare(modalOverlay, "opacity", 0.0) tryCompare(window.modalPopup, "visible", false) modalOverlay = findOverlay(window, window.modalPopup) verify(!modalOverlay) + compare(window.overlay.children.length, countBefore) - var countBefore = window.overlay.children.length window.plainPopup.open() tryCompare(window.plainPopup, "visible", true) compare(window.overlay.children.length, countBefore + 1) // only popup added, no overlays involved diff --git a/tests/auto/drawer/data/hover.qml b/tests/auto/drawer/data/hover.qml new file mode 100644 index 00000000..5ac41457 --- /dev/null +++ b/tests/auto/drawer/data/hover.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + width: 400 + height: 400 + + property alias drawer: drawer + property alias backgroundButton: backgroundButton + property alias drawerButton: drawerButton + + Button { + id: backgroundButton + text: "Background" + anchors.fill: parent + } + + Drawer { + id: drawer + width: 100 + height: 400 + topPadding: 2 + leftPadding: 2 + rightPadding: 2 + bottomPadding: 2 + + contentItem: Button { + id: drawerButton + text: "Drawer" + } + } +} diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 062b430a..0507d01e 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -43,6 +43,7 @@ #include <QtGui/qguiapplication.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickdrawer_p.h> +#include <QtQuickTemplates2/private/qquickbutton_p.h> using namespace QQuickVisualTestUtil; @@ -58,6 +59,9 @@ private slots: void dragMargin(); void reposition(); + + void hover_data(); + void hover(); }; void tst_Drawer::position_data() @@ -175,6 +179,66 @@ void tst_Drawer::reposition() QTRY_COMPARE(drawer->popupItem()->x(), static_cast<qreal>(window->width())); } +void tst_Drawer::hover_data() +{ + QTest::addColumn<bool>("modal"); + + QTest::newRow("modal") << true; + QTest::newRow("modeless") << false; +} + +void tst_Drawer::hover() +{ + QFETCH(bool, modal); + + QQuickApplicationHelper helper(this, QStringLiteral("hover.qml")); + QQuickApplicationWindow *window = helper.window; + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickDrawer *drawer = helper.window->property("drawer").value<QQuickDrawer*>(); + QVERIFY(drawer); + drawer->setModal(modal); + + QQuickButton *backgroundButton = helper.window->property("backgroundButton").value<QQuickButton*>(); + QVERIFY(backgroundButton); + backgroundButton->setHoverEnabled(true); + + QQuickButton *drawerButton = helper.window->property("drawerButton").value<QQuickButton*>(); + QVERIFY(drawerButton); + drawerButton->setHoverEnabled(true); + + QSignalSpy openedSpy(drawer, SIGNAL(opened())); + QVERIFY(openedSpy.isValid()); + drawer->open(); + QVERIFY(openedSpy.count() == 1 || openedSpy.wait()); + + // hover the background button outside the drawer + QTest::mouseMove(window, QPoint(window->width() - 1, window->height() - 1)); + QCOMPARE(backgroundButton->isHovered(), !modal); + QVERIFY(!drawerButton->isHovered()); + + // hover the drawer background + QTest::mouseMove(window, QPoint(1, 1)); + QVERIFY(!backgroundButton->isHovered()); + QVERIFY(!drawerButton->isHovered()); + + // hover the button in a drawer + QTest::mouseMove(window, QPoint(2, 2)); + QVERIFY(!backgroundButton->isHovered()); + QVERIFY(drawerButton->isHovered()); + + QSignalSpy closedSpy(drawer, SIGNAL(closed())); + QVERIFY(closedSpy.isValid()); + drawer->close(); + QVERIFY(closedSpy.count() == 1 || closedSpy.wait()); + + // hover the background button after closing the drawer + QTest::mouseMove(window, QPoint(window->width() / 2, window->height() / 2)); + QVERIFY(backgroundButton->isHovered()); +} + QTEST_MAIN(tst_Drawer) #include "tst_drawer.moc" diff --git a/tests/auto/popup/data/applicationwindow.qml b/tests/auto/popup/data/applicationwindow.qml index 7af71495..9b85eb85 100644 --- a/tests/auto/popup/data/applicationwindow.qml +++ b/tests/auto/popup/data/applicationwindow.qml @@ -46,6 +46,7 @@ ApplicationWindow { height: 400 property alias popup: popup + property alias popup2: popup2 property alias button: button Button { @@ -69,4 +70,14 @@ ApplicationWindow { } } } + + Popup { + id: popup2 + y: popup.y + z: 1 + contentItem: Text { + text: "Popup2" + font.pixelSize: 36 + } + } } diff --git a/tests/auto/popup/data/hover.qml b/tests/auto/popup/data/hover.qml new file mode 100644 index 00000000..044d983c --- /dev/null +++ b/tests/auto/popup/data/hover.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + width: 400 + height: 400 + + property alias popup: popup + property alias parentButton: parentButton + property alias childButton: childButton + + Button { + id: parentButton + text: "Parent" + anchors.fill: parent + + Popup { + id: popup + x: 1 + y: 1 + padding: 1 + + Button { + id: childButton + text: "Child" + } + } + } +} diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp index 3da32407..7a8a6557 100644 --- a/tests/auto/popup/tst_popup.cpp +++ b/tests/auto/popup/tst_popup.cpp @@ -53,11 +53,14 @@ class tst_popup : public QQmlDataTest private slots: void visible(); void overlay(); + void zOrder(); void windowChange(); void closePolicy_data(); void closePolicy(); void activeFocusOnClose1(); void activeFocusOnClose2(); + void hover_data(); + void hover(); }; void tst_popup::visible() @@ -134,6 +137,7 @@ void tst_popup::overlay() QVERIFY(!overlay->isVisible()); popup->setModal(true); + popup->setClosePolicy(QQuickPopup::CloseOnReleaseOutside); popup->open(); QVERIFY(popup->isVisible()); @@ -148,7 +152,40 @@ void tst_popup::overlay() QCOMPARE(overlayReleasedSignal.count(), 1); QVERIFY(!popup->isVisible()); - QVERIFY(overlay->isVisible()); + QVERIFY(!overlay->isVisible()); +} + +void tst_popup::zOrder() +{ + QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml")); + + QQuickApplicationWindow *window = helper.window; + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>(); + QVERIFY(popup); + popup->setModal(true); + + QQuickPopup *popup2 = helper.window->property("popup2").value<QQuickPopup*>(); + QVERIFY(popup2); + popup2->setModal(true); + + // show popups in reverse order. popup2 has higher z-order so it appears + // on top and must be closed first, even if the other popup was opened last + popup2->open(); + popup->open(); + QVERIFY(popup2->isVisible()); + QVERIFY(popup->isVisible()); + + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + QVERIFY(!popup2->isVisible()); + QVERIFY(popup->isVisible()); + + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + QVERIFY(!popup2->isVisible()); + QVERIFY(!popup->isVisible()); } void tst_popup::windowChange() @@ -329,6 +366,66 @@ void tst_popup::activeFocusOnClose2() QVERIFY(popup1->hasActiveFocus()); } +void tst_popup::hover_data() +{ + QTest::addColumn<bool>("modal"); + + QTest::newRow("modal") << true; + QTest::newRow("modeless") << false; +} + +void tst_popup::hover() +{ + QFETCH(bool, modal); + + QQuickApplicationHelper helper(this, QStringLiteral("hover.qml")); + QQuickApplicationWindow *window = helper.window; + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>(); + QVERIFY(popup); + popup->setModal(modal); + + QQuickButton *parentButton = helper.window->property("parentButton").value<QQuickButton*>(); + QVERIFY(parentButton); + parentButton->setHoverEnabled(true); + + QQuickButton *childButton = helper.window->property("childButton").value<QQuickButton*>(); + QVERIFY(childButton); + childButton->setHoverEnabled(true); + + QSignalSpy openedSpy(popup, SIGNAL(opened())); + QVERIFY(openedSpy.isValid()); + popup->open(); + QVERIFY(openedSpy.count() == 1 || openedSpy.wait()); + + // hover the parent button outside the popup + QTest::mouseMove(window, QPoint(window->width() - 1, window->height() - 1)); + QCOMPARE(parentButton->isHovered(), !modal); + QVERIFY(!childButton->isHovered()); + + // hover the popup background + QTest::mouseMove(window, QPoint(1, 1)); + QVERIFY(!parentButton->isHovered()); + QVERIFY(!childButton->isHovered()); + + // hover the child button in a popup + QTest::mouseMove(window, QPoint(2, 2)); + QVERIFY(!parentButton->isHovered()); + QVERIFY(childButton->isHovered()); + + QSignalSpy closedSpy(popup, SIGNAL(closed())); + QVERIFY(closedSpy.isValid()); + popup->close(); + QVERIFY(closedSpy.count() == 1 || closedSpy.wait()); + + // hover the parent button after closing the popup + QTest::mouseMove(window, QPoint(window->width() / 2, window->height() / 2)); + QVERIFY(parentButton->isHovered()); +} + QTEST_MAIN(tst_popup) #include "tst_popup.moc" diff --git a/tests/manual/testbench/main.qml b/tests/manual/testbench/main.qml index 11bcb84d..b037bc3d 100644 --- a/tests/manual/testbench/main.qml +++ b/tests/manual/testbench/main.qml @@ -48,11 +48,14 @@ import QtQuick.Controls.Universal 2.1 ApplicationWindow { id: window visible: true - x: Screen.width / 2 - width / 2 - y: Screen.height / 2 - height / 2 width: 750 height: 1000 + Component.onCompleted: { + x = Screen.width / 2 - width / 2 + y = Screen.height / 2 - height / 2 + } + Material.theme: themeSwitch.checked ? Material.Dark : Material.Light Universal.theme: themeSwitch.checked ? Universal.Dark : Universal.Light |