1 | /****************************************************************************
|
---|
2 | ** $Id: qmessagebox.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Implementation of QMessageBox class
|
---|
5 | **
|
---|
6 | ** Created : 950503
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the dialogs module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
23 | ** Agreement provided with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | #include "qmessagebox.h"
|
---|
39 |
|
---|
40 | #ifndef QT_NO_MESSAGEBOX
|
---|
41 |
|
---|
42 | #include "qaccel.h"
|
---|
43 | #include "qlabel.h"
|
---|
44 | #include "qpushbutton.h"
|
---|
45 | #include "qimage.h"
|
---|
46 | #include "qapplication.h"
|
---|
47 | #include "qstyle.h"
|
---|
48 | #include "qobjectlist.h"
|
---|
49 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
50 | #include "qaccessible.h"
|
---|
51 | #endif
|
---|
52 | #if defined QT_NON_COMMERCIAL
|
---|
53 | #include "qnc_win.h"
|
---|
54 | #endif
|
---|
55 |
|
---|
56 |
|
---|
57 | // Internal class - don't touch
|
---|
58 |
|
---|
59 | class QMessageBoxLabel : public QLabel
|
---|
60 | {
|
---|
61 | Q_OBJECT
|
---|
62 | public:
|
---|
63 | QMessageBoxLabel( QWidget* parent ) : QLabel( parent, "messageBoxText")
|
---|
64 | {
|
---|
65 | setAlignment( AlignAuto|ExpandTabs );
|
---|
66 | }
|
---|
67 | };
|
---|
68 | #include "qmessagebox.moc"
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 | // the Qt logo, for aboutQt
|
---|
73 | /* XPM */
|
---|
74 | static const char * const qtlogo_xpm[] = {
|
---|
75 | /* width height ncolors chars_per_pixel */
|
---|
76 | "50 50 17 1",
|
---|
77 | /* colors */
|
---|
78 | " c #000000",
|
---|
79 | ". c #495808",
|
---|
80 | "X c #2A3304",
|
---|
81 | "o c #242B04",
|
---|
82 | "O c #030401",
|
---|
83 | "+ c #9EC011",
|
---|
84 | "@ c #93B310",
|
---|
85 | "# c #748E0C",
|
---|
86 | "$ c #A2C511",
|
---|
87 | "% c #8BA90E",
|
---|
88 | "& c #99BA10",
|
---|
89 | "* c #060701",
|
---|
90 | "= c #181D02",
|
---|
91 | "- c #212804",
|
---|
92 | "; c #61770A",
|
---|
93 | ": c #0B0D01",
|
---|
94 | "/ c None",
|
---|
95 | /* pixels */
|
---|
96 | "/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/",
|
---|
97 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
98 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
99 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
100 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
101 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
102 | "$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
103 | "$$$$$$$$$$$$$$$$$$$@;.o=::=o.;@$$$$$$$$$$$$$$$$$$$",
|
---|
104 | "$$$$$$$$$$$$$$$$+#X* **X#+$$$$$$$$$$$$$$$$",
|
---|
105 | "$$$$$$$$$$$$$$$#oO* O **o#+$$$$$$$$$$$$$$",
|
---|
106 | "$$$$$$$$$$$$$&.* OO O*.&$$$$$$$$$$$$$",
|
---|
107 | "$$$$$$$$$$$$@XOO * OO X&$$$$$$$$$$$$",
|
---|
108 | "$$$$$$$$$$$@XO OO O **:::OOO OOO X@$$$$$$$$$$$",
|
---|
109 | "$$$$$$$$$$&XO O-;#@++@%.oOO X&$$$$$$$$$$",
|
---|
110 | "$$$$$$$$$$.O : *-#+$$$$$$$$+#- : O O*.$$$$$$$$$$",
|
---|
111 | "$$$$$$$$$#*OO O*.&$$$$$$$$$$$$+.OOOO **#$$$$$$$$$",
|
---|
112 | "$$$$$$$$+-OO O *;$$$$$$$$$$$&$$$$;* o+$$$$$$$$",
|
---|
113 | "$$$$$$$$#O* O .+$$$$$$$$$$@X;$$$+.O *#$$$$$$$$",
|
---|
114 | "$$$$$$$$X* -&$$$$$$$$$$@- :;$$$&- OX$$$$$$$$",
|
---|
115 | "$$$$$$$@*O *O#$$$$$$$$$$@oOO**;$$$# O*%$$$$$$$",
|
---|
116 | "$$$$$$$; -+$$$$$$$$$@o O OO ;+$$-O *;$$$$$$$",
|
---|
117 | "$$$$$$$. ;$$$$$$$$$@-OO OO X&$$;O .$$$$$$$",
|
---|
118 | "$$$$$$$o *#$$$$$$$$@o O O O-@$$$#O *o$$$$$$$",
|
---|
119 | "$$$$$$+= *@$$$$$$$@o* OO -@$$$$&: =$$$$$$$",
|
---|
120 | "$$$$$$+: :+$$$$$$@- *-@$$$$$$: :+$$$$$$",
|
---|
121 | "$$$$$$+: :+$$$$$@o* O *-@$$$$$$: :+$$$$$$",
|
---|
122 | "$$$$$$$= :@$$$$@o*OOO -@$$$$@: =+$$$$$$",
|
---|
123 | "$$$$$$$- O%$$$@o* O O O O-@$$$#* OX$$$$$$$",
|
---|
124 | "$$$$$$$. O *O;$$&o O*O* *O -@$$; O.$$$$$$$",
|
---|
125 | "$$$$$$$;* Oo+$$;O*O:OO-- Oo@+= *;$$$$$$$",
|
---|
126 | "$$$$$$$@* O O#$$$;*OOOo@@-O Oo;O* **@$$$$$$$",
|
---|
127 | "$$$$$$$$X* OOO-+$$$;O o@$$@- O O OX$$$$$$$$",
|
---|
128 | "$$$$$$$$#* * O.$$$$;X@$$$$@-O O O#$$$$$$$$",
|
---|
129 | "$$$$$$$$+oO O OO.+$$+&$$$$$$@-O o+$$$$$$$$",
|
---|
130 | "$$$$$$$$$#* **.&$$$$$$$$$$@o OO:#$$$$$$$$$",
|
---|
131 | "$$$$$$$$$+. O* O-#+$$$$$$$$+;O OOO:@$$$$$$$$$",
|
---|
132 | "$$$$$$$$$$&X *O -;#@++@#;=O O -@$$$$$$$$",
|
---|
133 | "$$$$$$$$$$$&X O O*O::::O OO Oo@$$$$$$$",
|
---|
134 | "$$$$$$$$$$$$@XOO OO O*X+$$$$$$",
|
---|
135 | "$$$$$$$$$$$$$&.* ** O :: *:#$$$$$$$",
|
---|
136 | "$$$$$$$$$$$$$$$#o*OO O Oo#@-OOO=#$$$$$$$$",
|
---|
137 | "$$$$$$$$$$$$$$$$+#X:* * O**X#+$$@-*:#$$$$$$$$$",
|
---|
138 | "$$$$$$$$$$$$$$$$$$$%;.o=::=o.#@$$$$$$@X#$$$$$$$$$$",
|
---|
139 | "$$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$+$$$$$$$$$$$",
|
---|
140 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
141 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
142 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
143 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
144 | "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
---|
145 | "/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/",
|
---|
146 | };
|
---|
147 |
|
---|
148 |
|
---|
149 | /*!
|
---|
150 | \class QMessageBox
|
---|
151 | \brief The QMessageBox class provides a modal dialog with a short message, an icon, and some buttons.
|
---|
152 | \ingroup dialogs
|
---|
153 | \mainclass
|
---|
154 |
|
---|
155 | Message boxes are used to provide informative messages and to ask
|
---|
156 | simple questions.
|
---|
157 |
|
---|
158 | QMessageBox provides a range of different messages, arranged
|
---|
159 | roughly along two axes: severity and complexity.
|
---|
160 |
|
---|
161 | Severity is
|
---|
162 | \table
|
---|
163 | \row
|
---|
164 | \i \img qmessagebox-quest.png
|
---|
165 | \i Question
|
---|
166 | \i For message boxes that ask a question as part of normal
|
---|
167 | operation. Some style guides recommend using Information for this
|
---|
168 | purpose.
|
---|
169 | \row
|
---|
170 | \i \img qmessagebox-info.png
|
---|
171 | \i Information
|
---|
172 | \i For message boxes that are part of normal operation.
|
---|
173 | \row
|
---|
174 | \i \img qmessagebox-warn.png
|
---|
175 | \i Warning
|
---|
176 | \i For message boxes that tell the user about unusual errors.
|
---|
177 | \row
|
---|
178 | \i \img qmessagebox-crit.png
|
---|
179 | \i Critical
|
---|
180 | \i For message boxes that tell the user about critical errors.
|
---|
181 | \endtable
|
---|
182 |
|
---|
183 | The message box has a different icon for each of the severity levels.
|
---|
184 |
|
---|
185 | Complexity is one button (OK) for simple messages, or two or even
|
---|
186 | three buttons for questions.
|
---|
187 |
|
---|
188 | There are static functions for the most common cases.
|
---|
189 |
|
---|
190 | Examples:
|
---|
191 |
|
---|
192 | If a program is unable to find a supporting file, but can do perfectly
|
---|
193 | well without it:
|
---|
194 |
|
---|
195 | \code
|
---|
196 | QMessageBox::information( this, "Application name",
|
---|
197 | "Unable to find the user preferences file.\n"
|
---|
198 | "The factory default will be used instead." );
|
---|
199 | \endcode
|
---|
200 |
|
---|
201 | question() is useful for simple yes/no questions:
|
---|
202 |
|
---|
203 | \code
|
---|
204 | if ( QFile::exists( filename ) &&
|
---|
205 | QMessageBox::question(
|
---|
206 | this,
|
---|
207 | tr("Overwrite File? -- Application Name"),
|
---|
208 | tr("A file called %1 already exists."
|
---|
209 | "Do you want to overwrite it?")
|
---|
210 | .arg( filename ),
|
---|
211 | tr("&Yes"), tr("&No"),
|
---|
212 | QString::null, 0, 1 ) )
|
---|
213 | return false;
|
---|
214 | \endcode
|
---|
215 |
|
---|
216 | warning() can be used to tell the user about unusual errors, or
|
---|
217 | errors which can't be easily fixed:
|
---|
218 |
|
---|
219 | \code
|
---|
220 | switch( QMessageBox::warning( this, "Application name",
|
---|
221 | "Could not connect to the <mumble> server.\n"
|
---|
222 | "This program can't function correctly "
|
---|
223 | "without the server.\n\n",
|
---|
224 | "Retry",
|
---|
225 | "Quit", 0, 0, 1 ) ) {
|
---|
226 | case 0: // The user clicked the Retry again button or pressed Enter
|
---|
227 | // try again
|
---|
228 | break;
|
---|
229 | case 1: // The user clicked the Quit or pressed Escape
|
---|
230 | // exit
|
---|
231 | break;
|
---|
232 | }
|
---|
233 | \endcode
|
---|
234 |
|
---|
235 | The text part of all message box messages can be either rich text
|
---|
236 | or plain text. If you specify a rich text formatted string, it
|
---|
237 | will be rendered using the default stylesheet. See
|
---|
238 | QStyleSheet::defaultSheet() for details. With certain strings that
|
---|
239 | contain XML meta characters, the auto-rich text detection may
|
---|
240 | fail, interpreting plain text incorrectly as rich text. In these
|
---|
241 | rare cases, use QStyleSheet::convertFromPlainText() to convert
|
---|
242 | your plain text string to a visually equivalent rich text string
|
---|
243 | or set the text format explicitly with setTextFormat().
|
---|
244 |
|
---|
245 | Note that the Microsoft Windows User Interface Guidelines
|
---|
246 | recommend using the application name as the window's caption.
|
---|
247 |
|
---|
248 | Below are more examples of how to use the static member functions.
|
---|
249 | After these examples you will find an overview of the non-static
|
---|
250 | member functions.
|
---|
251 |
|
---|
252 | Exiting a program is part of its normal operation. If there is
|
---|
253 | unsaved data the user probably should be asked if they want to
|
---|
254 | save the data. For example:
|
---|
255 |
|
---|
256 | \code
|
---|
257 | switch( QMessageBox::information( this, "Application name here",
|
---|
258 | "The document contains unsaved changes\n"
|
---|
259 | "Do you want to save the changes before exiting?",
|
---|
260 | "&Save", "&Discard", "Cancel",
|
---|
261 | 0, // Enter == button 0
|
---|
262 | 2 ) ) { // Escape == button 2
|
---|
263 | case 0: // Save clicked or Alt+S pressed or Enter pressed.
|
---|
264 | // save
|
---|
265 | break;
|
---|
266 | case 1: // Discard clicked or Alt+D pressed
|
---|
267 | // don't save but exit
|
---|
268 | break;
|
---|
269 | case 2: // Cancel clicked or Escape pressed
|
---|
270 | // don't exit
|
---|
271 | break;
|
---|
272 | }
|
---|
273 | \endcode
|
---|
274 |
|
---|
275 | The Escape button cancels the entire exit operation, and pressing
|
---|
276 | Enter causes the changes to be saved before the exit occurs.
|
---|
277 |
|
---|
278 | Disk full errors are unusual and they certainly can be hard to
|
---|
279 | correct. This example uses predefined buttons instead of
|
---|
280 | hard-coded button texts:
|
---|
281 |
|
---|
282 | \code
|
---|
283 | switch( QMessageBox::warning( this, "Application name here",
|
---|
284 | "Could not save the user preferences,\n"
|
---|
285 | "because the disk is full. You can delete\n"
|
---|
286 | "some files and press Retry, or you can\n"
|
---|
287 | "abort the Save Preferences operation.",
|
---|
288 | QMessageBox::Retry | QMessageBox::Default,
|
---|
289 | QMessageBox::Abort | QMessageBox::Escape )) {
|
---|
290 | case QMessageBox::Retry: // Retry clicked or Enter pressed
|
---|
291 | // try again
|
---|
292 | break;
|
---|
293 | case QMessageBox::Abort: // Abort clicked or Escape pressed
|
---|
294 | // abort
|
---|
295 | break;
|
---|
296 | }
|
---|
297 | \endcode
|
---|
298 |
|
---|
299 | The critical() function should be reserved for critical errors. In
|
---|
300 | this example errorDetails is a QString or const char*, and QString
|
---|
301 | is used to concatenate several strings:
|
---|
302 |
|
---|
303 | \code
|
---|
304 | QMessageBox::critical( 0, "Application name here",
|
---|
305 | QString("An internal error occurred. Please ") +
|
---|
306 | "call technical support at 1234-56789 and report\n"+
|
---|
307 | "these numbers:\n\n" + errorDetails +
|
---|
308 | "\n\nApplication will now exit." );
|
---|
309 | \endcode
|
---|
310 |
|
---|
311 | In this example an OK button is displayed.
|
---|
312 |
|
---|
313 | QMessageBox provides a very simple About box which displays an
|
---|
314 | appropriate icon and the string you provide:
|
---|
315 |
|
---|
316 | \code
|
---|
317 | QMessageBox::about( this, "About <Application>",
|
---|
318 | "<Application> is a <one-paragraph blurb>\n\n"
|
---|
319 | "Copyright 1991-2003 Such-and-such. "
|
---|
320 | "<License words here.>\n\n"
|
---|
321 | "For technical support, call 1234-56789 or see\n"
|
---|
322 | "http://www.such-and-such.com/Application/\n" );
|
---|
323 | \endcode
|
---|
324 |
|
---|
325 | See about() for more information.
|
---|
326 |
|
---|
327 | If you want your users to know that the application is built using
|
---|
328 | Qt (so they know that you use high quality tools) you might like
|
---|
329 | to add an "About Qt" menu option under the Help menu to invoke
|
---|
330 | aboutQt().
|
---|
331 |
|
---|
332 | If none of the standard message boxes is suitable, you can create a
|
---|
333 | QMessageBox from scratch and use custom button texts:
|
---|
334 |
|
---|
335 | \code
|
---|
336 | QMessageBox mb( "Application name here",
|
---|
337 | "Saving the file will overwrite the original file on the disk.\n"
|
---|
338 | "Do you really want to save?",
|
---|
339 | QMessageBox::Information,
|
---|
340 | QMessageBox::Yes | QMessageBox::Default,
|
---|
341 | QMessageBox::No,
|
---|
342 | QMessageBox::Cancel | QMessageBox::Escape );
|
---|
343 | mb.setButtonText( QMessageBox::Yes, "Save" );
|
---|
344 | mb.setButtonText( QMessageBox::No, "Discard" );
|
---|
345 | switch( mb.exec() ) {
|
---|
346 | case QMessageBox::Yes:
|
---|
347 | // save and exit
|
---|
348 | break;
|
---|
349 | case QMessageBox::No:
|
---|
350 | // exit without saving
|
---|
351 | break;
|
---|
352 | case QMessageBox::Cancel:
|
---|
353 | // don't save and don't exit
|
---|
354 | break;
|
---|
355 | }
|
---|
356 | \endcode
|
---|
357 |
|
---|
358 | QMessageBox defines two enum types: Icon and an unnamed button type.
|
---|
359 | Icon defines the \c Question, \c Information, \c Warning, and \c
|
---|
360 | Critical icons for each GUI style. It is used by the constructor
|
---|
361 | and by the static member functions question(), information(),
|
---|
362 | warning() and critical(). A function called standardIcon() gives
|
---|
363 | you access to the various icons.
|
---|
364 |
|
---|
365 | The button types are:
|
---|
366 | \list
|
---|
367 | \i Ok - the default for single-button message boxes
|
---|
368 | \i Cancel - note that this is \e not automatically Escape
|
---|
369 | \i Yes
|
---|
370 | \i No
|
---|
371 | \i Abort
|
---|
372 | \i Retry
|
---|
373 | \i Ignore
|
---|
374 | \i YesAll
|
---|
375 | \i NoAll
|
---|
376 | \endlist
|
---|
377 |
|
---|
378 | Button types can be combined with two modifiers by using OR, '|':
|
---|
379 | \list
|
---|
380 | \i Default - makes pressing Enter equivalent to
|
---|
381 | clicking this button. Normally used with Ok, Yes or similar.
|
---|
382 | \i Escape - makes pressing Escape equivalent to clicking this button.
|
---|
383 | Normally used with Abort, Cancel or similar.
|
---|
384 | \endlist
|
---|
385 |
|
---|
386 | The text(), icon() and iconPixmap() functions provide access to the
|
---|
387 | current text and pixmap of the message box. The setText(), setIcon()
|
---|
388 | and setIconPixmap() let you change it. The difference between
|
---|
389 | setIcon() and setIconPixmap() is that the former accepts a
|
---|
390 | QMessageBox::Icon and can be used to set standard icons, whereas the
|
---|
391 | latter accepts a QPixmap and can be used to set custom icons.
|
---|
392 |
|
---|
393 | setButtonText() and buttonText() provide access to the buttons.
|
---|
394 |
|
---|
395 | QMessageBox has no signals or slots.
|
---|
396 |
|
---|
397 | <img src=qmsgbox-m.png> <img src=qmsgbox-w.png>
|
---|
398 |
|
---|
399 | \sa QDialog,
|
---|
400 | \link http://www.iarchitect.com/errormsg.htm
|
---|
401 | Isys on error messages \endlink,
|
---|
402 | \link guibooks.html#fowler GUI Design Handbook: Message Box \endlink
|
---|
403 | */
|
---|
404 |
|
---|
405 |
|
---|
406 | /*!
|
---|
407 | \enum QMessageBox::Icon
|
---|
408 |
|
---|
409 | This enum has the following values:
|
---|
410 |
|
---|
411 | \value NoIcon the message box does not have any icon.
|
---|
412 |
|
---|
413 | \value Question an icon indicating that
|
---|
414 | the message is asking a question.
|
---|
415 |
|
---|
416 | \value Information an icon indicating that
|
---|
417 | the message is nothing out of the ordinary.
|
---|
418 |
|
---|
419 | \value Warning an icon indicating that the
|
---|
420 | message is a warning, but can be dealt with.
|
---|
421 |
|
---|
422 | \value Critical an icon indicating that
|
---|
423 | the message represents a critical problem.
|
---|
424 |
|
---|
425 | */
|
---|
426 |
|
---|
427 |
|
---|
428 | struct QMessageBoxData {
|
---|
429 | QMessageBoxData(QMessageBox* parent) :
|
---|
430 | iconLabel( parent, "icon" )
|
---|
431 | {
|
---|
432 | }
|
---|
433 |
|
---|
434 | int numButtons; // number of buttons
|
---|
435 | QMessageBox::Icon icon; // message box icon
|
---|
436 | QLabel iconLabel; // label holding any icon
|
---|
437 | int button[3]; // button types
|
---|
438 | int defButton; // default button (index)
|
---|
439 | int escButton; // escape button (index)
|
---|
440 | QSize buttonSize; // button size
|
---|
441 | QPushButton *pb[3]; // buttons
|
---|
442 | };
|
---|
443 |
|
---|
444 | static const int LastButton = QMessageBox::NoAll;
|
---|
445 |
|
---|
446 | /*
|
---|
447 | NOTE: The table of button texts correspond to the button enum.
|
---|
448 | */
|
---|
449 |
|
---|
450 | #ifndef Q_OS_TEMP
|
---|
451 | static const char * const mb_texts[] = {
|
---|
452 | #else
|
---|
453 | const char * mb_texts[] = {
|
---|
454 | #endif
|
---|
455 | 0,
|
---|
456 | QT_TRANSLATE_NOOP("QMessageBox","OK"),
|
---|
457 | QT_TRANSLATE_NOOP("QMessageBox","Cancel"),
|
---|
458 | QT_TRANSLATE_NOOP("QMessageBox","&Yes"),
|
---|
459 | QT_TRANSLATE_NOOP("QMessageBox","&No"),
|
---|
460 | QT_TRANSLATE_NOOP("QMessageBox","&Abort"),
|
---|
461 | QT_TRANSLATE_NOOP("QMessageBox","&Retry"),
|
---|
462 | QT_TRANSLATE_NOOP("QMessageBox","&Ignore"),
|
---|
463 | QT_TRANSLATE_NOOP("QMessageBox","Yes to &All"),
|
---|
464 | QT_TRANSLATE_NOOP("QMessageBox","N&o to All"),
|
---|
465 | 0
|
---|
466 | };
|
---|
467 |
|
---|
468 | /*!
|
---|
469 | Constructs a message box with no text and a button with the label
|
---|
470 | "OK".
|
---|
471 |
|
---|
472 | If \a parent is 0, the message box becomes an application-global
|
---|
473 | modal dialog box. If \a parent is a widget, the message box
|
---|
474 | becomes modal relative to \a parent.
|
---|
475 |
|
---|
476 | The \a parent and \a name arguments are passed to the QDialog
|
---|
477 | constructor.
|
---|
478 | */
|
---|
479 |
|
---|
480 | QMessageBox::QMessageBox( QWidget *parent, const char *name )
|
---|
481 | : QDialog( parent, name, TRUE, WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu )
|
---|
482 | {
|
---|
483 | init( Ok, 0, 0 );
|
---|
484 | }
|
---|
485 |
|
---|
486 |
|
---|
487 | /*!
|
---|
488 | Constructs a message box with a \a caption, a \a text, an \a icon,
|
---|
489 | and up to three buttons.
|
---|
490 |
|
---|
491 | The \a icon must be one of the following:
|
---|
492 | \list
|
---|
493 | \i QMessageBox::NoIcon
|
---|
494 | \i QMessageBox::Question
|
---|
495 | \i QMessageBox::Information
|
---|
496 | \i QMessageBox::Warning
|
---|
497 | \i QMessageBox::Critical
|
---|
498 | \endlist
|
---|
499 |
|
---|
500 | Each button, \a button0, \a button1 and \a button2, can have one
|
---|
501 | of the following values:
|
---|
502 | \list
|
---|
503 | \i QMessageBox::NoButton
|
---|
504 | \i QMessageBox::Ok
|
---|
505 | \i QMessageBox::Cancel
|
---|
506 | \i QMessageBox::Yes
|
---|
507 | \i QMessageBox::No
|
---|
508 | \i QMessageBox::Abort
|
---|
509 | \i QMessageBox::Retry
|
---|
510 | \i QMessageBox::Ignore
|
---|
511 | \i QMessageBox::YesAll
|
---|
512 | \i QMessageBox::NoAll
|
---|
513 | \endlist
|
---|
514 |
|
---|
515 | Use QMessageBox::NoButton for the later parameters to have fewer
|
---|
516 | than three buttons in your message box. If you don't specify any
|
---|
517 | buttons at all, QMessageBox will provide an Ok button.
|
---|
518 |
|
---|
519 | One of the buttons can be OR-ed with the \c QMessageBox::Default
|
---|
520 | flag to make it the default button (clicked when Enter is
|
---|
521 | pressed).
|
---|
522 |
|
---|
523 | One of the buttons can be OR-ed with the \c QMessageBox::Escape
|
---|
524 | flag to make it the cancel or close button (clicked when Escape is
|
---|
525 | pressed).
|
---|
526 |
|
---|
527 | Example:
|
---|
528 | \code
|
---|
529 | QMessageBox mb( "Application Name",
|
---|
530 | "Hardware failure.\n\nDisk error detected\nDo you want to stop?",
|
---|
531 | QMessageBox::Question,
|
---|
532 | QMessageBox::Yes | QMessageBox::Default,
|
---|
533 | QMessageBox::No | QMessageBox::Escape
|
---|
534 | QMessageBox::NoButton );
|
---|
535 | if ( mb.exec() == QMessageBox::No )
|
---|
536 | // try again
|
---|
537 | \endcode
|
---|
538 |
|
---|
539 | If \a parent is 0, the message box becomes an application-global
|
---|
540 | modal dialog box. If \a parent is a widget, the message box
|
---|
541 | becomes modal relative to \a parent.
|
---|
542 |
|
---|
543 | If \a modal is TRUE the message box is modal; otherwise it
|
---|
544 | is modeless.
|
---|
545 |
|
---|
546 | The \a parent, \a name, \a modal, and \a f arguments are passed to
|
---|
547 | the QDialog constructor.
|
---|
548 |
|
---|
549 | \sa setCaption(), setText(), setIcon()
|
---|
550 | */
|
---|
551 |
|
---|
552 | QMessageBox::QMessageBox( const QString& caption,
|
---|
553 | const QString &text, Icon icon,
|
---|
554 | int button0, int button1, int button2,
|
---|
555 | QWidget *parent, const char *name,
|
---|
556 | bool modal, WFlags f )
|
---|
557 | : QDialog( parent, name, modal, f | WStyle_Customize | WStyle_DialogBorder | WStyle_Title | WStyle_SysMenu )
|
---|
558 | {
|
---|
559 | init( button0, button1, button2 );
|
---|
560 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
561 | setCaption( caption );
|
---|
562 | #endif
|
---|
563 | setText( text );
|
---|
564 | setIcon( icon );
|
---|
565 | }
|
---|
566 |
|
---|
567 |
|
---|
568 | /*!
|
---|
569 | Destroys the message box.
|
---|
570 | */
|
---|
571 |
|
---|
572 | QMessageBox::~QMessageBox()
|
---|
573 | {
|
---|
574 | delete mbd;
|
---|
575 | }
|
---|
576 |
|
---|
577 | static QString * translatedTextAboutQt = 0;
|
---|
578 |
|
---|
579 | void QMessageBox::init( int button0, int button1, int button2 )
|
---|
580 | {
|
---|
581 | if ( !translatedTextAboutQt ) {
|
---|
582 | translatedTextAboutQt = new QString;
|
---|
583 |
|
---|
584 | #if defined(QT_NON_COMMERCIAL)
|
---|
585 | QT_NC_MSGBOX
|
---|
586 | #else
|
---|
587 | *translatedTextAboutQt = tr(
|
---|
588 | "<h3>About Qt</h3>"
|
---|
589 | "<p>This program uses Qt version %1.</p>"
|
---|
590 | "<p>Qt is a C++ toolkit for multiplatform GUI & "
|
---|
591 | "application development.</p>"
|
---|
592 | "<p>Qt provides single-source "
|
---|
593 | "portability across MS Windows, Mac OS X, "
|
---|
594 | "Linux, and all major commercial Unix variants."
|
---|
595 | "<br>Qt is also available for embedded devices.</p>"
|
---|
596 | "<p>Qt is a Trolltech product. "
|
---|
597 | "See <tt>http://www.trolltech.com/qt/</tt> "
|
---|
598 | "for more information.</p>"
|
---|
599 | ).arg( QT_VERSION_STR );
|
---|
600 | #endif
|
---|
601 |
|
---|
602 | }
|
---|
603 | label = new QMessageBoxLabel( this );
|
---|
604 | Q_CHECK_PTR( label );
|
---|
605 |
|
---|
606 | if ( (button2 && !button1) || (button1 && !button0) ) {
|
---|
607 | #if defined(QT_CHECK_RANGE)
|
---|
608 | qWarning( "QMessageBox: Inconsistent button parameters" );
|
---|
609 | #endif
|
---|
610 | button0 = button1 = button2 = 0;
|
---|
611 | }
|
---|
612 | mbd = new QMessageBoxData(this);
|
---|
613 | Q_CHECK_PTR( mbd );
|
---|
614 | mbd->icon = NoIcon;
|
---|
615 | mbd->iconLabel.setPixmap( QPixmap() );
|
---|
616 | mbd->numButtons = 0;
|
---|
617 | mbd->button[0] = button0;
|
---|
618 | mbd->button[1] = button1;
|
---|
619 | mbd->button[2] = button2;
|
---|
620 | mbd->defButton = -1;
|
---|
621 | mbd->escButton = -1;
|
---|
622 | int i;
|
---|
623 | for ( i=0; i<3; i++ ) {
|
---|
624 | int b = mbd->button[i];
|
---|
625 | if ( (b & Default) ) {
|
---|
626 | if ( mbd->defButton >= 0 ) {
|
---|
627 | #if defined(QT_CHECK_RANGE)
|
---|
628 | qWarning( "QMessageBox: There can be at most one "
|
---|
629 | "default button" );
|
---|
630 | #endif
|
---|
631 | } else {
|
---|
632 | mbd->defButton = i;
|
---|
633 | }
|
---|
634 | }
|
---|
635 | if ( (b & Escape) ) {
|
---|
636 | if ( mbd->escButton >= 0 ) {
|
---|
637 | #if defined(QT_CHECK_RANGE)
|
---|
638 | qWarning( "QMessageBox: There can be at most one "
|
---|
639 | "escape button" );
|
---|
640 | #endif
|
---|
641 | } else {
|
---|
642 | mbd->escButton = i;
|
---|
643 | }
|
---|
644 | }
|
---|
645 | b &= ButtonMask;
|
---|
646 | if ( b == 0 ) {
|
---|
647 | if ( i == 0 ) // no buttons, add an Ok button
|
---|
648 | b = Ok;
|
---|
649 | } else if ( b < 0 || b > LastButton ) {
|
---|
650 | #if defined(QT_CHECK_RANGE)
|
---|
651 | qWarning( "QMessageBox: Invalid button specifier" );
|
---|
652 | #endif
|
---|
653 | b = Ok;
|
---|
654 | } else {
|
---|
655 | if ( i > 0 && mbd->button[i-1] == 0 ) {
|
---|
656 | #if defined(QT_CHECK_RANGE)
|
---|
657 | qWarning( "QMessageBox: Inconsistent button parameters; "
|
---|
658 | "button %d defined but not button %d",
|
---|
659 | i+1, i );
|
---|
660 | #endif
|
---|
661 | b = 0;
|
---|
662 | }
|
---|
663 | }
|
---|
664 | mbd->button[i] = b;
|
---|
665 | if ( b )
|
---|
666 | mbd->numButtons++;
|
---|
667 | }
|
---|
668 | for ( i=0; i<3; i++ ) {
|
---|
669 | if ( i >= mbd->numButtons ) {
|
---|
670 | mbd->pb[i] = 0;
|
---|
671 | } else {
|
---|
672 | QCString buttonName;
|
---|
673 | buttonName.sprintf( "button%d", i+1 );
|
---|
674 | mbd->pb[i] = new QPushButton(
|
---|
675 | tr(mb_texts[mbd->button[i]]),
|
---|
676 | this, buttonName );
|
---|
677 | if ( mbd->defButton == i ) {
|
---|
678 | mbd->pb[i]->setDefault( TRUE );
|
---|
679 | mbd->pb[i]->setFocus();
|
---|
680 | }
|
---|
681 | mbd->pb[i]->setAutoDefault( TRUE );
|
---|
682 | mbd->pb[i]->setFocusPolicy( QWidget::StrongFocus );
|
---|
683 | connect( mbd->pb[i], SIGNAL(clicked()), SLOT(buttonClicked()) );
|
---|
684 | }
|
---|
685 | }
|
---|
686 | resizeButtons();
|
---|
687 | reserved1 = reserved2 = 0;
|
---|
688 | }
|
---|
689 |
|
---|
690 |
|
---|
691 | int QMessageBox::indexOf( int button ) const
|
---|
692 | {
|
---|
693 | int index = -1;
|
---|
694 | for ( int i=0; i<mbd->numButtons; i++ ) {
|
---|
695 | if ( mbd->button[i] == button ) {
|
---|
696 | index = i;
|
---|
697 | break;
|
---|
698 | }
|
---|
699 | }
|
---|
700 | return index;
|
---|
701 | }
|
---|
702 |
|
---|
703 |
|
---|
704 | void QMessageBox::resizeButtons()
|
---|
705 | {
|
---|
706 | int i;
|
---|
707 | QSize maxSize;
|
---|
708 | for ( i=0; i<mbd->numButtons; i++ ) {
|
---|
709 | QSize s = mbd->pb[i]->sizeHint();
|
---|
710 | maxSize.setWidth( QMAX(maxSize.width(), s.width()) );
|
---|
711 | maxSize.setHeight( QMAX(maxSize.height(),s.height()) );
|
---|
712 | }
|
---|
713 | mbd->buttonSize = maxSize;
|
---|
714 | for ( i=0; i<mbd->numButtons; i++ )
|
---|
715 | mbd->pb[i]->resize( maxSize );
|
---|
716 | }
|
---|
717 |
|
---|
718 |
|
---|
719 | /*!
|
---|
720 | \property QMessageBox::text
|
---|
721 | \brief the message box text to be displayed.
|
---|
722 |
|
---|
723 | The text will be interpreted either as a plain text or as rich
|
---|
724 | text, depending on the text format setting (\l
|
---|
725 | QMessageBox::textFormat). The default setting is \c AutoText, i.e.
|
---|
726 | the message box will try to auto-detect the format of the text.
|
---|
727 |
|
---|
728 | The default value of this property is QString::null.
|
---|
729 |
|
---|
730 | \sa textFormat
|
---|
731 | */
|
---|
732 | QString QMessageBox::text() const
|
---|
733 | {
|
---|
734 | return label->text();
|
---|
735 | }
|
---|
736 |
|
---|
737 |
|
---|
738 | void QMessageBox::setText( const QString &text )
|
---|
739 | {
|
---|
740 | label->setText( text );
|
---|
741 | }
|
---|
742 |
|
---|
743 |
|
---|
744 | /*!
|
---|
745 | \property QMessageBox::icon
|
---|
746 | \brief the message box's icon
|
---|
747 |
|
---|
748 | The icon of the message box can be one of the following predefined
|
---|
749 | icons:
|
---|
750 | \list
|
---|
751 | \i QMessageBox::NoIcon
|
---|
752 | \i QMessageBox::Question
|
---|
753 | \i QMessageBox::Information
|
---|
754 | \i QMessageBox::Warning
|
---|
755 | \i QMessageBox::Critical
|
---|
756 | \endlist
|
---|
757 |
|
---|
758 | The actual pixmap used for displaying the icon depends on the
|
---|
759 | current \link QWidget::style() GUI style\endlink. You can also set
|
---|
760 | a custom pixmap icon using the \l QMessageBox::iconPixmap
|
---|
761 | property. The default icon is QMessageBox::NoIcon.
|
---|
762 |
|
---|
763 | \sa iconPixmap
|
---|
764 | */
|
---|
765 |
|
---|
766 | QMessageBox::Icon QMessageBox::icon() const
|
---|
767 | {
|
---|
768 | return mbd->icon;
|
---|
769 | }
|
---|
770 |
|
---|
771 | void QMessageBox::setIcon( Icon icon )
|
---|
772 | {
|
---|
773 | setIconPixmap( standardIcon(icon) );
|
---|
774 | mbd->icon = icon;
|
---|
775 | }
|
---|
776 |
|
---|
777 | /*!
|
---|
778 | \obsolete
|
---|
779 |
|
---|
780 | Returns the pixmap used for a standard icon. This
|
---|
781 | allows the pixmaps to be used in more complex message boxes.
|
---|
782 | \a icon specifies the required icon, e.g. QMessageBox::Information,
|
---|
783 | QMessageBox::Warning or QMessageBox::Critical.
|
---|
784 |
|
---|
785 | \a style is unused.
|
---|
786 | */
|
---|
787 |
|
---|
788 | QPixmap QMessageBox::standardIcon( Icon icon, GUIStyle style)
|
---|
789 | {
|
---|
790 | Q_UNUSED(style);
|
---|
791 | return QMessageBox::standardIcon(icon);
|
---|
792 | }
|
---|
793 |
|
---|
794 |
|
---|
795 | /*!
|
---|
796 | Returns the pixmap used for a standard icon. This allows the
|
---|
797 | pixmaps to be used in more complex message boxes. \a icon
|
---|
798 | specifies the required icon, e.g. QMessageBox::Question,
|
---|
799 | QMessageBox::Information, QMessageBox::Warning or
|
---|
800 | QMessageBox::Critical.
|
---|
801 | */
|
---|
802 |
|
---|
803 | QPixmap QMessageBox::standardIcon( Icon icon )
|
---|
804 | {
|
---|
805 | QPixmap pm;
|
---|
806 | switch ( icon ) {
|
---|
807 | case Information:
|
---|
808 | pm = QApplication::style().stylePixmap( QStyle::SP_MessageBoxInformation );
|
---|
809 | break;
|
---|
810 | case Warning:
|
---|
811 | pm = QApplication::style().stylePixmap( QStyle::SP_MessageBoxWarning );
|
---|
812 | break;
|
---|
813 | case Critical:
|
---|
814 | pm = QApplication::style().stylePixmap( QStyle::SP_MessageBoxCritical );
|
---|
815 | break;
|
---|
816 | case Question:
|
---|
817 | pm = QApplication::style().stylePixmap( QStyle::SP_MessageBoxQuestion );
|
---|
818 | default:
|
---|
819 | break;
|
---|
820 | }
|
---|
821 | return pm;
|
---|
822 | }
|
---|
823 |
|
---|
824 |
|
---|
825 | /*!
|
---|
826 | \property QMessageBox::iconPixmap
|
---|
827 | \brief the current icon
|
---|
828 |
|
---|
829 | The icon currently used by the message box. Note that it's often
|
---|
830 | hard to draw one pixmap that looks appropriate in both Motif and
|
---|
831 | Windows GUI styles; you may want to draw two pixmaps.
|
---|
832 |
|
---|
833 | \sa icon
|
---|
834 | */
|
---|
835 |
|
---|
836 | const QPixmap *QMessageBox::iconPixmap() const
|
---|
837 | {
|
---|
838 | return mbd->iconLabel.pixmap();
|
---|
839 | }
|
---|
840 |
|
---|
841 |
|
---|
842 | void QMessageBox::setIconPixmap( const QPixmap &pixmap )
|
---|
843 | {
|
---|
844 | mbd->iconLabel.setPixmap(pixmap);
|
---|
845 | mbd->icon = NoIcon;
|
---|
846 | }
|
---|
847 |
|
---|
848 |
|
---|
849 | /*!
|
---|
850 | Returns the text of the message box button \a button, or
|
---|
851 | QString::null if the message box does not contain the button.
|
---|
852 |
|
---|
853 | \sa setButtonText()
|
---|
854 | */
|
---|
855 |
|
---|
856 | QString QMessageBox::buttonText( int button ) const
|
---|
857 | {
|
---|
858 | int index = indexOf(button);
|
---|
859 | return index >= 0 && mbd->pb[index]
|
---|
860 | ? mbd->pb[index]->text()
|
---|
861 | : QString::null;
|
---|
862 | }
|
---|
863 |
|
---|
864 |
|
---|
865 | /*!
|
---|
866 | Sets the text of the message box button \a button to \a text.
|
---|
867 | Setting the text of a button that is not in the message box is
|
---|
868 | silently ignored.
|
---|
869 |
|
---|
870 | \sa buttonText()
|
---|
871 | */
|
---|
872 |
|
---|
873 | void QMessageBox::setButtonText( int button, const QString &text )
|
---|
874 | {
|
---|
875 | int index = indexOf(button);
|
---|
876 | if ( index >= 0 && mbd->pb[index] ) {
|
---|
877 | mbd->pb[index]->setText( text );
|
---|
878 | resizeButtons();
|
---|
879 | }
|
---|
880 | }
|
---|
881 |
|
---|
882 |
|
---|
883 | /*!
|
---|
884 | \internal
|
---|
885 | Internal slot to handle button clicks.
|
---|
886 | */
|
---|
887 |
|
---|
888 | void QMessageBox::buttonClicked()
|
---|
889 | {
|
---|
890 | int reply = 0;
|
---|
891 | const QObject *s = sender();
|
---|
892 | for ( int i=0; i<mbd->numButtons; i++ ) {
|
---|
893 | if ( mbd->pb[i] == s )
|
---|
894 | reply = mbd->button[i];
|
---|
895 | }
|
---|
896 | done( reply );
|
---|
897 | }
|
---|
898 |
|
---|
899 |
|
---|
900 | /*!
|
---|
901 | Adjusts the size of the message box to fit the contents just before
|
---|
902 | QDialog::exec() or QDialog::show() is called.
|
---|
903 |
|
---|
904 | This function will not be called if the message box has been explicitly
|
---|
905 | resized before showing it.
|
---|
906 | */
|
---|
907 | void QMessageBox::adjustSize()
|
---|
908 | {
|
---|
909 | if ( !testWState(WState_Polished) )
|
---|
910 | polish();
|
---|
911 | resizeButtons();
|
---|
912 | label->adjustSize();
|
---|
913 | QSize labelSize( label->size() );
|
---|
914 | int n = mbd->numButtons;
|
---|
915 | int bw = mbd->buttonSize.width();
|
---|
916 | int bh = mbd->buttonSize.height();
|
---|
917 | int border = bh / 2 - style().pixelMetric(QStyle::PM_ButtonDefaultIndicator);
|
---|
918 | if ( border <= 0 )
|
---|
919 | border = 10;
|
---|
920 | int btn_spacing = 7;
|
---|
921 | if ( style().styleHint(QStyle::SH_GUIStyle) == MotifStyle )
|
---|
922 | btn_spacing = border;
|
---|
923 | #ifndef Q_OS_TEMP
|
---|
924 | int buttons = mbd->numButtons * bw + (n-1) * btn_spacing;
|
---|
925 | int h = bh;
|
---|
926 | #else
|
---|
927 | int visibleButtons = 0;
|
---|
928 | for ( int i = 0; i < mbd->numButtons; ++i )
|
---|
929 | visibleButtons += mbd->pb[i]->isVisible() ? 1 : 0;
|
---|
930 | int buttons = visibleButtons == 0 ? 0 : visibleButtons * bw + (visibleButtons-1) * btn_spacing;
|
---|
931 | int h = visibleButtons == 0 ? 0 : bh;
|
---|
932 | n = visibleButtons;
|
---|
933 | #endif
|
---|
934 | if ( labelSize.height() )
|
---|
935 | h += labelSize.height() + 3*border;
|
---|
936 | else
|
---|
937 | h += 2*border;
|
---|
938 | int lmargin = 0;
|
---|
939 | if ( mbd->iconLabel.pixmap() && mbd->iconLabel.pixmap()->width() ) {
|
---|
940 | mbd->iconLabel.adjustSize();
|
---|
941 | lmargin += mbd->iconLabel.width() + border;
|
---|
942 | if ( h < mbd->iconLabel.height() + 3*border + bh && n )
|
---|
943 | h = mbd->iconLabel.height() + 3*border + bh;
|
---|
944 | }
|
---|
945 | int w = QMAX( buttons, labelSize.width() + lmargin ) + 2*border;
|
---|
946 | QRect screen = QApplication::desktop()->screenGeometry( pos() );
|
---|
947 | if ( w > screen.width() )
|
---|
948 | w = screen.width();
|
---|
949 | resize( w, h );
|
---|
950 | setMinimumSize( size() );
|
---|
951 | }
|
---|
952 |
|
---|
953 |
|
---|
954 | /*!\reimp
|
---|
955 | */
|
---|
956 | void QMessageBox::resizeEvent( QResizeEvent * )
|
---|
957 | {
|
---|
958 | int i;
|
---|
959 | int n = mbd->numButtons;
|
---|
960 | int bw = mbd->buttonSize.width();
|
---|
961 | int bh = mbd->buttonSize.height();
|
---|
962 | #ifdef Q_OS_TEMP
|
---|
963 | int visibleButtons = 0;
|
---|
964 | for ( i = 0; i < n; ++i )
|
---|
965 | visibleButtons += mbd->pb[i]->isVisible() ? 1 : 0;
|
---|
966 | n = visibleButtons;
|
---|
967 | bw = visibleButtons == 0 ? 0 : bw;
|
---|
968 | bh = visibleButtons == 0 ? 0 : bh;
|
---|
969 | #endif
|
---|
970 | int border = bh / 2 - style().pixelMetric(QStyle::PM_ButtonDefaultIndicator);
|
---|
971 | if ( border <= 0 )
|
---|
972 | border = 10;
|
---|
973 | int btn_spacing = 7;
|
---|
974 | if ( style().styleHint(QStyle::SH_GUIStyle) == MotifStyle )
|
---|
975 | btn_spacing = border;
|
---|
976 | int lmargin = 0;
|
---|
977 | mbd->iconLabel.adjustSize();
|
---|
978 | mbd->iconLabel.move( border, border );
|
---|
979 | if ( mbd->iconLabel.pixmap() && mbd->iconLabel.pixmap()->width() )
|
---|
980 | lmargin += mbd->iconLabel.width() + border;
|
---|
981 | label->setGeometry( lmargin+border,
|
---|
982 | border,
|
---|
983 | width() - lmargin -2*border,
|
---|
984 | height() - 3*border - bh );
|
---|
985 | int extra_space = (width() - bw*n - 2*border - (n-1)*btn_spacing);
|
---|
986 | if ( style().styleHint(QStyle::SH_GUIStyle) == MotifStyle )
|
---|
987 | for ( i=0; i<n; i++ )
|
---|
988 | mbd->pb[i]->move( border + i*bw + i*btn_spacing + extra_space*(i+1)/(n+1),
|
---|
989 | height() - border - bh );
|
---|
990 | else
|
---|
991 | for ( i=0; i<n; i++ )
|
---|
992 | mbd->pb[i]->move( border + i*bw + extra_space/2 + i*btn_spacing,
|
---|
993 | height() - border - bh );
|
---|
994 | }
|
---|
995 |
|
---|
996 |
|
---|
997 | /*!\reimp
|
---|
998 | */
|
---|
999 | void QMessageBox::keyPressEvent( QKeyEvent *e )
|
---|
1000 | {
|
---|
1001 | if ( e->key() == Key_Escape ) {
|
---|
1002 | if ( mbd->escButton >= 0 ) {
|
---|
1003 | QPushButton *pb = mbd->pb[mbd->escButton];
|
---|
1004 | pb->animateClick();
|
---|
1005 | e->accept();
|
---|
1006 | return;
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 | #ifndef QT_NO_ACCEL
|
---|
1010 | if ( !( e->state() & AltButton ) ) {
|
---|
1011 | QObjectList *list = queryList( "QPushButton" );
|
---|
1012 | QObjectListIt it( *list );
|
---|
1013 | QPushButton *pb;
|
---|
1014 | while ( (pb = (QPushButton*)it.current()) ) {
|
---|
1015 | int key = e->key() & ~(MODIFIER_MASK|UNICODE_ACCEL);
|
---|
1016 | int acc = pb->accel() & ~(MODIFIER_MASK|UNICODE_ACCEL);
|
---|
1017 | if ( key && acc && acc == key ) {
|
---|
1018 | delete list;
|
---|
1019 | emit pb->animateClick();
|
---|
1020 | return;
|
---|
1021 | }
|
---|
1022 | ++it;
|
---|
1023 | }
|
---|
1024 | delete list;
|
---|
1025 | }
|
---|
1026 | #endif
|
---|
1027 | QDialog::keyPressEvent( e );
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | /*!\reimp
|
---|
1031 | */
|
---|
1032 | void QMessageBox::showEvent( QShowEvent *e )
|
---|
1033 | {
|
---|
1034 | #if defined(QT_ACCESSIBILITY_SUPPORT)
|
---|
1035 | QAccessible::updateAccessibility( this, 0, QAccessible::Alert );
|
---|
1036 | #endif
|
---|
1037 | QDialog::showEvent( e );
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | /*!\reimp
|
---|
1041 | */
|
---|
1042 | void QMessageBox::closeEvent( QCloseEvent *e )
|
---|
1043 | {
|
---|
1044 | QDialog::closeEvent( e );
|
---|
1045 | if ( mbd->escButton != -1 )
|
---|
1046 | setResult( mbd->button[mbd->escButton] );
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | /*****************************************************************************
|
---|
1050 | Static QMessageBox functions
|
---|
1051 | *****************************************************************************/
|
---|
1052 |
|
---|
1053 | /*!\fn int QMessageBox::message( const QString &,const QString&,const QString&,QWidget*,const char * )
|
---|
1054 | \obsolete
|
---|
1055 | Opens a modal message box directly using the specified parameters.
|
---|
1056 |
|
---|
1057 | Please use information(), warning(), question(), or critical() instead.
|
---|
1058 | */
|
---|
1059 |
|
---|
1060 | /*! \fn bool QMessageBox::query( const QString &,const QString&,const QString&,const QString&,QWidget *, const char * )
|
---|
1061 | \obsolete
|
---|
1062 | Queries the user using a modal message box with two buttons.
|
---|
1063 | Note that \a caption is not always shown, it depends on the window manager.
|
---|
1064 |
|
---|
1065 | Please use information(), question(), warning(), or critical() instead.
|
---|
1066 | */
|
---|
1067 |
|
---|
1068 | /*!
|
---|
1069 | Opens an information message box with the caption \a caption and
|
---|
1070 | the text \a text. The dialog may have up to three buttons. Each of
|
---|
1071 | the buttons, \a button0, \a button1 and \a button2 may be set to
|
---|
1072 | one of the following values:
|
---|
1073 |
|
---|
1074 | \list
|
---|
1075 | \i QMessageBox::NoButton
|
---|
1076 | \i QMessageBox::Ok
|
---|
1077 | \i QMessageBox::Cancel
|
---|
1078 | \i QMessageBox::Yes
|
---|
1079 | \i QMessageBox::No
|
---|
1080 | \i QMessageBox::Abort
|
---|
1081 | \i QMessageBox::Retry
|
---|
1082 | \i QMessageBox::Ignore
|
---|
1083 | \i QMessageBox::YesAll
|
---|
1084 | \i QMessageBox::NoAll
|
---|
1085 | \endlist
|
---|
1086 |
|
---|
1087 | If you don't want all three buttons, set the last button, or last
|
---|
1088 | two buttons to QMessageBox::NoButton.
|
---|
1089 |
|
---|
1090 | One button can be OR-ed with \c QMessageBox::Default, and one
|
---|
1091 | button can be OR-ed with \c QMessageBox::Escape.
|
---|
1092 |
|
---|
1093 | Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
---|
1094 | of the button that was clicked.
|
---|
1095 |
|
---|
1096 | If \a parent is 0, the message box becomes an application-global
|
---|
1097 | modal dialog box. If \a parent is a widget, the message box
|
---|
1098 | becomes modal relative to \a parent.
|
---|
1099 |
|
---|
1100 | \sa question(), warning(), critical()
|
---|
1101 | */
|
---|
1102 |
|
---|
1103 | int QMessageBox::information( QWidget *parent,
|
---|
1104 | const QString& caption, const QString& text,
|
---|
1105 | int button0, int button1, int button2 )
|
---|
1106 | {
|
---|
1107 | QMessageBox *mb = new QMessageBox( caption, text, Information,
|
---|
1108 | button0, button1, button2,
|
---|
1109 | parent, "qt_msgbox_information", TRUE,
|
---|
1110 | WDestructiveClose);
|
---|
1111 | Q_CHECK_PTR( mb );
|
---|
1112 | return mb->exec();
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | /*!
|
---|
1116 | Opens a question message box with the caption \a caption and the
|
---|
1117 | text \a text. The dialog may have up to three buttons. Each of the
|
---|
1118 | buttons, \a button0, \a button1 and \a button2 may be set to one
|
---|
1119 | of the following values:
|
---|
1120 |
|
---|
1121 | \list
|
---|
1122 | \i QMessageBox::NoButton
|
---|
1123 | \i QMessageBox::Ok
|
---|
1124 | \i QMessageBox::Cancel
|
---|
1125 | \i QMessageBox::Yes
|
---|
1126 | \i QMessageBox::No
|
---|
1127 | \i QMessageBox::Abort
|
---|
1128 | \i QMessageBox::Retry
|
---|
1129 | \i QMessageBox::Ignore
|
---|
1130 | \i QMessageBox::YesAll
|
---|
1131 | \i QMessageBox::NoAll
|
---|
1132 | \endlist
|
---|
1133 |
|
---|
1134 | If you don't want all three buttons, set the last button, or last
|
---|
1135 | two buttons to QMessageBox::NoButton.
|
---|
1136 |
|
---|
1137 | One button can be OR-ed with \c QMessageBox::Default, and one
|
---|
1138 | button can be OR-ed with \c QMessageBox::Escape.
|
---|
1139 |
|
---|
1140 | Returns the identity (QMessageBox::Yes, or QMessageBox::No, etc.)
|
---|
1141 | of the button that was clicked.
|
---|
1142 |
|
---|
1143 | If \a parent is 0, the message box becomes an application-global
|
---|
1144 | modal dialog box. If \a parent is a widget, the message box
|
---|
1145 | becomes modal relative to \a parent.
|
---|
1146 |
|
---|
1147 | \sa information(), warning(), critical()
|
---|
1148 | */
|
---|
1149 |
|
---|
1150 | int QMessageBox::question( QWidget *parent,
|
---|
1151 | const QString& caption, const QString& text,
|
---|
1152 | int button0, int button1, int button2 )
|
---|
1153 | {
|
---|
1154 | QMessageBox *mb = new QMessageBox( caption, text, Question,
|
---|
1155 | button0, button1, button2,
|
---|
1156 | parent, "qt_msgbox_information", TRUE,
|
---|
1157 | WDestructiveClose);
|
---|
1158 | Q_CHECK_PTR( mb );
|
---|
1159 | return mb->exec();
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 |
|
---|
1163 | /*!
|
---|
1164 | Opens a warning message box with the caption \a caption and the
|
---|
1165 | text \a text. The dialog may have up to three buttons. Each of the
|
---|
1166 | button parameters, \a button0, \a button1 and \a button2 may be
|
---|
1167 | set to one of the following values:
|
---|
1168 |
|
---|
1169 | \list
|
---|
1170 | \i QMessageBox::NoButton
|
---|
1171 | \i QMessageBox::Ok
|
---|
1172 | \i QMessageBox::Cancel
|
---|
1173 | \i QMessageBox::Yes
|
---|
1174 | \i QMessageBox::No
|
---|
1175 | \i QMessageBox::Abort
|
---|
1176 | \i QMessageBox::Retry
|
---|
1177 | \i QMessageBox::Ignore
|
---|
1178 | \i QMessageBox::YesAll
|
---|
1179 | \i QMessageBox::NoAll
|
---|
1180 | \endlist
|
---|
1181 |
|
---|
1182 | If you don't want all three buttons, set the last button, or last
|
---|
1183 | two buttons to QMessageBox::NoButton.
|
---|
1184 |
|
---|
1185 | One button can be OR-ed with \c QMessageBox::Default, and one
|
---|
1186 | button can be OR-ed with \c QMessageBox::Escape.
|
---|
1187 |
|
---|
1188 | Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
---|
1189 | of the button that was clicked.
|
---|
1190 |
|
---|
1191 | If \a parent is 0, the message box becomes an application-global
|
---|
1192 | modal dialog box. If \a parent is a widget, the message box
|
---|
1193 | becomes modal relative to \a parent.
|
---|
1194 |
|
---|
1195 | \sa information(), question(), critical()
|
---|
1196 | */
|
---|
1197 |
|
---|
1198 | int QMessageBox::warning( QWidget *parent,
|
---|
1199 | const QString& caption, const QString& text,
|
---|
1200 | int button0, int button1, int button2 )
|
---|
1201 | {
|
---|
1202 | QMessageBox *mb = new QMessageBox( caption, text, Warning,
|
---|
1203 | button0, button1, button2,
|
---|
1204 | parent, "qt_msgbox_warning", TRUE,
|
---|
1205 | WDestructiveClose);
|
---|
1206 | Q_CHECK_PTR( mb );
|
---|
1207 | return mb->exec();
|
---|
1208 | }
|
---|
1209 |
|
---|
1210 |
|
---|
1211 | /*!
|
---|
1212 | Opens a critical message box with the caption \a caption and the
|
---|
1213 | text \a text. The dialog may have up to three buttons. Each of the
|
---|
1214 | button parameters, \a button0, \a button1 and \a button2 may be
|
---|
1215 | set to one of the following values:
|
---|
1216 |
|
---|
1217 | \list
|
---|
1218 | \i QMessageBox::NoButton
|
---|
1219 | \i QMessageBox::Ok
|
---|
1220 | \i QMessageBox::Cancel
|
---|
1221 | \i QMessageBox::Yes
|
---|
1222 | \i QMessageBox::No
|
---|
1223 | \i QMessageBox::Abort
|
---|
1224 | \i QMessageBox::Retry
|
---|
1225 | \i QMessageBox::Ignore
|
---|
1226 | \i QMessageBox::YesAll
|
---|
1227 | \i QMessageBox::NoAll
|
---|
1228 | \endlist
|
---|
1229 |
|
---|
1230 | If you don't want all three buttons, set the last button, or last
|
---|
1231 | two buttons to QMessageBox::NoButton.
|
---|
1232 |
|
---|
1233 | One button can be OR-ed with \c QMessageBox::Default, and one
|
---|
1234 | button can be OR-ed with \c QMessageBox::Escape.
|
---|
1235 |
|
---|
1236 | Returns the identity (QMessageBox::Ok, or QMessageBox::No, etc.)
|
---|
1237 | of the button that was clicked.
|
---|
1238 |
|
---|
1239 | If \a parent is 0, the message box becomes an application-global
|
---|
1240 | modal dialog box. If \a parent is a widget, the message box
|
---|
1241 | becomes modal relative to \a parent.
|
---|
1242 |
|
---|
1243 | \sa information(), question(), warning()
|
---|
1244 | */
|
---|
1245 |
|
---|
1246 | int QMessageBox::critical( QWidget *parent,
|
---|
1247 | const QString& caption, const QString& text,
|
---|
1248 | int button0, int button1, int button2 )
|
---|
1249 | {
|
---|
1250 | QMessageBox *mb = new QMessageBox( caption, text, Critical,
|
---|
1251 | button0, button1, button2,
|
---|
1252 | parent, "qt_msgbox_critical", TRUE,
|
---|
1253 | WDestructiveClose);
|
---|
1254 | Q_CHECK_PTR( mb );
|
---|
1255 | return mb->exec();
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 |
|
---|
1259 | /*!
|
---|
1260 | Displays a simple about box with caption \a caption and text \a
|
---|
1261 | text. The about box's parent is \a parent.
|
---|
1262 |
|
---|
1263 | about() looks for a suitable icon in four locations:
|
---|
1264 | \list 1
|
---|
1265 | \i It prefers \link QWidget::icon() parent->icon() \endlink if that exists.
|
---|
1266 | \i If not, it tries the top-level widget containing \a parent.
|
---|
1267 | \i If that fails, it tries the \link
|
---|
1268 | QApplication::mainWidget() main widget. \endlink
|
---|
1269 | \i As a last resort it uses the Information icon.
|
---|
1270 | \endlist
|
---|
1271 |
|
---|
1272 | The about box has a single button labelled "OK".
|
---|
1273 |
|
---|
1274 | \sa QWidget::icon() QApplication::mainWidget()
|
---|
1275 | */
|
---|
1276 |
|
---|
1277 | void QMessageBox::about( QWidget *parent, const QString &caption,
|
---|
1278 | const QString& text )
|
---|
1279 | {
|
---|
1280 | QMessageBox *mb = new QMessageBox( caption, text,
|
---|
1281 | Information,
|
---|
1282 | Ok + Default, 0, 0,
|
---|
1283 | parent, "qt_msgbox_simple_about_box", TRUE,
|
---|
1284 | WDestructiveClose);
|
---|
1285 | Q_CHECK_PTR( mb );
|
---|
1286 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
1287 | const QPixmap *pm = parent ? parent->icon() : 0;
|
---|
1288 | if ( pm && !pm->isNull() )
|
---|
1289 | mb->setIconPixmap( *pm );
|
---|
1290 | else {
|
---|
1291 | pm = parent ? parent->topLevelWidget()->icon() : 0;
|
---|
1292 | if ( pm && !pm->isNull() )
|
---|
1293 | mb->setIconPixmap( *pm );
|
---|
1294 | else {
|
---|
1295 | pm = qApp && qApp->mainWidget() ? qApp->mainWidget()->icon() : 0;
|
---|
1296 | if ( pm && !pm->isNull() )
|
---|
1297 | mb->setIconPixmap( *pm );
|
---|
1298 | }
|
---|
1299 | }
|
---|
1300 | #endif
|
---|
1301 | mb->exec();
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 |
|
---|
1305 | /*! \reimp
|
---|
1306 | */
|
---|
1307 |
|
---|
1308 | void QMessageBox::styleChanged( QStyle& )
|
---|
1309 | {
|
---|
1310 | if ( mbd->icon != NoIcon ) {
|
---|
1311 | // Reload icon for new style
|
---|
1312 | setIcon( mbd->icon );
|
---|
1313 | }
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 |
|
---|
1317 | static int textBox( QWidget *parent, QMessageBox::Icon severity,
|
---|
1318 | const QString& caption, const QString& text,
|
---|
1319 | const QString& button0Text,
|
---|
1320 | const QString& button1Text,
|
---|
1321 | const QString& button2Text,
|
---|
1322 | int defaultButtonNumber,
|
---|
1323 | int escapeButtonNumber )
|
---|
1324 | {
|
---|
1325 | int b[3];
|
---|
1326 | b[0] = 1;
|
---|
1327 | b[1] = button1Text.isEmpty() ? 0 : 2;
|
---|
1328 | b[2] = button2Text.isEmpty() ? 0 : 3;
|
---|
1329 |
|
---|
1330 | int i;
|
---|
1331 | for( i=0; i<3; i++ ) {
|
---|
1332 | if ( b[i] && defaultButtonNumber == i )
|
---|
1333 | b[i] += QMessageBox::Default;
|
---|
1334 | if ( b[i] && escapeButtonNumber == i )
|
---|
1335 | b[i] += QMessageBox::Escape;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | QMessageBox *mb = new QMessageBox( caption, text, severity,
|
---|
1339 | b[0], b[1], b[2],
|
---|
1340 | parent, "qt_msgbox_information", TRUE,
|
---|
1341 | Qt::WDestructiveClose);
|
---|
1342 | Q_CHECK_PTR( mb );
|
---|
1343 | if ( button0Text.isEmpty() )
|
---|
1344 | mb->setButtonText( 1, QMessageBox::tr(mb_texts[QMessageBox::Ok]) );
|
---|
1345 | else
|
---|
1346 | mb->setButtonText( 1, button0Text );
|
---|
1347 | if ( b[1] )
|
---|
1348 | mb->setButtonText( 2, button1Text );
|
---|
1349 | if ( b[2] )
|
---|
1350 | mb->setButtonText( 3, button2Text );
|
---|
1351 |
|
---|
1352 | #ifndef QT_NO_CURSOR
|
---|
1353 | mb->setCursor( Qt::arrowCursor );
|
---|
1354 | #endif
|
---|
1355 | return mb->exec() - 1;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 |
|
---|
1359 | /*!
|
---|
1360 | \overload
|
---|
1361 |
|
---|
1362 | Displays an information message box with caption \a caption, text
|
---|
1363 | \a text and one, two or three buttons. Returns the index of the
|
---|
1364 | button that was clicked (0, 1 or 2).
|
---|
1365 |
|
---|
1366 | \a button0Text is the text of the first button, and is optional.
|
---|
1367 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
1368 | \a button1Text is the text of the second button, and is optional.
|
---|
1369 | \a button2Text is the text of the third button, and is optional.
|
---|
1370 | \a defaultButtonNumber (0, 1 or 2) is the index of the default
|
---|
1371 | button; pressing Return or Enter is the same as clicking the
|
---|
1372 | default button. It defaults to 0 (the first button). \a
|
---|
1373 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
1374 | Escape is the same as clicking this button. It defaults to -1;
|
---|
1375 | supply 0, 1 or 2 to make pressing Escape equivalent to clicking
|
---|
1376 | the relevant button.
|
---|
1377 |
|
---|
1378 | If \a parent is 0, the message box becomes an application-global
|
---|
1379 | modal dialog box. If \a parent is a widget, the message box
|
---|
1380 | becomes modal relative to \a parent.
|
---|
1381 |
|
---|
1382 | Note: If you do not specify an Escape button then if the Escape
|
---|
1383 | button is pressed then -1 will be returned. It is suggested that
|
---|
1384 | you specify an Escape button to prevent this from happening.
|
---|
1385 |
|
---|
1386 | \sa question(), warning(), critical()
|
---|
1387 | */
|
---|
1388 |
|
---|
1389 | int QMessageBox::information( QWidget *parent, const QString &caption,
|
---|
1390 | const QString& text,
|
---|
1391 | const QString& button0Text,
|
---|
1392 | const QString& button1Text,
|
---|
1393 | const QString& button2Text,
|
---|
1394 | int defaultButtonNumber,
|
---|
1395 | int escapeButtonNumber )
|
---|
1396 | {
|
---|
1397 | return textBox( parent, Information, caption, text,
|
---|
1398 | button0Text, button1Text, button2Text,
|
---|
1399 | defaultButtonNumber, escapeButtonNumber );
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | /*!
|
---|
1403 | \overload
|
---|
1404 |
|
---|
1405 | Displays a question message box with caption \a caption, text \a
|
---|
1406 | text and one, two or three buttons. Returns the index of the
|
---|
1407 | button that was clicked (0, 1 or 2).
|
---|
1408 |
|
---|
1409 | \a button0Text is the text of the first button, and is optional.
|
---|
1410 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
1411 | \a button1Text is the text of the second button, and is optional.
|
---|
1412 | \a button2Text is the text of the third button, and is optional.
|
---|
1413 | \a defaultButtonNumber (0, 1 or 2) is the index of the default
|
---|
1414 | button; pressing Return or Enter is the same as clicking the
|
---|
1415 | default button. It defaults to 0 (the first button). \a
|
---|
1416 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
1417 | Escape is the same as clicking this button. It defaults to -1;
|
---|
1418 | supply 0, 1 or 2 to make pressing Escape equivalent to clicking
|
---|
1419 | the relevant button.
|
---|
1420 |
|
---|
1421 | If \a parent is 0, the message box becomes an application-global
|
---|
1422 | modal dialog box. If \a parent is a widget, the message box
|
---|
1423 | becomes modal relative to \a parent.
|
---|
1424 |
|
---|
1425 | Note: If you do not specify an Escape button then if the Escape
|
---|
1426 | button is pressed then -1 will be returned. It is suggested that
|
---|
1427 | you specify an Escape button to prevent this from happening.
|
---|
1428 |
|
---|
1429 | \sa information(), warning(), critical()
|
---|
1430 | */
|
---|
1431 | int QMessageBox::question( QWidget *parent, const QString &caption,
|
---|
1432 | const QString& text,
|
---|
1433 | const QString& button0Text,
|
---|
1434 | const QString& button1Text,
|
---|
1435 | const QString& button2Text,
|
---|
1436 | int defaultButtonNumber,
|
---|
1437 | int escapeButtonNumber )
|
---|
1438 | {
|
---|
1439 | return textBox( parent, Question, caption, text,
|
---|
1440 | button0Text, button1Text, button2Text,
|
---|
1441 | defaultButtonNumber, escapeButtonNumber );
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 |
|
---|
1445 | /*!
|
---|
1446 | \overload
|
---|
1447 |
|
---|
1448 | Displays a warning message box with a caption, a text, and 1, 2 or
|
---|
1449 | 3 buttons. Returns the number of the button that was clicked (0,
|
---|
1450 | 1, or 2).
|
---|
1451 |
|
---|
1452 | \a button0Text is the text of the first button, and is optional.
|
---|
1453 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
1454 | \a button1Text is the text of the second button, and is optional,
|
---|
1455 | and \a button2Text is the text of the third button, and is
|
---|
1456 | optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
---|
1457 | default button; pressing Return or Enter is the same as clicking
|
---|
1458 | the default button. It defaults to 0 (the first button). \a
|
---|
1459 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
1460 | Escape is the same as clicking this button. It defaults to -1;
|
---|
1461 | supply 0, 1, or 2 to make pressing Escape equivalent to clicking
|
---|
1462 | the relevant button.
|
---|
1463 |
|
---|
1464 | If \a parent is 0, the message box becomes an application-global
|
---|
1465 | modal dialog box. If \a parent is a widget, the message box
|
---|
1466 | becomes modal relative to \a parent.
|
---|
1467 |
|
---|
1468 | Note: If you do not specify an Escape button then if the Escape
|
---|
1469 | button is pressed then -1 will be returned. It is suggested that
|
---|
1470 | you specify an Escape button to prevent this from happening.
|
---|
1471 |
|
---|
1472 | \sa information(), question(), critical()
|
---|
1473 | */
|
---|
1474 |
|
---|
1475 | int QMessageBox::warning( QWidget *parent, const QString &caption,
|
---|
1476 | const QString& text,
|
---|
1477 | const QString& button0Text,
|
---|
1478 | const QString& button1Text,
|
---|
1479 | const QString& button2Text,
|
---|
1480 | int defaultButtonNumber,
|
---|
1481 | int escapeButtonNumber )
|
---|
1482 | {
|
---|
1483 | return textBox( parent, Warning, caption, text,
|
---|
1484 | button0Text, button1Text, button2Text,
|
---|
1485 | defaultButtonNumber, escapeButtonNumber );
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 |
|
---|
1489 | /*!
|
---|
1490 | \overload
|
---|
1491 |
|
---|
1492 | Displays a critical error message box with a caption, a text, and
|
---|
1493 | 1, 2 or 3 buttons. Returns the number of the button that was
|
---|
1494 | clicked (0, 1 or 2).
|
---|
1495 |
|
---|
1496 | \a button0Text is the text of the first button, and is optional.
|
---|
1497 | If \a button0Text is not supplied, "OK" (translated) will be used.
|
---|
1498 | \a button1Text is the text of the second button, and is optional,
|
---|
1499 | and \a button2Text is the text of the third button, and is
|
---|
1500 | optional. \a defaultButtonNumber (0, 1 or 2) is the index of the
|
---|
1501 | default button; pressing Return or Enter is the same as clicking
|
---|
1502 | the default button. It defaults to 0 (the first button). \a
|
---|
1503 | escapeButtonNumber is the index of the Escape button; pressing
|
---|
1504 | Escape is the same as clicking this button. It defaults to -1;
|
---|
1505 | supply 0, 1, or 2 to make pressing Escape equivalent to clicking
|
---|
1506 | the relevant button.
|
---|
1507 |
|
---|
1508 | If \a parent is 0, the message box becomes an application-global
|
---|
1509 | modal dialog box. If \a parent is a widget, the message box
|
---|
1510 | becomes modal relative to \a parent.
|
---|
1511 |
|
---|
1512 | \sa information(), question(), warning()
|
---|
1513 | */
|
---|
1514 |
|
---|
1515 | int QMessageBox::critical( QWidget *parent, const QString &caption,
|
---|
1516 | const QString& text,
|
---|
1517 | const QString& button0Text,
|
---|
1518 | const QString& button1Text,
|
---|
1519 | const QString& button2Text,
|
---|
1520 | int defaultButtonNumber,
|
---|
1521 | int escapeButtonNumber )
|
---|
1522 | {
|
---|
1523 | return textBox( parent, Critical, caption, text,
|
---|
1524 | button0Text, button1Text, button2Text,
|
---|
1525 | defaultButtonNumber, escapeButtonNumber );
|
---|
1526 | }
|
---|
1527 |
|
---|
1528 |
|
---|
1529 | /*!
|
---|
1530 | Displays a simple message box about Qt, with caption \a caption
|
---|
1531 | and centered over \a parent (if \a parent is not 0). The message
|
---|
1532 | includes the version number of Qt being used by the application.
|
---|
1533 |
|
---|
1534 | This is useful for inclusion in the Help menu of an application.
|
---|
1535 | See the examples/menu/menu.cpp example.
|
---|
1536 |
|
---|
1537 | QApplication provides this functionality as a slot.
|
---|
1538 |
|
---|
1539 | \sa QApplication::aboutQt()
|
---|
1540 | */
|
---|
1541 |
|
---|
1542 | void QMessageBox::aboutQt( QWidget *parent, const QString &caption )
|
---|
1543 | {
|
---|
1544 | QMessageBox *mb = new QMessageBox( parent, "qt_msgbox_about_qt" );
|
---|
1545 | Q_CHECK_PTR( mb );
|
---|
1546 | mb->setWFlags( WDestructiveClose );
|
---|
1547 |
|
---|
1548 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
1549 | QString c = caption;
|
---|
1550 | if ( c.isNull() )
|
---|
1551 | c = tr( "About Qt" );
|
---|
1552 | mb->setCaption( c );
|
---|
1553 | #endif
|
---|
1554 | mb->setText( *translatedTextAboutQt );
|
---|
1555 | #ifndef QT_NO_IMAGEIO
|
---|
1556 | QPixmap pm;
|
---|
1557 | QImage logo( (const char **)qtlogo_xpm);
|
---|
1558 | if ( qGray(mb->palette().active().text().rgb()) >
|
---|
1559 | qGray(mb->palette().active().base().rgb()) )
|
---|
1560 | {
|
---|
1561 | // light on dark, adjust some colors (where's 10?)
|
---|
1562 | logo.setColor( 0, 0xffffffff );
|
---|
1563 | logo.setColor( 1, 0xff666666 );
|
---|
1564 | logo.setColor( 2, 0xffcccc66 );
|
---|
1565 | logo.setColor( 4, 0xffcccccc );
|
---|
1566 | logo.setColor( 6, 0xffffff66 );
|
---|
1567 | logo.setColor( 7, 0xff999999 );
|
---|
1568 | logo.setColor( 8, 0xff3333ff );
|
---|
1569 | logo.setColor( 9, 0xffffff33 );
|
---|
1570 | logo.setColor( 11, 0xffcccc99 );
|
---|
1571 | }
|
---|
1572 | if ( pm.convertFromImage( logo ) )
|
---|
1573 | mb->setIconPixmap( pm );
|
---|
1574 | #endif
|
---|
1575 | mb->setButtonText( 0, tr("OK") );
|
---|
1576 | if ( mb->mbd && mb->mbd->pb[0] ) {
|
---|
1577 | mb->mbd->pb[0]->setAutoDefault( TRUE );
|
---|
1578 | mb->mbd->pb[0]->setFocusPolicy( QWidget::StrongFocus );
|
---|
1579 | mb->mbd->pb[0]->setDefault( TRUE );
|
---|
1580 | mb->mbd->pb[0]->setFocus();
|
---|
1581 | }
|
---|
1582 | mb->exec();
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | /*!
|
---|
1586 | \reimp
|
---|
1587 | */
|
---|
1588 |
|
---|
1589 | void QMessageBox::setIcon( const QPixmap &pix )
|
---|
1590 | {
|
---|
1591 | //reimplemented to avoid compiler warning.
|
---|
1592 | #ifndef QT_NO_WIDGET_TOPEXTRA
|
---|
1593 | QDialog::setIcon( pix );
|
---|
1594 | #endif
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 |
|
---|
1598 | /*!
|
---|
1599 | \property QMessageBox::textFormat
|
---|
1600 | \brief the format of the text displayed by the message box
|
---|
1601 |
|
---|
1602 | The current text format used by the message box. See the \l
|
---|
1603 | Qt::TextFormat enum for an explanation of the possible options.
|
---|
1604 |
|
---|
1605 | The default format is \c AutoText.
|
---|
1606 |
|
---|
1607 | \sa setText()
|
---|
1608 | */
|
---|
1609 |
|
---|
1610 | Qt::TextFormat QMessageBox::textFormat() const
|
---|
1611 | {
|
---|
1612 | return label->textFormat();
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 |
|
---|
1616 | void QMessageBox::setTextFormat( Qt::TextFormat format )
|
---|
1617 | {
|
---|
1618 | label->setTextFormat( format );
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 |
|
---|
1622 | #endif
|
---|