Respect the DontUseNativeDialog flag.
authorChristoph Schleifenbaum <christoph.schleifenbaum@kdab.com>
Tue, 10 Apr 2012 15:17:41 +0000 (17:17 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 27 Apr 2012 03:51:14 +0000 (05:51 +0200)
QFontDialog and QColorDialog were ignoring the DontUseNativeDialog. This
lead to a native (Cocoa) dialog created all the time.

Fix the testcase for QFontDialog. It needs the DontUseNativeDialog flag
set.

Task-number: QTBUG-24321

Change-Id: I159c1ad057bac38226f1e01a56b15f142650bfd8
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
src/widgets/dialogs/qcolordialog.cpp
src/widgets/dialogs/qfontdialog.cpp
src/widgets/dialogs/qfontdialog_p.h
tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp

index 606b9b0..d7a8f5d 100644 (file)
@@ -1247,7 +1247,7 @@ inline bool QColorDialogPrivate::isAlphaVisible() const { return cs->isAlphaVisi
 
 QColor QColorDialogPrivate::currentQColor() const
 {
-    if (nativeDialogInUse)
+    if (!options->testOption(QColorDialogOptions::DontUseNativeDialog) && nativeDialogInUse)
         return platformColorDialogHelper()->currentColor_sys();
     return cs->currentQColor();
 }
@@ -1706,8 +1706,7 @@ void QColorDialog::setCurrentColor(const QColor &color)
     d->selectColor(color);
     d->setCurrentAlpha(color.alpha());
 
-    // ### fixme: Call helper
-    if (d->nativeDialogInUse)
+    if (!testOption(QColorDialog::DontUseNativeDialog) && d->nativeDialogInUse)
         d->platformColorDialogHelper()->setCurrentColor_sys(color);
 }
 
index 7e71cd7..b267f67 100644 (file)
@@ -171,11 +171,6 @@ void QFontDialogPrivate::init()
 {
     Q_Q(QFontDialog);
 
-#ifdef Q_WS_MAC
-    nativeDialogInUse = false;
-    delegate = 0;
-#endif
-
     q->setSizeGripEnabled(true);
     q->setWindowTitle(QFontDialog::tr("Select Font"));
 
@@ -805,8 +800,10 @@ void QFontDialog::setCurrentFont(const QFont &font)
     d->strikeout->setChecked(font.strikeOut());
     d->underline->setChecked(font.underline());
     d->updateFamilies();
-    if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
-        helper->setCurrentFont_sys(font);
+    if (d->canBeNativeDialog()) {
+        if (QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
+            helper->setCurrentFont_sys(font);
+    }
 
 #ifdef Q_WS_MAC
     if (d->delegate)
@@ -824,8 +821,10 @@ void QFontDialog::setCurrentFont(const QFont &font)
 QFont QFontDialog::currentFont() const
 {
     Q_D(const QFontDialog);
-    if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
-        return helper->currentFont_sys();
+    if (d->canBeNativeDialog()) {
+        if (const QPlatformFontDialogHelper *helper = d->platformFontDialogHelper())
+            return helper->currentFont_sys();
+    }
     return d->sampleEdit->font();
 }
 
@@ -1013,9 +1012,9 @@ void QFontDialog::done(int result)
     d->memberToDisconnectOnClose.clear();
 }
 
-bool QFontDialogPrivate::canBeNativeDialog()
+bool QFontDialogPrivate::canBeNativeDialog() const
 {
-    Q_Q(QFontDialog);
+    Q_Q(const QFontDialog);
     if (nativeDialogInUse)
         return true;
     if (q->testAttribute(Qt::WA_DontShowOnScreen))
index 9bf00d2..75a9045 100644 (file)
@@ -143,7 +143,7 @@ public:
     QPointer<QObject> receiverToDisconnectOnClose;
     QByteArray memberToDisconnectOnClose;
 
-    bool canBeNativeDialog();
+    bool canBeNativeDialog() const;
     void _q_runNativeAppModalPanel();
 #ifdef Q_WS_MAC
     static void setFont(void *delegate, const QFont &font);
index 6b2caf1..533014b 100644 (file)
@@ -160,12 +160,9 @@ class FriendlyFontDialog : public QFontDialog
 
 void tst_QFontDialog::task256466_wrongStyle()
 {
-#ifdef Q_OS_MAC
-    QSKIP("Test crashes on Mac OS X, see QTBUG-24321");
-#endif
-
     QFontDatabase fdb;
     FriendlyFontDialog dialog;
+    dialog.setOption(QFontDialog::DontUseNativeDialog);
     QListView *familyList = reinterpret_cast<QListView*>(dialog.d_func()->familyList);
     QListView *styleList = reinterpret_cast<QListView*>(dialog.d_func()->styleList);
     QListView *sizeList = reinterpret_cast<QListView*>(dialog.d_func()->sizeList);