Commit 258cd656 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Core work for Reset Forms Action support

Heavily inspired in Guillermo Amaral patches
CCMAIL: gamaral@kde.org
parent 23cf80a1
......@@ -429,3 +429,49 @@ QString MovieAction::actionTip() const
return i18n( "Play movie..." );
}
#endif
// FormAction
class Okular::ResetFormActionPrivate : public Okular::ActionPrivate
{
public:
ResetFormActionPrivate( const QStringList &fieldList, ResetFormAction::Behaviour behaviour )
: ActionPrivate(), m_fieldList(fieldList), m_behaviour(behaviour)
{
}
QStringList m_fieldList;
ResetFormAction::Behaviour m_behaviour;
};
ResetFormAction::ResetFormAction( const QStringList &fieldList, Behaviour behaviour )
: Action( *new ResetFormActionPrivate( fieldList, behaviour ) )
{
}
ResetFormAction::~ResetFormAction()
{
}
Action::ActionType ResetFormAction::actionType() const
{
return ResetForm;
}
QString ResetFormAction::actionTip() const
{
return i18n( "Reset Forms" );
}
ResetFormAction::Behaviour ResetFormAction::behaviour() const
{
Q_D( const Okular::ResetFormAction );
return d->m_behaviour;
}
QStringList ResetFormAction::fieldList() const
{
Q_D( const Okular::ResetFormAction );
return d->m_fieldList;
}
......@@ -27,6 +27,7 @@ class ScriptActionPrivate;
class MovieActionPrivate;
class Sound;
class DocumentViewport;
class ResetFormActionPrivate;
/**
* @short Encapsulates data that describes an action.
......@@ -48,7 +49,8 @@ class OKULAR_EXPORT Action
DocAction, ///< Start a custom action
Sound, ///< Play a sound
Movie, ///< Play a movie
Script ///< Executes a Script code
Script, ///< Executes a Script code
ResetForm ///< Start a reset form action @since 0.14 (KDE 4.8)
};
/**
......@@ -431,6 +433,55 @@ class MovieAction : public Action
};
#endif
/**
* The ResetFormAction action resets forms on activation
* @since 0.14 (KDE 4.8)
*/
class OKULAR_EXPORT ResetFormAction : public Action
{
public:
enum Behaviour
{
ResetAllForms, ///< Reset all the forms in the document
ResetFormsInFieldList, ///< Reset the forms whose fully qualified name is in the list
ResetAllFormsExceptFieldList ///< Reset all the forms in the document exect those whose fully qualified name is in the list
};
/**
* Creates a new reset form action.
*/
ResetFormAction( const QStringList &fieldList, Behaviour behaviour );
/**
* Destroys the document action.
*/
virtual ~ResetFormAction();
/**
* Returns the action type.
*/
ActionType actionType() const;
/**
* Returns the action tip.
*/
QString actionTip() const;
/**
* Returns the reset behaviour.
*/
Behaviour behaviour() const;
/**
* Returns the list of field fully qualified names.
*/
QStringList fieldList() const;
private:
Q_DECLARE_PRIVATE( ResetFormAction )
Q_DISABLE_COPY( ResetFormAction )
};
}
#endif
......@@ -77,6 +77,7 @@
#include "utils_p.h"
#include "view.h"
#include "view_p.h"
#include "form.h"
#include <memory>
......@@ -3001,6 +3002,55 @@ void Document::processAction( const Action * action )
//const MovieAction * movie = static_cast< const MovieAction * >( action );
// TODO this (Movie action)
break;
case Action::ResetForm: {
const ResetFormAction *resetFormAction = static_cast< const ResetFormAction * >( action );
foreach( Page *page, d->m_pagesVector )
{
foreach( FormField* ff, page->formFields() )
{
bool reset = false;
switch (resetFormAction->behaviour())
{
case ResetFormAction::ResetAllForms:
reset = true;
break;
case ResetFormAction::ResetFormsInFieldList:
reset = resetFormAction->fieldList().contains(ff->fullyQualifiedName());
break;
case ResetFormAction::ResetAllFormsExceptFieldList:
reset = !resetFormAction->fieldList().contains(ff->fullyQualifiedName());
break;
}
if (reset)
{
switch (ff->type()) {
case Okular::FormField::FormText: {
Okular::FormFieldText* fft = static_cast<Okular::FormFieldText *>(ff);
if (!fft->isReadOnly()) {
fft->setText( fft->defaultValue() );
emit formFieldChanged(fft);
}
} break;
case Okular::FormField::FormButton: {
Okular::FormFieldButton* ffb = static_cast<Okular::FormFieldButton *>(ff);
if (!ffb->isReadOnly()) {
ffb->setState( "true" == ffb->defaultValue() );
emit formFieldChanged(ffb);
}
} break;
default:
kDebug() << "Unhandled form field: " << ff->name() << ff->defaultValue();
break;
}
}
}
}
} break;
}
}
......
......@@ -43,6 +43,7 @@ class DocumentViewport;
class EmbeddedFile;
class ExportFormat;
class FontInfo;
class FormField;
class Generator;
class Action;
class Page;
......@@ -722,6 +723,12 @@ class OKULAR_EXPORT Document : public QObject
* Reports that the current search finished
*/
void searchFinished( int id, Okular::Document::SearchStatus endStatus );
/**
* Reports that some data of the given form changed
* @since 0.14 (KDE 4.8)
*/
void formFieldChanged( Okular::FormField *formField );
private:
/// @cond PRIVATE
......
......@@ -50,6 +50,12 @@ FormField::FieldType FormField::type() const
return d->m_type;
}
QString FormField::defaultValue() const
{
Q_D( const FormField );
return d->m_default;
}
bool FormField::isReadOnly() const
{
return false;
......@@ -66,6 +72,12 @@ Action* FormField::activationAction() const
return d->m_activateAction;
}
QString FormField::fullyQualifiedName() const
{
Q_D( const FormField );
return d->m_fullyQualifiedName;
}
void FormField::setActivationAction( Action *action )
{
Q_D( FormField );
......@@ -73,6 +85,11 @@ void FormField::setActivationAction( Action *action )
d->m_activateAction = action;
}
void FormField::setFullyQualifiedName( const QString &name )
{
Q_D( FormField );
d->m_fullyQualifiedName = name;
}
class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
{
......
......@@ -59,6 +59,12 @@ class OKULAR_EXPORT FormField
*/
FieldType type() const;
/**
* The field default value.
* @since 0.14 (KDE 4.8)
*/
QString defaultValue() const;
/**
* The bouding rect of the field, in normalized coordinates.
*/
......@@ -92,6 +98,12 @@ class OKULAR_EXPORT FormField
virtual bool isVisible() const;
Action* activationAction() const;
/**
* The internal fully qualified name of the field
* @since 0.14 (KDE 4.8)
*/
QString fullyQualifiedName() const;
protected:
/// @cond PRIVATE
......@@ -101,6 +113,8 @@ class OKULAR_EXPORT FormField
/// @endcond
void setActivationAction( Action *action );
/// @since 0.14 (KDE 4.8)
void setFullyQualifiedName( const QString &name );
private:
Q_DISABLE_COPY( FormField )
......
......@@ -33,6 +33,7 @@ class FormFieldPrivate
FormField::FieldType m_type;
QString m_default;
Action *m_activateAction;
QString m_fullyQualifiedName;
Q_DECLARE_PUBLIC( FormField )
FormField *q_ptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment