Cocoa: Fix QFontDialog, QColorDialog auto-tests

The new Cocoa event dispatcher made apparent some deficiencies in the
way the dialog helpers were being hidden. In particular, we would not stop
a dialog helper's modal loop when closing the dialog, resulting in the
auto-tests hanging. Also, since the QApplication event loop is runnig with
[NSApp run] in the stack, the previous workarounds are no longer needed.

Task-number: QTBUG-24321
Change-Id: Ifba713c286638d78a699c319a15683d09714f06f
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
Gabriel de Dietrich 2013-08-26 19:29:33 +02:00 committed by The Qt Project
parent e4b2a0b4ba
commit df7944e7d7
7 changed files with 42 additions and 25 deletions

View File

@ -59,6 +59,8 @@ public:
void setCurrentColor(const QColor&);
QColor currentColor() const;
bool event(QEvent *);
};
QT_END_NAMESPACE

View File

@ -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

View File

@ -203,6 +203,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
- (void)closePanel
{
if (mDialogIsExecuting) {
mDialogIsExecuting = false;
[NSApp stopModal];
}
[mFontPanel close];
}

View File

@ -2166,6 +2166,8 @@ void QColorDialog::keyPressEvent(QKeyEvent *e)
}
e->accept();
return;
} else if (d->nativeDialogInUse && d->platformColorDialogHelper()->event(e)) {
return;
}
QDialog::keyPressEvent(e);
}

View File

@ -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);
}
setAttribute(Qt::WA_DontShowOnScreen, d->nativeDialogInUse);
QDialog::setVisible(visible);
}

View File

@ -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()

View File

@ -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()