Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SUIT / SUIT_MessageBox.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "SUIT_MessageBox.h"
23
24 #include "SUIT_OverrideCursor.h"
25
26 #include <QMessageBox>
27 #include <QPushButton>
28 #include <QApplication>
29 #include <QString>
30
31 #include <stdarg.h>
32
33 /*!
34   \class SUIT_MessageBox
35   \brief Message dialog box for SUIT-based application
36
37   The class provides a modal dialog with a short message, an icon, 
38   and buttons laid out depending on the current style.
39   
40   Message boxes are used to provide informative messages and to ask 
41   simple questions.
42
43   The easiest way to pop up a message box is to call one of the static
44   functions information(), question(), critical(), and warning().
45
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).
53
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.
57
58   And finally, the last group of static functions allow displaying
59   the message boxes with an arbitrary number of buttons.
60
61   For example:
62   \code
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();
70
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);
76   switch ( result )
77   {
78   case 0:
79     hideMyself(); break;
80   case 1:
81     runAwayFromHere(); break;
82   case 2:
83     sitDownAndPray(); break;
84   default:
85     break;
86   }
87
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",
92                                             0, 0,
93                                             "Zero", "One", "Two", "Three", "Four", "Five");
94   useMyFavouriteNumberSomewhere( result );
95   \endcode
96 */
97
98 /*!
99   \brief Constructor.
100   \param parent parent widget
101 */
102 SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
103 : QMessageBox( parent )
104 {
105 }
106
107 /*!
108   \brief Constructor.
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
115 */
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 )
119 {
120 }
121
122 /*!
123   \brief Destructor.
124 */
125 SUIT_MessageBox::~SUIT_MessageBox()
126 {
127 }
128
129 /*!
130   \brief Get the standard button text.
131   \param btn standard button id
132   \return button text
133 */
134 QString SUIT_MessageBox::buttonText( StandardButton btn ) const
135 {
136   QString res;
137   QAbstractButton* b = button( btn );
138   if ( b )
139     res = b->text();
140   return res;
141 }
142
143 /*!
144   \brief Set the standard button text.
145   \param btn standard button id
146   \param text new button text
147 */
148 void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
149 {
150   QAbstractButton* b = button( btn );
151   if ( b )
152     b->setText( text );
153 }
154
155 /*!
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)
163 */
164 SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
165                                                            StandardButtons buttons, StandardButton defaultButton )
166 {
167   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
168   return QMessageBox::critical( parent, title, text, buttons, defaultButton );
169 }
170
171 /*!
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)
179 */
180 SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
181                                                           SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
182 {
183   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
184   return QMessageBox::warning( parent, title, text, buttons, defaultButton );
185 }
186
187 /*!
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)
195 */
196 SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
197                                                               StandardButtons buttons, StandardButton defaultButton )
198 {
199   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
200   return QMessageBox::information( parent, title, text, buttons, defaultButton );
201 }
202
203 /*!
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)
211 */
212 SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
213                                                            StandardButtons buttons, StandardButton defaultButton )
214 {
215   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
216   return QMessageBox::question( parent, title, text, buttons, defaultButton );
217 }
218
219 /*!
220   \brief Show critical message box with one custom button.
221
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
224   this button.
225
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)
231 */
232 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
233                                const QString& button )
234 {
235   ButtonInfos lst;
236   lst.append( ButtonInfo( 0, button ) );
237   return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst );
238 }
239
240 /*!
241   \brief Show warning message box with one custom button.
242   
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
245   this button.
246
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)
252 */
253 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
254                               const QString& button )
255 {
256   ButtonInfos lst;
257   lst.append( ButtonInfo( 0, button ) );
258   return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst );
259 }
260
261 /*!
262   \brief Show information message box with one custom button.
263
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
266   this button.
267
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)
273 */
274 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
275                                   const QString& button )
276 {
277   ButtonInfos lst;
278   lst.append( ButtonInfo( 0, button ) );
279   return messageBox( SUIT_MessageBox::Information, parent, title, text, lst );
280 }
281
282 /*!
283   \brief Show question message box with one custom button.
284
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.
289
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
292   this button.
293
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)
299 */
300 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
301                                const QString& button )
302 {
303   ButtonInfos lst;
304   lst.append( ButtonInfo( 0, button ) );
305   return messageBox( SUIT_MessageBox::Question, parent, title, text, lst );
306 }
307
308 /*!
309   \brief Show critical message box with two custom buttons.
310
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
314   second one as 1.
315
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.
321
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
330 */
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 )
334 {
335   ButtonInfos lst;
336   int id = 0;
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 );
341 }
342
343 /*!
344   \brief Show warning message box with two custom buttons.
345
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
349   second one as 1.
350
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.
356
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
365 */
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 )
369 {
370   ButtonInfos lst;
371   int id = 0;
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 );
376 }
377
378 /*!
379   \brief Show information message box with two custom buttons.
380
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
384   second one as 1.
385
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.
391
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
400 */
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 )
404 {
405   ButtonInfos lst;
406   int id = 0;
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 );
411 }
412
413 /*!
414   \brief Show question message box with two custom buttons.
415
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
419   second one as 1.
420
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.
426
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
435 */
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 )
439 {
440   ButtonInfos lst;
441   int id = 0;
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 );
446 }
447
448 /*!
449   \brief Show critical message box with three custom buttons.
450
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.
455
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.
461
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
471 */
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 )
476 {
477   ButtonInfos lst;
478   int id = 0;
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 );
484 }
485
486 /*!
487   \brief Show warning message box with three custom buttons.
488
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.
493
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.
499
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
509 */
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 )
514 {
515   ButtonInfos lst;
516   int id = 0;
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 );
522 }
523
524 /*!
525   \brief Show information message box with three custom buttons.
526
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.
531
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.
537
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
547 */
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 )
552 {
553   ButtonInfos lst;
554   int id = 0;
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 );
560 }
561
562 /*!
563   \brief Show question message box with three custom buttons.
564
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.
569
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.
575
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
585 */
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 )
590 {
591   ButtonInfos lst;
592   int id = 0;
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 );
598 }
599
600 /*!
601   \brief Show critical message box with four custom buttons.
602
603   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
604   the buttons text.
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.
608
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.
614
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
625 */
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 )
630 {
631   ButtonInfos lst;
632   int id = 0;
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 );
639 }
640
641 /*!
642   \brief Show warning message box with four custom buttons.
643
644   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
645   the buttons text.
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.
649
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.
655
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
666 */
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 )
671 {
672   ButtonInfos lst;
673   int id = 0;
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 );
680 }
681
682 /*!
683   \brief Show information message box with four custom buttons.
684
685   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
686   the buttons text.
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.
690
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.
696
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
707 */
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 )
712 {
713   ButtonInfos lst;
714   int id = 0;
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 );
721 }
722
723 /*!
724   \brief Show question message box with four custom buttons.
725
726   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
727   the buttons text.
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.
731
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.
737
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
748 */
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 )
753 {
754   ButtonInfos lst;
755   int id = 0;
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 );
762 }
763
764 /*!
765   \brief Show critical message box with arbitrary number of user-specified
766          buttons.
767
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 
771   specified.
772   
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.
776
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.
782
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
790 */
791 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, 
792                                const int defaultButton, const int escapeButton, 
793                                char* btn, ... )
794 {
795   va_list args;
796   va_start( args, btn );
797   return messageBox( SUIT_MessageBox::Critical, parent, title, text,
798                      messageList( btn, args ),
799                      defaultButton, escapeButton );
800 }
801
802 /*!
803   \brief Show warning message box with arbitrary number of user-specified
804          buttons.
805
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 
809   specified.
810   
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.
814
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.
820
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
828 */
829 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, 
830                               const int defaultButton, const int escapeButton, 
831                               char* btn, ... )
832 {
833   va_list args;
834   va_start( args, btn );
835   return messageBox( SUIT_MessageBox::Warning, parent, title, text,
836                      messageList( btn, args ),
837                      defaultButton, escapeButton );
838 }
839
840 /*!
841   \brief Show information message box with arbitrary number of user-specified
842          buttons.
843
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 
847   specified.
848   
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.
852
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.
858
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
866 */
867 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, 
868                                   const int defaultButton, const int escapeButton, 
869                                   char* btn, ... )
870 {
871   va_list args;
872   va_start( args, btn );
873   return messageBox( SUIT_MessageBox::Information, parent, title, text,
874                      messageList( btn, args ),
875                      defaultButton, escapeButton );
876 }
877
878 /*!
879   \brief Show question message box with arbitrary number of user-specified
880          buttons.
881
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 
885   specified.
886   
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.
890
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.
896
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
904 */
905 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, 
906                                const int defaultButton, const int escapeButton, 
907                                char* btn, ... )
908 {
909   va_list args;
910   va_start( args, btn );
911   return messageBox( SUIT_MessageBox::Question, parent, title, text,
912                      messageList( btn, args ),
913                      defaultButton, escapeButton );
914 }
915
916 /*!
917   \brief Parse arbitrary arguments list.
918
919   The last parameter in a sequence should be 0 (zero) value.
920
921   \param txt first argument which starts arbitrary sequence
922   \param args arguments list from the stack
923   \return list of buttons infos
924 */
925 SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args )
926 {
927   int i = 0;
928   ButtonInfos lst;
929   char* cur = txt;
930   while ( cur )
931   {
932     lst.append( ButtonInfo( i++, cur ) );
933     cur = va_arg( args, char* );
934   }
935
936   va_end( args );
937
938   return lst;
939 }
940
941 /*!
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
951 */
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 )
957 {
958   SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
959
960   QMap<QAbstractButton*, int> bm;
961   for ( int i = 0; i < lst.count(); i++ )
962   {
963     int btn         = lst[i].id();
964     QString txt     = lst[i].text();
965     ButtonRole role = lst[i].role();
966
967     QPushButton* pb = msgBox.addButton( txt, role );
968     bm.insert( pb, btn );
969
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 );
974   }
975     
976   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
977
978   int res = msgBox.exec();
979   if ( res != -1 )
980     res = bm[msgBox.clickedButton()];
981
982   QApplication::processEvents();
983
984   return res;
985 }
986