From af914694d81317b4a7bf0804d9d34a1f3bf2cf48 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 10 Nov 2011 13:07:01 +0100 Subject: QPlatformDialogHelper: Split class hierarchy, decouple from Dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduce hierarchy of QPlatformDialogHelper-derived classes for font, color and file dialogs. - Start reducing dependencies on QDialog: * Remove QDialog-specifics from interface, introduce enumeration for DialogCode * Make the helpers Q_OBJECTS to be able to add the signals passed on to the QDialogs * Remove QDialogPrivate pointer - Split setVisible_sys() in show_sys() (factory method for native dialogs) and hide_sys(). Pass parent window to show_sys(), removing the necessity to query the QDialog for it - Introduce a styleHint() similar to QGuiApplication's for platform-specific - Fix compile in cocoa/windows, reduce depency on QDialog (-private) classes. Change-Id: Ic1cb715e1edf767f2cb18b9780341d189339ef1d Reviewed-by: Morten Johan Sørvig --- src/widgets/dialogs/qdialog.cpp | 44 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'src/widgets/dialogs/qdialog.cpp') diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index 09c0127852..a0b0cdc564 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -64,16 +64,42 @@ QPlatformDialogHelper *QDialogPrivate::platformHelper() const // Delayed creation of the platform, ensuring that // that qobject_cast<> on the dialog works in the plugin. if (!m_platformHelperCreated) { + QDialogPrivate *ncThis = const_cast(this); m_platformHelperCreated = true; - QDialog *dialog = const_cast(q_func()); m_platformHelper = QGuiApplicationPrivate::platformIntegration() - ->createPlatformDialogHelper(dialog); + ->createPlatformDialogHelper(ncThis->q_func()); if (m_platformHelper) - m_platformHelper->d_ptr = const_cast(this); + ncThis->initHelper(m_platformHelper); } return m_platformHelper; } +QWindow *QDialogPrivate::parentWindow() const +{ + if (const QWidget *parent = q_func()->nativeParentWidget()) + return parent->windowHandle(); + return 0; +} + +bool QDialogPrivate::setNativeDialogVisible(bool visible) +{ + if (QPlatformDialogHelper *helper = platformHelper()) { + if (visible) { + nativeDialogInUse = helper->show_sys(parentWindow()); + } else { + helper->hide_sys(); + } + } + return nativeDialogInUse; +} + +QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const +{ + if (const QPlatformDialogHelper *helper = platformHelper()) + return helper->styleHint(hint); + return QPlatformDialogHelper::defaultStyleHint(hint); +} + /*! \class QDialog \brief The QDialog class is the base class of dialog windows. @@ -705,15 +731,9 @@ void QDialog::setVisible(bool visible) if (d->eventLoop) d->eventLoop->exit(); } -#ifdef Q_WS_WIN - if (d->mainDef && isActiveWindow()) { - BOOL snapToDefault = false; - if (SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, &snapToDefault, 0)) { - if (snapToDefault) - QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center())); - } - } -#endif + if (d->mainDef && isActiveWindow() + && d->styleHint(QPlatformDialogHelper::SnapToDefaultButton).toBool()) + QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center())); } /*!\reimp */ -- cgit v1.2.3