summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-09-25 13:54:17 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2018-09-29 09:32:43 +0000
commit076eef86db02331bb4874a8f79306ec1aeb26ffd (patch)
tree71b224f97fc49fbb417b37e17f4ea9db14c61e52 /src/plugins/platforms
parent9a8175a13124e156948914854d2fda7436065b08 (diff)
iOS: add support for custom buttons in native MessageDialog helper
[ChangeLog][QtWidgets][QMessageBox] On Android and iOS it's now possible to show a QMessageBox with custom buttons as a native dialog. Task-number: QTBUG-35545 Change-Id: Id3be69e70468f767a43ea5f2ba64f9bac1898423 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/ios/qiosmessagedialog.h1
-rw-r--r--src/plugins/platforms/ios/qiosmessagedialog.mm20
2 files changed, 20 insertions, 1 deletions
diff --git a/src/plugins/platforms/ios/qiosmessagedialog.h b/src/plugins/platforms/ios/qiosmessagedialog.h
index 92a4db8319..913fe0c2e9 100644
--- a/src/plugins/platforms/ios/qiosmessagedialog.h
+++ b/src/plugins/platforms/ios/qiosmessagedialog.h
@@ -63,6 +63,7 @@ private:
UIAlertController *m_alertController;
QString messageTextPlain();
UIAlertAction *createAction(StandardButton button);
+ UIAlertAction *createAction(const QMessageDialogOptions::CustomButton &customButton);
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/ios/qiosmessagedialog.mm b/src/plugins/platforms/ios/qiosmessagedialog.mm
index a7de9b473a..254922701a 100644
--- a/src/plugins/platforms/ios/qiosmessagedialog.mm
+++ b/src/plugins/platforms/ios/qiosmessagedialog.mm
@@ -79,6 +79,18 @@ inline QString QIOSMessageDialog::messageTextPlain()
return text;
}
+inline UIAlertAction *QIOSMessageDialog::createAction(
+ const QMessageDialogOptions::CustomButton &customButton)
+{
+ const QString label = QPlatformTheme::removeMnemonics(customButton.label);
+ const UIAlertActionStyle style = UIAlertActionStyleDefault;
+
+ return [UIAlertAction actionWithTitle:label.toNSString() style:style handler:^(UIAlertAction *) {
+ hide();
+ emit clicked(static_cast<QPlatformDialogHelper::StandardButton>(customButton.id), customButton.role);
+ }];
+}
+
inline UIAlertAction *QIOSMessageDialog::createAction(StandardButton button)
{
const StandardButton labelButton = button == NoButton ? Ok : button;
@@ -118,12 +130,18 @@ bool QIOSMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality win
message:messageTextPlain().toNSString()
preferredStyle:UIAlertControllerStyleAlert] retain];
+ const QVector<QMessageDialogOptions::CustomButton> customButtons = options()->customButtons();
+ for (const QMessageDialogOptions::CustomButton &button : customButtons) {
+ UIAlertAction *act = createAction(button);
+ [m_alertController addAction:act];
+ }
+
if (StandardButtons buttons = options()->standardButtons()) {
for (int i = FirstButton; i < LastButton; i<<=1) {
if (i & buttons)
[m_alertController addAction:createAction(StandardButton(i))];
}
- } else {
+ } else if (customButtons.isEmpty()) {
// We need at least one button to allow the user close the dialog
[m_alertController addAction:createAction(NoButton)];
}