+#include <QMessageBox>
+#include <QPushButton>
+#include <QApplication>
+#include <QString>
+
+#include <stdarg.h>
+
+/*!
+ \class SUIT_MessageBox
+ \brief Message dialog box for SUIT-based application
+
+ The class provides a modal dialog with a short message, an icon,
+ and buttons laid out depending on the current style.
+
+ Message boxes are used to provide informative messages and to ask
+ simple questions.
+
+ The easiest way to pop up a message box is to call one of the static
+ functions information(), question(), critical(), and warning().
+
+ The class provides the static functions to show message boxes with
+ standard buttons (like \c Ok, \c Cancel, \c Apply, \c Close, \c Yes,
+ \c No, \c Abort, \c Retry, etc). These methods accept ORed buttons
+ flags as one of the parameters. The buttons layouting type and order
+ is system-dependant and defined by the current style. In addition,
+ these methods allow to define default button (where input focus is
+ set by default and which is clicked when user presses \c Enter key).
+
+ Another set of static functions allows to show message boxes with
+ up to four user-defined buttons. It is possible to define default
+ and escape buttons using additional parameters.
+
+ And finally, the last group of static functions allow displaying
+ the message boxes with an arbitrary number of buttons.
+
+ For example:
+ \code
+ // show question message box with two standard buttons
+ int result = SUIT_MessageBox::question(desktop(), "Error",
+ "File already exists? Overwrite?",
+ SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+ SUIT_MessageBox::No );
+ if ( result == SUIT_MessageBox::Yes )
+ overwriteFileFunction();
+
+ // show critical message box with user-defined buttons
+ // default is second button and escape is third button
+ int result = SUIT_MessageBox::critical(desktop(), "Hazard!",
+ "The situation is critical! What to do?",
+ "Hide", "Run Away", "Stand still", 1, 2);
+ switch ( result )
+ {
+ case 0:
+ hideMyself(); break;
+ case 1:
+ runAwayFromHere(); break;
+ case 2:
+ sitDownAndPray(); break;
+ default:
+ break;
+ }
+
+ // show message box with 6 buttons
+ // both default and escape buttons are set to first button ("Zero")
+ int result = SUIT_MessageBox::information(desktop(), "Question",
+ "Select your favourite number",
+ 0, 0,
+ "Zero", "One", "Two", "Three", "Four", "Five");
+ useMyFavouriteNumberSomewhere( result );
+ \endcode
+*/
+
+/*!
+ \brief Constructor.
+ \param parent parent widget
+*/
+SUIT_MessageBox::SUIT_MessageBox( QWidget* parent )
+: QMessageBox( parent )
+{
+}
+
+/*!
+ \brief Constructor.
+ \param icon message box icon (QMessageBox::Icon)
+ \param title message box title
+ \param text message box text
+ \param buttons ORed message box standard buttons (QMessageBox::StandardButton)
+ \param parent parent widget
+ \param f window flags
+*/
+SUIT_MessageBox::SUIT_MessageBox( Icon icon, const QString& title, const QString& text,
+ StandardButtons buttons, QWidget* parent, Qt::WindowFlags f )
+: QMessageBox( icon, title, text, buttons, parent, f )
+{
+}
+
+/*!
+ \brief Destructor.
+*/
+SUIT_MessageBox::~SUIT_MessageBox()
+{
+}
+
+/*!
+ \brief Get the standard button text.
+ \param btn standard button id
+ \return button text
+*/
+QString SUIT_MessageBox::buttonText( StandardButton btn ) const
+{
+ QString res;
+ QAbstractButton* b = button( btn );
+ if ( b )
+ res = b->text();
+ return res;
+}
+
+/*!
+ \brief Set the standard button text.
+ \param btn standard button id
+ \param text new button text
+*/
+void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text )
+{
+ QAbstractButton* b = button( btn );
+ if ( b )
+ b->setText( text );
+}
+
+/*!
+ \brief Show critical message box with specified standard buttons.
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param buttons ORed message box buttons (QMessageBox::StandardButton)
+ \param defaultButton default button (QMessageBox::StandardButton)
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton )
+{
+ SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
+ return QMessageBox::critical( parent, title, text, buttons, defaultButton );
+}
+
+/*!
+ \brief Show warning message box with specified standard buttons.
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param buttons ORed message box buttons (QMessageBox::StandardButton)
+ \param defaultButton default button (QMessageBox::StandardButton)
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
+ SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton )
+{
+ SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
+ return QMessageBox::warning( parent, title, text, buttons, defaultButton );
+}
+
+/*!
+ \brief Show information message box with specified standard buttons.
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param buttons ORed message box buttons (QMessageBox::StandardButton)
+ \param defaultButton default button (QMessageBox::StandardButton)
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton )
+{
+ SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
+ return QMessageBox::information( parent, title, text, buttons, defaultButton );
+}
+
+/*!
+ \brief Show question message box with specified standard buttons.
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param buttons ORed message box buttons (QMessageBox::StandardButton)
+ \param defaultButton default button (QMessageBox::StandardButton)
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
+ StandardButtons buttons, StandardButton defaultButton )
+{
+ SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor );
+ return QMessageBox::question( parent, title, text, buttons, defaultButton );
+}
+
+/*!
+ \brief Show critical message box with one custom button.
+
+ Specified button becomes "default" button and "escape" button, i.e.
+ pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
+ this button.
+
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param button button text
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
+ const QString& button )
+{
+ ButtonInfos lst;
+ lst.append( ButtonInfo( 0, button ) );
+ return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst );
+}
+
+/*!
+ \brief Show warning message box with one custom button.
+
+ Specified button becomes "default" button and "escape" button, i.e.
+ pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
+ this button.
+
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param button button text
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
+ const QString& button )
+{
+ ButtonInfos lst;
+ lst.append( ButtonInfo( 0, button ) );
+ return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst );
+}
+
+/*!
+ \brief Show information message box with one custom button.
+
+ Specified button becomes "default" button and "escape" button, i.e.
+ pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
+ this button.
+
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param button button text
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
+ const QString& button )
+{
+ ButtonInfos lst;
+ lst.append( ButtonInfo( 0, button ) );
+ return messageBox( SUIT_MessageBox::Information, parent, title, text, lst );
+}
+
+/*!
+ \brief Show question message box with one custom button.
+
+ \warning This function does not make a lot of sense because it provides
+ message box with only one button, i.e. it is impossible to give several
+ answers for the question (at least 'yes'/'no').
+ This function is implemented only for completeness.
+
+ Specified button becomes "default" button and "escape" button, i.e.
+ pressing \c Return or \c Enter and \c Escape keys is equivalent to clicking
+ this button.
+
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param button button text
+ \return button id clicked by the user (QMessageBox::StandardButton)
+*/
+int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
+ const QString& button )
+{
+ ButtonInfos lst;
+ lst.append( ButtonInfo( 0, button ) );
+ return messageBox( SUIT_MessageBox::Question, parent, title, text, lst );
+}
+
+/*!
+ \brief Show critical message box with two custom buttons.
+
+ Parameters \a button1 and \a button2 specify the buttons text.
+ The function returns clicked button id. The identifiers for the buttons
+ are assigned automatically. The first button is identified as 0, the
+ second one as 1.
+
+ The \a defaultButton parameter allows to specify the button which is assigned
+ for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
+ allows specifing the button which is assigned for \c Escape key.
+ If these parameters are not specified (-1 by default), the first button
+ is set as default button and the second one is defined as escape button.
+
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param button1 first button text
+ \param button2 second button text
+ \param defaultButton default button
+ \param escapeButton escape button
+ \return button used button id
+*/
+int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
+ const QString& button1, const QString& button2,
+ const int defaultButton, const int escapeButton )
+{
+ ButtonInfos lst;
+ int id = 0;
+ lst.append( ButtonInfo( id++, button1 ) );
+ lst.append( ButtonInfo( id++, button2 ) );
+ return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
+ defaultButton, escapeButton );
+}
+
+/*!
+ \brief Show warning message box with two custom buttons.
+
+ Parameters \a button1 and \a button2 specify the buttons text.
+ The function returns clicked button id. The identifiers for the buttons
+ are assigned automatically. The first button is identified as 0, the
+ second one as 1.
+
+ The \a defaultButton parameter allows to specify the button which is assigned
+ for the \c Return or \c Enter key. Similarly, \a escapeButton parameter
+ allows specifing the button which is assigned for \c Escape key.
+ If these parameters are not specified (-1 by default), the first button
+ is set as default button and the second one is defined as escape button.
+
+ \param parent parent widget
+ \param title message box title
+ \param text message box text
+ \param button1 first button text
+ \param button2 second button text
+ \param defaultButton default button
+ \param escapeButton escape button
+ \return button used button id
+*/
+int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
+ const QString& button1, const QString& button2,
+ const int defaultButton, const int escapeButton )
+{
+ ButtonInfos lst;
+ int id = 0;
+ lst.append( ButtonInfo( id++, button1 ) );
+ lst.append( ButtonInfo( id++, button2 ) );
+ return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
+ defaultButton, escapeButton );
+}