File indexing completed on 2024-04-28 04:32:43
0001 /* 0002 SPDX-FileCopyrightText: 2007 Pino Toscano <pino@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _OKULAR_FORM_H_ 0008 #define _OKULAR_FORM_H_ 0009 0010 #include "annotations.h" 0011 #include "area.h" 0012 #include "document.h" 0013 #include "okularcore_export.h" 0014 #include "signatureutils.h" 0015 0016 #include <QStringList> 0017 0018 #include <memory> 0019 0020 namespace Okular 0021 { 0022 class Action; 0023 class Page; 0024 class PagePrivate; 0025 class FormFieldPrivate; 0026 class FormFieldButtonPrivate; 0027 class FormFieldTextPrivate; 0028 class FormFieldChoicePrivate; 0029 class FormFieldSignaturePrivate; 0030 0031 /** 0032 * @short The base interface of a form field. 0033 * 0034 * This is the very basic interface to represent a field in a form. 0035 * 0036 * This is not meant to be used as a direct base for the form fields in a 0037 * document, but its abstract subclasses are. 0038 */ 0039 class OKULARCORE_EXPORT FormField 0040 { 0041 /// @cond PRIVATE 0042 friend class Page; 0043 friend class PagePrivate; 0044 /// @endcond 0045 0046 public: 0047 /** 0048 * The types of form field. 0049 */ 0050 enum FieldType { 0051 FormButton, ///< A "button". See @ref FormFieldButton::ButtonType. 0052 FormText, ///< A field of variable text. See @ref FormFieldText::TextType. 0053 FormChoice, ///< A choice field. See @ref FormFieldChoice::ChoiceType. 0054 FormSignature ///< A signature. 0055 }; 0056 0057 virtual ~FormField(); 0058 0059 /** 0060 * The type of the field. 0061 */ 0062 FieldType type() const; 0063 0064 /** 0065 * The bounding rect of the field, in normalized coordinates. 0066 */ 0067 virtual NormalizedRect rect() const = 0; 0068 0069 /** 0070 * The ID of the field. 0071 */ 0072 virtual int id() const = 0; 0073 0074 /** 0075 * The internal name of the field, to be used when referring to the 0076 * field in eg scripts. 0077 */ 0078 virtual QString name() const = 0; 0079 0080 /** 0081 * The visible name of the field, to be used in the user interface 0082 * (eg in error messages, etc). 0083 */ 0084 virtual QString uiName() const = 0; 0085 0086 /** 0087 * The fully qualified name of the field, is used in the JavaScript 0088 * scripts. 0089 * 0090 * @since 1.9 0091 */ 0092 virtual QString fullyQualifiedName() const = 0; 0093 0094 /** 0095 * Whether the field is read-only. 0096 */ 0097 virtual bool isReadOnly() const; 0098 0099 /** 0100 * Whether the field is read-only. 0101 * 0102 * @since 1.4 0103 */ 0104 virtual void setReadOnly(bool value); 0105 0106 /** 0107 * Whether this form field is visible. 0108 */ 0109 virtual bool isVisible() const; 0110 0111 /** 0112 * Whether the field is visible. 0113 * 0114 * @since 1.5 0115 */ 0116 virtual void setVisible(bool value); 0117 0118 /** 0119 Whether this field is printable. 0120 0121 @since 1.9 0122 */ 0123 virtual bool isPrintable() const; 0124 0125 /** 0126 Set this field printable 0127 0128 @since 1.9 0129 */ 0130 virtual void setPrintable(bool value); 0131 0132 Action *activationAction() const; 0133 0134 /** 0135 * Describes the type of form additional action. 0136 * 0137 * @since 1.1 0138 */ 0139 enum AdditionalActionType { 0140 FieldModified, ///< An action to be performed when the user modifies the field 0141 FormatField, ///< An action to be performed before the field is formatted to display its value 0142 ValidateField, ///< An action to be performed when the field value changes 0143 CalculateField, ///< An action to be performed when the field needs to be recalculated 0144 }; 0145 0146 /** 0147 * Returns the additional action of the given @p type or @c nullptr if no action has been defined. 0148 * 0149 * @since 1.1 0150 */ 0151 Action *additionalAction(AdditionalActionType type) const; 0152 0153 /* Returns the additional action of the given @p type or @c nullptr if no action has been defined. 0154 * 0155 * This is for actions of annotation widgets associated with the FormField 0156 * 0157 * @since 1.5 0158 */ 0159 Action *additionalAction(Annotation::AdditionalActionType type) const; 0160 0161 /* Returns all the additional actions for this form 0162 * 0163 * @since 22.04 0164 */ 0165 QList<Action *> additionalActions() const; 0166 0167 /** 0168 * Returns the page of this form field 0169 * 0170 * @since 21.12.2 0171 */ 0172 Page *page() const; 0173 0174 protected: 0175 /// @cond PRIVATE 0176 explicit FormField(FormFieldPrivate &dd); 0177 Q_DECLARE_PRIVATE(FormField) 0178 FormFieldPrivate *d_ptr; 0179 /// @endcond 0180 0181 void setActivationAction(Action *action); 0182 void setAdditionalAction(AdditionalActionType type, Action *action); 0183 void setAdditionalAction(Annotation::AdditionalActionType type, Action *action); 0184 0185 private: 0186 Q_DISABLE_COPY(FormField) 0187 }; 0188 0189 /** 0190 * @short Interface of a button form field. 0191 * 0192 * This is the base interface to reimplement to represent a button field, like 0193 * a push button, a check box or a radio button. 0194 * 0195 * @since 0.7 (KDE 4.1) 0196 */ 0197 class OKULARCORE_EXPORT FormFieldButton : public FormField 0198 { 0199 public: 0200 /** 0201 * The types of button field. 0202 */ 0203 enum ButtonType { 0204 Push, ///< A simple push button. 0205 CheckBox, ///< A check box. 0206 Radio ///< A radio button. 0207 }; 0208 0209 ~FormFieldButton() override; 0210 0211 /** 0212 The particular type of the button field. 0213 */ 0214 virtual ButtonType buttonType() const = 0; 0215 0216 /** 0217 * The caption to be used for the button. 0218 */ 0219 virtual QString caption() const = 0; 0220 0221 /** 0222 * The state of the button. 0223 */ 0224 virtual bool state() const = 0; 0225 0226 /** 0227 * Sets the state of the button to the new \p state . 0228 */ 0229 virtual void setState(bool state); 0230 0231 /** 0232 * The list with the IDs of siblings (ie, buttons belonging to the same 0233 * group as the current one. 0234 * 0235 * Valid only for \ref Radio buttons, an empty list otherwise. 0236 */ 0237 virtual QList<int> siblings() const = 0; 0238 0239 /** 0240 * Sets the icon of the Button to the Icon of the field parameter. 0241 * 0242 * @since 1.9 0243 */ 0244 virtual void setIcon(Okular::FormField *field); 0245 0246 protected: 0247 FormFieldButton(); 0248 0249 private: 0250 Q_DECLARE_PRIVATE(FormFieldButton) 0251 Q_DISABLE_COPY(FormFieldButton) 0252 }; 0253 0254 /** 0255 * @short Interface of a text form field. 0256 * 0257 * This is the base interface to reimplement to represent a text field, ie a 0258 * field where the user insert text. 0259 */ 0260 class OKULARCORE_EXPORT FormFieldText : public FormField 0261 { 0262 public: 0263 /** 0264 * The types of text field. 0265 */ 0266 enum TextType { 0267 Normal, ///< A simple singleline text field. 0268 Multiline, ///< A multiline text field. 0269 FileSelect ///< An input field to select the path of a file on disk. 0270 }; 0271 0272 ~FormFieldText() override; 0273 0274 /** 0275 * The particular type of the text field. 0276 */ 0277 virtual TextType textType() const = 0; 0278 0279 /** 0280 * The text of text field. 0281 */ 0282 virtual QString text() const = 0; 0283 0284 /** 0285 * Sets the new @p text in the text field. 0286 * 0287 * The default implementation does nothing. 0288 * 0289 * Reimplemented only if the setting of new text is supported. 0290 */ 0291 virtual void setText(const QString &text); 0292 0293 /** 0294 * Whether this text field is a password input, eg its text @b must be 0295 * replaced with asterisks. 0296 * 0297 * Always false for @ref FileSelect text fields. 0298 */ 0299 virtual bool isPassword() const; 0300 0301 /** 0302 * Whether this text field should allow rich text. 0303 */ 0304 virtual bool isRichText() const; 0305 0306 /** 0307 * The maximum length allowed for the text of text field, or -1 if 0308 * there is no limitation for the text. 0309 */ 0310 virtual int maximumLength() const; 0311 0312 /** 0313 * The alignment of the text within the field. 0314 */ 0315 virtual Qt::Alignment textAlignment() const; 0316 0317 /** 0318 * Whether the text inserted manually in the field (where possible) 0319 * can be spell-checked. 0320 * 0321 * @note meaningful only if the field is editable. 0322 */ 0323 virtual bool canBeSpellChecked() const; 0324 0325 /** 0326 * Set the text which should be rendered by the PDF. 0327 * 0328 * @since 1.9 0329 */ 0330 virtual void setAppearanceText(const QString &text) = 0; 0331 0332 protected: 0333 FormFieldText(); 0334 0335 private: 0336 Q_DECLARE_PRIVATE(FormFieldText) 0337 Q_DISABLE_COPY(FormFieldText) 0338 }; 0339 0340 /** 0341 * @short Interface of a choice form field. 0342 * 0343 * This is the base interface to reimplement to represent a choice field, ie a 0344 * field where the user can select one (of more) element(s) among a set of 0345 * choices. 0346 */ 0347 class OKULARCORE_EXPORT FormFieldChoice : public FormField 0348 { 0349 public: 0350 /** 0351 * The types of choice field. 0352 */ 0353 enum ChoiceType { 0354 ComboBox, ///< A combo box choice field. 0355 ListBox ///< A list box choice field. 0356 }; 0357 0358 ~FormFieldChoice() override; 0359 0360 /** 0361 * The particular type of the choice field. 0362 */ 0363 virtual ChoiceType choiceType() const = 0; 0364 0365 /** 0366 * The possible choices of the choice field. 0367 */ 0368 virtual QStringList choices() const = 0; 0369 0370 /** 0371 * Whether this ComboBox is editable, ie the user can type in a custom 0372 * value. 0373 * 0374 * Always false for the other types of choices. 0375 */ 0376 virtual bool isEditable() const; 0377 0378 /** 0379 * Whether more than one choice of this ListBox can be selected at the 0380 * same time. 0381 * 0382 * Always false for the other types of choices. 0383 */ 0384 virtual bool multiSelect() const; 0385 0386 /** 0387 * The currently selected choices. 0388 * 0389 * Always one element in the list in case of single choice elements. 0390 */ 0391 virtual QList<int> currentChoices() const = 0; 0392 0393 /** 0394 * Sets the selected choices to @p choices . 0395 */ 0396 virtual void setCurrentChoices(const QList<int> &choices); 0397 0398 /** 0399 The text entered into an editable combo box choice field 0400 0401 @since 0.16 (KDE 4.10) 0402 */ 0403 virtual QString editChoice() const; 0404 0405 /** 0406 Sets the text entered into an editable combo box choice field 0407 0408 @since 0.16 (KDE 4.10) 0409 */ 0410 virtual void setEditChoice(const QString &text); 0411 0412 /** 0413 * The alignment of the text within the field. 0414 */ 0415 virtual Qt::Alignment textAlignment() const; 0416 0417 /** 0418 * Whether the text inserted manually in the field (where possible) 0419 * can be spell-checked. 0420 * 0421 * @note meaningful only if the field is editable. 0422 */ 0423 virtual bool canBeSpellChecked() const; 0424 0425 /** 0426 * Returns the export value for a given choice 0427 * 0428 * @since 1.11 0429 */ 0430 QString exportValueForChoice(const QString &choice) const; 0431 0432 protected: 0433 FormFieldChoice(); 0434 0435 /** 0436 * The possible choices of the choice field. 0437 * The key is the display name of the choice, 0438 * The value is the export value (i.e. for use in javascript, etc) of the choice 0439 * 0440 * @since 1.11 0441 */ 0442 void setExportValues(const QMap<QString, QString> &values); 0443 0444 private: 0445 Q_DECLARE_PRIVATE(FormFieldChoice) 0446 Q_DISABLE_COPY(FormFieldChoice) 0447 }; 0448 0449 /** 0450 * @short Interface of a signature form field. 0451 * 0452 * This is the base interface to reimplement to represent a signature field. 0453 */ 0454 class OKULARCORE_EXPORT FormFieldSignature : public FormField 0455 { 0456 public: 0457 /** 0458 * The types of signature. 0459 */ 0460 enum SignatureType { 0461 AdbePkcs7sha1, 0462 AdbePkcs7detached, 0463 EtsiCAdESdetached, 0464 UnknownType, 0465 UnsignedSignature ///< The signature field has not been signed yet. @since 22.04 0466 }; 0467 0468 ~FormFieldSignature() override; 0469 0470 /** 0471 * The signature type 0472 */ 0473 virtual SignatureType signatureType() const = 0; 0474 0475 /** 0476 * The signature info 0477 * @since 23.08 0478 */ 0479 virtual SignatureInfo signatureInfo() const = 0; 0480 0481 /** 0482 Signs a field of UnsignedSignature type. 0483 0484 @since 22.04 0485 */ 0486 virtual bool sign(const NewSignatureData &data, const QString &newPath) const = 0; 0487 0488 protected: 0489 FormFieldSignature(); 0490 0491 private: 0492 Q_DECLARE_PRIVATE(FormFieldSignature) 0493 Q_DISABLE_COPY(FormFieldSignature) 0494 }; 0495 0496 } 0497 0498 Q_DECLARE_METATYPE(const Okular::FormFieldSignature *); 0499 0500 #endif