Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qdialog.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qcolordialog.h" | - | ||||||||||||||||||||||||
35 | #include "qfontdialog.h" | - | ||||||||||||||||||||||||
36 | #include "qfiledialog.h" | - | ||||||||||||||||||||||||
37 | - | |||||||||||||||||||||||||
38 | #include "qevent.h" | - | ||||||||||||||||||||||||
39 | #include "qdesktopwidget.h" | - | ||||||||||||||||||||||||
40 | #include "qpushbutton.h" | - | ||||||||||||||||||||||||
41 | #include "qapplication.h" | - | ||||||||||||||||||||||||
42 | #include "qlayout.h" | - | ||||||||||||||||||||||||
43 | #include "qsizegrip.h" | - | ||||||||||||||||||||||||
44 | #include "qwhatsthis.h" | - | ||||||||||||||||||||||||
45 | #include "qmenu.h" | - | ||||||||||||||||||||||||
46 | #include "qcursor.h" | - | ||||||||||||||||||||||||
47 | #include "qmessagebox.h" | - | ||||||||||||||||||||||||
48 | #include "qerrormessage.h" | - | ||||||||||||||||||||||||
49 | #include <qpa/qplatformtheme.h> | - | ||||||||||||||||||||||||
50 | #include "private/qdialog_p.h" | - | ||||||||||||||||||||||||
51 | #include "private/qguiapplication_p.h" | - | ||||||||||||||||||||||||
52 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
53 | #include "qaccessible.h" | - | ||||||||||||||||||||||||
54 | #endif | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||
58 | static inline int themeDialogType(const QDialog *dialog) | - | ||||||||||||||||||||||||
59 | { | - | ||||||||||||||||||||||||
60 | #ifndef QT_NO_FILEDIALOG | - | ||||||||||||||||||||||||
61 | if (qobject_cast<const QFileDialog *>(dialog))
| 0 | ||||||||||||||||||||||||
62 | return QPlatformTheme::FileDialog; never executed: return QPlatformTheme::FileDialog; | 0 | ||||||||||||||||||||||||
63 | #endif | - | ||||||||||||||||||||||||
64 | #ifndef QT_NO_COLORDIALOG | - | ||||||||||||||||||||||||
65 | if (qobject_cast<const QColorDialog *>(dialog))
| 0 | ||||||||||||||||||||||||
66 | return QPlatformTheme::ColorDialog; never executed: return QPlatformTheme::ColorDialog; | 0 | ||||||||||||||||||||||||
67 | #endif | - | ||||||||||||||||||||||||
68 | #ifndef QT_NO_FONTDIALOG | - | ||||||||||||||||||||||||
69 | if (qobject_cast<const QFontDialog *>(dialog))
| 0 | ||||||||||||||||||||||||
70 | return QPlatformTheme::FontDialog; never executed: return QPlatformTheme::FontDialog; | 0 | ||||||||||||||||||||||||
71 | #endif | - | ||||||||||||||||||||||||
72 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||||||||||||||
73 | if (qobject_cast<const QMessageBox *>(dialog))
| 0 | ||||||||||||||||||||||||
74 | return QPlatformTheme::MessageDialog; never executed: return QPlatformTheme::MessageDialog; | 0 | ||||||||||||||||||||||||
75 | #endif | - | ||||||||||||||||||||||||
76 | #ifndef QT_NO_ERRORMESSAGE | - | ||||||||||||||||||||||||
77 | if (qobject_cast<const QErrorMessage *>(dialog))
| 0 | ||||||||||||||||||||||||
78 | return QPlatformTheme::MessageDialog; never executed: return QPlatformTheme::MessageDialog; | 0 | ||||||||||||||||||||||||
79 | #endif | - | ||||||||||||||||||||||||
80 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
81 | } | - | ||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||
83 | QPlatformDialogHelper *QDialogPrivate::platformHelper() const | - | ||||||||||||||||||||||||
84 | { | - | ||||||||||||||||||||||||
85 | // Delayed creation of the platform, ensuring that | - | ||||||||||||||||||||||||
86 | // that qobject_cast<> on the dialog works in the plugin. | - | ||||||||||||||||||||||||
87 | if (!m_platformHelperCreated) {
| 0 | ||||||||||||||||||||||||
88 | m_platformHelperCreated = true; | - | ||||||||||||||||||||||||
89 | QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this); | - | ||||||||||||||||||||||||
90 | QDialog *dialog = ncThis->q_func(); | - | ||||||||||||||||||||||||
91 | const int type = themeDialogType(dialog); | - | ||||||||||||||||||||||||
92 | if (type >= 0) {
| 0 | ||||||||||||||||||||||||
93 | m_platformHelper = QGuiApplicationPrivate::platformTheme() | - | ||||||||||||||||||||||||
94 | ->createPlatformDialogHelper(static_cast<QPlatformTheme::DialogType>(type)); | - | ||||||||||||||||||||||||
95 | if (m_platformHelper) {
| 0 | ||||||||||||||||||||||||
96 | QObject::connect(m_platformHelper, SIGNAL(accept()), dialog, SLOT(accept())); | - | ||||||||||||||||||||||||
97 | QObject::connect(m_platformHelper, SIGNAL(reject()), dialog, SLOT(reject())); | - | ||||||||||||||||||||||||
98 | ncThis->initHelper(m_platformHelper); | - | ||||||||||||||||||||||||
99 | } never executed: end of block | 0 | ||||||||||||||||||||||||
100 | } never executed: end of block | 0 | ||||||||||||||||||||||||
101 | } never executed: end of block | 0 | ||||||||||||||||||||||||
102 | return m_platformHelper; never executed: return m_platformHelper; | 0 | ||||||||||||||||||||||||
103 | } | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | bool QDialogPrivate::canBeNativeDialog() const | - | ||||||||||||||||||||||||
106 | { | - | ||||||||||||||||||||||||
107 | QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this); | - | ||||||||||||||||||||||||
108 | QDialog *dialog = ncThis->q_func(); | - | ||||||||||||||||||||||||
109 | const int type = themeDialogType(dialog); | - | ||||||||||||||||||||||||
110 | if (type >= 0)
| 0 | ||||||||||||||||||||||||
111 | return QGuiApplicationPrivate::platformTheme() never executed: return QGuiApplicationPrivate::platformTheme() ->usePlatformNativeDialog(static_cast<QPlatformTheme::DialogType>(type)); | 0 | ||||||||||||||||||||||||
112 | ->usePlatformNativeDialog(static_cast<QPlatformTheme::DialogType>(type)); never executed: return QGuiApplicationPrivate::platformTheme() ->usePlatformNativeDialog(static_cast<QPlatformTheme::DialogType>(type)); | 0 | ||||||||||||||||||||||||
113 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
114 | } | - | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | QWindow *QDialogPrivate::parentWindow() const | - | ||||||||||||||||||||||||
117 | { | - | ||||||||||||||||||||||||
118 | if (const QWidget *parent = q_func()->nativeParentWidget())
| 0 | ||||||||||||||||||||||||
119 | return parent->windowHandle(); never executed: return parent->windowHandle(); | 0 | ||||||||||||||||||||||||
120 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
121 | } | - | ||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | bool QDialogPrivate::setNativeDialogVisible(bool visible) | - | ||||||||||||||||||||||||
124 | { | - | ||||||||||||||||||||||||
125 | if (QPlatformDialogHelper *helper = platformHelper()) {
| 0 | ||||||||||||||||||||||||
126 | if (visible) {
| 0 | ||||||||||||||||||||||||
127 | Q_Q(QDialog); | - | ||||||||||||||||||||||||
128 | helperPrepareShow(helper); | - | ||||||||||||||||||||||||
129 | nativeDialogInUse = helper->show(q->windowFlags(), q->windowModality(), parentWindow()); | - | ||||||||||||||||||||||||
130 | } else if (nativeDialogInUse) { never executed: end of block
| 0 | ||||||||||||||||||||||||
131 | helper->hide(); | - | ||||||||||||||||||||||||
132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
133 | } never executed: end of block | 0 | ||||||||||||||||||||||||
134 | return nativeDialogInUse; never executed: return nativeDialogInUse; | 0 | ||||||||||||||||||||||||
135 | } | - | ||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const | - | ||||||||||||||||||||||||
138 | { | - | ||||||||||||||||||||||||
139 | if (const QPlatformDialogHelper *helper = platformHelper())
| 0 | ||||||||||||||||||||||||
140 | return helper->styleHint(hint); never executed: return helper->styleHint(hint); | 0 | ||||||||||||||||||||||||
141 | return QPlatformDialogHelper::defaultStyleHint(hint); never executed: return QPlatformDialogHelper::defaultStyleHint(hint); | 0 | ||||||||||||||||||||||||
142 | } | - | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | void QDialogPrivate::deletePlatformHelper() | - | ||||||||||||||||||||||||
145 | { | - | ||||||||||||||||||||||||
146 | delete m_platformHelper; | - | ||||||||||||||||||||||||
147 | m_platformHelper = 0; | - | ||||||||||||||||||||||||
148 | m_platformHelperCreated = false; | - | ||||||||||||||||||||||||
149 | nativeDialogInUse = false; | - | ||||||||||||||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | /*! | - | ||||||||||||||||||||||||
153 | \class QDialog | - | ||||||||||||||||||||||||
154 | \brief The QDialog class is the base class of dialog windows. | - | ||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | \ingroup dialog-classes | - | ||||||||||||||||||||||||
157 | \ingroup abstractwidgets | - | ||||||||||||||||||||||||
158 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | A dialog window is a top-level window mostly used for short-term | - | ||||||||||||||||||||||||
161 | tasks and brief communications with the user. QDialogs may be | - | ||||||||||||||||||||||||
162 | modal or modeless. QDialogs can | - | ||||||||||||||||||||||||
163 | provide a \l{#return}{return value}, and they can have \l{#default}{default buttons}. QDialogs can also have a QSizeGrip in their | - | ||||||||||||||||||||||||
164 | lower-right corner, using setSizeGripEnabled(). | - | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | Note that QDialog (and any other widget that has type \c Qt::Dialog) uses | - | ||||||||||||||||||||||||
167 | the parent widget slightly differently from other classes in Qt. A dialog is | - | ||||||||||||||||||||||||
168 | always a top-level widget, but if it has a parent, its default location is | - | ||||||||||||||||||||||||
169 | centered on top of the parent's top-level widget (if it is not top-level | - | ||||||||||||||||||||||||
170 | itself). It will also share the parent's taskbar entry. | - | ||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||
172 | Use the overload of the QWidget::setParent() function to change | - | ||||||||||||||||||||||||
173 | the ownership of a QDialog widget. This function allows you to | - | ||||||||||||||||||||||||
174 | explicitly set the window flags of the reparented widget; using | - | ||||||||||||||||||||||||
175 | the overloaded function will clear the window flags specifying the | - | ||||||||||||||||||||||||
176 | window-system properties for the widget (in particular it will | - | ||||||||||||||||||||||||
177 | reset the Qt::Dialog flag). | - | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | \section1 Modal Dialogs | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | A \b{modal} dialog is a dialog that blocks input to other | - | ||||||||||||||||||||||||
182 | visible windows in the same application. Dialogs that are used to | - | ||||||||||||||||||||||||
183 | request a file name from the user or that are used to set | - | ||||||||||||||||||||||||
184 | application preferences are usually modal. Dialogs can be | - | ||||||||||||||||||||||||
185 | \l{Qt::ApplicationModal}{application modal} (the default) or | - | ||||||||||||||||||||||||
186 | \l{Qt::WindowModal}{window modal}. | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | When an application modal dialog is opened, the user must finish | - | ||||||||||||||||||||||||
189 | interacting with the dialog and close it before they can access | - | ||||||||||||||||||||||||
190 | any other window in the application. Window modal dialogs only | - | ||||||||||||||||||||||||
191 | block access to the window associated with the dialog, allowing | - | ||||||||||||||||||||||||
192 | the user to continue to use other windows in an application. | - | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | The most common way to display a modal dialog is to call its | - | ||||||||||||||||||||||||
195 | exec() function. When the user closes the dialog, exec() will | - | ||||||||||||||||||||||||
196 | provide a useful \l{#return}{return value}. Typically, | - | ||||||||||||||||||||||||
197 | to get the dialog to close and return the appropriate value, we | - | ||||||||||||||||||||||||
198 | connect a default button, e.g. \uicontrol OK, to the accept() slot and a | - | ||||||||||||||||||||||||
199 | \uicontrol Cancel button to the reject() slot. | - | ||||||||||||||||||||||||
200 | Alternatively you can call the done() slot with \c Accepted or | - | ||||||||||||||||||||||||
201 | \c Rejected. | - | ||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||
203 | An alternative is to call setModal(true) or setWindowModality(), | - | ||||||||||||||||||||||||
204 | then show(). Unlike exec(), show() returns control to the caller | - | ||||||||||||||||||||||||
205 | immediately. Calling setModal(true) is especially useful for | - | ||||||||||||||||||||||||
206 | progress dialogs, where the user must have the ability to interact | - | ||||||||||||||||||||||||
207 | with the dialog, e.g. to cancel a long running operation. If you | - | ||||||||||||||||||||||||
208 | use show() and setModal(true) together to perform a long operation, | - | ||||||||||||||||||||||||
209 | you must call QApplication::processEvents() periodically during | - | ||||||||||||||||||||||||
210 | processing to enable the user to interact with the dialog. (See | - | ||||||||||||||||||||||||
211 | QProgressDialog.) | - | ||||||||||||||||||||||||
212 | - | |||||||||||||||||||||||||
213 | \section1 Modeless Dialogs | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | A \b{modeless} dialog is a dialog that operates | - | ||||||||||||||||||||||||
216 | independently of other windows in the same application. Find and | - | ||||||||||||||||||||||||
217 | replace dialogs in word-processors are often modeless to allow the | - | ||||||||||||||||||||||||
218 | user to interact with both the application's main window and with | - | ||||||||||||||||||||||||
219 | the dialog. | - | ||||||||||||||||||||||||
220 | - | |||||||||||||||||||||||||
221 | Modeless dialogs are displayed using show(), which returns control | - | ||||||||||||||||||||||||
222 | to the caller immediately. | - | ||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||
224 | If you invoke the \l{QWidget::show()}{show()} function after hiding | - | ||||||||||||||||||||||||
225 | a dialog, the dialog will be displayed in its original position. This is | - | ||||||||||||||||||||||||
226 | because the window manager decides the position for windows that | - | ||||||||||||||||||||||||
227 | have not been explicitly placed by the programmer. To preserve the | - | ||||||||||||||||||||||||
228 | position of a dialog that has been moved by the user, save its position | - | ||||||||||||||||||||||||
229 | in your \l{QWidget::closeEvent()}{closeEvent()} handler and then | - | ||||||||||||||||||||||||
230 | move the dialog to that position, before showing it again. | - | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | \target default | - | ||||||||||||||||||||||||
233 | \section1 Default Button | - | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | A dialog's \e default button is the button that's pressed when the | - | ||||||||||||||||||||||||
236 | user presses Enter (Return). This button is used to signify that | - | ||||||||||||||||||||||||
237 | the user accepts the dialog's settings and wants to close the | - | ||||||||||||||||||||||||
238 | dialog. Use QPushButton::setDefault(), QPushButton::isDefault() | - | ||||||||||||||||||||||||
239 | and QPushButton::autoDefault() to set and control the dialog's | - | ||||||||||||||||||||||||
240 | default button. | - | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | \target escapekey | - | ||||||||||||||||||||||||
243 | \section1 Escape Key | - | ||||||||||||||||||||||||
244 | - | |||||||||||||||||||||||||
245 | If the user presses the Esc key in a dialog, QDialog::reject() | - | ||||||||||||||||||||||||
246 | will be called. This will cause the window to close: The \l{QCloseEvent}{close event} cannot be \l{QEvent::ignore()}{ignored}. | - | ||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | \section1 Extensibility | - | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | Extensibility is the ability to show the dialog in two ways: a | - | ||||||||||||||||||||||||
251 | partial dialog that shows the most commonly used options, and a | - | ||||||||||||||||||||||||
252 | full dialog that shows all the options. Typically an extensible | - | ||||||||||||||||||||||||
253 | dialog will initially appear as a partial dialog, but with a | - | ||||||||||||||||||||||||
254 | \uicontrol More toggle button. If the user presses the \uicontrol More button down, | - | ||||||||||||||||||||||||
255 | the dialog is expanded. The \l{Extension Example} shows how to achieve | - | ||||||||||||||||||||||||
256 | extensible dialogs using Qt. | - | ||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||
258 | \target return | - | ||||||||||||||||||||||||
259 | \section1 Return Value (Modal Dialogs) | - | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | Modal dialogs are often used in situations where a return value is | - | ||||||||||||||||||||||||
262 | required, e.g. to indicate whether the user pressed \uicontrol OK or | - | ||||||||||||||||||||||||
263 | \uicontrol Cancel. A dialog can be closed by calling the accept() or the | - | ||||||||||||||||||||||||
264 | reject() slots, and exec() will return \c Accepted or \c Rejected | - | ||||||||||||||||||||||||
265 | as appropriate. The exec() call returns the result of the dialog. | - | ||||||||||||||||||||||||
266 | The result is also available from result() if the dialog has not | - | ||||||||||||||||||||||||
267 | been destroyed. | - | ||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||
269 | In order to modify your dialog's close behavior, you can reimplement | - | ||||||||||||||||||||||||
270 | the functions accept(), reject() or done(). The | - | ||||||||||||||||||||||||
271 | \l{QWidget::closeEvent()}{closeEvent()} function should only be | - | ||||||||||||||||||||||||
272 | reimplemented to preserve the dialog's position or to override the | - | ||||||||||||||||||||||||
273 | standard close or reject behavior. | - | ||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||
275 | \target examples | - | ||||||||||||||||||||||||
276 | \section1 Code Examples | - | ||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | A modal dialog: | - | ||||||||||||||||||||||||
279 | - | |||||||||||||||||||||||||
280 | \snippet dialogs/dialogs.cpp 1 | - | ||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||
282 | A modeless dialog: | - | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | \snippet dialogs/dialogs.cpp 0 | - | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | \sa QDialogButtonBox, QTabWidget, QWidget, QProgressDialog, | - | ||||||||||||||||||||||||
287 | {fowler}{GUI Design Handbook: Dialogs, Standard}, {Extension Example}, | - | ||||||||||||||||||||||||
288 | {Standard Dialogs Example} | - | ||||||||||||||||||||||||
289 | */ | - | ||||||||||||||||||||||||
290 | - | |||||||||||||||||||||||||
291 | /*! \enum QDialog::DialogCode | - | ||||||||||||||||||||||||
292 | - | |||||||||||||||||||||||||
293 | The value returned by a modal dialog. | - | ||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||
295 | \value Accepted | - | ||||||||||||||||||||||||
296 | \value Rejected | - | ||||||||||||||||||||||||
297 | */ | - | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | /*! | - | ||||||||||||||||||||||||
300 | \property QDialog::sizeGripEnabled | - | ||||||||||||||||||||||||
301 | \brief whether the size grip is enabled | - | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | A QSizeGrip is placed in the bottom-right corner of the dialog when this | - | ||||||||||||||||||||||||
304 | property is enabled. By default, the size grip is disabled. | - | ||||||||||||||||||||||||
305 | */ | - | ||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | - | |||||||||||||||||||||||||
308 | /*! | - | ||||||||||||||||||||||||
309 | Constructs a dialog with parent \a parent. | - | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | A dialog is always a top-level widget, but if it has a parent, its | - | ||||||||||||||||||||||||
312 | default location is centered on top of the parent. It will also | - | ||||||||||||||||||||||||
313 | share the parent's taskbar entry. | - | ||||||||||||||||||||||||
314 | - | |||||||||||||||||||||||||
315 | The widget flags \a f are passed on to the QWidget constructor. | - | ||||||||||||||||||||||||
316 | If, for example, you don't want a What's This button in the title bar | - | ||||||||||||||||||||||||
317 | of the dialog, pass Qt::WindowTitleHint | Qt::WindowSystemMenuHint in \a f. | - | ||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||
319 | \sa QWidget::setWindowFlags() | - | ||||||||||||||||||||||||
320 | */ | - | ||||||||||||||||||||||||
321 | - | |||||||||||||||||||||||||
322 | QDialog::QDialog(QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||||||||||||||
323 | : QWidget(*new QDialogPrivate, parent, | - | ||||||||||||||||||||||||
324 | f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0))) | - | ||||||||||||||||||||||||
325 | { | - | ||||||||||||||||||||||||
326 | } never executed: end of block | 0 | ||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||
328 | /*! | - | ||||||||||||||||||||||||
329 | \overload | - | ||||||||||||||||||||||||
330 | \internal | - | ||||||||||||||||||||||||
331 | */ | - | ||||||||||||||||||||||||
332 | QDialog::QDialog(QDialogPrivate &dd, QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||||||||||||||
333 | : QWidget(dd, parent, f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0))) | - | ||||||||||||||||||||||||
334 | { | - | ||||||||||||||||||||||||
335 | } never executed: end of block | 0 | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | /*! | - | ||||||||||||||||||||||||
338 | Destroys the QDialog, deleting all its children. | - | ||||||||||||||||||||||||
339 | */ | - | ||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||
341 | QDialog::~QDialog() | - | ||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||
343 | QT_TRY { | - | ||||||||||||||||||||||||
344 | // Need to hide() here, as our (to-be) overridden hide() | - | ||||||||||||||||||||||||
345 | // will not be called in ~QWidget. | - | ||||||||||||||||||||||||
346 | hide(); | - | ||||||||||||||||||||||||
347 | } QT_CATCH(...) { never executed: end of block dead code: { } | - | ||||||||||||||||||||||||
348 | // we're in the destructor - just swallow the exception dead code: { } | - | ||||||||||||||||||||||||
349 | } dead code: { } | - | ||||||||||||||||||||||||
350 | } | - | ||||||||||||||||||||||||
351 | - | |||||||||||||||||||||||||
352 | /*! | - | ||||||||||||||||||||||||
353 | \internal | - | ||||||||||||||||||||||||
354 | This function is called by the push button \a pushButton when it | - | ||||||||||||||||||||||||
355 | becomes the default button. If \a pushButton is 0, the dialogs | - | ||||||||||||||||||||||||
356 | default default button becomes the default button. This is what a | - | ||||||||||||||||||||||||
357 | push button calls when it loses focus. | - | ||||||||||||||||||||||||
358 | */ | - | ||||||||||||||||||||||||
359 | void QDialogPrivate::setDefault(QPushButton *pushButton) | - | ||||||||||||||||||||||||
360 | { | - | ||||||||||||||||||||||||
361 | Q_Q(QDialog); | - | ||||||||||||||||||||||||
362 | bool hasMain = false; | - | ||||||||||||||||||||||||
363 | QList<QPushButton*> list = q->findChildren<QPushButton*>(); | - | ||||||||||||||||||||||||
364 | for (int i=0; i<list.size(); ++i) {
| 0 | ||||||||||||||||||||||||
365 | QPushButton *pb = list.at(i); | - | ||||||||||||||||||||||||
366 | if (pb->window() == q) {
| 0 | ||||||||||||||||||||||||
367 | if (pb == mainDef)
| 0 | ||||||||||||||||||||||||
368 | hasMain = true; never executed: hasMain = true; | 0 | ||||||||||||||||||||||||
369 | if (pb != pushButton)
| 0 | ||||||||||||||||||||||||
370 | pb->setDefault(false); never executed: pb->setDefault(false); | 0 | ||||||||||||||||||||||||
371 | } never executed: end of block | 0 | ||||||||||||||||||||||||
372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
373 | if (!pushButton && hasMain)
| 0 | ||||||||||||||||||||||||
374 | mainDef->setDefault(true); never executed: mainDef->setDefault(true); | 0 | ||||||||||||||||||||||||
375 | if (!hasMain)
| 0 | ||||||||||||||||||||||||
376 | mainDef = pushButton; never executed: mainDef = pushButton; | 0 | ||||||||||||||||||||||||
377 | } never executed: end of block | 0 | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | /*! | - | ||||||||||||||||||||||||
380 | \internal | - | ||||||||||||||||||||||||
381 | This function sets the default default push button to \a pushButton. | - | ||||||||||||||||||||||||
382 | This function is called by QPushButton::setDefault(). | - | ||||||||||||||||||||||||
383 | */ | - | ||||||||||||||||||||||||
384 | void QDialogPrivate::setMainDefault(QPushButton *pushButton) | - | ||||||||||||||||||||||||
385 | { | - | ||||||||||||||||||||||||
386 | mainDef = 0; | - | ||||||||||||||||||||||||
387 | setDefault(pushButton); | - | ||||||||||||||||||||||||
388 | } never executed: end of block | 0 | ||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||
390 | /*! | - | ||||||||||||||||||||||||
391 | \internal | - | ||||||||||||||||||||||||
392 | Hides the default button indicator. Called when non auto-default | - | ||||||||||||||||||||||||
393 | push button get focus. | - | ||||||||||||||||||||||||
394 | */ | - | ||||||||||||||||||||||||
395 | void QDialogPrivate::hideDefault() | - | ||||||||||||||||||||||||
396 | { | - | ||||||||||||||||||||||||
397 | Q_Q(QDialog); | - | ||||||||||||||||||||||||
398 | QList<QPushButton*> list = q->findChildren<QPushButton*>(); | - | ||||||||||||||||||||||||
399 | for (int i=0; i<list.size(); ++i) {
| 0 | ||||||||||||||||||||||||
400 | list.at(i)->setDefault(false); | - | ||||||||||||||||||||||||
401 | } never executed: end of block | 0 | ||||||||||||||||||||||||
402 | } never executed: end of block | 0 | ||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||
404 | void QDialogPrivate::resetModalitySetByOpen() | - | ||||||||||||||||||||||||
405 | { | - | ||||||||||||||||||||||||
406 | Q_Q(QDialog); | - | ||||||||||||||||||||||||
407 | if (resetModalityTo != -1 && !q->testAttribute(Qt::WA_SetWindowModality)) {
| 0 | ||||||||||||||||||||||||
408 | // open() changed the window modality and the user didn't touch it afterwards; restore it | - | ||||||||||||||||||||||||
409 | q->setWindowModality(Qt::WindowModality(resetModalityTo)); | - | ||||||||||||||||||||||||
410 | q->setAttribute(Qt::WA_SetWindowModality, wasModalitySet); | - | ||||||||||||||||||||||||
411 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
412 | Q_ASSERT(resetModalityTo != Qt::WindowModal); | - | ||||||||||||||||||||||||
413 | q->setParent(q->parentWidget(), Qt::Dialog); | - | ||||||||||||||||||||||||
414 | #endif | - | ||||||||||||||||||||||||
415 | } never executed: end of block | 0 | ||||||||||||||||||||||||
416 | resetModalityTo = -1; | - | ||||||||||||||||||||||||
417 | } never executed: end of block | 0 | ||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||
419 | #if defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
420 | #ifdef Q_OS_WINCE_WM | - | ||||||||||||||||||||||||
421 | void QDialogPrivate::_q_doneAction() | - | ||||||||||||||||||||||||
422 | { | - | ||||||||||||||||||||||||
423 | //Done... | - | ||||||||||||||||||||||||
424 | QApplication::postEvent(q_func(), new QEvent(QEvent::OkRequest)); | - | ||||||||||||||||||||||||
425 | } | - | ||||||||||||||||||||||||
426 | #endif | - | ||||||||||||||||||||||||
427 | - | |||||||||||||||||||||||||
428 | /*! | - | ||||||||||||||||||||||||
429 | \reimp | - | ||||||||||||||||||||||||
430 | */ | - | ||||||||||||||||||||||||
431 | bool QDialog::event(QEvent *e) | - | ||||||||||||||||||||||||
432 | { | - | ||||||||||||||||||||||||
433 | bool result = QWidget::event(e); | - | ||||||||||||||||||||||||
434 | #ifdef Q_OS_WINCE | - | ||||||||||||||||||||||||
435 | if (e->type() == QEvent::OkRequest) { | - | ||||||||||||||||||||||||
436 | accept(); | - | ||||||||||||||||||||||||
437 | result = true; | - | ||||||||||||||||||||||||
438 | } | - | ||||||||||||||||||||||||
439 | #endif | - | ||||||||||||||||||||||||
440 | return result; | - | ||||||||||||||||||||||||
441 | } | - | ||||||||||||||||||||||||
442 | #endif | - | ||||||||||||||||||||||||
443 | - | |||||||||||||||||||||||||
444 | /*! | - | ||||||||||||||||||||||||
445 | In general returns the modal dialog's result code, \c Accepted or | - | ||||||||||||||||||||||||
446 | \c Rejected. | - | ||||||||||||||||||||||||
447 | - | |||||||||||||||||||||||||
448 | \note When called on a QMessageBox instance, the returned value is a | - | ||||||||||||||||||||||||
449 | value of the \l QMessageBox::StandardButton enum. | - | ||||||||||||||||||||||||
450 | - | |||||||||||||||||||||||||
451 | Do not call this function if the dialog was constructed with the | - | ||||||||||||||||||||||||
452 | Qt::WA_DeleteOnClose attribute. | - | ||||||||||||||||||||||||
453 | */ | - | ||||||||||||||||||||||||
454 | int QDialog::result() const | - | ||||||||||||||||||||||||
455 | { | - | ||||||||||||||||||||||||
456 | Q_D(const QDialog); | - | ||||||||||||||||||||||||
457 | return d->rescode; never executed: return d->rescode; | 0 | ||||||||||||||||||||||||
458 | } | - | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | /*! | - | ||||||||||||||||||||||||
461 | \fn void QDialog::setResult(int i) | - | ||||||||||||||||||||||||
462 | - | |||||||||||||||||||||||||
463 | Sets the modal dialog's result code to \a i. | - | ||||||||||||||||||||||||
464 | - | |||||||||||||||||||||||||
465 | \note We recommend that you use one of the values defined by | - | ||||||||||||||||||||||||
466 | QDialog::DialogCode. | - | ||||||||||||||||||||||||
467 | */ | - | ||||||||||||||||||||||||
468 | void QDialog::setResult(int r) | - | ||||||||||||||||||||||||
469 | { | - | ||||||||||||||||||||||||
470 | Q_D(QDialog); | - | ||||||||||||||||||||||||
471 | d->rescode = r; | - | ||||||||||||||||||||||||
472 | } never executed: end of block | 0 | ||||||||||||||||||||||||
473 | - | |||||||||||||||||||||||||
474 | /*! | - | ||||||||||||||||||||||||
475 | \since 4.5 | - | ||||||||||||||||||||||||
476 | - | |||||||||||||||||||||||||
477 | Shows the dialog as a \l{QDialog#Modal Dialogs}{window modal dialog}, | - | ||||||||||||||||||||||||
478 | returning immediately. | - | ||||||||||||||||||||||||
479 | - | |||||||||||||||||||||||||
480 | \sa exec(), show(), result(), setWindowModality() | - | ||||||||||||||||||||||||
481 | */ | - | ||||||||||||||||||||||||
482 | void QDialog::open() | - | ||||||||||||||||||||||||
483 | { | - | ||||||||||||||||||||||||
484 | Q_D(QDialog); | - | ||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||
486 | Qt::WindowModality modality = windowModality(); | - | ||||||||||||||||||||||||
487 | if (modality != Qt::WindowModal) {
| 0 | ||||||||||||||||||||||||
488 | d->resetModalityTo = modality; | - | ||||||||||||||||||||||||
489 | d->wasModalitySet = testAttribute(Qt::WA_SetWindowModality); | - | ||||||||||||||||||||||||
490 | setWindowModality(Qt::WindowModal); | - | ||||||||||||||||||||||||
491 | setAttribute(Qt::WA_SetWindowModality, false); | - | ||||||||||||||||||||||||
492 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
493 | setParent(parentWidget(), Qt::Sheet); | - | ||||||||||||||||||||||||
494 | #endif | - | ||||||||||||||||||||||||
495 | } never executed: end of block | 0 | ||||||||||||||||||||||||
496 | - | |||||||||||||||||||||||||
497 | setResult(0); | - | ||||||||||||||||||||||||
498 | show(); | - | ||||||||||||||||||||||||
499 | } never executed: end of block | 0 | ||||||||||||||||||||||||
500 | - | |||||||||||||||||||||||||
501 | /*! | - | ||||||||||||||||||||||||
502 | Shows the dialog as a \l{QDialog#Modal Dialogs}{modal dialog}, | - | ||||||||||||||||||||||||
503 | blocking until the user closes it. The function returns a \l | - | ||||||||||||||||||||||||
504 | DialogCode result. | - | ||||||||||||||||||||||||
505 | - | |||||||||||||||||||||||||
506 | If the dialog is \l{Qt::ApplicationModal}{application modal}, users cannot | - | ||||||||||||||||||||||||
507 | interact with any other window in the same application until they close | - | ||||||||||||||||||||||||
508 | the dialog. If the dialog is \l{Qt::ApplicationModal}{window modal}, only | - | ||||||||||||||||||||||||
509 | interaction with the parent window is blocked while the dialog is open. | - | ||||||||||||||||||||||||
510 | By default, the dialog is application modal. | - | ||||||||||||||||||||||||
511 | - | |||||||||||||||||||||||||
512 | \sa open(), show(), result(), setWindowModality() | - | ||||||||||||||||||||||||
513 | */ | - | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | int QDialog::exec() | - | ||||||||||||||||||||||||
516 | { | - | ||||||||||||||||||||||||
517 | Q_D(QDialog); | - | ||||||||||||||||||||||||
518 | - | |||||||||||||||||||||||||
519 | if (d->eventLoop) {
| 0 | ||||||||||||||||||||||||
520 | qWarning("QDialog::exec: Recursive call detected"); | - | ||||||||||||||||||||||||
521 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
522 | } | - | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose); | - | ||||||||||||||||||||||||
525 | setAttribute(Qt::WA_DeleteOnClose, false); | - | ||||||||||||||||||||||||
526 | - | |||||||||||||||||||||||||
527 | d->resetModalitySetByOpen(); | - | ||||||||||||||||||||||||
528 | - | |||||||||||||||||||||||||
529 | bool wasShowModal = testAttribute(Qt::WA_ShowModal); | - | ||||||||||||||||||||||||
530 | setAttribute(Qt::WA_ShowModal, true); | - | ||||||||||||||||||||||||
531 | setResult(0); | - | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | show(); | - | ||||||||||||||||||||||||
534 | - | |||||||||||||||||||||||||
535 | QPointer<QDialog> guard = this; | - | ||||||||||||||||||||||||
536 | if (d->nativeDialogInUse) {
| 0 | ||||||||||||||||||||||||
537 | d->platformHelper()->exec(); | - | ||||||||||||||||||||||||
538 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
539 | QEventLoop eventLoop; | - | ||||||||||||||||||||||||
540 | d->eventLoop = &eventLoop; | - | ||||||||||||||||||||||||
541 | (void) eventLoop.exec(QEventLoop::DialogExec); | - | ||||||||||||||||||||||||
542 | } never executed: end of block | 0 | ||||||||||||||||||||||||
543 | if (guard.isNull())
| 0 | ||||||||||||||||||||||||
544 | return QDialog::Rejected; never executed: return QDialog::Rejected; | 0 | ||||||||||||||||||||||||
545 | d->eventLoop = 0; | - | ||||||||||||||||||||||||
546 | - | |||||||||||||||||||||||||
547 | setAttribute(Qt::WA_ShowModal, wasShowModal); | - | ||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | int res = result(); | - | ||||||||||||||||||||||||
550 | if (d->nativeDialogInUse)
| 0 | ||||||||||||||||||||||||
551 | d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper()); never executed: d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper()); | 0 | ||||||||||||||||||||||||
552 | if (deleteOnClose)
| 0 | ||||||||||||||||||||||||
553 | delete this; never executed: delete this; | 0 | ||||||||||||||||||||||||
554 | return res; never executed: return res; | 0 | ||||||||||||||||||||||||
555 | } | - | ||||||||||||||||||||||||
556 | - | |||||||||||||||||||||||||
557 | /*! | - | ||||||||||||||||||||||||
558 | Closes the dialog and sets its result code to \a r. If this dialog | - | ||||||||||||||||||||||||
559 | is shown with exec(), done() causes the local event loop to finish, | - | ||||||||||||||||||||||||
560 | and exec() to return \a r. | - | ||||||||||||||||||||||||
561 | - | |||||||||||||||||||||||||
562 | As with QWidget::close(), done() deletes the dialog if the | - | ||||||||||||||||||||||||
563 | Qt::WA_DeleteOnClose flag is set. If the dialog is the application's | - | ||||||||||||||||||||||||
564 | main widget, the application terminates. If the dialog is the | - | ||||||||||||||||||||||||
565 | last window closed, the QApplication::lastWindowClosed() signal is | - | ||||||||||||||||||||||||
566 | emitted. | - | ||||||||||||||||||||||||
567 | - | |||||||||||||||||||||||||
568 | \sa accept(), reject(), QApplication::activeWindow(), QCoreApplication::quit() | - | ||||||||||||||||||||||||
569 | */ | - | ||||||||||||||||||||||||
570 | - | |||||||||||||||||||||||||
571 | void QDialog::done(int r) | - | ||||||||||||||||||||||||
572 | { | - | ||||||||||||||||||||||||
573 | Q_D(QDialog); | - | ||||||||||||||||||||||||
574 | hide(); | - | ||||||||||||||||||||||||
575 | setResult(r); | - | ||||||||||||||||||||||||
576 | - | |||||||||||||||||||||||||
577 | d->close_helper(QWidgetPrivate::CloseNoEvent); | - | ||||||||||||||||||||||||
578 | d->resetModalitySetByOpen(); | - | ||||||||||||||||||||||||
579 | - | |||||||||||||||||||||||||
580 | emit finished(r); | - | ||||||||||||||||||||||||
581 | if (r == Accepted)
| 0 | ||||||||||||||||||||||||
582 | emit accepted(); never executed: accepted(); | 0 | ||||||||||||||||||||||||
583 | else if (r == Rejected)
| 0 | ||||||||||||||||||||||||
584 | emit rejected(); never executed: rejected(); | 0 | ||||||||||||||||||||||||
585 | } never executed: end of block | 0 | ||||||||||||||||||||||||
586 | - | |||||||||||||||||||||||||
587 | /*! | - | ||||||||||||||||||||||||
588 | Hides the modal dialog and sets the result code to \c Accepted. | - | ||||||||||||||||||||||||
589 | - | |||||||||||||||||||||||||
590 | \sa reject(), done() | - | ||||||||||||||||||||||||
591 | */ | - | ||||||||||||||||||||||||
592 | - | |||||||||||||||||||||||||
593 | void QDialog::accept() | - | ||||||||||||||||||||||||
594 | { | - | ||||||||||||||||||||||||
595 | done(Accepted); | - | ||||||||||||||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||||||||||||||
597 | - | |||||||||||||||||||||||||
598 | /*! | - | ||||||||||||||||||||||||
599 | Hides the modal dialog and sets the result code to \c Rejected. | - | ||||||||||||||||||||||||
600 | - | |||||||||||||||||||||||||
601 | \sa accept(), done() | - | ||||||||||||||||||||||||
602 | */ | - | ||||||||||||||||||||||||
603 | - | |||||||||||||||||||||||||
604 | void QDialog::reject() | - | ||||||||||||||||||||||||
605 | { | - | ||||||||||||||||||||||||
606 | done(Rejected); | - | ||||||||||||||||||||||||
607 | } never executed: end of block | 0 | ||||||||||||||||||||||||
608 | - | |||||||||||||||||||||||||
609 | /*! \reimp */ | - | ||||||||||||||||||||||||
610 | bool QDialog::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||||||||||||||
611 | { | - | ||||||||||||||||||||||||
612 | return QWidget::eventFilter(o, e); never executed: return QWidget::eventFilter(o, e); | 0 | ||||||||||||||||||||||||
613 | } | - | ||||||||||||||||||||||||
614 | - | |||||||||||||||||||||||||
615 | /***************************************************************************** | - | ||||||||||||||||||||||||
616 | Event handlers | - | ||||||||||||||||||||||||
617 | *****************************************************************************/ | - | ||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||
619 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
620 | /*! \reimp */ | - | ||||||||||||||||||||||||
621 | void QDialog::contextMenuEvent(QContextMenuEvent *e) | - | ||||||||||||||||||||||||
622 | { | - | ||||||||||||||||||||||||
623 | #if defined(QT_NO_WHATSTHIS) || defined(QT_NO_MENU) | - | ||||||||||||||||||||||||
624 | Q_UNUSED(e); | - | ||||||||||||||||||||||||
625 | #else | - | ||||||||||||||||||||||||
626 | QWidget *w = childAt(e->pos()); | - | ||||||||||||||||||||||||
627 | if (!w) {
| 0 | ||||||||||||||||||||||||
628 | w = rect().contains(e->pos()) ? this : 0;
| 0 | ||||||||||||||||||||||||
629 | if (!w)
| 0 | ||||||||||||||||||||||||
630 | return; never executed: return; | 0 | ||||||||||||||||||||||||
631 | } never executed: end of block | 0 | ||||||||||||||||||||||||
632 | while (w && w->whatsThis().size() == 0 && !w->testAttribute(Qt::WA_CustomWhatsThis))
| 0 | ||||||||||||||||||||||||
633 | w = w->isWindow() ? 0 : w->parentWidget(); never executed: w = w->isWindow() ? 0 : w->parentWidget();
| 0 | ||||||||||||||||||||||||
634 | if (w) {
| 0 | ||||||||||||||||||||||||
635 | QPointer<QMenu> p = new QMenu(this); | - | ||||||||||||||||||||||||
636 | QAction *wt = p.data()->addAction(tr("What's This?")); | - | ||||||||||||||||||||||||
637 | if (p.data()->exec(e->globalPos()) == wt) {
| 0 | ||||||||||||||||||||||||
638 | QHelpEvent e(QEvent::WhatsThis, w->rect().center(), | - | ||||||||||||||||||||||||
639 | w->mapToGlobal(w->rect().center())); | - | ||||||||||||||||||||||||
640 | QApplication::sendEvent(w, &e); | - | ||||||||||||||||||||||||
641 | } never executed: end of block | 0 | ||||||||||||||||||||||||
642 | delete p.data(); | - | ||||||||||||||||||||||||
643 | } never executed: end of block | 0 | ||||||||||||||||||||||||
644 | #endif | - | ||||||||||||||||||||||||
645 | } never executed: end of block | 0 | ||||||||||||||||||||||||
646 | #endif // QT_NO_CONTEXTMENU | - | ||||||||||||||||||||||||
647 | - | |||||||||||||||||||||||||
648 | /*! \reimp */ | - | ||||||||||||||||||||||||
649 | void QDialog::keyPressEvent(QKeyEvent *e) | - | ||||||||||||||||||||||||
650 | { | - | ||||||||||||||||||||||||
651 | // Calls reject() if Escape is pressed. Simulates a button | - | ||||||||||||||||||||||||
652 | // click for the default button if Enter is pressed. Move focus | - | ||||||||||||||||||||||||
653 | // for the arrow keys. Ignore the rest. | - | ||||||||||||||||||||||||
654 | if (e->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||||||||||||||
655 | reject(); | - | ||||||||||||||||||||||||
656 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
657 | if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) {
| 0 | ||||||||||||||||||||||||
658 | switch (e->key()) { | - | ||||||||||||||||||||||||
659 | case Qt::Key_Enter: never executed: case Qt::Key_Enter: | 0 | ||||||||||||||||||||||||
660 | case Qt::Key_Return: { never executed: case Qt::Key_Return: | 0 | ||||||||||||||||||||||||
661 | QList<QPushButton*> list = findChildren<QPushButton*>(); | - | ||||||||||||||||||||||||
662 | for (int i=0; i<list.size(); ++i) {
| 0 | ||||||||||||||||||||||||
663 | QPushButton *pb = list.at(i); | - | ||||||||||||||||||||||||
664 | if (pb->isDefault() && pb->isVisible()) {
| 0 | ||||||||||||||||||||||||
665 | if (pb->isEnabled())
| 0 | ||||||||||||||||||||||||
666 | pb->click(); never executed: pb->click(); | 0 | ||||||||||||||||||||||||
667 | return; never executed: return; | 0 | ||||||||||||||||||||||||
668 | } | - | ||||||||||||||||||||||||
669 | } never executed: end of block | 0 | ||||||||||||||||||||||||
670 | } | - | ||||||||||||||||||||||||
671 | break; never executed: break; | 0 | ||||||||||||||||||||||||
672 | default: never executed: default: | 0 | ||||||||||||||||||||||||
673 | e->ignore(); | - | ||||||||||||||||||||||||
674 | return; never executed: return; | 0 | ||||||||||||||||||||||||
675 | } | - | ||||||||||||||||||||||||
676 | } else { | - | ||||||||||||||||||||||||
677 | e->ignore(); | - | ||||||||||||||||||||||||
678 | } never executed: end of block | 0 | ||||||||||||||||||||||||
679 | } | - | ||||||||||||||||||||||||
680 | - | |||||||||||||||||||||||||
681 | /*! \reimp */ | - | ||||||||||||||||||||||||
682 | void QDialog::closeEvent(QCloseEvent *e) | - | ||||||||||||||||||||||||
683 | { | - | ||||||||||||||||||||||||
684 | #ifndef QT_NO_WHATSTHIS | - | ||||||||||||||||||||||||
685 | if (isModal() && QWhatsThis::inWhatsThisMode())
| 0 | ||||||||||||||||||||||||
686 | QWhatsThis::leaveWhatsThisMode(); never executed: QWhatsThis::leaveWhatsThisMode(); | 0 | ||||||||||||||||||||||||
687 | #endif | - | ||||||||||||||||||||||||
688 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
689 | QPointer<QObject> that = this; | - | ||||||||||||||||||||||||
690 | reject(); | - | ||||||||||||||||||||||||
691 | if (that && isVisible())
| 0 | ||||||||||||||||||||||||
692 | e->ignore(); never executed: e->ignore(); | 0 | ||||||||||||||||||||||||
693 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
694 | e->accept(); | - | ||||||||||||||||||||||||
695 | } never executed: end of block | 0 | ||||||||||||||||||||||||
696 | } | - | ||||||||||||||||||||||||
697 | - | |||||||||||||||||||||||||
698 | /***************************************************************************** | - | ||||||||||||||||||||||||
699 | Geometry management. | - | ||||||||||||||||||||||||
700 | *****************************************************************************/ | - | ||||||||||||||||||||||||
701 | - | |||||||||||||||||||||||||
702 | /*! \reimp | - | ||||||||||||||||||||||||
703 | */ | - | ||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||
705 | void QDialog::setVisible(bool visible) | - | ||||||||||||||||||||||||
706 | { | - | ||||||||||||||||||||||||
707 | Q_D(QDialog); | - | ||||||||||||||||||||||||
708 | if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible))
| 0 | ||||||||||||||||||||||||
709 | return; never executed: return; | 0 | ||||||||||||||||||||||||
710 | - | |||||||||||||||||||||||||
711 | if (visible) {
| 0 | ||||||||||||||||||||||||
712 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
| 0 | ||||||||||||||||||||||||
713 | return; never executed: return; | 0 | ||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||
715 | QWidget::setVisible(visible); | - | ||||||||||||||||||||||||
716 | showExtension(d->doShowExtension); | - | ||||||||||||||||||||||||
717 | QWidget *fw = window()->focusWidget(); | - | ||||||||||||||||||||||||
718 | if (!fw)
| 0 | ||||||||||||||||||||||||
719 | fw = this; never executed: fw = this; | 0 | ||||||||||||||||||||||||
720 | - | |||||||||||||||||||||||||
721 | /* | - | ||||||||||||||||||||||||
722 | The following block is to handle a special case, and does not | - | ||||||||||||||||||||||||
723 | really follow propper logic in concern of autoDefault and TAB | - | ||||||||||||||||||||||||
724 | order. However, it's here to ease usage for the users. If a | - | ||||||||||||||||||||||||
725 | dialog has a default QPushButton, and first widget in the TAB | - | ||||||||||||||||||||||||
726 | order also is a QPushButton, then we give focus to the main | - | ||||||||||||||||||||||||
727 | default QPushButton. This simplifies code for the developers, | - | ||||||||||||||||||||||||
728 | and actually catches most cases... If not, then they simply | - | ||||||||||||||||||||||||
729 | have to use [widget*]->setFocus() themselves... | - | ||||||||||||||||||||||||
730 | */ | - | ||||||||||||||||||||||||
731 | if (d->mainDef && fw->focusPolicy() == Qt::NoFocus) {
| 0 | ||||||||||||||||||||||||
732 | QWidget *first = fw; | - | ||||||||||||||||||||||||
733 | while ((first = first->nextInFocusChain()) != fw && first->focusPolicy() == Qt::NoFocus)
| 0 | ||||||||||||||||||||||||
734 | ; never executed: ; | 0 | ||||||||||||||||||||||||
735 | if (first != d->mainDef && qobject_cast<QPushButton*>(first))
| 0 | ||||||||||||||||||||||||
736 | d->mainDef->setFocus(); never executed: d->mainDef->setFocus(); | 0 | ||||||||||||||||||||||||
737 | } never executed: end of block | 0 | ||||||||||||||||||||||||
738 | if (!d->mainDef && isWindow()) {
| 0 | ||||||||||||||||||||||||
739 | QWidget *w = fw; | - | ||||||||||||||||||||||||
740 | while ((w = w->nextInFocusChain()) != fw) {
| 0 | ||||||||||||||||||||||||
741 | QPushButton *pb = qobject_cast<QPushButton *>(w); | - | ||||||||||||||||||||||||
742 | if (pb && pb->autoDefault() && pb->focusPolicy() != Qt::NoFocus) {
| 0 | ||||||||||||||||||||||||
743 | pb->setDefault(true); | - | ||||||||||||||||||||||||
744 | break; never executed: break; | 0 | ||||||||||||||||||||||||
745 | } | - | ||||||||||||||||||||||||
746 | } never executed: end of block | 0 | ||||||||||||||||||||||||
747 | } never executed: end of block | 0 | ||||||||||||||||||||||||
748 | if (fw && !fw->hasFocus()) {
| 0 | ||||||||||||||||||||||||
749 | QFocusEvent e(QEvent::FocusIn, Qt::TabFocusReason); | - | ||||||||||||||||||||||||
750 | QApplication::sendEvent(fw, &e); | - | ||||||||||||||||||||||||
751 | } never executed: end of block | 0 | ||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||
753 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
754 | QAccessibleEvent event(this, QAccessible::DialogStart); | - | ||||||||||||||||||||||||
755 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
756 | #endif | - | ||||||||||||||||||||||||
757 | - | |||||||||||||||||||||||||
758 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
759 | if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
| 0 | ||||||||||||||||||||||||
760 | return; never executed: return; | 0 | ||||||||||||||||||||||||
761 | - | |||||||||||||||||||||||||
762 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||||||||
763 | if (isVisible()) {
| 0 | ||||||||||||||||||||||||
764 | QAccessibleEvent event(this, QAccessible::DialogEnd); | - | ||||||||||||||||||||||||
765 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||||||||
766 | } never executed: end of block | 0 | ||||||||||||||||||||||||
767 | #endif | - | ||||||||||||||||||||||||
768 | - | |||||||||||||||||||||||||
769 | // Reimplemented to exit a modal event loop when the dialog is hidden. | - | ||||||||||||||||||||||||
770 | QWidget::setVisible(visible); | - | ||||||||||||||||||||||||
771 | if (d->eventLoop)
| 0 | ||||||||||||||||||||||||
772 | d->eventLoop->exit(); never executed: d->eventLoop->exit(); | 0 | ||||||||||||||||||||||||
773 | } never executed: end of block | 0 | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||||||||
776 | if (d->mainDef && isActiveWindow()
| 0 | ||||||||||||||||||||||||
777 | && theme->themeHint(QPlatformTheme::DialogSnapToDefaultButton).toBool())
| 0 | ||||||||||||||||||||||||
778 | QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center())); never executed: QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center())); | 0 | ||||||||||||||||||||||||
779 | } never executed: end of block | 0 | ||||||||||||||||||||||||
780 | - | |||||||||||||||||||||||||
781 | /*!\reimp */ | - | ||||||||||||||||||||||||
782 | void QDialog::showEvent(QShowEvent *event) | - | ||||||||||||||||||||||||
783 | { | - | ||||||||||||||||||||||||
784 | if (!event->spontaneous() && !testAttribute(Qt::WA_Moved)) {
| 0 | ||||||||||||||||||||||||
785 | Qt::WindowStates state = windowState(); | - | ||||||||||||||||||||||||
786 | adjustPosition(parentWidget()); | - | ||||||||||||||||||||||||
787 | setAttribute(Qt::WA_Moved, false); // not really an explicit position | - | ||||||||||||||||||||||||
788 | if (state != windowState())
| 0 | ||||||||||||||||||||||||
789 | setWindowState(state); never executed: setWindowState(state); | 0 | ||||||||||||||||||||||||
790 | } never executed: end of block | 0 | ||||||||||||||||||||||||
791 | } never executed: end of block | 0 | ||||||||||||||||||||||||
792 | - | |||||||||||||||||||||||||
793 | /*! \internal */ | - | ||||||||||||||||||||||||
794 | void QDialog::adjustPosition(QWidget* w) | - | ||||||||||||||||||||||||
795 | { | - | ||||||||||||||||||||||||
796 | - | |||||||||||||||||||||||||
797 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
| 0 | ||||||||||||||||||||||||
798 | if (theme->themeHint(QPlatformTheme::WindowAutoPlacement).toBool())
| 0 | ||||||||||||||||||||||||
799 | return; never executed: return; | 0 | ||||||||||||||||||||||||
800 | QPoint p(0, 0); | - | ||||||||||||||||||||||||
801 | int extraw = 0, extrah = 0, scrn = 0; | - | ||||||||||||||||||||||||
802 | if (w)
| 0 | ||||||||||||||||||||||||
803 | w = w->window(); never executed: w = w->window(); | 0 | ||||||||||||||||||||||||
804 | QRect desk; | - | ||||||||||||||||||||||||
805 | if (w) {
| 0 | ||||||||||||||||||||||||
806 | scrn = QApplication::desktop()->screenNumber(w); | - | ||||||||||||||||||||||||
807 | } else if (QApplication::desktop()->isVirtualDesktop()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
808 | scrn = QApplication::desktop()->screenNumber(QCursor::pos()); | - | ||||||||||||||||||||||||
809 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
810 | scrn = QApplication::desktop()->screenNumber(this); | - | ||||||||||||||||||||||||
811 | } never executed: end of block | 0 | ||||||||||||||||||||||||
812 | desk = QApplication::desktop()->availableGeometry(scrn); | - | ||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||
814 | QWidgetList list = QApplication::topLevelWidgets(); | - | ||||||||||||||||||||||||
815 | for (int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i) {
| 0 | ||||||||||||||||||||||||
816 | QWidget * current = list.at(i); | - | ||||||||||||||||||||||||
817 | if (current->isVisible()) {
| 0 | ||||||||||||||||||||||||
818 | int framew = current->geometry().x() - current->x(); | - | ||||||||||||||||||||||||
819 | int frameh = current->geometry().y() - current->y(); | - | ||||||||||||||||||||||||
820 | - | |||||||||||||||||||||||||
821 | extraw = qMax(extraw, framew); | - | ||||||||||||||||||||||||
822 | extrah = qMax(extrah, frameh); | - | ||||||||||||||||||||||||
823 | } never executed: end of block | 0 | ||||||||||||||||||||||||
824 | } never executed: end of block | 0 | ||||||||||||||||||||||||
825 | - | |||||||||||||||||||||||||
826 | // sanity check for decoration frames. With embedding, we | - | ||||||||||||||||||||||||
827 | // might get extraordinary values | - | ||||||||||||||||||||||||
828 | if (extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40) {
| 0 | ||||||||||||||||||||||||
829 | extrah = 40; | - | ||||||||||||||||||||||||
830 | extraw = 10; | - | ||||||||||||||||||||||||
831 | } never executed: end of block | 0 | ||||||||||||||||||||||||
832 | - | |||||||||||||||||||||||||
833 | - | |||||||||||||||||||||||||
834 | if (w) {
| 0 | ||||||||||||||||||||||||
835 | // Use pos() if the widget is embedded into a native window | - | ||||||||||||||||||||||||
836 | QPoint pp; | - | ||||||||||||||||||||||||
837 | if (w->windowHandle() && w->windowHandle()->property("_q_embedded_native_parent_handle").value<WId>())
| 0 | ||||||||||||||||||||||||
838 | pp = w->pos(); never executed: pp = w->pos(); | 0 | ||||||||||||||||||||||||
839 | else | - | ||||||||||||||||||||||||
840 | pp = w->mapToGlobal(QPoint(0,0)); never executed: pp = w->mapToGlobal(QPoint(0,0)); | 0 | ||||||||||||||||||||||||
841 | p = QPoint(pp.x() + w->width()/2, | - | ||||||||||||||||||||||||
842 | pp.y() + w->height()/ 2); | - | ||||||||||||||||||||||||
843 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
844 | // p = middle of the desktop | - | ||||||||||||||||||||||||
845 | p = QPoint(desk.x() + desk.width()/2, desk.y() + desk.height()/2); | - | ||||||||||||||||||||||||
846 | } never executed: end of block | 0 | ||||||||||||||||||||||||
847 | - | |||||||||||||||||||||||||
848 | // p = origin of this | - | ||||||||||||||||||||||||
849 | p = QPoint(p.x()-width()/2 - extraw, | - | ||||||||||||||||||||||||
850 | p.y()-height()/2 - extrah); | - | ||||||||||||||||||||||||
851 | - | |||||||||||||||||||||||||
852 | - | |||||||||||||||||||||||||
853 | if (p.x() + extraw + width() > desk.x() + desk.width())
| 0 | ||||||||||||||||||||||||
854 | p.setX(desk.x() + desk.width() - width() - extraw); never executed: p.setX(desk.x() + desk.width() - width() - extraw); | 0 | ||||||||||||||||||||||||
855 | if (p.x() < desk.x())
| 0 | ||||||||||||||||||||||||
856 | p.setX(desk.x()); never executed: p.setX(desk.x()); | 0 | ||||||||||||||||||||||||
857 | - | |||||||||||||||||||||||||
858 | if (p.y() + extrah + height() > desk.y() + desk.height())
| 0 | ||||||||||||||||||||||||
859 | p.setY(desk.y() + desk.height() - height() - extrah); never executed: p.setY(desk.y() + desk.height() - height() - extrah); | 0 | ||||||||||||||||||||||||
860 | if (p.y() < desk.y())
| 0 | ||||||||||||||||||||||||
861 | p.setY(desk.y()); never executed: p.setY(desk.y()); | 0 | ||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||
863 | // QTBUG-52735: Manually set the correct target screen since scaling in a | - | ||||||||||||||||||||||||
864 | // subsequent call to QWindow::resize() may otherwise use the wrong factor | - | ||||||||||||||||||||||||
865 | // if the screen changed notification is still in an event queue. | - | ||||||||||||||||||||||||
866 | if (scrn >= 0) {
| 0 | ||||||||||||||||||||||||
867 | if (QWindow *window = windowHandle())
| 0 | ||||||||||||||||||||||||
868 | window->setScreen(QGuiApplication::screens().at(scrn)); never executed: window->setScreen(QGuiApplication::screens().at(scrn)); | 0 | ||||||||||||||||||||||||
869 | } never executed: end of block | 0 | ||||||||||||||||||||||||
870 | - | |||||||||||||||||||||||||
871 | move(p); | - | ||||||||||||||||||||||||
872 | } never executed: end of block | 0 | ||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||
874 | /*! | - | ||||||||||||||||||||||||
875 | \obsolete | - | ||||||||||||||||||||||||
876 | - | |||||||||||||||||||||||||
877 | If \a orientation is Qt::Horizontal, the extension will be displayed | - | ||||||||||||||||||||||||
878 | to the right of the dialog's main area. If \a orientation is | - | ||||||||||||||||||||||||
879 | Qt::Vertical, the extension will be displayed below the dialog's main | - | ||||||||||||||||||||||||
880 | area. | - | ||||||||||||||||||||||||
881 | - | |||||||||||||||||||||||||
882 | Instead of using this functionality, we recommend that you simply call | - | ||||||||||||||||||||||||
883 | show() or hide() on the part of the dialog that you want to use as an | - | ||||||||||||||||||||||||
884 | extension. See the \l{Extension Example} for details. | - | ||||||||||||||||||||||||
885 | - | |||||||||||||||||||||||||
886 | \sa setExtension() | - | ||||||||||||||||||||||||
887 | */ | - | ||||||||||||||||||||||||
888 | void QDialog::setOrientation(Qt::Orientation orientation) | - | ||||||||||||||||||||||||
889 | { | - | ||||||||||||||||||||||||
890 | Q_D(QDialog); | - | ||||||||||||||||||||||||
891 | d->orientation = orientation; | - | ||||||||||||||||||||||||
892 | } never executed: end of block | 0 | ||||||||||||||||||||||||
893 | - | |||||||||||||||||||||||||
894 | /*! | - | ||||||||||||||||||||||||
895 | \obsolete | - | ||||||||||||||||||||||||
896 | - | |||||||||||||||||||||||||
897 | Returns the dialog's extension orientation. | - | ||||||||||||||||||||||||
898 | - | |||||||||||||||||||||||||
899 | Instead of using this functionality, we recommend that you simply call | - | ||||||||||||||||||||||||
900 | show() or hide() on the part of the dialog that you want to use as an | - | ||||||||||||||||||||||||
901 | extension. See the \l{Extension Example} for details. | - | ||||||||||||||||||||||||
902 | - | |||||||||||||||||||||||||
903 | \sa extension() | - | ||||||||||||||||||||||||
904 | */ | - | ||||||||||||||||||||||||
905 | Qt::Orientation QDialog::orientation() const | - | ||||||||||||||||||||||||
906 | { | - | ||||||||||||||||||||||||
907 | Q_D(const QDialog); | - | ||||||||||||||||||||||||
908 | return d->orientation; never executed: return d->orientation; | 0 | ||||||||||||||||||||||||
909 | } | - | ||||||||||||||||||||||||
910 | - | |||||||||||||||||||||||||
911 | /*! | - | ||||||||||||||||||||||||
912 | \obsolete | - | ||||||||||||||||||||||||
913 | - | |||||||||||||||||||||||||
914 | Sets the widget, \a extension, to be the dialog's extension, | - | ||||||||||||||||||||||||
915 | deleting any previous extension. The dialog takes ownership of the | - | ||||||||||||||||||||||||
916 | extension. Note that if 0 is passed any existing extension will be | - | ||||||||||||||||||||||||
917 | deleted. This function must only be called while the dialog is hidden. | - | ||||||||||||||||||||||||
918 | - | |||||||||||||||||||||||||
919 | Instead of using this functionality, we recommend that you simply call | - | ||||||||||||||||||||||||
920 | show() or hide() on the part of the dialog that you want to use as an | - | ||||||||||||||||||||||||
921 | extension. See the \l{Extension Example} for details. | - | ||||||||||||||||||||||||
922 | - | |||||||||||||||||||||||||
923 | \sa showExtension(), setOrientation() | - | ||||||||||||||||||||||||
924 | */ | - | ||||||||||||||||||||||||
925 | void QDialog::setExtension(QWidget* extension) | - | ||||||||||||||||||||||||
926 | { | - | ||||||||||||||||||||||||
927 | Q_D(QDialog); | - | ||||||||||||||||||||||||
928 | delete d->extension; | - | ||||||||||||||||||||||||
929 | d->extension = extension; | - | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | if (!extension)
| 0 | ||||||||||||||||||||||||
932 | return; never executed: return; | 0 | ||||||||||||||||||||||||
933 | - | |||||||||||||||||||||||||
934 | if (extension->parentWidget() != this)
| 0 | ||||||||||||||||||||||||
935 | extension->setParent(this); never executed: extension->setParent(this); | 0 | ||||||||||||||||||||||||
936 | extension->hide(); | - | ||||||||||||||||||||||||
937 | } never executed: end of block | 0 | ||||||||||||||||||||||||
938 | - | |||||||||||||||||||||||||
939 | /*! | - | ||||||||||||||||||||||||
940 | \obsolete | - | ||||||||||||||||||||||||
941 | - | |||||||||||||||||||||||||
942 | Returns the dialog's extension or 0 if no extension has been | - | ||||||||||||||||||||||||
943 | defined. | - | ||||||||||||||||||||||||
944 | - | |||||||||||||||||||||||||
945 | Instead of using this functionality, we recommend that you simply call | - | ||||||||||||||||||||||||
946 | show() or hide() on the part of the dialog that you want to use as an | - | ||||||||||||||||||||||||
947 | extension. See the \l{Extension Example} for details. | - | ||||||||||||||||||||||||
948 | - | |||||||||||||||||||||||||
949 | \sa showExtension(), setOrientation() | - | ||||||||||||||||||||||||
950 | */ | - | ||||||||||||||||||||||||
951 | QWidget* QDialog::extension() const | - | ||||||||||||||||||||||||
952 | { | - | ||||||||||||||||||||||||
953 | Q_D(const QDialog); | - | ||||||||||||||||||||||||
954 | return d->extension; never executed: return d->extension; | 0 | ||||||||||||||||||||||||
955 | } | - | ||||||||||||||||||||||||
956 | - | |||||||||||||||||||||||||
957 | - | |||||||||||||||||||||||||
958 | /*! | - | ||||||||||||||||||||||||
959 | \obsolete | - | ||||||||||||||||||||||||
960 | - | |||||||||||||||||||||||||
961 | If \a showIt is true, the dialog's extension is shown; otherwise the | - | ||||||||||||||||||||||||
962 | extension is hidden. | - | ||||||||||||||||||||||||
963 | - | |||||||||||||||||||||||||
964 | Instead of using this functionality, we recommend that you simply call | - | ||||||||||||||||||||||||
965 | show() or hide() on the part of the dialog that you want to use as an | - | ||||||||||||||||||||||||
966 | extension. See the \l{Extension Example} for details. | - | ||||||||||||||||||||||||
967 | - | |||||||||||||||||||||||||
968 | \sa show(), setExtension(), setOrientation() | - | ||||||||||||||||||||||||
969 | */ | - | ||||||||||||||||||||||||
970 | void QDialog::showExtension(bool showIt) | - | ||||||||||||||||||||||||
971 | { | - | ||||||||||||||||||||||||
972 | Q_D(QDialog); | - | ||||||||||||||||||||||||
973 | d->doShowExtension = showIt; | - | ||||||||||||||||||||||||
974 | if (!d->extension)
| 0 | ||||||||||||||||||||||||
975 | return; never executed: return; | 0 | ||||||||||||||||||||||||
976 | if (!testAttribute(Qt::WA_WState_Visible))
| 0 | ||||||||||||||||||||||||
977 | return; never executed: return; | 0 | ||||||||||||||||||||||||
978 | if (d->extension->isVisible() == showIt)
| 0 | ||||||||||||||||||||||||
979 | return; never executed: return; | 0 | ||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||
981 | if (showIt) {
| 0 | ||||||||||||||||||||||||
982 | d->size = size(); | - | ||||||||||||||||||||||||
983 | d->min = minimumSize(); | - | ||||||||||||||||||||||||
984 | d->max = maximumSize(); | - | ||||||||||||||||||||||||
985 | if (layout())
| 0 | ||||||||||||||||||||||||
986 | layout()->setEnabled(false); never executed: layout()->setEnabled(false); | 0 | ||||||||||||||||||||||||
987 | QSize s(d->extension->sizeHint() | - | ||||||||||||||||||||||||
988 | .expandedTo(d->extension->minimumSize()) | - | ||||||||||||||||||||||||
989 | .boundedTo(d->extension->maximumSize())); | - | ||||||||||||||||||||||||
990 | if (d->orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
991 | int h = qMax(height(), s.height()); | - | ||||||||||||||||||||||||
992 | d->extension->setGeometry(width(), 0, s.width(), h); | - | ||||||||||||||||||||||||
993 | setFixedSize(width() + s.width(), h); | - | ||||||||||||||||||||||||
994 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
995 | int w = qMax(width(), s.width()); | - | ||||||||||||||||||||||||
996 | d->extension->setGeometry(0, height(), w, s.height()); | - | ||||||||||||||||||||||||
997 | setFixedSize(w, height() + s.height()); | - | ||||||||||||||||||||||||
998 | } never executed: end of block | 0 | ||||||||||||||||||||||||
999 | d->extension->show(); | - | ||||||||||||||||||||||||
1000 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1001 | const bool sizeGripEnabled = isSizeGripEnabled(); | - | ||||||||||||||||||||||||
1002 | setSizeGripEnabled(false); | - | ||||||||||||||||||||||||
1003 | d->sizeGripEnabled = sizeGripEnabled; | - | ||||||||||||||||||||||||
1004 | #endif | - | ||||||||||||||||||||||||
1005 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1006 | d->extension->hide(); | - | ||||||||||||||||||||||||
1007 | // workaround for CDE window manager that won't shrink with (-1,-1) | - | ||||||||||||||||||||||||
1008 | setMinimumSize(d->min.expandedTo(QSize(1, 1))); | - | ||||||||||||||||||||||||
1009 | setMaximumSize(d->max); | - | ||||||||||||||||||||||||
1010 | resize(d->size); | - | ||||||||||||||||||||||||
1011 | if (layout())
| 0 | ||||||||||||||||||||||||
1012 | layout()->setEnabled(true); never executed: layout()->setEnabled(true); | 0 | ||||||||||||||||||||||||
1013 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1014 | setSizeGripEnabled(d->sizeGripEnabled); | - | ||||||||||||||||||||||||
1015 | #endif | - | ||||||||||||||||||||||||
1016 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1017 | } | - | ||||||||||||||||||||||||
1018 | - | |||||||||||||||||||||||||
1019 | - | |||||||||||||||||||||||||
1020 | /*! \reimp */ | - | ||||||||||||||||||||||||
1021 | QSize QDialog::sizeHint() const | - | ||||||||||||||||||||||||
1022 | { | - | ||||||||||||||||||||||||
1023 | Q_D(const QDialog); | - | ||||||||||||||||||||||||
1024 | if (d->extension) {
| 0 | ||||||||||||||||||||||||
1025 | if (d->orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
1026 | return QSize(QWidget::sizeHint().width(), never executed: return QSize(QWidget::sizeHint().width(), qMax(QWidget::sizeHint().height(),d->extension->sizeHint().height())); | 0 | ||||||||||||||||||||||||
1027 | qMax(QWidget::sizeHint().height(),d->extension->sizeHint().height())); never executed: return QSize(QWidget::sizeHint().width(), qMax(QWidget::sizeHint().height(),d->extension->sizeHint().height())); | 0 | ||||||||||||||||||||||||
1028 | else | - | ||||||||||||||||||||||||
1029 | return QSize(qMax(QWidget::sizeHint().width(), d->extension->sizeHint().width()), never executed: return QSize(qMax(QWidget::sizeHint().width(), d->extension->sizeHint().width()), QWidget::sizeHint().height()); | 0 | ||||||||||||||||||||||||
1030 | QWidget::sizeHint().height()); never executed: return QSize(qMax(QWidget::sizeHint().width(), d->extension->sizeHint().width()), QWidget::sizeHint().height()); | 0 | ||||||||||||||||||||||||
1031 | } | - | ||||||||||||||||||||||||
1032 | return QWidget::sizeHint(); never executed: return QWidget::sizeHint(); | 0 | ||||||||||||||||||||||||
1033 | } | - | ||||||||||||||||||||||||
1034 | - | |||||||||||||||||||||||||
1035 | - | |||||||||||||||||||||||||
1036 | /*! \reimp */ | - | ||||||||||||||||||||||||
1037 | QSize QDialog::minimumSizeHint() const | - | ||||||||||||||||||||||||
1038 | { | - | ||||||||||||||||||||||||
1039 | Q_D(const QDialog); | - | ||||||||||||||||||||||||
1040 | if (d->extension) {
| 0 | ||||||||||||||||||||||||
1041 | if (d->orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
1042 | return QSize(QWidget::minimumSizeHint().width(), never executed: return QSize(QWidget::minimumSizeHint().width(), qMax(QWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height())); | 0 | ||||||||||||||||||||||||
1043 | qMax(QWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height())); never executed: return QSize(QWidget::minimumSizeHint().width(), qMax(QWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height())); | 0 | ||||||||||||||||||||||||
1044 | else | - | ||||||||||||||||||||||||
1045 | return QSize(qMax(QWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width()), never executed: return QSize(qMax(QWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width()), QWidget::minimumSizeHint().height()); | 0 | ||||||||||||||||||||||||
1046 | QWidget::minimumSizeHint().height()); never executed: return QSize(qMax(QWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width()), QWidget::minimumSizeHint().height()); | 0 | ||||||||||||||||||||||||
1047 | } | - | ||||||||||||||||||||||||
1048 | - | |||||||||||||||||||||||||
1049 | return QWidget::minimumSizeHint(); never executed: return QWidget::minimumSizeHint(); | 0 | ||||||||||||||||||||||||
1050 | } | - | ||||||||||||||||||||||||
1051 | - | |||||||||||||||||||||||||
1052 | /*! | - | ||||||||||||||||||||||||
1053 | \property QDialog::modal | - | ||||||||||||||||||||||||
1054 | \brief whether show() should pop up the dialog as modal or modeless | - | ||||||||||||||||||||||||
1055 | - | |||||||||||||||||||||||||
1056 | By default, this property is \c false and show() pops up the dialog | - | ||||||||||||||||||||||||
1057 | as modeless. Setting his property to true is equivalent to setting | - | ||||||||||||||||||||||||
1058 | QWidget::windowModality to Qt::ApplicationModal. | - | ||||||||||||||||||||||||
1059 | - | |||||||||||||||||||||||||
1060 | exec() ignores the value of this property and always pops up the | - | ||||||||||||||||||||||||
1061 | dialog as modal. | - | ||||||||||||||||||||||||
1062 | - | |||||||||||||||||||||||||
1063 | \sa QWidget::windowModality, show(), exec() | - | ||||||||||||||||||||||||
1064 | */ | - | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | void QDialog::setModal(bool modal) | - | ||||||||||||||||||||||||
1067 | { | - | ||||||||||||||||||||||||
1068 | setAttribute(Qt::WA_ShowModal, modal); | - | ||||||||||||||||||||||||
1069 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1070 | - | |||||||||||||||||||||||||
1071 | - | |||||||||||||||||||||||||
1072 | bool QDialog::isSizeGripEnabled() const | - | ||||||||||||||||||||||||
1073 | { | - | ||||||||||||||||||||||||
1074 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1075 | Q_D(const QDialog); | - | ||||||||||||||||||||||||
1076 | return !!d->resizer; never executed: return !!d->resizer; | 0 | ||||||||||||||||||||||||
1077 | #else | - | ||||||||||||||||||||||||
1078 | return false; | - | ||||||||||||||||||||||||
1079 | #endif | - | ||||||||||||||||||||||||
1080 | } | - | ||||||||||||||||||||||||
1081 | - | |||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||
1083 | void QDialog::setSizeGripEnabled(bool enabled) | - | ||||||||||||||||||||||||
1084 | { | - | ||||||||||||||||||||||||
1085 | #ifdef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1086 | Q_UNUSED(enabled); | - | ||||||||||||||||||||||||
1087 | #else | - | ||||||||||||||||||||||||
1088 | Q_D(QDialog); | - | ||||||||||||||||||||||||
1089 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1090 | d->sizeGripEnabled = enabled; | - | ||||||||||||||||||||||||
1091 | if (enabled && d->doShowExtension)
| 0 | ||||||||||||||||||||||||
1092 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1093 | #endif | - | ||||||||||||||||||||||||
1094 | if (!enabled != !d->resizer) {
| 0 | ||||||||||||||||||||||||
1095 | if (enabled) {
| 0 | ||||||||||||||||||||||||
1096 | d->resizer = new QSizeGrip(this); | - | ||||||||||||||||||||||||
1097 | // adjustSize() processes all events, which is suboptimal | - | ||||||||||||||||||||||||
1098 | d->resizer->resize(d->resizer->sizeHint()); | - | ||||||||||||||||||||||||
1099 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1100 | d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft()); never executed: d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft()); | 0 | ||||||||||||||||||||||||
1101 | else | - | ||||||||||||||||||||||||
1102 | d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight()); never executed: d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight()); | 0 | ||||||||||||||||||||||||
1103 | d->resizer->raise(); | - | ||||||||||||||||||||||||
1104 | d->resizer->show(); | - | ||||||||||||||||||||||||
1105 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1106 | delete d->resizer; | - | ||||||||||||||||||||||||
1107 | d->resizer = 0; | - | ||||||||||||||||||||||||
1108 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1109 | } | - | ||||||||||||||||||||||||
1110 | #endif //QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1111 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1112 | - | |||||||||||||||||||||||||
1113 | - | |||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||
1115 | /*! \reimp */ | - | ||||||||||||||||||||||||
1116 | void QDialog::resizeEvent(QResizeEvent *) | - | ||||||||||||||||||||||||
1117 | { | - | ||||||||||||||||||||||||
1118 | #ifndef QT_NO_SIZEGRIP | - | ||||||||||||||||||||||||
1119 | Q_D(QDialog); | - | ||||||||||||||||||||||||
1120 | if (d->resizer) {
| 0 | ||||||||||||||||||||||||
1121 | if (isRightToLeft())
| 0 | ||||||||||||||||||||||||
1122 | d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft()); never executed: d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft()); | 0 | ||||||||||||||||||||||||
1123 | else | - | ||||||||||||||||||||||||
1124 | d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight()); never executed: d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight()); | 0 | ||||||||||||||||||||||||
1125 | d->resizer->raise(); | - | ||||||||||||||||||||||||
1126 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1127 | #endif | - | ||||||||||||||||||||||||
1128 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1129 | - | |||||||||||||||||||||||||
1130 | /*! \fn void QDialog::finished(int result) | - | ||||||||||||||||||||||||
1131 | \since 4.1 | - | ||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||
1133 | This signal is emitted when the dialog's \a result code has been | - | ||||||||||||||||||||||||
1134 | set, either by the user or by calling done(), accept(), or | - | ||||||||||||||||||||||||
1135 | reject(). | - | ||||||||||||||||||||||||
1136 | - | |||||||||||||||||||||||||
1137 | Note that this signal is \e not emitted when hiding the dialog | - | ||||||||||||||||||||||||
1138 | with hide() or setVisible(false). This includes deleting the | - | ||||||||||||||||||||||||
1139 | dialog while it is visible. | - | ||||||||||||||||||||||||
1140 | - | |||||||||||||||||||||||||
1141 | \sa accepted(), rejected() | - | ||||||||||||||||||||||||
1142 | */ | - | ||||||||||||||||||||||||
1143 | - | |||||||||||||||||||||||||
1144 | /*! \fn void QDialog::accepted() | - | ||||||||||||||||||||||||
1145 | \since 4.1 | - | ||||||||||||||||||||||||
1146 | - | |||||||||||||||||||||||||
1147 | This signal is emitted when the dialog has been accepted either by | - | ||||||||||||||||||||||||
1148 | the user or by calling accept() or done() with the | - | ||||||||||||||||||||||||
1149 | QDialog::Accepted argument. | - | ||||||||||||||||||||||||
1150 | - | |||||||||||||||||||||||||
1151 | Note that this signal is \e not emitted when hiding the dialog | - | ||||||||||||||||||||||||
1152 | with hide() or setVisible(false). This includes deleting the | - | ||||||||||||||||||||||||
1153 | dialog while it is visible. | - | ||||||||||||||||||||||||
1154 | - | |||||||||||||||||||||||||
1155 | \sa finished(), rejected() | - | ||||||||||||||||||||||||
1156 | */ | - | ||||||||||||||||||||||||
1157 | - | |||||||||||||||||||||||||
1158 | /*! \fn void QDialog::rejected() | - | ||||||||||||||||||||||||
1159 | \since 4.1 | - | ||||||||||||||||||||||||
1160 | - | |||||||||||||||||||||||||
1161 | This signal is emitted when the dialog has been rejected either by | - | ||||||||||||||||||||||||
1162 | the user or by calling reject() or done() with the | - | ||||||||||||||||||||||||
1163 | QDialog::Rejected argument. | - | ||||||||||||||||||||||||
1164 | - | |||||||||||||||||||||||||
1165 | Note that this signal is \e not emitted when hiding the dialog | - | ||||||||||||||||||||||||
1166 | with hide() or setVisible(false). This includes deleting the | - | ||||||||||||||||||||||||
1167 | dialog while it is visible. | - | ||||||||||||||||||||||||
1168 | - | |||||||||||||||||||||||||
1169 | \sa finished(), accepted() | - | ||||||||||||||||||||||||
1170 | */ | - | ||||||||||||||||||||||||
1171 | - | |||||||||||||||||||||||||
1172 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
1173 | #include "moc_qdialog.cpp" | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |