]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/validators.h
* src/frontends/qt4/GuiSelection.C
[lyx.git] / src / frontends / qt4 / validators.h
1 // -*- C++ -*-
2 /**
3  * \file validators.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
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.
15  *
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
21  * further details.
22  */
23
24 #ifndef VALIDATORS_H
25 #define VALIDATORS_H
26
27 #include "lyxlength.h"
28 #include "lyxgluelength.h"
29
30 #include <QValidator>
31
32 class QWidget;
33 class QLineEdit;
34
35
36 namespace lyx {
37
38 /** A class to ascertain whether the data passed to the @c validate()
39  *  member function can be interpretted as a LyXGlueLength.
40  */
41 class LengthValidator : public QValidator
42 {
43         Q_OBJECT
44 public:
45         /// Define a validator for widget @c parent.
46         LengthValidator(QWidget * parent);
47
48         /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
49          *  If not, returns QValidator::Intermediate.
50          */
51         QValidator::State validate(QString & data, int &) const;
52
53         /** @name Bottom
54          *  Set and retrieve the minimum allowed LyXLength value.
55          */
56         //@{
57         void setBottom(LyXLength const &);
58         void setBottom(LyXGlueLength const &);
59         LyXLength bottom() const { return b_; }
60         //@}
61
62 private:
63 #if defined(Q_DISABLE_COPY)
64         LengthValidator( const LengthValidator & );
65         LengthValidator& operator=( const LengthValidator & );
66 #endif
67
68         LyXLength b_;
69         LyXGlueLength g_;
70         bool no_bottom_;
71         bool glue_length_;
72 };
73
74
75 /// @returns a new @c LengthValidator that does not accept negative lengths.
76 LengthValidator * unsignedLengthValidator(QLineEdit *);
77
78
79 // Forward declarations
80 class LyXRC;
81
82 namespace frontend { class KernelDocType; } 
83
84
85 /** A class to ascertain whether the data passed to the @c validate()
86  *  member function is a valid file path.
87  *  The test is active only when the path is to be stored in a LaTeX
88  *  file, LaTeX being quite picky about legal names.
89  */
90 class PathValidator : public QValidator
91 {
92         Q_OBJECT
93 public:
94         /** Define a validator for widget @c parent.
95          *  If @c acceptable_if_empty is @c true then an empty path
96          *  is regarded as acceptable.
97          */
98         PathValidator(bool acceptable_if_empty, QWidget * parent);
99
100         /** @returns QValidator::Acceptable if @c data is a valid path.
101          *  If not, returns QValidator::Intermediate.
102          */
103         QValidator::State validate(QString &, int &) const;
104
105         /** Define what checks that @c validate() will perform.
106          *  @param doc_type checks are activated only for @c LATEX docs.
107          *  @param lyxrc contains a @c tex_allows_spaces member that
108          *  is used to define what is legal.
109          */
110         void setChecker(frontend::KernelDocType const & doc_type,
111                         LyXRC const & lyxrc);
112
113 private:
114 #if defined(Q_DISABLE_COPY)
115         PathValidator(const PathValidator &);
116         PathValidator & operator=(const PathValidator &);
117 #endif
118
119         bool acceptable_if_empty_;
120         bool latex_doc_;
121         bool tex_allows_spaces_;
122 };
123
124
125 /// @returns the PathValidator attached to the widget, or 0.
126 PathValidator * getPathValidator(QLineEdit *);
127
128 } // namespace lyx
129
130 # endif // NOT VALIDATORS_H