3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
14 #include "validators.h"
15 #include "qt_helpers.h"
20 #include "frontends/Alert.h"
22 #include "frontends/controllers/Dialog.h"
24 #include "support/docstring.h"
25 #include "support/lstrings.h"
26 #include "support/std_ostream.h"
33 using lyx::support::isStrDbl;
39 LengthValidator::LengthValidator(QWidget * parent)
41 no_bottom_(true), glue_length_(false)
45 QValidator::State LengthValidator::validate(QString & qtext, int &) const
47 string const text = fromqstr(qtext);
48 if (text.empty() || isStrDbl(text))
49 return QValidator::Acceptable;
53 return (isValidGlueLength(text, &gl)) ?
54 QValidator::Acceptable : QValidator::Intermediate;
58 bool const valid_length = isValidLength(text, &l);
60 return QValidator::Intermediate;
63 return QValidator::Acceptable;
65 return b_.inPixels(100) <= l.inPixels(100) ?
66 QValidator::Acceptable : QValidator::Intermediate;
70 void LengthValidator::setBottom(LyXLength const & b)
77 void LengthValidator::setBottom(LyXGlueLength const & g)
85 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
87 LengthValidator * v = new LengthValidator(ed);
88 v->setBottom(LyXLength());
93 PathValidator::PathValidator(bool acceptable_if_empty,
96 acceptable_if_empty_(acceptable_if_empty),
98 tex_allows_spaces_(false)
104 docstring const printable_list(docstring const & invalid_chars)
107 docstring::const_iterator const begin = invalid_chars.begin();
108 docstring::const_iterator const end = invalid_chars.end();
109 docstring::const_iterator it = begin;
111 for (; it != end; ++it) {
113 s += lyx::from_ascii(", ");
114 if (*it == lyx::char_type(' '))
126 QValidator::State PathValidator::validate(QString & qtext, int &) const
129 return QValidator::Acceptable;
131 docstring const text = lyx::support::trim(qstring_to_ucs4(qtext));
133 return acceptable_if_empty_ ?
134 QValidator::Acceptable : QValidator::Intermediate;
136 docstring invalid_chars = lyx::from_ascii("#$%{}()[]\"^");
137 if (!tex_allows_spaces_)
138 invalid_chars += ' ';
140 if (text.find_first_of(invalid_chars) != docstring::npos) {
142 static int counter = 0;
144 lyx::frontend::Alert::error(_("Invalid filename"),
145 _("LyX does not provide LateX support for file names containing any of these characters:\n") +
146 printable_list(invalid_chars));
149 return QValidator::Intermediate;
152 return QValidator::Acceptable;
156 void PathValidator::setChecker(lyx::frontend::KernelDocType const & type,
159 latex_doc_ = type == lyx::frontend::Kernel::LATEX;
160 tex_allows_spaces_ = lyxrc.tex_allows_spaces;
164 PathValidator * getPathValidator(QLineEdit * ed)
168 QValidator * validator = const_cast<QValidator *>(ed->validator());
171 return dynamic_cast<PathValidator *>(validator);
174 #include "validators_moc.cpp"