diff --git a/core/script/kjs_field.cpp b/core/script/kjs_field.cpp index 16235e08f..2cc9bd026 100644 --- a/core/script/kjs_field.cpp +++ b/core/script/kjs_field.cpp @@ -134,8 +134,11 @@ static KJSObject fieldGetValue( KJSContext */*context*/, void *object ) case FormField::FormButton: { const FormFieldButton *button = static_cast< const FormFieldButton * >( field ); - Q_UNUSED( button ); // ### - break; + if ( button->state() ) + { + return KJSString( QStringLiteral( "Yes" ) ); + } + return KJSString( QStringLiteral( "Off" ) ); } case FormField::FormText: { @@ -167,7 +170,17 @@ static void fieldSetValue( KJSContext *context, void *object, KJSObject value ) case FormField::FormButton: { FormFieldButton *button = static_cast< FormFieldButton * >( field ); - Q_UNUSED( button ); // ### + const QString text = value.toString( context ); + if ( text == QStringLiteral( "Yes" ) ) + { + button->setState( true ); + updateField( field ); + } + else if ( text == QStringLiteral( "Off" ) ) + { + button->setState( false ); + updateField( field ); + } break; } case FormField::FormText: diff --git a/ui/formwidgets.cpp b/ui/formwidgets.cpp index dd9704a51..68f459571 100644 --- a/ui/formwidgets.cpp +++ b/ui/formwidgets.cpp @@ -154,7 +154,8 @@ bool FormWidgetsController::canRedo() void FormWidgetsController::slotButtonClicked( QAbstractButton *button ) { int pageNumber = -1; - if ( CheckBoxEdit *check = qobject_cast< CheckBoxEdit * >( button ) ) + CheckBoxEdit *check = qobject_cast< CheckBoxEdit * >( button ); + if ( check ) { // Checkboxes need to be uncheckable so if clicking a checked one // disable the exclusive status temporarily and uncheck it @@ -186,6 +187,13 @@ void FormWidgetsController::slotButtonClicked( QAbstractButton *button ) } if (checked != prevChecked) emit formButtonsChangedByWidget( pageNumber, formButtons, checked ); + if ( check ) + { + // The formButtonsChangedByWidget signal changes the value of the underlying + // Okular::FormField of the checkbox. We need to execute the activiation + // action after this. + check->doActivateAction(); + } } void FormWidgetsController::slotFormButtonsChangedByUndoRedo( int pageNumber, const QList< Okular::FormFieldButton* > & formButtons) @@ -194,6 +202,11 @@ void FormWidgetsController::slotFormButtonsChangedByUndoRedo( int pageNumber, co { int id = formButton->id(); QAbstractButton* button = m_buttons[id]; + CheckBoxEdit *check = qobject_cast< CheckBoxEdit * >( button ); + if ( check ) + { + emit refreshFormWidget( check->formField() ); + } // temporarily disable exclusiveness of the button group // since it breaks doing/redoing steps into which all the checkboxes // are unchecked @@ -384,16 +397,33 @@ void CheckBoxEdit::setFormWidgetsController( FormWidgetsController *controller ) FormWidgetIface::setFormWidgetsController( controller ); m_controller->registerRadioButton( this, form ); setChecked( form->state() ); - connect( this, &QCheckBox::stateChanged, this, &CheckBoxEdit::slotStateChanged ); } -void CheckBoxEdit::slotStateChanged( int state ) +void CheckBoxEdit::doActivateAction() { Okular::FormFieldButton *form = static_cast(m_ff); - if ( state == Qt::Checked && form->activationAction() ) + if ( form->activationAction() ) m_controller->signalAction( form->activationAction() ); } +void CheckBoxEdit::slotRefresh( Okular::FormField * form ) +{ + if ( form != m_ff ) + { + return; + } + FormWidgetIface::slotRefresh( form ); + + Okular::FormFieldButton *button = static_cast(m_ff); + bool oldState = isChecked(); + bool newState = button->state(); + if ( oldState != newState ) + { + setChecked( button->state() ); + doActivateAction(); + } +} + RadioButtonEdit::RadioButtonEdit( Okular::FormFieldButton * button, QWidget * parent ) : QRadioButton( parent ), FormWidgetIface( this, button ) diff --git a/ui/formwidgets.h b/ui/formwidgets.h index 22ae1a92d..22ea721af 100644 --- a/ui/formwidgets.h +++ b/ui/formwidgets.h @@ -192,8 +192,10 @@ class CheckBoxEdit : public QCheckBox, public FormWidgetIface // reimplemented from FormWidgetIface void setFormWidgetsController( FormWidgetsController *controller ) override; - private Q_SLOTS: - void slotStateChanged( int state ); + void doActivateAction(); + + protected: + void slotRefresh( Okular::FormField *form ) override; }; class RadioButtonEdit : public QRadioButton, public FormWidgetIface