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 "qwidgetplatformmessagedialog_p.h" |
5 | #include "qwidgetplatformdialog_p.h" |
6 | |
7 | #include <QtWidgets/qmessagebox.h> |
8 | #include <QtWidgets/qabstractbutton.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | QWidgetPlatformMessageDialog::QWidgetPlatformMessageDialog(QObject *parent) |
13 | : m_dialog(new QMessageBox) |
14 | { |
15 | setParent(parent); |
16 | |
17 | connect(sender: m_dialog.data(), signal: &QMessageBox::accepted, context: this, slot: &QPlatformDialogHelper::accept); |
18 | connect(sender: m_dialog.data(), signal: &QMessageBox::rejected, context: this, slot: &QPlatformDialogHelper::reject); |
19 | connect(sender: m_dialog.data(), signal: &QMessageBox::buttonClicked, slot: [this](QAbstractButton *button) { |
20 | QMessageBox::ButtonRole role = m_dialog->buttonRole(button); |
21 | QMessageBox::StandardButton standardButton = m_dialog->standardButton(button); |
22 | emit clicked(button: static_cast<StandardButton>(standardButton), role: static_cast<ButtonRole>(role)); |
23 | }); |
24 | } |
25 | |
26 | QWidgetPlatformMessageDialog::~QWidgetPlatformMessageDialog() |
27 | { |
28 | } |
29 | void QWidgetPlatformMessageDialog::exec() |
30 | { |
31 | m_dialog->exec(); |
32 | } |
33 | |
34 | bool QWidgetPlatformMessageDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) |
35 | { |
36 | QSharedPointer<QMessageDialogOptions> options = QPlatformMessageDialogHelper::options(); |
37 | m_dialog->setWindowTitle(options->windowTitle()); |
38 | m_dialog->setIcon(static_cast<QMessageBox::Icon>(options->standardIcon())); |
39 | m_dialog->setText(options->text()); |
40 | m_dialog->setInformativeText(options->informativeText()); |
41 | #if QT_CONFIG(textedit) |
42 | m_dialog->setDetailedText(options->detailedText()); |
43 | #endif |
44 | m_dialog->setStandardButtons(static_cast<QMessageBox::StandardButtons>(int(options->standardButtons()))); |
45 | |
46 | return QWidgetPlatformDialog::show(dialog: m_dialog.data(), flags, modality, parent); |
47 | } |
48 | |
49 | void QWidgetPlatformMessageDialog::hide() |
50 | { |
51 | m_dialog->hide(); |
52 | } |
53 | |
54 | QT_END_NAMESPACE |
55 | |
56 | #include "moc_qwidgetplatformmessagedialog_p.cpp" |
57 | |