1 /***************************************************************************
2 * Copyright (C) 2007 by Pino Toscano <pino@kde.org> *
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 #ifndef _OKULAR_FORM_H_
11 #define _OKULAR_FORM_H_
13 #include <okular/core/okular_export.h>
14 #include <okular/core/area.h>
16 #include <QtCore/QStringList>
23 class FormFieldPrivate
;
24 class FormFieldButtonPrivate
;
25 class FormFieldTextPrivate
;
26 class FormFieldChoicePrivate
;
29 * @short The base interface of a form field.
31 * This is the very basic interface to represent a field in a form.
33 * This is not meant to be used as a direct base for the form fields in a
34 * document, but its abstract subclasses are.
36 class OKULAR_EXPORT FormField
40 friend class PagePrivate
;
45 * The types of form field.
49 FormButton
, ///< A "button". See @ref FormFieldButton::ButtonType.
50 FormText
, ///< A field of variable text. See @ref FormFieldText::TextType.
51 FormChoice
, ///< A choice field. See @ref FormFieldChoice::ChoiceType.
52 FormSignature
///< A signature.
58 * The type of the field.
60 FieldType
type() const;
63 * The bouding rect of the field, in normalized coordinates.
65 virtual NormalizedRect
rect() const = 0;
68 * The ID of the field.
70 virtual int id() const = 0;
73 * The internal name of the field, to be used when referring to the
74 * field in eg scripts.
76 virtual QString
name() const = 0;
79 * The visible name of the field, to be used in the user interface
80 * (eg in error messages, etc).
82 virtual QString
uiName() const = 0;
85 * Whether the field is read-only.
87 virtual bool isReadOnly() const;
90 * Whether this form field is visible.
92 virtual bool isVisible() const;
94 Action
* activationAction() const;
98 FormField( FormFieldPrivate
&dd
);
99 Q_DECLARE_PRIVATE( FormField
)
100 FormFieldPrivate
*d_ptr
;
103 void setActivationAction( Action
*action
);
106 Q_DISABLE_COPY( FormField
)
111 * @short Interface of a button form field.
113 * This is the base interface to reimplement to represent a button field, like
114 * a push button, a check box or a radio button.
116 * @since 0.7 (KDE 4.1)
118 class OKULAR_EXPORT FormFieldButton
: public FormField
122 * The types of button field.
126 Push
, ///< A simple push button.
127 CheckBox
, ///< A check box.
128 Radio
///< A radio button.
131 virtual ~FormFieldButton();
134 The particular type of the button field.
136 virtual ButtonType
buttonType() const = 0;
139 * The caption to be used for the button.
141 virtual QString
caption() const = 0;
144 * The state of the button.
146 virtual bool state() const = 0;
149 * Sets the state of the button to the new \p state .
151 virtual void setState( bool state
);
154 * The list with the IDs of siblings (ie, buttons belonging to the same
155 * group as the current one.
157 * Valid only for \ref Radio buttons, an empty list otherwise.
159 virtual QList
< int > siblings() const = 0;
165 Q_DECLARE_PRIVATE( FormFieldButton
)
166 Q_DISABLE_COPY( FormFieldButton
)
171 * @short Interface of a text form field.
173 * This is the base interface to reimplement to represent a text field, ie a
174 * field where the user insert text.
176 class OKULAR_EXPORT FormFieldText
: public FormField
180 * The types of text field.
184 Normal
, ///< A simple singleline text field.
185 Multiline
, ///< A multiline text field.
186 FileSelect
///< An input field to select the path of a file on disk.
189 virtual ~FormFieldText();
192 * The particular type of the text field.
194 virtual TextType
textType() const = 0;
197 * The text of text field.
199 virtual QString
text() const = 0;
202 * Sets the new @p text in the text field.
204 * The default implementation does nothing.
206 * Reimplemented only if the setting of new text is supported.
208 virtual void setText( const QString
& text
);
211 * Whether this text field is a password input, eg its text @b must be
212 * replaced with asterisks.
214 * Always false for @ref FileSelect text fields.
216 virtual bool isPassword() const;
219 * Whether this text field should allow rich text.
221 virtual bool isRichText() const;
224 * The maximum length allowed for the text of text field, or -1 if
225 * there is no limitation for the text.
227 virtual int maximumLength() const;
230 * The alignment of the text within the field.
232 virtual Qt::Alignment
textAlignment() const;
235 * Whether the text inserted manually in the field (where possible)
236 * can be spell-checked.
238 * @note meaningful only if the field is editable.
240 virtual bool canBeSpellChecked() const;
246 Q_DECLARE_PRIVATE( FormFieldText
)
247 Q_DISABLE_COPY( FormFieldText
)
252 * @short Interface of a choice form field.
254 * This is the base interface to reimplement to represent a choice field, ie a
255 * field where the user can select one (of more) element(s) among a set of
258 class OKULAR_EXPORT FormFieldChoice
: public FormField
262 * The types of choice field.
266 ComboBox
, ///< A combo box choice field.
267 ListBox
///< A list box choice field.
270 virtual ~FormFieldChoice();
273 * The particular type of the choice field.
275 virtual ChoiceType
choiceType() const = 0;
278 * The possible choices of the choice field.
280 virtual QStringList
choices() const = 0;
283 * Whether this ComboBox is editable, ie the user can type in a custom
286 * Always false for the other types of choices.
288 virtual bool isEditable() const;
291 * Whether more than one choice of this ListBox can be selected at the
294 * Always false for the other types of choices.
296 virtual bool multiSelect() const;
299 * The currently selected choices.
301 * Always one element in the list in case of single choice elements.
303 virtual QList
< int > currentChoices() const = 0;
306 * Sets the selected choices to @p choices .
308 virtual void setCurrentChoices( const QList
< int >& choices
);
311 * The alignment of the text within the field.
313 virtual Qt::Alignment
textAlignment() const;
316 * Whether the text inserted manually in the field (where possible)
317 * can be spell-checked.
319 * @note meaningful only if the field is editable.
321 virtual bool canBeSpellChecked() const;
327 Q_DECLARE_PRIVATE( FormFieldChoice
)
328 Q_DISABLE_COPY( FormFieldChoice
)