1 // File: QtxComboBox.cxx
2 // Author: Sergey TELKOV
4 #include "QtxComboBox.h"
8 #include <qvaluelist.h>
10 QtxComboBox::QtxComboBox( QWidget* parent, const char* name )
11 : QComboBox( parent, name ),
14 connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
15 connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
18 QtxComboBox::QtxComboBox( bool rw, QWidget* parent, const char* name )
19 : QComboBox( rw, parent, name ),
22 connect( this, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
23 connect( this, SIGNAL( activated( const QString& ) ), this, SLOT( onActivated( const QString& ) ) );
26 QtxComboBox::~QtxComboBox()
30 bool QtxComboBox::isCleared() const
35 void QtxComboBox::setCleared( const bool isClear )
37 if ( myCleared == isClear )
45 lineEdit()->setText( "" );
47 lineEdit()->setText( text( currentItem() ) );
53 void QtxComboBox::setCurrentItem( int idx )
55 if ( idx < 0 || idx >= count() )
59 QComboBox::setCurrentItem( idx );
62 void QtxComboBox::setCurrentText( const QString& txt )
67 for ( int j = 0; j < count() && i == -1; j++ )
68 if ( text( j ) == txt )
70 if ( i >= 0 && i < count() )
72 else if ( editable() )
73 lineEdit()->setText( txt );
75 changeItem( txt, currentItem() );
77 QComboBox::setCurrentText( txt );
81 int QtxComboBox::currentId() const
83 return id( currentItem() );
86 void QtxComboBox::setCurrentId( int num )
88 setCurrentItem( index( num ) );
91 void QtxComboBox::paintEvent( QPaintEvent* e )
93 if ( !count() || !myCleared || editable() )
94 QComboBox::paintEvent( e );
99 void QtxComboBox::onActivated( int idx )
103 if ( myIndexId.contains( idx ) )
104 emit activatedId( myIndexId[idx] );
107 void QtxComboBox::onActivated( const QString& )
112 void QtxComboBox::resetClear()
121 void QtxComboBox::paintClear( QPaintEvent* e )
123 int curIndex = currentItem();
124 QString curText = text( curIndex );
127 if ( pixmap( curIndex ) )
128 curPix = *pixmap( curIndex );
130 bool upd = isUpdatesEnabled();
131 setUpdatesEnabled( false );
133 changeItem( "", curIndex );
134 QComboBox::paintEvent( e );
136 if ( curPix.isNull() )
137 changeItem( curText, curIndex );
139 changeItem( curPix, curText, curIndex );
141 setUpdatesEnabled( upd );
144 int QtxComboBox::id( const int idx ) const
147 if ( myIndexId.contains( idx ) )
152 int QtxComboBox::index( const int id ) const
155 for ( IndexIdMap::ConstIterator it = myIndexId.begin();
156 it != myIndexId.end() && idx == -1; ++it )
157 if ( it.data() == id )