[EMAIL PROTECTED] wrote:
> ------- Additional Comments From [EMAIL PROTECTED]  2002-12-03 15:35
> ------- Your Qt patch is fine with me, with two changes :
>
> 1) don't start functions with uppercase letter
> 2) leave two empty lines between functions

Changed, updated and attached.

> Your other patch also seems fine to me. Update and send
> them to lyx-devel again and I'll apply them (and I'll
> take the heat if others whine)

OK, thanks. Attached too.
(Note that both patches need to be applied, or you have to change len.empty() 
to len.zero() in QDocument::lengthToWidgets)

Regards,
Jürgen
Index: src/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.991
diff -u -r1.991 ChangeLog
--- src/ChangeLog	2002/12/02 09:59:42	1.991
+++ src/ChangeLog	2002/12/03 15:11:19
@@ -1,3 +1,8 @@
+2002-12-03  Juergen Spitzmueller  <[EMAIL PROTECTED]>
+
+	* lyxlength.[Ch]: set default unit to UNIT_NONE,
+	implement bool empty() [bug 490]
+
 2002-12-02  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>

 	* text2.C, CutAndPaste.C: use BoostFormat.h not boost/format.hpp
@@ -126,7 +131,7 @@

 	* undo_funcs.C (textHandleUndo): fixed problems with undo introduced
 	by my last patch (hopefully).
-
+
 2002-11-08  John Levon  <[EMAIL PROTECTED]>

 	* iterators.h:
Index: src/lyxlength.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxlength.C,v
retrieving revision 1.25
diff -u -r1.25 lyxlength.C
--- src/lyxlength.C	2002/11/27 10:30:10	1.25
+++ src/lyxlength.C	2002/12/03 15:11:20
@@ -27,7 +27,7 @@
 using std::abs;
 
 LyXLength::LyXLength()
-	: val_(0), unit_(LyXLength::PT)
+	: val_(0), unit_(LyXLength::UNIT_NONE)
 {}
 
 
@@ -120,6 +120,12 @@
 bool LyXLength::zero() const
 {
 	return val_ == 0.0;
+}
+
+
+bool LyXLength::empty() const
+{
+	return unit_ == LyXLength::UNIT_NONE;
 }
 
 
Index: src/lyxlength.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxlength.h,v
retrieving revision 1.10
diff -u -r1.10 lyxlength.h
--- src/lyxlength.h	2002/10/24 18:31:45	1.10
+++ src/lyxlength.h	2002/12/03 15:11:20
@@ -63,6 +63,8 @@
 	void unit(LyXLength::UNIT unit);
 	///
 	bool zero() const;
+	///
+	bool empty() const;
 	/// return string representation
 	string const asString() const;
 	/// return string representation for LaTeX
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.630
diff -u -r1.630 ChangeLog
--- src/frontends/xforms/ChangeLog	2002/12/02 13:41:18	1.630
+++ src/frontends/xforms/ChangeLog	2002/12/03 15:11:36
@@ -1,3 +1,8 @@
+2002-12-03  Juergen Spitzmueller  <[EMAIL PROTECTED]>
+
+	* xforms_helpers.C: (updateWidgetsFromLength)
+	use len.empty() instead of len.zero() [bug 490]
+
 2002-12-02  Angus Leeming  <[EMAIL PROTECTED]>

 	* FormIndex.C (update): if the contents aren't empty, then activate the
Index: src/frontends/xforms/xforms_helpers.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/xforms/xforms_helpers.C,v
retrieving revision 1.53
diff -u -r1.53 xforms_helpers.C
--- src/frontends/xforms/xforms_helpers.C	2002/11/27 10:30:25	1.53
+++ src/frontends/xforms/xforms_helpers.C	2002/12/03 15:11:38
@@ -163,7 +163,7 @@
 	lyx::Assert(input  && input->objclass  == FL_INPUT &&
 		    choice && choice->objclass == FL_CHOICE);
 
