From 604187b7a3f8a9333f8451e3f80743e63ee9af16 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 25 Aug 2011 02:25:43 +0200 Subject: [PATCH] Ui work for Reset Form Action support Heavily inspired in Guillermo Amaral patches CCMAIL: gamaral@kde.org --- part.cpp | 1 + ui/pageview.cpp | 34 ++++++++++++++++++++++++++++++++++ ui/pageview.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/part.cpp b/part.cpp index f459f796e..e4587bd7f 100644 --- a/part.cpp +++ b/part.cpp @@ -366,6 +366,7 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args connect( m_document, SIGNAL(error(QString,int)), m_pageView, SLOT(errorMessage(QString,int)) ); connect( m_document, SIGNAL(warning(QString,int)), m_pageView, SLOT(warningMessage(QString,int)) ); connect( m_document, SIGNAL(notice(QString,int)), m_pageView, SLOT(noticeMessage(QString,int)) ); + connect( m_document, SIGNAL(formFieldChanged(Okular::FormField*)), m_pageView, SLOT(slotFormFieldChanged(Okular::FormField*)) ); rightLayout->addWidget( m_pageView ); m_findBar = new FindBar( m_document, rightContainer ); rightLayout->addWidget( m_findBar ); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 3f1936fed..871b9e4fd 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -3708,6 +3708,40 @@ void PageView::slotAction( Okular::Action *action ) d->document->processAction( action ); } +void PageView::slotFormFieldChanged( Okular::FormField *ff ) +{ + QVector< PageViewItem * >::const_iterator dIt = d->items.constBegin(), dEnd = d->items.constEnd(); + for ( ; dIt != dEnd; ++dIt ) + { + FormWidgetIface *fw = (*dIt)->formWidgets().value( ff->id() ); + if (fw != NULL) + { + switch (ff->type()) { + case Okular::FormField::FormText: { + Okular::FormFieldText* fft = static_cast(ff); + FormLineEdit *le = dynamic_cast(fw); + TextAreaEdit *te = dynamic_cast(fw); + + if (le) le->setText( fft->text() ); + if (te) te->setText( fft->text() ); + } break; + + case Okular::FormField::FormButton: { + Okular::FormFieldButton* ffb = static_cast(ff); + QAbstractButton *be = dynamic_cast(fw); + if (be) be->setChecked( ffb->state() ); + } break; + + default: + kDebug() << "Unhandled form field: " << ff->name() << ff->defaultValue(); + break; + } + + break; // Found the widget, no need to loop more pages + } + } +} + void PageView::externalKeyPressEvent( QKeyEvent *e ) { keyPressEvent( e ); diff --git a/ui/pageview.h b/ui/pageview.h index cd88b99ba..dd1f14e34 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -36,6 +36,7 @@ namespace Okular { class Action; class Document; class Annotation; +class FormField; } class FormWidgetIface; @@ -229,6 +230,7 @@ Q_OBJECT void slotSpeakCurrentPage(); void slotStopSpeaks(); void slotAction( Okular::Action *action ); + void slotFormFieldChanged( Okular::FormField *formField ); void externalKeyPressEvent( QKeyEvent *e ); };