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/ or email : webmaster.salome@opencascade.com
19 // File: QtxComboBox.cxx
20 // Author: Sergey TELKOV
22 #include "QtxComboBox.h"
25 #include <qlineedit.h>
26 #include <qvaluelist.h>
31 QtxComboBox::QtxComboBox( QWidget* parent, const char* name )
32 : QComboBox( parent, name ),
35 connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
36 connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
42 QtxComboBox::QtxComboBox( bool rw, QWidget* parent, const char* name )
43 : QComboBox( rw, parent, name ),
46 connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
47 connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
53 QtxComboBox::~QtxComboBox()
58 \return true if combobox is cleared
60 bool QtxComboBox::isCleared() const
67 \param isClear - new status
69 void QtxComboBox::setCleared( const bool isClear )
71 if ( myCleared == isClear )
79 lineEdit()->setText( "" );
81 lineEdit()->setText( text( currentItem() ) );
88 Sets currently selected item
89 \param idx - index of item
91 void QtxComboBox::setCurrentItem( int idx )
93 if ( idx < 0 || idx >= count() )
97 QComboBox::setCurrentItem( idx );
102 \param txt - new current text
104 void QtxComboBox::setCurrentText( const QString& txt )
109 for ( int j = 0; j < count() && i == -1; j++ )
110 if ( text( j ) == txt )
112 if ( i >= 0 && i < count() )
114 else if ( editable() )
115 lineEdit()->setText( txt );
117 changeItem( txt, currentItem() );
119 QComboBox::setCurrentText( txt );
124 \return current selected id
126 int QtxComboBox::currentId() const
128 return id( currentItem() );
132 Sets current selected id
134 void QtxComboBox::setCurrentId( int num )
136 setCurrentItem( index( num ) );
140 Custom paint event handler
142 void QtxComboBox::paintEvent( QPaintEvent* e )
144 if ( !count() || !myCleared || editable() )
145 QComboBox::paintEvent( e );
151 SLOT: called if some item is activated
152 \param idx - index of activated item
154 void QtxComboBox::onActivated( int idx )
158 if ( myIndexId.contains( idx ) )
159 emit activatedId( myIndexId[idx] );
163 SLOT: called if some item is activated
164 */void QtxComboBox::onActivated( const QString& )
170 Strips "cleared" state and updates
172 void QtxComboBox::resetClear()
182 Draws combobox when it is cleared or isn't editable
184 void QtxComboBox::paintClear( QPaintEvent* e )
186 int curIndex = currentItem();
187 QString curText = text( curIndex );
190 if ( pixmap( curIndex ) )
191 curPix = *pixmap( curIndex );
193 bool upd = isUpdatesEnabled();
194 setUpdatesEnabled( false );
196 changeItem( "", curIndex );
197 QComboBox::paintEvent( e );
199 if ( curPix.isNull() )
200 changeItem( curText, curIndex );
202 changeItem( curPix, curText, curIndex );
204 setUpdatesEnabled( upd );
210 int QtxComboBox::id( const int idx ) const
213 if ( myIndexId.contains( idx ) )
221 int QtxComboBox::index( const int id ) const
224 for ( IndexIdMap::ConstIterator it = myIndexId.begin();
225 it != myIndexId.end() && idx == -1; ++it )
226 if ( it.data() == id )