Okular

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

KDE's Doxygen guidelines are available online.