Attached is a patch that adds validators to all remaining qt dialogs.

One problem remains: The vspace input widget in QDocument does not have a 
label, so the validator does not work. Angus, what can be done? Can we have a 
checkedwidget that uses an other widget than a label? If so, what is the best 
implementation?

I have detected a second minor problem, independent from the frontend: In some 
widgets (e.g. screen fonts in Prefs, scale in QGraphics), when I enter 
"10.3", I get the following value after reopening the dialog:

10.30000019073486

Isn't this a bit too precise? ;-)

I don't know the exact reason for this, maybe tostr is to blame?

Regards,
Jürgen
Index: QDocument.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QDocument.C,v
retrieving revision 1.75
diff -u -r1.75 QDocument.C
--- QDocument.C	5 Oct 2004 10:11:40 -0000	1.75
+++ QDocument.C	29 Nov 2004 11:18:39 -0000
@@ -10,6 +10,7 @@
 
 #include <config.h>
 
+#include "checkedwidgets.h"
 #include "QDocument.h"
 #include "QDocumentDialog.h"
 #include "Qt2BC.h"
@@ -174,6 +175,28 @@
 	bcview().setApply(dialog_->applyPB);
 	bcview().setCancel(dialog_->closePB);
 	bcview().setRestore(dialog_->restorePB);
+	
+	// initialize the length validator
+	//addCheckedLineEdit(bcview(), dialog_->textLayoutModule->skipLE, 
+	//	FIXME: no label!);
+	addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperheightLE, 
+		dialog_->pageLayoutModule->paperheightL);
+	addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperwidthLE, 
+		dialog_->pageLayoutModule->paperwidthL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->topLE, 
+		dialog_->marginsModule->topL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->bottomLE, 
+		dialog_->marginsModule->bottomL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->innerLE, 
+		dialog_->marginsModule->innerL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->outerLE, 
+		dialog_->marginsModule->outerL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->headsepLE, 
+		dialog_->marginsModule->headsepL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->headheightLE, 
+		dialog_->marginsModule->headheightL);
+	addCheckedLineEdit(bcview(), dialog_->marginsModule->footskipLE, 
+		dialog_->marginsModule->footskipL);
 }
 
 
@@ -322,12 +345,10 @@
 		break;
 	case 3:
 	{
-		LyXLength::UNIT unit =
-			dialog_->textLayoutModule->skipLengthCO->
-			currentLengthItem();
-		double length =
-			dialog_->textLayoutModule->skipLE->text().toDouble();
-		VSpace vs = VSpace(LyXGlueLength(LyXLength(length,unit)));
+		VSpace vs = VSpace(
+			widgetsToLength(dialog_->textLayoutModule->skipLE, 
+				dialog_->textLayoutModule->skipLengthCO)
+			);
 		params.setDefSkip(vs);
 		break;
 	}
@@ -573,8 +594,9 @@
 	{
 		skip = 3;
 		string const length = params.getDefSkip().asLyXCommand();
-		dialog_->textLayoutModule->skipLengthCO->setCurrentItem(LyXLength(length).unit());
-		dialog_->textLayoutModule->skipLE->setText(toqstr(tostr(LyXLength(length).value())));
+		lengthToWidgets(dialog_->textLayoutModule->skipLE, 
+			dialog_->textLayoutModule->skipLengthCO, 
+			length, defaultUnit);
 		break;
 	}
 	default:
Index: QDocumentDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QDocumentDialog.C,v
retrieving revision 1.54
diff -u -r1.54 QDocumentDialog.C
--- QDocumentDialog.C	5 Oct 2004 10:11:40 -0000	1.54
+++ QDocumentDialog.C	29 Nov 2004 11:18:42 -0000
@@ -15,6 +15,7 @@
 
 #include "floatplacement.h"
 #include "lengthcombo.h"
+#include "lengthvalidator.h"
 #include "panelstack.h"
 #include "qt_helpers.h"
 
@@ -37,6 +38,7 @@
 #include <qpixmap.h>
 #include <qcolor.h>
 #include <qcolordialog.h>
+#include <qvalidator.h>
 
 using lyx::support::token;
 
@@ -45,6 +47,19 @@
 namespace lyx {
 namespace frontend {
 
+
+namespace {
+
+LengthValidator * unsignedLengthValidator(QLineEdit * ed)
+{
+	LengthValidator * v = new LengthValidator(ed);
+	v->setBottom(LyXLength());
+	return v;
+}
+
+} // namespace anon
+
+
 QDocumentDialog::QDocumentDialog(QDocument * form)
 	: QDocumentDialogBase(0, 0, false, 0), form_(form)
 {
@@ -172,6 +187,30 @@
 		SLOT(branchDoubleClicked(QListViewItem *)));
 	connect(branchesModule->colorPB, SIGNAL(clicked()), this, SLOT(toggleBranchColor()));
 	branchesModule->branchesLV->setSorting(0);
+	
+	textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
+		textLayoutModule->lspacingLE));
+	
+	textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
+		textLayoutModule->skipLE));
+	pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
+		pageLayoutModule->paperheightLE));
+	pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
+		pageLayoutModule->paperwidthLE));
+	marginsModule->topLE->setValidator(unsignedLengthValidator(
+		marginsModule->topLE));
+	marginsModule->bottomLE->setValidator(unsignedLengthValidator(
+		marginsModule->bottomLE));
+	marginsModule->innerLE->setValidator(unsignedLengthValidator(
+		marginsModule->innerLE));
+	marginsModule->outerLE->setValidator(unsignedLengthValidator(
+		marginsModule->outerLE));
+	marginsModule->headsepLE->setValidator(unsignedLengthValidator(
+		marginsModule->headsepLE));
+	marginsModule->headheightLE->setValidator(unsignedLengthValidator(
+		marginsModule->headheightLE));
+	marginsModule->footskipLE->setValidator(unsignedLengthValidator(
+		marginsModule->footskipLE));
 }
 
 
