4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
11 * Validators are used to decide upon the legality of some input action.
12 * For example, a "line edit" widget might be used to input a "glue length".
13 * The correct syntax for such a length is "2em + 0.5em". The LengthValidator
14 * below will report whether the input text conforms to this syntax.
16 * This information is used in LyX primarily to give the user some
17 * feedback on the validity of the input data using the "checked_widget"
18 * concept. For example, if the data is invalid then the label of
19 * a "line edit" widget is changed in colour and the dialog's "Ok"
20 * and "Apply" buttons are disabled. See checked_widgets.[Ch] for
27 #include "lyxlength.h"
28 #include "lyxgluelength.h"
29 #include <qvalidator.h>
35 /** A class to ascertain whether the data passed to the @c validate()
36 * member function can be interpretted as a LyXGlueLength.
38 class LengthValidator : public QValidator
42 /// Define a validator for widget @c parent.
43 LengthValidator(QWidget * parent, const char *name = 0);
45 /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
46 * If not, returns QValidator::Intermediate.
48 QValidator::State validate(QString & data, int &) const;
51 * Set and retrieve the minimum allowed LyXLength value.
54 void setBottom(LyXLength const &);
55 void setBottom(LyXGlueLength const &);
56 LyXLength bottom() const { return b_; }
60 #if defined(Q_DISABLE_COPY)
61 LengthValidator( const LengthValidator & );
62 LengthValidator& operator=( const LengthValidator & );
72 /// @returns a new @c LengthValidator that does not accept negative lengths.
73 LengthValidator * unsignedLengthValidator(QLineEdit *);
76 // Forward declarations
84 } // namespace frontend
88 /** A class to ascertain whether the data passed to the @c validate()
89 * member function is a valid file path.
90 * The test is active only when the path is to be stored in a LaTeX
91 * file, LaTeX being quite picky about legal names.
93 class PathValidator : public QValidator
97 /** Define a validator for widget @c parent.
98 * If @c acceptable_if_empty is @c true then an empty path
99 * is regarded as acceptable.
101 PathValidator(bool acceptable_if_empty,
102 QWidget * parent, const char *name = 0);
104 /** @returns QValidator::Acceptable if @c data is a valid path.
105 * If not, returns QValidator::Intermediate.
107 QValidator::State validate(QString &, int &) const;
109 /** Define what checks that @c validate() will perform.
110 * @param doc_type checks are activated only for @c LATEX docs.
111 * @param lyxrc contains a @c tex_allows_spaces member that
112 * is used to define what is legal.
114 void setChecker(lyx::frontend::KernelDocType const & doc_type,
115 LyXRC const & lyxrc);
118 #if defined(Q_DISABLE_COPY)
119 PathValidator( const PathValidator & );
120 PathValidator& operator=( const PathValidator & );
123 bool acceptable_if_empty_;
125 bool tex_allows_spaces_;
129 /// @returns the PathValidator attached to the widget, or 0.
130 PathValidator * getPathValidator(QLineEdit *);
132 # endif // NOT VALIDATORS_H