1 | /********************************************************************** |
2 | ** |
3 | ** Copyright (C) 1999 Glen Parker <glenebob@nwlink.com> |
4 | ** Copyright (C) 2002 Marc Mutz <mutz@kde.org> |
5 | ** |
6 | ** This library is free software; you can redistribute it and/or |
7 | ** modify it under the terms of the GNU Library General Public |
8 | ** License as published by the Free Software Foundation; either |
9 | ** version 2 of the License, or (at your option) any later version. |
10 | ** |
11 | ** This library is distributed in the hope that it will be useful, |
12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | ** Library General Public License for more details. |
15 | ** |
16 | ** You should have received a copy of the GNU Library General Public |
17 | ** License along with this library; if not, write to the Free |
18 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | ** |
20 | *****************************************************************************/ |
21 | |
22 | #ifndef KNUMVALIDATOR_H |
23 | #define KNUMVALIDATOR_H |
24 | |
25 | #include <kdeui_export.h> |
26 | |
27 | #include <QtGui/QValidator> |
28 | |
29 | class QWidget; |
30 | class QString; |
31 | |
32 | /** |
33 | * QValidator for integers. |
34 | |
35 | This can be used by QLineEdit or subclass to provide validated |
36 | text entry. Can be provided with a base value (default is 10), to allow |
37 | the proper entry of hexadecimal, octal, or any other base numeric data. |
38 | |
39 | @author Glen Parker <glenebob@nwlink.com> |
40 | @version 0.0.1 |
41 | */ |
42 | class KDEUI_EXPORT KIntValidator : public QValidator { |
43 | |
44 | public: |
45 | /** |
46 | * Constructor. Also sets the base value. |
47 | */ |
48 | explicit KIntValidator ( QWidget * parent, int base = 10 ); |
49 | /** |
50 | * Constructor. Also sets the minimum, maximum, and numeric base values. |
51 | */ |
52 | KIntValidator ( int bottom, int top, QWidget * parent, int base = 10 ); |
53 | /** |
54 | * Destructs the validator. |
55 | */ |
56 | virtual ~KIntValidator (); |
57 | /** |
58 | * Validates the text, and return the result. Does not modify the parameters. |
59 | */ |
60 | virtual State validate ( QString &, int & ) const; |
61 | /** |
62 | * Fixes the text if possible, providing a valid string. The parameter may be modified. |
63 | */ |
64 | virtual void fixup ( QString & ) const; |
65 | /** |
66 | * Sets the minimum and maximum values allowed. |
67 | * If @p top is greater than @p bottom, it is set to the value of @p bottom. |
68 | */ |
69 | virtual void setRange ( int bottom, int top ); |
70 | /** |
71 | * Sets the numeric base value. @p base must be between 2 and 36. |
72 | */ |
73 | virtual void setBase ( int base ); |
74 | /** |
75 | * Returns the current minimum value allowed. |
76 | */ |
77 | virtual int bottom () const; |
78 | /** |
79 | * Returns the current maximum value allowed. |
80 | */ |
81 | virtual int top () const; |
82 | /** |
83 | * Returns the current numeric base. |
84 | */ |
85 | virtual int base () const; |
86 | |
87 | private: |
88 | class KIntValidatorPrivate; |
89 | KIntValidatorPrivate * const d; |
90 | }; |
91 | |
92 | /** |
93 | \brief QValidator for floating point entry (Obsolete) |
94 | |
95 | @obsolete Use KDoubleValidator |
96 | |
97 | Extends the QValidator class to properly validate double numeric data. |
98 | This can be used by QLineEdit or subclass to provide validated |
99 | text entry. |
100 | |
101 | @author Glen Parker <glenebob@nwlink.com> |
102 | @version 0.0.1 |
103 | */ |
104 | class KDEUI_EXPORT_DEPRECATED KFloatValidator : public QValidator { |
105 | |
106 | public: |
107 | /** |
108 | * Constructor. |
109 | */ |
110 | explicit KFloatValidator ( QWidget * parent ); |
111 | /** |
112 | * Constructor. Also sets the minimum and maximum values. |
113 | */ |
114 | KFloatValidator ( double bottom, double top, QWidget * parent ); |
115 | /** |
116 | * Constructor. Sets the validator to be locale aware if @p localeAware is true. |
117 | */ |
118 | KFloatValidator ( double bottom, double top, bool localeAware, QWidget * parent ); |
119 | /** |
120 | * Destructs the validator. |
121 | */ |
122 | virtual ~KFloatValidator (); |
123 | /** |
124 | * Validates the text, and return the result. Does not modify the parameters. |
125 | */ |
126 | virtual State validate ( QString &, int & ) const; |
127 | /** |
128 | * Fixes the text if possible, providing a valid string. The parameter may be modified. |
129 | */ |
130 | virtual void fixup ( QString & ) const; |
131 | /** |
132 | * Sets the minimum and maximum value allowed. |
133 | */ |
134 | virtual void setRange ( double bottom, double top ); |
135 | /** |
136 | * Returns the current minimum value allowed. |
137 | */ |
138 | virtual double bottom () const; |
139 | /** |
140 | * Returns the current maximum value allowed. |
141 | */ |
142 | virtual double top () const; |
143 | /** |
144 | * Sets the validator to be locale aware if @p is true. In this case, the |
145 | * character KLocale::decimalSymbol() from the global locale is recognized |
146 | * as decimal separator. |
147 | */ |
148 | void setAcceptLocalizedNumbers(bool b); |
149 | /** |
150 | * Returns true if the validator is locale aware. |
151 | * @see setAcceptLocalizedNumbers(). |
152 | */ |
153 | bool acceptLocalizedNumbers() const; |
154 | |
155 | private: |
156 | class KFloatValidatorPrivate; |
157 | KFloatValidatorPrivate * const d; |
158 | }; |
159 | |
160 | /** |
161 | @short A locale-aware QDoubleValidator |
162 | |
163 | KDoubleValidator extends QDoubleValidator to be |
164 | locale-aware. That means that - subject to not being disabled - |
165 | KLocale::decimalSymbol(), KLocale::thousandsSeparator() |
166 | and KLocale::positiveSign() and KLocale::negativeSign() |
167 | are respected. |
168 | |
169 | @author Marc Mutz <mutz@kde.org> |
170 | @see KIntValidator |
171 | **/ |
172 | |
173 | class KDEUI_EXPORT KDoubleValidator : public QDoubleValidator { |
174 | Q_OBJECT |
175 | Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) |
176 | public: |
177 | /** Constuct a locale-aware KDoubleValidator with default range |
178 | (whatever QDoubleValidator uses for that) and parent @p |
179 | parent */ |
180 | explicit KDoubleValidator( QObject * parent ); |
181 | /** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p |
182 | top] and a precision of @p decimals decimals after the decimal |
183 | point. */ |
184 | KDoubleValidator( double bottom, double top, int decimals, |
185 | QObject * parent ); |
186 | /** Destructs the validator. |
187 | */ |
188 | virtual ~KDoubleValidator(); |
189 | |
190 | /** Overloaded for internal reasons. The API is not affected. */ |
191 | virtual QValidator::State validate( QString & input, int & pos ) const; |
192 | |
193 | /** @return whether localized numbers are accepted (default: true) */ |
194 | bool acceptLocalizedNumbers() const; |
195 | /** Sets whether to accept localized numbers (default: true) */ |
196 | void setAcceptLocalizedNumbers( bool accept ); |
197 | |
198 | private: |
199 | typedef QDoubleValidator base; |
200 | class KDoubleValidatorPrivate; |
201 | KDoubleValidatorPrivate * const d; |
202 | }; |
203 | |
204 | #endif |
205 | |