Salome HOME
b8712d706daac91e6a635730b049e452cdfabc3a
[modules/gui.git] / src / SUIT / SUIT_MessageBox.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
23 #include "SUIT_MessageBox.h"
24
25 #include "SUIT_OverrideCursor.h"
26
27 #include <QMessageBox>
28 #include <QPushButton>
29 #include <QApplication>
30 #include <QString>
31
32 #include <stdarg.h>
33
34 /*!
35   \class SUIT_MessageBox
36   \brief Message dialog box for SUIT-based application
37
38   The class provides a modal dialog with a short message, an icon, 
39   and buttons laid out depending on the current style.
40   
41   Message boxes are used to provide informative messages and to ask 
42   simple questions.
43
44   The easiest way to pop up a message box is to call one of the static
45   functions information(), question(), critical(), and warning().
46
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).
54
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.
58
59   And finally, the last group of static functions allow displaying
60   the message boxes with an arbitrary number of buttons.
61
62   For example:
63   \code
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();
71
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);
77   switch ( result )
78   {
79   case 0:
80     hideMyself(); break;
81   case 1:
82     runAwayFromHere(); break;
83   case 2:
84     sitDownAndPray(); break;
85   default:
86     break;
87   }
88
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",
93                                             0, 0,
94                                             "Zero", "One", "Two", "Three", "Four", "Five");
95   useMyFavouriteNumberSomewhere( result );
96   \endcode
97 */
98
99 /*!
100   \brief Constructor.
101   \param parent parent widget
102 */
103 SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
104 : QMessageBox( parent )
105 {
106 }
107
108 /*!
109   \brief Constructor.
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
116 */
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 )
120 {
121 }
122
123 /*!
124   \brief Destructor.
125 */
126 SUIT_MessageBox::~SUIT_MessageBox()
127 {
128 }
129
130 /*!
131   \brief Get the standard button text.
132   \param btn standard button id
133   \return button text
134 */
135 QString SUIT_MessageBox::buttonText( StandardButton btn ) const
136 {
137   QString res;
138   QAbstractButton* b = button( btn );
139   if ( b )
140     res = b->text();
141   return res;
142 }
143
144 /*!
145   \brief Set the standard button text.
146   \param btn standard button id
147   \param text new button text
148 */
149 void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
150 {
151   QAbstractButton* b = button( btn );
152   if ( b )
153     b->setText( text );
154 }
155
156 /*!
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)
164 */
165 SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
166                                                            StandardButtons buttons, StandardButton defaultButton )
167 {
168   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
169   return QMessageBox::critical( parent, title, text, buttons, defaultButton );
170 }
171
172 /*!
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)
180 */
181 SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
182                                                           SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
183 {
184   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
185   return QMessageBox::warning( parent, title, text, buttons, defaultButton );
186 }
187
188 /*!
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)
196 */
197 SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
198                                                               StandardButtons buttons, StandardButton defaultButton )
199 {
200   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
201   return QMessageBox::information( parent, title, text, buttons, defaultButton );
202 }
203
204 /*!
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)
212 */
213 SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
214                                                            StandardButtons buttons, StandardButton defaultButton )
215 {
216   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
217   return QMessageBox::question( parent, title, text, buttons, defaultButton );
218 }
219
220 /*!
221   \brief Show critical message box with one custom button.
222
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
225   this button.
226
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)
232 */
233 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
234                                const QString& button )
235 {
236   ButtonInfos lst;
237   lst.append( ButtonInfo( 0, button ) );
238   return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst );
239 }
240
241 /*!
242   \brief Show warning message box with one custom button.
243   
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
246   this button.
247
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)
253 */
254 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
255                               const QString& button )
256 {
257   ButtonInfos lst;
258   lst.append( ButtonInfo( 0, button ) );
259   return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst );
260 }
261
262 /*!
263   \brief Show information message box with one custom button.
264
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
267   this button.
268
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)
274 */
275 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
276                                   const QString& button )
277 {
278   ButtonInfos lst;
279   lst.append( ButtonInfo( 0, button ) );
280   return messageBox( SUIT_MessageBox::Information, parent, title, text, lst );
281 }
282
283 /*!
284   \brief Show question message box with one custom button.
285
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.
290
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
293   this button.
294
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)
300 */
301 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
302                                const QString& button )
303 {
304   ButtonInfos lst;
305   lst.append( ButtonInfo( 0, button ) );
306   return messageBox( SUIT_MessageBox::Question, parent, title, text, lst );
307 }
308
309 /*!
310   \brief Show critical message box with two custom buttons.
311
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
315   second one as 1.
316
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.
322
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
331 */
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 )
335 {
336   ButtonInfos lst;
337   int id = 0;
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 );
342 }
343
344 /*!
345   \brief Show warning message box with two custom buttons.
346
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
350   second one as 1.
351
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.
357
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
366 */
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 )
370 {
371   ButtonInfos lst;
372   int id = 0;
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 );
377 }
378
379 /*!
380   \brief Show information message box with two custom buttons.
381
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
385   second one as 1.
386
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.
392
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
401 */
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 )
405 {
406   ButtonInfos lst;
407   int id = 0;
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 );
412 }
413
414 /*!
415   \brief Show question message box with two custom buttons.
416
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
420   second one as 1.
421
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.
427
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
436 */
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 )
440 {
441   ButtonInfos lst;
442   int id = 0;
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 );
447 }
448
449 /*!
450   \brief Show critical message box with three custom buttons.
451
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.
456
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.
462
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
472 */
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 )
477 {
478   ButtonInfos lst;
479   int id = 0;
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 );
485 }
486
487 /*!
488   \brief Show warning message box with three custom buttons.
489
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.
494
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.
500
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
510 */
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 )
515 {
516   ButtonInfos lst;
517   int id = 0;
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 );
523 }
524
525 /*!
526   \brief Show information message box with three custom buttons.
527
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.
532
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.
538
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
548 */
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 )
553 {
554   ButtonInfos lst;
555   int id = 0;
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 );
561 }
562
563 /*!
564   \brief Show question message box with three custom buttons.
565
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.
570
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.
576
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
586 */
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 )
591 {
592   ButtonInfos lst;
593   int id = 0;
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 );
599 }
600
601 /*!
602   \brief Show critical message box with four custom buttons.
603
604   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
605   the buttons text.
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.
609
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.
615
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
626 */
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 )
631 {
632   ButtonInfos lst;
633   int id = 0;
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 );
640 }
641
642 /*!
643   \brief Show warning message box with four custom buttons.
644
645   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
646   the buttons text.
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.
650
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.
656
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
667 */
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 )
672 {
673   ButtonInfos lst;
674   int id = 0;
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 );
681 }
682
683 /*!
684   \brief Show information message box with four custom buttons.
685
686   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
687   the buttons text.
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.
691
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.
697
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
708 */
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 )
713 {
714   ButtonInfos lst;
715   int id = 0;
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 );
722 }
723
724 /*!
725   \brief Show question message box with four custom buttons.
726
727   Parameters \a button1, \a button2, \a button3 and \a button4 specify 
728   the buttons text.
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.
732
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.
738
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
749 */
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 )
754 {
755   ButtonInfos lst;
756   int id = 0;
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 );
763 }
764
765 /*!
766   \brief Show critical message box with arbitrary number of user-specified
767          buttons.
768
769   List of buttons to be shown is specified via \a buttons parameter.
770   
771   The function returns clicked button id. The identifiers for the buttons
772   are assigned automatically. The first button is identified as 0, the
773   second one as 1, etc.
774
775   The \a defaultButton parameter allows to specify the button which is assigned
776   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
777   allows specifing the button which is assigned for \c Escape key.
778   If these parameters are not specified (-1 by default), the first button
779   is set as default button and the last one is defined as escape button.
780
781   \param parent parent widget
782   \param title message box title
783   \param text message box text
784   \param defaultButton default button
785   \param escapeButton escape button
786   \param buttons list of buttons to be shown
787   \return button used button id
788 */
789 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
790                                const QStringList& buttons,
791                                const int defaultButton, const int escapeButton )
792 {
793   ButtonInfos lst;
794   int id = 0;
795   Q_FOREACH( QString button, buttons )
796     lst.append( ButtonInfo( id++, button ) );
797   return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
798                      defaultButton, escapeButton );
799 }
800
801 /*!
802   \brief Show warning message box with arbitrary number of user-specified
803          buttons.
804
805   List of buttons to be shown is specified via \a buttons parameter.
806   
807   The function returns clicked button id. The identifiers for the buttons
808   are assigned automatically. The first button is identified as 0, the
809   second one as 1, etc.
810
811   The \a defaultButton parameter allows to specify the button which is assigned
812   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
813   allows specifing the button which is assigned for \c Escape key.
814   If these parameters are not specified (-1 by default), the first button
815   is set as default button and the last one is defined as escape button.
816
817   \param parent parent widget
818   \param title message box title
819   \param text message box text
820   \param defaultButton default button
821   \param escapeButton escape button
822   \param buttons list of buttons to be shown
823   \return button used button id
824 */
825 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
826                               const QStringList& buttons,
827                               const int defaultButton, const int escapeButton )
828 {
829   ButtonInfos lst;
830   int id = 0;
831   Q_FOREACH( QString button, buttons )
832     lst.append( ButtonInfo( id++, button ) );
833   return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
834                      defaultButton, escapeButton );
835 }
836
837 /*!
838   \brief Show information message box with arbitrary number of user-specified
839          buttons.
840
841   List of buttons to be shown is specified via \a buttons parameter.
842   
843   The function returns clicked button id. The identifiers for the buttons
844   are assigned automatically. The first button is identified as 0, the
845   second one as 1, etc.
846
847   The \a defaultButton parameter allows to specify the button which is assigned
848   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
849   allows specifing the button which is assigned for \c Escape key.
850   If these parameters are not specified (-1 by default), the first button
851   is set as default button and the last one is defined as escape button.
852
853   \param parent parent widget
854   \param title message box title
855   \param text message box text
856   \param defaultButton default button
857   \param escapeButton escape button
858   \param buttons list of buttons to be shown
859   \return button used button id
860 */
861 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
862                                   const QStringList& buttons,
863                                   const int defaultButton, const int escapeButton )
864 {
865   ButtonInfos lst;
866   int id = 0;
867   Q_FOREACH( QString button, buttons )
868     lst.append( ButtonInfo( id++, button ) );
869   return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
870                      defaultButton, escapeButton );
871 }
872
873 /*!
874   \brief Show question message box with arbitrary number of user-specified
875          buttons.
876
877   List of buttons to be shown is specified via \a buttons parameter.
878   
879   The function returns clicked button id. The identifiers for the buttons
880   are assigned automatically. The first button is identified as 0, the
881   second one as 1, etc.
882
883   The \a defaultButton parameter allows to specify the button which is assigned
884   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
885   allows specifing the button which is assigned for \c Escape key.
886   If these parameters are not specified (-1 by default), the first button
887   is set as default button and the last one is defined as escape button.
888
889   \param parent parent widget
890   \param title message box title
891   \param text message box text
892   \param defaultButton default button
893   \param escapeButton escape button
894   \param buttons list of buttons to be shown
895   \return button used button id
896 */
897 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
898                                const QStringList& buttons,
899                                const int defaultButton, const int escapeButton )
900 {
901   ButtonInfos lst;
902   int id = 0;
903   Q_FOREACH( QString button, buttons )
904     lst.append( ButtonInfo( id++, button ) );
905   return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
906                      defaultButton, escapeButton );
907 }
908
909 /*!
910   \brief Show critical message box with arbitrary number of user-specified
911          buttons.
912
913   The function accepts arbitrary number of parameters. Each parameter starting
914   from \a btn should be of type const char* to specify the button text.
915   After the last button parameter and additional 0 (zero) value should be 
916   specified.
917   
918   The function returns clicked button id. The identifiers for the buttons
919   are assigned automatically. The first button is identified as 0, the
920   second one as 1, etc.
921
922   The \a defaultButton parameter allows to specify the button which is assigned
923   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
924   allows specifing the button which is assigned for \c Escape key.
925   If these parameters are not specified (-1 by default), the first button
926   is set as default button and the last one is defined as escape button.
927
928   \param parent parent widget
929   \param title message box title
930   \param text message box text
931   \param defaultButton default button
932   \param escapeButton escape button
933   \param btn first button text
934   \return button used button id
935 */
936 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, 
937                                const int defaultButton, const int escapeButton, 
938                                char* btn, ... )
939 {
940   va_list args;
941   va_start( args, btn );
942   return messageBox( SUIT_MessageBox::Critical, parent, title, text,
943                      messageList( btn, args ),
944                      defaultButton, escapeButton );
945 }
946
947 /*!
948   \brief Show warning message box with arbitrary number of user-specified
949          buttons.
950
951   The function accepts arbitrary number of parameters. Each parameter starting
952   from \a btn should be of type const char* to specify the button text.
953   After the last button parameter and additional 0 (zero) value should be 
954   specified.
955   
956   The function returns clicked button id. The identifiers for the buttons
957   are assigned automatically. The first button is identified as 0, the
958   second one as 1, etc.
959
960   The \a defaultButton parameter allows to specify the button which is assigned
961   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
962   allows specifing the button which is assigned for \c Escape key.
963   If these parameters are not specified (-1 by default), the first button
964   is set as default button and the last one is defined as escape button.
965
966   \param parent parent widget
967   \param title message box title
968   \param text message box text
969   \param defaultButton default button
970   \param escapeButton escape button
971   \param btn first button text
972   \return button used button id
973 */
974 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, 
975                               const int defaultButton, const int escapeButton, 
976                               char* btn, ... )
977 {
978   va_list args;
979   va_start( args, btn );
980   return messageBox( SUIT_MessageBox::Warning, parent, title, text,
981                      messageList( btn, args ),
982                      defaultButton, escapeButton );
983 }
984
985 /*!
986   \brief Show information message box with arbitrary number of user-specified
987          buttons.
988
989   The function accepts arbitrary number of parameters. Each parameter starting
990   from \a btn should be of type const char* to specify the button text.
991   After the last button parameter and additional 0 (zero) value should be 
992   specified.
993   
994   The function returns clicked button id. The identifiers for the buttons
995   are assigned automatically. The first button is identified as 0, the
996   second one as 1, etc.
997
998   The \a defaultButton parameter allows to specify the button which is assigned
999   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
1000   allows specifing the button which is assigned for \c Escape key.
1001   If these parameters are not specified (-1 by default), the first button
1002   is set as default button and the last one is defined as escape button.
1003
1004   \param parent parent widget
1005   \param title message box title
1006   \param text message box text
1007   \param defaultButton default button
1008   \param escapeButton escape button
1009   \param btn first button text
1010   \return button used button id
1011 */
1012 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, 
1013                                   const int defaultButton, const int escapeButton, 
1014                                   char* btn, ... )
1015 {
1016   va_list args;
1017   va_start( args, btn );
1018   return messageBox( SUIT_MessageBox::Information, parent, title, text,
1019                      messageList( btn, args ),
1020                      defaultButton, escapeButton );
1021 }
1022
1023 /*!
1024   \brief Show question message box with arbitrary number of user-specified
1025          buttons.
1026
1027   The function accepts arbitrary number of parameters. Each parameter starting
1028   from \a btn should be of type const char* to specify the button text.
1029   After the last button parameter and additional 0 (zero) value should be 
1030   specified.
1031   
1032   The function returns clicked button id. The identifiers for the buttons
1033   are assigned automatically. The first button is identified as 0, the
1034   second one as 1, etc.
1035
1036   The \a defaultButton parameter allows to specify the button which is assigned
1037   for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
1038   allows specifing the button which is assigned for \c Escape key.
1039   If these parameters are not specified (-1 by default), the first button
1040   is set as default button and the last one is defined as escape button.
1041
1042   \param parent parent widget
1043   \param title message box title
1044   \param text message box text
1045   \param defaultButton default button
1046   \param escapeButton escape button
1047   \param btn first button text
1048   \return button used button id
1049 */
1050 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, 
1051                                const int defaultButton, const int escapeButton, 
1052                                char* btn, ... )
1053 {
1054   va_list args;
1055   va_start( args, btn );
1056   return messageBox( SUIT_MessageBox::Question, parent, title, text,
1057                      messageList( btn, args ),
1058                      defaultButton, escapeButton );
1059 }
1060
1061 /*!
1062   \brief Parse arbitrary arguments list.
1063
1064   The last parameter in a sequence should be 0 (zero) value.
1065
1066   \param txt first argument which starts arbitrary sequence
1067   \param args arguments list from the stack
1068   \return list of buttons infos
1069 */
1070 SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args )
1071 {
1072   int i = 0;
1073   ButtonInfos lst;
1074   char* cur = txt;
1075   while ( cur )
1076   {
1077     lst.append( ButtonInfo( i++, cur ) );
1078     cur = va_arg( args, char* );
1079   }
1080
1081   va_end( args );
1082
1083   return lst;
1084 }
1085
1086 /*!
1087   \brief Create and show the message box.
1088   \param icon icon type
1089   \param parent parent widget
1090   \param title message box title
1091   \param text message box text
1092   \param lst list of buttons infos
1093   \param defaultButton default button
1094   \param escapeButton escape button
1095   \return button used button id
1096 */
1097 int SUIT_MessageBox::messageBox( Icon icon, QWidget* parent, 
1098                                  const QString& title, const QString& text, 
1099                                  const ButtonInfos& lst, 
1100                                  const int defaultButton, 
1101                                  const int escapeButton )
1102 {
1103   SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
1104
1105   QMap<QAbstractButton*, int> bm;
1106   for ( int i = 0; i < lst.count(); i++ )
1107   {
1108     int btn         = lst[i].id();
1109     QString txt     = lst[i].text();
1110     ButtonRole role = lst[i].role();
1111
1112     QPushButton* pb = msgBox.addButton( txt, role );
1113     bm.insert( pb, btn );
1114
1115     if ( ( defaultButton == -1 && i == 0 ) || btn == defaultButton )
1116       msgBox.setDefaultButton( pb );
1117     if ( ( escapeButton == -1 && i == lst.count() - 1 ) || btn == escapeButton )
1118       msgBox.setEscapeButton( pb );
1119   }
1120     
1121   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
1122
1123   int res = msgBox.exec();
1124   if ( res != -1 )
1125     res = bm[msgBox.clickedButton()];
1126
1127   QApplication::processEvents();
1128
1129   return res;
1130 }
1131