diff --git a/core/form.h b/core/form.h --- a/core/form.h +++ b/core/form.h @@ -87,6 +87,11 @@ virtual bool isReadOnly() const; /** + * Whether the field is read-only. + */ + virtual void setReadOnly( bool value ); + + /** * Whether this form field is visible. */ virtual bool isVisible() const; diff --git a/core/form.cpp b/core/form.cpp --- a/core/form.cpp +++ b/core/form.cpp @@ -55,6 +55,10 @@ return false; } +void FormField::setReadOnly( bool ) +{ +} + bool FormField::isVisible() const { return true; diff --git a/core/script/kjs_field.cpp b/core/script/kjs_field.cpp --- a/core/script/kjs_field.cpp +++ b/core/script/kjs_field.cpp @@ -31,6 +31,23 @@ typedef QHash< FormField *, Page * > FormCache; Q_GLOBAL_STATIC( FormCache, g_fieldCache ) + +// Helper for modified fields +static void updateField( FormField *field ) +{ + Page *page = g_fieldCache->value( field ); + if (page) + { + Document *doc = PagePrivate::get( page )->m_doc->m_parent; + QMetaObject::invokeMethod( doc, "refreshPixmaps", Qt::QueuedConnection, Q_ARG( int, page->number() ) ); + emit doc->refreshFormWidget( field ); + } + else + { + qWarning() << "Could not get page of field" << field; + } +} + // Field.doc static KJSObject fieldGetDoc( KJSContext *context, void * ) { @@ -54,16 +71,11 @@ // Field.readonly (setter) static void fieldSetReadOnly( KJSContext *context, void *object, KJSObject value ) { -#if 0 FormField *field = reinterpret_cast< FormField * >( object ); bool b = value.toBoolean( context ); field->setReadOnly( b ); -#else - Q_UNUSED( context ); - Q_UNUSED( object ); - Q_UNUSED( value ); - qCDebug(OkularCoreDebug) << "Not implemented: setting readonly property"; -#endif + + updateField( field ); } static QString fieldGetTypeHelper( const FormField *field ) @@ -165,18 +177,7 @@ if ( text != textField->text() ) { textField->setText( text ); - - Page *page = g_fieldCache->value( field ); - if (page) - { - Document *doc = PagePrivate::get( page )->m_doc->m_parent; - QMetaObject::invokeMethod( doc, "refreshPixmaps", Qt::QueuedConnection, Q_ARG( int, page->number() ) ); - emit doc->refreshFormWidget( field ); - } - else - { - qWarning() << "Could not get page of field" << field; - } + updateField( field ); } break; } diff --git a/generators/poppler/formfields.h b/generators/poppler/formfields.h --- a/generators/poppler/formfields.h +++ b/generators/poppler/formfields.h @@ -25,6 +25,7 @@ QString name() const override; QString uiName() const override; bool isReadOnly() const override; + void setReadOnly( bool value ) override; bool isVisible() const override; // inherited from Okular::FormFieldButton @@ -53,6 +54,7 @@ QString name() const override; QString uiName() const override; bool isReadOnly() const override; + void setReadOnly( bool value ) override; bool isVisible() const override; // inherited from Okular::FormFieldText @@ -84,6 +86,7 @@ QString name() const override; QString uiName() const override; bool isReadOnly() const override; + void setReadOnly( bool value ) override; bool isVisible() const override; // inherited from Okular::FormFieldChoice diff --git a/generators/poppler/formfields.cpp b/generators/poppler/formfields.cpp --- a/generators/poppler/formfields.cpp +++ b/generators/poppler/formfields.cpp @@ -67,6 +67,15 @@ return m_field->isReadOnly(); } +void PopplerFormFieldButton::setReadOnly( bool value ) +{ +#ifdef HAVE_POPPLER_0_63 + m_field->setReadOnly( value ); +#else + Q_UNUSED( value ); +#endif +} + bool PopplerFormFieldButton::isVisible() const { return m_field->isVisible(); @@ -145,6 +154,15 @@ return m_field->isReadOnly(); } +void PopplerFormFieldText::setReadOnly( bool value ) +{ +#ifdef HAVE_POPPLER_0_63 + m_field->setReadOnly( value ); +#else + Q_UNUSED( value ); +#endif +} + bool PopplerFormFieldText::isVisible() const { return m_field->isVisible(); @@ -238,6 +256,15 @@ return m_field->isReadOnly(); } +void PopplerFormFieldChoice::setReadOnly( bool value ) +{ +#ifdef HAVE_POPPLER_0_63 + m_field->setReadOnly( value ); +#else + Q_UNUSED( value ); +#endif +} + bool PopplerFormFieldChoice::isVisible() const { return m_field->isVisible();