diff options
-rw-r--r-- | src/quicktemplates2/qquickpopup.cpp | 13 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_dialog.qml | 44 |
2 files changed, 55 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index 3b224698..ef807064 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -40,6 +40,7 @@ #include "qquickshortcutcontext_p_p.h" #include "qquickoverlay_p_p.h" #include "qquickcontrol_p_p.h" +#include "qquickdialog_p.h" #include <QtGui/private/qshortcutmap_p.h> #include <QtGui/private/qguiapplication_p.h> @@ -252,6 +253,14 @@ void QQuickPopupPrivate::init() QObject::connect(popupItem, &QQuickControl::paddingChanged, q, &QQuickPopup::paddingChanged); } +static void closeOrReject(QQuickPopup *popup) +{ + if (QQuickDialog *dialog = qobject_cast<QQuickDialog*>(popup)) + dialog->reject(); + else + popup->close(); +} + bool QQuickPopupPrivate::tryClose(QQuickItem *item, QMouseEvent *event) { Q_Q(QQuickPopup); @@ -261,7 +270,7 @@ bool QQuickPopupPrivate::tryClose(QQuickItem *item, QMouseEvent *event) if (onOutside || onOutsideParent) { if (!popupItem->contains(item->mapToItem(popupItem, event->pos()))) { if (!onOutsideParent || !parentItem || !parentItem->contains(item->mapToItem(parentItem, event->pos()))) { - q->close(); + closeOrReject(q); return true; } } @@ -531,7 +540,7 @@ bool QQuickPopupItem::event(QEvent *event) if (event->type() == QEvent::Shortcut) { QShortcutEvent *se = static_cast<QShortcutEvent *>(event); if (se->shortcutId() == d->escapeId || se->shortcutId() == d->backId) { - d->popup->close(); + closeOrReject(d->popup); return true; } } diff --git a/tests/auto/controls/data/tst_dialog.qml b/tests/auto/controls/data/tst_dialog.qml index 69c47fed..4cfda8ee 100644 --- a/tests/auto/controls/data/tst_dialog.qml +++ b/tests/auto/controls/data/tst_dialog.qml @@ -106,6 +106,50 @@ TestCase { tryCompare(control, "visible", false) + // Check that rejected() is emitted when CloseOnEscape is triggered. + control.x = 10 + control.y = 10 + control.width = 100 + control.height = 100 + control.closePolicy = Popup.CloseOnEscape + control.open() + verify(control.visible) + + keyPress(Qt.Key_Escape) + compare(rejectedSpy.count, 2) + tryCompare(control, "visible", false) + + keyRelease(Qt.Key_Escape) + compare(rejectedSpy.count, 2) + + // Check that rejected() is emitted when CloseOnPressOutside is triggered. + control.closePolicy = Popup.CloseOnPressOutside + control.open() + verify(control.visible) + + mousePress(testCase, 1, 1) + compare(rejectedSpy.count, 3) + tryCompare(control, "visible", false) + + mouseRelease(testCase, 1, 1) + compare(rejectedSpy.count, 3) + + // Check that rejected() is emitted when CloseOnReleaseOutside is triggered. + // For this, we need to make the dialog modal, because the overlay won't accept + // the press event because it doesn't want to block the press. + control.modal = true + control.closePolicy = Popup.CloseOnReleaseOutside + control.open() + verify(control.visible) + + mousePress(testCase, 1, 1) + compare(rejectedSpy.count, 3) + verify(control.visible) + + mouseRelease(testCase, 1, 1) + compare(rejectedSpy.count, 4) + tryCompare(control, "visible", false) + control.destroy() } |