aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2019-10-08 17:50:25 +0800
committerWang Chuan <ouchuanm@outlook.com>2019-10-24 16:00:56 +0800
commit66de71b26a6c3b5be308c1a92287b6490164ae72 (patch)
treeac6121eb826904815d4ec71b17b1cb8be151bb2a /tests
parent78569ded1a6b9b660416bfc1208efecdfb1bdd51 (diff)
QQuickMenuBar: let MenuBarItem lose highlight when Menu is dismissed
When adding new MenuBarItem to MenuBar, MenuBar will first check the Menu pointer in MenuBarItem and then connect the Menu's signal [aboutToHide] to MenuBar's slot [onMenuAboutToHide] to unhighlight the MenuBarItem. In case of adding dynamic Menu, this operation will be performed before setting new Menu to MenuBarItem. So the Menu pointer in MenuBarItem is null, and the connection will not be performed. [ChangeLog][Controls][QQuickMenuBar] Fixed issue with dynamically menu bar items not losing their highlight when their menu was dismissed. Fixes: QTBUG-77306 Change-Id: Ibe987462505f65747b4290b3c206e9dfbcbbef57 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qquickmenubar/data/checkHighlightWhenDismissed.qml93
-rw-r--r--tests/auto/qquickmenubar/tst_qquickmenubar.cpp58
2 files changed, 151 insertions, 0 deletions
diff --git a/tests/auto/qquickmenubar/data/checkHighlightWhenDismissed.qml b/tests/auto/qquickmenubar/data/checkHighlightWhenDismissed.qml
new file mode 100644
index 00000000..072fa6b1
--- /dev/null
+++ b/tests/auto/qquickmenubar/data/checkHighlightWhenDismissed.qml
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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.13
+import QtQuick.Controls 2.13
+
+ApplicationWindow {
+ width: 300
+ height: 300
+ visible: true
+ MenuBar {
+ id: mb
+ objectName: "menuBar"
+ width: parent.width
+ Menu {
+ title: "StaticMenu"
+ MenuItem {
+ text: "Cut"
+ }
+ MenuItem {
+ text: "Copy"
+ }
+ MenuItem {
+ text: "Paste"
+ }
+ }
+ }
+ Component {
+ id: cmp
+ Menu {
+ title: "DynamicMenu"
+ MenuItem {
+ text: "Cut"
+ }
+ MenuItem {
+ text: "Copy"
+ }
+ MenuItem {
+ text: "Paste"
+ }
+ }
+ }
+ Component.onCompleted: {
+ mb.addMenu(cmp.createObject(mb))
+ }
+}
diff --git a/tests/auto/qquickmenubar/tst_qquickmenubar.cpp b/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
index 9a22d26f..2fb1a02b 100644
--- a/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
+++ b/tests/auto/qquickmenubar/tst_qquickmenubar.cpp
@@ -60,6 +60,7 @@ private slots:
void keys();
void mnemonics();
void addRemove();
+ void checkHighlightWhenMenuDismissed();
};
void tst_qquickmenubar::delegate()
@@ -564,6 +565,63 @@ void tst_qquickmenubar::addRemove()
QVERIFY(menuBarItem1.isNull());
}
+void tst_qquickmenubar::checkHighlightWhenMenuDismissed()
+{
+ if ((QGuiApplication::platformName() == QLatin1String("offscreen"))
+ || (QGuiApplication::platformName() == QLatin1String("minimal")))
+ QSKIP("Mouse highlight not functional on offscreen/minimal platforms");
+
+ QQmlApplicationEngine engine(testFileUrl("checkHighlightWhenDismissed.qml"));
+ QScopedPointer<QQuickApplicationWindow> window(qobject_cast<QQuickApplicationWindow *>(engine.rootObjects().value(0)));
+ QVERIFY(window);
+
+ centerOnScreen(window.data());
+ moveMouseAway(window.data());
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
+ QQuickMenuBar *menuBar = window->findChild<QQuickMenuBar *>("menuBar");
+ QVERIFY(menuBar);
+
+ QQuickMenu *staticMenu = menuBar->menuAt(0);
+ QQuickMenu *dynamicMenu = menuBar->menuAt(1);
+ QVERIFY(staticMenu && dynamicMenu);
+ QQuickMenuBarItem *staticMenuBarItem = qobject_cast<QQuickMenuBarItem *>(staticMenu->parentItem());
+ QQuickMenuBarItem *dynamicMenuBarItem = qobject_cast<QQuickMenuBarItem *>(dynamicMenu->parentItem());
+ QVERIFY(staticMenuBarItem && dynamicMenuBarItem);
+
+ // highlight the static MenuBarItem and open the menu
+ QTest::mouseMove(window.data(), staticMenuBarItem->mapToScene(
+ QPointF(staticMenuBarItem->width() / 2, staticMenuBarItem->height() / 2)).toPoint());
+ QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier,
+ staticMenuBarItem->mapToScene(QPointF(staticMenuBarItem->width() / 2, staticMenuBarItem->height() / 2)).toPoint());
+ QCOMPARE(staticMenuBarItem->isHighlighted(), true);
+ QCOMPARE(staticMenu->isVisible(), true);
+ QTRY_COMPARE(staticMenu->isOpened(), true);
+
+ // click a menu item to dismiss the menu and unhighlight the static MenuBarItem
+ QQuickMenuItem *menuItem = qobject_cast<QQuickMenuItem *>(staticMenu->itemAt(0));
+ QVERIFY(menuItem);
+ QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier,
+ menuItem->mapToScene(QPointF(menuItem->width() / 2, menuItem->height() / 2)).toPoint());
+ QCOMPARE(staticMenuBarItem->isHighlighted(), false);
+
+ // highlight the dynamic MenuBarItem and open the menu
+ QTest::mouseMove(window.data(), dynamicMenuBarItem->mapToScene(
+ QPointF(dynamicMenuBarItem->width() / 2, dynamicMenuBarItem->height() / 2)).toPoint());
+ QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier,
+ dynamicMenuBarItem->mapToScene(QPointF(dynamicMenuBarItem->width() / 2, dynamicMenuBarItem->height() / 2)).toPoint());
+ QCOMPARE(dynamicMenuBarItem->isHighlighted(), true);
+ QCOMPARE(dynamicMenu->isVisible(), true);
+ QTRY_COMPARE(dynamicMenu->isOpened(), true);
+
+ // click a menu item to dismiss the menu and unhighlight the dynamic MenuBarItem
+ menuItem = qobject_cast<QQuickMenuItem *>(dynamicMenu->itemAt(0));
+ QVERIFY(menuItem);
+ QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier,
+ menuItem->mapToScene(QPointF(menuItem->width() / 2, menuItem->height() / 2)).toPoint());
+ QCOMPARE(dynamicMenuBarItem->isHighlighted(), false);
+}
+
QTEST_QUICKCONTROLS_MAIN(tst_qquickmenubar)
#include "tst_qquickmenubar.moc"