| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Quick Dialogs module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qquickabstractmessagedialog_p.h" |
| 41 | #include <QtGui/qpa/qplatformdialoghelper.h> |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | QQuickAbstractMessageDialog::QQuickAbstractMessageDialog(QObject *parent) |
| 46 | : QQuickAbstractDialog(parent) |
| 47 | , m_dlgHelper(0) |
| 48 | , m_options(QMessageDialogOptions::create()) |
| 49 | , m_clickedButton(NoButton) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | QQuickAbstractMessageDialog::~QQuickAbstractMessageDialog() |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | void QQuickAbstractMessageDialog::setVisible(bool v) |
| 58 | { |
| 59 | if (helper() && v) |
| 60 | m_dlgHelper->setOptions(m_options); |
| 61 | if (v) |
| 62 | m_clickedButton = NoButton; |
| 63 | QQuickAbstractDialog::setVisible(v); |
| 64 | } |
| 65 | |
| 66 | void QQuickAbstractMessageDialog::setTitle(const QString &arg) |
| 67 | { |
| 68 | if (arg != m_options->windowTitle()) { |
| 69 | m_options->setWindowTitle(arg); |
| 70 | emit titleChanged(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | void QQuickAbstractMessageDialog::setText(const QString &arg) |
| 75 | { |
| 76 | if (arg != m_options->text()) { |
| 77 | m_options->setText(arg); |
| 78 | emit textChanged(); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void QQuickAbstractMessageDialog::setInformativeText(const QString &arg) |
| 83 | { |
| 84 | if (arg != m_options->informativeText()) { |
| 85 | m_options->setInformativeText(arg); |
| 86 | emit informativeTextChanged(); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | void QQuickAbstractMessageDialog::setDetailedText(const QString &arg) |
| 91 | { |
| 92 | if (arg != m_options->detailedText()) { |
| 93 | m_options->setDetailedText(arg); |
| 94 | emit detailedTextChanged(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void QQuickAbstractMessageDialog::setIcon(QQuickAbstractMessageDialog::Icon icon) |
| 99 | { |
| 100 | if (static_cast<int>(icon) != static_cast<int>(m_options->icon())) { |
| 101 | m_options->setIcon(static_cast<QMessageDialogOptions::Icon>(icon)); |
| 102 | emit iconChanged(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | QUrl QQuickAbstractMessageDialog::standardIconSource() |
| 107 | { |
| 108 | switch (m_options->icon()) { |
| 109 | case QMessageDialogOptions::Information: |
| 110 | return QUrl("images/information.png" ); |
| 111 | break; |
| 112 | case QMessageDialogOptions::Warning: |
| 113 | return QUrl("images/warning.png" ); |
| 114 | break; |
| 115 | case QMessageDialogOptions::Critical: |
| 116 | return QUrl("images/critical.png" ); |
| 117 | break; |
| 118 | case QMessageDialogOptions::Question: |
| 119 | return QUrl("images/question.png" ); |
| 120 | break; |
| 121 | default: |
| 122 | return QUrl(); |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void QQuickAbstractMessageDialog::setStandardButtons(StandardButtons buttons) |
| 128 | { |
| 129 | if (buttons != m_options->standardButtons()) { |
| 130 | m_options->setStandardButtons(static_cast<QPlatformDialogHelper::StandardButtons>(static_cast<int>(buttons))); |
| 131 | emit standardButtonsChanged(); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void QQuickAbstractMessageDialog::click(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role) |
| 136 | { |
| 137 | setVisible(false); |
| 138 | m_clickedButton = static_cast<StandardButton>(button); |
| 139 | emit buttonClicked(); |
| 140 | switch (role) { |
| 141 | case QPlatformDialogHelper::AcceptRole: |
| 142 | accept(); |
| 143 | break; |
| 144 | case QPlatformDialogHelper::RejectRole: |
| 145 | reject(); |
| 146 | break; |
| 147 | case QPlatformDialogHelper::DestructiveRole: |
| 148 | emit discard(); |
| 149 | break; |
| 150 | case QPlatformDialogHelper::HelpRole: |
| 151 | emit help(); |
| 152 | break; |
| 153 | case QPlatformDialogHelper::YesRole: |
| 154 | emit yes(); |
| 155 | break; |
| 156 | case QPlatformDialogHelper::NoRole: |
| 157 | emit no(); |
| 158 | break; |
| 159 | case QPlatformDialogHelper::ApplyRole: |
| 160 | emit apply(); |
| 161 | break; |
| 162 | case QPlatformDialogHelper::ResetRole: |
| 163 | emit reset(); |
| 164 | break; |
| 165 | default: |
| 166 | qWarning(msg: "unhandled MessageDialog button %d with role %d" , (int)button, (int)role); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | void QQuickAbstractMessageDialog::click(QQuickAbstractDialog::StandardButton button) |
| 171 | { |
| 172 | click(button: static_cast<QPlatformDialogHelper::StandardButton>(button), |
| 173 | role: static_cast<QPlatformDialogHelper::ButtonRole>( |
| 174 | QPlatformDialogHelper::buttonRole(button: static_cast<QPlatformDialogHelper::StandardButton>(button)))); |
| 175 | } |
| 176 | |
| 177 | QT_END_NAMESPACE |
| 178 | |