1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SUIT_MessageBox.h"
24 #include "SUIT_OverrideCursor.h"
26 #include <QMessageBox>
27 #include <QPushButton>
28 #include <QApplication>
34 \class SUIT_MessageBox
35 \brief Message dialog box for SUIT-based application
37 The class provides a modal dialog with a short message, an icon,
38 and buttons laid out depending on the current style.
40 Message boxes are used to provide informative messages and to ask
43 The easiest way to pop up a message box is to call one of the static
44 functions information(), question(), critical(), and warning().
46 The class provides the static functions to show message boxes with
47 standard buttons (like \c Ok, \c Cancel, \c Apply, \c Close, \c Yes,
48 \c No, \c Abort, \c Retry, etc). These methods accept ORed buttons
49 flags as one of the parameters. The buttons layouting type and order
50 is system-dependant and defined by the current style. In addition,
51 these methods allow to define default button (where input focus is
52 set by default and which is clicked when user presses \c Enter key).
54 Another set of static functions allows to show message boxes with
55 up to four user-defined buttons. It is possible to define default
56 and escape buttons using additional parameters.
58 And finally, the last group of static functions allow displaying
59 the message boxes with an arbitrary number of buttons.
63 // show question message box with two standard buttons
64 int result = SUIT_MessageBox::question(desktop(), "Error",
65 "File already exists? Overwrite?",
66 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
67 SUIT_MessageBox::No );
68 if ( result == SUIT_MessageBox::Yes )
69 overwriteFileFunction();
71 // show critical message box with user-defined buttons
72 // default is second button and escape is third button
73 int result = SUIT_MessageBox::critical(desktop(), "Hazard!",
74 "The situation is critical! What to do?",
75 "Hide", "Run Away", "Stand still", 1, 2);
81 runAwayFromHere(); break;
83 sitDownAndPray(); break;
88 // show message box with 6 buttons
89 // both default and escape buttons are set to first button ("Zero")
90 int result = SUIT_MessageBox::information(desktop(), "Question",
91 "Select your favourite number",
93 "Zero", "One", "Two", "Three", "Four", "Five");
94 useMyFavouriteNumberSomewhere( result );
100 \param parent parent widget
102 SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
103 : QMessageBox( parent )
109 \param icon message box icon (QMessageBox::Icon)
110 \param title message box title
111 \param text message box text
112 \param buttons ORed message box standard buttons (QMessageBox::StandardButton)
113 \param parent parent widget
114 \param f window flags
116 SUIT_MessageBox::SUIT_MessageBox( Icon icon, const QString& title, const QString& text,
117 StandardButtons buttons, QWidget* parent, Qt::WindowFlags f )
118 : QMessageBox( icon, title, text, buttons, parent, f )
125 SUIT_MessageBox::~SUIT_MessageBox()
130 \brief Get the standard button text.
131 \param btn standard button id
134 QString SUIT_MessageBox::buttonText( StandardButton btn ) const
137 QAbstractButton* b = button( btn );
144 \brief Set the standard button text.
145 \param btn standard button id
146 \param text new button text
148 void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
150 QAbstractButton* b = button( btn );
156 \brief Show critical message box with specified standard buttons.
157 \param parent parent widget
158 \param title message box title
159 \param text message box text
160 \param buttons ORed message box buttons (QMessageBox::StandardButton)
161 \param defaultButton default button (QMessageBox::StandardButton)
162 \return button id clicked by the user (QMessageBox::StandardButton)
164 SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
165 StandardButtons buttons, StandardButton defaultButton )
167 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
168 return QMessageBox::critical( parent, title, text, buttons, defaultButton );
172 \brief Show warning message box with specified standard buttons.
173 \param parent parent widget
174 \param title message box title
175 \param text message box text
176 \param buttons ORed message box buttons (QMessageBox::StandardButton)
177 \param defaultButton default button (QMessageBox::StandardButton)
178 \return button id clicked by the user (QMessageBox::StandardButton)
180 SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
181 SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
183 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
184 return QMessageBox::warning( parent, title, text, buttons, defaultButton );
188 \brief Show information message box with specified standard buttons.
189 \param parent parent widget
190 \param title message box title
191 \param text message box text
192 \param buttons ORed message box buttons (QMessageBox::StandardButton)
193 \param defaultButton default button (QMessageBox::StandardButton)
194 \return button id clicked by the user (QMessageBox::StandardButton)
196 SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
197 StandardButtons buttons, StandardButton defaultButton )
199 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
200 return QMessageBox::information( parent, title, text, buttons, defaultButton );
204 \brief Show question message box with specified standard buttons.
205 \param parent parent widget
206 \param title message box title
207 \param text message box text
208 \param buttons ORed message box buttons (QMessageBox::StandardButton)
209 \param defaultButton default button (QMessageBox::StandardButton)
210 \return button id clicked by the user (QMessageBox::StandardButton)
212 SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
213 StandardButtons buttons, StandardButton defaultButton )
215 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
216 return QMessageBox::question( parent, title, text, buttons, defaultButton );
220 \brief Show critical message box with one custom button.
222 Specified button becomes "default" button and "escape" button, i.e.
223 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
226 \param parent parent widget
227 \param title message box title
228 \param text message box text
229 \param button button text
230 \return button id clicked by the user (QMessageBox::StandardButton)
232 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
233 const QString& button )
236 lst.append( ButtonInfo( 0, button ) );
237 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst );
241 \brief Show warning message box with one custom button.
243 Specified button becomes "default" button and "escape" button, i.e.
244 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
247 \param parent parent widget
248 \param title message box title
249 \param text message box text
250 \param button button text
251 \return button id clicked by the user (QMessageBox::StandardButton)
253 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
254 const QString& button )
257 lst.append( ButtonInfo( 0, button ) );
258 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst );
262 \brief Show information message box with one custom button.
264 Specified button becomes "default" button and "escape" button, i.e.
265 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
268 \param parent parent widget
269 \param title message box title
270 \param text message box text
271 \param button button text
272 \return button id clicked by the user (QMessageBox::StandardButton)
274 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
275 const QString& button )
278 lst.append( ButtonInfo( 0, button ) );
279 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst );
283 \brief Show question message box with one custom button.
285 \warning This function does not make a lot of sense because it provides
286 message box with only one button, i.e. it is impossible to give several
287 answers for the question (at least 'yes'/'no').
288 This function is implemented only for completeness.
290 Specified button becomes "default" button and "escape" button, i.e.
291 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
294 \param parent parent widget
295 \param title message box title
296 \param text message box text
297 \param button button text
298 \return button id clicked by the user (QMessageBox::StandardButton)
300 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
301 const QString& button )
304 lst.append( ButtonInfo( 0, button ) );
305 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst );
309 \brief Show critical message box with two custom buttons.
311 Parameters \a button1 and \a button2 specify the buttons text.
312 The function returns clicked button id. The identifiers for the buttons
313 are assigned automatically. The first button is identified as 0, the
316 The \a defaultButton parameter allows to specify the button which is assigned
317 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
318 allows specifing the button which is assigned for \c Escape key.
319 If these parameters are not specified (-1 by default), the first button
320 is set as default button and the second one is defined as escape button.
322 \param parent parent widget
323 \param title message box title
324 \param text message box text
325 \param button1 first button text
326 \param button2 second button text
327 \param defaultButton default button
328 \param escapeButton escape button
329 \return button used button id
331 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
332 const QString& button1, const QString& button2,
333 const int defaultButton, const int escapeButton )
337 lst.append( ButtonInfo( id++, button1 ) );
338 lst.append( ButtonInfo( id++, button2 ) );
339 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
340 defaultButton, escapeButton );
344 \brief Show warning message box with two custom buttons.
346 Parameters \a button1 and \a button2 specify the buttons text.
347 The function returns clicked button id. The identifiers for the buttons
348 are assigned automatically. The first button is identified as 0, the
351 The \a defaultButton parameter allows to specify the button which is assigned
352 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
353 allows specifing the button which is assigned for \c Escape key.
354 If these parameters are not specified (-1 by default), the first button
355 is set as default button and the second one is defined as escape button.
357 \param parent parent widget
358 \param title message box title
359 \param text message box text
360 \param button1 first button text
361 \param button2 second button text
362 \param defaultButton default button
363 \param escapeButton escape button
364 \return button used button id
366 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
367 const QString& button1, const QString& button2,
368 const int defaultButton, const int escapeButton )
372 lst.append( ButtonInfo( id++, button1 ) );
373 lst.append( ButtonInfo( id++, button2 ) );
374 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
375 defaultButton, escapeButton );
379 \brief Show information message box with two custom buttons.
381 Parameters \a button1 and \a button2 specify the buttons text.
382 The function returns clicked button id. The identifiers for the buttons
383 are assigned automatically. The first button is identified as 0, the
386 The \a defaultButton parameter allows to specify the button which is assigned
387 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
388 allows specifing the button which is assigned for \c Escape key.
389 If these parameters are not specified (-1 by default), the first button
390 is set as default button and the second one is defined as escape button.
392 \param parent parent widget
393 \param title message box title
394 \param text message box text
395 \param button1 first button text
396 \param button2 second button text
397 \param defaultButton default button
398 \param escapeButton escape button
399 \return button used button id
401 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
402 const QString& button1, const QString& button2,
403 const int defaultButton, const int escapeButton )
407 lst.append( ButtonInfo( id++, button1 ) );
408 lst.append( ButtonInfo( id++, button2 ) );
409 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
410 defaultButton, escapeButton );
414 \brief Show question message box with two custom buttons.
416 Parameters \a button1 and \a button2 specify the buttons text.
417 The function returns clicked button id. The identifiers for the buttons
418 are assigned automatically. The first button is identified as 0, the
421 The \a defaultButton parameter allows to specify the button which is assigned
422 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
423 allows specifing the button which is assigned for \c Escape key.
424 If these parameters are not specified (-1 by default), the first button
425 is set as default button and the second one is defined as escape button.
427 \param parent parent widget
428 \param title message box title
429 \param text message box text
430 \param button1 first button text
431 \param button2 second button text
432 \param defaultButton default button
433 \param escapeButton escape button
434 \return button used button id
436 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
437 const QString& button1, const QString& button2,
438 const int defaultButton, const int escapeButton )
442 lst.append( ButtonInfo( id++, button1 ) );
443 lst.append( ButtonInfo( id++, button2 ) );
444 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
445 defaultButton, escapeButton );
449 \brief Show critical message box with three custom buttons.
451 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
452 The function returns clicked button id. The identifiers for the buttons
453 are assigned automatically. The first button is identified as 0, the
454 second one as 1, etc.
456 The \a defaultButton parameter allows to specify the button which is assigned
457 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
458 allows specifing the button which is assigned for \c Escape key.
459 If these parameters are not specified (-1 by default), the first button
460 is set as default button and the last one is defined as escape button.
462 \param parent parent widget
463 \param title message box title
464 \param text message box text
465 \param button1 first button text
466 \param button2 second button text
467 \param button3 third button text
468 \param defaultButton default button
469 \param escapeButton escape button
470 \return button used button id
472 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
473 const QString& button1, const QString& button2,
474 const QString& button3,
475 const int defaultButton, const int escapeButton )
479 lst.append( ButtonInfo( id++, button1 ) );
480 lst.append( ButtonInfo( id++, button2 ) );
481 lst.append( ButtonInfo( id++, button3 ) );
482 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
483 defaultButton, escapeButton );
487 \brief Show warning message box with three custom buttons.
489 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
490 The function returns clicked button id. The identifiers for the buttons
491 are assigned automatically. The first button is identified as 0, the
492 second one as 1, etc.
494 The \a defaultButton parameter allows to specify the button which is assigned
495 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
496 allows specifing the button which is assigned for \c Escape key.
497 If these parameters are not specified (-1 by default), the first button
498 is set as default button and the last one is defined as escape button.
500 \param parent parent widget
501 \param title message box title
502 \param text message box text
503 \param button1 first button text
504 \param button2 second button text
505 \param button3 third button text
506 \param defaultButton default button
507 \param escapeButton escape button
508 \return button used button id
510 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
511 const QString& button1, const QString& button2,
512 const QString& button3,
513 const int defaultButton, const int escapeButton )
517 lst.append( ButtonInfo( id++, button1 ) );
518 lst.append( ButtonInfo( id++, button2 ) );
519 lst.append( ButtonInfo( id++, button3 ) );
520 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
521 defaultButton, escapeButton );
525 \brief Show information message box with three custom buttons.
527 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
528 The function returns clicked button id. The identifiers for the buttons
529 are assigned automatically. The first button is identified as 0, the
530 second one as 1, etc.
532 The \a defaultButton parameter allows to specify the button which is assigned
533 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
534 allows specifing the button which is assigned for \c Escape key.
535 If these parameters are not specified (-1 by default), the first button
536 is set as default button and the last one is defined as escape button.
538 \param parent parent widget
539 \param title message box title
540 \param text message box text
541 \param button1 first button text
542 \param button2 second button text
543 \param button3 third button text
544 \param defaultButton default button
545 \param escapeButton escape button
546 \return button used button id
548 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
549 const QString& button1, const QString& button2,
550 const QString& button3,
551 const int defaultButton, const int escapeButton )
555 lst.append( ButtonInfo( id++, button1 ) );
556 lst.append( ButtonInfo( id++, button2 ) );
557 lst.append( ButtonInfo( id++, button3 ) );
558 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
559 defaultButton, escapeButton );
563 \brief Show question message box with three custom buttons.
565 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
566 The function returns clicked button id. The identifiers for the buttons
567 are assigned automatically. The first button is identified as 0, the
568 second one as 1, etc.
570 The \a defaultButton parameter allows to specify the button which is assigned
571 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
572 allows specifing the button which is assigned for \c Escape key.
573 If these parameters are not specified (-1 by default), the first button
574 is set as default button and the last one is defined as escape button.
576 \param parent parent widget
577 \param title message box title
578 \param text message box text
579 \param button1 first button text
580 \param button2 second button text
581 \param button3 third button text
582 \param defaultButton default button
583 \param escapeButton escape button
584 \return button used button id
586 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
587 const QString& button1, const QString& button2,
588 const QString& button3,
589 const int defaultButton, const int escapeButton )
593 lst.append( ButtonInfo( id++, button1 ) );
594 lst.append( ButtonInfo( id++, button2 ) );
595 lst.append( ButtonInfo( id++, button3 ) );
596 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
597 defaultButton, escapeButton );
601 \brief Show critical message box with four custom buttons.
603 Parameters \a button1, \a button2, \a button3 and \a button4 specify
605 The function returns clicked button id. The identifiers for the buttons
606 are assigned automatically. The first button is identified as 0, the
607 second one as 1, etc.
609 The \a defaultButton parameter allows to specify the button which is assigned
610 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
611 allows specifing the button which is assigned for \c Escape key.
612 If these parameters are not specified (-1 by default), the first button
613 is set as default button and the last one is defined as escape button.
615 \param parent parent widget
616 \param title message box title
617 \param text message box text
618 \param button1 first button text
619 \param button2 second button text
620 \param button3 third button text
621 \param button4 fourth button text
622 \param defaultButton default button
623 \param escapeButton escape button
624 \return button used button id
626 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
627 const QString& button1, const QString& button2,
628 const QString& button3, const QString& button4,
629 const int defaultButton, const int escapeButton )
633 lst.append( ButtonInfo( id++, button1 ) );
634 lst.append( ButtonInfo( id++, button2 ) );
635 lst.append( ButtonInfo( id++, button3 ) );
636 lst.append( ButtonInfo( id++, button4 ) );
637 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
638 defaultButton, escapeButton );
642 \brief Show warning message box with four custom buttons.
644 Parameters \a button1, \a button2, \a button3 and \a button4 specify
646 The function returns clicked button id. The identifiers for the buttons
647 are assigned automatically. The first button is identified as 0, the
648 second one as 1, etc.
650 The \a defaultButton parameter allows to specify the button which is assigned
651 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
652 allows specifing the button which is assigned for \c Escape key.
653 If these parameters are not specified (-1 by default), the first button
654 is set as default button and the last one is defined as escape button.
656 \param parent parent widget
657 \param title message box title
658 \param text message box text
659 \param button1 first button text
660 \param button2 second button text
661 \param button3 third button text
662 \param button4 fourth button text
663 \param defaultButton default button
664 \param escapeButton escape button
665 \return button used button id
667 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
668 const QString& button1, const QString& button2,
669 const QString& button3, const QString& button4,
670 const int defaultButton, const int escapeButton )
674 lst.append( ButtonInfo( id++, button1 ) );
675 lst.append( ButtonInfo( id++, button2 ) );
676 lst.append( ButtonInfo( id++, button3 ) );
677 lst.append( ButtonInfo( id++, button4 ) );
678 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
679 defaultButton, escapeButton );
683 \brief Show information message box with four custom buttons.
685 Parameters \a button1, \a button2, \a button3 and \a button4 specify
687 The function returns clicked button id. The identifiers for the buttons
688 are assigned automatically. The first button is identified as 0, the
689 second one as 1, etc.
691 The \a defaultButton parameter allows to specify the button which is assigned
692 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
693 allows specifing the button which is assigned for \c Escape key.
694 If these parameters are not specified (-1 by default), the first button
695 is set as default button and the last one is defined as escape button.
697 \param parent parent widget
698 \param title message box title
699 \param text message box text
700 \param button1 first button text
701 \param button2 second button text
702 \param button3 third button text
703 \param button4 fourth button text
704 \param defaultButton default button
705 \param escapeButton escape button
706 \return button used button id
708 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
709 const QString& button1, const QString& button2,
710 const QString& button3, const QString& button4,
711 const int defaultButton, const int escapeButton )
715 lst.append( ButtonInfo( id++, button1 ) );
716 lst.append( ButtonInfo( id++, button2 ) );
717 lst.append( ButtonInfo( id++, button3 ) );
718 lst.append( ButtonInfo( id++, button4 ) );
719 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
720 defaultButton, escapeButton );
724 \brief Show question message box with four custom buttons.
726 Parameters \a button1, \a button2, \a button3 and \a button4 specify
728 The function returns clicked button id. The identifiers for the buttons
729 are assigned automatically. The first button is identified as 0, the
730 second one as 1, etc.
732 The \a defaultButton parameter allows to specify the button which is assigned
733 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
734 allows specifing the button which is assigned for \c Escape key.
735 If these parameters are not specified (-1 by default), the first button
736 is set as default button and the last one is defined as escape button.
738 \param parent parent widget
739 \param title message box title
740 \param text message box text
741 \param button1 first button text
742 \param button2 second button text
743 \param button3 third button text
744 \param button4 fourth button text
745 \param defaultButton default button
746 \param escapeButton escape button
747 \return button used button id
749 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
750 const QString& button1, const QString& button2,
751 const QString& button3, const QString& button4,
752 const int defaultButton, const int escapeButton )
756 lst.append( ButtonInfo( id++, button1 ) );
757 lst.append( ButtonInfo( id++, button2 ) );
758 lst.append( ButtonInfo( id++, button3 ) );
759 lst.append( ButtonInfo( id++, button4 ) );
760 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
761 defaultButton, escapeButton );
765 \brief Show critical message box with arbitrary number of user-specified
768 The function accepts arbitrary number of parameters. Each parameter starting
769 from \a btn should be of type const char* to specify the button text.
770 After the last button parameter and additional 0 (zero) value should be
773 The function returns clicked button id. The identifiers for the buttons
774 are assigned automatically. The first button is identified as 0, the
775 second one as 1, etc.
777 The \a defaultButton parameter allows to specify the button which is assigned
778 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
779 allows specifing the button which is assigned for \c Escape key.
780 If these parameters are not specified (-1 by default), the first button
781 is set as default button and the last one is defined as escape button.
783 \param parent parent widget
784 \param title message box title
785 \param text message box text
786 \param defaultButton default button
787 \param escapeButton escape button
788 \param btn first button text
789 \return button used button id
791 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
792 const int defaultButton, const int escapeButton,
796 va_start( args, btn );
797 return messageBox( SUIT_MessageBox::Critical, parent, title, text,
798 messageList( btn, args ),
799 defaultButton, escapeButton );
803 \brief Show warning message box with arbitrary number of user-specified
806 The function accepts arbitrary number of parameters. Each parameter starting
807 from \a btn should be of type const char* to specify the button text.
808 After the last button parameter and additional 0 (zero) value should be
811 The function returns clicked button id. The identifiers for the buttons
812 are assigned automatically. The first button is identified as 0, the
813 second one as 1, etc.
815 The \a defaultButton parameter allows to specify the button which is assigned
816 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
817 allows specifing the button which is assigned for \c Escape key.
818 If these parameters are not specified (-1 by default), the first button
819 is set as default button and the last one is defined as escape button.
821 \param parent parent widget
822 \param title message box title
823 \param text message box text
824 \param defaultButton default button
825 \param escapeButton escape button
826 \param btn first button text
827 \return button used button id
829 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
830 const int defaultButton, const int escapeButton,
834 va_start( args, btn );
835 return messageBox( SUIT_MessageBox::Warning, parent, title, text,
836 messageList( btn, args ),
837 defaultButton, escapeButton );
841 \brief Show information message box with arbitrary number of user-specified
844 The function accepts arbitrary number of parameters. Each parameter starting
845 from \a btn should be of type const char* to specify the button text.
846 After the last button parameter and additional 0 (zero) value should be
849 The function returns clicked button id. The identifiers for the buttons
850 are assigned automatically. The first button is identified as 0, the
851 second one as 1, etc.
853 The \a defaultButton parameter allows to specify the button which is assigned
854 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
855 allows specifing the button which is assigned for \c Escape key.
856 If these parameters are not specified (-1 by default), the first button
857 is set as default button and the last one is defined as escape button.
859 \param parent parent widget
860 \param title message box title
861 \param text message box text
862 \param defaultButton default button
863 \param escapeButton escape button
864 \param btn first button text
865 \return button used button id
867 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
868 const int defaultButton, const int escapeButton,
872 va_start( args, btn );
873 return messageBox( SUIT_MessageBox::Information, parent, title, text,
874 messageList( btn, args ),
875 defaultButton, escapeButton );
879 \brief Show question message box with arbitrary number of user-specified
882 The function accepts arbitrary number of parameters. Each parameter starting
883 from \a btn should be of type const char* to specify the button text.
884 After the last button parameter and additional 0 (zero) value should be
887 The function returns clicked button id. The identifiers for the buttons
888 are assigned automatically. The first button is identified as 0, the
889 second one as 1, etc.
891 The \a defaultButton parameter allows to specify the button which is assigned
892 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
893 allows specifing the button which is assigned for \c Escape key.
894 If these parameters are not specified (-1 by default), the first button
895 is set as default button and the last one is defined as escape button.
897 \param parent parent widget
898 \param title message box title
899 \param text message box text
900 \param defaultButton default button
901 \param escapeButton escape button
902 \param btn first button text
903 \return button used button id
905 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
906 const int defaultButton, const int escapeButton,
910 va_start( args, btn );
911 return messageBox( SUIT_MessageBox::Question, parent, title, text,
912 messageList( btn, args ),
913 defaultButton, escapeButton );
917 \brief Parse arbitrary arguments list.
919 The last parameter in a sequence should be 0 (zero) value.
921 \param txt first argument which starts arbitrary sequence
922 \param args arguments list from the stack
923 \return list of buttons infos
925 SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args )
932 lst.append( ButtonInfo( i++, cur ) );
933 cur = va_arg( args, char* );
942 \brief Create and show the message box.
943 \param icon icon type
944 \param parent parent widget
945 \param title message box title
946 \param text message box text
947 \param lst list of buttons infos
948 \param defaultButton default button
949 \param escapeButton escape button
950 \return button used button id
952 int SUIT_MessageBox::messageBox( Icon icon, QWidget* parent,
953 const QString& title, const QString& text,
954 const ButtonInfos& lst,
955 const int defaultButton,
956 const int escapeButton )
958 SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
960 QMap<QAbstractButton*, int> bm;
961 for ( int i = 0; i < lst.count(); i++ )
963 int btn = lst[i].id();
964 QString txt = lst[i].text();
965 ButtonRole role = lst[i].role();
967 QPushButton* pb = msgBox.addButton( txt, role );
968 bm.insert( pb, btn );
970 if ( defaultButton == -1 && i == 0 || btn == defaultButton )
971 msgBox.setDefaultButton( pb );
972 if ( escapeButton == -1 && i == lst.count() - 1 || btn == escapeButton )
973 msgBox.setEscapeButton( pb );
976 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
978 int res = msgBox.exec();
980 res = bm[msgBox.clickedButton()];
982 QApplication::processEvents();