diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2013-11-07 18:31:47 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-08 09:10:07 +0100 |
commit | c286b4fccb2d83fcc01b21913b95c5e4f21f2982 (patch) | |
tree | 4c0d6d915b225583ffe3d509141909730fafc046 /src/imports/widgets | |
parent | 8c6a34133c07f28f62bf9a06a3952affd239424e (diff) |
MessageDialog: handle clicked(button, role) signal properly
Depends on I7be753080794adabb784df9b95ac04aa1c29151c in qtbase.
Now the Android native dialog can provide the same functionality as
the QML and QMessageBox implementations.
Change-Id: Icc9c610669742199d48497096524f6cf8ed4d835
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'src/imports/widgets')
-rw-r--r-- | src/imports/widgets/qmessageboxhelper_p.h | 107 | ||||
-rw-r--r-- | src/imports/widgets/qquickqmessagebox.cpp | 81 | ||||
-rw-r--r-- | src/imports/widgets/qquickqmessagebox_p.h | 9 | ||||
-rw-r--r-- | src/imports/widgets/widgets.pro | 1 |
4 files changed, 113 insertions, 85 deletions
diff --git a/src/imports/widgets/qmessageboxhelper_p.h b/src/imports/widgets/qmessageboxhelper_p.h new file mode 100644 index 0000000000..4f1070f97d --- /dev/null +++ b/src/imports/widgets/qmessageboxhelper_p.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMESSAGEBOXHELPER_P_H +#define QMESSAGEBOXHELPER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QMessageBox> +#include "../dialogs/qquickabstractmessagedialog_p.h" + +QT_BEGIN_NAMESPACE + +class QMessageBoxHelper : public QPlatformMessageDialogHelper +{ + Q_OBJECT +public: + QMessageBoxHelper() { + connect(&m_dialog, SIGNAL(accepted()), this, SIGNAL(accept())); + connect(&m_dialog, SIGNAL(rejected()), this, SIGNAL(reject())); + connect(&m_dialog, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); + } + + virtual void exec() { m_dialog.exec(); } + + virtual bool show(Qt::WindowFlags f, Qt::WindowModality m, QWindow *parent) { + m_dialog.winId(); + QWindow *window = m_dialog.windowHandle(); + Q_ASSERT(window); + window->setTransientParent(parent); + window->setFlags(f); + m_dialog.setWindowModality(m); + m_dialog.setWindowTitle(QPlatformMessageDialogHelper::options()->windowTitle()); + m_dialog.setIcon(static_cast<QMessageBox::Icon>(QPlatformMessageDialogHelper::options()->icon())); + if (!QPlatformMessageDialogHelper::options()->text().isNull()) + m_dialog.setText(QPlatformMessageDialogHelper::options()->text()); + if (!QPlatformMessageDialogHelper::options()->informativeText().isNull()) + m_dialog.setInformativeText(QPlatformMessageDialogHelper::options()->informativeText()); + if (!QPlatformMessageDialogHelper::options()->detailedText().isNull()) + m_dialog.setDetailedText(QPlatformMessageDialogHelper::options()->detailedText()); + m_dialog.setStandardButtons(static_cast<QMessageBox::StandardButtons>(static_cast<int>( + QPlatformMessageDialogHelper::options()->standardButtons()))); + m_dialog.show(); + return m_dialog.isVisible(); + } + + virtual void hide() { m_dialog.hide(); } + + QMessageBox m_dialog; + +public Q_SLOTS: + void buttonClicked(QAbstractButton* button) { + emit clicked(static_cast<QMessageDialogOptions::StandardButton>(m_dialog.standardButton(button)), + static_cast<QMessageDialogOptions::ButtonRole>(m_dialog.buttonRole(button))); + } +}; + +QT_END_NAMESPACE + +#endif // QMESSAGEBOXHELPER_P_H diff --git a/src/imports/widgets/qquickqmessagebox.cpp b/src/imports/widgets/qquickqmessagebox.cpp index 2f7c748c7b..1b92efc5ef 100644 --- a/src/imports/widgets/qquickqmessagebox.cpp +++ b/src/imports/widgets/qquickqmessagebox.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qquickqmessagebox_p.h" +#include "qmessageboxhelper_p.h" #include "qquickitem.h" #include <private/qguiapplication_p.h> @@ -51,42 +52,6 @@ QT_BEGIN_NAMESPACE -class QMessageBoxHelper : public QPlatformMessageDialogHelper -{ -public: - QMessageBoxHelper() { - connect(&m_dialog, SIGNAL(accepted()), this, SIGNAL(accept())); - connect(&m_dialog, SIGNAL(rejected()), this, SIGNAL(reject())); - } - - virtual void exec() { m_dialog.exec(); } - - virtual bool show(Qt::WindowFlags f, Qt::WindowModality m, QWindow *parent) { - m_dialog.winId(); - QWindow *window = m_dialog.windowHandle(); - Q_ASSERT(window); - window->setTransientParent(parent); - window->setFlags(f); - m_dialog.setWindowModality(m); - m_dialog.setWindowTitle(QPlatformMessageDialogHelper::options()->windowTitle()); - m_dialog.setIcon(static_cast<QMessageBox::Icon>(QPlatformMessageDialogHelper::options()->icon())); - if (!QPlatformMessageDialogHelper::options()->text().isNull()) - m_dialog.setText(QPlatformMessageDialogHelper::options()->text()); - if (!QPlatformMessageDialogHelper::options()->informativeText().isNull()) - m_dialog.setInformativeText(QPlatformMessageDialogHelper::options()->informativeText()); - if (!QPlatformMessageDialogHelper::options()->detailedText().isNull()) - m_dialog.setDetailedText(QPlatformMessageDialogHelper::options()->detailedText()); - m_dialog.setStandardButtons(static_cast<QMessageBox::StandardButtons>(static_cast<int>( - QPlatformMessageDialogHelper::options()->standardButtons()))); - m_dialog.show(); - return m_dialog.isVisible(); - } - - virtual void hide() { m_dialog.hide(); } - - QMessageBox m_dialog; -}; - /*! \qmltype QtMessageDialog \instantiates QQuickQMessageBox @@ -156,44 +121,6 @@ QQuickQMessageBox::~QQuickQMessageBox() delete m_dlgHelper; } -void QQuickQMessageBox::finished(int button) { - click(static_cast<StandardButton>(button)); -} - -void QQuickQMessageBox::clicked(QAbstractButton* button) { - QMessageBox &mb = static_cast<QMessageBoxHelper*>(QQuickAbstractMessageDialog::m_dlgHelper)->m_dialog; - switch (mb.buttonRole(button)) { - case QMessageBox::AcceptRole: - emit accepted(); - break; - case QMessageBox::RejectRole: - emit rejected(); - break; - case QMessageBox::DestructiveRole: - emit discard(); - break; - case QMessageBox::HelpRole: - emit help(); - break; - case QMessageBox::YesRole: - emit yes(); - break; - case QMessageBox::NoRole: - emit no(); - break; - case QMessageBox::ApplyRole: - emit apply(); - break; - case QMessageBox::ResetRole: - emit reset(); - break; - default: - qWarning("unhandled QMessageBox button role %d", mb.buttonRole(button)); - } - if (!mb.isVisible()) - setVisible(false); -} - QPlatformDialogHelper *QQuickQMessageBox::helper() { QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent()); @@ -203,10 +130,12 @@ QPlatformDialogHelper *QQuickQMessageBox::helper() if (!QQuickAbstractMessageDialog::m_dlgHelper) { QMessageBoxHelper* helper = new QMessageBoxHelper(); QQuickAbstractMessageDialog::m_dlgHelper = helper; + // accept() shouldn't be emitted. reject() happens only if the dialog is + // dismissed by closing the window rather than by one of its button widgets. connect(helper, SIGNAL(accept()), this, SLOT(accept())); connect(helper, SIGNAL(reject()), this, SLOT(reject())); - connect(&helper->m_dialog, SIGNAL(finished(int)), this, SLOT(finished(int))); - connect(&helper->m_dialog, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*))); + connect(helper, SIGNAL(clicked(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole)), + this, SLOT(click(QMessageDialogOptions::StandardButton, QMessageDialogOptions::ButtonRole))); } return QQuickAbstractMessageDialog::m_dlgHelper; diff --git a/src/imports/widgets/qquickqmessagebox_p.h b/src/imports/widgets/qquickqmessagebox_p.h index 9c3c1f2dd6..be91f1d02b 100644 --- a/src/imports/widgets/qquickqmessagebox_p.h +++ b/src/imports/widgets/qquickqmessagebox_p.h @@ -53,25 +53,16 @@ // We mean it. // -#include <QMessageBox> #include "../dialogs/qquickabstractmessagedialog_p.h" QT_BEGIN_NAMESPACE -class QAbstractButton; - class QQuickQMessageBox : public QQuickAbstractMessageDialog { - Q_OBJECT - public: QQuickQMessageBox(QObject *parent = 0); virtual ~QQuickQMessageBox(); -protected slots: - void clicked(QAbstractButton* button); - void finished(int button); - protected: virtual QPlatformDialogHelper *helper(); diff --git a/src/imports/widgets/widgets.pro b/src/imports/widgets/widgets.pro index 8c075945fd..5320838082 100644 --- a/src/imports/widgets/widgets.pro +++ b/src/imports/widgets/widgets.pro @@ -17,6 +17,7 @@ SOURCES += \ HEADERS += \ qquickqmessagebox_p.h \ + qmessageboxhelper_p.h \ ../dialogs/qquickabstractmessagedialog_p.h \ qquickqfiledialog_p.h \ ../dialogs/qquickabstractfiledialog_p.h \ |