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:
parent
e4b2a0b4ba
commit
df7944e7d7
@ -59,6 +59,8 @@ public:
|
||||
|
||||
void setCurrentColor(const QColor&);
|
||||
QColor currentColor() const;
|
||||
|
||||
bool event(QEvent *);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -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
|
||||
|
@ -203,6 +203,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
|
||||
|
||||
- (void)closePanel
|
||||
{
|
||||
if (mDialogIsExecuting) {
|
||||
mDialogIsExecuting = false;
|
||||
[NSApp stopModal];
|
||||
}
|
||||
[mFontPanel close];
|
||||
}
|
||||
|
||||
|
@ -2166,6 +2166,8 @@ void QColorDialog::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
e->accept();
|
||||
return;
|
||||
} else if (d->nativeDialogInUse && d->platformColorDialogHelper()->event(e)) {
|
||||
return;
|
||||
}
|
||||
QDialog::keyPressEvent(e);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user