]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/lengthvalidator.C
Minipage is no more (long live the box inset)
[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
16 #include "support/lstrings.h"
17
18 #include "qt_helpers.h"
19
20 #include <qwidget.h>
21
22
23 using lyx::support::isStrDbl;
24 using std::string;
25
26
27 LengthValidator::LengthValidator(QWidget * parent, const char * name)
28         : QValidator(parent, name),
29           no_bottom_(true)
30 {}
31
32
33 QValidator::State LengthValidator::validate(QString & qtext, int &) const
34 {
35         string const text = fromqstr(qtext);
36         if (text.empty() || isStrDbl(text))
37                 return QValidator::Acceptable;
38
39         LyXLength l;
40         bool const valid_length = isValidLength(text, &l);
41         if (!valid_length)
42                 return QValidator::Intermediate;
43
44         if (no_bottom_)
45                 return QValidator::Acceptable;
46
47         return b_.inPixels(100) <= l.inPixels(100) ?
48                 QValidator::Acceptable : QValidator::Intermediate;
49 }
50
51
52 void LengthValidator::setBottom(LyXLength b)
53 {
54         b_ = b;
55         no_bottom_ = false;
56 }