2007-02-25 00:07:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "form.h"
|
2007-07-04 11:41:45 +00:00
|
|
|
#include "form_p.h"
|
|
|
|
|
|
|
|
// qt includes
|
2018-08-31 09:23:45 +00:00
|
|
|
#include <QVariant>
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2008-03-20 17:42:17 +00:00
|
|
|
#include "action.h"
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
FormFieldPrivate::FormFieldPrivate( FormField::FieldType type )
|
2017-09-05 21:27:18 +00:00
|
|
|
: m_type( type ), m_activateAction( nullptr )
|
2007-07-03 17:20:38 +00:00
|
|
|
{
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldPrivate::~FormFieldPrivate()
|
|
|
|
{
|
2008-03-20 17:42:17 +00:00
|
|
|
delete m_activateAction;
|
2018-05-30 08:04:06 +00:00
|
|
|
qDeleteAll( m_additionalActions.values() );
|
|
|
|
qDeleteAll( m_additionalAnnotActions.values() );
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldPrivate::setDefault()
|
|
|
|
{
|
|
|
|
m_default = value();
|
|
|
|
}
|
2007-07-03 17:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
FormField::FormField( FormFieldPrivate &dd )
|
|
|
|
: d_ptr( &dd )
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
2007-07-04 11:41:45 +00:00
|
|
|
d_ptr->q_ptr = this;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormField::~FormField()
|
|
|
|
{
|
2007-07-03 17:20:38 +00:00
|
|
|
delete d_ptr;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormField::FieldType FormField::type() const
|
|
|
|
{
|
2007-07-03 17:20:38 +00:00
|
|
|
Q_D( const FormField );
|
|
|
|
return d->m_type;
|
2007-02-25 00:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FormField::isReadOnly() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:59:37 +00:00
|
|
|
void FormField::setReadOnly( bool )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
bool FormField::isVisible() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-23 21:47:42 +00:00
|
|
|
void FormField::setVisible( bool )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-03-20 17:42:17 +00:00
|
|
|
Action* FormField::activationAction() const
|
|
|
|
{
|
|
|
|
Q_D( const FormField );
|
|
|
|
return d->m_activateAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setActivationAction( Action *action )
|
|
|
|
{
|
|
|
|
Q_D( FormField );
|
|
|
|
delete d->m_activateAction;
|
|
|
|
d->m_activateAction = action;
|
|
|
|
}
|
|
|
|
|
2017-03-02 23:41:06 +00:00
|
|
|
Action* FormField::additionalAction( AdditionalActionType type ) const
|
|
|
|
{
|
|
|
|
Q_D( const FormField );
|
|
|
|
return d->m_additionalActions.value(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setAdditionalAction( AdditionalActionType type, Action *action )
|
|
|
|
{
|
|
|
|
Q_D( FormField );
|
|
|
|
delete d->m_additionalActions.value(type);
|
|
|
|
d->m_additionalActions[type] = action;
|
|
|
|
}
|
|
|
|
|
2018-05-30 08:04:06 +00:00
|
|
|
Action* FormField::additionalAction( Annotation::AdditionalActionType type ) const
|
|
|
|
{
|
|
|
|
Q_D( const FormField );
|
|
|
|
return d->m_additionalAnnotActions.value(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormField::setAdditionalAction( Annotation::AdditionalActionType type, Action *action )
|
|
|
|
{
|
|
|
|
Q_D( FormField );
|
|
|
|
delete d->m_additionalAnnotActions.value(type);
|
|
|
|
d->m_additionalAnnotActions[type] = action;
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
|
2008-02-11 10:41:04 +00:00
|
|
|
class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldButtonPrivate()
|
|
|
|
: FormFieldPrivate( FormField::FormButton )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_DECLARE_PUBLIC( FormFieldButton )
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
void setValue( const QString& v ) override
|
2008-02-11 10:41:04 +00:00
|
|
|
{
|
|
|
|
Q_Q( FormFieldButton );
|
|
|
|
q->setState( QVariant( v ).toBool() );
|
|
|
|
}
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
QString value() const override
|
2008-02-11 10:41:04 +00:00
|
|
|
{
|
|
|
|
Q_Q( const FormFieldButton );
|
|
|
|
return qVariantFromValue<bool>( q->state() ).toString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FormFieldButton::FormFieldButton()
|
|
|
|
: FormField( *new FormFieldButtonPrivate() )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldButton::~FormFieldButton()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldButton::setState( bool )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-03 17:20:38 +00:00
|
|
|
class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldTextPrivate()
|
|
|
|
: FormFieldPrivate( FormField::FormText )
|
|
|
|
{
|
|
|
|
}
|
2007-07-04 11:41:45 +00:00
|
|
|
|
|
|
|
Q_DECLARE_PUBLIC( FormFieldText )
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
void setValue( const QString& v ) override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q( FormFieldText );
|
|
|
|
q->setText( v );
|
|
|
|
}
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
QString value() const override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q( const FormFieldText );
|
|
|
|
return q->text();
|
|
|
|
}
|
2007-07-03 17:20:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
FormFieldText::FormFieldText()
|
2007-07-03 17:20:38 +00:00
|
|
|
: FormField( *new FormFieldTextPrivate() )
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-03 17:20:38 +00:00
|
|
|
class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormFieldChoicePrivate()
|
|
|
|
: FormFieldPrivate( FormField::FormChoice )
|
|
|
|
{
|
|
|
|
}
|
2007-07-04 11:41:45 +00:00
|
|
|
|
|
|
|
Q_DECLARE_PUBLIC( FormFieldChoice )
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
void setValue( const QString& v ) override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q( FormFieldChoice );
|
2016-07-11 20:07:57 +00:00
|
|
|
QStringList choices = v.split( QLatin1Char (';'), QString::SkipEmptyParts );
|
2007-07-04 11:41:45 +00:00
|
|
|
QList<int> newchoices;
|
|
|
|
foreach ( const QString& str, choices )
|
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
int val = str.toInt( &ok );
|
|
|
|
if ( ok )
|
|
|
|
newchoices.append( val );
|
|
|
|
}
|
|
|
|
if ( !newchoices.isEmpty() )
|
|
|
|
q->setCurrentChoices( newchoices );
|
|
|
|
}
|
|
|
|
|
2016-10-29 14:38:19 +00:00
|
|
|
QString value() const override
|
2007-07-04 11:41:45 +00:00
|
|
|
{
|
|
|
|
Q_Q( const FormFieldChoice );
|
|
|
|
QList<int> choices = q->currentChoices();
|
|
|
|
qSort( choices );
|
|
|
|
QStringList list;
|
|
|
|
foreach ( int c, choices )
|
|
|
|
{
|
|
|
|
list.append( QString::number( c ) );
|
|
|
|
}
|
2015-10-29 12:37:11 +00:00
|
|
|
return list.join( QStringLiteral( ";" ) );
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
2007-07-03 17:20:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
FormFieldChoice::FormFieldChoice()
|
2007-07-03 17:20:38 +00:00
|
|
|
: FormField( *new FormFieldChoicePrivate() )
|
2007-02-25 00:07:59 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldChoice::~FormFieldChoice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::isEditable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::multiSelect() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldChoice::setCurrentChoices( const QList< int >& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-31 23:54:14 +00:00
|
|
|
QString FormFieldChoice::editChoice() const
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormFieldChoice::setEditChoice( const QString& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-02-25 00:07:59 +00:00
|
|
|
Qt::Alignment FormFieldChoice::textAlignment() const
|
|
|
|
{
|
|
|
|
return Qt::AlignVCenter | Qt::AlignLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::canBeSpellChecked() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|