1 // Copyright (C) 2007-2013 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
23 #include "SUIT_MessageBox.h"
25 #include "SUIT_OverrideCursor.h"
27 #include <QMessageBox>
28 #include <QPushButton>
29 #include <QApplication>
35 \class SUIT_MessageBox
36 \brief Message dialog box for SUIT-based application
38 The class provides a modal dialog with a short message, an icon,
39 and buttons laid out depending on the current style.
41 Message boxes are used to provide informative messages and to ask
44 The easiest way to pop up a message box is to call one of the static
45 functions information(), question(), critical(), and warning().
47 The class provides the static functions to show message boxes with
48 standard buttons (like \c Ok, \c Cancel, \c Apply, \c Close, \c Yes,
49 \c No, \c Abort, \c Retry, etc). These methods accept ORed buttons
50 flags as one of the parameters. The buttons layouting type and order
51 is system-dependant and defined by the current style. In addition,
52 these methods allow to define default button (where input focus is
53 set by default and which is clicked when user presses \c Enter key).
55 Another set of static functions allows to show message boxes with
56 up to four user-defined buttons. It is possible to define default
57 and escape buttons using additional parameters.
59 And finally, the last group of static functions allow displaying
60 the message boxes with an arbitrary number of buttons.
64 // show question message box with two standard buttons
65 int result = SUIT_MessageBox::question(desktop(), "Error",
66 "File already exists? Overwrite?",
67 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
68 SUIT_MessageBox::No );
69 if ( result == SUIT_MessageBox::Yes )
70 overwriteFileFunction();
72 // show critical message box with user-defined buttons
73 // default is second button and escape is third button
74 int result = SUIT_MessageBox::critical(desktop(), "Hazard!",
75 "The situation is critical! What to do?",
76 "Hide", "Run Away", "Stand still", 1, 2);
82 runAwayFromHere(); break;
84 sitDownAndPray(); break;
89 // show message box with 6 buttons
90 // both default and escape buttons are set to first button ("Zero")
91 int result = SUIT_MessageBox::information(desktop(), "Question",
92 "Select your favourite number",
94 "Zero", "One", "Two", "Three", "Four", "Five");
95 useMyFavouriteNumberSomewhere( result );
101 \param parent parent widget
103 SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
104 : QMessageBox( parent )
110 \param icon message box icon (QMessageBox::Icon)
111 \param title message box title
112 \param text message box text
113 \param buttons ORed message box standard buttons (QMessageBox::StandardButton)
114 \param parent parent widget
115 \param f window flags
117 SUIT_MessageBox::SUIT_MessageBox( Icon icon, const QString& title, const QString& text,
118 StandardButtons buttons, QWidget* parent, Qt::WindowFlags f )
119 : QMessageBox( icon, title, text, buttons, parent, f )
126 SUIT_MessageBox::~SUIT_MessageBox()
131 \brief Get the standard button text.
132 \param btn standard button id
135 QString SUIT_MessageBox::buttonText( StandardButton btn ) const
138 QAbstractButton* b = button( btn );
145 \brief Set the standard button text.
146 \param btn standard button id
147 \param text new button text
149 void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
151 QAbstractButton* b = button( btn );
157 \brief Show critical message box with specified standard buttons.
158 \param parent parent widget
159 \param title message box title
160 \param text message box text
161 \param buttons ORed message box buttons (QMessageBox::StandardButton)
162 \param defaultButton default button (QMessageBox::StandardButton)
163 \return button id clicked by the user (QMessageBox::StandardButton)
165 SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
166 StandardButtons buttons, StandardButton defaultButton )
168 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
169 return QMessageBox::critical( parent, title, text, buttons, defaultButton );
173 \brief Show warning message box with specified standard buttons.
174 \param parent parent widget
175 \param title message box title
176 \param text message box text
177 \param buttons ORed message box buttons (QMessageBox::StandardButton)
178 \param defaultButton default button (QMessageBox::StandardButton)
179 \return button id clicked by the user (QMessageBox::StandardButton)
181 SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
182 SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
184 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
185 return QMessageBox::warning( parent, title, text, buttons, defaultButton );
189 \brief Show information message box with specified standard buttons.
190 \param parent parent widget
191 \param title message box title
192 \param text message box text
193 \param buttons ORed message box buttons (QMessageBox::StandardButton)
194 \param defaultButton default button (QMessageBox::StandardButton)
195 \return button id clicked by the user (QMessageBox::StandardButton)
197 SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
198 StandardButtons buttons, StandardButton defaultButton )
200 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
201 return QMessageBox::information( parent, title, text, buttons, defaultButton );
205 \brief Show question message box with specified standard buttons.
206 \param parent parent widget
207 \param title message box title
208 \param text message box text
209 \param buttons ORed message box buttons (QMessageBox::StandardButton)
210 \param defaultButton default button (QMessageBox::StandardButton)
211 \return button id clicked by the user (QMessageBox::StandardButton)
213 SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
214 StandardButtons buttons, StandardButton defaultButton )
216 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
217 return QMessageBox::question( parent, title, text, buttons, defaultButton );
221 \brief Show critical message box with one custom button.
223 Specified button becomes "default" button and "escape" button, i.e.
224 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
227 \param parent parent widget
228 \param title message box title
229 \param text message box text
230 \param button button text
231 \return button id clicked by the user (QMessageBox::StandardButton)
233 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
234 const QString& button )
237 lst.append( ButtonInfo( 0, button ) );
238 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst );
242 \brief Show warning message box with one custom button.
244 Specified button becomes "default" button and "escape" button, i.e.
245 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
248 \param parent parent widget
249 \param title message box title
250 \param text message box text
251 \param button button text
252 \return button id clicked by the user (QMessageBox::StandardButton)
254 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
255 const QString& button )
258 lst.append( ButtonInfo( 0, button ) );
259 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst );
263 \brief Show information message box with one custom button.
265 Specified button becomes "default" button and "escape" button, i.e.
266 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
269 \param parent parent widget
270 \param title message box title
271 \param text message box text
272 \param button button text
273 \return button id clicked by the user (QMessageBox::StandardButton)
275 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
276 const QString& button )
279 lst.append( ButtonInfo( 0, button ) );
280 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst );
284 \brief Show question message box with one custom button.
286 \warning This function does not make a lot of sense because it provides
287 message box with only one button, i.e. it is impossible to give several
288 answers for the question (at least 'yes'/'no').
289 This function is implemented only for completeness.
291 Specified button becomes "default" button and "escape" button, i.e.
292 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
295 \param parent parent widget
296 \param title message box title
297 \param text message box text
298 \param button button text
299 \return button id clicked by the user (QMessageBox::StandardButton)
301 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
302 const QString& button )
305 lst.append( ButtonInfo( 0, button ) );
306 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst );
310 \brief Show critical message box with two custom buttons.
312 Parameters \a button1 and \a button2 specify the buttons text.
313 The function returns clicked button id. The identifiers for the buttons
314 are assigned automatically. The first button is identified as 0, the
317 The \a defaultButton parameter allows to specify the button which is assigned
318 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
319 allows specifing the button which is assigned for \c Escape key.
320 If these parameters are not specified (-1 by default), the first button
321 is set as default button and the second one is defined as escape button.
323 \param parent parent widget
324 \param title message box title
325 \param text message box text
326 \param button1 first button text
327 \param button2 second button text
328 \param defaultButton default button
329 \param escapeButton escape button
330 \return button used button id
332 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
333 const QString& button1, const QString& button2,
334 const int defaultButton, const int escapeButton )
338 lst.append( ButtonInfo( id++, button1 ) );
339 lst.append( ButtonInfo( id++, button2 ) );
340 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
341 defaultButton, escapeButton );
345 \brief Show warning message box with two custom buttons.
347 Parameters \a button1 and \a button2 specify the buttons text.
348 The function returns clicked button id. The identifiers for the buttons
349 are assigned automatically. The first button is identified as 0, the
352 The \a defaultButton parameter allows to specify the button which is assigned
353 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
354 allows specifing the button which is assigned for \c Escape key.
355 If these parameters are not specified (-1 by default), the first button
356 is set as default button and the second one is defined as escape button.
358 \param parent parent widget
359 \param title message box title
360 \param text message box text
361 \param button1 first button text
362 \param button2 second button text
363 \param defaultButton default button
364 \param escapeButton escape button
365 \return button used button id
367 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
368 const QString& button1, const QString& button2,
369 const int defaultButton, const int escapeButton )
373 lst.append( ButtonInfo( id++, button1 ) );
374 lst.append( ButtonInfo( id++, button2 ) );
375 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
376 defaultButton, escapeButton );
380 \brief Show information message box with two custom buttons.
382 Parameters \a button1 and \a button2 specify the buttons text.
383 The function returns clicked button id. The identifiers for the buttons
384 are assigned automatically. The first button is identified as 0, the
387 The \a defaultButton parameter allows to specify the button which is assigned
388 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
389 allows specifing the button which is assigned for \c Escape key.
390 If these parameters are not specified (-1 by default), the first button
391 is set as default button and the second one is defined as escape button.
393 \param parent parent widget
394 \param title message box title
395 \param text message box text
396 \param button1 first button text
397 \param button2 second button text
398 \param defaultButton default button
399 \param escapeButton escape button
400 \return button used button id
402 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
403 const QString& button1, const QString& button2,
404 const int defaultButton, const int escapeButton )
408 lst.append( ButtonInfo( id++, button1 ) );
409 lst.append( ButtonInfo( id++, button2 ) );
410 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
411 defaultButton, escapeButton );
415 \brief Show question message box with two custom buttons.
417 Parameters \a button1 and \a button2 specify the buttons text.
418 The function returns clicked button id. The identifiers for the buttons
419 are assigned automatically. The first button is identified as 0, the
422 The \a defaultButton parameter allows to specify the button which is assigned
423 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
424 allows specifing the button which is assigned for \c Escape key.
425 If these parameters are not specified (-1 by default), the first button
426 is set as default button and the second one is defined as escape button.
428 \param parent parent widget
429 \param title message box title
430 \param text message box text
431 \param button1 first button text
432 \param button2 second button text
433 \param defaultButton default button
434 \param escapeButton escape button
435 \return button used button id
437 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
438 const QString& button1, const QString& button2,
439 const int defaultButton, const int escapeButton )
443 lst.append( ButtonInfo( id++, button1 ) );
444 lst.append( ButtonInfo( id++, button2 ) );
445 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
446 defaultButton, escapeButton );
450 \brief Show critical message box with three custom buttons.
452 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
453 The function returns clicked button id. The identifiers for the buttons
454 are assigned automatically. The first button is identified as 0, the
455 second one as 1, etc.
457 The \a defaultButton parameter allows to specify the button which is assigned
458 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
459 allows specifing the button which is assigned for \c Escape key.
460 If these parameters are not specified (-1 by default), the first button
461 is set as default button and the last one is defined as escape button.
463 \param parent parent widget
464 \param title message box title
465 \param text message box text
466 \param button1 first button text
467 \param button2 second button text
468 \param button3 third button text
469 \param defaultButton default button
470 \param escapeButton escape button
471 \return button used button id
473 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
474 const QString& button1, const QString& button2,
475 const QString& button3,
476 const int defaultButton, const int escapeButton )
480 lst.append( ButtonInfo( id++, button1 ) );
481 lst.append( ButtonInfo( id++, button2 ) );
482 lst.append( ButtonInfo( id++, button3 ) );
483 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
484 defaultButton, escapeButton );
488 \brief Show warning message box with three custom buttons.
490 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
491 The function returns clicked button id. The identifiers for the buttons
492 are assigned automatically. The first button is identified as 0, the
493 second one as 1, etc.
495 The \a defaultButton parameter allows to specify the button which is assigned
496 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
497 allows specifing the button which is assigned for \c Escape key.
498 If these parameters are not specified (-1 by default), the first button
499 is set as default button and the last one is defined as escape button.
501 \param parent parent widget
502 \param title message box title
503 \param text message box text
504 \param button1 first button text
505 \param button2 second button text
506 \param button3 third button text
507 \param defaultButton default button
508 \param escapeButton escape button
509 \return button used button id
511 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
512 const QString& button1, const QString& button2,
513 const QString& button3,
514 const int defaultButton, const int escapeButton )
518 lst.append( ButtonInfo( id++, button1 ) );
519 lst.append( ButtonInfo( id++, button2 ) );
520 lst.append( ButtonInfo( id++, button3 ) );
521 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
522 defaultButton, escapeButton );
526 \brief Show information message box with three custom buttons.
528 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
529 The function returns clicked button id. The identifiers for the buttons
530 are assigned automatically. The first button is identified as 0, the
531 second one as 1, etc.
533 The \a defaultButton parameter allows to specify the button which is assigned
534 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
535 allows specifing the button which is assigned for \c Escape key.
536 If these parameters are not specified (-1 by default), the first button
537 is set as default button and the last one is defined as escape button.
539 \param parent parent widget
540 \param title message box title
541 \param text message box text
542 \param button1 first button text
543 \param button2 second button text
544 \param button3 third button text
545 \param defaultButton default button
546 \param escapeButton escape button
547 \return button used button id
549 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
550 const QString& button1, const QString& button2,
551 const QString& button3,
552 const int defaultButton, const int escapeButton )
556 lst.append( ButtonInfo( id++, button1 ) );
557 lst.append( ButtonInfo( id++, button2 ) );
558 lst.append( ButtonInfo( id++, button3 ) );
559 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
560 defaultButton, escapeButton );
564 \brief Show question message box with three custom buttons.
566 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
567 The function returns clicked button id. The identifiers for the buttons
568 are assigned automatically. The first button is identified as 0, the
569 second one as 1, etc.
571 The \a defaultButton parameter allows to specify the button which is assigned
572 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
573 allows specifing the button which is assigned for \c Escape key.
574 If these parameters are not specified (-1 by default), the first button
575 is set as default button and the last one is defined as escape button.
577 \param parent parent widget
578 \param title message box title
579 \param text message box text
580 \param button1 first button text
581 \param button2 second button text
582 \param button3 third button text
583 \param defaultButton default button
584 \param escapeButton escape button
585 \return button used button id
587 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
588 const QString& button1, const QString& button2,
589 const QString& button3,
590 const int defaultButton, const int escapeButton )
594 lst.append( ButtonInfo( id++, button1 ) );
595 lst.append( ButtonInfo( id++, button2 ) );
596 lst.append( ButtonInfo( id++, button3 ) );
597 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
598 defaultButton, escapeButton );
602 \brief Show critical message box with four custom buttons.
604 Parameters \a button1, \a button2, \a button3 and \a button4 specify
606 The function returns clicked button id. The identifiers for the buttons
607 are assigned automatically. The first button is identified as 0, the
608 second one as 1, etc.
610 The \a defaultButton parameter allows to specify the button which is assigned
611 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
612 allows specifing the button which is assigned for \c Escape key.
613 If these parameters are not specified (-1 by default), the first button
614 is set as default button and the last one is defined as escape button.
616 \param parent parent widget
617 \param title message box title
618 \param text message box text
619 \param button1 first button text
620 \param button2 second button text
621 \param button3 third button text
622 \param button4 fourth button text
623 \param defaultButton default button
624 \param escapeButton escape button
625 \return button used button id
627 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
628 const QString& button1, const QString& button2,
629 const QString& button3, const QString& button4,
630 const int defaultButton, const int escapeButton )
634 lst.append( ButtonInfo( id++, button1 ) );
635 lst.append( ButtonInfo( id++, button2 ) );
636 lst.append( ButtonInfo( id++, button3 ) );
637 lst.append( ButtonInfo( id++, button4 ) );
638 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
639 defaultButton, escapeButton );
643 \brief Show warning message box with four custom buttons.
645 Parameters \a button1, \a button2, \a button3 and \a button4 specify
647 The function returns clicked button id. The identifiers for the buttons
648 are assigned automatically. The first button is identified as 0, the
649 second one as 1, etc.
651 The \a defaultButton parameter allows to specify the button which is assigned
652 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
653 allows specifing the button which is assigned for \c Escape key.
654 If these parameters are not specified (-1 by default), the first button
655 is set as default button and the last one is defined as escape button.
657 \param parent parent widget
658 \param title message box title
659 \param text message box text
660 \param button1 first button text
661 \param button2 second button text
662 \param button3 third button text
663 \param button4 fourth button text
664 \param defaultButton default button
665 \param escapeButton escape button
666 \return button used button id
668 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
669 const QString& button1, const QString& button2,
670 const QString& button3, const QString& button4,
671 const int defaultButton, const int escapeButton )
675 lst.append( ButtonInfo( id++, button1 ) );
676 lst.append( ButtonInfo( id++, button2 ) );
677 lst.append( ButtonInfo( id++, button3 ) );
678 lst.append( ButtonInfo( id++, button4 ) );
679 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
680 defaultButton, escapeButton );
684 \brief Show information message box with four custom buttons.
686 Parameters \a button1, \a button2, \a button3 and \a button4 specify
688 The function returns clicked button id. The identifiers for the buttons
689 are assigned automatically. The first button is identified as 0, the
690 second one as 1, etc.
692 The \a defaultButton parameter allows to specify the button which is assigned
693 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
694 allows specifing the button which is assigned for \c Escape key.
695 If these parameters are not specified (-1 by default), the first button
696 is set as default button and the last one is defined as escape button.
698 \param parent parent widget
699 \param title message box title
700 \param text message box text
701 \param button1 first button text
702 \param button2 second button text
703 \param button3 third button text
704 \param button4 fourth button text
705 \param defaultButton default button
706 \param escapeButton escape button
707 \return button used button id
709 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
710 const QString& button1, const QString& button2,
711 const QString& button3, const QString& button4,
712 const int defaultButton, const int escapeButton )
716 lst.append( ButtonInfo( id++, button1 ) );
717 lst.append( ButtonInfo( id++, button2 ) );
718 lst.append( ButtonInfo( id++, button3 ) );
719 lst.append( ButtonInfo( id++, button4 ) );
720 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
721 defaultButton, escapeButton );
725 \brief Show question message box with four custom buttons.
727 Parameters \a button1, \a button2, \a button3 and \a button4 specify
729 The function returns clicked button id. The identifiers for the buttons
730 are assigned automatically. The first button is identified as 0, the
731 second one as 1, etc.
733 The \a defaultButton parameter allows to specify the button which is assigned
734 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
735 allows specifing the button which is assigned for \c Escape key.
736 If these parameters are not specified (-1 by default), the first button
737 is set as default button and the last one is defined as escape button.
739 \param parent parent widget
740 \param title message box title
741 \param text message box text
742 \param button1 first button text
743 \param button2 second button text
744 \param button3 third button text
745 \param button4 fourth button text
746 \param defaultButton default button
747 \param escapeButton escape button
748 \return button used button id
750 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
751 const QString& button1, const QString& button2,
752 const QString& button3, const QString& button4,
753 const int defaultButton, const int escapeButton )
757 lst.append( ButtonInfo( id++, button1 ) );
758 lst.append( ButtonInfo( id++, button2 ) );
759 lst.append( ButtonInfo( id++, button3 ) );
760 lst.append( ButtonInfo( id++, button4 ) );
761 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
762 defaultButton, escapeButton );
766 \brief Show critical message box with arbitrary number of user-specified
769 The function accepts arbitrary number of parameters. Each parameter starting
770 from \a btn should be of type const char* to specify the button text.
771 After the last button parameter and additional 0 (zero) value should be
774 The function returns clicked button id. The identifiers for the buttons
775 are assigned automatically. The first button is identified as 0, the
776 second one as 1, etc.
778 The \a defaultButton parameter allows to specify the button which is assigned
779 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
780 allows specifing the button which is assigned for \c Escape key.
781 If these parameters are not specified (-1 by default), the first button
782 is set as default button and the last one is defined as escape button.
784 \param parent parent widget
785 \param title message box title
786 \param text message box text
787 \param defaultButton default button
788 \param escapeButton escape button
789 \param btn first button text
790 \return button used button id
792 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
793 const int defaultButton, const int escapeButton,
797 va_start( args, btn );
798 return messageBox( SUIT_MessageBox::Critical, parent, title, text,
799 messageList( btn, args ),
800 defaultButton, escapeButton );
804 \brief Show warning message box with arbitrary number of user-specified
807 The function accepts arbitrary number of parameters. Each parameter starting
808 from \a btn should be of type const char* to specify the button text.
809 After the last button parameter and additional 0 (zero) value should be
812 The function returns clicked button id. The identifiers for the buttons
813 are assigned automatically. The first button is identified as 0, the
814 second one as 1, etc.
816 The \a defaultButton parameter allows to specify the button which is assigned
817 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
818 allows specifing the button which is assigned for \c Escape key.
819 If these parameters are not specified (-1 by default), the first button
820 is set as default button and the last one is defined as escape button.
822 \param parent parent widget
823 \param title message box title
824 \param text message box text
825 \param defaultButton default button
826 \param escapeButton escape button
827 \param btn first button text
828 \return button used button id
830 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
831 const int defaultButton, const int escapeButton,
835 va_start( args, btn );
836 return messageBox( SUIT_MessageBox::Warning, parent, title, text,
837 messageList( btn, args ),
838 defaultButton, escapeButton );
842 \brief Show information message box with arbitrary number of user-specified
845 The function accepts arbitrary number of parameters. Each parameter starting
846 from \a btn should be of type const char* to specify the button text.
847 After the last button parameter and additional 0 (zero) value should be
850 The function returns clicked button id. The identifiers for the buttons
851 are assigned automatically. The first button is identified as 0, the
852 second one as 1, etc.
854 The \a defaultButton parameter allows to specify the button which is assigned
855 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
856 allows specifing the button which is assigned for \c Escape key.
857 If these parameters are not specified (-1 by default), the first button
858 is set as default button and the last one is defined as escape button.
860 \param parent parent widget
861 \param title message box title
862 \param text message box text
863 \param defaultButton default button
864 \param escapeButton escape button
865 \param btn first button text
866 \return button used button id
868 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
869 const int defaultButton, const int escapeButton,
873 va_start( args, btn );
874 return messageBox( SUIT_MessageBox::Information, parent, title, text,
875 messageList( btn, args ),
876 defaultButton, escapeButton );
880 \brief Show question message box with arbitrary number of user-specified
883 The function accepts arbitrary number of parameters. Each parameter starting
884 from \a btn should be of type const char* to specify the button text.
885 After the last button parameter and additional 0 (zero) value should be
888 The function returns clicked button id. The identifiers for the buttons
889 are assigned automatically. The first button is identified as 0, the
890 second one as 1, etc.
892 The \a defaultButton parameter allows to specify the button which is assigned
893 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
894 allows specifing the button which is assigned for \c Escape key.
895 If these parameters are not specified (-1 by default), the first button
896 is set as default button and the last one is defined as escape button.
898 \param parent parent widget
899 \param title message box title
900 \param text message box text
901 \param defaultButton default button
902 \param escapeButton escape button
903 \param btn first button text
904 \return button used button id
906 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
907 const int defaultButton, const int escapeButton,
911 va_start( args, btn );
912 return messageBox( SUIT_MessageBox::Question, parent, title, text,
913 messageList( btn, args ),
914 defaultButton, escapeButton );
918 \brief Parse arbitrary arguments list.
920 The last parameter in a sequence should be 0 (zero) value.
922 \param txt first argument which starts arbitrary sequence
923 \param args arguments list from the stack
924 \return list of buttons infos
926 SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args )
933 lst.append( ButtonInfo( i++, cur ) );
934 cur = va_arg( args, char* );
943 \brief Create and show the message box.
944 \param icon icon type
945 \param parent parent widget
946 \param title message box title
947 \param text message box text
948 \param lst list of buttons infos
949 \param defaultButton default button
950 \param escapeButton escape button
951 \return button used button id
953 int SUIT_MessageBox::messageBox( Icon icon, QWidget* parent,
954 const QString& title, const QString& text,
955 const ButtonInfos& lst,
956 const int defaultButton,
957 const int escapeButton )
959 SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
961 QMap<QAbstractButton*, int> bm;
962 for ( int i = 0; i < lst.count(); i++ )
964 int btn = lst[i].id();
965 QString txt = lst[i].text();
966 ButtonRole role = lst[i].role();
968 QPushButton* pb = msgBox.addButton( txt, role );
969 bm.insert( pb, btn );
971 if ( ( defaultButton == -1 && i == 0 ) || btn == defaultButton )
972 msgBox.setDefaultButton( pb );
973 if ( ( escapeButton == -1 && i == lst.count() - 1 ) || btn == escapeButton )
974 msgBox.setEscapeButton( pb );
977 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
979 int res = msgBox.exec();
981 res = bm[msgBox.clickedButton()];
983 QApplication::processEvents();