1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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/
19 // File: QtxComboBox.cxx
20 // Author: Sergey TELKOV
22 #include "QtxComboBox.h"
25 #include <qlineedit.h>
26 #include <qvaluelist.h>
28 QtxComboBox::QtxComboBox( QWidget* parent, const char* name )
29 : QComboBox( parent, name ),
32 connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
33 connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
36 QtxComboBox::QtxComboBox( bool rw, QWidget* parent, const char* name )
37 : QComboBox( rw, parent, name ),
40 connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
41 connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
44 QtxComboBox::~QtxComboBox()
48 bool QtxComboBox::isCleared() const
53 void QtxComboBox::setCleared( const bool isClear )
55 if ( myCleared == isClear )
63 lineEdit()->setText( "" );
65 lineEdit()->setText( text( currentItem() ) );
71 void QtxComboBox::setCurrentItem( int idx )
73 if ( idx < 0 || idx >= count() )
77 QComboBox::setCurrentItem( idx );
80 void QtxComboBox::setCurrentText( const QString& txt )
85 for ( int j = 0; j < count() && i == -1; j++ )
86 if ( text( j ) == txt )
88 if ( i >= 0 && i < count() )
90 else if ( editable() )
91 lineEdit()->setText( txt );
93 changeItem( txt, currentItem() );
95 QComboBox::setCurrentText( txt );
99 int QtxComboBox::currentId() const
101 return id( currentItem() );
104 void QtxComboBox::setCurrentId( int num )
106 setCurrentItem( index( num ) );
109 void QtxComboBox::paintEvent( QPaintEvent* e )
111 if ( !count() || !myCleared || editable() )
112 QComboBox::paintEvent( e );
117 void QtxComboBox::onActivated( int idx )
121 if ( myIndexId.contains( idx ) )
122 emit activatedId( myIndexId[idx] );
125 void QtxComboBox::onActivated( const QString& )
130 void QtxComboBox::resetClear()
139 void QtxComboBox::paintClear( QPaintEvent* e )
141 int curIndex = currentItem();
142 QString curText = text( curIndex );
145 if ( pixmap( curIndex ) )
146 curPix = *pixmap( curIndex );
148 bool upd = isUpdatesEnabled();
149 setUpdatesEnabled( false );
151 changeItem( "", curIndex );
152 QComboBox::paintEvent( e );
154 if ( curPix.isNull() )
155 changeItem( curText, curIndex );
157 changeItem( curPix, curText, curIndex );
159 setUpdatesEnabled( upd );
162 int QtxComboBox::id( const int idx ) const
165 if ( myIndexId.contains( idx ) )
170 int QtxComboBox::index( const int id ) const
173 for ( IndexIdMap::ConstIterator it = myIndexId.begin();
174 it != myIndexId.end() && idx == -1; ++it )
175 if ( it.data() == id )