John,
I have added a method noPercents() to lengthcombo, which allows to use the 
lengthcombo widget without the %-items (text% and friends). With this, we can 
use lengthcombo for all length unit combos, including those who should not 
contain %-items (VSpace for instance). This also allows to use the qt_helpers 
widgetsToLength() etc (which really simplifies the code a lot).

Currently, we already have some lengthcombos which should not contain %-items, 
but do: paragraphSkip in documents (results in a LaTeX error) and papersize 
(falls back to A4 afaics). I'm not sure about margins. It does not produce an 
error, but xforms does not have %-items. The former two are fixed with the 
patch.

Opinions?
Jürgen.
Index: src/frontends/qt2/QDocument.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QDocument.C,v
retrieving revision 1.63
diff -u -r1.63 QDocument.C
--- src/frontends/qt2/QDocument.C	21 Nov 2003 11:38:16 -0000	1.63
+++ src/frontends/qt2/QDocument.C	30 Nov 2003 10:40:51 -0000
@@ -114,6 +114,9 @@
 	cb->insertItem(qt_("B3"));
 	cb->insertItem(qt_("B4"));
 	cb->insertItem(qt_("B5"));
+	// remove the %-items from the unit choice
+	dialog_->pageLayoutModule->paperwidthUnitCO->noPercents();
+	dialog_->pageLayoutModule->paperheightUnitCO->noPercents();

 	// layout
 	for (LyXTextClassList::const_iterator cit = textclasslist.begin();
@@ -141,6 +144,8 @@
 	dialog_->textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
 	dialog_->textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
 	dialog_->textLayoutModule->skipCO->insertItem(qt_("Length"));
+	// remove the %-items from the unit choice
+	dialog_->textLayoutModule->skipLengthCO->noPercents();

 	dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
 	dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
Index: src/frontends/qt2/QVSpace.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QVSpace.C,v
retrieving revision 1.2
diff -u -r1.2 QVSpace.C
--- src/frontends/qt2/QVSpace.C	29 Nov 2003 17:25:30 -0000	1.2
+++ src/frontends/qt2/QVSpace.C	30 Nov 2003 10:40:52 -0000
@@ -155,13 +155,7 @@
 	bcview().addReadOnly(dialog_->keepCB);

 	// remove the %-items from the unit choice
-	int num = dialog_->unitCO->count();
-	for (int i=0; i < num; i++) {
-		if (dialog_->unitCO->text(i).contains("%") > 0) {
-			dialog_->unitCO->removeItem(i);
-			i -= 1;
-		}
-	}
+	dialog_->unitCO->noPercents();
 }


Index: src/frontends/qt2/lengthcombo.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthcombo.C,v
retrieving revision 1.15
diff -u -r1.15 lengthcombo.C
--- src/frontends/qt2/lengthcombo.C	7 Sep 2003 01:45:38 -0000	1.15
+++ src/frontends/qt2/lengthcombo.C	30 Nov 2003 10:40:52 -0000
@@ -50,3 +50,15 @@
 {
 	QComboBox::setEnabled(b);
 }
+
+
+void LengthCombo::noPercents()
+{
+	int num = QComboBox::count();
+	for (int i=0; i < num; i++) {
+		if (QComboBox::text(i).contains("%") > 0) {
+			QComboBox::removeItem(i);
+			i -= 1;
+		}
+	}
+}
Index: src/frontends/qt2/lengthcombo.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/lengthcombo.h,v
retrieving revision 1.8
diff -u -r1.8 lengthcombo.h
--- src/frontends/qt2/lengthcombo.h	23 Aug 2003 00:16:39 -0000	1.8
+++ src/frontends/qt2/lengthcombo.h	30 Nov 2003 10:40:53 -0000
@@ -31,6 +31,8 @@
 	LyXLength::UNIT currentLengthItem() const;
 	/// enable the widget
 	virtual void setEnabled(bool b);
+	/// use the %-items?
+	virtual void noPercents();

 protected slots:
 	virtual void has_activated(int index);

Reply via email to