Salome HOME
Merge remote-tracking branch 'origin/fbt/fix_french_translation'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshDlg.cxx
index 0716cdd8e447e91ed682f1073995574f75c40203..0c492b5d7ffd317f3a3a977c9b43c0b39c574017 100644 (file)
@@ -30,6 +30,7 @@
 // SALOME GUI includes
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
+#include <QtxMenu.h>
 
 // Qt includes
 #include <QComboBox>
@@ -163,19 +164,32 @@ SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
  *  \param [in] txt - item text
  *  \param [in] type - HypType
  *  \param [in] index - index of item in a list of items
+ *  \param [in] isGroup - is the item a group title
  */
 //================================================================================
-
-void SMESHGUI_MeshTab::addItem( const QString& txt, const int type, const int index )
+void SMESHGUI_MeshTab::addItem( const QString& txt,
+                                const int      type,
+                                const int      index,
+                                const bool     isGroup )
 {
+  const char* prefix = "  ";
   if ( type <= AddHyp )
   {
-    myHypCombo[ type ]->addItem( txt, QVariant( index ));
-    myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) );
+    if ( isGroup )
+    {
+      int idx = myHypCombo[ type ]->count();
+      myHypCombo[ type ]->addItem( txt.mid( 6 ), QVariant( index ));
+      myHypCombo[ type ]->setItemData( idx, "separator", Qt::AccessibleDescriptionRole );
+    }
+    else
+    {
+      myHypCombo[ type ]->addItem( prefix + txt, QVariant( index ));
+    }
+    //myHypCombo[ type ]->setMaxVisibleItems( qMax( 10, myHypCombo[ type ]->count() ) );
   }
   else
   {
-    QListWidgetItem* item = new QListWidgetItem( txt, myAddHypList );
+    QListWidgetItem* item = new QListWidgetItem( prefix + txt, myAddHypList );
     item->setData( Qt::UserRole, QVariant( index ));
   }
 }
@@ -185,7 +199,6 @@ void SMESHGUI_MeshTab::addItem( const QString& txt, const int type, const int in
  * \brief Returns index of hyp of a given type
  */
 //================================================================================
-
 int SMESHGUI_MeshTab::getCurrentIndex( const int type, const bool curByType ) const
 {
   if ( type <= AddHyp )
@@ -222,7 +235,7 @@ void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& the
     {
       addItem( tr( "NONE"), Algo, 0 );
       for ( int i = 0, nbHyp = theHyps.count(); i < nbHyp; ++i )
-        addItem( theHyps[i], Algo, i+1 );
+        addItem( theHyps[i], Algo, i+1, theHyps[i].startsWith( "GROUP:" ));
       myHypCombo[ Algo ]->setCurrentIndex( 0 );
     }
   }
@@ -296,24 +309,6 @@ void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
     myMoreAddHypBtn->setEnabled( true );
 }
 
-//================================================================================
-/*!
- * \brief Renames hypothesis
- * \param theId - identifier of hypothesis (main or additional, see HypType enumeration)
- * \param theIndex - index of hypothesis to be renamed
- * \param theNewName - new name of hypothesis to be renamed
- *
- * Renames hypothesis
- */
-//================================================================================
-// void SMESHGUI_MeshTab::renameHyp( const int theId,
-//                                   const int theIndex,
-//                                   const QString& theNewName )
-// {
-//   if ( theIndex > 0 && theIndex < myHypCombo[ theId ]->count() )
-//     myHypCombo[ theId ]->setItemText( theIndex, theNewName );
-// }
-
 //================================================================================
 /*!
  * \brief Sets current hypothesis
@@ -382,7 +377,6 @@ int SMESHGUI_MeshTab::currentHyp( const int theId ) const
  * range 0 <= i < this->nbAddHypTypes()
  */
 //================================================================================
