]> git.lyx.org Git - features.git/commitdiff
* qt_helpers.{cpp,h}:
authorJürgen Spitzmüller <spitz@lyx.org>
Wed, 14 Jan 2009 17:53:31 +0000 (17:53 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Wed, 14 Jan 2009 17:53:31 +0000 (17:53 +0000)
- 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
src/frontends/qt4/Validator.cpp
src/frontends/qt4/Validator.h
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

index aab4109be6f5420ef975952c5be87f1fb7469e5a..ec280162356bb8fab7241731f2b722d4e15ace26 100644 (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);
index 51103d957df393514ffbeee851c1fc1bbf373f7e..34141894971f0ca8020f2556b2adacc1909a9be3 100644 (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);
 }
index ee3ae343697d3d76c8d01d90acdcddf1c3e77225..81e46b0f571d175bc716272093775bfbff3a29e7 100644 (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_;
 };
 
 
index 8d37d7beccd6686e555778436ce85f26335185f1..e2a379d4c1c7b09b74bb941be7c5de2342bc6ae3 100644 (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);
 }
 
 
index 101ad94ba76ce2e484b3947f465fc2a2e5835beb..7e145f99ef38293d068adfe40e681ceaff5a6c00 100644 (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);