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 --- src/gui/kernel/qplatformdialoghelper.cpp | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel/qplatformdialoghelper.cpp') diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index b456c1ca31..b787629f6a 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -786,7 +787,8 @@ class QMessageDialogOptionsPrivate : public QSharedData public: QMessageDialogOptionsPrivate() : icon(QMessageDialogOptions::NoIcon), - buttons(QPlatformDialogHelper::Ok) + buttons(QPlatformDialogHelper::Ok), + nextCustomButtonId(QPlatformDialogHelper::LastButton + 1) {} QString windowTitle; @@ -795,6 +797,8 @@ public: QString informativeText; QString detailedText; QPlatformDialogHelper::StandardButtons buttons; + QVector customButtons; + int nextCustomButtonId; }; QMessageDialogOptions::QMessageDialogOptions(QMessageDialogOptionsPrivate *dd) @@ -886,6 +890,35 @@ QPlatformDialogHelper::StandardButtons QMessageDialogOptions::standardButtons() return d->buttons; } +int QMessageDialogOptions::addButton(const QString &label, QPlatformDialogHelper::ButtonRole role, + void *buttonImpl) +{ + const CustomButton b(d->nextCustomButtonId++, label, role, buttonImpl); + d->customButtons.append(b); + return b.id; +} + +static inline bool operator==(const QMessageDialogOptions::CustomButton &a, + const QMessageDialogOptions::CustomButton &b) { + return a.id == b.id; +} + +void QMessageDialogOptions::removeButton(int id) +{ + d->customButtons.removeOne(CustomButton(id)); +} + +const QVector &QMessageDialogOptions::customButtons() +{ + return d->customButtons; +} + +const QMessageDialogOptions::CustomButton *QMessageDialogOptions::customButton(int id) +{ + int i = d->customButtons.indexOf(CustomButton(id)); + return (i < 0 ? nullptr : &d->customButtons.at(i)); +} + QPlatformDialogHelper::ButtonRole QPlatformDialogHelper::buttonRole(QPlatformDialogHelper::StandardButton button) { switch (button) { -- cgit v1.2.3