1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME VTKViewer : build VTK viewer into Salome desktop
28 #include "SVTK_ComboAction.h"
31 #include <QHBoxLayout>
33 SVTK_ComboAction::SVTK_ComboAction( QObject* parent )
34 : QWidgetAction( parent )
39 SVTK_ComboAction::SVTK_ComboAction( const QString& text, QObject* parent )
40 : QWidgetAction( parent )
46 SVTK_ComboAction::~SVTK_ComboAction()
51 void SVTK_ComboAction::insertItem( const QIcon& icon, const int index )
53 if ( index < 0 || index > myIcons.size() )
54 myIcons.append( icon );
56 myIcons.insert( index, icon );
61 void SVTK_ComboAction::clear()
67 void SVTK_ComboAction::setCurrentIndex( const int id )
76 int SVTK_ComboAction::currentIndex() const
81 QWidget* SVTK_ComboAction::createWidget( QWidget* parent )
84 if ( parent->inherits("QToolBar") )
86 w = new QWidget( parent );
87 QHBoxLayout* l = new QHBoxLayout( w );
88 l->setSpacing(0); l->setMargin(0);
89 QComboBox* combo = new QComboBox( w );
90 combo->setFocusPolicy( Qt::NoFocus );
91 combo->setSizeAdjustPolicy( QComboBox::AdjustToContents );
93 l->addWidget( combo );
97 connect( combo, SIGNAL( activated( int ) ), this, SIGNAL( triggered( int ) ) );
102 void SVTK_ComboAction::update()
104 QList<QWidget*> aList = createdWidgets();
105 for ( QList<QWidget*>::const_iterator it = aList.begin(); it != aList.end(); ++it )
106 updateCombo( qFindChild<QComboBox*>(*it) );
109 void SVTK_ComboAction::updateCombo( QComboBox* combo )
111 if ( !combo ) return;
115 for ( QList<QIcon>::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it )
116 combo->addItem( *it, "" );
118 if ( combo->count() > 0 ) {
119 if ( myCurId < 0 ) myCurId = 0;
120 combo->setCurrentIndex( myCurId );