Commit db8a10dc authored by Pino Toscano's avatar Pino Toscano

Preliminary supports for text and choice form fields.

This includes:
- the interfaces for the generators
- the basic widgets for editing their value
- a top bar for show/hide the forms of a document
- the implementation of the forms for the PDF backend
still nothing that can be done with them, nor the value of the forms can be saved...
... but it's a start! :-)

svn path=/trunk/playground/graphics/okular/; revision=637001
parent 252de94b
......@@ -35,6 +35,7 @@ set(okularcore_SRCS
core/bookmarkmanager.cpp
core/chooseenginedialog.cpp
core/document.cpp
core/form.cpp
core/generator.cpp
core/link.cpp
core/misc.cpp
......@@ -114,6 +115,7 @@ set(okularpart_SRCS
ui/annotationtools.cpp
ui/annotationwidgets.cpp
ui/bookmarklist.cpp
ui/formwidgets.cpp
ui/minibar.cpp
ui/newstuff.cpp
ui/pageitemdelegate.cpp
......
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
// local includes
#include "form.h"
using namespace Okular;
FormField::FormField( FormField::FieldType t )
: m_type( t )
{
}
FormField::~FormField()
{
}
FormField::FieldType FormField::type() const
{
return m_type;
}
bool FormField::isReadOnly() const
{
return false;
}
bool FormField::isVisible() const
{
return true;
}
FormFieldText::FormFieldText()
: FormField( FormField::FormText )
{
}
FormFieldText::~FormFieldText()
{
}
void FormFieldText::setText( const QString& )
{
}
bool FormFieldText::isPassword() const
{
return false;
}
bool FormFieldText::isRichText() const
{
return false;
}
int FormFieldText::maximumLength() const
{
return -1;
}
Qt::Alignment FormFieldText::textAlignment() const
{
return Qt::AlignVCenter | Qt::AlignLeft;
}
bool FormFieldText::canBeSpellChecked() const
{
return false;
}
FormFieldChoice::FormFieldChoice()
: FormField( FormField::FormChoice )
{
}
FormFieldChoice::~FormFieldChoice()
{
}
bool FormFieldChoice::isEditable() const
{
return false;
}
bool FormFieldChoice::multiSelect() const
{
return false;
}
void FormFieldChoice::setCurrentChoices( const QList< int >& )
{
}
Qt::Alignment FormFieldChoice::textAlignment() const
{
return Qt::AlignVCenter | Qt::AlignLeft;
}
bool FormFieldChoice::canBeSpellChecked() const
{
return false;
}
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef _OKULAR_FORM_H_
#define _OKULAR_FORM_H_
#include <core/okular_export.h>
#include <core/area.h>
#include <QtCore/QStringList>
namespace Okular {
/**
* @short The base interface of a form field.
*
* This is the very basic interface to represent a field in a form.
*
* This is not meant to be used as a direct base for the form fields in a
* document, but its abstract subclasses are.
*/
class OKULAR_EXPORT FormField
{
public:
/**
* The types of form field.
*/
enum FieldType
{
FormButton, ///< A "button". See @ref FormFieldButton::ButtonType.
FormText, ///< A field of variable text. See @ref FormFieldText::TextType.
FormChoice, ///< A choice field. See @ref FormFieldChoice::ChoiceType.
FormSignature ///< A signature.
};
virtual ~FormField();
/**
* The type of the field.
*/
FieldType type() const;
/**
* The bouding rect of the field, in normalized coordinates.
*/
virtual NormalizedRect rect() const = 0;
/**
* The ID of the field.
*/
virtual int id() const = 0;
/**
* The internal name of the field, to be used when referring to the
* field in eg scripts.
*/
virtual QString name() const = 0;
/**
* The visible name of the field, to be used in the user interface
* (eg in error messages, etc).
*/
virtual QString uiName() const = 0;
/**
* Whether the field is read-only.
*/
virtual bool isReadOnly() const;
/**
* Whether this form field is visible.
*/
virtual bool isVisible() const;
protected:
FormField( FieldType t );
private:
FieldType m_type;
Q_DISABLE_COPY( FormField )
};
/**
* @short Interface of a text form field.
*
* This is the base interface to reimplement to represent a text field, ie a
* field where the user insert text.
*/
class OKULAR_EXPORT FormFieldText : public FormField
{
public:
/**
* The types of text field.
*/
enum TextType
{
Normal, ///< A simple singleline text field.
Multiline, ///< A multiline text field.
FileSelect ///< An input field to select the path of a file on disk.
};
virtual ~FormFieldText();
/**
* The particular type of the text field.
*/
virtual TextType textType() const = 0;
/**
* The text of text field.
*/
virtual QString text() const = 0;
/**
* Sets the new @p text in the text field.
*
* The default implementation does nothing.
*
* Reimplemented only if the setting of new text is supported.
*/
virtual void setText( const QString& text );
/**
* Whether this text field is a password input, eg its text @b must be
* replaced with asterisks.
*
* Always false for @ref FileSelect text fields.
*/
virtual bool isPassword() const;
/**
* Whether this text field should allow rich text.
*/
virtual bool isRichText() const;
/**
* The maximum length allowed for the text of text field, or -1 if
* there is no limitation for the text.
*/
virtual int maximumLength() const;
/**
* The alignment of the text within the field.
*/
virtual Qt::Alignment textAlignment() const;
/**
* Whether the text inserted manually in the field (where possible)
* can be spell-checked.
*
* @note meaningful only if the field is editable.
*/
virtual bool canBeSpellChecked() const;
protected:
FormFieldText();
};
/**
* @short Interface of a choice form field.
*
* This is the base interface to reimplement to represent a choice field, ie a
* field where the user can select one (of more) element(s) among a set of
* choices.
*/
class OKULAR_EXPORT FormFieldChoice : public FormField
{
public:
/**
* The types of choice field.
*/
enum ChoiceType
{
ComboBox, ///< A combo box choice field.
ListBox ///< A list box choice field.
};
virtual ~FormFieldChoice();
/**
* The particular type of the choice field.
*/
virtual ChoiceType choiceType() const = 0;
/**
* The possible choices of the choice field.
*/
virtual QStringList choices() const = 0;
/**
* Whether this ComboBox is editable, ie the user can type in a custom
* value.
*
* Always false for the other types of choices.
*/
virtual bool isEditable() const;
/**
* Whether more than one choice of this ListBox can be selected at the
* same time.
*
* Always false for the other types of choices.
*/
virtual bool multiSelect() const;
/**
* The currently selected choices.
*
* Always one element in the list in case of single choice elements.
*/
virtual QList< int > currentChoices() const = 0;
/**
* Sets the selected choices to @p choices .
*/
virtual void setCurrentChoices( const QList< int >& choices );
/**
* The alignment of the text within the field.
*/
virtual Qt::Alignment textAlignment() const;
/**
* Whether the text inserted manually in the field (where possible)
* can be spell-checked.
*
* @note meaningful only if the field is editable.
*/
virtual bool canBeSpellChecked() const;
protected:
FormFieldChoice();
};
}
#endif
......@@ -19,6 +19,7 @@
// local includes
#include "annotations.h"
#include "area.h"
#include "form.h"
#include "link.h"
#include "page.h"
#include "pagesize.h"
......@@ -61,6 +62,7 @@ class Page::Private
~Private()
{
qDeleteAll( formfields );
delete m_openingAction;
delete m_closingAction;
delete m_text;
......@@ -79,6 +81,7 @@ class Page::Private
TextPage * m_text;
PageTransition * m_transition;
QLinkedList< FormField * > formfields;
Link * m_openingAction;
Link * m_closingAction;
double m_duration;
......@@ -367,6 +370,11 @@ const Link * Page::pageAction( PageAction action ) const
return 0;
}
const QLinkedList< FormField * > Page::formFields() const
{
return d->formfields;
}
void Page::setPixmap( int id, QPixmap *pixmap )
{
if ( d->m_rotation == Rotation0 ) {
......@@ -572,6 +580,12 @@ void Page::setPageAction( PageAction action, Link * link )
}
}
void Page::setFormFields( const QLinkedList< FormField * >& fields )
{
qDeleteAll( d->formfields );
d->formfields = fields;
}
void Page::deletePixmap( int id )
{
PixmapObject object = m_pixmaps.take( id );
......
......@@ -26,6 +26,7 @@ class PagePainter;
namespace Okular {
class Annotation;
class FormField;
class PageSize;
class PageTransition;
class SourceReference;
......@@ -190,6 +191,11 @@ class OKULAR_EXPORT Page : public QObject
*/
const Link * pageAction( PageAction action ) const;
/**
* Returns the list of FormField of the page.
*/
const QLinkedList< FormField * > formFields() const;
/**
* Rotates the image and object rects of the page to the given @p orientation.
*/
......@@ -289,6 +295,11 @@ class OKULAR_EXPORT Page : public QObject
*/
void setPageAction( PageAction action, Link * link );
/**
* Sets @p fields as list of FormField of the page.
*/
void setFormFields( const QLinkedList< FormField * >& fields );
/**
* Deletes the pixmap for the observer with the given @p id.
*/
......
......@@ -7,7 +7,7 @@ include_directories(
########### next target ###############
set(okularGenerator_poppler_PART_SRCS generator_pdf.cpp )
set(okularGenerator_poppler_PART_SRCS generator_pdf.cpp formfields.cpp )
kde4_automoc(${okularGenerator_poppler_PART_SRCS})
......
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>
// local includes
#include "formfields.h"
PopplerFormFieldText::PopplerFormFieldText( Poppler::FormFieldText * field )
: Okular::FormFieldText(), m_field( field )
{
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
}
PopplerFormFieldText::~PopplerFormFieldText()
{
delete m_field;
}
Okular::NormalizedRect PopplerFormFieldText::rect() const
{
return m_rect;
}
int PopplerFormFieldText::id() const
{
return m_field->id();
}
QString PopplerFormFieldText::name() const
{
return m_field->name();
}
QString PopplerFormFieldText::uiName() const
{
return m_field->uiName();
}
bool PopplerFormFieldText::isReadOnly() const
{
return m_field->isReadOnly();
}
bool PopplerFormFieldText::isVisible() const
{
return m_field->isVisible();
}
Okular::FormFieldText::TextType PopplerFormFieldText::textType() const
{
switch ( m_field->textType() )
{
case Poppler::FormFieldText::Normal:
return Okular::FormFieldText::Normal;
case Poppler::FormFieldText::Multiline:
return Okular::FormFieldText::Multiline;
case Poppler::FormFieldText::FileSelect:
return Okular::FormFieldText::FileSelect;
}
return Okular::FormFieldText::Normal;
}
QString PopplerFormFieldText::text() const
{
return m_field->text();
}
void PopplerFormFieldText::setText( const QString& text )
{
m_field->setText( text );
}
bool PopplerFormFieldText::isPassword() const
{
return m_field->isPassword();
}
bool PopplerFormFieldText::isRichText() const
{
return m_field->isRichText();
}
int PopplerFormFieldText::maximumLength() const
{
return m_field->maximumLength();
}
Qt::Alignment PopplerFormFieldText::textAlignment() const
{
return Qt::AlignTop | m_field->textAlignment();
}
bool PopplerFormFieldText::canBeSpellChecked() const
{
return m_field->canBeSpellChecked();
}
PopplerFormFieldChoice::PopplerFormFieldChoice( Poppler::FormFieldChoice * field )
: Okular::FormFieldChoice(), m_field( field )
{
m_rect = Okular::NormalizedRect::fromQRectF( m_field->rect() );
}
PopplerFormFieldChoice::~PopplerFormFieldChoice()
{
delete m_field;
}
Okular::NormalizedRect PopplerFormFieldChoice::rect() const
{
return m_rect;
}
int PopplerFormFieldChoice::id() const
{
return m_field->id();
}
QString PopplerFormFieldChoice::name() const
{
return m_field->name();
}
QString PopplerFormFieldChoice::uiName() const
{
return m_field->uiName();
}
bool PopplerFormFieldChoice::isReadOnly() const
{
return m_field->isReadOnly();
}
bool PopplerFormFieldChoice::isVisible() const
{
return m_field->isVisible();
}
Okular::FormFieldChoice::ChoiceType PopplerFormFieldChoice::choiceType() const
{
switch ( m_field->choiceType() )
{
case Poppler::FormFieldChoice::ComboBox:
return Okular::FormFieldChoice::ComboBox;
case Poppler::FormFieldChoice::ListBox:
return Okular::FormFieldChoice::ListBox;
}
return Okular::FormFieldChoice::ListBox;
}
QStringList PopplerFormFieldChoice::choices() const
{
return m_field->choices();
}
bool PopplerFormFieldChoice::isEditable() const
{
return m_field->isEditable();
}
bool PopplerFormFieldChoice::multiSelect() const
{
return m_field->multiSelect();
}
QList<int> PopplerFormFieldChoice::currentChoices() const
{
return m_field->currentChoices();
}
void PopplerFormFieldChoice::setCurrentChoices( const QList<int>& choices )
{
m_field->setCurrentChoices( choices );
}
Qt::Alignment PopplerFormFieldChoice::textAlignment() const
{
return Qt::AlignTop | m_field->textAlignment();
}
bool PopplerFormFieldChoice::canBeSpellChecked() const
{
return m_field->canBeSpellChecked();
}
/***************************************************************************
* Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *