|
|
|
|
@ -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
|
|
|
|
|
@ -211,9 +224,6 @@ FormWidgetIface * FormWidgetFactory::createWidget( Okular::FormField * ff, QWidg |
|
|
|
|
{ |
|
|
|
|
FormWidgetIface * widget = nullptr; |
|
|
|
|
|
|
|
|
|
if (ff->isReadOnly()) |
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
|
|
switch ( ff->type() ) |
|
|
|
|
{ |
|
|
|
|
case Okular::FormField::FormButton: |
|
|
|
|
@ -267,15 +277,17 @@ FormWidgetIface * FormWidgetFactory::createWidget( Okular::FormField * ff, QWidg |
|
|
|
|
} |
|
|
|
|
default: ; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( ff->isReadOnly() ) |
|
|
|
|
widget->setVisibility( false ); |
|
|
|
|
|
|
|
|
|
return widget; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FormWidgetIface::FormWidgetIface( QWidget * w, Okular::FormField * ff, bool canBeEnabled ) |
|
|
|
|
: m_controller( nullptr ), m_ff( ff ), m_widget( w ), m_pageItem( nullptr ), |
|
|
|
|
m_canBeEnabled( canBeEnabled ) |
|
|
|
|
FormWidgetIface::FormWidgetIface( QWidget * w, Okular::FormField * ff ) |
|
|
|
|
: m_controller( nullptr ), m_ff( ff ), m_widget( w ), m_pageItem( nullptr ) |
|
|
|
|
{ |
|
|
|
|
m_widget->setEnabled( m_canBeEnabled ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FormWidgetIface::~FormWidgetIface() |
|
|
|
|
@ -308,7 +320,7 @@ bool FormWidgetIface::setVisibility( bool visible ) |
|
|
|
|
|
|
|
|
|
void FormWidgetIface::setCanBeFilled( bool fill ) |
|
|
|
|
{ |
|
|
|
|
m_widget->setEnabled( fill && m_canBeEnabled ); |
|
|
|
|
m_widget->setEnabled( fill ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FormWidgetIface::setPageItem( PageViewItem *pageItem ) |
|
|
|
|
@ -334,11 +346,27 @@ PageViewItem* FormWidgetIface::pageItem() const |
|
|
|
|
void FormWidgetIface::setFormWidgetsController( FormWidgetsController *controller ) |
|
|
|
|
{ |
|
|
|
|
m_controller = controller; |
|
|
|
|
QObject *obj = dynamic_cast< QObject * > ( this ); |
|
|
|
|
QObject::connect( m_controller, &FormWidgetsController::refreshFormWidget, obj, |
|
|
|
|
[this] ( Okular::FormField *form ) { |
|
|
|
|
slotRefresh ( form ); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FormWidgetIface::slotRefresh( Okular::FormField * form ) |
|
|
|
|
{ |
|
|
|
|
if ( m_ff != form ) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
setVisibility( form->isVisible() && !form->isReadOnly() ); |
|
|
|
|
|
|
|
|
|
m_widget->setEnabled( !form->isReadOnly() ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PushButtonEdit::PushButtonEdit( Okular::FormFieldButton * button, QWidget * parent ) |
|
|
|
|
: QPushButton( parent ), FormWidgetIface( this, button, !button->isReadOnly() ) |
|
|
|
|
: QPushButton( parent ), FormWidgetIface( this, button ) |
|
|
|
|
{ |
|
|
|
|
setText( button->caption() ); |
|
|
|
|
setVisible( button->isVisible() ); |
|
|
|
|
@ -355,7 +383,7 @@ void PushButtonEdit::slotClicked() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CheckBoxEdit::CheckBoxEdit( Okular::FormFieldButton * button, QWidget * parent ) |
|
|
|
|
: QCheckBox( parent ), FormWidgetIface( this, button, !button->isReadOnly() ) |
|
|
|
|
: QCheckBox( parent ), FormWidgetIface( this, button ) |
|
|
|
|
{ |
|
|
|
|
setText( button->caption() ); |
|
|
|
|
|
|
|
|
|
@ -369,19 +397,36 @@ 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<Okular::FormFieldButton *>(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<Okular::FormFieldButton *>(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, !button->isReadOnly() ) |
|
|
|
|
: QRadioButton( parent ), FormWidgetIface( this, button ) |
|
|
|
|
{ |
|
|
|
|
setText( button->caption() ); |
|
|
|
|
|
|
|
|
|
@ -399,7 +444,7 @@ void RadioButtonEdit::setFormWidgetsController( FormWidgetsController *controlle |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FormLineEdit::FormLineEdit( Okular::FormFieldText * text, QWidget * parent ) |
|
|
|
|
: QLineEdit( parent ), FormWidgetIface( this, text, true ) |
|
|
|
|
: QLineEdit( parent ), FormWidgetIface( this, text ) |
|
|
|
|
{ |
|
|
|
|
int maxlen = text->maximumLength(); |
|
|
|
|
if ( maxlen >= 0 ) |
|
|
|
|
@ -423,8 +468,6 @@ void FormLineEdit::setFormWidgetsController(FormWidgetsController* controller) |
|
|
|
|
FormWidgetIface::setFormWidgetsController(controller); |
|
|
|
|
connect( m_controller, &FormWidgetsController::formTextChangedByUndoRedo, |
|
|
|
|
this, &FormLineEdit::slotHandleTextChangedByUndoRedo ); |
|
|
|
|
connect( m_controller, &FormWidgetsController::refreshFormWidget, |
|
|
|
|
this, &FormLineEdit::slotRefresh ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool FormLineEdit::event( QEvent* e ) |
|
|
|
|
@ -527,13 +570,14 @@ void FormLineEdit::slotRefresh( Okular::FormField *form ) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Okular::FormFieldText *text = static_cast<Okular::FormFieldText *> ( form ); |
|
|
|
|
FormWidgetIface::slotRefresh( form ); |
|
|
|
|
|
|
|
|
|
Okular::FormFieldText *text = static_cast<Okular::FormFieldText *> ( form ); |
|
|
|
|
setText( text->text() ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TextAreaEdit::TextAreaEdit( Okular::FormFieldText * text, QWidget * parent ) |
|
|
|
|
: KTextEdit( parent ), FormWidgetIface( this, text, true ) |
|
|
|
|
: KTextEdit( parent ), FormWidgetIface( this, text ) |
|
|
|
|
{ |
|
|
|
|
setAcceptRichText( text->isRichText() ); |
|
|
|
|
setCheckSpellingEnabled( text->canBeSpellChecked() ); |
|
|
|
|
@ -599,8 +643,6 @@ void TextAreaEdit::setFormWidgetsController( FormWidgetsController* controller ) |
|
|
|
|
FormWidgetIface::setFormWidgetsController( controller ); |
|
|
|
|
connect( m_controller, &FormWidgetsController::formTextChangedByUndoRedo, |
|
|
|
|
this, &TextAreaEdit::slotHandleTextChangedByUndoRedo ); |
|
|
|
|
connect( m_controller, &FormWidgetsController::refreshFormWidget, |
|
|
|
|
this, &TextAreaEdit::slotRefresh ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TextAreaEdit::slotHandleTextChangedByUndoRedo( int pageNumber, |
|
|
|
|
@ -648,13 +690,14 @@ void TextAreaEdit::slotRefresh( Okular::FormField *form ) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Okular::FormFieldText *text = static_cast<Okular::FormFieldText *> ( form ); |
|
|
|
|
FormWidgetIface::slotRefresh( form ); |
|
|
|
|
|
|
|
|
|
Okular::FormFieldText *text = static_cast<Okular::FormFieldText *> ( form ); |
|
|
|
|
setPlainText( text->text() ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
FileEdit::FileEdit( Okular::FormFieldText * text, QWidget * parent ) |
|
|
|
|
: KUrlRequester( parent ), FormWidgetIface( this, text, !text->isReadOnly() ) |
|
|
|
|
: KUrlRequester( parent ), FormWidgetIface( this, text ) |
|
|
|
|
{ |
|
|
|
|
setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly ); |
|
|
|
|
setFilter( i18n( "*|All Files" ) ); |
|
|
|
|
@ -780,7 +823,7 @@ void FileEdit::slotHandleFileChangedByUndoRedo( int pageNumber, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ListEdit::ListEdit( Okular::FormFieldChoice * choice, QWidget * parent ) |
|
|
|
|
: QListWidget( parent ), FormWidgetIface( this, choice, !choice->isReadOnly() ) |
|
|
|
|
: QListWidget( parent ), FormWidgetIface( this, choice ) |
|
|
|
|
{ |
|
|
|
|
addItems( choice->choices() ); |
|
|
|
|
setSelectionMode( choice->multiSelect() ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection ); |
|
|
|
|
@ -850,7 +893,7 @@ void ListEdit::slotHandleFormListChangedByUndoRedo( int pageNumber, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ComboEdit::ComboEdit( Okular::FormFieldChoice * choice, QWidget * parent ) |
|
|
|
|
: QComboBox( parent ), FormWidgetIface( this, choice, !choice->isReadOnly() ) |
|
|
|
|
: QComboBox( parent ), FormWidgetIface( this, choice ) |
|
|
|
|
{ |
|
|
|
|
addItems( choice->choices() ); |
|
|
|
|
setEditable( true ); |
|
|
|
|
|