1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SALOME VTKViewer : build VTK viewer into Salome desktop
24 #include "SVTK_ComboAction.h"
27 #include <QHBoxLayout>
29 SVTK_ComboAction::SVTK_ComboAction( QObject* parent )
30 : QWidgetAction( parent )
35 SVTK_ComboAction::SVTK_ComboAction( const QString& text, QObject* parent )
36 : QWidgetAction( parent )
42 SVTK_ComboAction::~SVTK_ComboAction()
47 void SVTK_ComboAction::insertItem( const QIcon& icon, const int index )
49 if ( index < 0 || index > myIcons.size() )
50 myIcons.append( icon );
52 myIcons.insert( index, icon );
57 void SVTK_ComboAction::clear()
63 void SVTK_ComboAction::setCurrentIndex( const int id )
72 int SVTK_ComboAction::currentIndex() const
77 QWidget* SVTK_ComboAction::createWidget( QWidget* parent )
80 if ( parent->inherits("QToolBar") )
82 w = new QWidget( parent );
83 QHBoxLayout* l = new QHBoxLayout( w );
84 l->setSpacing(0); l->setMargin(0);
85 QComboBox* combo = new QComboBox( w );
86 combo->setFocusPolicy( Qt::NoFocus );
87 combo->setSizeAdjustPolicy( QComboBox::AdjustToContents );
89 l->addWidget( combo );
93 connect( combo, SIGNAL( activated( int ) ), this, SIGNAL( triggered( int ) ) );
98 void SVTK_ComboAction::update()
100 QList<QWidget*> aList = createdWidgets();
101 for ( QList<QWidget*>::const_iterator it = aList.begin(); it != aList.end(); ++it )
102 updateCombo( qFindChild<QComboBox*>(*it) );
105 void SVTK_ComboAction::updateCombo( QComboBox* combo )
107 if ( !combo ) return;
111 for ( QList<QIcon>::const_iterator it = myIcons.begin(); it != myIcons.end(); ++it )
112 combo->addItem( *it, "" );
114 if ( combo->count() > 0 ) {
115 if ( myCurId < 0 ) myCurId = 0;
116 combo->setCurrentIndex( myCurId );