compile
[kdegraphics.git] / okular / core / form.cpp
blobb56071bce88dddc1b4968b7f6bef1d049e1f53c1
1 /***************************************************************************
2 * Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "form.h"
11 #include "form_p.h"
13 // qt includes
14 #include <QtCore/QVariant>
16 #include "action.h"
18 using namespace Okular;
20 FormFieldPrivate::FormFieldPrivate( FormField::FieldType type )
21 : m_type( type ), m_activateAction( 0 )
25 FormFieldPrivate::~FormFieldPrivate()
27 delete m_activateAction;
30 void FormFieldPrivate::setDefault()
32 m_default = value();
36 FormField::FormField( FormFieldPrivate &dd )
37 : d_ptr( &dd )
39 d_ptr->q_ptr = this;
42 FormField::~FormField()
44 delete d_ptr;
47 FormField::FieldType FormField::type() const
49 Q_D( const FormField );
50 return d->m_type;
53 bool FormField::isReadOnly() const
55 return false;
58 bool FormField::isVisible() const
60 return true;
63 Action* FormField::activationAction() const
65 Q_D( const FormField );
66 return d->m_activateAction;
69 void FormField::setActivationAction( Action *action )
71 Q_D( FormField );
72 delete d->m_activateAction;
73 d->m_activateAction = action;
77 class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
79 public:
80 FormFieldButtonPrivate()
81 : FormFieldPrivate( FormField::FormButton )
85 Q_DECLARE_PUBLIC( FormFieldButton )
87 void setValue( const QString& v )
89 Q_Q( FormFieldButton );
90 q->setState( QVariant( v ).toBool() );
93 QString value() const
95 Q_Q( const FormFieldButton );
96 return qVariantFromValue<bool>( q->state() ).toString();
101 FormFieldButton::FormFieldButton()
102 : FormField( *new FormFieldButtonPrivate() )
106 FormFieldButton::~FormFieldButton()
110 void FormFieldButton::setState( bool )
115 class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
117 public:
118 FormFieldTextPrivate()
119 : FormFieldPrivate( FormField::FormText )
123 Q_DECLARE_PUBLIC( FormFieldText )
125 void setValue( const QString& v )
127 Q_Q( FormFieldText );
128 q->setText( v );
131 QString value() const
133 Q_Q( const FormFieldText );
134 return q->text();
139 FormFieldText::FormFieldText()
140 : FormField( *new FormFieldTextPrivate() )
144 FormFieldText::~FormFieldText()
148 void FormFieldText::setText( const QString& )
152 bool FormFieldText::isPassword() const
154 return false;
157 bool FormFieldText::isRichText() const
159 return false;
162 int FormFieldText::maximumLength() const
164 return -1;
167 Qt::Alignment FormFieldText::textAlignment() const
169 return Qt::AlignVCenter | Qt::AlignLeft;
172 bool FormFieldText::canBeSpellChecked() const
174 return false;
178 class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
180 public:
181 FormFieldChoicePrivate()
182 : FormFieldPrivate( FormField::FormChoice )
186 Q_DECLARE_PUBLIC( FormFieldChoice )
188 void setValue( const QString& v )
190 Q_Q( FormFieldChoice );
191 QStringList choices = v.split( ';', QString::SkipEmptyParts );
192 QList<int> newchoices;
193 foreach ( const QString& str, choices )
195 bool ok = true;
196 int val = str.toInt( &ok );
197 if ( ok )
198 newchoices.append( val );
200 if ( !newchoices.isEmpty() )
201 q->setCurrentChoices( newchoices );
204 QString value() const
206 Q_Q( const FormFieldChoice );
207 QList<int> choices = q->currentChoices();
208 qSort( choices );
209 QStringList list;
210 foreach ( int c, choices )
212 list.append( QString::number( c ) );
214 return list.join( QLatin1String( ";" ) );
219 FormFieldChoice::FormFieldChoice()
220 : FormField( *new FormFieldChoicePrivate() )
224 FormFieldChoice::~FormFieldChoice()
228 bool FormFieldChoice::isEditable() const
230 return false;
233 bool FormFieldChoice::multiSelect() const
235 return false;
238 void FormFieldChoice::setCurrentChoices( const QList< int >& )
242 Qt::Alignment FormFieldChoice::textAlignment() const
244 return Qt::AlignVCenter | Qt::AlignLeft;
247 bool FormFieldChoice::canBeSpellChecked() const
249 return false;