Пример #1
0
QValidator::State LengthValidator::validate(QString & qtext, int &) const
{
	QLocale loc;
	bool ok;
	double d = loc.toDouble(qtext.trimmed(), &ok);
	// QLocale::toDouble accepts something like "1."
	// We don't.
	bool dp = qtext.endsWith(loc.decimalPoint());
	if (!ok) {
		// Fall back to C
		QLocale c(QLocale::C);
		d = c.toDouble(qtext.trimmed(), &ok);
		dp = qtext.endsWith(c.decimalPoint());
	}

	if (ok && unsigned_ && d < 0)
		return QValidator::Invalid;

	if (qtext.isEmpty() || (ok && !dp))
		return QValidator::Acceptable;

	string const text = fromqstr(qtext);

	if (glue_length_) {
		GlueLength gl;
		if (unsigned_ && gl.len().value() < 0)
			return QValidator::Invalid;
		return (isValidGlueLength(text, &gl)) ?
			QValidator::Acceptable : QValidator::Intermediate;
	}

	Length l;
	bool const valid_length = isValidLength(text, &l);
	if (!valid_length)
		return QValidator::Intermediate;

	if (no_bottom_)
		return QValidator::Acceptable;

	if (unsigned_ && l.value() < 0)
		return QValidator::Invalid;

	return b_.inPixels(100) <= l.inPixels(100) ?
		QValidator::Acceptable : QValidator::Intermediate;
}
Пример #2
0
bool operator==(GlueLength const & l1, GlueLength const & l2)
{
	return l1.len() == l2.len()
		 && l1.plus() == l2.plus()
		 && l1.minus() == l2.minus();
}