Lars Gullik Bjønnes wrote: > | Index: QExternalDialog.C > | =================================================================== > | RCS file: > | /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QExternalDialog.C,v > | retrieving revision 1.22 > | diff -p -u -r1.22 QExternalDialog.C > | --- QExternalDialog.C 2 Jun 2004 20:13:18 -0000 1.22 > | +++ QExternalDialog.C 22 Nov 2004 07:40:23 -0000 > | @@ -49,7 +49,8 @@ namespace { > | LengthValidator * unsignedLengthValidator(QLineEdit * ed) > | { > | LengthValidator * v = new LengthValidator(ed); > | - v->setBottom(LyXLength()); > | + LyXLength len = LyXLength(); > > LyXLength len;
Shouldn't len be (explicitely) initialized? I thought I got a compiler warning (but actually I don't). Anyway, changed. > | + v->setBottom(len); > | return v; > | } > | > | Index: QVSpaceDialog.C > | =================================================================== > | RCS file: > | /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QVSpaceDialog.C,v > | retrieving revision 1.8 > | diff -p -u -r1.8 QVSpaceDialog.C > | --- QVSpaceDialog.C 2 Jun 2004 20:13:18 -0000 1.8 > | +++ QVSpaceDialog.C 22 Nov 2004 07:40:23 -0000 > | @@ -27,6 +28,20 @@ > | namespace lyx { > | namespace frontend { > | > | + > | +namespace { > | + > | +LengthValidator * unsignedLengthValidator(QLineEdit * ed) > | +{ > | + LengthValidator * v = new LengthValidator(ed); > | + LyXGlueLength glen = LyXGlueLength(); > > LyXGlueLength glen; dito. > | + v->setBottom(glen); > | + return v; > | +} > > I really dont' like these returning pointers. I didn't invent these (that's Angus' original code). What do you propose? > | + > | +} // namespace anon > | + > | + > | QVSpaceDialog::QVSpaceDialog(QVSpace * form) > | > | : QVSpaceDialogBase(0, 0, false, 0), > | > | form_(form) > | Index: lengthvalidator.C > | =================================================================== > | RCS file: > | /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthvalidator.C,v > | retrieving revision 1.4 > | diff -p -u -r1.4 lengthvalidator.C > | --- lengthvalidator.C 20 May 2004 09:36:28 -0000 1.4 > | +++ lengthvalidator.C 22 Nov 2004 07:40:23 -0000 > | @@ -25,16 +25,24 @@ using std::string; > | > | LengthValidator::LengthValidator(QWidget * parent, const char * name) > | > | : QValidator(parent, name), > | > | - no_bottom_(true) > | + no_bottom_(true), glue_length_(false) > | {} > | > | > | QValidator::State LengthValidator::validate(QString & qtext, int &) > | const { > > is qtext in-out-argument? if not make it const. > The "int&" also look stragne. If I make it const, I get the following error: QExternalDialog.C: In function `LengthValidator* lyx::frontend::<unnamed>::unsignedLengthValidator(QLineEdit*)': QExternalDialog.C:51: error: cannot allocate an object of type `LengthValidator ' QExternalDialog.C:51: error: because the following virtual functions are abstract: /usr/lib/qt3/include/qvalidator.h:59: error: virtual QValidator::State QValidator::validate(QString&, int&) const No idea what the int is actually for (also not my code). > > | string const text = fromqstr(qtext); > | - if (text.empty() || isStrDbl(text)) > | + if (!text.empty() && isStrDbl(text)) > | return QValidator::Acceptable; > | > | + if (glue_length_) { > | + LyXGlueLength gl; > | + if (isValidGlueLength(text, &gl)) > > Why is this taking a pointer? Also not my code, but isValidGlueLength needs a pointer. lyxgluelenght.h (70): bool isValidGlueLength(std::string const & data, LyXGlueLength * result = 0); > | + return QValidator::Acceptable; > | + else > | + return QValidator::Intermediate; > | + } > > return (isValidGlueLength(text, &gl) ? > QValidator::Acceptable : > QValidator::Intermediate); ok. > | + > | LyXLength l; > | bool const valid_length = isValidLength(text, &l); > | if (!valid_length) > | @@ -48,8 +56,16 @@ QValidator::State LengthValidator::valid > | } > | > | > | -void LengthValidator::setBottom(LyXLength b) > | +void LengthValidator::setBottom(LyXLength & b) > | { > > why? should at least be "const &" ok. > | b_ = b; > | no_bottom_ = false; > | +} > | + > | + > | +bool LengthValidator::setBottom(LyXGlueLength & g) > > ditto ok. > | +{ > | + g_ = g; > | + no_bottom_ = false; > | + glue_length_ = true; > | } > | Index: lengthvalidator.h > | =================================================================== > | RCS file: > | /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthvalidator.h,v > | retrieving revision 1.3 > | diff -p -u -r1.3 lengthvalidator.h > | --- lengthvalidator.h 10 Dec 2003 09:26:18 -0000 1.3 > | +++ lengthvalidator.h 22 Nov 2004 07:40:23 -0000 > | @@ -13,6 +13,7 @@ > | #define LENGTHVALIDATOR_H > | > | #include "lyxlength.h" > | +#include "lyxgluelength.h" > | #include <qvalidator.h> > | > | class QWidget; > | @@ -26,7 +27,8 @@ public: > | > | QValidator::State validate(QString &, int &) const; > | > | - void setBottom(LyXLength); > | + void setBottom(LyXLength &); > | + bool setBottom(LyXGlueLength &); > > double-ditto double-ok. Partially changed patch attached. Jürgen
Index: QVSpace.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QVSpace.C,v retrieving revision 1.7 diff -p -u -r1.7 QVSpace.C --- QVSpace.C 20 May 2004 09:36:28 -0000 1.7 +++ QVSpace.C 22 Nov 2004 09:23:00 -0000 @@ -19,6 +19,7 @@ #include "QVSpaceDialog.h" #include "Qt2BC.h" +#include "checkedwidgets.h" #include "lengthcombo.h" #include "qt_helpers.h" @@ -150,6 +151,9 @@ void QVSpace::build_dialog() bcview().addReadOnly(dialog_->unitCO); bcview().addReadOnly(dialog_->keepCB); + // initialize the length validator + addCheckedLineEdit(bcview(), dialog_->valueLE, dialog_->valueL); + // remove the %-items from the unit choice dialog_->unitCO->noPercents(); } Index: QVSpaceDialog.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QVSpaceDialog.C,v retrieving revision 1.8 diff -p -u -r1.8 QVSpaceDialog.C --- QVSpaceDialog.C 2 Jun 2004 20:13:18 -0000 1.8 +++ QVSpaceDialog.C 22 Nov 2004 09:23:00 -0000 @@ -16,6 +16,7 @@ #include "QVSpace.h" #include "lengthcombo.h" +#include "lengthvalidator.h" #include "qt_helpers.h" #include <qcombobox.h> @@ -27,6 +28,19 @@ namespace lyx { namespace frontend { + +namespace { + +LengthValidator * unsignedLengthValidator(QLineEdit * ed) +{ + LengthValidator * v = new LengthValidator(ed); + v->setBottom(LyXGlueLength()); + return v; +} + +} // namespace anon + + QVSpaceDialog::QVSpaceDialog(QVSpace * form) : QVSpaceDialogBase(0, 0, false, 0), form_(form) @@ -37,6 +51,8 @@ QVSpaceDialog::QVSpaceDialog(QVSpace * f form_, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose())); + + valueLE->setValidator(unsignedLengthValidator(valueLE)); } @@ -55,7 +71,7 @@ void QVSpaceDialog::change_adaptor() void QVSpaceDialog::enableCustom(int) { - bool const enable = spacingCO->currentItem()==5; + bool const enable = spacingCO->currentItem() == 5; valueLE->setEnabled(enable); unitCO->setEnabled(enable); } Index: lengthcombo.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthcombo.C,v retrieving revision 1.19 diff -p -u -r1.19 lengthcombo.C --- lengthcombo.C 20 May 2004 09:36:28 -0000 1.19 +++ lengthcombo.C 22 Nov 2004 09:23:00 -0000 @@ -19,7 +19,7 @@ LengthCombo::LengthCombo(QWidget * parent, char * name) : QComboBox(parent, name) { - for (int i=0; i < num_units; i++) + for (int i = 0; i < num_units; i++) insertItem(unit_name_gui[i]); connect(this, SIGNAL(activated(int)), Index: lengthvalidator.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthvalidator.C,v retrieving revision 1.4 diff -p -u -r1.4 lengthvalidator.C --- lengthvalidator.C 20 May 2004 09:36:28 -0000 1.4 +++ lengthvalidator.C 22 Nov 2004 09:23:00 -0000 @@ -25,16 +25,22 @@ using std::string; LengthValidator::LengthValidator(QWidget * parent, const char * name) : QValidator(parent, name), - no_bottom_(true) + no_bottom_(true), glue_length_(false) {} QValidator::State LengthValidator::validate(QString & qtext, int &) const { string const text = fromqstr(qtext); - if (text.empty() || isStrDbl(text)) + if (!text.empty() && isStrDbl(text)) return QValidator::Acceptable; + if (glue_length_) { + LyXGlueLength gl; + return (isValidGlueLength(text, &gl)) ? + QValidator::Acceptable : QValidator::Intermediate; + } + LyXLength l; bool const valid_length = isValidLength(text, &l); if (!valid_length) @@ -48,8 +54,16 @@ QValidator::State LengthValidator::valid } -void LengthValidator::setBottom(LyXLength b) +void LengthValidator::setBottom(LyXLength const & b) { b_ = b; no_bottom_ = false; +} + + +void LengthValidator::setBottom(LyXGlueLength const & g) +{ + g_ = g; + no_bottom_ = false; + glue_length_ = true; } Index: lengthvalidator.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthvalidator.h,v retrieving revision 1.3 diff -p -u -r1.3 lengthvalidator.h --- lengthvalidator.h 10 Dec 2003 09:26:18 -0000 1.3 +++ lengthvalidator.h 22 Nov 2004 09:23:00 -0000 @@ -13,6 +13,7 @@ #define LENGTHVALIDATOR_H #include "lyxlength.h" +#include "lyxgluelength.h" #include <qvalidator.h> class QWidget; @@ -26,7 +27,8 @@ public: QValidator::State validate(QString &, int &) const; - void setBottom(LyXLength); + void setBottom(LyXLength const &); + void setBottom(LyXGlueLength const &); LyXLength bottom() const { return b_; } private: @@ -36,7 +38,9 @@ private: #endif LyXLength b_; + LyXGlueLength g_; bool no_bottom_; + bool glue_length_; }; # endif // NOT LENGTHVALIDATOR_H