Salome HOME
Merge remote branch 'origin/V7_dev' into V8_0_0_BR
[modules/gui.git] / src / LightApp / LightApp_ModuleDlg.cxx
index 28b37d92fa513d1e031cbfac836c347f6e185eef..c3d22961c079640d32920ca40d02b80e48ef60d9 100644 (file)
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// File   : LightApp_ModuleDlg.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 //
-//  File   : LightApp_ModuleDlg.cxx\r
-//  Author : Michael Zorin (mzn)\r
-//  Module : LightApp\r
-\r
-#include <LightApp_ModuleDlg.h>\r
-\r
-#include <qframe.h>\r
-#include <qlabel.h>\r
-#include <qpushbutton.h>\r
-#include <qlayout.h>\r
-#include <qpixmap.h>\r
-\r
-#ifndef WIN32\r
-using namespace std;\r
-#endif\r
-\r
-/*!Default icon*/\r
-static const char* const default_icon[] = { \r
-"48 48 17 1",\r
-". c None",\r
-"# c #161e4c",\r
-"b c #1d3638",\r
-"e c #2f585b",\r
-"i c #345b5e",\r
-"c c #386266",\r
-"g c #3f7477",\r
-"d c #4d8589",\r
-"m c #519099",\r
-"o c #6abbc1",\r
-"a c #70c9d3",\r
-"f c #79ddea",\r
-"n c #7adff2",\r
-"k c #7ce2f4",\r
-"j c #993550",\r
-"h c #d84b71",\r
-"l c #ef537d",\r
-"................................................",\r
-"................................................",\r
-"................................................",\r
-"................................................",\r
-"................................................",\r
-"................########.########.########......",\r
-"...............#aaaaaa###aaaaaa###aaaaaa##......",\r
-"..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......",\r
-".............########b########b########cc#......",\r
-".............#dddddd#b#dddddd#b#dddddd#cc#......",\r
-"...........########d########d########d#cc#......",\r
-"..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......",\r
-".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......",\r
-"........########b########e########cc#d#c#.......",\r
-"........#dddddd#b#dddddd#e#ffffff#cc#d####......",\r
-"......########d########d########f#cc###g##......",\r
-".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......",\r
-"....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......",\r
-"...########b########i########jj#f#c#gg#cc#......",\r
-"...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......",\r
-"...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......",\r
-"...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......",\r
-"...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......",\r
-"...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......",\r
-"...#kkkkkk###kkkkkk###llllll####d#cc###g##......",\r
-"...########g########g########o##d#cc#gg#c#......",\r
-"....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......",\r
-"...########b########b########cc#d#c#gg#cc#......",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........",\r
-"...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........",\r
-"...########g########g########g##g#cc#...........",\r
-"....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........",\r
-"...########b########b########cc#g#c#............",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",\r
-"...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................",\r
-"...#kkkkkk###kkkkkk###kkkkkk##..................",\r
-"...########.########.########...................",\r
-"................................................",\r
-"................................................",\r
-"................................................",\r
-"................................................"};\r
-\r
-//==============================================================================================================================\r
-/*!\r
- *  LightApp_ModuleDlg::LightApp_ModuleDlg \n\r
- *\r
- *  Constructor.\r
- */\r
-//==============================================================================================================================\r
-LightApp_ModuleDlg::LightApp_ModuleDlg ( QWidget * parent, const QString& component, const QPixmap icon )\r
-     : QDialog ( parent, "ActivateModuleDlg", true,  WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )\r
-{\r
-  QPixmap defaultIcon( ( const char** ) default_icon );\r
-  setCaption( tr( "CAPTION" ) );\r
-  setSizeGripEnabled( TRUE );\r
-  \r
-  QGridLayout* ActivateModuleDlgLayout = new QGridLayout( this ); \r
-  ActivateModuleDlgLayout->setMargin( 11 ); ActivateModuleDlgLayout->setSpacing( 6 );\r
-\r
-  // Module's name and icon\r
-  myComponentFrame = new QFrame( this, "myComponentFrame" );\r
-  myComponentFrame->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ) );\r
-  myComponentFrame->setMinimumHeight( 100 );\r
-  myComponentFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );\r
-  \r
-  QGridLayout* myComponentFrameLayout = new QGridLayout( myComponentFrame ); \r
-  myComponentFrameLayout->setMargin( 11 ); myComponentFrameLayout->setSpacing( 6 );\r
-\r
-  // --> icon\r
-  myComponentIcon = new QLabel( myComponentFrame, "myComponentIcon" );\r
-  myComponentIcon->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );\r
-  myComponentIcon->setPixmap( !icon.isNull() ? icon : defaultIcon );\r
-  myComponentIcon->setScaledContents( false );\r
-  myComponentIcon->setAlignment( AlignCenter );\r
-  // --> name\r
-  myComponentLab = new QLabel( component, myComponentFrame, "myComponentLab" );\r
-  QFont fnt = myComponentLab->font(); fnt.setBold( TRUE ); myComponentLab->setFont( fnt ); \r
-  myComponentLab->setAlignment( AlignCenter );\r
-\r
-  myComponentFrameLayout->addWidget( myComponentIcon, 0, 0 );\r
-  myComponentFrameLayout->addWidget( myComponentLab,  0, 1 );\r
-\r
-  // Info\r
-  QVBoxLayout* infoLayout = new QVBoxLayout();\r
-  infoLayout->setMargin( 0 ); infoLayout->setSpacing( 6 );\r
-  \r
-  // --> top line\r
-  QFrame* myLine1 = new QFrame( this, "myLine1" );\r
-  myLine1->setFrameStyle( QFrame::HLine | QFrame::Plain );\r
-  // --> info label  \r
-  myInfoLabel = new QLabel( tr ("ActivateComponent_DESCRIPTION"), this, "myInfoLabel" );\r
-  myInfoLabel->setAlignment( AlignCenter );\r
-  // --> bottom line\r
-  QFrame*  myLine2 = new QFrame( this, "myLine2" );\r
-  myLine2->setFrameStyle( QFrame::HLine | QFrame::Plain );\r
-  \r
-  infoLayout->addStretch();\r
-  infoLayout->addWidget( myLine1 );\r
-  infoLayout->addWidget( myInfoLabel );\r
-  infoLayout->addWidget( myLine2 );\r
-  infoLayout->addStretch();\r
-  \r
-  // Buttons\r
-  QHBoxLayout* btnLayout = new QHBoxLayout(); \r
-  btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 );\r
-  \r
-  // --> New\r
-  myNewBtn = new QPushButton( tr( "NEW" ), this, "myNewBtn" );\r
-  myNewBtn->setDefault( true ); myNewBtn->setAutoDefault( true );\r
-  // --> Open\r
-  myOpenBtn = new QPushButton( tr( "OPEN" ), this, "myOpenBtn" );\r
-  myOpenBtn->setAutoDefault( true );\r
-  // --> Load\r
-  myLoadBtn = new QPushButton( tr( "LOAD" ), this, "myLoadBtn" );\r
-  myLoadBtn->setAutoDefault( true );\r
-  // --> Cancel\r
-  myCancelBtn = new QPushButton( tr( "CANCEL" ), this, "myCancelBtn" );\r
-  myCancelBtn->setAutoDefault( true );\r
-  \r
-  btnLayout->addWidget( myNewBtn );\r
-  btnLayout->addWidget( myOpenBtn );\r
-  btnLayout->addWidget( myLoadBtn );\r
-  btnLayout->addStretch();\r
-  btnLayout->addSpacing( 70 );\r
-  btnLayout->addStretch();\r
-  btnLayout->addWidget( myCancelBtn );\r
-\r
-  ActivateModuleDlgLayout->addWidget(          myComponentFrame, 0,    0    );\r
-  ActivateModuleDlgLayout->addLayout(          infoLayout,       0,    1    );\r
-  ActivateModuleDlgLayout->addMultiCellLayout( btnLayout,        1, 1, 0, 1 );\r
-\r
-  // signals and slots connections\r
-  connect( myNewBtn,    SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );\r
-  connect( myOpenBtn,   SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );\r
-  connect( myLoadBtn,   SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );\r
-  connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );\r
-}\r
-\r
-//==============================================================================================================================\r
-/*!\r
- *  LightApp_ModuleDlg::onButtonClicked\r
- *\r
- *  Buttons slot\r
- */\r
-//==============================================================================================================================\r
-void LightApp_ModuleDlg::onButtonClicked()\r
-{\r
-  QPushButton* btn = ( QPushButton* )sender();\r
-  if ( btn == myNewBtn )\r
-    done( 1 );\r
-  if ( btn == myOpenBtn )\r
-    done( 2 );\r
-  if ( btn == myLoadBtn )\r
-    done( 3 );\r
-}\r
+#include "LightApp_ModuleDlg.h"
+
+#include <QLabel>
+#include <QPushButton>
+#include <QGridLayout>
+#include <QHBoxLayout>
+
+/*!
+  \brief Pixmap used as default icon for the module.
+  \internal
+*/
+static const char* const default_icon[] = { 
+"48 48 17 1",
+". c None",
+"# c #161e4c",
+"b c #1d3638",
+"e c #2f585b",
+"i c #345b5e",
+"c c #386266",
+"g c #3f7477",
+"d c #4d8589",
+"m c #519099",
+"o c #6abbc1",
+"a c #70c9d3",
+"f c #79ddea",
+"n c #7adff2",
+"k c #7ce2f4",
+"j c #993550",
+"h c #d84b71",
+"l c #ef537d",
+"................................................",
+"................................................",
+"................................................",
+"................................................",
+"................................................",
+"................########.########.########......",
+"...............#aaaaaa###aaaaaa###aaaaaa##......",
+"..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......",
+".............########b########b########cc#......",
+".............#dddddd#b#dddddd#b#dddddd#cc#......",
+"...........########d########d########d#cc#......",
+"..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......",
+".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......",
+"........########b########e########cc#d#c#.......",
+"........#dddddd#b#dddddd#e#ffffff#cc#d####......",
+"......########d########d########f#cc###g##......",
+".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......",
+"....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......",
+"...########b########i########jj#f#c#gg#cc#......",
+"...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......",
+"...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......",
+"...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......",
+"...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......",
+"...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......",
+"...#kkkkkk###kkkkkk###llllll####d#cc###g##......",
+"...########g########g########o##d#cc#gg#c#......",
+"....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......",
+"...########b########b########cc#d#c#gg#cc#......",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........",
+"...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........",
+"...########g########g########g##g#cc#...........",
+"....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........",
+"...########b########b########cc#g#c#............",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
+"...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................",
+"...#kkkkkk###kkkkkk###kkkkkk##..................",
+"...########.########.########...................",
+"................................................",
+"................................................",
+"................................................",
+"................................................"};
+
+/*!
+  \class LightApp_ModuleDlg
+  \brief A dialog box allowing to select study operation to be performed
+  on the module activating.
+
+  The dialog box is shown when the user tries to activate any module
+  while there is no opened study. The dialog box proposes user to select
+  one of the possible operations which should be done before module activating,
+  for example, create new study or open study from the file.
+  The available operations are assigned by adding the buttons with the unique
+  identifier to the dialog box. When the user clicks any operation button,
+  the dialog box sets its identifier as the return code and closes.
+
+  The typical usage of the dialog box:
+  \code
+  LightApp_ModuleDlg dlg( desktop() );
+  dlg.addButton( "New study", NewStudyId );
+  dlg.addButton( "Open study...", OpenStudyId );
+  int ret = dlg.exec();
+  switch( ret ) {
+  case NewStudyId:
+    // create new study
+    createNewStudy();
+    break;
+  case OpenStudyId:
+    // open study from the file
+    // ... show dialog box to choose the file
+    QString fileName = QFileDialog::getOpenFileName( desktop(), "Open File" );
+    if ( !fileName.isEmpty() )
+      openStudy( fileName );
+    break;
+  default:
+    // operation is cancelled
+    break;
+  }
+  \endcode
+
+  \sa addButton()
+*/
+
+/*!
+  \brief Constructor.
+  \param parent parent widget
+  \param component module name
+  \param icon module icon
+*/
+LightApp_ModuleDlg::LightApp_ModuleDlg( QWidget*       parent, 
+                                        const QString& component, 
+                                        const QPixmap& icon )
+: QDialog ( parent )
+{
+  setModal( true );
+
+  QPixmap defaultIcon( default_icon );
+  setWindowTitle( tr( "CAPTION" ) );
+  
+  // icon
+  QLabel* iconLab = new QLabel( this );
+  iconLab->setFrameStyle( QFrame::Box | QFrame::Sunken );
+  iconLab->setMinimumSize( 70, 70 );
+  iconLab->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
+  iconLab->setPixmap( !icon.isNull() ? icon : defaultIcon );
+  iconLab->setScaledContents( false );
+  iconLab->setAlignment( Qt::AlignCenter );
+
+  // info message
+  QLabel* infoLab = new QLabel( tr ( "DESCRIPTION" ).arg( component ), this );
+  infoLab->setTextFormat( Qt::RichText );
+  infoLab->setAlignment( Qt::AlignCenter );
+  
+  // Buttons
+  myButtonLayout = new QHBoxLayout(); 
+  myButtonLayout->setMargin( 0 ); 
+  myButtonLayout->setSpacing( 6 );
+
+  // <Cancel>
+  QPushButton* cancelBtn = new QPushButton( tr( "CANCEL" ), this );
+  cancelBtn->setAutoDefault( true );
+
+  myButtonLayout->addSpacing( 70 );
+  myButtonLayout->addStretch();
+  myButtonLayout->addWidget( cancelBtn );
+
+  QGridLayout* layout = new QGridLayout( this ); 
+  layout->setMargin( 11 );
+  layout->setSpacing( 6 );
+
+  layout->addWidget( iconLab, 0, 0 );
+  layout->addWidget( infoLab, 0, 1 );
+  layout->addLayout( myButtonLayout, 1, 0, 1, 2 );
+
+  // signals and slots connections
+  connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
+}
+
+/*!
+  \brief Destructor.
+*/
+LightApp_ModuleDlg::~LightApp_ModuleDlg()
+{
+}
+
+/*!
+  \brief Add operation button to the dialog box.
+
+  If the parameter \a id is equal to -1, then the 
+  button identifier is generated automatically.
+
+  \param button button text
+  \param id button identifier
+  \return button identifier
+*/
+int LightApp_ModuleDlg::addButton( const QString& button, const int id )
+{
+  static int lastId = 0;
+  int bid = id == -1 ? --lastId : id;
+
+  QPushButton* b = findButton( bid );
+  if ( b ) {
+    myButtons.remove( b );
+    delete b;
+  }
+
+  QPushButton* newButton = new QPushButton( button, this );
+  newButton->setAutoDefault( true );
+
+  if ( myButtons.empty() ) {
+       newButton->setDefault( true );
+       newButton->setFocus();
+  }
+
+  myButtons.insert( newButton, bid );
+  myButtonLayout->insertWidget( myButtonLayout->count()-3, newButton );
+  connect( newButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
+
+  return bid;
+}
+
+/*!
+  \brief Search button with the specified identifier.
+  \param id button identifier
+  \return button or 0 if \a id is invalid
+*/
+QPushButton* LightApp_ModuleDlg::findButton( const int id ) const
+{
+  QPushButton* btn = 0;
+  for ( ButtonMap::ConstIterator it = myButtons.begin(); 
+        it != myButtons.end() && !btn; ++it ) {
+    if ( it.value() == id )
+      btn = it.key();
+  }
+  return btn;
+}
+
+/*!
+  \brief Called when any dialog button (except \c Cancel) 
+  is clicked.
+  
+  Closes the dialog and sets its result code to the identifier
+  of the button clicked by the user.
+*/
+void LightApp_ModuleDlg::accept()
+{
+  QPushButton* btn = ( QPushButton* )sender();
+  done( myButtons[ btn ] );
+}