size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
+static string autostr = N_("automatically");
+
} // namespace anon
{
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());
}
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
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);
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);
}
-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)
{}
QValidator::State DoubleAutoValidator::validate(QString & input, int & pos) const {
- if (input == "auto")
+ if (input == autotext_)
return QValidator::Acceptable;
return QDoubleValidator::validate(input, pos);
}
/// @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_;
};
}
-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);
}
/// 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);