X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUIT%2FSUIT_MessageBox.cxx;h=43437b5258197a1cafce2a91e3ba6c6d0a0f2145;hb=efe3cdefadc31ad9cdaa9fd7fc368e2931cebdf1;hp=1d4d03cada3d6d54a1577c9204b36b312349c0b6;hpb=9b90197d4313ed2f2ac58f731e8bcb8a0b8698fc;p=modules%2Fgui.git diff --git a/src/SUIT/SUIT_MessageBox.cxx b/src/SUIT/SUIT_MessageBox.cxx index 1d4d03cad..43437b525 100755 --- a/src/SUIT/SUIT_MessageBox.cxx +++ b/src/SUIT/SUIT_MessageBox.cxx @@ -1,349 +1,1131 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -/******************************************************************** -** Class: SUIT_MessageBox -** Descr: Message dialog box for SUIT-based application -** Module: SUIT -** Created: UI team, 02.10.00 -*********************************************************************/ #include "SUIT_MessageBox.h" + #include "SUIT_OverrideCursor.h" -#include -#include +#include +#include +#include +#include + +#include /*! - Shows info message box with one button [ static ] + \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 */ -int SUIT_MessageBox::info1( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0 ) + +/*! + \brief Constructor. + \param parent parent widget +*/ +SUIT_MessageBox::SUIT_MessageBox( QWidget* parent ) +: QMessageBox( parent ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); - int ret = QMessageBox::information( parent, caption, text, textButton0, - QString::null, QString::null, 0, 0 ); - qApp->processEvents(); - return ret; } /*! - Shows warning message box with one button [ static ] + \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 */ -int SUIT_MessageBox::warn1( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0 ) +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 ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); - int ret = QMessageBox::warning( parent, caption, text, textButton0, - QString::null, QString::null, 0, 0 ); - qApp->processEvents(); - return ret; } /*! - Shows error message box with one button [ static ] + \brief Destructor. */ -int SUIT_MessageBox::error1( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0 ) +SUIT_MessageBox::~SUIT_MessageBox() { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); - int ret = QMessageBox::critical( parent, caption, text, textButton0, - QString::null, QString::null, 0, 0 ); - qApp->processEvents(); - return ret; } /*! - Shows question message box with one button [ static ] + \brief Get the standard button text. + \param btn standard button id + \return button text */ -int SUIT_MessageBox::question1( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0 ) +QString SUIT_MessageBox::buttonText( StandardButton btn ) const { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); - int ret = QMessageBox::question( parent, caption, text, textButton0, - QString::null, QString::null, 0, 0 ); - qApp->processEvents(); - return ret; + QString res; + QAbstractButton* b = button( btn ); + if ( b ) + res = b->text(); + return res; } /*! - Shows info message box with two buttons. - Returns id of the pressed button or -1 if escaped [ static ] + \brief Set the standard button text. + \param btn standard button id + \param text new button text */ -int SUIT_MessageBox::info2( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - int idButton0, int idButton1, int idDefault ) +void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else - idDefault = 0; - - int ret = QMessageBox::information( parent, caption, text, textButton0, - textButton1, QString::null, idDefault ); - qApp->processEvents(); - return ( ret == 0 ? idButton0 : idButton1 ); + QAbstractButton* b = button( btn ); + if ( b ) + b->setText( text ); } /*! - Shows warning message box with two buttons. - Returns id of the pressed button or -1 if escaped [ static ] + \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) */ -int SUIT_MessageBox::warn2( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - int idButton0, int idButton1, int idDefault ) +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 ); - - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else - idDefault = 0; - - int ret = QMessageBox::warning( parent, caption, text, textButton0, - textButton1, QString::null, idDefault ); - qApp->processEvents(); - return ( ret == 0 ? idButton0 : idButton1 ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); + return QMessageBox::critical( parent, title, text, buttons, defaultButton ); } /*! - Shows error message box with two buttons - Returns id of the pressed button or -1 if escaped [ static ] + \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) */ -int SUIT_MessageBox::error2( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - int idButton0, int idButton1, int idDefault ) +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 ); - - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else - idDefault = 0; - - int ret = QMessageBox::critical( parent, caption, text, textButton0, - textButton1, QString::null, idDefault ); - qApp->processEvents(); - return ( ret == 0 ? idButton0 : idButton1 ); + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); + return QMessageBox::warning( parent, title, text, buttons, defaultButton ); } /*! - Shows question message box with two buttons - Returns id of the pressed button or -1 if escaped [ static ] + \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) */ -int SUIT_MessageBox::question2( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - int idButton0, int idButton1, int idDefault ) +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 ); - - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else - idDefault = 0; + 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. - int ret = QMessageBox::question( parent, caption, text, textButton0, - textButton1, QString::null, idDefault ); - qApp->processEvents(); - return ( ret == 0 ? idButton0 : idButton1 ); + 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 ); +} + +/*! + \brief Show information 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::information( 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::Information, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show question 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::question( 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::Question, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show critical message box with three custom buttons. + + Parameters \a button1, \a button2 and \a button3 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, etc. + + 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 last 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 button3 third 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 QString& button3, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show warning message box with three custom buttons. + + Parameters \a button1, \a button2 and \a button3 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, etc. + + 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 last 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 button3 third 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 QString& button3, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show information message box with three custom buttons. + + Parameters \a button1, \a button2 and \a button3 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, etc. + + 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 last 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 button3 third button text + \param defaultButton default button + \param escapeButton escape button + \return button used button id +*/ +int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + return messageBox( SUIT_MessageBox::Information, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show question message box with three custom buttons. + + Parameters \a button1, \a button2 and \a button3 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, etc. + + 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 last 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 button3 third button text + \param defaultButton default button + \param escapeButton escape button + \return button used button id +*/ +int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + return messageBox( SUIT_MessageBox::Question, parent, title, text, lst, + defaultButton, escapeButton ); } /*! - Shows info message box with three buttons. - Returns id of the pressed button or -1 if escaped [ static ] + \brief Show critical message box with four custom buttons. + + Parameters \a button1, \a button2, \a button3 and \a button4 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, etc. + + 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 last 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 button3 third button text + \param button4 fourth 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 QString& button3, const QString& button4, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + lst.append( ButtonInfo( id++, button4 ) ); + return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show warning message box with four custom buttons. + + Parameters \a button1, \a button2, \a button3 and \a button4 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, etc. + + 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 last 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 button3 third button text + \param button4 fourth 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 QString& button3, const QString& button4, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + lst.append( ButtonInfo( id++, button4 ) ); + return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show information message box with four custom buttons. + + Parameters \a button1, \a button2, \a button3 and \a button4 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, etc. + + 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 last 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 button3 third button text + \param button4 fourth button text + \param defaultButton default button + \param escapeButton escape button + \return button used button id +*/ +int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + lst.append( ButtonInfo( id++, button4 ) ); + return messageBox( SUIT_MessageBox::Information, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show question message box with four custom buttons. + + Parameters \a button1, \a button2, \a button3 and \a button4 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, etc. + + 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 last 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 button3 third button text + \param button4 fourth button text + \param defaultButton default button + \param escapeButton escape button + \return button used button id */ -int SUIT_MessageBox::info3( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - const QString& textButton2, - int idButton0, int idButton1, - int idButton2, int idDefault ) +int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton, const int escapeButton ) { - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + ButtonInfos lst; + int id = 0; + lst.append( ButtonInfo( id++, button1 ) ); + lst.append( ButtonInfo( id++, button2 ) ); + lst.append( ButtonInfo( id++, button3 ) ); + lst.append( ButtonInfo( id++, button4 ) ); + return messageBox( SUIT_MessageBox::Question, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show critical message box with arbitrary number of user-specified + buttons. + + List of buttons to be shown is specified via \a buttons parameter. - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else if ( idDefault == idButton2 ) - idDefault = 2; - else - idDefault = 0; + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param buttons list of buttons to be shown + \return button used button id +*/ +int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, + const QStringList& buttons, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + Q_FOREACH( QString button, buttons ) + lst.append( ButtonInfo( id++, button ) ); + return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show warning message box with arbitrary number of user-specified + buttons. + + List of buttons to be shown is specified via \a buttons parameter. - int ret = QMessageBox::information( parent, caption, text, textButton0, - textButton1, textButton2, idDefault ); - qApp->processEvents(); - switch ( ret ) - { - case 0: - return idButton0; - case 1: - return idButton1; - case 2: - return idButton2; - } - return -1; -} - -/*! - Shows warning message box with three buttons. - Returns id of the pressed button or -1 if escaped [ static ] -*/ -int SUIT_MessageBox::warn3( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - const QString& textButton2, - int idButton0, int idButton1, - int idButton2, int idDefault ) -{ - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param buttons list of buttons to be shown + \return button used button id +*/ +int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, + const QStringList& buttons, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + Q_FOREACH( QString button, buttons ) + lst.append( ButtonInfo( id++, button ) ); + return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show information message box with arbitrary number of user-specified + buttons. + + List of buttons to be shown is specified via \a buttons parameter. - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else if ( idDefault == idButton2 ) - idDefault = 2; - else - idDefault = 0; + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param buttons list of buttons to be shown + \return button used button id +*/ +int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, + const QStringList& buttons, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + Q_FOREACH( QString button, buttons ) + lst.append( ButtonInfo( id++, button ) ); + return messageBox( SUIT_MessageBox::Information, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show question message box with arbitrary number of user-specified + buttons. + + List of buttons to be shown is specified via \a buttons parameter. - int ret = QMessageBox::warning( parent, caption, text, textButton0, - textButton1, textButton2, idDefault ); - qApp->processEvents(); - switch ( ret ) - { - case 0: - return idButton0; - case 1: - return idButton1; - case 2: - return idButton2; - } - return -1; -} - -/*! - Shows error message box with three buttons. - Returns id of the pressed button or -1 if escaped [ static ] -*/ -int SUIT_MessageBox::error3( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - const QString& textButton2, - int idButton0, int idButton1, - int idButton2, int idDefault ) -{ - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param buttons list of buttons to be shown + \return button used button id +*/ +int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, + const QStringList& buttons, + const int defaultButton, const int escapeButton ) +{ + ButtonInfos lst; + int id = 0; + Q_FOREACH( QString button, buttons ) + lst.append( ButtonInfo( id++, button ) ); + return messageBox( SUIT_MessageBox::Question, parent, title, text, lst, + defaultButton, escapeButton ); +} + +/*! + \brief Show critical message box with arbitrary number of user-specified + buttons. + + The function accepts arbitrary number of parameters. Each parameter starting + from \a btn should be of type const char* to specify the button text. + After the last button parameter and additional 0 (zero) value should be + specified. - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else if ( idDefault == idButton2 ) - idDefault = 2; - else - idDefault = 0; + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param btn first button text + \return button used button id +*/ +int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char* btn, ... ) +{ + va_list args; + va_start( args, btn ); + return messageBox( SUIT_MessageBox::Critical, parent, title, text, + messageList( btn, args ), + defaultButton, escapeButton ); +} + +/*! + \brief Show warning message box with arbitrary number of user-specified + buttons. + + The function accepts arbitrary number of parameters. Each parameter starting + from \a btn should be of type const char* to specify the button text. + After the last button parameter and additional 0 (zero) value should be + specified. - int ret = QMessageBox::critical( parent, caption, text, textButton0, - textButton1, textButton2, idDefault ); - qApp->processEvents(); - switch ( ret ) - { - case 0: - return idButton0; - case 1: - return idButton1; - case 2: - return idButton2; - } - return -1; -} - -/*! - Shows question message box with three buttons. - Returns id of the pressed button or -1 if escaped [ static ] -*/ -int SUIT_MessageBox::question3( QWidget* parent, - const QString& caption, - const QString& text, - const QString& textButton0, - const QString& textButton1, - const QString& textButton2, - int idButton0, int idButton1, - int idButton2, int idDefault ) -{ - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor ); + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param btn first button text + \return button used button id +*/ +int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char* btn, ... ) +{ + va_list args; + va_start( args, btn ); + return messageBox( SUIT_MessageBox::Warning, parent, title, text, + messageList( btn, args ), + defaultButton, escapeButton ); +} + +/*! + \brief Show information message box with arbitrary number of user-specified + buttons. + + The function accepts arbitrary number of parameters. Each parameter starting + from \a btn should be of type const char* to specify the button text. + After the last button parameter and additional 0 (zero) value should be + specified. - if ( idDefault == idButton0 ) - idDefault = 0; - else if ( idDefault == idButton1 ) - idDefault = 1; - else if ( idDefault == idButton2 ) - idDefault = 2; - else - idDefault = 0; + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param btn first button text + \return button used button id +*/ +int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char* btn, ... ) +{ + va_list args; + va_start( args, btn ); + return messageBox( SUIT_MessageBox::Information, parent, title, text, + messageList( btn, args ), + defaultButton, escapeButton ); +} + +/*! + \brief Show question message box with arbitrary number of user-specified + buttons. + + The function accepts arbitrary number of parameters. Each parameter starting + from \a btn should be of type const char* to specify the button text. + After the last button parameter and additional 0 (zero) value should be + specified. - int ret = QMessageBox::question( parent, caption, text, textButton0, - textButton1, textButton2, idDefault ); - qApp->processEvents(); - switch ( ret ) - { - case 0: - return idButton0; - case 1: - return idButton1; - case 2: - return idButton2; - } - return -1; + 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, etc. + + 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 last one is defined as escape button. + + \param parent parent widget + \param title message box title + \param text message box text + \param defaultButton default button + \param escapeButton escape button + \param btn first button text + \return button used button id +*/ +int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char* btn, ... ) +{ + va_list args; + va_start( args, btn ); + return messageBox( SUIT_MessageBox::Question, parent, title, text, + messageList( btn, args ), + defaultButton, escapeButton ); } + +/*! + \brief Parse arbitrary arguments list. + + The last parameter in a sequence should be 0 (zero) value. + + \param txt first argument which starts arbitrary sequence + \param args arguments list from the stack + \return list of buttons infos +*/ +SUIT_MessageBox::ButtonInfos SUIT_MessageBox::messageList( char* txt, va_list& args ) +{ + int i = 0; + ButtonInfos lst; + char* cur = txt; + while ( cur ) + { + lst.append( ButtonInfo( i++, cur ) ); + cur = va_arg( args, char* ); + } + + va_end( args ); + + return lst; +} + +/*! + \brief Create and show the message box. + \param icon icon type + \param parent parent widget + \param title message box title + \param text message box text + \param lst list of buttons infos + \param defaultButton default button + \param escapeButton escape button + \return button used button id +*/ +int SUIT_MessageBox::messageBox( Icon icon, QWidget* parent, + const QString& title, const QString& text, + const ButtonInfos& lst, + const int defaultButton, + const int escapeButton ) +{ + SUIT_MessageBox msgBox( icon, title, text, NoButton, parent ); + + QMap bm; + for ( int i = 0; i < lst.count(); i++ ) + { + int btn = lst[i].id(); + QString txt = lst[i].text(); + ButtonRole role = lst[i].role(); + + QPushButton* pb = msgBox.addButton( txt, role ); + bm.insert( pb, btn ); + + if ( ( defaultButton == -1 && i == 0 ) || btn == defaultButton ) + msgBox.setDefaultButton( pb ); + if ( ( escapeButton == -1 && i == lst.count() - 1 ) || btn == escapeButton ) + msgBox.setEscapeButton( pb ); + } + + SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); + + int res = msgBox.exec(); + if ( res != -1 ) + res = bm[msgBox.clickedButton()]; + + QApplication::processEvents(); + + return res; +} +