Salome HOME
Splash screen was implemented. Changes in packages SUIT and Session are integrated.
[modules/gui.git] / src / ObjBrowser / OB_Browser.cxx
index fe451d4b1ee423890ba926da32c676db6f0fefb6..2208b59c4099b39b52cf25e2d40a1a6a14857fdf 100755 (executable)
@@ -82,6 +82,7 @@ myRootDecorated( true )
   myView->setRootIsDecorated( true );
   myView->setSelectionMode( QListView::Extended );
   myView->installEventFilter( this );
+  myView->viewport()->installEventFilter( this );
 
   QVBoxLayout* main = new QVBoxLayout( this );
   main->addWidget( myView );
@@ -428,9 +429,22 @@ void OB_Browser::setColumnTitle( const int id, const QIconSet& icon, const QStri
     lv->setColumnText( myColumnIds[id], icon, label );
 }
 
+QString OB_Browser::nameTitle() const
+{
+  return myView->columnText( 0 );
+}
+
+QString OB_Browser::columnTitle( const int id ) const
+{
+  QString txt;
+  if ( myColumnIds.contains( id ) )
+    txt = myView->columnText( myColumnIds[id] );
+  return txt;
+}
+
 bool OB_Browser::isColumnVisible( const int id ) const
 {
-  myColumnIds.contains( id ) && myView->isShown( myColumnIds[id] );
+  return myColumnIds.contains( id ) && myView->isShown( myColumnIds[id] );
 }
 
 void OB_Browser::setColumnShown( const int id, const bool on )
@@ -441,14 +455,33 @@ void OB_Browser::setColumnShown( const int id, const bool on )
   myView->setShown( myColumnIds[id], on );
 }
 
-void OB_Browser::updateTree( SUIT_DataObject* o )
+QValueList<int> OB_Browser::columns() const
 {
-  updateTree( o ? o : getRootObject(), false );
+  QValueList<int> lst;
+  for ( QMap<int, int>::ConstIterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
+    lst.append( it.key() );
+  return lst;
 }
 
-void OB_Browser::updateTree( SUIT_DataObject* obj, const bool notify )
+bool OB_Browser::appropriateColumn( const int id ) const
 {
-  if ( !obj )
+  bool res = false;
+  if ( myColumnIds.contains( id ) )
+    res = myView->appropriate( myColumnIds[id] );
+  return res;
+}
+
+void OB_Browser::setAppropriateColumn( const int id, const bool on )
+{
+  if ( !myColumnIds.contains( id ) )
+    return;
+
+  myView->setAppropriate( myColumnIds[id], on );
+}
+
+void OB_Browser::updateTree( SUIT_DataObject* obj )
+{
+  if ( !obj && !(obj = getRootObject()) )
     return;
 
   DataObjectKey curKey;
@@ -459,9 +492,6 @@ void OB_Browser::updateTree( SUIT_DataObject* obj, const bool notify )
 
   SUIT_DataObject* curObj = storeState( selObjs, openObjs, selKeys, openKeys, curKey );
 
-  if ( notify )
-    emit aboutRefresh();
-
   createConnections( obj );
   updateView( obj );
 
@@ -564,7 +594,7 @@ void OB_Browser::updateView( const SUIT_DataObject* theStartObj )
       createTree( it.current(), 0, 0 );
   }
   else
-    createTree( theStartObj, parent, after );
+    createTree( theStartObj, parent, after ? after : parent );
 }
 
 QListViewItem* OB_Browser::createTree( const SUIT_DataObject* obj,
@@ -580,6 +610,9 @@ QListViewItem* OB_Browser::createTree( const SUIT_DataObject* obj,
   for ( DataObjectListIterator it ( lst ); it.current(); ++it )
     createTree( it.current(), item );
 
+  if ( item )
+    item->setOpen( obj->isOpen() );
+
   return item;
 }
 
@@ -829,9 +862,9 @@ void OB_Browser::onExpand()
     expand( listViewItem( itr.current() ) );
 }
 
-void OB_Browser::onRefresh()
+void OB_Browser::onColumnVisible( int id )
 {
-  updateTree( 0, true );
+  setColumnShown( id, !isColumnVisible( id ) );
 }
 
 void OB_Browser::onDestroyed( SUIT_DataObject* obj )
@@ -887,18 +920,53 @@ void OB_Browser::updateText( QListViewItem* item )
     item->setText( it.data(), obj->text( it.key() ) );
 }
 
-bool OB_Browser::eventFilter(QObject* watched, QEvent* e)
+bool OB_Browser::eventFilter( QObject* o, QEvent* e )
 {
-  if ( watched == myView && e->type() == QEvent::ContextMenu )
+  if ( o == myView && e->type() == QEvent::ContextMenu )
   {
-    contextMenuRequest( (QContextMenuEvent*)e );
+    QContextMenuEvent* ce = (QContextMenuEvent*)e;
+    if ( ce->reason() != QContextMenuEvent::Mouse )
+      contextMenuRequest( ce );
     return true;
   }
-  return QFrame::eventFilter(watched, e);
+  if ( o == myView->viewport() && e->type() == QEvent::MouseButtonRelease )
+  {
+    QMouseEvent* me = (QMouseEvent*)e;
+    if ( me->button() == RightButton )
+    {
+      QContextMenuEvent ce( QContextMenuEvent::Mouse, me->pos(), me->globalPos(), me->state() );
+      contextMenuRequest( &ce );
+      return true;
+    }
+  }
+
+  return QFrame::eventFilter( o, e );
 }
 
 void OB_Browser::contextMenuPopup( QPopupMenu* menu )
 {
+/*  QValueList<int> cols;
+  for ( QMap<int, int>::ConstIterator it = myColumnIds.begin(); it != myColumnIds.end(); ++it )
+  {
+    if ( appropriateColumn( it.key() ) )
+      cols.append( it.key() );
+  }
+
+  uint num = menu->count();
+  menu->setCheckable( true );
+  for ( QValueList<int>::const_iterator iter = cols.begin(); iter != cols.end(); ++iter )
+  {
+    QString name = columnTitle( *iter );
+    if ( name.isEmpty() )
+      continue;
+
+    int id = menu->insertItem( name, this, SLOT( onColumnVisible( int ) ) );
+    menu->setItemChecked( id, isColumnVisible( *iter ) );
+    menu->setItemParameter( id, *iter );
+  }
+  if ( menu->count() != num )
+    menu->insertSeparator();*/
+
   DataObjectList selected;
   getSelected( selected );
 
@@ -911,7 +979,6 @@ void OB_Browser::contextMenuPopup( QPopupMenu* menu )
     menu->insertItem( tr( "MEN_EXPAND_ALL" ), this, SLOT( onExpand() ) );
     menu->insertSeparator();
   }
-  menu->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) );
 }
 
 void OB_Browser::expand( QListViewItem* item )
@@ -994,7 +1061,7 @@ void OB_Browser::openBranch( QListViewItem* item, const int level )
   item->setOpen( true );
   while ( item )
   {
-    openBranch( item, level - 1 );
+    openBranch( item->firstChild(), level - 1 );
     item = item->nextSibling();
   }
 }