aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quicktemplates2/qquickdrawer.cpp6
-rw-r--r--src/quicktemplates2/qquickoverlay.cpp2
-rw-r--r--tests/auto/drawer/data/hover.qml72
-rw-r--r--tests/auto/drawer/tst_drawer.cpp64
4 files changed, 142 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickdrawer.cpp b/src/quicktemplates2/qquickdrawer.cpp
index c165b077..fe0a3c72 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 028fa7b1..2e19e02d 100644
--- a/src/quicktemplates2/qquickoverlay.cpp
+++ b/src/quicktemplates2/qquickoverlay.cpp
@@ -108,7 +108,7 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ
item->setParentItem(parent);
item->stackBefore(popup->popupItem());
item->setZ(popup->z());
- if (popup->isModal()) {
+ if (popup->isModal() && !qobject_cast<QQuickDrawer *>(popup)) {
// TODO: switch to QStyleHints::useHoverEffects in Qt 5.8
item->setAcceptHoverEvents(true);
// item->setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects());
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"