From 209a5f1e8dc3e2275f225823ad9edfee09ba756c Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 29 Aug 2013 09:30:32 +0200 Subject: Adding QPlatformMessageDialogHelper and QMessageDialogOptions We plan to add support for native message/alert dialogs on Android and iOS because it's otherwise impossible to have a true popup window. Then we might as well have native message/alert dialogs on other platforms too. It will become an alternative implementation behind QMessageBox and perhaps QErrorMessage. Task-number: QTBUG-30883 Task-number: QTBUG-29462 Change-Id: I73dcfc6438e696189b6d37091874c7ad69b4ec68 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qplatformdialoghelper.cpp | 117 +++++++++++++++++++++++++++++++ src/gui/kernel/qplatformdialoghelper.h | 81 +++++++++++++++++++++ src/gui/kernel/qplatformtheme.h | 3 +- src/widgets/dialogs/qmessagebox.h | 2 +- 4 files changed, 201 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index f297236655..fe5db27117 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -596,4 +596,121 @@ QStringList QPlatformFileDialogHelper::cleanFilterList(const QString &filter) return f.split(QLatin1Char(' '), QString::SkipEmptyParts); } +// Message dialog + +class QMessageDialogOptionsPrivate : public QSharedData +{ +public: + QMessageDialogOptionsPrivate() : + icon(QMessageDialogOptions::NoIcon), + buttons(QMessageDialogOptions::Ok) + {} + + QString windowTitle; + QMessageDialogOptions::Icon icon; + QString text; + QString informativeText; + QString detailedText; + QMessageDialogOptions::StandardButtons buttons; +}; + +QMessageDialogOptions::QMessageDialogOptions() : d(new QMessageDialogOptionsPrivate) +{ +} + +QMessageDialogOptions::QMessageDialogOptions(const QMessageDialogOptions &rhs) : d(rhs.d) +{ +} + +QMessageDialogOptions &QMessageDialogOptions::operator=(const QMessageDialogOptions &rhs) +{ + if (this != &rhs) + d = rhs.d; + return *this; +} + +QMessageDialogOptions::~QMessageDialogOptions() +{ +} + +QString QMessageDialogOptions::windowTitle() const +{ + return d->windowTitle; +} + +void QMessageDialogOptions::setWindowTitle(const QString &title) +{ + d->windowTitle = title; +} + +QMessageDialogOptions::Icon QMessageDialogOptions::icon() const +{ + return d->icon; +} + +void QMessageDialogOptions::setIcon(Icon icon) +{ + d->icon = icon; +} + +QString QMessageDialogOptions::text() const +{ + return d->text; +} + +void QMessageDialogOptions::setText(const QString &text) +{ + d->text = text; +} + +QString QMessageDialogOptions::informativeText() const +{ + return d->informativeText; +} + +void QMessageDialogOptions::setInformativeText(const QString &informativeText) +{ + d->informativeText = informativeText; +} + +QString QMessageDialogOptions::detailedText() const +{ + return d->detailedText; +} + +void QMessageDialogOptions::setDetailedText(const QString &detailedText) +{ + d->detailedText = detailedText; +} + +void QMessageDialogOptions::setStandardButtons(StandardButtons buttons) +{ + d->buttons = buttons; +} + +QMessageDialogOptions::StandardButtons QMessageDialogOptions::standardButtons() const +{ + return d->buttons; +} + + +/*! + \class QPlatformMessageDialogHelper + \since 5.0 + \internal + \ingroup qpa + + \brief The QPlatformMessageDialogHelper class allows for platform-specific customization of Message dialogs. + +*/ +const QSharedPointer &QPlatformMessageDialogHelper::options() const +{ + return m_options; +} + +void QPlatformMessageDialogHelper::setOptions(const QSharedPointer &options) +{ + m_options = options; +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index 5269416ffd..ad818c8644 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -72,6 +72,7 @@ class QUrl; class QColorDialogOptionsPrivate; class QFontDialogOptionsPrivate; class QFileDialogOptionsPrivate; +class QMessageDialogOptionsPrivate; class Q_GUI_EXPORT QPlatformDialogHelper : public QObject { @@ -325,6 +326,86 @@ private: QSharedPointer m_options; }; +class Q_GUI_EXPORT QMessageDialogOptions +{ +public: + // Keep in sync with QMessageBox::Icon + enum Icon { NoIcon, Information, Warning, Critical, Question }; + + enum StandardButton { + // keep this in sync with QDialogButtonBox::StandardButton and QMessageBox::StandardButton + NoButton = 0x00000000, + Ok = 0x00000400, + Save = 0x00000800, + SaveAll = 0x00001000, + Open = 0x00002000, + Yes = 0x00004000, + YesToAll = 0x00008000, + No = 0x00010000, + NoToAll = 0x00020000, + Abort = 0x00040000, + Retry = 0x00080000, + Ignore = 0x00100000, + Close = 0x00200000, + Cancel = 0x00400000, + Discard = 0x00800000, + Help = 0x01000000, + Apply = 0x02000000, + Reset = 0x04000000, + RestoreDefaults = 0x08000000, + + + FirstButton = Ok, // internal + LastButton = RestoreDefaults // internal + }; + + Q_DECLARE_FLAGS(StandardButtons, StandardButton) + + QMessageDialogOptions(); + QMessageDialogOptions(const QMessageDialogOptions &rhs); + QMessageDialogOptions &operator=(const QMessageDialogOptions &rhs); + ~QMessageDialogOptions(); + + void swap(QMessageDialogOptions &other) { qSwap(d, other.d); } + + QString windowTitle() const; + void setWindowTitle(const QString &); + + void setIcon(Icon icon); + Icon icon() const; + + void setText(const QString &text); + QString text() const; + + void setInformativeText(const QString &text); + QString informativeText() const; + + void setDetailedText(const QString &text); + QString detailedText() const; + + void setStandardButtons(StandardButtons buttons); + StandardButtons standardButtons() const; + +private: + QSharedDataPointer d; +}; + +Q_DECLARE_SHARED(QMessageDialogOptions) + +class Q_GUI_EXPORT QPlatformMessageDialogHelper : public QPlatformDialogHelper +{ + Q_OBJECT +public: + const QSharedPointer &options() const; + void setOptions(const QSharedPointer &options); + +Q_SIGNALS: + void clicked(QMessageDialogOptions::StandardButton button); + +private: + QSharedPointer m_options; +}; + QT_END_NAMESPACE #endif // QPLATFORMDIALOGHELPER_H diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 710e36ae42..4bddac5b1b 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -112,7 +112,8 @@ public: enum DialogType { FileDialog, ColorDialog, - FontDialog + FontDialog, + MessageDialog }; enum Palette { diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h index 32b7027d89..c7c42b1e7a 100644 --- a/src/widgets/dialogs/qmessagebox.h +++ b/src/widgets/dialogs/qmessagebox.h @@ -95,7 +95,7 @@ public: }; enum StandardButton { - // keep this in sync with QDialogButtonBox::StandardButton + // keep this in sync with QDialogButtonBox::StandardButton and QMessageDialogOptions::StandardButton NoButton = 0x00000000, Ok = 0x00000400, Save = 0x00000800, -- cgit v1.2.3