Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / SUIT / SUIT_MessageBox.cxx
1 // Copyright (C) 2007-2012  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
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   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 
772   specified.
773   
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.
777
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.
783
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
791 */
792 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, 
793                                const int defaultButton, const int escapeButton, 
794                                char* btn, ... )
795 {
796   va_list args;
797   va_start( args, btn );
798   return messageBox( SUIT_MessageBox::Critical, parent, title, text,
799                      messageList( btn, args ),
800                      defaultButton, escapeButton );
801 }
802
803 /*!
804   \brief Show warning message box with arbitrary number of user-specified
805          buttons.
806
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 
810   specified.
811   
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.
815
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.
821
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
829 */
830 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, 
831                               const int defaultButton, const int escapeButton, 
832                               char* btn, ... )
833 {
834   va_list args;
835   va_start( args, btn );
836   return messageBox( SUIT_MessageBox::Warning, parent, title, text,
837                      messageList( btn, args ),
838                      defaultButton, escapeButton );
839 }
840
841 /*!
842   \brief Show information message box with arbitrary number of user-specified
843          buttons.
844
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 
848   specified.
849   
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.
853
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.
859
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
867 */
868 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, 
869                                   const int defaultButton, const int escapeButton, 
870                                   char* btn, ... )
871 {
872   va_list args;
873   va_start( args, btn );
874   return messageBox( SUIT_MessageBox::Information, parent, title, text,
875                      messageList( btn, args ),
876                      defaultButton, escapeButton );
877 }
878
879 /*!
880   \brief Show question message box with arbitrary number of user-specified
881          buttons.
882
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 
886   specified.
887   
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.
891
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.
897
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
905 */
906 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, 
907                                const int defaultButton, const int escapeButton, 
908                                char* btn, ... )
909 {
910   va_list args;
911   va_start( args, btn );
912   return messageBox( SUIT_MessageBox::Question, parent, title, text,
913                      messageList( btn, args ),
914                      defaultButton, escapeButton );
915 }
916
917 /*!
918   \brief Parse arbitrary arguments list.
919
920   The last parameter in a sequence should be 0 (zero) value.
921
922   \param txt first argument which starts arbitrary sequence
923   \param args arguments list from the stack
924   \return list of buttons infos
925 */
926 SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args )
927 {
928   int i = 0;
929   ButtonInfos lst;
930   char* cur = txt;
931   while ( cur )
932   {
933     lst.append( ButtonInfo( i++, cur ) );
934     cur = va_arg( args, char* );
935   }
936
937   va_end( args );
938
939   return lst;
940 }
941
942 /*!
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
952 */
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 )
958 {
959   SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
960
961   QMap<QAbstractButton*, int> bm;
962   for ( int i = 0; i < lst.count(); i++ )
963   {
964     int btn         = lst[i].id();
965     QString txt     = lst[i].text();
966     ButtonRole role = lst[i].role();
967
968     QPushButton* pb = msgBox.addButton( txt, role );
969     bm.insert( pb, btn );
970
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 );
975   }
976     
977   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
978
979   int res = msgBox.exec();
980   if ( res != -1 )
981     res = bm[msgBox.clickedButton()];
982
983   QApplication::processEvents();
984
985   return res;
986 }
987