-	if (len.zero()) {
+	if (len.empty()) {
 		fl_set_input(input, "");
 		fl_set_choice_text(choice, default_unit.c_str());
 	} else {
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.334
diff -u -r1.334 ChangeLog
--- src/frontends/qt2/ChangeLog	2002/12/03 05:27:19	1.334
+++ src/frontends/qt2/ChangeLog	2002/12/03 15:11:25
@@ -1,3 +1,8 @@
+2002-11-03  Juergen Spitzmueller  <[EMAIL PROTECTED]>
+
+	* QDocument.C: new methods widgetsToLength, lengthToWidgets.
+	set defaultUnit
+
 2002-12-03  John Levon  <[EMAIL PROTECTED]>

 	* QIncludeDialog.C: another fix
Index: src/frontends/qt2/QDocument.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QDocument.C,v
retrieving revision 1.28
diff -u -r1.28 QDocument.C
--- src/frontends/qt2/QDocument.C	2002/12/01 22:59:18	1.28
+++ src/frontends/qt2/QDocument.C	2002/12/03 15:11:27
@@ -25,6 +25,7 @@
 #include "helper_funcs.h" // getSecond()
 #include "insets/insetquotes.h"
 #include "frnt_lang.h"
+#include "lyxrc.h" // defaultUnit
 #include "tex-strings.h" // tex_graphics
 #include "support/lstrings.h" // tostr()
 #include "support/filetools.h" // LibFileSearch()
@@ -150,6 +151,36 @@
 }


+string QDocument::widgetsToLength(QLineEdit * const input, LengthCombo * const combo)
+{
+	QString length = input->text();
+	if (length.isEmpty())
+		return string();
+
+	// don't return unit-from-choice if the input(field) contains a unit
+	if (isValidGlueLength(length.latin1()))
+		return length.latin1();
+
+	LyXLength::UNIT unit = combo->currentLengthItem();
+
+	return LyXLength(length.toDouble(), unit).asString();
+}
+
+
+void QDocument::lengthToWidgets(QLineEdit * & input, LengthCombo * & combo,
+	string const & len, LyXLength::UNIT defaultUnit)
+{
+	if (len.empty()) {
+		// no length (UNIT_NONE)
+		combo->setCurrentItem(defaultUnit);
+		input->setText("");
+	} else {
+		combo->setCurrentItem(LyXLength(len).unit());
+		input->setText(tostr(LyXLength(len).value()).c_str());
+	}
+}
+
+
 void QDocument::apply()
 {
 	BufferParams & params = controller().params();
@@ -300,16 +331,12 @@
 	params.papersize2 =
 		dialog_->paperModule->papersizeCO->currentItem();
 
-	params.paperwidth =
-		LyXLength(dialog_->paperModule->paperwidthLE->text().toDouble(),
-			  dialog_->paperModule->paperwidthUnitCO->currentLengthItem()
-			).asString();
-
-	params.paperheight =
-		LyXLength(dialog_->paperModule->paperheightLE->text().toDouble(),
-			  dialog_->paperModule->paperheightUnitCO->currentLengthItem()
-			).asString();
+	params.paperwidth = widgetsToLength(dialog_->paperModule->paperwidthLE,
+		dialog_->paperModule->paperwidthUnitCO);
 
+	params.paperheight = widgetsToLength(dialog_->paperModule->paperheightLE,
+		dialog_->paperModule->paperheightUnitCO);
+
 	if (dialog_->paperModule->twoColumnCB->isChecked())
 		params.columns = 2;
 	else
@@ -336,41 +363,20 @@
 	params.paperpackage = char(margin);

 	MarginsModuleBase const * m(dialog_->marginsModule);
+
+	params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
+
+	params.topmargin = widgetsToLength(m->topLE, m->topUnit);
+
+	params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
+
+	params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
+
+	params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
+
+	params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);

-	params.leftmargin =
-		LyXLength(m->innerLE->text().toDouble(),
-			  m->innerUnit->currentLengthItem()
-			  ).asString();
-
-	params.topmargin =
-		LyXLength(m->topLE->text().toDouble(),
-			  m->topUnit->currentLengthItem()
-			  ).asString();
-
-	params.rightmargin =
-		LyXLength(m->outerLE->text().toDouble(),
-			  m->outerUnit->currentLengthItem()
-			  ).asString();
-
-	params.bottommargin =
-		LyXLength(m->bottomLE->text().toDouble(),
-			  m->bottomUnit->currentLengthItem()
-			  ).asString();
-
-	params.headheight =
-		LyXLength(m->headheightLE->text().toDouble(),
-			  m->headheightUnit->currentLengthItem()
-			  ).asString();
-
-	params.headsep =
-		LyXLength(m->headsepLE->text().toDouble(),
-			  m->headsepUnit->currentLengthItem()
-			  ).asString();
-
-	params.footskip =
-		LyXLength(m->footskipLE->text().toDouble(),
-			  m->footskipUnit->currentLengthItem()
-			  ).asString();
+	params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
 }

 
@@ -400,6 +406,25 @@
 
 	BufferParams const & params = controller().params();
 
