Core work for Reset Forms Action support

Heavily inspired in Guillermo Amaral patches
CCMAIL: gamaral@kde.org
remotes/origin/textfind-and-transparency
Albert Astals Cid 15 years ago
parent 23cf80a16b
commit 258cd6562a
  1. 46
      core/action.cpp
  2. 53
      core/action.h
  3. 50
      core/document.cpp
  4. 7
      core/document.h
  5. 17
      core/form.cpp
  6. 14
      core/form.h
  7. 1
      core/form_p.h

@ -429,3 +429,49 @@ QString MovieAction::actionTip() const
return i18n( "Play movie..." ); return i18n( "Play movie..." );
} }
#endif #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 MovieActionPrivate;
class Sound; class Sound;
class DocumentViewport; class DocumentViewport;
class ResetFormActionPrivate;
/** /**
* @short Encapsulates data that describes an action. * @short Encapsulates data that describes an action.
@ -48,7 +49,8 @@ class OKULAR_EXPORT Action
DocAction, ///< Start a custom action DocAction, ///< Start a custom action
Sound, ///< Play a sound Sound, ///< Play a sound
Movie, ///< Play a movie 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 #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 #endif

@ -77,6 +77,7 @@
#include "utils_p.h" #include "utils_p.h"
#include "view.h" #include "view.h"
#include "view_p.h" #include "view_p.h"
#include "form.h"
#include <memory> #include <memory>
@ -3001,6 +3002,55 @@ void Document::processAction( const Action * action )
//const MovieAction * movie = static_cast< const MovieAction * >( action ); //const MovieAction * movie = static_cast< const MovieAction * >( action );
// TODO this (Movie action) // TODO this (Movie action)
break; 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 EmbeddedFile;
class ExportFormat; class ExportFormat;
class FontInfo; class FontInfo;
class FormField;
class Generator; class Generator;
class Action; class Action;
class Page; class Page;
@ -722,6 +723,12 @@ class OKULAR_EXPORT Document : public QObject
* Reports that the current search finished * Reports that the current search finished
*/ */
void searchFinished( int id, Okular::Document::SearchStatus endStatus ); 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: private:
/// @cond PRIVATE /// @cond PRIVATE

@ -50,6 +50,12 @@ FormField::FieldType FormField::type() const
return d->m_type; return d->m_type;
} }
QString FormField::defaultValue() const
{
Q_D( const FormField );
return d->m_default;
}
bool FormField::isReadOnly() const bool FormField::isReadOnly() const
{ {
return false; return false;
@ -66,6 +72,12 @@ Action* FormField::activationAction() const
return d->m_activateAction; return d->m_activateAction;
} }
QString FormField::fullyQualifiedName() const
{
Q_D( const FormField );
return d->m_fullyQualifiedName;
}
void FormField::setActivationAction( Action *action ) void FormField::setActivationAction( Action *action )
{ {
Q_D( FormField ); Q_D( FormField );
@ -73,6 +85,11 @@ void FormField::setActivationAction( Action *action )
d->m_activateAction = action; d->m_activateAction = action;
} }
void FormField::setFullyQualifiedName( const QString &name )
{
Q_D( FormField );
d->m_fullyQualifiedName = name;
}
class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
{ {

@ -59,6 +59,12 @@ class OKULAR_EXPORT FormField
*/ */
FieldType type() const; 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. * The bouding rect of the field, in normalized coordinates.
*/ */
@ -92,6 +98,12 @@ class OKULAR_EXPORT FormField
virtual bool isVisible() const; virtual bool isVisible() const;
Action* activationAction() const; Action* activationAction() const;
/**
* The internal fully qualified name of the field
* @since 0.14 (KDE 4.8)
*/
QString fullyQualifiedName() const;
protected: protected:
/// @cond PRIVATE /// @cond PRIVATE
@ -101,6 +113,8 @@ class OKULAR_EXPORT FormField
/// @endcond /// @endcond
void setActivationAction( Action *action ); void setActivationAction( Action *action );
/// @since 0.14 (KDE 4.8)
void setFullyQualifiedName( const QString &name );
private: private:
Q_DISABLE_COPY( FormField ) Q_DISABLE_COPY( FormField )

@ -33,6 +33,7 @@ class FormFieldPrivate
FormField::FieldType m_type; FormField::FieldType m_type;
QString m_default; QString m_default;
Action *m_activateAction; Action *m_activateAction;
QString m_fullyQualifiedName;
Q_DECLARE_PUBLIC( FormField ) Q_DECLARE_PUBLIC( FormField )
FormField *q_ptr; FormField *q_ptr;

Loading…
Cancel
Save