From: Juergen Spitzmueller Date: Wed, 25 Sep 2024 08:22:36 +0000 (+0200) Subject: Factor out (signed) glueLenghValidator X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=112c2c3d0e224284096d0c92343a2b69935f92a2;p=lyx.git Factor out (signed) glueLenghValidator --- diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp index 32f98006d4..4eb945e1af 100644 --- a/src/frontends/qt/GuiDocument.cpp +++ b/src/frontends/qt/GuiDocument.cpp @@ -894,9 +894,7 @@ GuiDocument::GuiDocument(GuiView & lv) textLayoutModule->indentLE->setValidator(new LengthValidator( textLayoutModule->indentLE, false)); // parskip accepts glue length - LengthValidator * skipLEValidator = new LengthValidator(textLayoutModule->skipLE, false); - skipLEValidator->setBottom(GlueLength()); - textLayoutModule->skipLE->setValidator(skipLEValidator); + textLayoutModule->skipLE->setValidator(glueLengthValidator(textLayoutModule->skipLE)); textLayoutModule->indentCO->addItem(qt_("Default"), toqstr("default")); textLayoutModule->indentCO->addItem(qt_("Custom"), toqstr("custom")); diff --git a/src/frontends/qt/GuiLine.cpp b/src/frontends/qt/GuiLine.cpp index 8587a5d6eb..af981c3d76 100644 --- a/src/frontends/qt/GuiLine.cpp +++ b/src/frontends/qt/GuiLine.cpp @@ -56,10 +56,7 @@ GuiLine::GuiLine(QWidget * parent) : InsetParamsWidget(parent) addCheckedWidget(WidthLE, WidthValueL); addCheckedWidget(HeightLE, HeightValueL); - // Set up a signed glue length validator - LengthValidator * v = new LengthValidator(OffsetLE); - v->setBottom(GlueLength()); - OffsetLE->setValidator(v); + OffsetLE->setValidator(glueLengthValidator(OffsetLE)); WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE)); HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE)); diff --git a/src/frontends/qt/GuiVSpace.cpp b/src/frontends/qt/GuiVSpace.cpp index 7163634441..01fa980a52 100644 --- a/src/frontends/qt/GuiVSpace.cpp +++ b/src/frontends/qt/GuiVSpace.cpp @@ -53,10 +53,7 @@ GuiVSpace::GuiVSpace(QWidget * parent) : InsetParamsWidget(parent) connect(spacingCO, SIGNAL(activated(int)), this, SLOT(enableCustom(int))); - // Set up a signed glue length validator - LengthValidator * v = new LengthValidator(valueLE); - v->setBottom(GlueLength()); - valueLE->setValidator(v); + valueLE->setValidator(glueLengthValidator(valueLE)); // initialize the length validator addCheckedWidget(valueLE, valueL); diff --git a/src/frontends/qt/Validator.cpp b/src/frontends/qt/Validator.cpp index 9e8d8d07b9..f6f871e6a8 100644 --- a/src/frontends/qt/Validator.cpp +++ b/src/frontends/qt/Validator.cpp @@ -134,6 +134,15 @@ LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed) } +LengthValidator * glueLengthValidator(QLineEdit * ed) +{ + LengthValidator * v = new LengthValidator(ed); + v->setBottom(GlueLength()); + v->setUnsigned(false); + return v; +} + + LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const & autotext) : LengthValidator(parent), autotext_(autotext) diff --git a/src/frontends/qt/Validator.h b/src/frontends/qt/Validator.h index 0793cf8104..647b47733b 100644 --- a/src/frontends/qt/Validator.h +++ b/src/frontends/qt/Validator.h @@ -86,6 +86,11 @@ LengthValidator * unsignedLengthValidator(QLineEdit *); */ LengthValidator * unsignedGlueLengthValidator(QLineEdit *); +/** @returns a new @c LengthValidator that does accept negative lengths + * and glue lengths. + */ +LengthValidator * glueLengthValidator(QLineEdit *); + /** A class to ascertain whether the data passed to the @c validate() * member function can be interpreted as a GlueLength or is @param autotext.