aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2016-11-10 13:03:28 +0100
committerMitch Curtis <mitch.curtis@qt.io>2016-11-10 12:53:51 +0000
commit48731e5c2eee6d6f6e8029f82195e3209e01d066 (patch)
treea9c43fd46b3358665c7c96a877d65fc920f693d1 /src
parent80ef46b3b2c234832be4280ea7025083fd4f632a (diff)
Dialog: emit rejected() when closed interactively
This is what QDialog does, for example. This allows applications to perform some actions that must be done when the dialog is closed. For example, clearing any unsaved changes in a shortcut editor dialog. [ChangeLog][Controls][Dialog] Dialog now emits rejected() when closed interactively. Task-number: QTBUG-56928 Change-Id: Iad4e2fe984323d0b9fdfd17ee3746043b5eaf849 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickpopup.cpp13
1 files changed, 11 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;
}
}