Salome HOME
Updated copyright comment
[modules/gui.git] / src / Qtx / QtxWorkstack.cxx
index 99bc305f9d32ac57c644e19a135442d91ad722fc..6a5ba33f5e7173d72d6b2ab67fdc874155fc9128 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -528,16 +528,16 @@ QtxWorkstackArea::QtxWorkstackArea( QWidget* parent )
   base->setMargin( frameWidth() );
   base->setSpacing( 0 );
 
-  QWidget* top = new QWidget( this );
-  base->addWidget( top );
+  myTop = new QWidget( this );
+  base->addWidget( myTop );
 
-  QHBoxLayout* tl = new QHBoxLayout( top );
+  QHBoxLayout* tl = new QHBoxLayout( myTop );
   tl->setMargin( 0 );
 
-  myBar = new QtxWorkstackTabBar( top );
+  myBar = new QtxWorkstackTabBar( myTop );
   tl->addWidget( myBar, 1 );
 
-  CloseButton* close = new CloseButton( top );
+  CloseButton* close = new CloseButton( myTop );
   close->setIcon( style()->standardIcon( QStyle::SP_TitleBarCloseButton ) );
   myClose = close;
   tl->addWidget( myClose );
@@ -884,7 +884,7 @@ bool QtxWorkstackArea::restoreState( QDataStream& stream, QMap<QString, QtxWorks
     QtxWorkstackChild* c = map.contains( name ) ? map[name] : 0;
     if ( !c )
     {
-      qWarning( "QtxWorkstack: Restored child widget \"%s\" not found.", (const char*)name.toLatin1() );
+      qWarning( "QtxWorkstack: Restored child widget \"%s\" not found.", (const char*)name.toUtf8() );
       return false;
     }
 
@@ -902,6 +902,16 @@ bool QtxWorkstackArea::restoreState( QDataStream& stream, QMap<QString, QtxWorks
   return true;
 }
 
+/*!
+  \brief Show/Hide tab bar.
+*/
+void QtxWorkstackArea::showTabBar( bool visible)
+{
+  myTop->setVisible(visible);
+  myBar->setVisible(visible);
+}
+
+
 /*!
   \brief Get rectangle to be drawn when highlighting drop area.
   \return area drop rectangle
@@ -949,10 +959,15 @@ void QtxWorkstackArea::customEvent( QEvent* e )
 {
   WidgetEvent* we = (WidgetEvent*)e;
 
-  switch ( we->type() )
+  switch ( (int)we->type() )
   {
   case ActivateWidget:
     myBar->updateActiveState();
+    // IMN 27/03/2015: This workaround caused by the bug INT PAL 0052623: OCC view blinking when
+    // using polyline sketcher which is reproduced on Unix systems with qt-4.8.4.
+    myStack->setUpdatesEnabled( false );
+    updateCurrent();
+    myStack->setUpdatesEnabled( true );
     emit activated( activeWidget() );
     break;
   case FocusWidget:
@@ -1065,7 +1080,7 @@ void QtxWorkstackArea::onChildDestroyed( QObject* obj )
   \brief Called when child widget container is shown.
   \param c child widget container being shown
 */
-void QtxWorkstackArea::onChildShown( QtxWorkstackChild* c )
+void QtxWorkstackArea::onChildShown( QtxWorkstackChild* /*c*/ )
 {
   updateState();
 }
@@ -1074,7 +1089,7 @@ void QtxWorkstackArea::onChildShown( QtxWorkstackChild* c )
   \brief Called when child widget container is hidden.
   \param c child widget container being hidden
 */
-void QtxWorkstackArea::onChildHidden( QtxWorkstackChild* c )
+void QtxWorkstackArea::onChildHidden( QtxWorkstackChild* /*c*/ )
 {
   updateState();
 }
@@ -1454,7 +1469,7 @@ bool QtxWorkstackChild::eventFilter( QObject* o, QEvent* e )
   \brief Called when child widget is destroyed.
   \param obj child widget being destroyed
 */
-void QtxWorkstackChild::onDestroyed( QObject* obj )
+void QtxWorkstackChild::onDestroyed( QObject* /*obj*/ )
 {
   deleteLater();
 }
@@ -2188,7 +2203,7 @@ int QtxWorkstack::accel( const int id ) const
 {
   int res = 0;
   if ( myActionsMap.contains( id ) )
-    res = myActionsMap[id]->shortcut();
+    res = myActionsMap[id]->shortcut()[0];
   return res;
 }
 
@@ -2272,8 +2287,6 @@ static int positionSimple (QIntList& szList, const int nb, const int splitter_si
   int new_this = szList[item_ind];
   int new_next = 0;
 
-  bool isToCheck = false;
-
   if (need_pos < splitter_pos) {
     // Set size of all previous workareas to zero <--
     if (item_ind == nb - 1) {
@@ -2305,7 +2318,6 @@ static int positionSimple (QIntList& szList, const int nb, const int splitter_si
         new_this = splitter_size - new_item_rel_pos;
       }
       // jfa to do: in this case fixed size of next widgets could prevent right resizing
-      isToCheck = true;
     }
     if (item_ind == nb - 1) {
       new_this = splitter_size - new_item_rel_pos;
@@ -2636,7 +2648,7 @@ void QtxWorkstack::insertWidget( QWidget* wid, QWidget* pWid, QWidget* after )
   for ( QWidgetList::iterator itr = moveList.begin(); itr != moveList.end(); ++itr )
   {
     (*itr)->setParent( pWid );
-    (*itr)->setShown( map.contains( *itr ) ? map[*itr] : false );
+    (*itr)->setVisible( map.contains( *itr ) ? map[*itr] : false );
   }
 }
 
@@ -3112,7 +3124,7 @@ bool QtxWorkstack::restoreState( QDataStream& stream )
 
       map.insert( c->widget()->objectName(), c );
 
-      qDebug( "QtxWorkstack::restoreState: found widget \"%s\"", (const char*)c->widget()->objectName().toLatin1() );
+      qDebug( "QtxWorkstack::restoreState: found widget \"%s\"", (const char*)c->widget()->objectName().toUtf8() );
     }
   }
 
@@ -3174,6 +3186,91 @@ bool QtxWorkstack::opaqueResize() const
   return mySplit->opaqueResize();
 }
 
