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 "qquickqmessagebox_p.h"
41#include "qmessageboxhelper_p.h"
42#include "qquickitem.h"
43
44#include <private/qguiapplication_p.h>
45#include <private/qqmlcontext_p.h>
46#include <QWindow>
47#include <QQuickWindow>
48#include <QMessageBox>
49#include <QAbstractButton>
50
51QT_BEGIN_NAMESPACE
52
53/*!
54 \qmltype QtMessageDialog
55 \instantiates QQuickQMessageBox
56 \inqmlmodule QtQuick.PrivateWidgets
57 \ingroup qtquick-visual
58 \brief Dialog component for choosing a color.
59 \since 5.2
60 \internal
61
62 QtMessageDialog provides a means to instantiate and manage a QMessageBox.
63 It is not recommended to be used directly; it is an implementation
64 detail of \l MessageDialog in the \l QtQuick.Dialogs module.
65
66 To use this type, you will need to import the module with the following line:
67 \code
68 import QtQuick.PrivateWidgets 1.1
69 \endcode
70*/
71
72/*!
73 \qmlsignal QtQuick::Dialogs::MessageDialog::accepted
74
75 The \a accepted signal is emitted when the user has pressed the OK button
76 on the dialog.
77
78 Example:
79
80 \qml
81 MessageDialog {
82 onAccepted: { console.log("accepted") }
83 }
84 \endqml
85
86 The corresponding handler is \c onAccepted.
87*/
88
89/*!
90 \qmlsignal QtQuick::Dialogs::MessageDialog::rejected
91
92 The \a rejected signal is emitted when the user has dismissed the dialog,
93 either by closing the dialog window or by pressing the Cancel button.
94
95 The corresponding handler is \c onRejected.
96*/
97
98/*!
99 \class QQuickQMessageBox
100 \inmodule QtQuick.PrivateWidgets
101 \internal
102
103 \brief The QQuickQMessageBox class is a wrapper for a QMessageBox.
104
105 \since 5.2
106*/
107
108/*!
109 Constructs a message dialog with parent window \a parent.
110*/
111QQuickQMessageBox::QQuickQMessageBox(QObject *parent)
112 : QQuickAbstractMessageDialog(parent)
113{
114}
115
116/*!
117 Destroys the message dialog.
118*/
119QQuickQMessageBox::~QQuickQMessageBox()
120{
121 if (m_dlgHelper)
122 m_dlgHelper->hide();
123 delete m_dlgHelper;
124}
125
126QPlatformDialogHelper *QQuickQMessageBox::helper()
127{
128 QQuickItem *parentItem = qobject_cast<QQuickItem *>(object: parent());
129 if (parentItem)
130 m_parentWindow = parentItem->window();
131
132 if (!QQuickAbstractMessageDialog::m_dlgHelper) {
133 QMessageBoxHelper* helper = new QMessageBoxHelper();
134 QQuickAbstractMessageDialog::m_dlgHelper = helper;
135 // accept() shouldn't be emitted. reject() happens only if the dialog is
136 // dismissed by closing the window rather than by one of its button widgets.
137 connect(sender: helper, SIGNAL(accept()), receiver: this, SLOT(accept()));
138 connect(sender: helper, SIGNAL(reject()), receiver: this, SLOT(reject()));
139 connect(sender: helper, SIGNAL(clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)),
140 receiver: this, SLOT(click(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)));
141 }
142
143 return QQuickAbstractMessageDialog::m_dlgHelper;
144}
145
146QT_END_NAMESPACE
147

source code of qtquickcontrols/src/widgets/qquickqmessagebox.cpp