26 #define SEND_SELECTION_CHANGED_EVENT 0
30 #include <qcombobox.h>
31 #include <qlineedit.h>
32 #define YUILogComponent "qt-ui"
33 #include <yui/YUILog.h>
37 #include <yui/YEvent.h>
38 #include "QY2CharValidator.h"
39 #include "YQComboBox.h"
40 #include "YQSignalBlocker.h"
41 #include "YQWidgetCaption.h"
42 #include <QVBoxLayout>
53 : QFrame( (QWidget *) parent->widgetRep() )
54 , YComboBox( parent, label, editable )
57 QVBoxLayout* layout =
new QVBoxLayout(
this );
61 layout->setSpacing( YQWidgetSpacing );
62 layout->setMargin ( YQWidgetMargin );
65 YUI_CHECK_NEW( _caption );
66 layout->addWidget( _caption );
68 _qt_comboBox =
new QComboBox(
this);
69 _qt_comboBox->setEditable(editable);
70 YUI_CHECK_NEW( _caption );
71 layout->addWidget( _qt_comboBox );
73 _caption->setBuddy( _qt_comboBox );
75 #if SEND_SELECTION_CHANGED_EVENT
76 connect( _qt_comboBox, &pclass(_qt_comboBox)::highlighted,
80 #if (QT_VERSION < QT_VERSION_CHECK( 5, 15, 0 ))
93 connect( _qt_comboBox,
static_cast<void (QComboBox::*)(
const QString&)
>(&QComboBox::activated),
96 connect( _qt_comboBox,
static_cast<void (QComboBox::*)(
const QString&)
>(&QComboBox::textActivated),
100 connect( _qt_comboBox, &pclass(_qt_comboBox)::editTextChanged,
113 return toUTF8( _qt_comboBox->currentText() );
119 QString
text = fromUTF8( newValue );
124 int index = _qt_comboBox->findText(
text );
126 _qt_comboBox->setEditText(
text );
129 _qt_comboBox->setCurrentIndex( index );
130 _qt_comboBox->setItemText(index,
text );
135 yuiError() <<
this <<
": Rejecting invalid value \"" << newValue <<
"\"" << endl;
142 YComboBox::addItem( item );
145 if ( item->hasIconName() )
151 _qt_comboBox->addItem( fromUTF8( item->label() ) );
153 _qt_comboBox->addItem( icon, fromUTF8( item->label() ) );
155 if ( item->selected() )
167 _qt_comboBox->clear();
168 YComboBox::deleteAllItems();
175 YComboBox::setLabel( label );
181 if ( ! _qt_comboBox->isEditable() )
183 yuiWarning() <<
this <<
": Setting ValidChars is useless on a combo box that isn't editable!" << endl;
194 _qt_comboBox->setValidator( _validator );
200 if ( !
isValidText( _qt_comboBox->currentText() ) )
202 yuiError() <<
this <<
": Old value \"" << _qt_comboBox->currentText()
203 <<
" \" invalid according to new ValidChars \""<< newValidChars <<
"\" - deleting"
205 _qt_comboBox->setItemText(_qt_comboBox->currentIndex(),
"");
208 YComboBox::setValidChars( newValidChars );
220 return _validator->
validate(
text, pos ) == QValidator::Acceptable;
228 if ( !
YQUI::ui()->eventPendingFor(
this ) )
247 _qt_comboBox->lineEdit()->setMaxLength( len );
248 YComboBox::setInputMaxLength( len );
254 return sizeHint().width();
260 return sizeHint().height();
266 resize( newWidth, newHeight );
272 _caption->setEnabled( enabled );
273 _qt_comboBox->setEnabled( enabled );
274 YWidget::setEnabled( enabled );
280 _qt_comboBox->setFocus();