]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/validators.h
get rid of QT3_SUPPORT and some cleanup
[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 /** A class to ascertain whether the data passed to the @c validate()
37  *  member function can be interpretted as a LyXGlueLength.
38  */
39 class LengthValidator : public QValidator
40 {
41         Q_OBJECT
42 public:
43         /// Define a validator for widget @c parent.
44         LengthValidator(QWidget * parent);
45
46         /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
47          *  If not, returns QValidator::Intermediate.
48          */
49         QValidator::State validate(QString & data, int &) const;
50
51         /** @name Bottom
52          *  Set and retrieve the minimum allowed LyXLength value.
53          */
54         //@{
55         void setBottom(LyXLength const &);
56         void setBottom(LyXGlueLength const &);
57         LyXLength bottom() const { return b_; }
58         //@}
59
60 private:
61 #if defined(Q_DISABLE_COPY)
62         LengthValidator( const LengthValidator & );
63         LengthValidator& operator=( const LengthValidator & );
64 #endif
65
66         LyXLength b_;
67         LyXGlueLength g_;
68         bool no_bottom_;
69         bool glue_length_;
70 };
71
72
73 /// @returns a new @c LengthValidator that does not accept negative lengths.
74 LengthValidator * unsignedLengthValidator(QLineEdit *);
75
76
77 // Forward declarations
78 class LyXRC;
79
80 namespace lyx {
81 namespace frontend {
82
83 class KernelDocType;
84
85 } // namespace frontend
86 } // namespace lyx
87
88
89 /** A class to ascertain whether the data passed to the @c validate()
90  *  member function is a valid file path.
91  *  The test is active only when the path is to be stored in a LaTeX
92  *  file, LaTeX being quite picky about legal names.
93  */
94 class PathValidator : public QValidator
95 {
96         Q_OBJECT
97 public:
98         /** Define a validator for widget @c parent.
99          *  If @c acceptable_if_empty is @c true then an empty path
100          *  is regarded as acceptable.
101          */
102         PathValidator(bool acceptable_if_empty, QWidget * parent);
103
104         /** @returns QValidator::Acceptable if @c data is a valid path.
105          *  If not, returns QValidator::Intermediate.
106          */
107         QValidator::State validate(QString &, int &) const;
108
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.
113          */
114         void setChecker(lyx::frontend::KernelDocType const & doc_type,
115                         LyXRC const & lyxrc);
116
117 private:
118 #if defined(Q_DISABLE_COPY)
119         PathValidator( const PathValidator & );
120         PathValidator& operator=( const PathValidator & );
121 #endif
122
123         bool acceptable_if_empty_;
124         bool latex_doc_;
125         bool tex_allows_spaces_;
126 };
127
128
129 /// @returns the PathValidator attached to the widget, or 0.
130 PathValidator * getPathValidator(QLineEdit *);
131
132 # endif // NOT VALIDATORS_H