+/*!
+  \brief Show/hide splitter state and area.
+  \param wid widget (and parent area) will be shown/hidden
+  \param parent_list parent splitters list
+  \param split splitter will be shown/hidden
+  \param visible splitter
+*/
+void QtxWorkstack::splitterVisible(QWidget* wid, QList<QSplitter*>& parent_list, QSplitter* split, bool visible)
+{
+  QList<QSplitter*> recList;
+  splitters( split, recList, false );
+  for ( QList<QSplitter*>::iterator itr = recList.begin(); itr != recList.end(); ++itr ) {
+    parent_list.prepend( *itr );
+    splitterVisible( wid, parent_list, *itr, visible );
+  }
+
+  QList<QtxWorkstackArea*> areaList;
+  areas( split, areaList, false );
+  for ( QList<QtxWorkstackArea*>::const_iterator it = areaList.begin(); it != areaList.end(); ++it ) {
+    QtxWorkstackArea* area = *it;
+    bool isCurrentWidget = false;
+
+    area->showTabBar(visible);
+
+    // 1. Looking for the selected widget at the lowest level among all splitted areas.
+    QList<QtxWorkstackChild*> childList = area->childList();
+    for ( QList<QtxWorkstackChild*>::iterator itr = childList.begin(); itr != childList.end(); ++itr ) {
+      QWidget* aCurWid = (*itr)->widget();
+      if ( aCurWid == wid ) {
+        isCurrentWidget = true;
+        aCurWid->setVisible( true );
+      }
+      else
+        aCurWid->setVisible( visible );
+    }
+
+    // 2. Show/Hide other areas and widgets that don't contain the desired widget
+    if ( !isCurrentWidget || visible )
+      area->setVisible( visible );
+
+    if ( !isCurrentWidget && !visible )
+      continue;
+
+    // 3. Show/hide all parent widgets
+    QSplitter* pSplit = splitter( area );
+    int count = pSplit->count();
+    for ( int i = 0; i < count; i++ ) {
+      if ( pSplit->indexOf( area ) == i && !visible )
+        continue;
+      pSplit->widget(i)->setVisible( visible );
+    }
+
+    // 4. Show/hide all parent splitters don't contain the selected widget
+    if ( visible )
+      pSplit->setVisible( true );
+
+    if ( isCurrentWidget && !visible ) {
+      for ( QList<QSplitter*>::iterator itr = parent_list.begin(); itr != parent_list.end() && pSplit != mySplit; ++itr ) {
+        if ( pSplit == *itr )
+          continue;
+        QList<QSplitter*> splitList;
+        splitters( *itr, splitList, false );
+        for ( QList<QSplitter*>::iterator iter = splitList.begin(); iter != splitList.end(); ++iter ) {
+          if ( pSplit == (*iter) ) {
+            pSplit = *itr;
+            continue;
+          }
+          (*iter)->setVisible( false );
+        }
+      }
+    }
+  }
+}
+
+/*!
+  \brief Show/hide splitters state and area.
+  \param wid widget (and parent area) will be shown/hidden
+  \param visible splitters
+*/
+void QtxWorkstack::splittersVisible( QWidget* wid, bool visible )
+{
+  QList<QSplitter*> parent_list;
+  parent_list.append( mySplit );
+  splitterVisible( wid, parent_list, mySplit, visible );
+}
 
 /*!
   \fn void QtxWorkstack::windowActivated( QWidget* w )
@@ -3209,7 +3306,7 @@ QtxWorkstackArea* QtxWorkstack::wgArea( QWidget* wid ) const
   \param wid_to widget specified the destination area
   \param before specifies whether the first widget has to be moved before or after
          the second widget
-  \return TRUE if operation is completed successfully, FALSE otherwise
+  \return \c true if operation is completed successfully, \c false otherwise
 */
 bool QtxWorkstack::move( QWidget* wid, QWidget* wid_to, const bool before )
 {
@@ -3245,7 +3342,7 @@ bool QtxWorkstack::move( QWidget* wid, QWidget* wid_to, const bool before )
 
 /*!
   \brief Group all windows in one area
-  \return TRUE if operation is completed successfully, FALSE otherwise
+  \return \c true if operation is completed successfully, \c false otherwise
 */
 void QtxWorkstack::stack()
 {