From 9c8cc9a3050cdf3b5eaed7866b4bba0a6f9de7e5 Mon Sep 17 00:00:00 2001 From: John Levon Date: Wed, 4 Dec 2002 02:57:14 +0000 Subject: [PATCH] fix bug 490 from Juergen S git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5770 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 ++ src/frontends/qt2/ChangeLog | 12 +++ src/frontends/qt2/QDocument.C | 122 ++++++++++++-------------- src/frontends/qt2/QDocument.h | 2 + src/frontends/qt2/qt_helpers.C | 35 ++++++++ src/frontends/qt2/qt_helpers.h | 13 +++ src/frontends/xforms/ChangeLog | 5 ++ src/frontends/xforms/xforms_helpers.C | 2 +- src/lyxlength.C | 8 +- src/lyxlength.h | 2 + 10 files changed, 139 insertions(+), 67 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index a135964a78..dfda1c2be8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2002-12-03 Juergen Spitzmueller + + * lyxlength.[Ch]: set default unit to UNIT_NONE, + implement bool empty() [bug 490] + 2002-12-02 Lars Gullik Bjønnes * text2.C, CutAndPaste.C: use BoostFormat.h not boost/format.hpp diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0c695071c8..a8ecb5ebe1 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,15 @@ +2002-12-04 John Levon + + * qt_helpers.h: + * qt_helpers.C: + * QDocument.h: + * QDocument.C: move methods below to helpers + +2002-11-03 Juergen Spitzmueller + + * QDocument.C: new methods widgetsToLength, lengthToWidgets. + set defaultUnit + 2002-12-03 John Levon * QIncludeDialog.C: another fix diff --git a/src/frontends/qt2/QDocument.C b/src/frontends/qt2/QDocument.C index e40c10ebf7..acc1cea0c2 100644 --- a/src/frontends/qt2/QDocument.C +++ b/src/frontends/qt2/QDocument.C @@ -25,12 +25,14 @@ #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() #include "lyxtextclasslist.h" #include "vspace.h" #include "bufferparams.h" +#include "qt_helpers.h" #include #include @@ -300,15 +302,11 @@ void QDocument::apply() params.papersize2 = dialog_->paperModule->papersizeCO->currentItem(); - params.paperwidth = - LyXLength(dialog_->paperModule->paperwidthLE->text().toDouble(), - dialog_->paperModule->paperwidthUnitCO->currentLengthItem() - ).asString(); + params.paperwidth = widgetsToLength(dialog_->paperModule->paperwidthLE, + dialog_->paperModule->paperwidthUnitCO); - params.paperheight = - LyXLength(dialog_->paperModule->paperheightLE->text().toDouble(), - dialog_->paperModule->paperheightUnitCO->currentLengthItem() - ).asString(); + params.paperheight = widgetsToLength(dialog_->paperModule->paperheightLE, + dialog_->paperModule->paperheightUnitCO); if (dialog_->paperModule->twoColumnCB->isChecked()) params.columns = 2; @@ -337,40 +335,19 @@ void QDocument::apply() MarginsModuleBase const * m(dialog_->marginsModule); - 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.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.footskip = widgetsToLength(m->footskipLE, m->footskipUnit); } @@ -400,6 +377,26 @@ void QDocument::update_contents() BufferParams const & params = controller().params(); + // set the default unit + // FIXME: move to controller + 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 +562,12 @@ void QDocument::update_contents() 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 +582,26 @@ void QDocument::update_contents() 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); } diff --git a/src/frontends/qt2/QDocument.h b/src/frontends/qt2/QDocument.h index 62432a88c2..fbcaa24196 100644 --- a/src/frontends/qt2/QDocument.h +++ b/src/frontends/qt2/QDocument.h @@ -24,6 +24,8 @@ class ControlDocument; class QDocumentDialog; +class LengthCombo; +class QLineEdit; class QDocument : public Qt2CB > diff --git a/src/frontends/qt2/qt_helpers.C b/src/frontends/qt2/qt_helpers.C index 9e3cf6b33c..76a56b50f8 100644 --- a/src/frontends/qt2/qt_helpers.C +++ b/src/frontends/qt2/qt_helpers.C @@ -14,9 +14,14 @@ #pragma implementation #endif +#include "support/lstrings.h" + #include "qt_helpers.h" +#include "lengthcombo.h" + #include +#include using std::pair; using std::make_pair; @@ -49,3 +54,33 @@ pair parseFontName(string const & name) name.substr(0, idx)); #endif } + + +string 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 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()); + } +} diff --git a/src/frontends/qt2/qt_helpers.h b/src/frontends/qt2/qt_helpers.h index 244db7b7d1..f9c6f7feeb 100644 --- a/src/frontends/qt2/qt_helpers.h +++ b/src/frontends/qt2/qt_helpers.h @@ -20,7 +20,20 @@ #include +#include "lyxlength.h" + +class LengthCombo; +class QLineEdit; + string makeFontName(string const & family, string const & foundry); + std::pair parseFontName(string const & name); +/// 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); + #endif // QTHELPERS_H diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 72184112a8..0bbc811b7e 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2002-12-03 Juergen Spitzmueller + + * xforms_helpers.C: (updateWidgetsFromLength) + use len.empty() instead of len.zero() [bug 490] + 2002-12-03 Lars Gullik Bjønnes * XWorkArea.C (work_area_handler): send fewer motion events if the diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 66e227fd44..edd06a4187 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -163,7 +163,7 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, 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 { diff --git a/src/lyxlength.C b/src/lyxlength.C index ff1b580c09..62ef59b666 100644 --- a/src/lyxlength.C +++ b/src/lyxlength.C @@ -27,7 +27,7 @@ using std::abs; LyXLength::LyXLength() - : val_(0), unit_(LyXLength::PT) + : val_(0), unit_(LyXLength::UNIT_NONE) {} @@ -123,6 +123,12 @@ bool LyXLength::zero() const } +bool LyXLength::empty() const +{ + return unit_ == LyXLength::UNIT_NONE; +} + + int LyXLength::inPixels(int text_width, int em_width_base) const { // Zoom factor specified by user in percent diff --git a/src/lyxlength.h b/src/lyxlength.h index 565d820fd6..dcf7198c18 100644 --- a/src/lyxlength.h +++ b/src/lyxlength.h @@ -63,6 +63,8 @@ public: void unit(LyXLength::UNIT unit); /// bool zero() const; + /// + bool empty() const; /// return string representation string const asString() const; /// return string representation for LaTeX -- 2.39.2