* qt_helpers.{cpp,h}:

- get rid of function lengthAutoToWidgets, which was only used by GuiGraphics
	- new variant of lengthToWidgets that takes a docstring

* Validator.{cpp,h}:
	- the auto text in the Auto validators are customizable

* GuiGraphics.cpp:
	- make the "auto" string translatable

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28165 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-01-14 17:53:31 +00:00
parent 5707a39041
commit 94442d8b30
5 changed files with 48 additions and 39 deletions

View File

@ -74,6 +74,8 @@ char const * const rorigin_gui_strs[] = {
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
static string autostr = N_("automatically");
} // namespace anon
@ -99,8 +101,8 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
{
if (!checkBox->isChecked())
lengthToWidgets(lineEdit, lengthCombo,
"auto", lengthCombo->currentLengthItem());
else if (lineEdit->text() == "auto")
_(autostr), lengthCombo->currentLengthItem());
else if (lineEdit->text() == qt_(autostr))
lengthToWidgets(lineEdit, lengthCombo, string(),
lengthCombo->currentLengthItem());
}
@ -191,12 +193,13 @@ GuiGraphics::GuiGraphics(GuiView & lv)
filename->setValidator(new PathValidator(true, filename));
setFocusProxy(filename);
QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
QDoubleValidator * scaleValidator =
new DoubleAutoValidator(Scale, qt_(autostr));
scaleValidator->setBottom(0);
scaleValidator->setDecimals(256); //I guess that will do
Scale->setValidator(scaleValidator);
Height->setValidator(unsignedLengthAutoValidator(Height));
Width->setValidator(unsignedLengthAutoValidator(Width));
Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
//clipping pane
@ -338,7 +341,7 @@ void GuiGraphics::setAutoText()
if (scaleCB->isChecked())
return;
if (!Scale->isEnabled() && Scale->text() != "100")
Scale->setText(QString("auto"));
Scale->setText(qt_(autostr));
setAutoTextCB(WidthCB, Width, widthUnit);
setAutoTextCB(HeightCB, Height, heightUnit);
@ -565,20 +568,26 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
groupId->setCurrentIndex(groupId->findText(toqstr(igp.groupId), Qt::MatchExactly));
groupId->blockSignals(false);
lengthAutoToWidgets(Width, widthUnit, igp.width,
unitDefault);
if (igp.width.value() == 0)
lengthToWidgets(Width, widthUnit, _(autostr), unitDefault);
else
lengthToWidgets(Width, widthUnit, igp.width, unitDefault);
bool const widthChecked = !Width->text().isEmpty() &&
Width->text() != "auto";
Width->text() != qt_(autostr);
WidthCB->blockSignals(true);
WidthCB->setChecked(widthChecked);
WidthCB->blockSignals(false);
Width->setEnabled(widthChecked);
widthUnit->setEnabled(widthChecked);
lengthAutoToWidgets(Height, heightUnit, igp.height,
unitDefault);
if (igp.height.value() == 0)
lengthToWidgets(Height, heightUnit, _(autostr), unitDefault);
else
lengthToWidgets(Height, heightUnit, igp.height, unitDefault);
bool const heightChecked = !Height->text().isEmpty()
&& Height->text() != "auto";
&& Height->text() != qt_(autostr);
HeightCB->blockSignals(true);
HeightCB->setChecked(heightChecked);
HeightCB->blockSignals(false);

View File

@ -85,29 +85,31 @@ LengthValidator * unsignedLengthValidator(QLineEdit * ed)
}
LengthAutoValidator::LengthAutoValidator(QWidget * parent)
: LengthValidator(parent)
LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const autotext)
: LengthValidator(parent),
autotext_(autotext)
{}
QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) const
{
if (qtext == "auto")
if (qtext == autotext_)
return QValidator::Acceptable;
return LengthValidator::validate(qtext, dummy);
}
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed)
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const autotext)
{
LengthAutoValidator * v = new LengthAutoValidator(ed);
LengthAutoValidator * v = new LengthAutoValidator(ed, autotext);
v->setBottom(Length());
return v;
}
DoubleAutoValidator::DoubleAutoValidator(QWidget * parent)
: QDoubleValidator(parent)
DoubleAutoValidator::DoubleAutoValidator(QWidget * parent, QString const autotext)
: QDoubleValidator(parent),
autotext_(autotext)
{}
@ -118,7 +120,7 @@ DoubleAutoValidator::DoubleAutoValidator(double bottom,
QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
if (input == "auto")
if (input == autotext_)
return QValidator::Acceptable;
return QDoubleValidator::validate(input, pos);
}

View File

@ -75,44 +75,45 @@ private:
/// @returns a new @c LengthValidator that does not accept negative lengths.
LengthValidator * unsignedLengthValidator(QLineEdit *);
//FIXME This should be generalized to take "text" as part of the
//constructor and so to set what text we check for, rather than
//hard-coding it as "auto". But see qt_helpers.h for reasons this
//is not so trivial and an idea about how to do it. (RGH)
/** A class to ascertain whether the data passed to the @c validate()
* member function can be interpretted as a GlueLength or is "auto".
* member function can be interpretted as a GlueLength or is @param autotext.
*/
class LengthAutoValidator : public LengthValidator
{
Q_OBJECT
public:
/// Define a validator for widget @c parent.
LengthAutoValidator(QWidget * parent);
LengthAutoValidator(QWidget * parent, QString const autotext);
/** @returns QValidator::Acceptable if @c data is a GlueLength
* or is "auto". If not, returns QValidator::Intermediate.
*/
QValidator::State validate(QString & data, int &) const;
private:
QString autotext_;
};
/// @returns a new @c LengthAutoValidator that does not accept negative lengths.
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *);
LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const autotext);
//FIXME As above, this should really take a text argument.
/**
* A class to determine whether the passed is a double
* or is "auto".
* or is @param autotext.
*
*/
class DoubleAutoValidator : public QDoubleValidator
{
Q_OBJECT
public:
DoubleAutoValidator(QWidget * parent);
DoubleAutoValidator(QWidget * parent, QString const autotext);
DoubleAutoValidator(double bottom, double top, int decimals,
QObject * parent);
QValidator::State validate(QString & input, int & pos) const;
private:
QString autotext_;
};

View File

@ -130,13 +130,10 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
}
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
Length const & len, Length::UNIT defaultUnit)
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
docstring const & len, Length::UNIT defaultUnit)
{
if (len.value() == 0)
lengthToWidgets(input, combo, "auto", defaultUnit);
else
lengthToWidgets(input, combo, len, defaultUnit);
lengthToWidgets(input, combo, to_utf8(len), defaultUnit);
}

View File

@ -48,9 +48,9 @@ Length const & len, Length::UNIT default_unit);
/// method to set widgets from a string
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
std::string const & len, Length::UNIT default_unit);
/// method to set widgets from a Length with optional "auto" if zero
void lengthAutoToWidgets(QLineEdit * input, LengthCombo * combo,
Length const & len, Length::UNIT defaultUnit);
/// method to set widgets from a docstring
void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
docstring const & len, Length::UNIT default_unit);
/// colors a widget red if invalid
void setValid(QWidget * widget, bool valid);