-
 int SMESHGUI_MeshTab::nbAddHypTypes() const
 {
   return myAddHypList->count();
@@ -400,15 +394,25 @@ void SMESHGUI_MeshTab::onCreateHyp()
 {
   bool isMainHyp = ( sender() == myCreateHypBtn[ MainHyp ]);
 
-  QMenu aPopup( this );
+  QtxMenu aPopup( this );
   
   QStringList aHypNames = isMainHyp ? 
     myAvailableHypTypes[ MainHyp ] : myAvailableHypTypes[ AddHyp ];
 
   QList<QAction*> actions;
   for ( int i = 0, n = aHypNames.count(); i < n; i++ )
-    actions.append( aPopup.addAction( aHypNames[ i ] ) );
-
+  {
+    QAction* a = 0;
+    if ( aHypNames[ i ].startsWith( "GROUP:" ))
+    {
+      aPopup.appendGroupTitle( aHypNames[ i ].mid( 6 ));
+    }
+    else
+    {
+      a = aPopup.addAction( aHypNames[ i ] );
+    }
+    actions.append( a );
+  }
   QAction* a = aPopup.exec( QCursor::pos() );
   if ( a )
     emit createHyp( isMainHyp ? MainHyp : AddHyp, actions.indexOf( a ) );
@@ -444,7 +448,18 @@ void SMESHGUI_MeshTab::onEditHyp()
 //================================================================================
 void SMESHGUI_MeshTab::onHyp( int theIndex )
 {
-  const QObject* aSender = sender();
+  QObject* aSender = sender();
+
+  if ( QComboBox* cb = qobject_cast< QComboBox* >( aSender ))
+  {
+    // don't allow selecting a group title
+    if ( cb->itemData( theIndex, Qt::AccessibleDescriptionRole ) == "separator" )
+    {
+      cb->setCurrentIndex( theIndex+1 );
+      return;
+    }
+  }
+
   if ( aSender == myHypCombo[ Algo ] )
   {
     emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
@@ -471,7 +486,6 @@ void SMESHGUI_MeshTab::onHyp( int theIndex )
  * SLOT called when myMoreAddHypBtn ("plus") clicked
  */
 //================================================================================
-
 void SMESHGUI_MeshTab::onMoreAddHyp()
 {
   int hypIndex = currentHyp( AddHyp );
@@ -496,7 +510,6 @@ void SMESHGUI_MeshTab::onMoreAddHyp()
  * SLOT called when myLessAddHypBtn ("minus") clicked
  */
 //================================================================================
-
 void SMESHGUI_MeshTab::onLessAddHyp()
 {
   if ( QListWidgetItem * item = myAddHypList->currentItem() )
@@ -624,12 +637,31 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh
     objectWg( Mesh, Btn )->hide();
     objectWg( Geom, Btn )->hide();
   }
+  setTitile( theToCreate, theIsMesh );
 }
 
 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
 {
 }
 
+//================================================================================
+/*!
+ * \brief Set dialog title
+ */
+//================================================================================
+void SMESHGUI_MeshDlg::setTitile( const bool theToCreate, const bool theIsMesh )
+{
+  if ( theToCreate )
+  {
+    setWindowTitle( tr( theIsMesh ? "CREATE_MESH" : "CREATE_SUBMESH" ));
+  }
+  else
+  {
+    setWindowTitle( tr( theIsMesh ? "EDIT_MESH" : "EDIT_SUBMESH") );
+  }
+  
+}
+
 //================================================================================
 /*!
  * \brief Gets tab with given id
@@ -675,7 +707,6 @@ void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
   * \param int - maximum possible dimention
  */
 //================================================================================
-
 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
 {
   const int DIM = maxDim;
@@ -699,7 +730,6 @@ void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
  * \brief Sets list of available Sets of Hypotheses
  */
 //================================================================================
-
 void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
 {
   QMenu* aHypoSetPopup = myHypoSetButton->menu();
@@ -724,7 +754,6 @@ void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
  * signal to notify operation about this event
  */
 //================================================================================
-
 void SMESHGUI_MeshDlg::onHypoSetPopup( QAction* a )
 {
   emit hypoSet( a->text() );
@@ -769,9 +798,9 @@ void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
  * \param int - tab ID
  */
 //================================================================================
-void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
+void SMESHGUI_MeshDlg::disableTab(const int theTabId)
+{
   myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), false );
-  if ( theTabId == Dim3D ) myHypoSetButton->setEnabled( false );
 }
 
 //================================================================================
@@ -780,7 +809,8 @@ void SMESHGUI_MeshDlg::disableTab(const int theTabId) {
  * \param int - tab ID
  */
 //================================================================================
-void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
+void SMESHGUI_MeshDlg::enableTab(const int theTabId)
+{
   myTabWg->setTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ), true );
   if ( theTabId == Dim3D ) {
     QMenu* aHypoSetPopup = myHypoSetButton->menu();
@@ -794,21 +824,37 @@ void SMESHGUI_MeshDlg::enableTab(const int theTabId) {
  * \param int - tab ID
  */
 //================================================================================
-bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const {
+bool SMESHGUI_MeshDlg::isTabEnabled(const int theTabId) const
+{
   return myTabWg->isTabEnabled( myTabWg->indexOf( myTabs[ theTabId ] ) );
 }
 
+//================================================================================
+/*!
+ * \brief SLOT called when a Geom selection button is clicked
+ */
+//================================================================================
 void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
 {
   if ( myGeomPopup && isBtnOn )
     myGeomPopup->exec( QCursor::pos() );
 }
 
+//================================================================================
+/*!
+ * \brief SLOT called when a item of Geom selection popup is choosen
+ */
+//================================================================================
 void SMESHGUI_MeshDlg::onGeomPopup( QAction* a )
 {
   emit geomSelectionByMesh( a->data().toInt() == GEOM_BY_MESH_INDEX );
 }
 
+//================================================================================
+/*!
+ * \brief Return ID of an active selection button
+ */
+//================================================================================
 int SMESHGUI_MeshDlg::getActiveObject()
 {
   for (int i = 0; i < 3; ++i )