From 779195343f14fcbc6c12bee0948f6a20ecfec852 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 22 Jan 2013 10:58:25 +0100 Subject: Windows: Fix modal dialogs for declarative. Make it possible to show a modal dialog by just calling show(). Start an idle timer, which will start the dialog thread. This timer is stopped in exec(). Change-Id: I8f7352bf577b09a19be7df4484e0077bb1aa46ab Reviewed-by: Joerg Bornemann --- .../platforms/windows/qwindowsdialoghelpers.cpp | 38 +++++++++++++++++++--- .../platforms/windows/qwindowsdialoghelpers.h | 4 +++ 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index b4699b6306..e9c0cccc14 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -450,7 +450,8 @@ protected: template QWindowsDialogHelperBase::QWindowsDialogHelperBase() : m_nativeDialog(0), - m_ownerWindow(0) + m_ownerWindow(0), + m_timerId(0) { } @@ -471,6 +472,12 @@ void QWindowsDialogHelperBase::deleteNativeDialog() m_nativeDialog = 0; } +template +void QWindowsDialogHelperBase::timerEvent(QTimerEvent *) +{ + startDialogThread(); +} + template QWindowsNativeDialogBase *QWindowsDialogHelperBase::ensureNativeDialog() { @@ -527,13 +534,35 @@ bool QWindowsDialogHelperBase::show(Qt::WindowFlags, return false; // Was it changed in-between? if (!ensureNativeDialog()) return false; - if (!modal) { // Modal dialogs are shown in separate slot. - QWindowsDialogThread *thread = new QWindowsDialogThread(this); - thread->start(); + // Start a background thread to show the dialog. For modal dialogs, + // a subsequent call to exec() may follow. So, start an idle timer + // which will start the dialog thread. If exec() is then called, the + // timer is stopped and dialog->exec() is called directly. + if (modal) { + m_timerId = this->startTimer(0); + } else { + startDialogThread(); } return true; } +template +void QWindowsDialogHelperBase::startDialogThread() +{ + QWindowsDialogThread *thread = new QWindowsDialogThread(this); + thread->start(); + stopTimer(); +} + +template +void QWindowsDialogHelperBase::stopTimer() +{ + if (m_timerId) { + this->killTimer(m_timerId); + m_timerId = 0; + } +} + template void QWindowsDialogHelperBase::hide() { @@ -547,6 +576,7 @@ void QWindowsDialogHelperBase::exec() { if (QWindowsContext::verboseDialogs) qDebug("%s" , __FUNCTION__); + stopTimer(); if (QWindowsNativeDialogBase *nd = nativeDialog()) { nd->exec(m_ownerWindow); deleteNativeDialog(); diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.h b/src/plugins/platforms/windows/qwindowsdialoghelpers.h index a46caf0e1e..7884f398f3 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.h +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.h @@ -81,13 +81,17 @@ protected: QWindowsNativeDialogBase *nativeDialog() const; inline bool hasNativeDialog() const { return m_nativeDialog; } void deleteNativeDialog(); + void timerEvent(QTimerEvent *); private: virtual QWindowsNativeDialogBase *createNativeDialog() = 0; inline QWindowsNativeDialogBase *ensureNativeDialog(); + inline void startDialogThread(); + inline void stopTimer(); QWindowsNativeDialogBase *m_nativeDialog; HWND m_ownerWindow; + int m_timerId; }; QT_END_NAMESPACE -- cgit v1.2.3