From 4c631c0bf971f0b41eb319cd3c6d5c723055aac6 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 9 Feb 2016 14:19:46 +0100 Subject: Android: add support for custom buttons in native MessageDialog helper New API in QMessageDialogOptions and implementation on Android. Task-number: QTBUG-35545 Change-Id: I59567251199f220862d01ba76979266379eecd86 Reviewed-by: Shawn Rutledge Reviewed-by: Ulf Hermann --- .../platforms/android/qandroidplatformdialoghelpers.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp index ced35c4cfa..9218afa7f5 100644 --- a/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp +++ b/src/plugins/platforms/android/qandroidplatformdialoghelpers.cpp @@ -1,5 +1,6 @@ /**************************************************************************** ** +** Copyright (C) 2018 The Qt Company Ltd. ** Copyright (C) 2013 BogDan Vatra ** Contact: https://www.qt.io/licensing/ ** @@ -117,6 +118,15 @@ bool QAndroidPlatformMessageDialogHelper::show(Qt::WindowFlags windowFlags void QAndroidPlatformMessageDialogHelper::addButtons(QSharedPointer opt, ButtonRole role) { + for (const QMessageDialogOptions::CustomButton &b : opt->customButtons()) { + if (b.role == role) { + QString label = b.label; + label.remove(QChar('&')); + m_javaMessageDialog.callMethod("addButton", "(ILjava/lang/String;)V", b.id, + QJNIObjectPrivate::fromString(label).object()); + } + } + for (int i = QPlatformDialogHelper::FirstButton; i < QPlatformDialogHelper::LastButton; i<<=1) { StandardButton b = static_cast(i); if (buttonRole(b) == role && (opt->standardButtons() & i)) { @@ -144,6 +154,12 @@ void QAndroidPlatformMessageDialogHelper::dialogResult(int buttonID) QPlatformDialogHelper::StandardButton standardButton = static_cast(buttonID); QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(standardButton); + if (buttonID > QPlatformDialogHelper::LastButton) { + const QMessageDialogOptions::CustomButton *custom = options()->customButton(buttonID); + Q_ASSERT(custom); + role = custom->role; + } + emit clicked(standardButton, role); } -- cgit v1.2.3