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;
41 LengthValidator::LengthValidator(QWidget * parent)
43 no_bottom_(true), glue_length_(false)
47 QValidator::State LengthValidator::validate(QString & qtext, int &) const
49 string const text = fromqstr(qtext);
50 if (text.empty() || isStrDbl(text))
51 return QValidator::Acceptable;
55 return (isValidGlueLength(text, &gl)) ?
56 QValidator::Acceptable : QValidator::Intermediate;
60 bool const valid_length = isValidLength(text, &l);
62 return QValidator::Intermediate;
65 return QValidator::Acceptable;
67 return b_.inPixels(100) <= l.inPixels(100) ?
68 QValidator::Acceptable : QValidator::Intermediate;
72 void LengthValidator::setBottom(LyXLength const & b)
79 void LengthValidator::setBottom(LyXGlueLength const & g)
87 LengthValidator * unsignedLengthValidator(QLineEdit * ed)
89 LengthValidator * v = new LengthValidator(ed);
90 v->setBottom(LyXLength());
95 PathValidator::PathValidator(bool acceptable_if_empty,
98 acceptable_if_empty_(acceptable_if_empty),
100 tex_allows_spaces_(false)
106 docstring const printable_list(docstring const & invalid_chars)
109 docstring::const_iterator const begin = invalid_chars.begin();
110 docstring::const_iterator const end = invalid_chars.end();
111 docstring::const_iterator it = begin;
113 for (; it != end; ++it) {
115 s += lyx::from_ascii(", ");
116 if (*it == lyx::char_type(' '))
128 QValidator::State PathValidator::validate(QString & qtext, int &) const
131 return QValidator::Acceptable;
133 docstring const text = lyx::support::trim(qstring_to_ucs4(qtext));
135 return acceptable_if_empty_ ?
136 QValidator::Acceptable : QValidator::Intermediate;
138 docstring invalid_chars = lyx::from_ascii("#$%{}()[]\"^");
139 if (!tex_allows_spaces_)
140 invalid_chars += ' ';
142 if (text.find_first_of(invalid_chars) != docstring::npos) {
144 static int counter = 0;
146 lyx::frontend::Alert::error(_("Invalid filename"),
147 _("LyX does not provide LateX support for file names containing any of these characters:\n") +
148 printable_list(invalid_chars));
151 return QValidator::Intermediate;
154 return QValidator::Acceptable;
158 void PathValidator::setChecker(lyx::frontend::KernelDocType const & type,
161 latex_doc_ = type == lyx::frontend::Kernel::LATEX;
162 tex_allows_spaces_ = lyxrc.tex_allows_spaces;
166 PathValidator * getPathValidator(QLineEdit * ed)
170 QValidator * validator = const_cast<QValidator *>(ed->validator());
173 return dynamic_cast<PathValidator *>(validator);
178 #include "validators_moc.cpp"