]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lengthvalidator.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / qt2 / lengthvalidator.C
1 /**
2  * \file lengthvalidator.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11
12 #include <config.h>
13
14 #include "lengthvalidator.h"
15 #include "qt_helpers.h"
16
17 #include "support/lstrings.h"
18
19 #include <qwidget.h>
20
21
22 using lyx::support::isStrDbl;
23 using std::string;
24
25
26 LengthValidator::LengthValidator(QWidget * parent, const char * name)
27         : QValidator(parent, name),
28           no_bottom_(true), glue_length_(false)
29 {}
30
31
32 QValidator::State LengthValidator::validate(QString & qtext, int &) const
33 {
34         string const text = fromqstr(qtext);
35         if (!text.empty() && isStrDbl(text))
36                 return QValidator::Acceptable;
37
38         if (glue_length_) {
39                 LyXGlueLength gl;
40                 return (isValidGlueLength(text, &gl)) ?
41                         QValidator::Acceptable : QValidator::Intermediate;
42                 }
43
44         LyXLength l;
45         bool const valid_length = isValidLength(text, &l);
46         if (!valid_length)
47                 return QValidator::Intermediate;
48
49         if (no_bottom_)
50                 return QValidator::Acceptable;
51
52         return b_.inPixels(100) <= l.inPixels(100) ?
53                 QValidator::Acceptable : QValidator::Intermediate;
54 }
55
56
57 void LengthValidator::setBottom(LyXLength const & b)
58 {
59         b_ = b;
60         no_bottom_ = false;
61 }
62
63
64 void LengthValidator::setBottom(LyXGlueLength const & g)
65 {
66         g_ = g;
67         no_bottom_ = false;
68         glue_length_ = true;
69 }