]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/validators.h
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[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 #include <qvalidator.h>
30
31 class QWidget;
32 class QLineEdit;
33
34
35 /** A class to ascertain whether the data passed to the @c validate()
36  *  member function can be interpretted as a LyXGlueLength.
37  */
38 class LengthValidator : public QValidator
39 {
40         Q_OBJECT
41 public:
42         /// Define a validator for widget @c parent.
43         LengthValidator(QWidget * parent, const char *name = 0);
44
45         /** @returns QValidator::Acceptable if @c data is a LyXGlueLength.
46          *  If not, returns QValidator::Intermediate.
47          */
48         QValidator::State validate(QString & data, int &) const;
49
50         /** @name Bottom
51          *  Set and retrieve the minimum allowed LyXLength value.
52          */
53         //@{
54         void setBottom(LyXLength const &);
55         void setBottom(LyXGlueLength const &);
56         LyXLength bottom() const { return b_; }
57         //@}
58
59 private:
60 #if defined(Q_DISABLE_COPY)
61         LengthValidator( const LengthValidator & );
62         LengthValidator& operator=( const LengthValidator & );
63 #endif
64
65         LyXLength b_;
66         LyXGlueLength g_;
67         bool no_bottom_;
68         bool glue_length_;
69 };
70
71
72 /// @returns a new @c LengthValidator that does not accept negative lengths.
73 LengthValidator * unsignedLengthValidator(QLineEdit *);
74
75
76 // Forward declarations
77 class LyXRC;
78
79 namespace lyx {
80 namespace frontend {
81
82 class KernelDocType;
83
84 } // namespace frontend
85 } // namespace lyx
86
87
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.
92  */
93 class PathValidator : public QValidator
94 {
95         Q_OBJECT
96 public:
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.
100          */
101         PathValidator(bool acceptable_if_empty,
102                       QWidget * parent, const char *name = 0);
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