Salome HOME
refs #1278: by default objects in study are not expanded
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_OrderedListWidget.cxx
index 8c23d22407f6d6e66af11030f07b6232f1d92615..a6ef3229b156335e7ff510b9012524bdf408058c 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  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) 2014-2015  EDF-R&D
 // 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.
+// 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
@@ -66,48 +62,53 @@ HYDROGUI_OrderedListWidget::HYDROGUI_OrderedListWidget( QWidget* theParent, int
 
   myList->setModel( aFilteredModel );
 
-  // Buttons top, up, down, bottom
-  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-  myTop = new QPushButton( this );
-  myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
-  myTop->setIconSize( QSize( theArrowIconSize, theArrowIconSize ) );
-  myTop->setToolTip( tr( "TOP_TLT" ) );
-  myUp = new QPushButton( this );
-  myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
-  myUp->setIconSize( myTop->iconSize() );
-  myUp->setToolTip( tr( "UP_TLT" ) );
-  myDown = new QPushButton( this );
-  myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) );
-  myDown->setIconSize( myTop->iconSize() );
-  myDown->setToolTip( tr( "DOWN_TLT" ) );
-  myBottom = new QPushButton( this );
-  myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) );
-  myBottom->setIconSize( myTop->iconSize() );
-  myBottom->setToolTip( tr( "BOTTOM_TLT" ) );
-
-  // Layout
-  // buttons
-  QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
-  aListButtonsLayout->addWidget( myTop );
-  aListButtonsLayout->addWidget( myUp );
-  aListButtonsLayout->addWidget( myDown );
-  aListButtonsLayout->addWidget( myBottom );
-  aListButtonsLayout->addStretch();
-  // main
+  // Add list to the main layout
   aMainLayout->addWidget( myList );
-  aMainLayout->addLayout( aListButtonsLayout );
-
-  // Connections
-  QSignalMapper* aSignalMapper = new QSignalMapper( this );
-  aSignalMapper->setMapping( myTop, HYDROGUI_ListModel::Top );
-  aSignalMapper->setMapping( myUp, HYDROGUI_ListModel::Up );
-  aSignalMapper->setMapping( myDown, HYDROGUI_ListModel::Down );
-  aSignalMapper->setMapping( myBottom, HYDROGUI_ListModel::Bottom );
-  connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
-  connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
+
+  // Buttons top, up, down, bottom
+  if ( theArrowIconSize > 0 ) {
+    SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+    myTop = new QPushButton( this );
+    myTop->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_TOP_ICO" ) ) );
+    myTop->setIconSize( QSize( theArrowIconSize, theArrowIconSize ) );
+    myTop->setToolTip( tr( "TOP_TLT" ) );
+    myUp = new QPushButton( this );
+    myUp->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_UP_ICO" ) ) );
+    myUp->setIconSize( myTop->iconSize() );
+    myUp->setToolTip( tr( "UP_TLT" ) );
+    myDown = new QPushButton( this );
+    myDown->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_DOWN_ICO" ) ) );
+    myDown->setIconSize( myTop->iconSize() );
+    myDown->setToolTip( tr( "DOWN_TLT" ) );
+    myBottom = new QPushButton( this );
+    myBottom->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "ARROW_BOTTOM_ICO" ) ) );
+    myBottom->setIconSize( myTop->iconSize() );
+    myBottom->setToolTip( tr( "BOTTOM_TLT" ) );
+
+    // Add buttons to the main layout
+    QVBoxLayout* aListButtonsLayout = new QVBoxLayout();
+    aListButtonsLayout->addWidget( myTop );
+    aListButtonsLayout->addWidget( myUp );
+    aListButtonsLayout->addWidget( myDown );
+    aListButtonsLayout->addWidget( myBottom );
+    aListButtonsLayout->addStretch();
+    
+    aMainLayout->addLayout( aListButtonsLayout );
+
+    // Buttons connections
+    QSignalMapper* aSignalMapper = new QSignalMapper( this );
+    aSignalMapper->setMapping( myTop, HYDROGUI_ListModel::Top );
+    aSignalMapper->setMapping( myUp, HYDROGUI_ListModel::Up );
+    aSignalMapper->setMapping( myDown, HYDROGUI_ListModel::Down );
+    aSignalMapper->setMapping( myBottom, HYDROGUI_ListModel::Bottom );
+    connect( myTop, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
+    connect( myUp, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
+    connect( myDown, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
+    connect( myBottom, SIGNAL( clicked() ), aSignalMapper, SLOT( map() ) );
+    connect( aSignalMapper, SIGNAL( mapped( int ) ), this, SLOT( onMove( int ) ) );
+  } else {
+    myTop = myUp = myDown = myBottom = 0;
+  }
 
   connect ( myList->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), 
             this, SIGNAL( selectionChanged() ) );
@@ -136,6 +137,31 @@ void HYDROGUI_OrderedListWidget::setObjects( const HYDROGUI_ListModel::Object2Vi
   }
 }
 
+void HYDROGUI_OrderedListWidget::setBackgroundColor (int theInd, QColor theColor)
+{
+  HYDROGUI_ListModel* aModel = getSourceModel();
+  if( aModel ) {
+    aModel->setBackgroundColor( theInd, theColor );
+  }
+}
+
+void HYDROGUI_OrderedListWidget::clearAllBackgroundColors ()
+{
+  HYDROGUI_ListModel* aModel = getSourceModel();
+  if( aModel ) {
+    aModel->clearAllBackgroundColors( );
+  }
+}
+
+
+ QColor HYDROGUI_OrderedListWidget::getBackgroundColor (int theInd) const
+ {
+   HYDROGUI_ListModel* aModel = getSourceModel();
+   if( aModel ) {
+     return aModel->getBackgroundColor( theInd );
+   }
+ }
+
 /**
   Returns the ordered list of objects.
   @return the list of objects
@@ -327,7 +353,8 @@ void HYDROGUI_OrderedListWidget::onMove( int theType )
     }
   }
 
-  if ( isMoved ) {
+  if ( isMoved )
+  {
     emit orderChanged();
   }
 }
@@ -355,11 +382,20 @@ HYDROGUI_ListModel* HYDROGUI_OrderedListWidget::getSourceModel() const
 void HYDROGUI_OrderedListWidget::setOrderingEnabled( const bool theIsToEnable )
 {
   // enable/disable arrow buttons
-  myTop->setEnabled( theIsToEnable );
-  myUp->setEnabled( theIsToEnable );
-  myDown->setEnabled( theIsToEnable );
-  myBottom->setEnabled( theIsToEnable );
+  if ( myTop && myUp && myDown && myBottom ) {
+    myTop->setEnabled( theIsToEnable );
+    myUp->setEnabled( theIsToEnable );
+    myDown->setEnabled( theIsToEnable );
+    myBottom->setEnabled( theIsToEnable );
+  }
 
   // enable/disable drag and drop
   myList->setDragEnabled( theIsToEnable );
-}
\ No newline at end of file
+}
+
+void HYDROGUI_OrderedListWidget::undoLastMove()
+{
+  HYDROGUI_ListModel* aModel = getSourceModel();
+  if( aModel )
+    aModel->undoLastMove();
+}