From 637cf6b7b03d7b6d4a5a89dc7575f93fc1f5287a Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 28 May 2007 12:56:33 +0000 Subject: [PATCH] Porting to Qt 4 --- src/CAF/CAF_Application.cxx | 2 +- src/CAF/CAF_Study.cxx | 8 +- src/CAM/CAM_Application.cxx | 10 +- src/GLViewer/GLViewer_ViewFrame.cxx | 14 +- src/LightApp/LightApp_Application.cxx | 34 +- src/LightApp/LightApp_PreferencesDlg.cxx | 7 +- src/LogWindow/LogWindow.cxx | 2 +- src/Makefile.am | 13 +- src/Plot2d/Plot2d_ViewFrame.cxx | 4 +- src/STD/STD_Application.cxx | 30 +- src/SUIT/SUIT_MessageBox.cxx | 1004 +++++++++++++---- src/SUIT/SUIT_MessageBox.h | 130 ++- src/SUIT/SUIT_Study.cxx | 3 +- src/SalomeApp/SalomeApp_Application.cxx | 52 +- .../SalomeApp_StudyPropertiesDlg.cxx | 7 +- src/SalomeApp/SalomeApp_Tools.cxx | 8 +- src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx | 14 +- 17 files changed, 984 insertions(+), 358 deletions(-) diff --git a/src/CAF/CAF_Application.cxx b/src/CAF/CAF_Application.cxx index 5a921a7d3..c3365dcd7 100755 --- a/src/CAF/CAF_Application.cxx +++ b/src/CAF/CAF_Application.cxx @@ -318,7 +318,7 @@ void CAF_Application::updateCommandsStatus() */ void CAF_Application::onHelpAbout() { - SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" ); + SUIT_MessageBox::information( desktop(), tr( "About" ), tr( "ABOUT_INFO" ) ); } /*! diff --git a/src/CAF/CAF_Study.cxx b/src/CAF/CAF_Study.cxx index 706597b48..95ac4cbf8 100755 --- a/src/CAF/CAF_Study.cxx +++ b/src/CAF/CAF_Study.cxx @@ -375,8 +375,8 @@ bool CAF_Study::undo() undoModified(); /* decrement modification counter */ } catch ( Standard_Failure ) { - SUIT_MessageBox::error1(application()->desktop(), tr( "ERR_ERROR" ), - tr( "ERR_DOC_UNDO" ), tr ( "BUT_OK" )); + SUIT_MessageBox::critical(application()->desktop(), tr( "ERR_ERROR" ), + tr( "ERR_DOC_UNDO" )); return false; } return true; @@ -399,8 +399,8 @@ bool CAF_Study::redo() doModified(); /* increment modification counter */ } catch ( Standard_Failure ) { - SUIT_MessageBox::error1( application()->desktop(), tr( "ERR_ERROR" ), - tr( "ERR_DOC_REDO" ), tr ( "BUT_OK" ) ); + SUIT_MessageBox::critical( application()->desktop(), tr( "ERR_ERROR" ), + tr( "ERR_DOC_REDO" ) ); return false; } return true; diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 5a3bad8eb..9739791d0 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -236,8 +236,8 @@ void CAM_Application::loadModules() addModule( mod ); else { if ( desktop() && desktop()->isVisible() ) - SUIT_MessageBox::error1( desktop(), tr( "Loading modules" ), - tr( "Can not load module %1" ).arg( (*it).title ), tr( "Ok" ) ); + SUIT_MessageBox::critical( desktop(), tr( "Loading modules" ), + tr( "Can not load module %1" ).arg( (*it).title ) ); else qWarning( tr( "Can not load module %1" ).arg( (*it).title ).toLatin1().data() ); } @@ -316,7 +316,7 @@ CAM_Module* CAM_Application::loadModule( const QString& modName ) if ( !err.isEmpty() ) { if ( desktop() && desktop()->isVisible() ) - SUIT_MessageBox::warn1( desktop(), tr( "Error" ), err, tr( "Ok" ) ); + SUIT_MessageBox::warning( desktop(), tr( "Error" ), err ); else qWarning( err.toLatin1().data() ); } @@ -386,7 +386,7 @@ bool CAM_Application::activateModule( CAM_Module* mod ) myModule->setMenuShown( false ); myModule->setToolShown( false ); if ( desktop() && desktop()->isVisible() ) - SUIT_MessageBox::error1( desktop(), tr( "ERROR_TLT" ), tr( "ERROR_ACTIVATE_MODULE_MSG" ).arg( myModule->moduleName() ), tr( "BUT_OK" ) ); + SUIT_MessageBox::critical( desktop(), tr( "ERROR_TLT" ), tr( "ERROR_ACTIVATE_MODULE_MSG" ).arg( myModule->moduleName() ) ); else qWarning( tr( "ERROR_ACTIVATE_MODULE_MSG" ).arg( myModule->moduleName() ).toLatin1().data() ); myModule = 0; @@ -595,7 +595,7 @@ void CAM_Application::readModuleList() if ( myInfoList.isEmpty() ) { if ( desktop() && desktop()->isVisible() ) - SUIT_MessageBox::warn1( desktop(), tr( "Warning" ), tr( "Modules list is empty" ), tr( "&OK" ) ); + SUIT_MessageBox::warning( desktop(), tr( "Warning" ), tr( "Modules list is empty" ) ); else { printf( "****************************************************************\n" ); diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index 322870cfc..c0b63bb6c 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -409,10 +409,9 @@ void GLViewer_ViewFrame::onViewDump() if( aFileName.isEmpty() ) { - SUIT_MessageBox::error1( this, - tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), - tr( "DUMP_VIEW_ERROR_DLG_TEXT" ), - tr( "BUT_OK" ) ); + SUIT_MessageBox::critical( this, + tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), + tr( "DUMP_VIEW_ERROR_DLG_TEXT" ) ); } QString aSaveOp = "BMP"; @@ -435,10 +434,9 @@ void GLViewer_ViewFrame::onViewDump() if( !aWidget->grabFrameBuffer().save( aFileName, aSaveOp ) ) //#endif { - SUIT_MessageBox::error1( this, - tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), - tr( "DUMP_VIEW_ERROR_DLG_TEXT" ), - tr( "BUT_OK" ) ); + SUIT_MessageBox::critical( this, + tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), + tr( "DUMP_VIEW_ERROR_DLG_TEXT" ) ); } } diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index e91cb94c7..3024d7c04 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -124,7 +125,6 @@ #include #include #include -#include #include #define FIRST_HELP_ID 1000000 @@ -752,8 +752,6 @@ void LightApp_Application::onOpenDoc() } } -#include "SUIT_MessageBox.h" - /*! SLOT: Opens new document. \param aName - name of file @@ -775,10 +773,11 @@ bool LightApp_Application::onOpenDoc( const QString& aName ) // The document ... is already open. // Do you want to reload it? - int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"), - tr("QUE_DOC_ALREADYOPEN").arg(aName), - tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2); - if (aAnswer == 1) { // reload + int aAnswer = SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), + tr("QUE_DOC_ALREADYOPEN").arg(aName), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::No ); + if (aAnswer == SUIT_MessageBox::Yes) { // reload if (activeStudy()->studyName() == aName && aAppList.count() > 1) { // Opened in THIS (active) application. STD_Application* app1 = (STD_Application*)aAppList.at(0); @@ -997,9 +996,10 @@ void LightApp_Application::onHelpContentsModule() rs->start(); } else { - if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"), - tr("DEFINE_EXTERNAL_BROWSER"), - tr("BUT_OK"),tr("BUT_CANCEL"),0,1,0 )==0 ) + if( SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), + tr("DEFINE_EXTERNAL_BROWSER"), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) onPreferences(); } } @@ -1033,9 +1033,10 @@ void LightApp_Application::onHelpContextModule(const QString& theComponentName, rs->start(); } else { - if( SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"), - tr("DEFINE_EXTERNAL_BROWSER"), - tr("BUT_OK"), tr("BUT_CANCEL"),0,1,0)==0 ) + if( SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), + tr("DEFINE_EXTERNAL_BROWSER"), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) onPreferences(); } } @@ -2503,9 +2504,10 @@ bool LightApp_Application::event( QEvent* e ) { QCustomEvent* ce = ( QCustomEvent* )e; QString* d = ( QString* )ce->data(); - if( SUIT_MessageBox::warn2(0, tr("WRN_WARNING"), - d ? *d : "", - tr("BUT_OK"), tr("BUT_CANCEL"), 0, 1, 0 )==0 ) + if( SUIT_MessageBox::question(0, tr("WRN_WARNING"), + d ? *d : "", + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes ) onPreferences(); if( d ) delete d; diff --git a/src/LightApp/LightApp_PreferencesDlg.cxx b/src/LightApp/LightApp_PreferencesDlg.cxx index b691eb459..204fc2f11 100644 --- a/src/LightApp/LightApp_PreferencesDlg.cxx +++ b/src/LightApp/LightApp_PreferencesDlg.cxx @@ -24,9 +24,10 @@ #include "QtxResourceMgr.h" +#include + #include #include -#include #include #include @@ -124,7 +125,9 @@ void LightApp_PreferencesDlg::onApply() /*! Restore default preferences*/ void LightApp_PreferencesDlg::onDefault() { - if( QMessageBox::Ok == QMessageBox::information( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), QMessageBox::Ok, QMessageBox::Cancel ) ) + if( SUIT_MessageBox::Ok == SUIT_MessageBox::question( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), + SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, + SUIT_MessageBox::Ok ) ) { if ( myPrefs && myPrefs->resourceMgr() ) { diff --git a/src/LogWindow/LogWindow.cxx b/src/LogWindow/LogWindow.cxx index c0f6bbcb4..fb6ef862d 100755 --- a/src/LogWindow/LogWindow.cxx +++ b/src/LogWindow/LogWindow.cxx @@ -365,7 +365,7 @@ void LogWindow::onSaveToFile() QApplication::restoreOverrideCursor(); if ( !bOk ) - SUIT_MessageBox::error1( this, tr( "ERR_ERROR" ), tr( "ERR_CANT_SAVE_FILE" ), tr( "BUT_OK" ) ); + SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "ERR_CANT_SAVE_FILE" ) ); } /*! diff --git a/src/Makefile.am b/src/Makefile.am index 462e3ac2e..cba9f1f8d 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,9 +30,6 @@ SUBDIRS = Qtx DDS QDS SUIT SUITApp STD CAF CAM LogWindow Prs if ENABLE_SALOMEOBJECT -# VSR: this is the original packages list -# SUBDIRS += OBJECT -# VSR: already migrated to Qt4 packages SUBDIRS += OBJECT endif @@ -92,14 +89,14 @@ if ENABLE_SUPERVGRAPHVIEWER SUBDIRS += endif # VSR: this is the original packages list -#SUBDIRS += LightApp ResExporter +#SUBDIRS += Event LightApp ResExporter # VSR: already migrated to Qt4 packages -SUBDIRS += +SUBDIRS += Event if GUI_ENABLE_CORBA # VSR: this is the original packages list -# SUBDIRS += RegistryDisplay TOOLSGUI \ -# Event Session SalomeApp SALOME_SWIG SALOME_PY SALOME_PYQT +# SUBDIRS += RegistryDisplay TOOLSGUI \ +# Session SalomeApp SALOME_SWIG SALOME_PY SALOME_PYQT # VSR: already migrated to Qt4 packages - SUBDIRS += Event + SUBDIRS += endif diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 55b805bfc..b68a44439 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -1339,7 +1339,7 @@ void Plot2d_ViewFrame::setHorScaleMode( const int mode, bool update ) // it crashes if switched to X/Y logarithmic mode, when one or more points have // non-positive X/Y coordinate if ( mode && !isXLogEnabled() ){ - SUIT_MessageBox::warn1(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED"), tr("BUT_OK")); + SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_XLOG_NOT_ALLOWED")); return; } @@ -1360,7 +1360,7 @@ void Plot2d_ViewFrame::setVerScaleMode( const int mode, bool update ) // it crashes if switched to X/Y logarithmic mode, when one or more points have // non-positive X/Y coordinate if ( mode && !isYLogEnabled() ){ - SUIT_MessageBox::warn1(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED"), tr("BUT_OK")); + SUIT_MessageBox::warning(this, tr("WARNING"), tr("WRN_YLOG_NOT_ALLOWED")); return; } diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 152863723..cb09b74f1 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -832,9 +832,9 @@ QString STD_Application::getFileName( bool open, const QString& initial, const Q isOk = true; else { - int aEnd = aUsedFilter.lastIndexOf( ')' ); - int aStart = aUsedFilter.lastIndexOf( '(', aEnd ); - QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 ); + int aEnd = aUsedFilter.lastIndexOf( ')' ); + int aStart = aUsedFilter.lastIndexOf( '(', aEnd ); + QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 ); int idx = 0; QStringList extList; @@ -848,23 +848,23 @@ QString STD_Application::getFileName( bool open, const QString& initial, const Q if ( !extList.isEmpty() && !extList.contains( SUIT_Tools::extension( aName ) ) ) aName += QString( ".%1" ).arg( extList.first() ); - if ( QFileInfo( aName ).exists() ) + if ( QFileInfo( aName ).exists() ) { - int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ), - tr( "MSG_FILE_EXISTS" ).arg( aName ), - SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes ); - if ( aAnswer == SUIT_MessageBox::Cancel ) + int aAnswer = SUIT_MessageBox::question( desktop(), tr( "TIT_FILE_SAVEAS" ), + tr( "MSG_FILE_EXISTS" ).arg( aName ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No | SUIT_MessageBox::Cancel, SUIT_MessageBox::Yes ); + if ( aAnswer == SUIT_MessageBox::Cancel ) { // cancelled aName = QString::null; - isOk = true; + isOk = true; } - else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file - anOldPath = aName; // not to return to the same initial dir at each "while" step - else // overwrite the existing file - isOk = true; + else if ( aAnswer == SUIT_MessageBox::No ) // not save to this file + anOldPath = aName; // not to return to the same initial dir at each "while" step + else // overwrite the existing file + isOk = true; } - else - isOk = true; + else + isOk = true; } } return aName; diff --git a/src/SUIT/SUIT_MessageBox.cxx b/src/SUIT/SUIT_MessageBox.cxx index 075df6e7b..ba2d261e0 100755 --- a/src/SUIT/SUIT_MessageBox.cxx +++ b/src/SUIT/SUIT_MessageBox.cxx @@ -17,13 +17,6 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -/*! - \class: SUIT_MessageBox - Message dialog box for SUIT-based application - Module: SUIT - Created: UI team, 02.10.00 -*/ - #include "SUIT_MessageBox.h" #include "SUIT_OverrideCursor.h" @@ -31,9 +24,78 @@ #include #include #include +#include + +#include + +/*! + \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 +*/ /*! - Constructor + \brief Constructor. + \param parent parent widget */ SUIT_MessageBox::SUIT_MessageBox( QWidget* parent ) : QMessageBox( parent ) @@ -41,7 +103,13 @@ SUIT_MessageBox::SUIT_MessageBox( QWidget* parent ) } /*! - Constructor + \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 ) @@ -50,14 +118,16 @@ SUIT_MessageBox::SUIT_MessageBox( Icon icon, const QString& title, const QString } /*! - Destructor + \brief Destructor. */ SUIT_MessageBox::~SUIT_MessageBox() { } /*! - Returns the text of the specified button + \brief Get the standard button text. + \param btn standard button id + \return button text */ QString SUIT_MessageBox::buttonText( StandardButton btn ) const { @@ -69,7 +139,9 @@ QString SUIT_MessageBox::buttonText( StandardButton btn ) const } /*! - Set the text of the specified button + \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 ) { @@ -79,7 +151,13 @@ void SUIT_MessageBox::setButtonText( StandardButton btn, const QString& text ) } /*! - Shows critical message box with specified standard buttons. [ 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) */ SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, StandardButtons buttons, StandardButton defaultButton ) @@ -88,7 +166,28 @@ SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, cons } /*! - Shows information message box with specified standard buttons. [ 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) +*/ +SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, + SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton ) +{ + 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 ) @@ -97,7 +196,13 @@ SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, c } /*! - Shows question message box with specified standard buttons. [ static ] + \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 ) @@ -106,297 +211,770 @@ SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, cons } /*! - Shows warning message box with specified standard buttons. [ static ] + \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) */ -SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, - SUIT_MessageBox::StandardButtons buttons, StandardButton defaultButton ) +int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text, + const QString& button ) { - return QMessageBox::warning( parent, title, text, buttons, defaultButton ); + ButtonInfos lst; + lst.append( ButtonInfo( 0, button ) ); + return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst ); } /*! - Shows critical message box. Some buttons can be renamed. Variable number of arguments - should be specified starting from \param btn as pairs of StandardButton and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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) */ -SUIT_MessageBox::StandardButton SUIT_MessageBox::critical( QWidget* parent, const QString& title, - const QString& text, StandardButtons buttons, - StandardButton defaultButton, StandardButton btn, ... ) +int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, + const QString& button ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Critical, parent, title, text, - buttons, defaultButton, messageMap( btn, args ) ); + ButtonInfos lst; + lst.append( ButtonInfo( 0, button ) ); + return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst ); } /*! - Shows information message box. Some buttons can be renamed. Variable number of arguments - should be specified starting from \param btn as pairs of StandardButton and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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) */ -SUIT_MessageBox::StandardButton SUIT_MessageBox::information( QWidget* parent, const QString& title, - const QString& text, - SUIT_MessageBox::StandardButtons buttons, - SUIT_MessageBox::StandardButton defaultButton, - SUIT_MessageBox::StandardButton btn, ... ) +int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text, + const QString& button ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Information, parent, title, text, - buttons, defaultButton, messageMap( btn, args ) ); + ButtonInfos lst; + lst.append( ButtonInfo( 0, button ) ); + return messageBox( SUIT_MessageBox::Information, parent, title, text, lst ); } /*! - Shows question message box. Some buttons can be renamed. Variable number of arguments - should be specified starting from \param btn as pairs of StandardButton and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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) */ -SUIT_MessageBox::StandardButton SUIT_MessageBox::question( QWidget* parent, const QString& title, - const QString& text, StandardButtons buttons, - StandardButton defaultButton, StandardButton btn, ... ) +int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text, + const QString& button ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Question, parent, title, text, - buttons, defaultButton, messageMap( btn, args ) ); + 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 ); } /*! - Shows warning message box. Some buttons can be renamed. Variable number of arguments - should be specified starting from \param btn as pairs of StandardButton and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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 */ -SUIT_MessageBox::StandardButton SUIT_MessageBox::warning( QWidget* parent, const QString& title, - const QString& text, StandardButtons buttons, - StandardButton defaultButton, StandardButton btn, ... ) +int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const int defaultButton, const int escapeButton ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Warning, parent, title, text, - buttons, defaultButton, messageMap( btn, args ) ); + 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 ); } /*! - Shows critical message box with user specified buttons. Each button decribed by two - parameters: int - button id and QString - button text. First button specified by \param btn0 - and \param txt0, following buttons specified as variable number of arguments which - should be started from \param btn as pairs of int and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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, - int defaultButton, int btn0, QString txt0, int btn, ... ) + const QString& button1, const QString& button2, + const QString& button3, + const int defaultButton, const int escapeButton ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Critical, parent, title, text, - defaultButton, messageList( btn0, txt0, btn, args ) ); + 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 ); } /*! - Shows information message box with user specified buttons. Each button decribed by two - parameters: int - button id and QString - button text. First button specified by \param btn0 - and \param txt0, following buttons specified as variable number of arguments which - should be started from \param btn as pairs of int and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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, - int defaultButton, int btn0, QString txt0, int btn, ... ) + const QString& button1, const QString& button2, + const QString& button3, + const int defaultButton, const int escapeButton ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Information, parent, title, text, - defaultButton, messageList( btn0, txt0, btn, args ) ); + 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 ); } /*! - Shows question message box with user specified buttons. Each button decribed by two - parameters: int - button id and QString - button text. First button specified by \param btn0 - and \param txt0, following buttons specified as variable number of arguments which - should be started from \param btn as pairs of int and QString. - After the last pair 0 (zero) value should be specified. [ static ] + \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, - int defaultButton, int btn0, QString txt0, int btn, ... ) + const QString& button1, const QString& button2, + const QString& button3, + const int defaultButton, const int escapeButton ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Question, parent, title, text, - defaultButton, messageList( btn0, txt0, btn, args ) ); + 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 warning message box with user specified buttons. Each button decribed by two - parameters: int - button id and QString - button text. First button specified by \param btn0 - and \param txt0, following buttons specified as variable number of arguments which - should be started from \param btn as pairs of int and QString. - After the last pair 0 (zero) value should be specified. [ 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, - int defaultButton, int btn0, QString txt0, int btn, ... ) + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton, const int escapeButton ) { - va_list args; - va_start( args, btn ); - return messageBox( SUIT_MessageBox::Warning, parent, title, text, - defaultButton, messageList( btn0, txt0, btn, args ) ); + 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 ); } /*! - Shows critical message box with user specified buttons. Each button decribed by button text. - Variable number of arguments should be started from \param txt. After the last text 0 (zero) - value should be specified. [ static ] + \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::critical( QWidget* parent, const QString& title, const QString& text, char* txt, ... ) +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 ) { - va_list args; - va_start( args, txt ); - return messageBox( SUIT_MessageBox::Critical, parent, title, text, - 0, messageList( txt, args ) ); + 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 ); } /*! - Shows information message box with user specified buttons. Each button decribed by button text. - Variable number of arguments should be started from \param txt. After the last text 0 (zero) - value should be specified. [ static ] + \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::information( QWidget* parent, const QString& title, const QString& text, char* txt, ... ) +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 ) { - va_list args; - va_start( args, txt ); - return messageBox( SUIT_MessageBox::Information, parent, title, text, - 0, messageList( txt, args ) ); + 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 ); } /*! - Shows question message box with user specified buttons. Each button decribed by button text. - Variable number of arguments should be started from \param txt. After the last text 0 (zero) - value should be specified. [ static ] + \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. + + 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, char* txt, ... ) +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, txt ); - return messageBox( SUIT_MessageBox::Question, parent, title, text, - 0, messageList( txt, args ) ); + va_start( args, btn ); + return messageBox( SUIT_MessageBox::Critical, parent, title, text, + messageList( btn, args ), + defaultButton, escapeButton ); } /*! - Shows warning message box with user specified buttons. Each button decribed by button text. - Variable number of arguments should be started from \param txt. After the last text 0 (zero) - value should be specified. [ static ] + \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. + + 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, char* txt, ... ) +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, txt ); + va_start( args, btn ); return messageBox( SUIT_MessageBox::Warning, parent, title, text, - 0, messageList( txt, args ) ); + messageList( btn, args ), + defaultButton, escapeButton ); } -SUIT_MessageBox::StandardButton SUIT_MessageBox::messageBox( SUIT_MessageBox::Icon icon, QWidget* parent, - const QString& title, const QString& text, - StandardButtons buttons, StandardButton defaultButton, - const ButtonMap& map ) +/*! + \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. + + 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, ... ) { - SUIT_MessageBox msgBox( icon, title, text, buttons, parent ); - for ( ButtonMap::const_iterator it = map.begin(); it != map.end(); ++it ) - msgBox.setButtonText( it.key(), it.value() ); + va_list args; + va_start( args, btn ); + return messageBox( SUIT_MessageBox::Information, parent, title, text, + messageList( btn, args ), + defaultButton, escapeButton ); +} - if ( defaultButton != NoButton ) - msgBox.setDefaultButton( ::qobject_cast( msgBox.button( defaultButton ) ) ); +/*! + \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. + + 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 ); +} - SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::ArrowCursor ); +/*! + \brief Parse arbitrary arguments list. - StandardButton res = NoButton; - if ( msgBox.exec() == -1 ) - res = QMessageBox::Cancel; - else - res = msgBox.standardButton( msgBox.clickedButton() ); + The last parameter in a sequence should be 0 (zero) value. - QApplication::processEvents(); + \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* ); + } - return res; + va_end( args ); + + return lst; } -int SUIT_MessageBox::messageBox( Icon icon, QWidget* parent, const QString& title, const QString& text, - const int defaultButton, const ButtonList& 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 map; - for ( ButtonList::const_iterator it = lst.begin(); it != lst.end(); ++it ) + QMap bm; + for ( int i = 0; i < lst.count(); i++ ) { - int btn = (*it).first; - QString txt = (*it).second; - ButtonRole role = InvalidRole; - - if ( btn == defaultButton ) - role = AcceptRole; + int btn = lst[i].id(); + QString txt = lst[i].text(); + ButtonRole role = lst[i].role(); QPushButton* pb = msgBox.addButton( txt, role ); - map.insert( pb, btn ); + bm.insert( pb, btn ); - if ( btn == defaultButton ) + 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 = NoButton; - if ( msgBox.exec() == -1 ) - res = Cancel; - else - res = map[msgBox.clickedButton()]; + int res = msgBox.exec(); + if ( res != -1 ) + res = bm[msgBox.clickedButton()]; QApplication::processEvents(); return res; } -SUIT_MessageBox::ButtonMap SUIT_MessageBox::messageMap( StandardButton btn, va_list& args ) -{ - ButtonMap map; - StandardButton cur = btn; - while ( !cur ) - { - QString name = va_arg( args, QString ); - map.insert( cur, name ); - cur = va_arg( args, StandardButton ); - } - - va_end( args ); - - return map; -} - -SUIT_MessageBox::ButtonList SUIT_MessageBox::messageList( int btn0, QString txt0, int btn, va_list& args ) -{ - ButtonList lst; - lst.append( QPair( btn0, txt0 ) ); - int cur = btn; - while ( !cur ) - { - QString name = va_arg( args, QString ); - lst.append( QPair( cur, name ) ); - cur = va_arg( args, int ); - } - - va_end( args ); - - return lst; -} - -SUIT_MessageBox::ButtonList SUIT_MessageBox::messageList( char* txt, va_list& args ) -{ - int i = 0; - ButtonList lst; - char* cur = txt; - while ( cur ) - { - lst.append( QPair( i++, cur ) ); - cur = va_arg( args, char* ); - } - - va_end( args ); - - return lst; -} diff --git a/src/SUIT/SUIT_MessageBox.h b/src/SUIT/SUIT_MessageBox.h index 68ebb1bea..d9d24133c 100755 --- a/src/SUIT/SUIT_MessageBox.h +++ b/src/SUIT/SUIT_MessageBox.h @@ -26,69 +26,125 @@ #include #include -#include - -/*! - \class SUIT_MessageBox - \brief Message dialog box for SUIT-based application -*/ class SUIT_EXPORT SUIT_MessageBox : public QMessageBox { public: + // construction/destruction SUIT_MessageBox( QWidget* = 0 ); SUIT_MessageBox( Icon, const QString&, const QString&, StandardButtons buttons = NoButton, QWidget* = 0, Qt::WindowFlags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint ); ~SUIT_MessageBox(); + // customize the standard buttons text QString buttonText( StandardButton ) const; void setButtonText( StandardButton, const QString& ); + // message box with standard buttons static StandardButton critical( QWidget* parent, const QString& title, const QString& text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); - static StandardButton information( QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); - static StandardButton question( QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); static StandardButton warning( QWidget* parent, const QString& title, const QString& text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); - - static StandardButton critical( QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons, StandardButton defaultButton, StandardButton, ... ); static StandardButton information( QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons, StandardButton defaultButton, StandardButton, ... ); + StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); static StandardButton question( QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons, StandardButton defaultButton, StandardButton, ... ); - static StandardButton warning( QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons, StandardButton defaultButton, StandardButton, ... ); + StandardButtons buttons = Ok, StandardButton defaultButton = NoButton ); + + // message boxes with one custom button + static int critical( QWidget* parent, const QString& title, const QString& text, + const QString& button ); + static int warning( QWidget* parent, const QString& title, const QString& text, + const QString& button ); + static int information( QWidget* parent, const QString& title, const QString& text, + const QString& button ); + static int question( QWidget* parent, const QString& title, const QString& text, + const QString& button ); + // message boxes with two custom buttons static int critical( QWidget* parent, const QString& title, const QString& text, - int defaultButton, int, QString, int, ... ); + const QString& button1, const QString& button2, + const int defaultButton = -1, const int escapeButton = -1 ); + static int warning( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const int defaultButton = -1, const int escapeButton = -1 ); static int information( QWidget* parent, const QString& title, const QString& text, - int defaultButton, int, QString, int, ... ); + const QString& button1, const QString& button2, + const int defaultButton = -1, const int escapeButton = -1 ); static int question( QWidget* parent, const QString& title, const QString& text, - int defaultButton, int, QString, int, ... ); + const QString& button1, const QString& button2, + const int defaultButton = -1, const int escapeButton = -1 ); + + // message boxes with three custom buttons + static int critical( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, const QString& button3, + const int defaultButton = -1, const int escapeButton = -1 ); static int warning( QWidget* parent, const QString& title, const QString& text, - int defaultButton, int, QString, int, ... ); - - static int critical( QWidget* parent, const QString& title, const QString& text, char*, ... ); - static int information( QWidget* parent, const QString& title, const QString& text, char*, ... ); - static int question( QWidget* parent, const QString& title, const QString& text, char*, ... ); - static int warning( QWidget* parent, const QString& title, const QString& text, char*, ... ); - -private: - typedef QMap ButtonMap; - typedef QList< QPair > ButtonList; + const QString& button1, const QString& button2, const QString& button3, + const int defaultButton = -1, const int escapeButton = -1 ); + static int information( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, const QString& button3, + const int defaultButton = -1, const int escapeButton = -1 ); + static int question( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, const QString& button3, + const int defaultButton = -1, const int escapeButton = -1 ); + + // message boxes with four custom buttons + static int critical( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton = -1, const int escapeButton = -1 ); + static int warning( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton = -1, const int escapeButton = -1 ); + static int information( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton = -1, const int escapeButton = -1 ); + static int question( QWidget* parent, const QString& title, const QString& text, + const QString& button1, const QString& button2, + const QString& button3, const QString& button4, + const int defaultButton = -1, const int escapeButton = -1 ); + + // message boxes with arbitrary number of buttons + static int critical( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char*, ... ); + static int warning( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char*, ... ); + static int information( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char*, ... ); + static int question( QWidget* parent, const QString& title, const QString& text, + const int defaultButton, const int escapeButton, + char*, ... ); private: - static StandardButton messageBox( Icon icon, QWidget* parent, const QString& title, const QString& text, - StandardButtons buttons, StandardButton defaultButton, const ButtonMap& ); + class ButtonInfo + { + public: + ButtonInfo( const int id, + const QString& text, + const ButtonRole role = ActionRole ) + : myId( id ), myText( text ), myRole( role ) {} + int id() const { return myId; } + QString text() const { return myText; } + ButtonRole role() const { return myRole; } + private: + int myId; //!< button id + QString myText; //!< button text + ButtonRole myRole; //!< button role + }; - static int messageBox( Icon icon, QWidget* parent, const QString& title, const QString& text, - const int defaultButton, const ButtonList& ); + typedef QList ButtonInfos; - static ButtonMap messageMap( StandardButton, va_list& ); - static ButtonList messageList( int, QString, int, va_list& ); - static ButtonList messageList( char*, va_list& ); +private: + static int messageBox( SUIT_MessageBox::Icon icon, QWidget* parent, + const QString& title, const QString& text, + const ButtonInfos& lst, + const int defaultButton = -1, + const int escapeButton = -1 ); + static ButtonInfos messageList( char*, va_list& ); }; #endif diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index 75513f08d..8fc4f71ce 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -275,8 +275,7 @@ bool SUIT_Study::start( SUIT_Operation* theOp, const bool toCheck ) { int anAnsw = SUIT_MessageBox::question( application()->desktop(), tr( "OPERATION_LAUNCH" ), tr( "PREVIOUS_NOT_FINISHED" ), - SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel, SUIT_MessageBox::Ok, - SUIT_MessageBox::Ok, tr( "CONTINUE" ), 0 ); + tr( "CONTINUE" ), tr( "CANCEL" ) ); if ( anAnsw == 1 ) return false; diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 4b6ba17cd..fa94bedc6 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -300,10 +300,11 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName ) // The document ... is already open. // Do you want to reload it? - int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"), - tr("QUE_DOC_ALREADYOPEN").arg(aName), - tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2); - if (aAnswer == 1) { // reload + int aAnswer = SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), + tr("QUE_DOC_ALREADYOPEN").arg(aName), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::No); + if (aAnswer == SUIT_MessageBox::Yes) { // reload if (activeStudy()->studyName() == aName && aAppList.count() > 1) { // Opened in THIS (active) application. STD_Application* app1 = (STD_Application*)aAppList.at(0); @@ -348,10 +349,11 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName ) // The document ... already exists in the study manager. // Do you want to reload it? - int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"), - tr("QUE_DOC_ALREADYEXIST").arg(aName), - tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2); - if (aAnswer == 1) { + int aAnswer = SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), + tr("QUE_DOC_ALREADYEXIST").arg(aName), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::No); + if (aAnswer == SUIT_MessageBox::Yes) { _PTR(Study) aStudy = studyMgr()->GetStudyByName(aName.latin1()); if (aStudy) studyMgr()->Close(aStudy); @@ -475,10 +477,9 @@ void SalomeApp_Application::onPaste() if(!stdDS) return; if ( stdDS->GetProperties()->IsLocked() ) { - SUIT_MessageBox::warn1 ( desktop(), - QObject::tr("WRN_WARNING"), - QObject::tr("WRN_STUDY_LOCKED"), - QObject::tr("BUT_OK") ); + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED") ); return; } @@ -504,14 +505,11 @@ void SalomeApp_Application::onCloseDoc( bool ask ) if (study != NULL) { _PTR(Study) stdDS = study->studyDS(); if(stdDS && stdDS->IsStudyLocked()) { - if ( SUIT_MessageBox::warn2( desktop(), - QObject::tr( "WRN_WARNING" ), - QObject::tr( "CLOSE_LOCKED_STUDY" ), - QObject::tr( "BUT_YES" ), - QObject::tr( "BUT_NO" ), - SUIT_YES, - SUIT_NO, - SUIT_NO ) == SUIT_NO ) return; + if ( SUIT_MessageBox::question( desktop(), + QObject::tr( "WRN_WARNING" ), + QObject::tr( "CLOSE_LOCKED_STUDY" ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, + SUIT_MessageBox::No) == SUIT_MessageBox::No ) return; } } @@ -701,10 +699,9 @@ void SalomeApp_Application::onDumpStudy( ) if ( toSaveGUI ) appStudy->removeSavePoint(savePoint); //SRN: remove the created temporary save point. if ( !res ) - SUIT_MessageBox::warn1 ( desktop(), - QObject::tr("WRN_WARNING"), - tr("WRN_DUMP_STUDY_FAILED"), - QObject::tr("BUT_OK") ); + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + tr("WRN_DUMP_STUDY_FAILED") ); } } @@ -716,10 +713,9 @@ void SalomeApp_Application::onLoadScript( ) _PTR(Study) aStudy = appStudy->studyDS(); if ( aStudy->GetProperties()->IsLocked() ) { - SUIT_MessageBox::warn1 ( desktop(), - QObject::tr("WRN_WARNING"), - QObject::tr("WRN_STUDY_LOCKED"), - QObject::tr("BUT_OK") ); + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED") ); return; } diff --git a/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx b/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx index 830536676..5f637cece 100644 --- a/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx +++ b/src/SalomeApp/SalomeApp_StudyPropertiesDlg.cxx @@ -301,10 +301,9 @@ void SalomeApp_StudyPropertiesDlg::onOK() propAttr->SetUserName(item->getValue().stripWhiteSpace().latin1()); myChanged = true; } else { - SUIT_MessageBox::warn1(SUIT_Session::session()->activeApplication()->desktop(), - QObject::tr("WRN_WARNING"), - QObject::tr("WRN_STUDY_LOCKED"), - QObject::tr("BUT_OK")); + SUIT_MessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED") ); } } break; diff --git a/src/SalomeApp/SalomeApp_Tools.cxx b/src/SalomeApp/SalomeApp_Tools.cxx index a20fbf0c8..39989f6a6 100644 --- a/src/SalomeApp/SalomeApp_Tools.cxx +++ b/src/SalomeApp/SalomeApp_Tools.cxx @@ -111,10 +111,10 @@ void SalomeApp_Tools::QtCatchCorbaException( const SALOME::SALOME_Exception& S_e } if ( error ) - SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), - title, message, QObject::tr( "OK" ) ); + SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), + title, message ); else - SUIT_MessageBox::warn1( SUIT_Session::session()->activeApplication()->desktop(), - title, message, QObject::tr( "OK" ) ); + SUIT_MessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), + title, message ); } diff --git a/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx b/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx index 5cf6f399e..19bf74bed 100755 --- a/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx +++ b/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx @@ -371,20 +371,18 @@ void ToolsGUI_CatalogGeneratorDlg::onApply() if ( !XmlFile.isEmpty() && !IdlFile.isEmpty() ) { if ( !QFile::exists( IdlFile ) ) { - SUIT_MessageBox::error1( this, - tr("TOOLS_ERR_ERROR"), - tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile), - tr ("TOOLS_BUT_OK") ); + SUIT_MessageBox::critical( this, + tr("TOOLS_ERR_ERROR"), + tr("TOOLS_ERR_FILE_NOT_EXIST").arg(IdlFile) ); } else { QString command = ""; if ( getenv("KERNEL_ROOT_DIR") ) command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile; else { - SUIT_MessageBox::error1( this, - tr("TOOLS_ERR_ERROR"), - tr("KERNEL_ROOT_DIR variable is not defined"), - tr("TOOLS_BUT_OK") ); + SUIT_MessageBox::critical( this, + tr("TOOLS_ERR_ERROR"), + tr("KERNEL_ROOT_DIR variable is not defined") ); } if (!Author.isEmpty()) command += ",author=" + Author; -- 2.39.2