diff options
7 files changed, 42 insertions, 25 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h index 59e029769d..2b34f909d1 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.h @@ -59,6 +59,8 @@ public: void setCurrentColor(const QColor&); QColor currentColor() const; + + bool event(QEvent *); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index d90d77ec1d..ef2b4cbcfb 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -161,6 +161,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); - (void)closePanel { + if (mDialogIsExecuting) { + mDialogIsExecuting = false; + [NSApp stopModal]; + } [mColorPanel close]; } @@ -488,6 +492,22 @@ QColor QCocoaColorDialogHelper::currentColor() const return sharedColorPanel()->currentColor(); } +bool QCocoaColorDialogHelper::event(QEvent *e) +{ + if (e->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast<QKeyEvent *>(e); + if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) { + emit accept(); + return true; + } else if (ke->key() == Qt::Key_Escape) { + emit reject(); + return true; + } + } + + return false; +} + QT_END_NAMESPACE #endif // QT_NO_COLORDIALOG diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 91fb52eb6d..5bd0ad2a43 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -203,6 +203,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); - (void)closePanel { + if (mDialogIsExecuting) { + mDialogIsExecuting = false; + [NSApp stopModal]; + } [mFontPanel close]; } diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 5da41aa0a5..c9f03c5a97 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -2166,6 +2166,8 @@ void QColorDialog::keyPressEvent(QKeyEvent *e) } e->accept(); return; + } else if (d->nativeDialogInUse && d->platformColorDialogHelper()->event(e)) { + return; } QDialog::keyPressEvent(e); } diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index b989ea7c86..28afd91a09 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -983,14 +983,9 @@ void QFontDialog::setVisible(bool visible) Q_D(QFontDialog); if (d->canBeNativeDialog()) d->setNativeDialogVisible(visible); - if (d->nativeDialogInUse) { - // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below - // updates the state correctly, but skips showing the non-native version: - setAttribute(Qt::WA_DontShowOnScreen, true); - } else { - d->nativeDialogInUse = false; - setAttribute(Qt::WA_DontShowOnScreen, false); - } + // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below + // updates the state correctly, but skips showing the non-native version: + setAttribute(Qt::WA_DontShowOnScreen, d->nativeDialogInUse); QDialog::setVisible(visible); } diff --git a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp index d83e4729ef..06491f96ab 100644 --- a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp +++ b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp @@ -144,13 +144,10 @@ void tst_QColorDialog::postKeyReturn() { void tst_QColorDialog::testGetRgba() { -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "Sending QTest::keyClick to OSX color dialog helper fails, see QTBUG-24320", Continue); -#endif - bool ok = false; - QTimer::singleShot(500, this, SLOT(postKeyReturn())); - QColorDialog::getRgba(0xffffffff, &ok); - QVERIFY(ok); + QColorDialog cd; + cd.show(); + QTimer::singleShot(0, this, SLOT(postKeyReturn())); + QTRY_COMPARE(cd.result(), int(QDialog::Accepted)); } void tst_QColorDialog::defaultOkButton() diff --git a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp index 1762e40a9d..ae70adf94b 100644 --- a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp +++ b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp @@ -64,7 +64,7 @@ public: public slots: void postKeyReturn(); - void testGetFont(); + void testDefaultOkButton(); void testSetFont(); public slots: @@ -116,15 +116,12 @@ void tst_QFontDialog::postKeyReturn() { } } -void tst_QFontDialog::testGetFont() +void tst_QFontDialog::testDefaultOkButton() { -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "Sending QTest::keyClick to OSX font dialog helper fails, see QTBUG-24321", Continue); -#endif - bool ok = false; - QTimer::singleShot(2000, this, SLOT(postKeyReturn())); - QFontDialog::getFont(&ok); - QVERIFY(ok); + QFontDialog fd; + fd.show(); + QTimer::singleShot(0, this, SLOT(postKeyReturn())); + QTRY_COMPARE(fd.result(), int(QDialog::Accepted)); } void tst_QFontDialog::runSlotWithFailsafeTimer(const char *member) @@ -144,7 +141,7 @@ void tst_QFontDialog::runSlotWithFailsafeTimer(const char *member) void tst_QFontDialog::defaultOkButton() { - runSlotWithFailsafeTimer(SLOT(testGetFont())); + runSlotWithFailsafeTimer(SLOT(testDefaultOkButton())); } void tst_QFontDialog::testSetFont() |