From d916ffa113459574473b7e38c8e18e2e86dc3a0f Mon Sep 17 00:00:00 2001
From: Shawn Rutledge <shawn.rutledge@digia.com>
Date: Thu, 16 Oct 2014 13:36:13 +0200
Subject: [PATCH] Dialogs: don't use widgets on mobile touch-based platforms

It doesn't make sense to use widget-based dialogs in a QtQuick app
on a mobile platform because widgets are not optimized for touch.

Change-Id: I8659f247eb6e75ca827e8b42a0fb1e7f65dceee1
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
---
 src/dialogs/plugin.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/dialogs/plugin.cpp b/src/dialogs/plugin.cpp
index b8ddf35b9..1d701cbe1 100644
--- a/src/dialogs/plugin.cpp
+++ b/src/dialogs/plugin.cpp
@@ -50,6 +50,7 @@
 #include "qquickdialog_p.h"
 #include <private/qguiapplication_p.h>
 #include <qpa/qplatformintegration.h>
+#include <QTouchDevice>
 
 //#define PURE_QML_ONLY
 //#define DEBUG_REGISTRATION
@@ -186,9 +187,20 @@ protected:
         Q_UNUSED(widgetsDir)
         Q_UNUSED(hasTopLevelWindows)
 #else
+        bool mobileTouchPlatform = false;
+#if defined(Q_OS_IOS)
+        mobileTouchPlatform = true;
+#elif defined(Q_OS_ANDROID) || defined(Q_OS_BLACKBERRY) || defined(Q_OS_QNX) || defined(Q_OS_WINRT)
+        foreach (const QTouchDevice *dev, QTouchDevice::devices())
+            if (dev->type() == QTouchDevice::TouchScreen)
+                mobileTouchPlatform = true;
+#endif
         // If there is a qmldir and we have a QApplication instance (as opposed to a
-        // widget-free QGuiApplication), assume that the widget-based dialog will work.
-        if (hasTopLevelWindows && widgetsDir.exists("qmldir") &&
+        // widget-free QGuiApplication), and this isn't a mobile touch-based platform,
+        // assume that the widget-based dialog will work.  Otherwise an application developer
+        // can ensure that widgets are omitted from the deployment to ensure that the widget
+        // dialogs won't be used.
+        if (!mobileTouchPlatform && hasTopLevelWindows && widgetsDir.exists("qmldir") &&
                 QCoreApplication::instance()->inherits("QApplication")) {
             QUrl dialogQmlPath =  m_useResources ?
                 QUrl(QString("qrc:/QtQuick/Dialogs/Widget%1.qml").arg(qmlName)) :
-- 
GitLab