-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// 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
+// 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 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, 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.
+// 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
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// 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/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
#include "SUIT_MessageBox.h"
#include "SUIT_OverrideCursor.h"
// 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 );
+ SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+ SUIT_MessageBox::No );
if ( result == SUIT_MessageBox::Yes )
overwriteFileFunction();
// 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);
+ "Hide", "Run Away", "Stand still", 1, 2);
switch ( result )
{
case 0:
// 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");
+ 0, 0,
+ "Zero", "One", "Two", "Three", "Four", "Five");
useMyFavouriteNumberSomewhere( result );
\endcode
*/
\return button id clicked by the user (QMessageBox::StandardButton)
*/
int SUIT_MessageBox::critical( QWidget* parent, const QString& title, const QString& text,
- const QString& button )
+ const QString& button )
{
ButtonInfos lst;
lst.append( ButtonInfo( 0, button ) );
\return button id clicked by the user (QMessageBox::StandardButton)
*/
int SUIT_MessageBox::warning( QWidget* parent, const QString& title, const QString& text,
- const QString& button )
+ const QString& button )
{
ButtonInfos lst;
lst.append( ButtonInfo( 0, button ) );
\return button id clicked by the user (QMessageBox::StandardButton)
*/
int SUIT_MessageBox::information( QWidget* parent, const QString& title, const QString& text,
- const QString& button )
+ const QString& button )
{
ButtonInfos lst;
lst.append( ButtonInfo( 0, button ) );
\return button id clicked by the user (QMessageBox::StandardButton)
*/
int SUIT_MessageBox::question( QWidget* parent, const QString& title, const QString& text,
- const QString& button )
+ const QString& button )
{
ButtonInfos lst;
lst.append( ButtonInfo( 0, 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 )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ const QString& button1, const QString& button2,
+ const QString& button3,
+ const int defaultButton, const int escapeButton )
{
ButtonInfos lst;
int id = 0;
lst.append( ButtonInfo( id++, button2 ) );
lst.append( ButtonInfo( id++, button3 ) );
return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ const QString& button1, const QString& button2,
+ const QString& button3,
+ const int defaultButton, const int escapeButton )
{
ButtonInfos lst;
int id = 0;
lst.append( ButtonInfo( id++, button2 ) );
lst.append( ButtonInfo( id++, button3 ) );
return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ const QString& button1, const QString& button2,
+ const QString& button3,
+ const int defaultButton, const int escapeButton )
{
ButtonInfos lst;
int id = 0;
lst.append( ButtonInfo( id++, button2 ) );
lst.append( ButtonInfo( id++, button3 ) );
return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ const QString& button1, const QString& button2,
+ const QString& button3,
+ const int defaultButton, const int escapeButton )
{
ButtonInfos lst;
int id = 0;
lst.append( ButtonInfo( id++, button2 ) );
lst.append( ButtonInfo( id++, button3 ) );
return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ 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++, button3 ) );
lst.append( ButtonInfo( id++, button4 ) );
return messageBox( SUIT_MessageBox::Critical, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ 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++, button3 ) );
lst.append( ButtonInfo( id++, button4 ) );
return messageBox( SUIT_MessageBox::Warning, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ 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++, button3 ) );
lst.append( ButtonInfo( id++, button4 ) );
return messageBox( SUIT_MessageBox::Information, parent, title, text, lst,
- defaultButton, escapeButton );
+ defaultButton, escapeButton );
}
/*!
\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 QString& button4,
- const int defaultButton, const int escapeButton )
+ 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++, button3 ) );
lst.append( ButtonInfo( id++, button4 ) );
return messageBox( SUIT_MessageBox::Question, parent, title, text, lst,
- defaultButton, escapeButton );
+ 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.
+
+ 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.
+
+ 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.
+
+ 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.
+
+ 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 );
}
/*!
\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, ... )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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, ... )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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, ... )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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, ... )
+ 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 );
+ defaultButton, escapeButton );
}
/*!
\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 )
+ const QString& title, const QString& text,
+ const ButtonInfos& lst,
+ const int defaultButton,
+ const int escapeButton )
{
SUIT_MessageBox msgBox( icon, title, text, NoButton, parent );
QPushButton* pb = msgBox.addButton( txt, role );
bm.insert( pb, btn );
- if ( defaultButton == -1 && i == 0 || btn == defaultButton )
+ if ( ( defaultButton == -1 && i == 0 ) || btn == defaultButton )
msgBox.setDefaultButton( pb );
- if ( escapeButton == -1 && i == lst.count() - 1 || btn == escapeButton )
+ if ( ( escapeButton == -1 && i == lst.count() - 1 ) || btn == escapeButton )
msgBox.setEscapeButton( pb );
}