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
|
|
|
|
#include <QtCore/QVariant>
|
2007-02-25 00:07:59 +00:00
|
|
|
|
|
|
|
using namespace Okular;
|
|
|
|
|
2007-07-04 11:41:45 +00:00
|
|
|
FormFieldPrivate::FormFieldPrivate( FormField::FieldType type )
|
|
|
|
: m_type( type )
|
2007-07-03 17:20:38 +00:00
|
|
|
{
|
2007-07-04 11:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FormFieldPrivate::~FormFieldPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormField::isVisible() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
|
|
|
void setValue( const QString& v )
|
|
|
|
{
|
|
|
|
Q_Q( FormFieldText );
|
|
|
|
q->setText( v );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString value() const
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
|
|
|
|
void setValue( const QString& v )
|
|
|
|
{
|
|
|
|
Q_Q( FormFieldChoice );
|
|
|
|
QStringList choices = v.split( ';', QString::SkipEmptyParts );
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString value() const
|
|
|
|
{
|
|
|
|
Q_Q( const FormFieldChoice );
|
|
|
|
QList<int> choices = q->currentChoices();
|
|
|
|
qSort( choices );
|
|
|
|
QStringList list;
|
|
|
|
foreach ( int c, choices )
|
|
|
|
{
|
|
|
|
list.append( QString::number( c ) );
|
|
|
|
}
|
|
|
|
return list.join( QLatin1String( ";" ) );
|
|
|
|
}
|
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 >& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Alignment FormFieldChoice::textAlignment() const
|
|
|
|
{
|
|
|
|
return Qt::AlignVCenter | Qt::AlignLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormFieldChoice::canBeSpellChecked() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|