Okular

form.cpp
1 /***************************************************************************
2  * Copyright (C) 2007 by Pino Toscano <[email protected]> *
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  ***************************************************************************/
9 
10 #include "form.h"
11 #include "form_p.h"
12 
13 // qt includes
14 #include <QVariant>
15 
16 #include "action.h"
17 
18 using namespace Okular;
19 
20 FormFieldPrivate::FormFieldPrivate( FormField::FieldType type )
21  : m_type( type ), m_activateAction( nullptr )
22 {
23 }
24 
25 FormFieldPrivate::~FormFieldPrivate()
26 {
27  delete m_activateAction;
28  qDeleteAll( m_additionalActions );
29  qDeleteAll( m_additionalAnnotActions );
30 }
31 
32 void FormFieldPrivate::setDefault()
33 {
34  m_default = value();
35 }
36 
37 
38 FormField::FormField( FormFieldPrivate &dd )
39  : d_ptr( &dd )
40 {
41  d_ptr->q_ptr = this;
42 }
43 
44 FormField::~FormField()
45 {
46  delete d_ptr;
47 }
48 
50 {
51  Q_D( const FormField );
52  return d->m_type;
53 }
54 
56 {
57  return false;
58 }
59 
61 {
62 }
63 
65 {
66  return true;
67 }
68 
70 {
71 }
72 
74 {
75  return true;
76 }
77 
79 {
80 }
81 
82 Action* FormField::activationAction() const
83 {
84  Q_D( const FormField );
85  return d->m_activateAction;
86 }
87 
88 void FormField::setActivationAction( Action *action )
89 {
90  Q_D( FormField );
91  delete d->m_activateAction;
92  d->m_activateAction = action;
93 }
94 
96 {
97  Q_D( const FormField );
98  return d->m_additionalActions.value(type);
99 }
100 
101 void FormField::setAdditionalAction( AdditionalActionType type, Action *action )
102 {
103  Q_D( FormField );
104  delete d->m_additionalActions.value(type);
105  d->m_additionalActions[type] = action;
106 }
107 
109 {
110  Q_D( const FormField );
111  return d->m_additionalAnnotActions.value(type);
112 }
113 
114 void FormField::setAdditionalAction( Annotation::AdditionalActionType type, Action *action )
115 {
116  Q_D( FormField );
117  delete d->m_additionalAnnotActions.value(type);
118  d->m_additionalAnnotActions[type] = action;
119 }
120 
121 
122 class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
123 {
124  public:
125  FormFieldButtonPrivate()
126  : FormFieldPrivate( FormField::FormButton )
127  {
128  }
129 
130  Q_DECLARE_PUBLIC( FormFieldButton )
131 
132  void setValue( const QString& v ) override
133  {
134  Q_Q( FormFieldButton );
135  q->setState( QVariant( v ).toBool() );
136  }
137 
138  QString value() const override
139  {
140  Q_Q( const FormFieldButton );
141  return QVariant::fromValue<bool>( q->state() ).toString();
142  }
143 };
144 
145 
146 FormFieldButton::FormFieldButton()
147  : FormField( *new FormFieldButtonPrivate() )
148 {
149 }
150 
151 FormFieldButton::~FormFieldButton()
152 {
153 }
154 
156 {
157 }
158 
160 {
161 }
162 
163 
164 class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
165 {
166  public:
167  FormFieldTextPrivate()
168  : FormFieldPrivate( FormField::FormText )
169  {
170  }
171 
172  Q_DECLARE_PUBLIC( FormFieldText )
173 
174  void setValue( const QString& v ) override
175  {
176  Q_Q( FormFieldText );
177  q->setText( v );
178  }
179 
180  QString value() const override
181  {
182  Q_Q( const FormFieldText );
183  return q->text();
184  }
185 };
186 
187 
188 FormFieldText::FormFieldText()
189  : FormField( *new FormFieldTextPrivate() )
190 {
191 }
192 
193 FormFieldText::~FormFieldText()
194 {
195 }
196 
198 {
199 }
200 
202 {
203  return false;
204 }
205 
207 {
208  return false;
209 }
210 
212 {
213  return -1;
214 }
215 
217 {
218  return Qt::AlignVCenter | Qt::AlignLeft;
219 }
220 
222 {
223  return false;
224 }
225 
226 class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
227 {
228  public:
229  FormFieldChoicePrivate()
230  : FormFieldPrivate( FormField::FormChoice )
231  {
232  }
233 
234  Q_DECLARE_PUBLIC( FormFieldChoice )
235 
236  void setValue( const QString& v ) override
237  {
238  Q_Q( FormFieldChoice );
239  const QStringList choices = v.split( QLatin1Char (';'), QString::SkipEmptyParts );
240  QList<int> newchoices;
241  for ( const QString &str : choices )
242  {
243  bool ok = true;
244  int val = str.toInt( &ok );
245  if ( ok )
246  newchoices.append( val );
247  }
248  if ( !newchoices.isEmpty() )
249  q->setCurrentChoices( newchoices );
250  }
251 
252  QString value() const override
253  {
254  Q_Q( const FormFieldChoice );
255  QList<int> choices = q->currentChoices();
256  std::sort(choices.begin(), choices.end());
257  QStringList list;
258  for ( const int c : qAsConst(choices) )
259  {
260  list.append( QString::number( c ) );
261  }
262  return list.join( QStringLiteral( ";" ) );
263  }
264 
265  QMap<QString, QString> exportValues;
266 };
267 
268 
269 FormFieldChoice::FormFieldChoice()
270  : FormField( *new FormFieldChoicePrivate() )
271 {
272 }
273 
274 FormFieldChoice::~FormFieldChoice()
275 {
276 }
277 
279 {
280  return false;
281 }
282 
284 {
285  return false;
286 }
287 
289 {
290 }
291 
293 {
294  return QString();
295 }
296 
298 {
299 }
300 
302 {
303  return Qt::AlignVCenter | Qt::AlignLeft;
304 }
305 
307 {
308  return false;
309 }
310 
312 {
313  Q_D( FormFieldChoice );
314  d->exportValues = values;
315 }
316 
318 {
319  Q_D( const FormFieldChoice );
320  return d->exportValues.value(choice, choice);
321 }
322 
323 class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate
324 {
325  public:
326  FormFieldSignaturePrivate()
327  : FormFieldPrivate( FormField::FormSignature )
328  {
329  }
330 
331  Q_DECLARE_PUBLIC( FormFieldSignature )
332 
333  void setValue( const QString& v ) override
334  {
335  Q_UNUSED( v )
336  }
337 
338  QString value() const override
339  {
340  return QString();
341  }
342 };
343 
344 FormFieldSignature::FormFieldSignature()
345  : FormField( *new FormFieldSignaturePrivate() )
346 {
347 }
348 
349 FormFieldSignature::~FormFieldSignature()
350 {
351 }
virtual void setEditChoice(const QString &text)
Sets the text entered into an editable combo box choice field.
Definition: form.cpp:297
Action * additionalAction(AdditionalActionType type) const
Returns the additional action of the given type or nullptr if no action has been defined.
Definition: form.cpp:95
virtual bool isRichText() const
Whether this text field should allow rich text.
Definition: form.cpp:206
A choice field. See FormFieldChoice::ChoiceType.
Definition: form.h:56
virtual bool isPrintable() const
Whether this field is printable.
Definition: form.cpp:73
void setExportValues(const QMap< QString, QString > &values)
The possible choices of the choice field.
Definition: form.cpp:311
FontType type() const
Returns the type of the font.
Definition: fontinfo.cpp:81
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
FieldType
The types of form field.
Definition: form.h:52
virtual bool isEditable() const
Whether this ComboBox is editable, ie the user can type in a custom value.
Definition: form.cpp:278
A field of variable text. See FormFieldText::TextType.
Definition: form.h:55
global.h
Definition: action.h:19
A "button". See FormFieldButton::ButtonType.
Definition: form.h:54
virtual bool isVisible() const
Whether this form field is visible.
Definition: form.cpp:64
typedef Alignment
Interface of a text form field.
Definition: form.h:254
QString number(int n, int base)
AdditionalActionType
Describes the type of form additional action.
Definition: form.h:142
void append(const T &value)
virtual QString editChoice() const
The text entered into an editable combo box choice field.
Definition: form.cpp:292
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition: form.cpp:301
QString exportValueForChoice(const QString &choice) const
Returns the export value for a given choice.
Definition: form.cpp:317
Interface of a choice form field.
Definition: form.h:343
bool isEmpty() const const
Interface of a signature form field.
Definition: form.h:451
virtual void setIcon(Okular::FormField *field)
Sets the icon of the Button to the Icon of the field parameter.
Definition: form.cpp:159
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition: form.cpp:306
virtual int maximumLength() const
The maximum length allowed for the text of text field, or -1 if there is no limitation for the text...
Definition: form.cpp:211
virtual bool multiSelect() const
Whether more than one choice of this ListBox can be selected at the same time.
Definition: form.cpp:283
FieldType type() const
The type of the field.
Definition: form.cpp:49
QList::iterator end()
virtual bool isReadOnly() const
Whether the field is read-only.
Definition: form.cpp:55
virtual void setCurrentChoices(const QList< int > &choices)
Sets the selected choices to choices .
Definition: form.cpp:288
virtual void setVisible(bool value)
Whether the field is visible.
Definition: form.cpp:69
AdditionalActionType
Describes the type of additional actions.
Definition: annotations.h:192
Encapsulates data that describes an action.
Definition: action.h:43
virtual void setPrintable(bool value)
Set this field printable.
Definition: form.cpp:78
virtual void setState(bool state)
Sets the state of the button to the new state .
Definition: form.cpp:155
virtual bool isPassword() const
Whether this text field is a password input, eg its text must be replaced with asterisks.
Definition: form.cpp:201
virtual void setText(const QString &text)
Sets the new text in the text field.
Definition: form.cpp:197
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition: form.cpp:216
virtual void setReadOnly(bool value)
Whether the field is read-only.
Definition: form.cpp:60
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition: form.cpp:221
QList::iterator begin()
Interface of a button form field.
Definition: form.h:189
The base interface of a form field.
Definition: form.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 22:31:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.