From 692a1babe53c342e9f5435517a1265765f77f676 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 26 Jan 2012 11:29:24 +0100 Subject: Decouple QPlatformTheme from QDialog. - Use an enumeration for the dialog type. - Implemented on Windows and Mac Reviewed-by: Morten Johan Sorvig Change-Id: I213748a08168efbabc2ac0106308e97ff19d19c0 Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qdialog.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/widgets/dialogs') diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index 66f7870ce1..92cec3ef85 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -39,8 +39,9 @@ ** ****************************************************************************/ -#include "qdialog.h" - +#include "qcolordialog.h" +#include "qfontdialog.h" +#include "qfiledialog.h" #include "qevent.h" #include "qdesktopwidget.h" @@ -59,22 +60,36 @@ QT_BEGIN_NAMESPACE +static inline int themeDialogType(const QDialog *dialog) +{ + if (qobject_cast(dialog)) + return QPlatformTheme::FileDialog; + if (qobject_cast(dialog)) + return QPlatformTheme::ColorDialog; + if (qobject_cast(dialog)) + return QPlatformTheme::FontDialog; + return -1; +} + 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; + QDialogPrivate *ncThis = const_cast(this); QDialog *dialog = ncThis->q_func(); - m_platformHelper = QGuiApplicationPrivate::platformTheme() - ->createPlatformDialogHelper(dialog); - if (m_platformHelper) { - QObject::connect(m_platformHelper, SIGNAL(accept()), dialog, SLOT(accept())); - QObject::connect(m_platformHelper, SIGNAL(reject()), dialog, SLOT(reject())); - QObject::connect(m_platformHelper, SIGNAL(launchNativeAppModalPanel()), - dialog, SLOT(_q_platformRunNativeAppModalPanel())); - ncThis->initHelper(m_platformHelper); + const int type = themeDialogType(dialog); + if (type >= 0) { + m_platformHelper = QGuiApplicationPrivate::platformTheme() + ->createPlatformDialogHelper(static_cast(type)); + if (m_platformHelper) { + QObject::connect(m_platformHelper, SIGNAL(accept()), dialog, SLOT(accept())); + QObject::connect(m_platformHelper, SIGNAL(reject()), dialog, SLOT(reject())); + QObject::connect(m_platformHelper, SIGNAL(launchNativeAppModalPanel()), + dialog, SLOT(_q_platformRunNativeAppModalPanel())); + ncThis->initHelper(m_platformHelper); + } } } return m_platformHelper; -- cgit v1.2.3