fix bug 490 from Juergen S

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5770 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-12-04 02:57:14 +00:00
parent c5058bffd8
commit 9c8cc9a305
10 changed files with 133 additions and 61 deletions

View File

@ -1,3 +1,8 @@
2002-12-03 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* lyxlength.[Ch]: set default unit to UNIT_NONE,
implement bool empty() [bug 490]
2002-12-02 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C, CutAndPaste.C: use BoostFormat.h not boost/format.hpp

View File

@ -1,3 +1,15 @@
2002-12-04 John Levon <levon@movementarian.org>
* qt_helpers.h:
* qt_helpers.C:
* QDocument.h:
* QDocument.C: move methods below to helpers
2002-11-03 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* QDocument.C: new methods widgetsToLength, lengthToWidgets.
set defaultUnit
2002-12-03 John Levon <levon@movementarian.org>
* QIncludeDialog.C: another fix

View File

@ -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 <qpushbutton.h>
#include <qmultilineedit.h>
@ -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.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
params.topmargin =
LyXLength(m->topLE->text().toDouble(),
m->topUnit->currentLengthItem()
).asString();
params.topmargin = widgetsToLength(m->topLE, m->topUnit);
params.rightmargin =
LyXLength(m->outerLE->text().toDouble(),
m->outerUnit->currentLengthItem()
).asString();
params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
params.bottommargin =
LyXLength(m->bottomLE->text().toDouble(),
m->bottomUnit->currentLengthItem()
).asString();
params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
params.headheight =
LyXLength(m->headheightLE->text().toDouble(),
m->headheightUnit->currentLengthItem()
).asString();
params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
params.headsep =
LyXLength(m->headsepLE->text().toDouble(),
m->headsepUnit->currentLengthItem()
).asString();
params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
params.footskip =
LyXLength(m->footskipLE->text().toDouble(),
m->footskipUnit->currentLengthItem()
).asString();
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());
lengthToWidgets(dialog_->paperModule->paperwidthLE,
dialog_->paperModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
dialog_->paperModule->paperheightUnitCO->setCurrentItem(
LyXLength(params.paperheight).unit());
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);
}

View File

@ -24,6 +24,8 @@
class ControlDocument;
class QDocumentDialog;
class LengthCombo;
class QLineEdit;
class QDocument
: public Qt2CB<ControlDocument, Qt2DB<QDocumentDialog> >

View File

@ -14,9 +14,14 @@
#pragma implementation
#endif
#include "support/lstrings.h"
#include "qt_helpers.h"
#include "lengthcombo.h"
#include <qglobal.h>
#include <qlineedit.h>
using std::pair;
using std::make_pair;
@ -49,3 +54,33 @@ pair<string,string> 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());
}
}

View File

@ -20,7 +20,20 @@
#include <utility>
#include "lyxlength.h"
class LengthCombo;
class QLineEdit;
string makeFontName(string const & family, string const & foundry);
std::pair<string,string> 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

View File

@ -1,3 +1,8 @@
2002-12-03 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* xforms_helpers.C: (updateWidgetsFromLength)
use len.empty() instead of len.zero() [bug 490]
2002-12-03 Lars Gullik Bjønnes <larsbj@birdstep.com>
* XWorkArea.C (work_area_handler): send fewer motion events if the

View File

@ -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 {

View File

@ -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

View File

@ -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