summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2016-02-09 14:19:46 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-09-25 14:15:40 +0000
commit4c631c0bf971f0b41eb319cd3c6d5c723055aac6 (patch)
treeabb82a4a0200bceeff929691ecf9312538879dca /src/gui
parent2d587a03eb41cc907660deffeaf6805237706594 (diff)
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 <shawn.rutledge@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qplatformdialoghelper.cpp37
-rw-r--r--src/gui/kernel/qplatformdialoghelper.h22
2 files changed, 56 insertions, 3 deletions
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 <QtCore/QSharedData>
#include <QtCore/QSettings>
#include <QtCore/QUrl>
+#include <QtCore/QVector>
#include <QtGui/QColor>
#include <algorithm>
@@ -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<QMessageDialogOptions::CustomButton> 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::CustomButton> &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) {
diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h
index 64b703e524..bfcb658172 100644
--- a/src/gui/kernel/qplatformdialoghelper.h
+++ b/src/gui/kernel/qplatformdialoghelper.h
@@ -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.
@@ -460,6 +460,26 @@ public:
void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
QPlatformDialogHelper::StandardButtons standardButtons() const;
+ struct CustomButton {
+ explicit CustomButton(
+ int id = -1, const QString &label = QString(),
+ QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::InvalidRole,
+ void *button = nullptr) :
+ label(label), role(role), id(id), button(button)
+ {}
+
+ QString label;
+ QPlatformDialogHelper::ButtonRole role;
+ int id;
+ void *button; // strictly internal use only
+ };
+
+ int addButton(const QString &label, QPlatformDialogHelper::ButtonRole role,
+ void *buttonImpl = nullptr);
+ void removeButton(int id);
+ const QVector<CustomButton> &customButtons();
+ const CustomButton *customButton(int id);
+
private:
QMessageDialogOptionsPrivate *d;
};