summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/kernel/qplatformdialoghelper.cpp17
-rw-r--r--src/gui/kernel/qplatformdialoghelper.h7
-rw-r--r--src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp2
-rw-r--r--src/plugins/platforms/cocoa/qcocoamessagedialog.mm31
-rw-r--r--src/plugins/platforms/ios/qiosmessagedialog.mm2
-rw-r--r--src/widgets/dialogs/qerrormessage.cpp8
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp11
7 files changed, 62 insertions, 16 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp
index f1370a07b8..7038954ea0 100644
--- a/src/gui/kernel/qplatformdialoghelper.cpp
+++ b/src/gui/kernel/qplatformdialoghelper.cpp
@@ -776,7 +776,8 @@ public:
QList<QMessageDialogOptions::CustomButton> customButtons;
int nextCustomButtonId;
QPixmap iconPixmap;
- bool enableSupressionCheckBox = false;
+ QString checkBoxLabel;
+ Qt::CheckState checkBoxState = Qt::Unchecked;
};
QMessageDialogOptions::QMessageDialogOptions(QMessageDialogOptionsPrivate *dd)
@@ -907,14 +908,20 @@ const QMessageDialogOptions::CustomButton *QMessageDialogOptions::customButton(i
return (i < 0 ? nullptr : &d->customButtons.at(i));
}
-void QMessageDialogOptions::setSupressionCheckBoxEnabled(bool enabled)
+void QMessageDialogOptions::setCheckBox(const QString &label, Qt::CheckState state)
{
- d->enableSupressionCheckBox = enabled;
+ d->checkBoxLabel = label;
+ d->checkBoxState = state;
}
-bool QMessageDialogOptions::supressionCheckBoxEnabled() const
+QString QMessageDialogOptions::checkBoxLabel() const
{
- return d->enableSupressionCheckBox;
+ return d->checkBoxLabel;
+}
+
+Qt::CheckState QMessageDialogOptions::checkBoxState() const
+{
+ return d->checkBoxState;
}
QPlatformDialogHelper::ButtonRole QPlatformDialogHelper::buttonRole(QPlatformDialogHelper::StandardButton button)
diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h
index 43d3dfe358..25543a70b8 100644
--- a/src/gui/kernel/qplatformdialoghelper.h
+++ b/src/gui/kernel/qplatformdialoghelper.h
@@ -451,8 +451,9 @@ public:
const QList<CustomButton> &customButtons();
const CustomButton *customButton(int id);
- void setSupressionCheckBoxEnabled(bool enabled);
- bool supressionCheckBoxEnabled() const;
+ void setCheckBox(const QString &label, Qt::CheckState state);
+ QString checkBoxLabel() const;
+ Qt::CheckState checkBoxState() const;
private:
QMessageDialogOptionsPrivate *d;
@@ -467,7 +468,7 @@ public:
Q_SIGNALS:
void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role);
- void supressionCheckBoxChanged(bool checked);
+ void checkBoxStateChanged(Qt::CheckState state);
private:
QSharedPointer<QMessageDialogOptions> m_options;
diff --git a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp
index 81c6b41d65..25427d5ede 100644
--- a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp
+++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp
@@ -54,7 +54,7 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags,
if (!opt.data())
return false;
- if (opt->supressionCheckBoxEnabled())
+ if (!opt->checkBoxLabel().isNull())
return false; // Can't support
m_javaMessageDialog.callMethod<void>("setStandardIcon", "(I)V", opt->standardIcon());
diff --git a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm
index 8dcc5fab53..f19146c60c 100644
--- a/src/plugins/platforms/cocoa/qcocoamessagedialog.mm
+++ b/src/plugins/platforms/cocoa/qcocoamessagedialog.mm
@@ -46,6 +46,16 @@ static QString toPlainText(const QString &text)
return textDocument.toPlainText();
}
+static NSControlStateValue controlStateFor(Qt::CheckState state)
+{
+ switch (state) {
+ case Qt::Checked: return NSControlStateValueOn;
+ case Qt::Unchecked: return NSControlStateValueOff;
+ case Qt::PartiallyChecked: return NSControlStateValueMixed;
+ }
+ Q_UNREACHABLE();
+}
+
/*
Called from QDialogPrivate::setNativeDialogVisible() when the message box
is ready to be shown.
@@ -185,7 +195,14 @@ bool QCocoaMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality w
StandardButton::Ok, ButtonRole::AcceptRole);
}
- m_alert.showsSuppressionButton = options()->supressionCheckBoxEnabled();
+ if (auto checkBoxLabel = options()->checkBoxLabel(); !checkBoxLabel.isNull()) {
+ checkBoxLabel = QPlatformTheme::removeMnemonics(checkBoxLabel);
+ m_alert.suppressionButton.title = checkBoxLabel.toNSString();
+ auto state = options()->checkBoxState();
+ m_alert.suppressionButton.allowsMixedState = state == Qt::PartiallyChecked;
+ m_alert.suppressionButton.state = controlStateFor(state);
+ m_alert.showsSuppressionButton = YES;
+ }
qCDebug(lcQpaDialogs) << "Showing" << m_alert;
@@ -233,6 +250,16 @@ void QCocoaMessageDialog::exec()
// Custom modal response code to record that the dialog was hidden by us
static const NSInteger kModalResponseDialogHidden = NSAlertThirdButtonReturn + 1;
+static Qt::CheckState checkStateFor(NSControlStateValue state)
+{
+ switch (state) {
+ case NSControlStateValueOn: return Qt::Checked;
+ case NSControlStateValueOff: return Qt::Unchecked;
+ case NSControlStateValueMixed: return Qt::PartiallyChecked;
+ }
+ Q_UNREACHABLE();
+}
+
void QCocoaMessageDialog::processResponse(NSModalResponse response)
{
qCDebug(lcQpaDialogs) << "Processing response" << response << "for" << m_alert;
@@ -244,7 +271,7 @@ void QCocoaMessageDialog::processResponse(NSModalResponse response)
[alert autorelease];
if (alert.showsSuppressionButton)
- emit supressionCheckBoxChanged(alert.suppressionButton.state == NSControlStateValueOn);
+ emit checkBoxStateChanged(checkStateFor(alert.suppressionButton.state));
if (response >= NSAlertFirstButtonReturn) {
// Safe range for user-defined modal responses
diff --git a/src/plugins/platforms/ios/qiosmessagedialog.mm b/src/plugins/platforms/ios/qiosmessagedialog.mm
index 1f39a94172..b95cfada60 100644
--- a/src/plugins/platforms/ios/qiosmessagedialog.mm
+++ b/src/plugins/platforms/ios/qiosmessagedialog.mm
@@ -92,7 +92,7 @@ bool QIOSMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality win
|| windowModality == Qt::NonModal) // We can only do modal dialogs
return false;
- if (options()->supressionCheckBoxEnabled())
+ if (!options()->checkBoxLabel().isNull())
return false; // Can't support
m_alertController = [[UIAlertController
diff --git a/src/widgets/dialogs/qerrormessage.cpp b/src/widgets/dialogs/qerrormessage.cpp
index 374cdb53cc..5a6d529fc2 100644
--- a/src/widgets/dialogs/qerrormessage.cpp
+++ b/src/widgets/dialogs/qerrormessage.cpp
@@ -63,9 +63,9 @@ void QErrorMessagePrivate::initHelper(QPlatformDialogHelper *helper)
{
Q_Q(QErrorMessage);
auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(helper);
- QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::supressionCheckBoxChanged, q,
- [this](bool supressionChecked) {
- again->setChecked(!supressionChecked);
+ QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged, q,
+ [this](Qt::CheckState state) {
+ again->setCheckState(state);
}
);
QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::clicked, q,
@@ -86,7 +86,7 @@ void QErrorMessagePrivate::helperPrepareShow(QPlatformDialogHelper *helper)
options->setText(QErrorMessage::tr("An error occurred"));
options->setInformativeText(currentMessage);
options->setStandardIcon(QMessageDialogOptions::Critical);
- options->setSupressionCheckBoxEnabled(true);
+ options->setCheckBox(again->text(), again->checkState());
messageDialogHelper->setOptions(options);
}
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index cf731b2961..cdd073350b 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -2682,6 +2682,15 @@ void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h)
Q_Q(QMessageBox);
QObject::connect(h, SIGNAL(clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)),
q, SLOT(_q_clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)));
+
+ auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(h);
+ QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged, q,
+ [this](Qt::CheckState state) {
+ if (checkbox)
+ checkbox->setCheckState(state);
+ }
+ );
+
static_cast<QPlatformMessageDialogHelper *>(h)->setOptions(options);
}
@@ -2720,6 +2729,8 @@ void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *)
options->setStandardIcon(helperIcon(q->icon()));
options->setIconPixmap(q->iconPixmap());
options->setStandardButtons(helperStandardButtons(q));
+ if (checkbox)
+ options->setCheckBox(checkbox->text(), checkbox->checkState());
}
void QMessageBoxPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *)