summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-22 17:53:34 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-26 01:20:44 +0200
commitc5d9e4a7a78b82ed31e5225c169de4718dfe4f05 (patch)
treed81df6b447239ca32926f19acb97462041f39bff /src/gui/kernel
parentd44413d526ec12ed83acd7343c2005782178c7ad (diff)
Teach QMessageDialogOptions about default and escape buttons
There's logic in QMessageBox to resolve the default and escape button if not set by the user. And the user may of course override these. We now propagate the resulting buttons via the dialog helper, and pick them up in the macOS native dialog backend. The only common information we have between the standard buttons and custom buttons is the button identifier, which for standard buttons is the enum value, and for custom buttons is an auto generated identifier. The same identifier is used when reporting the clicked button from the native dialog helper. Fixes: QTBUG-118308 Pick-to: 6.6 6.5 Change-Id: I5ca45604b51f0bbf74e56134d7b55bb8911f3563 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qplatformdialoghelper.cpp27
-rw-r--r--src/gui/kernel/qplatformdialoghelper.h7
2 files changed, 34 insertions, 0 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp
index 7153c90f50..847a841cee 100644
--- a/src/gui/kernel/qplatformdialoghelper.cpp
+++ b/src/gui/kernel/qplatformdialoghelper.cpp
@@ -778,6 +778,8 @@ public:
QPixmap iconPixmap;
QString checkBoxLabel;
Qt::CheckState checkBoxState = Qt::Unchecked;
+ int defaultButtonId = 0;
+ int escapeButtonId = 0;
QMessageDialogOptions::Options options;
};
@@ -903,6 +905,11 @@ const QList<QMessageDialogOptions::CustomButton> &QMessageDialogOptions::customB
return d->customButtons;
}
+void QMessageDialogOptions::clearCustomButtons()
+{
+ d->customButtons.clear();
+}
+
const QMessageDialogOptions::CustomButton *QMessageDialogOptions::customButton(int id)
{
const int i = int(d->customButtons.indexOf(CustomButton(id)));
@@ -925,6 +932,26 @@ Qt::CheckState QMessageDialogOptions::checkBoxState() const
return d->checkBoxState;
}
+void QMessageDialogOptions::setDefaultButton(int id)
+{
+ d->defaultButtonId = id;
+}
+
+int QMessageDialogOptions::defaultButton() const
+{
+ return d->defaultButtonId;
+}
+
+void QMessageDialogOptions::setEscapeButton(int id)
+{
+ d->escapeButtonId = id;
+}
+
+int QMessageDialogOptions::escapeButton() const
+{
+ return d->escapeButtonId;
+}
+
void QMessageDialogOptions::setOption(QMessageDialogOptions::Option option, bool on)
{
if (!(d->options & option) != !on)
diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h
index 1f8a7ec0a9..7483ded396 100644
--- a/src/gui/kernel/qplatformdialoghelper.h
+++ b/src/gui/kernel/qplatformdialoghelper.h
@@ -463,11 +463,18 @@ public:
void removeButton(int id);
const QList<CustomButton> &customButtons();
const CustomButton *customButton(int id);
+ void clearCustomButtons();
void setCheckBox(const QString &label, Qt::CheckState state);
QString checkBoxLabel() const;
Qt::CheckState checkBoxState() const;
+ void setEscapeButton(int id);
+ int escapeButton() const;
+
+ void setDefaultButton(int id);
+ int defaultButton() const;
+
private:
QMessageDialogOptionsPrivate *d;
};