From 94442d8b30c779b37b5147a189549a5eb40c6076 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Wed, 14 Jan 2009 17:53:31 +0000 Subject: [PATCH] * 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 --- src/frontends/qt4/GuiGraphics.cpp | 33 ++++++++++++++++++++----------- src/frontends/qt4/Validator.cpp | 18 +++++++++-------- src/frontends/qt4/Validator.h | 21 ++++++++++---------- src/frontends/qt4/qt_helpers.cpp | 9 +++------ src/frontends/qt4/qt_helpers.h | 6 +++--- 5 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index aab4109be6..ec28016235 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -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); diff --git a/src/frontends/qt4/Validator.cpp b/src/frontends/qt4/Validator.cpp index 51103d957d..3414189497 100644 --- a/src/frontends/qt4/Validator.cpp +++ b/src/frontends/qt4/Validator.cpp @@ -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); } diff --git a/src/frontends/qt4/Validator.h b/src/frontends/qt4/Validator.h index ee3ae34369..81e46b0f57 100644 --- a/src/frontends/qt4/Validator.h +++ b/src/frontends/qt4/Validator.h @@ -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_; }; diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index 8d37d7becc..e2a379d4c1 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -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); } diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 101ad94ba7..7e145f99ef 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -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); -- 2.39.2