1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qdialog.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | #include "qevent.h"
|
---|
46 | #include "qdesktopwidget.h"
|
---|
47 | #include "qpushbutton.h"
|
---|
48 | #include "qapplication.h"
|
---|
49 | #include "qlayout.h"
|
---|
50 | #include "qsizegrip.h"
|
---|
51 | #include "qwhatsthis.h"
|
---|
52 | #include "qmenu.h"
|
---|
53 | #include "qcursor.h"
|
---|
54 | #include "private/qdialog_p.h"
|
---|
55 | #ifndef QT_NO_ACCESSIBILITY
|
---|
56 | #include "qaccessible.h"
|
---|
57 | #endif
|
---|
58 | #if defined(Q_OS_WINCE)
|
---|
59 | #include "qt_windows.h"
|
---|
60 | #include "qmenubar.h"
|
---|
61 | #include "qpointer.h"
|
---|
62 | #include "qguifunctions_wince.h"
|
---|
63 | extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
|
---|
64 | extern bool qt_wince_is_smartphone(); //is defined in qguifunctions_wce.cpp
|
---|
65 | #elif defined(Q_WS_X11)
|
---|
66 | # include "../kernel/qt_x11_p.h"
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #ifndef SPI_GETSNAPTODEFBUTTON
|
---|
70 | # define SPI_GETSNAPTODEFBUTTON 95
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | QT_BEGIN_NAMESPACE
|
---|
74 |
|
---|
75 | /*!
|
---|
76 | \class QDialog
|
---|
77 | \brief The QDialog class is the base class of dialog windows.
|
---|
78 |
|
---|
79 | \ingroup dialogs
|
---|
80 | \ingroup abstractwidgets
|
---|
81 | \mainclass
|
---|
82 |
|
---|
83 | A dialog window is a top-level window mostly used for short-term
|
---|
84 | tasks and brief communications with the user. QDialogs may be
|
---|
85 | modal or modeless. QDialogs can
|
---|
86 | provide a \link #return return
|
---|
87 | value\endlink, and they can have \link #default default
|
---|
88 | buttons\endlink. QDialogs can also have a QSizeGrip in their
|
---|
89 | lower-right corner, using setSizeGripEnabled().
|
---|
90 |
|
---|
91 | Note that QDialog (an any other widget that has type Qt::Dialog) uses
|
---|
92 | the parent widget slightly differently from other classes in Qt. A
|
---|
93 | dialog is always a top-level widget, but if it has a parent, its
|
---|
94 | default location is centered on top of the parent's top-level widget
|
---|
95 | (if it is not top-level itself). It will also share the parent's
|
---|
96 | taskbar entry.
|
---|
97 |
|
---|
98 | Use the overload of the QWidget::setParent() function to change
|
---|
99 | the ownership of a QDialog widget. This function allows you to
|
---|
100 | explicitly set the window flags of the reparented widget; using
|
---|
101 | the overloaded function will clear the window flags specifying the
|
---|
102 | window-system properties for the widget (in particular it will
|
---|
103 | reset the Qt::Dialog flag).
|
---|
104 |
|
---|
105 | \section1 Modal Dialogs
|
---|
106 |
|
---|
107 | A \bold{modal} dialog is a dialog that blocks input to other
|
---|
108 | visible windows in the same application. Dialogs that are used to
|
---|
109 | request a file name from the user or that are used to set
|
---|
110 | application preferences are usually modal. Dialogs can be
|
---|
111 | \l{Qt::ApplicationModal}{application modal} (the default) or
|
---|
112 | \l{Qt::WindowModal}{window modal}.
|
---|
113 |
|
---|
114 | When an application modal dialog is opened, the user must finish
|
---|
115 | interacting with the dialog and close it before they can access
|
---|
116 | any other window in the application. Window modal dialogs only
|
---|
117 | block access to the window associated with the dialog, allowing
|
---|
118 | the user to continue to use other windows in an application.
|
---|
119 |
|
---|
120 | The most common way to display a modal dialog is to call its
|
---|
121 | exec() function. When the user closes the dialog, exec() will
|
---|
122 | provide a useful \link #return return value\endlink. Typically,
|
---|
123 | to get the dialog to close and return the appropriate value, we
|
---|
124 | connect a default button, e.g. \gui OK, to the accept() slot and a
|
---|
125 | \gui Cancel button to the reject() slot.
|
---|
126 | Alternatively you can call the done() slot with \c Accepted or
|
---|
127 | \c Rejected.
|
---|
128 |
|
---|
129 | An alternative is to call setModal(true) or setWindowModality(),
|
---|
130 | then show(). Unlike exec(), show() returns control to the caller
|
---|
131 | immediately. Calling setModal(true) is especially useful for
|
---|
132 | progress dialogs, where the user must have the ability to interact
|
---|
133 | with the dialog, e.g. to cancel a long running operation. If you
|
---|
134 | use show() and setModal(true) together to perform a long operation,
|
---|
135 | you must call QApplication::processEvents() periodically during
|
---|
136 | processing to enable the user to interact with the dialog. (See
|
---|
137 | QProgressDialog.)
|
---|
138 |
|
---|
139 | \section1 Modeless Dialogs
|
---|
140 |
|
---|
141 | A \bold{modeless} dialog is a dialog that operates
|
---|
142 | independently of other windows in the same application. Find and
|
---|
143 | replace dialogs in word-processors are often modeless to allow the
|
---|
144 | user to interact with both the application's main window and with
|
---|
145 | the dialog.
|
---|
146 |
|
---|
147 | Modeless dialogs are displayed using show(), which returns control
|
---|
148 | to the caller immediately.
|
---|
149 |
|
---|
150 | If you invoke the \l{QWidget::show()}{show()} function after hiding
|
---|
151 | a dialog, the dialog will be displayed in its original position. This is
|
---|
152 | because the window manager decides the position for windows that
|
---|
153 | have not been explicitly placed by the programmer. To preserve the
|
---|
154 | position of a dialog that has been moved by the user, save its position
|
---|
155 | in your \l{QWidget::closeEvent()}{closeEvent()} handler and then
|
---|
156 | move the dialog to that position, before showing it again.
|
---|
157 |
|
---|
158 | \target default
|
---|
159 | \section1 Default Button
|
---|
160 |
|
---|
161 | A dialog's \e default button is the button that's pressed when the
|
---|
162 | user presses Enter (Return). This button is used to signify that
|
---|
163 | the user accepts the dialog's settings and wants to close the
|
---|
164 | dialog. Use QPushButton::setDefault(), QPushButton::isDefault()
|
---|
165 | and QPushButton::autoDefault() to set and control the dialog's
|
---|
166 | default button.
|
---|
167 |
|
---|
168 | \target escapekey
|
---|
169 | \section1 Escape Key
|
---|
170 |
|
---|
171 | If the user presses the Esc key in a dialog, QDialog::reject()
|
---|
172 | will be called. This will cause the window to close: The \link
|
---|
173 | QCloseEvent close event \endlink cannot be \link
|
---|
174 | QCloseEvent::ignore() ignored \endlink.
|
---|
175 |
|
---|
176 | \section1 Extensibility
|
---|
177 |
|
---|
178 | Extensibility is the ability to show the dialog in two ways: a
|
---|
179 | partial dialog that shows the most commonly used options, and a
|
---|
180 | full dialog that shows all the options. Typically an extensible
|
---|
181 | dialog will initially appear as a partial dialog, but with a
|
---|
182 | \gui More toggle button. If the user presses the \gui More button down,
|
---|
183 | the dialog is expanded. The \l{Extension Example} shows how to achieve
|
---|
184 | extensible dialogs using Qt.
|
---|
185 |
|
---|
186 | \target return
|
---|
187 | \section1 Return Value (Modal Dialogs)
|
---|
188 |
|
---|
189 | Modal dialogs are often used in situations where a return value is
|
---|
190 | required, e.g. to indicate whether the user pressed \gui OK or
|
---|
191 | \gui Cancel. A dialog can be closed by calling the accept() or the
|
---|
192 | reject() slots, and exec() will return \c Accepted or \c Rejected
|
---|
193 | as appropriate. The exec() call returns the result of the dialog.
|
---|
194 | The result is also available from result() if the dialog has not
|
---|
195 | been destroyed.
|
---|
196 |
|
---|
197 | In order to modify your dialog's close behavior, you can reimplement
|
---|
198 | the functions accept(), reject() or done(). The
|
---|
199 | \l{QWidget::closeEvent()}{closeEvent()} function should only be
|
---|
200 | reimplemented to preserve the dialog's position or to override the
|
---|
201 | standard close or reject behavior.
|
---|
202 |
|
---|
203 | \target examples
|
---|
204 | \section1 Code Examples
|
---|
205 |
|
---|
206 | A modal dialog:
|
---|
207 |
|
---|
208 | \snippet doc/src/snippets/dialogs/dialogs.cpp 1
|
---|
209 |
|
---|
210 | A modeless dialog:
|
---|
211 |
|
---|
212 | \snippet doc/src/snippets/dialogs/dialogs.cpp 0
|
---|
213 |
|
---|
214 | \sa QDialogButtonBox, QTabWidget, QWidget, QProgressDialog,
|
---|
215 | {fowler}{GUI Design Handbook: Dialogs, Standard}, {Extension Example},
|
---|
216 | {Standard Dialogs Example}
|
---|
217 | */
|
---|
218 |
|
---|
219 | /*! \enum QDialog::DialogCode
|
---|
220 |
|
---|
221 | The value returned by a modal dialog.
|
---|
222 |
|
---|
223 | \value Accepted
|
---|
224 | \value Rejected
|
---|
225 | */
|
---|
226 |
|
---|
227 | /*!
|
---|
228 | \property QDialog::sizeGripEnabled
|
---|
229 | \brief whether the size grip is enabled
|
---|
230 |
|
---|
231 | A QSizeGrip is placed in the bottom-right corner of the dialog when this
|
---|
232 | property is enabled. By default, the size grip is disabled.
|
---|
233 | */
|
---|
234 |
|
---|
235 |
|
---|
236 | /*!
|
---|
|
---|