2003-12-05 02:49:22 +00:00
|
|
|
/**
|
|
|
|
* \file lengthvalidator.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lengthvalidator.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
#include "qt_helpers.h"
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2003-12-10 09:26:18 +00:00
|
|
|
#include <qwidget.h>
|
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
|
|
|
|
using lyx::support::isStrDbl;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
2003-12-09 13:18:25 +00:00
|
|
|
LengthValidator::LengthValidator(QWidget * parent, const char * name)
|
2003-12-05 02:49:22 +00:00
|
|
|
: QValidator(parent, name),
|
2004-11-22 12:22:19 +00:00
|
|
|
no_bottom_(true), glue_length_(false)
|
2003-12-05 02:49:22 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
QValidator::State LengthValidator::validate(QString & qtext, int &) const
|
|
|
|
{
|
|
|
|
string const text = fromqstr(qtext);
|
2004-12-03 11:02:06 +00:00
|
|
|
if (text.empty() || isStrDbl(text))
|
2003-12-05 02:49:22 +00:00
|
|
|
return QValidator::Acceptable;
|
|
|
|
|
2004-11-22 12:22:19 +00:00
|
|
|
if (glue_length_) {
|
|
|
|
LyXGlueLength gl;
|
|
|
|
return (isValidGlueLength(text, &gl)) ?
|
|
|
|
QValidator::Acceptable : QValidator::Intermediate;
|
|
|
|
}
|
2004-11-26 14:52:54 +00:00
|
|
|
|
2003-12-05 02:49:22 +00:00
|
|
|
LyXLength l;
|
|
|
|
bool const valid_length = isValidLength(text, &l);
|
|
|
|
if (!valid_length)
|
|
|
|
return QValidator::Intermediate;
|
|
|
|
|
|
|
|
if (no_bottom_)
|
|
|
|
return QValidator::Acceptable;
|
|
|
|
|
|
|
|
return b_.inPixels(100) <= l.inPixels(100) ?
|
|
|
|
QValidator::Acceptable : QValidator::Intermediate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-22 12:22:19 +00:00
|
|
|
void LengthValidator::setBottom(LyXLength const & b)
|
2003-12-05 02:49:22 +00:00
|
|
|
{
|
|
|
|
b_ = b;
|
|
|
|
no_bottom_ = false;
|
|
|
|
}
|
2004-11-22 12:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LengthValidator::setBottom(LyXGlueLength const & g)
|
|
|
|
{
|
|
|
|
g_ = g;
|
|
|
|
no_bottom_ = false;
|
|
|
|
glue_length_ = true;
|
|
|
|
}
|