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)
22  , m_activateAction(nullptr)
23 {
24 }
25 
26 FormFieldPrivate::~FormFieldPrivate()
27 {
28  delete m_activateAction;
29  qDeleteAll(m_additionalActions);
30  qDeleteAll(m_additionalAnnotActions);
31 }
32 
33 void FormFieldPrivate::setDefault()
34 {
35  m_default = value();
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 class Okular::FormFieldButtonPrivate : public Okular::FormFieldPrivate
122 {
123 public:
124  FormFieldButtonPrivate()
125  : FormFieldPrivate(FormField::FormButton)
126  {
127  }
128 
129  Q_DECLARE_PUBLIC(FormFieldButton)
130 
131  void setValue(const QString &v) override
132  {
133  Q_Q(FormFieldButton);
134  q->setState(QVariant(v).toBool());
135  }
136 
137  QString value() const override
138  {
139  Q_Q(const FormFieldButton);
140  return QVariant::fromValue<bool>(q->state()).toString();
141  }
142 };
143 
144 FormFieldButton::FormFieldButton()
145  : FormField(*new FormFieldButtonPrivate())
146 {
147 }
148 
149 FormFieldButton::~FormFieldButton()
150 {
151 }
152 
154 {
155 }
156 
158 {
159 }
160 
161 class Okular::FormFieldTextPrivate : public Okular::FormFieldPrivate
162 {
163 public:
164  FormFieldTextPrivate()
165  : FormFieldPrivate(FormField::FormText)
166  {
167  }
168 
169  Q_DECLARE_PUBLIC(FormFieldText)
170 
171  void setValue(const QString &v) override
172  {
173  Q_Q(FormFieldText);
174  q->setText(v);
175  }
176 
177  QString value() const override
178  {
179  Q_Q(const FormFieldText);
180  return q->text();
181  }
182 };
183 
184 FormFieldText::FormFieldText()
185  : FormField(*new FormFieldTextPrivate())
186 {
187 }
188 
189 FormFieldText::~FormFieldText()
190 {
191 }
192 
194 {
195 }
196 
198 {
199  return false;
200 }
201 
203 {
204  return false;
205 }
206 
208 {
209  return -1;
210 }
211 
213 {
215 }
216 
218 {
219  return false;
220 }
221 
222 class Okular::FormFieldChoicePrivate : public Okular::FormFieldPrivate
223 {
224 public:
225  FormFieldChoicePrivate()
226  : FormFieldPrivate(FormField::FormChoice)
227  {
228  }
229 
230  Q_DECLARE_PUBLIC(FormFieldChoice)
231 
232  void setValue(const QString &v) override
233  {
234  Q_Q(FormFieldChoice);
235  const QStringList choices = v.split(QLatin1Char(';'), QString::SkipEmptyParts);
236  QList<int> newchoices;
237  for (const QString &str : choices) {
238  bool ok = true;
239  int val = str.toInt(&ok);
240  if (ok)
241  newchoices.append(val);
242  }
243  if (!newchoices.isEmpty())
244  q->setCurrentChoices(newchoices);
245  }
246 
247  QString value() const override
248  {
249  Q_Q(const FormFieldChoice);
250  QList<int> choices = q->currentChoices();
251  std::sort(choices.begin(), choices.end());
252  QStringList list;
253  for (const int c : qAsConst(choices)) {
254  list.append(QString::number(c));
255  }
256  return list.join(QStringLiteral(";"));
257  }
258 
259  QMap<QString, QString> exportValues;
260 };
261 
262 FormFieldChoice::FormFieldChoice()
263  : FormField(*new FormFieldChoicePrivate())
264 {
265 }
266 
267 FormFieldChoice::~FormFieldChoice()
268 {
269 }
270 
272 {
273  return false;
274 }
275 
277 {
278  return false;
279 }
280 
282 {
283 }
284 
286 {
287  return QString();
288 }
289 
291 {
292 }
293 
295 {
297 }
298 
300 {
301  return false;
302 }
303 
305 {
306  Q_D(FormFieldChoice);
307  d->exportValues = values;
308 }
309 
311 {
312  Q_D(const FormFieldChoice);
313  return d->exportValues.value(choice, choice);
314 }
315 
316 class Okular::FormFieldSignaturePrivate : public Okular::FormFieldPrivate
317 {
318 public:
319  FormFieldSignaturePrivate()
320  : FormFieldPrivate(FormField::FormSignature)
321  {
322  }
323 
324  Q_DECLARE_PUBLIC(FormFieldSignature)
325 
326  void setValue(const QString &v) override
327  {
328  Q_UNUSED(v)
329  }
330 
331  QString value() const override
332  {
333  return QString();
334  }
335 };
336 
337 FormFieldSignature::FormFieldSignature()
338  : FormField(*new FormFieldSignaturePrivate())
339 {
340 }
341 
342 FormFieldSignature::~FormFieldSignature()
343 {
344 }
virtual void setEditChoice(const QString &text)
Sets the text entered into an editable combo box choice field.
Definition: form.cpp:290
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:202
A choice field. See FormFieldChoice::ChoiceType.
Definition: form.h:55
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:304
FontType type() const
Returns the type of the font.
Definition: fontinfo.cpp:75
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:271
A field of variable text. See FormFieldText::TextType.
Definition: form.h:54
global.h
Definition: action.h:19
A "button". See FormFieldButton::ButtonType.
Definition: form.h:53
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:249
QString number(int n, int base)
AdditionalActionType
Describes the type of form additional action.
Definition: form.h:141
void append(const T &value)
virtual QString editChoice() const
The text entered into an editable combo box choice field.
Definition: form.cpp:285
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition: form.cpp:294
QString exportValueForChoice(const QString &choice) const
Returns the export value for a given choice.
Definition: form.cpp:310
Interface of a choice form field.
Definition: form.h:336
bool isEmpty() const const
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
Interface of a signature form field.
Definition: form.h:443
virtual void setIcon(Okular::FormField *field)
Sets the icon of the Button to the Icon of the field parameter.
Definition: form.cpp:157
virtual bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
Definition: form.cpp:299
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:207
virtual bool multiSelect() const
Whether more than one choice of this ListBox can be selected at the same time.
Definition: form.cpp:276
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:281
virtual void setVisible(bool value)
Whether the field is visible.
Definition: form.cpp:69
AdditionalActionType
Describes the type of additional actions.
Definition: annotations.h:183
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:153
virtual bool isPassword() const
Whether this text field is a password input, eg its text must be replaced with asterisks.
Definition: form.cpp:197
virtual void setText(const QString &text)
Sets the new text in the text field.
Definition: form.cpp:193
virtual Qt::Alignment textAlignment() const
The alignment of the text within the field.
Definition: form.cpp:212
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:217
QList::iterator begin()
Interface of a button form field.
Definition: form.h:186
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 Sun Sep 20 2020 22:35:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.