Index: QExternalDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QExternalDialog.C,v
retrieving revision 1.22
diff -u -r1.22 QExternalDialog.C
--- QExternalDialog.C	2 Jun 2004 20:13:18 -0000	1.22
+++ QExternalDialog.C	29 Nov 2004 11:18:42 -0000
@@ -78,9 +78,7 @@
 	xrED->setValidator(new QIntValidator(xrED));
 	ytED->setValidator(new QIntValidator(ytED));
 
-	// The width is initially set to 'scale' and so should accept
-	// a pure number only.
-	widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
+	widthED->setValidator(unsignedLengthValidator(widthED));
 	heightED->setValidator(unsignedLengthValidator(heightED));
 }
 
Index: QPrefsDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QPrefsDialog.C,v
retrieving revision 1.43
diff -u -r1.43 QPrefsDialog.C
--- QPrefsDialog.C	26 Nov 2004 14:52:53 -0000	1.43
+++ QPrefsDialog.C	29 Nov 2004 11:18:44 -0000
@@ -49,6 +49,7 @@
 #include <qpushbutton.h>
 #include <qspinbox.h>
 #include <qstring.h>
+#include <qvalidator.h>
 
 using std::string;
 
@@ -276,6 +277,28 @@
 	connect(screenfontsModule->screenHugerED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
 	connect(identityModule->nameED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
 	connect(identityModule->emailED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
+	
+	// initialize the validators
+	screenfontsModule->screenTinyED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenTinyED));
+	screenfontsModule->screenSmallestED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenSmallestED));
+	screenfontsModule->screenSmallerED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenSmallerED));
+	screenfontsModule->screenSmallED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenSmallED));
+	screenfontsModule->screenNormalED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenNormalED));
+	screenfontsModule->screenLargeED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenLargeED));
+	screenfontsModule->screenLargerED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenLargerED));
+	screenfontsModule->screenLargestED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenLargestED));
+	screenfontsModule->screenHugeED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenHugeED));
+	screenfontsModule->screenHugerED->setValidator(new QDoubleValidator(
+		screenfontsModule->screenHugerED));
 }
 
 
Index: QTabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QTabular.C,v
retrieving revision 1.31
diff -u -r1.31 QTabular.C
--- QTabular.C	20 May 2004 09:36:28 -0000	1.31
+++ QTabular.C	29 Nov 2004 11:18:44 -0000
@@ -12,6 +12,7 @@
 
 #include <config.h>
 
+#include "checkedwidgets.h"
 #include "QTabular.h"
 #include "QTabularDialog.h"
 #include "Qt2BC.h"
@@ -75,6 +76,10 @@
 	bcview().addReadOnly(dialog_->lastfooterBorderBelowCB);
 	bcview().addReadOnly(dialog_->lastfooterNoContentsCB);
 	bcview().addReadOnly(dialog_->newpageCB);
+	
+	// initialize the length validator
+	addCheckedLineEdit(bcview(), dialog_->widthED, 
+		dialog_->fixedWidthColLA);
 }
 
 
Index: QTabularDialog.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QTabularDialog.C,v
retrieving revision 1.24
diff -u -r1.24 QTabularDialog.C
--- QTabularDialog.C	2 Jun 2004 20:13:18 -0000	1.24
+++ QTabularDialog.C	29 Nov 2004 11:18:45 -0000
@@ -14,6 +14,7 @@
 
 #include "QTabularDialog.h"
 #include "QTabular.h"
+#include "lengthvalidator.h"
 #include "qt_helpers.h"
 
 #include "controllers/ControlTabular.h"
@@ -28,12 +29,26 @@
 namespace frontend {
 
 
+namespace {
+
+LengthValidator * unsignedLengthValidator(QLineEdit * ed)
+{
+	LengthValidator * v = new LengthValidator(ed);
+	v->setBottom(LyXLength());
+	return v;
+}
+
+} // namespace anon
+
+
 QTabularDialog::QTabularDialog(QTabular * form)
 	: QTabularDialogBase(0, 0, false, 0),
 	form_(form)
 {
 	connect(closePB, SIGNAL(clicked()),
 		form, SLOT(slotClose()));
+		
+	widthED->setValidator(unsignedLengthValidator(widthED));
 }
 
 
Index: lengthvalidator.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthvalidator.C,v
retrieving revision 1.6
diff -u -r1.6 lengthvalidator.C
--- lengthvalidator.C	26 Nov 2004 14:52:54 -0000	1.6
+++ lengthvalidator.C	29 Nov 2004 11:18:45 -0000
@@ -32,7 +32,7 @@
 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_) {

Reply via email to