1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquicklabsplatformmessagedialog_p.h"
5
6#if QT_DEPRECATED_SINCE(6, 9)
7
8#include <QtQml/qqmlinfo.h>
9
10QT_BEGIN_NAMESPACE
11
12/*!
13 \qmltype MessageDialog
14 \inherits Dialog
15//! \nativetype QQuickLabsPlatformMessageDialog
16 \inqmlmodule Qt.labs.platform
17 \since 5.8
18 \deprecated [6.9] Use QtQuick.Dialogs::MessageDialog instead.
19 \brief A native message dialog.
20
21 The MessageDialog type provides a QML API for native platform message dialogs.
22
23 \image {qtlabsplatform-messagedialog-android.png} {A native message dialog}
24
25 A message dialog is used to inform the user, or ask the user a question.
26 A message dialog displays a primary \l text to alert the user to a situation,
27 an \l {informativeText}{informative text} to further explain the alert or to
28 ask the user a question, and an optional \l {detailedText}{detailed text} to
29 provide even more data if the user requests it. A message box can also display
30 a configurable set of \l buttons for accepting a user response.
31
32 To show a message dialog, construct an instance of MessageDialog, set the
33 desired properties, and call \l {Dialog::}{open()}.
34
35 \code
36 MessageDialog {
37 buttons: MessageDialog.Ok
38 text: "The document has been modified."
39 }
40 \endcode
41
42 The user must click the \uicontrol OK button to dismiss the message dialog.
43 A modal message dialog blocks the rest of the GUI until the message is
44 dismissed.
45
46 A more elaborate approach than just alerting the user to an event is to
47 also ask the user what to do about it. Store the question in the
48 \l {informativeText}{informative text} property, and specify the \l buttons
49 property to the set of buttons you want as the set of user responses. The
50 buttons are specified by combining values using the bitwise OR operator. The
51 display order for the buttons is platform dependent.
52
53 \code
54 MessageDialog {
55 text: "The document has been modified."
56 informativeText: "Do you want to save your changes?"
57 buttons: MessageDialog.Ok | MessageDialog.Cancel
58
59 onAccepted: document.save()
60 }
61 \endcode
62
63 \image {qtlabsplatform-messagedialog-informative-android.png} {A native informative message dialog}
64
65 The \l clicked() signal passes the information of which button was clicked.
66
67 A native platform message dialog is currently available on the following platforms:
68
69 \list
70 \li Android
71 \li iOS
72 \li macOS
73 \endlist
74
75 \input includes/widgets.qdocinc 1
76
77 \labs
78
79 \sa QtQuick.Dialogs::MessageDialog
80*/
81
82/*!
83 \qmlsignal Qt.labs.platform::MessageDialog::clicked(button)
84
85 This signal is emitted when a dialog \a button is clicked.
86
87 \sa buttons
88*/
89
90/*!
91 \qmlsignal Qt.labs.platform::MessageDialog::okClicked()
92
93 This signal is emitted when \uicontrol Ok is clicked.
94*/
95
96/*!
97 \qmlsignal Qt.labs.platform::MessageDialog::saveClicked()
98
99 This signal is emitted when \uicontrol Save is clicked.
100*/
101
102/*!
103 \qmlsignal Qt.labs.platform::MessageDialog::saveAllClicked()
104
105 This signal is emitted when \uicontrol {Save All} is clicked.
106*/
107
108/*!
109 \qmlsignal Qt.labs.platform::MessageDialog::openClicked()
110
111 This signal is emitted when \uicontrol Open is clicked.
112*/
113
114/*!
115 \qmlsignal Qt.labs.platform::MessageDialog::yesClicked()
116
117 This signal is emitted when \uicontrol Yes is clicked.
118*/
119
120/*!
121 \qmlsignal Qt.labs.platform::MessageDialog::yesToAllClicked()
122
123 This signal is emitted when \uicontrol {Yes To All} is clicked.
124*/
125
126/*!
127 \qmlsignal Qt.labs.platform::MessageDialog::noClicked()
128
129 This signal is emitted when \uicontrol No is clicked.
130*/
131
132/*!
133 \qmlsignal Qt.labs.platform::MessageDialog::noToAllClicked()
134
135 This signal is emitted when \uicontrol {No To All} is clicked.
136*/
137
138/*!
139 \qmlsignal Qt.labs.platform::MessageDialog::abortClicked()
140
141 This signal is emitted when \uicontrol Abort is clicked.
142*/
143
144/*!
145 \qmlsignal Qt.labs.platform::MessageDialog::retryClicked()
146
147 This signal is emitted when \uicontrol Retry is clicked.
148*/
149
150/*!
151 \qmlsignal Qt.labs.platform::MessageDialog::ignoreClicked()
152
153 This signal is emitted when \uicontrol Ignore is clicked.
154*/
155
156/*!
157 \qmlsignal Qt.labs.platform::MessageDialog::closeClicked()
158
159 This signal is emitted when \uicontrol Close is clicked.
160*/
161
162/*!
163 \qmlsignal Qt.labs.platform::MessageDialog::cancelClicked()
164
165 This signal is emitted when \uicontrol Cancel is clicked.
166*/
167
168/*!
169 \qmlsignal Qt.labs.platform::MessageDialog::discardClicked()
170
171 This signal is emitted when \uicontrol Discard is clicked.
172*/
173
174/*!
175 \qmlsignal Qt.labs.platform::MessageDialog::helpClicked()
176
177 This signal is emitted when \uicontrol Help is clicked.
178*/
179
180/*!
181 \qmlsignal Qt.labs.platform::MessageDialog::applyClicked()
182
183 This signal is emitted when \uicontrol Apply is clicked.
184*/
185
186/*!
187 \qmlsignal Qt.labs.platform::MessageDialog::resetClicked()
188
189 This signal is emitted when \uicontrol Reset is clicked.
190*/
191
192/*!
193 \qmlsignal Qt.labs.platform::MessageDialog::restoreDefaultsClicked()
194
195 This signal is emitted when \uicontrol {Restore Defaults} is clicked.
196*/
197
198QQuickLabsPlatformMessageDialog::QQuickLabsPlatformMessageDialog(QObject *parent)
199 : QQuickLabsPlatformDialog(QPlatformTheme::MessageDialog, parent),
200 m_options(QMessageDialogOptions::create())
201{
202}
203
204/*!
205 \qmlproperty string Qt.labs.platform::MessageDialog::text
206
207 This property holds the text to be displayed on the message dialog.
208
209 \sa informativeText, detailedText
210*/
211QString QQuickLabsPlatformMessageDialog::text() const
212{
213 return m_options->text();
214}
215
216void QQuickLabsPlatformMessageDialog::setText(const QString &text)
217{
218 if (m_options->text() == text)
219 return;
220
221 m_options->setText(text);
222 emit textChanged();
223}
224
225/*!
226 \qmlproperty string Qt.labs.platform::MessageDialog::informativeText
227
228 This property holds the informative text that provides a fuller description for the message.
229
230 Informative text can be used to expand upon the \l text to give more information to the user.
231
232 \sa text, detailedText
233*/
234QString QQuickLabsPlatformMessageDialog::informativeText() const
235{
236 return m_options->informativeText();
237}
238
239void QQuickLabsPlatformMessageDialog::setInformativeText(const QString &text)
240{
241 if (m_options->informativeText() == text)
242 return;
243
244 m_options->setInformativeText(text);
245 emit informativeTextChanged();
246}
247
248/*!
249 \qmlproperty string Qt.labs.platform::MessageDialog::detailedText
250
251 This property holds the text to be displayed in the details area.
252
253 \sa text, informativeText
254*/
255QString QQuickLabsPlatformMessageDialog::detailedText() const
256{
257 return m_options->detailedText();
258}
259
260void QQuickLabsPlatformMessageDialog::setDetailedText(const QString &text)
261{
262 if (m_options->detailedText() == text)
263 return;
264
265 m_options->setDetailedText(text);
266 emit detailedTextChanged();
267}
268
269/*!
270 \qmlproperty flags Qt.labs.platform::MessageDialog::buttons
271
272 This property holds a combination of buttons that are used by the message dialog.
273 The default value is \c MessageDialog.NoButton.
274
275 Possible flags:
276 \value MessageDialog.Ok An "OK" button defined with the \c AcceptRole.
277 \value MessageDialog.Open An "Open" button defined with the \c AcceptRole.
278 \value MessageDialog.Save A "Save" button defined with the \c AcceptRole.
279 \value MessageDialog.Cancel A "Cancel" button defined with the \c RejectRole.
280 \value MessageDialog.Close A "Close" button defined with the \c RejectRole.
281 \value MessageDialog.Discard A "Discard" or "Don't Save" button, depending on the platform, defined with the \c DestructiveRole.
282 \value MessageDialog.Apply An "Apply" button defined with the \c ApplyRole.
283 \value MessageDialog.Reset A "Reset" button defined with the \c ResetRole.
284 \value MessageDialog.RestoreDefaults A "Restore Defaults" button defined with the \c ResetRole.
285 \value MessageDialog.Help A "Help" button defined with the \c HelpRole.
286 \value MessageDialog.SaveAll A "Save All" button defined with the \c AcceptRole.
287 \value MessageDialog.Yes A "Yes" button defined with the \c YesRole.
288 \value MessageDialog.YesToAll A "Yes to All" button defined with the \c YesRole.
289 \value MessageDialog.No A "No" button defined with the \c NoRole.
290 \value MessageDialog.NoToAll A "No to All" button defined with the \c NoRole.
291 \value MessageDialog.Abort An "Abort" button defined with the \c RejectRole.
292 \value MessageDialog.Retry A "Retry" button defined with the \c AcceptRole.
293 \value MessageDialog.Ignore An "Ignore" button defined with the \c AcceptRole.
294 \value MessageDialog.NoButton The dialog has no buttons.
295
296 \sa clicked()
297*/
298QPlatformDialogHelper::StandardButtons QQuickLabsPlatformMessageDialog::buttons() const
299{
300 return m_options->standardButtons();
301}
302
303void QQuickLabsPlatformMessageDialog::setButtons(QPlatformDialogHelper::StandardButtons buttons)
304{
305 if (m_options->standardButtons() == buttons)
306 return;
307
308 m_options->setStandardButtons(buttons);
309 emit buttonsChanged();
310}
311
312void QQuickLabsPlatformMessageDialog::onCreate(QPlatformDialogHelper *dialog)
313{
314 if (QPlatformMessageDialogHelper *messageDialog = qobject_cast<QPlatformMessageDialogHelper *>(object: dialog)) {
315 connect(sender: messageDialog, signal: &QPlatformMessageDialogHelper::clicked, context: this, slot: &QQuickLabsPlatformMessageDialog::handleClick);
316 messageDialog->setOptions(m_options);
317 }
318}
319
320void QQuickLabsPlatformMessageDialog::onShow(QPlatformDialogHelper *dialog)
321{
322 m_options->setWindowTitle(title());
323 if (QPlatformMessageDialogHelper *messageDialog = qobject_cast<QPlatformMessageDialogHelper *>(object: dialog))
324 messageDialog->setOptions(m_options);
325}
326
327void QQuickLabsPlatformMessageDialog::handleClick(QPlatformDialogHelper::StandardButton button)
328{
329 done(result: button);
330 emit clicked(button);
331
332 switch (button) {
333 case QPlatformDialogHelper::Ok: emit okClicked(); break;
334 case QPlatformDialogHelper::Save: emit saveClicked(); break;
335 case QPlatformDialogHelper::SaveAll: emit saveAllClicked(); break;
336 case QPlatformDialogHelper::Open: emit openClicked(); break;
337 case QPlatformDialogHelper::Yes: emit yesClicked(); break;
338 case QPlatformDialogHelper::YesToAll: emit yesToAllClicked(); break;
339 case QPlatformDialogHelper::No: emit noClicked(); break;
340 case QPlatformDialogHelper::NoToAll: emit noToAllClicked(); break;
341 case QPlatformDialogHelper::Abort: emit abortClicked(); break;
342 case QPlatformDialogHelper::Retry: emit retryClicked(); break;
343 case QPlatformDialogHelper::Ignore: emit ignoreClicked(); break;
344 case QPlatformDialogHelper::Close: emit closeClicked(); break;
345 case QPlatformDialogHelper::Cancel: emit cancelClicked(); break;
346 case QPlatformDialogHelper::Discard: emit discardClicked(); break;
347 case QPlatformDialogHelper::Help: emit helpClicked(); break;
348 case QPlatformDialogHelper::Apply: emit applyClicked(); break;
349 case QPlatformDialogHelper::Reset: emit resetClicked(); break;
350 case QPlatformDialogHelper::RestoreDefaults: emit restoreDefaultsClicked(); break;
351 default: qmlWarning(me: this) << "unknown button" << int(button); break;
352 }
353}
354
355QT_END_NAMESPACE
356
357#include "moc_qquicklabsplatformmessagedialog_p.cpp"
358
359#endif // QT_DEPRECATED_SINCE(6, 9)
360

source code of qtdeclarative/src/labs/platform/qquicklabsplatformmessagedialog.cpp