+	// set the default unit
+	LyXLength::UNIT defaultUnit = LyXLength::CM;
+	switch (lyxrc.default_papersize) {
+		case BufferParams::PAPER_DEFAULT: break;
+
+		case BufferParams::PAPER_USLETTER:
+		case BufferParams::PAPER_LEGALPAPER:
+		case BufferParams::PAPER_EXECUTIVEPAPER:
+			defaultUnit = LyXLength::IN;
+			break;
+
+		case BufferParams::PAPER_A3PAPER:
+		case BufferParams::PAPER_A4PAPER:
+		case BufferParams::PAPER_A5PAPER:
+		case BufferParams::PAPER_B5PAPER:
+			defaultUnit = LyXLength::CM;
+			break;
+	}
+
 	// preamble
 	QString preamble = params.preamble.c_str();
 	dialog_->preambleModule->preambleMLE->setText(preamble);
@@ -565,17 +590,12 @@
 	dialog_->paperModule->twoColumnCB->setChecked(
 		params.columns == 2);

-	dialog_->paperModule->paperwidthUnitCO->setCurrentItem(
-		LyXLength(params.paperwidth).unit());
-
-	dialog_->paperModule->paperwidthLE->setText(
-		tostr(LyXLength(params.paperwidth).value()).c_str());

-	dialog_->paperModule->paperheightUnitCO->setCurrentItem(
-		LyXLength(params.paperheight).unit());
+	lengthToWidgets(dialog_->paperModule->paperwidthLE,
+		dialog_->paperModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
 
-	dialog_->paperModule->paperheightLE->setText(
-		tostr(LyXLength(params.paperheight).value()).c_str());
+	lengthToWidgets(dialog_->paperModule->paperheightLE,
+		dialog_->paperModule->paperheightUnitCO, params.paperheight, defaultUnit);

 	// margins

@@ -590,26 +610,26 @@
 	m->marginCO->setCurrentItem(item);
 	dialog_->setCustomMargins(item);

-	m->topUnit->setCurrentItem(LyXLength(params.topmargin).unit());
-	m->topLE->setText(tostr(LyXLength(params.topmargin).value()).c_str());
+	lengthToWidgets(m->topLE, m->topUnit,
+		params.topmargin, defaultUnit);
 
-	m->bottomUnit->setCurrentItem(LyXLength(params.bottommargin).unit());
-	m->bottomLE->setText(tostr(LyXLength(params.bottommargin).value()).c_str());
+	lengthToWidgets(m->bottomLE, m->bottomUnit,
+		params.bottommargin, defaultUnit);

-	m->innerUnit->setCurrentItem(LyXLength(params.leftmargin).unit());
-	m->innerLE->setText(tostr(LyXLength(params.leftmargin).value()).c_str());
+	lengthToWidgets(m->innerLE, m->innerUnit,
+		params.leftmargin, defaultUnit);
 
-	m->outerUnit->setCurrentItem(LyXLength(params.rightmargin).unit());
-	m->outerLE->setText(tostr(LyXLength(params.rightmargin).value()).c_str());
+	lengthToWidgets(m->outerLE, m->outerUnit,
+		params.rightmargin, defaultUnit);

-	m->headheightUnit->setCurrentItem(LyXLength(params.headheight).unit());
-	m->headheightLE->setText(tostr(LyXLength(params.headheight).value()).c_str());
+	lengthToWidgets(m->headheightLE, m->headheightUnit,
+		params.headheight, defaultUnit);
 
-	m->headsepUnit->setCurrentItem(LyXLength(params.headsep).unit());
-	m->headsepLE->setText(tostr(LyXLength(params.headsep).value()).c_str());
+	lengthToWidgets(m->headsepLE, m->headsepUnit,
+		params.headsep, defaultUnit);

-	m->footskipUnit->setCurrentItem(LyXLength(params.footskip).unit());
-	m->footskipLE->setText(tostr(LyXLength(params.footskip).value()).c_str());
+	lengthToWidgets(m->footskipLE, m->footskipUnit,
+		params.footskip, defaultUnit);
 }


Index: src/frontends/qt2/QDocument.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/qt2/QDocument.h,v
retrieving revision 1.14
diff -u -r1.14 QDocument.h
--- src/frontends/qt2/QDocument.h	2002/12/01 22:59:19	1.14
+++ src/frontends/qt2/QDocument.h	2002/12/03 15:17:11
@@ -34,6 +34,11 @@

 	QDocument();
 private:
+	/// method to get a LyXLength from widgets
+	string widgetsToLength(QLineEdit * const input, LengthCombo * const combo);
+	/// method to set widgets from a LyXLength
+	void lengthToWidgets(QLineEdit * & input, LengthCombo * & combo,
+		string const & len, LyXLength::UNIT default_unit);
 	/// Apply changes
 	void apply();
 	/// update

Reply via email to