diff options
-rw-r--r-- | src/quicktemplates2/qquickoverlay.cpp | 17 | ||||
-rw-r--r-- | src/quicktemplates2/qquickoverlay_p_p.h | 1 | ||||
-rw-r--r-- | tests/auto/popup/data/grabber.qml | 70 | ||||
-rw-r--r-- | tests/auto/popup/tst_popup.cpp | 52 |
4 files changed, 135 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index ba0dfc46..4a95244f 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -193,6 +193,13 @@ void QQuickOverlayPrivate::removePopup(QQuickPopup *popup) q->setVisible(!allDrawers.isEmpty() || !q->childItems().isEmpty()); } +void QQuickOverlayPrivate::setMouseGrabberPopup(QQuickPopup *popup) +{ + if (popup && !popup->isVisible()) + popup = nullptr; + mouseGrabberPopup = popup; +} + QQuickOverlay::QQuickOverlay(QQuickItem *parent) : QQuickItem(*(new QQuickOverlayPrivate), parent) { @@ -326,7 +333,7 @@ void QQuickOverlay::mousePressEvent(QMouseEvent *event) for (QQuickDrawer *drawer : drawers) { QQuickDrawerPrivate *p = QQuickDrawerPrivate::get(drawer); if (p->startDrag(window(), event)) { - d->mouseGrabberPopup = drawer; + d->setMouseGrabberPopup(drawer); return; } } @@ -336,7 +343,7 @@ void QQuickOverlay::mousePressEvent(QMouseEvent *event) const auto popups = d->stackingOrderPopups(); for (QQuickPopup *popup : popups) { if (popup->overlayEvent(this, event)) { - d->mouseGrabberPopup = popup; + d->setMouseGrabberPopup(popup); return; } } @@ -359,7 +366,7 @@ void QQuickOverlay::mouseReleaseEvent(QMouseEvent *event) if (d->mouseGrabberPopup) { d->mouseGrabberPopup->overlayEvent(this, event); - d->mouseGrabberPopup = nullptr; + d->setMouseGrabberPopup(nullptr); } else { const auto popups = d->stackingOrderPopups(); for (QQuickPopup *popup : popups) { @@ -405,7 +412,7 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) case QEvent::MouseButtonPress: emit pressed(); if (popup->overlayEvent(item, event)) { - d->mouseGrabberPopup = popup; + d->setMouseGrabberPopup(popup); return true; } break; @@ -413,7 +420,7 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) return popup->overlayEvent(item, event); case QEvent::MouseButtonRelease: emit released(); - d->mouseGrabberPopup = nullptr; + d->setMouseGrabberPopup(nullptr); return popup->overlayEvent(item, event); default: break; diff --git a/src/quicktemplates2/qquickoverlay_p_p.h b/src/quicktemplates2/qquickoverlay_p_p.h index 6201908e..6e72b39a 100644 --- a/src/quicktemplates2/qquickoverlay_p_p.h +++ b/src/quicktemplates2/qquickoverlay_p_p.h @@ -72,6 +72,7 @@ public: void addPopup(QQuickPopup *popup); void removePopup(QQuickPopup *popup); + void setMouseGrabberPopup(QQuickPopup *popup); void popupAboutToShow(); void popupAboutToHide(); diff --git a/tests/auto/popup/data/grabber.qml b/tests/auto/popup/data/grabber.qml new file mode 100644 index 00000000..6cd5f765 --- /dev/null +++ b/tests/auto/popup/data/grabber.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 menu: menu + property alias popup: popup + property alias combo: combo.popup + + Menu { + id: menu + MenuItem { + onTriggered: popup.open() + } + } + + Popup { + id: popup + modal: true + width: 200 + height: 200 + + ComboBox { + id: combo + model: 3 + } + } +} diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp index af6ccf34..fbd0605b 100644 --- a/tests/auto/popup/tst_popup.cpp +++ b/tests/auto/popup/tst_popup.cpp @@ -71,6 +71,7 @@ private slots: void wheel(); void parentDestroyed(); void nested(); + void grabber(); }; void tst_popup::visible_data() @@ -669,6 +670,57 @@ void tst_popup::nested() QCOMPARE(modalPopup->isVisible(), true); } +// QTBUG-56697 +void tst_popup::grabber() +{ + QQuickApplicationHelper helper(this, QStringLiteral("grabber.qml")); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickPopup *menu = window->property("menu").value<QQuickPopup *>(); + QVERIFY(menu); + + QQuickPopup *popup = window->property("popup").value<QQuickPopup *>(); + QVERIFY(popup); + + QQuickPopup *combo = window->property("combo").value<QQuickPopup *>(); + QVERIFY(combo); + + menu->open(); + QCOMPARE(menu->isVisible(), true); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); + + // click a menu item to open the popup + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(menu->width() / 2, menu->height() / 2)); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), true); + QCOMPARE(combo->isVisible(), false); + + combo->open(); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), true); + QCOMPARE(combo->isVisible(), true); + + // click outside to close both the combo popup and the parent popup + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() - 1)); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); + + menu->open(); + QCOMPARE(menu->isVisible(), true); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); + + // click outside the menu to close it (QTBUG-56697) + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() - 1)); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); +} + QTEST_MAIN(tst_popup) #include "tst_popup.moc" |