From a48508cd766b056d3cb5b6502cf269a8293bb5a5 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 30 Oct 2012 10:21:36 +0200 Subject: Send leave to most recently entered window when modal dialog is shown. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a modal dialog was shown as a response to button click, the button retained its hover highlight, because it didn't get leave event. Fixed by tracking the most recently entered window and sending a leave to it when modal dialog is shown that blocks it. Also modified tst_QGuiApplication::modalWindow() autotest to check for enters and leaves. Task-number: QTBUG-27644 Change-Id: I387647e18a762a39d523e3df31221b9583a39f9d Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 18 ++++++++++++++++++ src/gui/kernel/qguiapplication_p.h | 1 + src/gui/kernel/qwindow.cpp | 4 ++++ 3 files changed, 23 insertions(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 64d2f8001f..6e367ebfcf 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -105,6 +105,7 @@ QPointF QGuiApplicationPrivate::lastCursorPosition(0.0, 0.0); bool QGuiApplicationPrivate::tabletState = false; QWindow *QGuiApplicationPrivate::tabletPressTarget = 0; +QWindow *QGuiApplicationPrivate::currentMouseWindow = 0; QPlatformIntegration *QGuiApplicationPrivate::platform_integration = 0; QPlatformTheme *QGuiApplicationPrivate::platform_theme = 0; @@ -455,6 +456,19 @@ void QGuiApplicationPrivate::showModalWindow(QWindow *modal) { self->modalWindowList.prepend(modal); + // Send leave for currently entered window if it should be blocked + if (currentMouseWindow && (currentMouseWindow->windowType() & Qt::Popup) != Qt::Popup) { + bool shouldBeBlocked = self->isWindowBlocked(currentMouseWindow); + if (shouldBeBlocked) { + // Remove the new window from modalWindowList temporarily so leave can go through + self->modalWindowList.removeFirst(); + QEvent e(QEvent::Leave); + QGuiApplication::sendEvent(currentMouseWindow, &e); + currentMouseWindow = 0; + self->modalWindowList.prepend(modal); + } + } + QEvent e(QEvent::WindowBlocked); QWindowList windows = QGuiApplication::topLevelWindows(); for (int i = 0; i < windows.count(); ++i) { @@ -1410,6 +1424,8 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En return; } + currentMouseWindow = e->enter; + QEvent event(QEvent::Enter); QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event); } @@ -1423,6 +1439,8 @@ void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::Le return; } + currentMouseWindow = 0; + QEvent event(QEvent::Leave); QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event); } diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 44a9275688..c9eb672220 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -189,6 +189,7 @@ public: static QPointF lastCursorPosition; static bool tabletState; static QWindow *tabletPressTarget; + static QWindow *currentMouseWindow; #ifndef QT_NO_CLIPBOARD static QClipboard *qt_clipboard; diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 4f1610cb21..a17270912f 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -214,6 +214,8 @@ QWindow::~QWindow() { if (QGuiApplicationPrivate::focus_window == this) QGuiApplicationPrivate::focus_window = 0; + if (QGuiApplicationPrivate::currentMouseWindow == this) + QGuiApplicationPrivate::currentMouseWindow = 0; QGuiApplicationPrivate::window_list.removeAll(this); destroy(); } @@ -1445,6 +1447,8 @@ bool QWindow::close() if (QGuiApplicationPrivate::focus_window == this) QGuiApplicationPrivate::focus_window = 0; + if (QGuiApplicationPrivate::currentMouseWindow == this) + QGuiApplicationPrivate::currentMouseWindow = 0; QGuiApplicationPrivate::window_list.removeAll(this); destroy(); -- cgit v1.2.3