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::insertStringList( const QIntList& ids, const QStringList& list, int index )
95 void QtxComboBox::insertItem( const int id, const QString& t, int index )
99 void QtxComboBox::insertItem( const int id, const QPixmap& pixmap, int index )
103 void QtxComboBox::insertItem( const int id, const QPixmap& pixmap, const QString& text, int index )
107 void QtxComboBox::paintEvent( QPaintEvent* e )
109 if ( !count() || !myCleared || editable() )
110 QComboBox::paintEvent( e );
115 void QtxComboBox::onActivated( int idx )
119 if ( myIndexId.contains( idx ) )
120 emit activatedId( myIndexId[idx] );
123 void QtxComboBox::onActivated( const QString& )
128 void QtxComboBox::resetClear()
137 void QtxComboBox::paintClear( QPaintEvent* e )
139 int curIndex = currentItem();
140 QString curText = text( curIndex );
143 if ( pixmap( curIndex ) )
144 curPix = *pixmap( curIndex );
146 bool upd = isUpdatesEnabled();
147 setUpdatesEnabled( false );
149 changeItem( "", curIndex );
150 QComboBox::paintEvent( e );
152 if ( curPix.isNull() )
153 changeItem( curText, curIndex );
155 changeItem( curPix, curText, curIndex );
157 setUpdatesEnabled( upd );
160 int QtxComboBox::id( const int idx ) const
163 if ( myIndexId.contains( idx ) )
168 int QtxComboBox::index( const int id ) const
171 for ( IndexIdMap::ConstIterator it = myIndexId.begin();
172 it != myIndexId.end() && idx == -1; ++it )
173 if ( it.data() == id )