aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/platform/qquickplatformdialog.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-08-15 14:36:02 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-08-15 12:47:36 +0000
commit8793cba8aab832a03ed0f608114d83765a02a8ec (patch)
tree639058d38fa38132a498ddadae5218ce30058e7e /src/imports/platform/qquickplatformdialog.cpp
parent748a9418544e25c2abc6e3eb8862517bea091e7d (diff)
Platform dialogs: cleanup creation
Now that we know the type and whether it should be native, it can be all done in the base class to reduce a lot of code duplication. Change-Id: I7d7d7057fa499df75b72914d2b505bfa0288048d Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/imports/platform/qquickplatformdialog.cpp')
-rw-r--r--src/imports/platform/qquickplatformdialog.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/imports/platform/qquickplatformdialog.cpp b/src/imports/platform/qquickplatformdialog.cpp
index 70d571e0..00066d0a 100644
--- a/src/imports/platform/qquickplatformdialog.cpp
+++ b/src/imports/platform/qquickplatformdialog.cpp
@@ -36,9 +36,18 @@
#include "qquickplatformdialog_p.h"
+#include <QtCore/qloggingcategory.h>
+#include <QtGui/private/qguiapplication_p.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickwindow.h>
+#ifdef QT_WIDGETS_LIB
+#include "widgets/qwidgetplatformcolordialog_p.h"
+#include "widgets/qwidgetplatformfiledialog_p.h"
+#include "widgets/qwidgetplatformfontdialog_p.h"
+#include "widgets/qwidgetplatformmessagedialog_p.h"
+#endif
+
QT_BEGIN_NAMESPACE
/*!
@@ -81,6 +90,8 @@ QT_BEGIN_NAMESPACE
\sa accepted()
*/
+Q_DECLARE_LOGGING_CATEGORY(qtLabsPlatformDialogs)
+
QQuickPlatformDialog::QQuickPlatformDialog(QPlatformTheme::DialogType type, QObject *parent)
: QObject(parent),
m_visible(false),
@@ -335,11 +346,41 @@ void QQuickPlatformDialog::componentComplete()
setParentWindow(findParentWindow());
}
+static QPlatformDialogHelper *createWidgetDialog(QPlatformTheme::DialogType type, QObject *parent)
+{
+ QPlatformDialogHelper *dialog = nullptr;
+#ifdef QT_WIDGETS_LIB
+ switch (type) {
+ case QPlatformTheme::ColorDialog:
+ dialog = new QWidgetPlatformColorDialog(parent);
+ break;
+ case QPlatformTheme::FileDialog:
+ dialog = new QWidgetPlatformFileDialog(parent);
+ break;
+ case QPlatformTheme::FontDialog:
+ dialog = new QWidgetPlatformFontDialog(parent);
+ break;
+ case QPlatformTheme::MessageDialog:
+ dialog = new QWidgetPlatformMessageDialog(parent);
+ break;
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+#endif
+ return dialog;
+}
+
bool QQuickPlatformDialog::create()
{
if (!m_handle) {
- m_handle = onCreate();
+ if (useNativeDialog())
+ m_handle = QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(m_type);
+ if (!m_handle)
+ m_handle = createWidgetDialog(m_type, this);
+ qCDebug(qtLabsPlatformDialogs) << this << "created" << m_handle;
if (m_handle) {
+ onCreate(m_handle);
connect(m_handle, &QPlatformDialogHelper::accept, this, &QQuickPlatformDialog::accept);
connect(m_handle, &QPlatformDialogHelper::reject, this, &QQuickPlatformDialog::reject);
}
@@ -358,6 +399,11 @@ bool QQuickPlatformDialog::useNativeDialog() const
return true;
}
+void QQuickPlatformDialog::onCreate(QPlatformDialogHelper *dialog)
+{
+ Q_UNUSED(dialog);
+}
+
void QQuickPlatformDialog::onShow(QPlatformDialogHelper *dialog)
{
Q_UNUSED(dialog);