1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SUIT_MessageBox.h"
25 #include "SUIT_OverrideCursor.h"
27 #include <QMessageBox>
28 #include <QPushButton>
29 #include <QApplication>
35 \class SUIT_MessageBox
36 \brief Message dialog box for SUIT-based application
38 The class provides a modal dialog with a short message, an icon,
39 and buttons laid out depending on the current style.
41 Message boxes are used to provide informative messages and to ask
44 The easiest way to pop up a message box is to call one of the static
45 functions information(), question(), critical(), and warning().
47 The class provides the static functions to show message boxes with
48 standard buttons (like \c Ok, \c Cancel, \c Apply, \c Close, \c Yes,
49 \c No, \c Abort, \c Retry, etc). These methods accept ORed buttons
50 flags as one of the parameters. The buttons layouting type and order
51 is system-dependant and defined by the current style. In addition,
52 these methods allow to define default button (where input focus is
53 set by default and which is clicked when user presses \c Enter key).
55 Another set of static functions allows to show message boxes with
56 up to four user-defined buttons. It is possible to define default
57 and escape buttons using additional parameters.
59 And finally, the last group of static functions allow displaying
60 the message boxes with an arbitrary number of buttons.
64 // show question message box with two standard buttons
65 int result = SUIT_MessageBox::question(desktop(), "Error",
66 "File already exists? Overwrite?",
67 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
68 SUIT_MessageBox::No );
69 if ( result == SUIT_MessageBox::Yes )
70 overwriteFileFunction();
72 // show critical message box with user-defined buttons
73 // default is second button and escape is third button
74 int result = SUIT_MessageBox::critical(desktop(), "Hazard!",
75 "The situation is critical! What to do?",
76 "Hide", "Run Away", "Stand still", 1, 2);
82 runAwayFromHere(); break;
84 sitDownAndPray(); break;
89 // show message box with 6 buttons
90 // both default and escape buttons are set to first button ("Zero")
91 int result = SUIT_MessageBox::information(desktop(), "Question",
92 "Select your favourite number",
94 "Zero", "One", "Two", "Three", "Four", "Five");
95 useMyFavouriteNumberSomewhere( result );
101 \param parent parent widget
103 SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
104 : QMessageBox( parent )
110 \param icon message box icon (QMessageBox::Icon)
111 \param title message box title
112 \param text message box text
113 \param buttons ORed message box standard buttons (QMessageBox::StandardButton)
114 \param parent parent widget
115 \param f window flags
117 SUIT_MessageBox::SUIT_MessageBox( Icon icon, const QString& title, const QString& text,
118 StandardButtons buttons, QWidget* parent, Qt::WindowFlags f )
119 : QMessageBox( icon, title, text, buttons, parent, f )
126 SUIT_MessageBox::~SUIT_MessageBox()
131 \brief Get the standard button text.
132 \param btn standard button id
135 QString SUIT_MessageBox::buttonText( StandardButton btn ) const
138 QAbstractButton* b = button( btn );
145 \brief Set the standard button text.
146 \param btn standard button id
147 \param text new button text
149 void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
151 QAbstractButton* b = button( btn );
157 \brief Show critical message box with specified standard buttons.
158 \param parent parent widget
159 \param title message box title
160 \param text message box text
161 \param buttons ORed message box buttons (QMessageBox::StandardButton)
162 \param defaultButton default button (QMessageBox::StandardButton)
163 \return button id clicked by the user (QMessageBox::StandardButton)
165 SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
166 StandardButtons buttons, StandardButton defaultButton )
168 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
169 return QMessageBox::critical( parent, title, text, buttons, defaultButton );
173 \brief Show warning message box with specified standard buttons.
174 \param parent parent widget
175 \param title message box title
176 \param text message box text
177 \param buttons ORed message box buttons (QMessageBox::StandardButton)
178 \param defaultButton default button (QMessageBox::StandardButton)
179 \return button id clicked by the user (QMessageBox::StandardButton)
181 SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
182 SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
184 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
185 return QMessageBox::warning( parent, title, text, buttons, defaultButton );
189 \brief Show information message box with specified standard buttons.
190 \param parent parent widget
191 \param title message box title
192 \param text message box text
193 \param buttons ORed message box buttons (QMessageBox::StandardButton)
194 \param defaultButton default button (QMessageBox::StandardButton)
195 \return button id clicked by the user (QMessageBox::StandardButton)
197 SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
198 StandardButtons buttons, StandardButton defaultButton )
200 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
201 return QMessageBox::information( parent, title, text, buttons, defaultButton );
205 \brief Show question message box with specified standard buttons.
206 \param parent parent widget
207 \param title message box title
208 \param text message box text
209 \param buttons ORed message box buttons (QMessageBox::StandardButton)
210 \param defaultButton default button (QMessageBox::StandardButton)
211 \return button id clicked by the user (QMessageBox::StandardButton)
213 SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
214 StandardButtons buttons, StandardButton defaultButton )
216 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
217 return QMessageBox::question( parent, title, text, buttons, defaultButton );
221 \brief Show critical message box with one custom button.
223 Specified button becomes "default" button and "escape" button, i.e.
224 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
227 \param parent parent widget
228 \param title message box title
229 \param text message box text
230 \param button button text
231 \return button id clicked by the user (QMessageBox::StandardButton)
233 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
234 const QString& button )
237 lst.append( ButtonInfo( 0, button ) );
238 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst );
242 \brief Show warning message box with one custom button.
244 Specified button becomes "default" button and "escape" button, i.e.
245 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
248 \param parent parent widget
249 \param title message box title
250 \param text message box text
251 \param button button text
252 \return button id clicked by the user (QMessageBox::StandardButton)
254 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
255 const QString& button )
258 lst.append( ButtonInfo( 0, button ) );
259 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst );
263 \brief Show information message box with one custom button.
265 Specified button becomes "default" button and "escape" button, i.e.
266 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
269 \param parent parent widget
270 \param title message box title
271 \param text message box text
272 \param button button text
273 \return button id clicked by the user (QMessageBox::StandardButton)
275 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
276 const QString& button )
279 lst.append( ButtonInfo( 0, button ) );
280 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst );
284 \brief Show question message box with one custom button.
286 \warning This function does not make a lot of sense because it provides
287 message box with only one button, i.e. it is impossible to give several
288 answers for the question (at least 'yes'/'no').
289 This function is implemented only for completeness.
291 Specified button becomes "default" button and "escape" button, i.e.
292 pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
295 \param parent parent widget
296 \param title message box title
297 \param text message box text
298 \param button button text
299 \return button id clicked by the user (QMessageBox::StandardButton)
301 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
302 const QString& button )
305 lst.append( ButtonInfo( 0, button ) );
306 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst );
310 \brief Show critical message box with two custom buttons.
312 Parameters \a button1 and \a button2 specify the buttons text.
313 The function returns clicked button id. The identifiers for the buttons
314 are assigned automatically. The first button is identified as 0, the
317 The \a defaultButton parameter allows to specify the button which is assigned
318 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
319 allows specifing the button which is assigned for \c Escape key.
320 If these parameters are not specified (-1 by default), the first button
321 is set as default button and the second one is defined as escape button.
323 \param parent parent widget
324 \param title message box title
325 \param text message box text
326 \param button1 first button text
327 \param button2 second button text
328 \param defaultButton default button
329 \param escapeButton escape button
330 \return button used button id
332 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
333 const QString& button1, const QString& button2,
334 const int defaultButton, const int escapeButton )
338 lst.append( ButtonInfo( id++, button1 ) );
339 lst.append( ButtonInfo( id++, button2 ) );
340 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
341 defaultButton, escapeButton );
345 \brief Show warning message box with two custom buttons.
347 Parameters \a button1 and \a button2 specify the buttons text.
348 The function returns clicked button id. The identifiers for the buttons
349 are assigned automatically. The first button is identified as 0, the
352 The \a defaultButton parameter allows to specify the button which is assigned
353 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
354 allows specifing the button which is assigned for \c Escape key.
355 If these parameters are not specified (-1 by default), the first button
356 is set as default button and the second one is defined as escape button.
358 \param parent parent widget
359 \param title message box title
360 \param text message box text
361 \param button1 first button text
362 \param button2 second button text
363 \param defaultButton default button
364 \param escapeButton escape button
365 \return button used button id
367 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
368 const QString& button1, const QString& button2,
369 const int defaultButton, const int escapeButton )
373 lst.append( ButtonInfo( id++, button1 ) );
374 lst.append( ButtonInfo( id++, button2 ) );
375 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
376 defaultButton, escapeButton );
380 \brief Show information message box with two custom buttons.
382 Parameters \a button1 and \a button2 specify the buttons text.
383 The function returns clicked button id. The identifiers for the buttons
384 are assigned automatically. The first button is identified as 0, the
387 The \a defaultButton parameter allows to specify the button which is assigned
388 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
389 allows specifing the button which is assigned for \c Escape key.
390 If these parameters are not specified (-1 by default), the first button
391 is set as default button and the second one is defined as escape button.
393 \param parent parent widget
394 \param title message box title
395 \param text message box text
396 \param button1 first button text
397 \param button2 second button text
398 \param defaultButton default button
399 \param escapeButton escape button
400 \return button used button id
402 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
403 const QString& button1, const QString& button2,
404 const int defaultButton, const int escapeButton )
408 lst.append( ButtonInfo( id++, button1 ) );
409 lst.append( ButtonInfo( id++, button2 ) );
410 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
411 defaultButton, escapeButton );
415 \brief Show question message box with two custom buttons.
417 Parameters \a button1 and \a button2 specify the buttons text.
418 The function returns clicked button id. The identifiers for the buttons
419 are assigned automatically. The first button is identified as 0, the
422 The \a defaultButton parameter allows to specify the button which is assigned
423 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
424 allows specifing the button which is assigned for \c Escape key.
425 If these parameters are not specified (-1 by default), the first button
426 is set as default button and the second one is defined as escape button.
428 \param parent parent widget
429 \param title message box title
430 \param text message box text
431 \param button1 first button text
432 \param button2 second button text
433 \param defaultButton default button
434 \param escapeButton escape button
435 \return button used button id
437 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
438 const QString& button1, const QString& button2,
439 const int defaultButton, const int escapeButton )
443 lst.append( ButtonInfo( id++, button1 ) );
444 lst.append( ButtonInfo( id++, button2 ) );
445 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
446 defaultButton, escapeButton );
450 \brief Show critical message box with three custom buttons.
452 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
453 The function returns clicked button id. The identifiers for the buttons
454 are assigned automatically. The first button is identified as 0, the
455 second one as 1, etc.
457 The \a defaultButton parameter allows to specify the button which is assigned
458 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
459 allows specifing the button which is assigned for \c Escape key.
460 If these parameters are not specified (-1 by default), the first button
461 is set as default button and the last one is defined as escape button.
463 \param parent parent widget
464 \param title message box title
465 \param text message box text
466 \param button1 first button text
467 \param button2 second button text
468 \param button3 third button text
469 \param defaultButton default button
470 \param escapeButton escape button
471 \return button used button id
473 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
474 const QString& button1, const QString& button2,
475 const QString& button3,
476 const int defaultButton, const int escapeButton )
480 lst.append( ButtonInfo( id++, button1 ) );
481 lst.append( ButtonInfo( id++, button2 ) );
482 lst.append( ButtonInfo( id++, button3 ) );
483 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
484 defaultButton, escapeButton );
488 \brief Show warning message box with three custom buttons.
490 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
491 The function returns clicked button id. The identifiers for the buttons
492 are assigned automatically. The first button is identified as 0, the
493 second one as 1, etc.
495 The \a defaultButton parameter allows to specify the button which is assigned
496 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
497 allows specifing the button which is assigned for \c Escape key.
498 If these parameters are not specified (-1 by default), the first button
499 is set as default button and the last one is defined as escape button.
501 \param parent parent widget
502 \param title message box title
503 \param text message box text
504 \param button1 first button text
505 \param button2 second button text
506 \param button3 third button text
507 \param defaultButton default button
508 \param escapeButton escape button
509 \return button used button id
511 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
512 const QString& button1, const QString& button2,
513 const QString& button3,
514 const int defaultButton, const int escapeButton )
518 lst.append( ButtonInfo( id++, button1 ) );
519 lst.append( ButtonInfo( id++, button2 ) );
520 lst.append( ButtonInfo( id++, button3 ) );
521 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
522 defaultButton, escapeButton );
526 \brief Show information message box with three custom buttons.
528 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
529 The function returns clicked button id. The identifiers for the buttons
530 are assigned automatically. The first button is identified as 0, the
531 second one as 1, etc.
533 The \a defaultButton parameter allows to specify the button which is assigned
534 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
535 allows specifing the button which is assigned for \c Escape key.
536 If these parameters are not specified (-1 by default), the first button
537 is set as default button and the last one is defined as escape button.
539 \param parent parent widget
540 \param title message box title
541 \param text message box text
542 \param button1 first button text
543 \param button2 second button text
544 \param button3 third button text
545 \param defaultButton default button
546 \param escapeButton escape button
547 \return button used button id
549 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
550 const QString& button1, const QString& button2,
551 const QString& button3,
552 const int defaultButton, const int escapeButton )
556 lst.append( ButtonInfo( id++, button1 ) );
557 lst.append( ButtonInfo( id++, button2 ) );
558 lst.append( ButtonInfo( id++, button3 ) );
559 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
560 defaultButton, escapeButton );
564 \brief Show question message box with three custom buttons.
566 Parameters \a button1, \a button2 and \a button3 specify the buttons text.
567 The function returns clicked button id. The identifiers for the buttons
568 are assigned automatically. The first button is identified as 0, the
569 second one as 1, etc.
571 The \a defaultButton parameter allows to specify the button which is assigned
572 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
573 allows specifing the button which is assigned for \c Escape key.
574 If these parameters are not specified (-1 by default), the first button
575 is set as default button and the last one is defined as escape button.
577 \param parent parent widget
578 \param title message box title
579 \param text message box text
580 \param button1 first button text
581 \param button2 second button text
582 \param button3 third button text
583 \param defaultButton default button
584 \param escapeButton escape button
585 \return button used button id
587 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
588 const QString& button1, const QString& button2,
589 const QString& button3,
590 const int defaultButton, const int escapeButton )
594 lst.append( ButtonInfo( id++, button1 ) );
595 lst.append( ButtonInfo( id++, button2 ) );
596 lst.append( ButtonInfo( id++, button3 ) );
597 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
598 defaultButton, escapeButton );
602 \brief Show critical message box with four custom buttons.
604 Parameters \a button1, \a button2, \a button3 and \a button4 specify
606 The function returns clicked button id. The identifiers for the buttons
607 are assigned automatically. The first button is identified as 0, the
608 second one as 1, etc.
610 The \a defaultButton parameter allows to specify the button which is assigned
611 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
612 allows specifing the button which is assigned for \c Escape key.
613 If these parameters are not specified (-1 by default), the first button
614 is set as default button and the last one is defined as escape button.
616 \param parent parent widget
617 \param title message box title
618 \param text message box text
619 \param button1 first button text
620 \param button2 second button text
621 \param button3 third button text
622 \param button4 fourth button text
623 \param defaultButton default button
624 \param escapeButton escape button
625 \return button used button id
627 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
628 const QString& button1, const QString& button2,
629 const QString& button3, const QString& button4,
630 const int defaultButton, const int escapeButton )
634 lst.append( ButtonInfo( id++, button1 ) );
635 lst.append( ButtonInfo( id++, button2 ) );
636 lst.append( ButtonInfo( id++, button3 ) );
637 lst.append( ButtonInfo( id++, button4 ) );
638 return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
639 defaultButton, escapeButton );
643 \brief Show warning message box with four custom buttons.
645 Parameters \a button1, \a button2, \a button3 and \a button4 specify
647 The function returns clicked button id. The identifiers for the buttons
648 are assigned automatically. The first button is identified as 0, the
649 second one as 1, etc.
651 The \a defaultButton parameter allows to specify the button which is assigned
652 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
653 allows specifing the button which is assigned for \c Escape key.
654 If these parameters are not specified (-1 by default), the first button
655 is set as default button and the last one is defined as escape button.
657 \param parent parent widget
658 \param title message box title
659 \param text message box text
660 \param button1 first button text
661 \param button2 second button text
662 \param button3 third button text
663 \param button4 fourth button text
664 \param defaultButton default button
665 \param escapeButton escape button
666 \return button used button id
668 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
669 const QString& button1, const QString& button2,
670 const QString& button3, const QString& button4,
671 const int defaultButton, const int escapeButton )
675 lst.append( ButtonInfo( id++, button1 ) );
676 lst.append( ButtonInfo( id++, button2 ) );
677 lst.append( ButtonInfo( id++, button3 ) );
678 lst.append( ButtonInfo( id++, button4 ) );
679 return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
680 defaultButton, escapeButton );
684 \brief Show information message box with four custom buttons.
686 Parameters \a button1, \a button2, \a button3 and \a button4 specify
688 The function returns clicked button id. The identifiers for the buttons
689 are assigned automatically. The first button is identified as 0, the
690 second one as 1, etc.
692 The \a defaultButton parameter allows to specify the button which is assigned
693 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
694 allows specifing the button which is assigned for \c Escape key.
695 If these parameters are not specified (-1 by default), the first button
696 is set as default button and the last one is defined as escape button.
698 \param parent parent widget
699 \param title message box title
700 \param text message box text
701 \param button1 first button text
702 \param button2 second button text
703 \param button3 third button text
704 \param button4 fourth button text
705 \param defaultButton default button
706 \param escapeButton escape button
707 \return button used button id
709 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
710 const QString& button1, const QString& button2,
711 const QString& button3, const QString& button4,
712 const int defaultButton, const int escapeButton )
716 lst.append( ButtonInfo( id++, button1 ) );
717 lst.append( ButtonInfo( id++, button2 ) );
718 lst.append( ButtonInfo( id++, button3 ) );
719 lst.append( ButtonInfo( id++, button4 ) );
720 return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
721 defaultButton, escapeButton );
725 \brief Show question message box with four custom buttons.
727 Parameters \a button1, \a button2, \a button3 and \a button4 specify
729 The function returns clicked button id. The identifiers for the buttons
730 are assigned automatically. The first button is identified as 0, the
731 second one as 1, etc.
733 The \a defaultButton parameter allows to specify the button which is assigned
734 for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
735 allows specifing the button which is assigned for \c Escape key.
736 If these parameters are not specified (-1 by default), the first button
737 is set as default button and the last one is defined as escape button.
739 \param parent parent widget
740 \param title message box title
741 \param text message box text
742 \param button1 first button text
743 \param button2 second button text
744 \param button3 third button text
745 \param button4 fourth button text
746 \param defaultButton default button
747 \param escapeButton escape button
748 \return button used button id
750 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
751 const QString& button1, const QString& button2,
752 const QString& button3, const QString& button4,
753 const int defaultButton, const int escapeButton )
757 lst.append( ButtonInfo( id++, button1 ) );
758 lst.append( ButtonInfo( id++, button2 ) );
759 lst.append( ButtonInfo( id++, button3 ) );
760 lst.append( ButtonInfo( id++, button4 ) );
761 return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
762 defaultButton, escapeButton );
766 \brief Show critical message box with arbitrary number of user-specified
769 List of buttons to be shown is specified via \a buttons parameter.
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.
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.
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
789 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
790 const QStringList& buttons,
791 const int defaultButton, const int escapeButton )
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 );
802 \brief Show warning message box with arbitrary number of user-specified
805 List of buttons to be shown is specified via \a buttons parameter.
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.
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.
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
825 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
826 const QStringList& buttons,
827 const int defaultButton, const int escapeButton )
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 );
838 \brief Show information message box with arbitrary number of user-specified
841 List of buttons to be shown is specified via \a buttons parameter.
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.
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.
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
861 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
862 const QStringList& buttons,
863 const int defaultButton, const int escapeButton )
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 );
874 \brief Show question message box with arbitrary number of user-specified
877 List of buttons to be shown is specified via \a buttons parameter.
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.
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.
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
897 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
898 const QStringList& buttons,
899 const int defaultButton, const int escapeButton )
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 );
910 \brief Show critical message box with arbitrary number of user-specified
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
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.
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.
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
936 int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
937 const int defaultButton, const int escapeButton,
941 va_start( args, btn );
942 return messageBox( SUIT_MessageBox::Critical, parent, title, text,
943 messageList( btn, args ),
944 defaultButton, escapeButton );
948 \brief Show warning message box with arbitrary number of user-specified
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
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.
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.
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
974 int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
975 const int defaultButton, const int escapeButton,
979 va_start( args, btn );
980 return messageBox( SUIT_MessageBox::Warning, parent, title, text,
981 messageList( btn, args ),
982 defaultButton, escapeButton );
986 \brief Show information message box with arbitrary number of user-specified
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
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.
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.
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
1012 int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
1013 const int defaultButton, const int escapeButton,
1017 va_start( args, btn );
1018 return messageBox( SUIT_MessageBox::Information, parent, title, text,
1019 messageList( btn, args ),
1020 defaultButton, escapeButton );
1024 \brief Show question message box with arbitrary number of user-specified
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
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.
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.
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
1050 int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
1051 const int defaultButton, const int escapeButton,
1055 va_start( args, btn );
1056 return messageBox( SUIT_MessageBox::Question, parent, title, text,
1057 messageList( btn, args ),
1058 defaultButton, escapeButton );
1062 \brief Parse arbitrary arguments list.
1064 The last parameter in a sequence should be 0 (zero) value.
1066 \param txt first argument which starts arbitrary sequence
1067 \param args arguments list from the stack
1068 \return list of buttons infos
1070 SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args )
1077 lst.append( ButtonInfo( i++, cur ) );
1078 cur = va_arg( args, char* );
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
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 )
1103 SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
1105 QMap<QAbstractButton*, int> bm;
1106 for ( int i = 0; i < lst.count(); i++ )
1108 int btn = lst[i].id();
1109 QString txt = lst[i].text();
1110 ButtonRole role = lst[i].role();
1112 QPushButton* pb = msgBox.addButton( txt, role );
1113 bm.insert( pb, btn );
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 );
1121 SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
1123 int res = msgBox.exec();
1125 res = bm[msgBox.clickedButton()];
1127 QApplication::processEvents();