The attached patch adds a glue length validator to qt/lengthvalidator and uses 
it in QVSpace (this is related to bug . More dialogs to come.

Comments?

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	19 Nov 2004 13:53:52 -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	19 Nov 2004 13:53:52 -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	19 Nov 2004 13:53:53 -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	19 Nov 2004 13:53:53 -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
 {
 	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))
+			return QValidator::Acceptable;
+		else
+			return QValidator::Intermediate;
+		}
+		
 	LyXLength l;
 	bool const valid_length = isValidLength(text, &l);
 	if (!valid_length)
@@ -52,4 +60,12 @@ void LengthValidator::setBottom(LyXLengt
 {
 	b_ = b;
 	no_bottom_ = false;
+}
+
+
+bool LengthValidator::setBottom(LyXGlueLength 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	19 Nov 2004 13:53:53 -0000
@@ -13,6 +13,7 @@
 #define LENGTHVALIDATOR_H
 
 #include "lyxlength.h"
+#include "lyxgluelength.h"
 #include <qvalidator.h>
 
 class QWidget;
@@ -27,6 +28,7 @@ public:
 	QValidator::State validate(QString &, int &) const;
 
 	void setBottom(LyXLength);
+	bool setBottom(LyXGlueLength);
 	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

Reply via email to