diff options
author | Filippo Cucchetto <filippocucchetto@gmail.com> | 2015-11-24 22:35:51 +0100 |
---|---|---|
committer | Filippo Cucchetto <filippocucchetto@gmail.com> | 2015-11-26 23:03:20 +0000 |
commit | 812f5779855d94cbe779f77003cc14935e02ef63 (patch) | |
tree | 931a601a7deb5125ef3d2ee8be286f6248f4f05f | |
parent | 2407d7ede10547025af05d875f33f4580cdbb565 (diff) | |
download | qtquickcontrols-812f5779855d94cbe779f77003cc14935e02ef63.tar.gz |
Menubar popups should handle only release events of a previous press event
When a popup is brought up by a press event for a menu
inside the menubar it should not handle the relative
next release event if it falls outside the popup.
Before forwarding the release event we first check if a
previous press event was seen, if not we simply discard
the event.
Task-number: QTBUG-47295
Task-number: QTBUG-45117
Change-Id: I632fab0a3abfdfc9872f85f99f9d7f50d41526cc
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r-- | src/controls/qquickpopupwindow.cpp | 15 | ||||
-rw-r--r-- | src/controls/qquickpopupwindow_p.h | 1 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_menubar.qml | 51 |
3 files changed, 63 insertions, 4 deletions
diff --git a/src/controls/qquickpopupwindow.cpp b/src/controls/qquickpopupwindow.cpp index 59cfe22b..cfab5bd5 100644 --- a/src/controls/qquickpopupwindow.cpp +++ b/src/controls/qquickpopupwindow.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE QQuickPopupWindow::QQuickPopupWindow() : QQuickWindow(), m_parentItem(0), m_contentItem(0), m_mouseMoved(false), m_needsActivatedEvent(true), - m_dismissed(false) + m_dismissed(false), m_pressed(false) { setFlags(Qt::Popup); connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), @@ -146,17 +146,22 @@ void QQuickPopupWindow::mouseMoveEvent(QMouseEvent *e) { QRect rect = QRect(QPoint(), size()); m_mouseMoved = true; - if (rect.contains(e->pos())) + if (rect.contains(e->pos())) { + if (e->buttons() != Qt::NoButton) + m_pressed = true; QQuickWindow::mouseMoveEvent(e); + } else forwardEventToTransientParent(e); } void QQuickPopupWindow::mousePressEvent(QMouseEvent *e) { + m_pressed = true; QRect rect = QRect(QPoint(), size()); - if (rect.contains(e->pos())) + if (rect.contains(e->pos())) { QQuickWindow::mousePressEvent(e); + } else forwardEventToTransientParent(e); } @@ -173,8 +178,10 @@ void QQuickPopupWindow::mouseReleaseEvent(QMouseEvent *e) } m_mouseMoved = true; // Initial mouse release counts as move. } else { - forwardEventToTransientParent(e); + if (m_pressed) + forwardEventToTransientParent(e); } + m_pressed = false; } void QQuickPopupWindow::forwardEventToTransientParent(QMouseEvent *e) diff --git a/src/controls/qquickpopupwindow_p.h b/src/controls/qquickpopupwindow_p.h index 617df53d..830ba382 100644 --- a/src/controls/qquickpopupwindow_p.h +++ b/src/controls/qquickpopupwindow_p.h @@ -88,6 +88,7 @@ private: bool m_mouseMoved; bool m_needsActivatedEvent; bool m_dismissed; + bool m_pressed; }; QT_END_NAMESPACE diff --git a/tests/auto/controls/data/tst_menubar.qml b/tests/auto/controls/data/tst_menubar.qml index bf6371e0..44238e21 100644 --- a/tests/auto/controls/data/tst_menubar.qml +++ b/tests/auto/controls/data/tst_menubar.qml @@ -39,6 +39,7 @@ ****************************************************************************/ import QtQuick 2.2 +import QtQuick.Controls 1.4 import QtTest 1.0 TestCase { @@ -48,8 +49,58 @@ TestCase { width:400 height:400 + Component { + id: windowComponent + ApplicationWindow { + width: 300; height: 300 + visible: true + menuBar: MenuBar { + Menu { + title: "&File"; objectName: "fileMenu" + Menu { + title: "&Recent Files"; objectName: "recentFilesSubMenu" + MenuItem { text: "RecentFile1"; objectName: "recentFile1MenuItem" } + MenuItem { text: "RecentFile2"; objectName: "recentFile2MenuItem" } + } + MenuItem { text: "&Save"; objectName: "saveMenuItem" } + MenuItem { text: "&Load"; objectName: "loadMenuItem" } + MenuItem { text: "&Exit"; objectName: "exitMenuItem" } + } + Menu { + title: "&Edit"; objectName: "editMenu" + Menu { + title: "&Advanced"; objectName: "advancedSubMenu" + MenuItem { text: "advancedOption1"; objectName: "advancedOption1MenuItem" } + } + MenuItem { text: "&Preferences"; objectName: "preferencesMenuItem" } + } + } + } + } + function test_createMenuBar() { var menuBar = Qt.createQmlObject('import QtQuick.Controls 1.2; MenuBar {}', testCase, ''); menuBar.destroy() } + + + function test_qtBug47295() + { + if (Qt.platform.os === "osx") + skip("MenuBar cannot be reliably tested on OS X") + + var window = windowComponent.createObject() + waitForRendering(window.contentItem) + var fileMenu = findChild(window, "fileMenu") + verify(fileMenu) + tryCompare(fileMenu, "__popupVisible", false) + mousePress(fileMenu.__visualItem) + wait(200); + tryCompare(fileMenu, "__popupVisible", true) + mouseMove(fileMenu.__contentItem, 0, -10) + wait(200) + mouseRelease(fileMenu.__contentItem, 0, -10) + tryCompare(fileMenu, "__popupVisible", true) + wait(200) + } } |