diff --git a/core/form.cpp b/core/form.cpp index b56071bce..ca8a13267 100644 --- a/core/form.cpp +++ b/core/form.cpp @@ -239,6 +239,15 @@ void FormFieldChoice::setCurrentChoices( const QList< int >& ) { } +QString FormFieldChoice::editChoice() const +{ + return QString(); +} + +void FormFieldChoice::setEditChoice( const QString& ) +{ +} + Qt::Alignment FormFieldChoice::textAlignment() const { return Qt::AlignVCenter | Qt::AlignLeft; diff --git a/core/form.h b/core/form.h index c6e0104e9..901c6b729 100644 --- a/core/form.h +++ b/core/form.h @@ -307,6 +307,20 @@ class OKULAR_EXPORT FormFieldChoice : public FormField */ virtual void setCurrentChoices( const QList< int >& choices ); + /** + The text entered into an editable combo box choice field + + @since 0.16 (KDE 4.10) + */ + virtual QString editChoice() const; + + /** + Sets the text entered into an editable combo box choice field + + @since 0.16 (KDE 4.10) + */ + virtual void setEditChoice( const QString& text ); + /** * The alignment of the text within the field. */ diff --git a/generators/poppler/formfields.cpp b/generators/poppler/formfields.cpp index 0b15ff6eb..53e50ed3d 100644 --- a/generators/poppler/formfields.cpp +++ b/generators/poppler/formfields.cpp @@ -277,6 +277,22 @@ void PopplerFormFieldChoice::setCurrentChoices( const QList& choices ) m_field->setCurrentChoices( choices ); } +QString PopplerFormFieldChoice::editChoice() const +{ +#ifdef HAVE_POPPLER_0_22 + return m_field->editChoice(); +#else + return QString(); +#endif +} + +void PopplerFormFieldChoice::setEditChoice( const QString& text ) +{ +#ifdef HAVE_POPPLER_0_22 + m_field->setEditChoice( text ); +#endif +} + Qt::Alignment PopplerFormFieldChoice::textAlignment() const { return Qt::AlignTop | m_field->textAlignment(); diff --git a/generators/poppler/formfields.h b/generators/poppler/formfields.h index fdff52d90..245b8ce54 100644 --- a/generators/poppler/formfields.h +++ b/generators/poppler/formfields.h @@ -91,6 +91,8 @@ class PopplerFormFieldChoice : public Okular::FormFieldChoice virtual bool multiSelect() const; virtual QList currentChoices() const; virtual void setCurrentChoices( const QList& choices ); + virtual QString editChoice() const; + virtual void setEditChoice( const QString& text ); virtual Qt::Alignment textAlignment() const; virtual bool canBeSpellChecked() const; diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp index 8c47c597b..57ecceb50 100644 --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -415,20 +415,36 @@ ComboEdit::ComboEdit( Okular::FormFieldChoice * choice, QWidget * parent ) { addItems( m_form->choices() ); setEditable( true ); + setInsertPolicy( NoInsert ); lineEdit()->setReadOnly( !m_form->isEditable() ); QList< int > selectedItems = m_form->currentChoices(); if ( selectedItems.count() == 1 && selectedItems.at(0) >= 0 && selectedItems.at(0) < count() ) setCurrentIndex( selectedItems.at(0) ); setEnabled( !m_form->isReadOnly() ); - connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int)) ); + if ( m_form->isEditable() && !m_form->editChoice().isEmpty() ) + lineEdit()->setText( m_form->editChoice() ); + + connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(slotValueChanged()) ); + connect( this, SIGNAL(editTextChanged(QString)), this, SLOT(slotValueChanged()) ); setVisible( m_form->isVisible() ); setCursor( Qt::ArrowCursor ); } -void ComboEdit::indexChanged( int index ) +void ComboEdit::slotValueChanged() { - m_form->setCurrentChoices( QList< int >() << index ); + const int index = currentIndex(); + const QString text = currentText(); + const bool isCustomValue = ( index == -1 || itemText( index ) != text ); + + if ( isCustomValue ) + { + m_form->setEditChoice( text ); + } + else + { + m_form->setCurrentChoices( QList< int >() << index ); + } m_controller->signalChanged( this ); } diff --git a/ui/formwidgets.h b/ui/formwidgets.h index 2ed9c970a..24108b80b 100644 --- a/ui/formwidgets.h +++ b/ui/formwidgets.h @@ -221,9 +221,10 @@ class ComboEdit : public QComboBox, public FormWidgetIface explicit ComboEdit( Okular::FormFieldChoice * choice, QWidget * parent = 0 ); private slots: - void indexChanged( int ); + void slotValueChanged(); private: + Okular::FormFieldChoice * m_form; };