From: John Levon Date: Sun, 17 Nov 2002 11:24:08 +0000 (+0000) Subject: graphics fixes from herbert and me X-Git-Tag: 1.6.10~17949 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2e385ab589e5ccc90f3a13aa45b2c5fca3b02d60;p=features.git graphics fixes from herbert and me git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5660 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index bbe23aa462..2ba6fd50ea 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2002-11-17 John Levon + + * QGraphics.C: some fixes from Herbert & me + 2002-11-15 Juergen Spitzmueller * FileDialog.C: fix empty mask string diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index 4be626a1ce..bdc1810a1a 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -44,6 +44,7 @@ #include "Qt2BC.h" using std::vector; +using std::endl; typedef Qt2CB > base_class; @@ -97,51 +98,23 @@ void QGraphics::build_dialog() bc().addReadOnly(dialog_->origin); bc().addReadOnly(dialog_->latexoptions); bc().addReadOnly(dialog_->getPB); - - using namespace frnt; - vector origindata = getRotationOriginData(); - vector const origin_lang = getFirst(origindata); - origin_ltx = getSecond(origindata); - // build the list - for (vector::const_iterator it = origin_lang.begin(); - it != origin_lang.end(); ++it) { - dialog_->origin->insertItem((*it).c_str(), -1); - } - - // clear and fill in the comboboxes - vector const bb_units = getBBUnits(); - dialog_->lbXunit->clear(); - dialog_->lbYunit->clear(); - dialog_->rtXunit->clear(); - dialog_->rtYunit->clear(); - for (vector::const_iterator it = bb_units.begin(); - it != bb_units.end(); ++it) { - dialog_->lbXunit->insertItem((*it).c_str(), -1); - dialog_->lbYunit->insertItem((*it).c_str(), -1); - dialog_->rtXunit->insertItem((*it).c_str(), -1); - dialog_->rtYunit->insertItem((*it).c_str(), -1); - } - } namespace { - + // returns the number of the string s in the vector v int getItemNo(vector v, string const & s) { vector::const_iterator cit = find(v.begin(), v.end(), s); - if (cit != v.end()) - return int(cit - v.begin()); - - return 0; + return (cit != v.end()) ? int(cit - v.begin()) : 0; } // returns the number of the unit in the array unit_name, // which is defined in lengthcommon.C -int getUnitNo(string const & s) { +int getUnitNo(char const * c[], string const & s) { int i = 0; - while (i < num_units && s != unit_name[i]) + while (i < num_units && s != c[i]) ++i; return (i < num_units) ? i : 0; } @@ -151,24 +124,38 @@ int getUnitNo(string const & s) { void QGraphics::update_contents() { + // clear and fill in the comboboxes + vector const bb_units = frnt::getBBUnits(); + dialog_->lbXunit->clear(); + dialog_->lbYunit->clear(); + dialog_->rtXunit->clear(); + dialog_->rtYunit->clear(); + for (vector::const_iterator it = bb_units.begin(); + it != bb_units.end(); ++it) { + dialog_->lbXunit->insertItem((*it).c_str(), -1); + dialog_->lbYunit->insertItem((*it).c_str(), -1); + dialog_->rtXunit->insertItem((*it).c_str(), -1); + dialog_->rtYunit->insertItem((*it).c_str(), -1); + } + InsetGraphicsParams & igp = controller().params(); // set the right default unit - string unitDefault("cm"); + LyXLength::UNIT unitDefault = LyXLength::CM; switch (lyxrc.default_papersize) { case BufferParams::PAPER_DEFAULT: break; case BufferParams::PAPER_USLETTER: case BufferParams::PAPER_LEGALPAPER: case BufferParams::PAPER_EXECUTIVEPAPER: - unitDefault = "in"; + unitDefault = LyXLength::IN; break; case BufferParams::PAPER_A3PAPER: case BufferParams::PAPER_A4PAPER: case BufferParams::PAPER_A5PAPER: case BufferParams::PAPER_B5PAPER: - unitDefault = "cm"; + unitDefault = LyXLength::CM; break; } @@ -176,17 +163,19 @@ void QGraphics::update_contents() // set the bounding box values if (igp.bb.empty()) { - controller().bbChanged = false; string const bb = controller().readBB(igp.filename); - // the values from the file always have the point-unit + // the values from the file always have the bigpoint-unit bp dialog_->lbX->setText(token(bb, ' ', 0).c_str()); dialog_->lbY->setText(token(bb, ' ', 1).c_str()); dialog_->rtX->setText(token(bb, ' ', 2).c_str()); dialog_->rtY->setText(token(bb, ' ', 3).c_str()); + dialog_->lbXunit->setCurrentItem(0); + dialog_->lbYunit->setCurrentItem(0); + dialog_->rtXunit->setCurrentItem(0); + dialog_->rtYunit->setCurrentItem(0); + controller().bbChanged = false; } else { // get the values from the inset - controller().bbChanged = true; - vector const bb_units = frnt::getBBUnits(); LyXLength anyLength; string const xl(token(igp.bb,' ',0)); string const yl(token(igp.bb,' ',1)); @@ -220,6 +209,7 @@ void QGraphics::update_contents() } else { dialog_->rtY->setText(xl.c_str()); } + controller().bbChanged = true; } // Update the draft and clip mode @@ -245,15 +235,16 @@ void QGraphics::update_contents() dialog_->displayscale->setEnabled(igp.display != grfx::NoDisplay && !readOnly()); dialog_->displayscale->setText(tostr(igp.lyxscale).c_str()); - // the output section + //// the output section (width/height) // set the length combo boxes // only the width has the possibility for scale%. The original // units are defined in lengthcommon.C - dialog_->widthUnit->insertItem("Scale%"); - for (int i = 0; i < num_units; i++) { - dialog_->widthUnit->insertItem(unit_name[i], -1); - dialog_->heightUnit->insertItem(unit_name[i], -1); - } + // 1. the width (a listttype) + dialog_->widthUnit->clear(); + dialog_->widthUnit->insertItem(_("Scale%")); + for (int i = 0; i < num_units; i++) + dialog_->widthUnit->insertItem(unit_name_gui[i], -1); + if (!lyx::float_equal(igp.scale, 0.0, 0.05)) { // there is a scale value > 0.05 dialog_->width->setText(tostr(igp.scale).c_str()); @@ -261,15 +252,17 @@ void QGraphics::update_contents() } else { // no scale means default width/height dialog_->width->setText(tostr(igp.width.value()).c_str()); - string const widthUnit = (igp.width.value() > 0.0) ? - unit_name[igp.width.unit()] : unitDefault; - // +1 instead of the "Scale%" option - dialog_->widthUnit->setCurrentItem(getUnitNo(widthUnit) + 1); + // the width cannot have a unitDefault, because + // it is a "Scale%" or another user defined unit! + // +1 instead of the "Scale%" option + int unit_ = igp.width.unit(); + dialog_->widthUnit->setCurrentItem(unit_ + 1); } + // 2. the height (a lengthgcombo type) dialog_->height->setText(tostr(igp.height.value()).c_str()); - string const heightUnit = (igp.height.value() > 0.0) ? - unit_name[igp.height.unit()] : unitDefault; - dialog_->heightUnit->setCurrentItem(getUnitNo(heightUnit)); + LyXLength::UNIT unit_ = (igp.height.value() > 0.0) ? + igp.height.unit() : unitDefault; + dialog_->heightUnit->setCurrentItem(unit_); // enable height input in case of non "Scale%" as width-unit bool use_height = (dialog_->widthUnit->currentItem() > 0); @@ -280,9 +273,22 @@ void QGraphics::update_contents() dialog_->angle->setText(tostr(igp.rotateAngle).c_str()); + dialog_->origin->clear(); + + using namespace frnt; + vector origindata = getRotationOriginData(); + vector const origin_lang = getFirst(origindata); + QGraphics::origin_ltx = getSecond(origindata); + + for (vector::const_iterator it = origin_lang.begin(); + it != origin_lang.end(); ++it) + dialog_->origin->insertItem((*it).c_str(), -1); + if (!igp.rotateOrigin.empty()) dialog_->origin->setCurrentItem( ::getItemNo(origin_ltx, igp.rotateOrigin)); + else + dialog_->origin->setCurrentItem(0); //// latex section dialog_->latexoptions->setText(igp.special.c_str()); @@ -296,33 +302,35 @@ void QGraphics::apply() igp.filename = dialog_->filename->text(); // the bb section - if (!controller().bbChanged) { - // don't write anything - igp.bb.erase(); - } else if (dialog_->clip->isChecked()) { + igp.bb.erase(); + if (controller().bbChanged) { string bb; string lbX(dialog_->lbX->text()); string lbY(dialog_->lbY->text()); string rtX(dialog_->rtX->text()); string rtY(dialog_->rtY->text()); - - if (lbX.empty()) - bb = "0 "; - else - bb = lbX + dialog_->lbXunit->currentText().latin1() + ' '; - if (lbY.empty()) - bb += "0 "; - else - bb += (lbY + dialog_->lbYunit->currentText().latin1() + ' '); - if (rtX.empty()) - bb += "0 "; - else - bb += (rtX + dialog_->rtXunit->currentText().latin1() + ' '); - if (rtY.empty()) - bb += "0"; - else - bb += (rtY + dialog_->rtYunit->currentText().latin1()); - igp.bb = bb; + int bb_sum = + strToInt(lbX) + strToInt(lbY) + + strToInt(rtX) + strToInt(rtX); + if (bb_sum) { + if (lbX.empty()) + bb = "0 "; + else + bb = lbX + dialog_->lbXunit->currentText().latin1() + ' '; + if (lbY.empty()) + bb += "0 "; + else + bb += (lbY + dialog_->lbYunit->currentText().latin1() + ' '); + if (rtX.empty()) + bb += "0 "; + else + bb += (rtX + dialog_->rtXunit->currentText().latin1() + ' '); + if (rtY.empty()) + bb += "0"; + else + bb += (rtY + dialog_->rtYunit->currentText().latin1()); + igp.bb = bb; + } } igp.draft = dialog_->draftCB->isChecked(); @@ -344,8 +352,9 @@ void QGraphics::apply() string value(dialog_->width->text()); if (dialog_->widthUnit->currentItem() > 0) { // width/height combination - string const unit(dialog_->widthUnit->currentText()); - igp.width = LyXLength(value + unit); + int const unitNo = getUnitNo(unit_name_gui, + string(dialog_->widthUnit->currentText())); + igp.width = LyXLength(value + unit_name_ltx[unitNo]); igp.scale = 0.0; } else { // scaling instead of a width @@ -353,8 +362,9 @@ void QGraphics::apply() igp.width = LyXLength(); } value = string(dialog_->height->text()); - string const unit = string(dialog_->heightUnit->currentText()); - igp.height = LyXLength(value + unit); + int const unitNo = getUnitNo(unit_name_gui, + string(dialog_->heightUnit->currentText())); + igp.height = LyXLength(value + unit_name_ltx[unitNo]); igp.keepAspectRatio = dialog_->aspectratio->isChecked(); @@ -370,8 +380,9 @@ void QGraphics::apply() // save the latex name for the origin. If it is the default // then origin_ltx returns "" - igp.rotateOrigin = origin_ltx[dialog_->origin->currentItem()]; - + igp.rotateOrigin = + QGraphics::origin_ltx[dialog_->origin->currentItem()]; + // more latex options igp.special = dialog_->latexoptions->text(); } diff --git a/src/frontends/qt2/QGraphicsDialog.C b/src/frontends/qt2/QGraphicsDialog.C index a391702110..33c6e8b42e 100644 --- a/src/frontends/qt2/QGraphicsDialog.C +++ b/src/frontends/qt2/QGraphicsDialog.C @@ -27,6 +27,8 @@ #include #include +#include "lengthcombo.h" + #include "QGraphicsDialog.h" #include "QGraphics.h" @@ -64,6 +66,8 @@ void QGraphicsDialog::change_adaptor() void QGraphicsDialog::change_bb() { form_->controller().bbChanged = true; + lyxerr[Debug::GRAPHICS] + << "[controller().bb_Changed set to true]\n"; form_->changed(); } @@ -73,6 +77,7 @@ void QGraphicsDialog::change_WUnit() bool useHeight = (widthUnit->currentItem() > 0); height->setEnabled(useHeight); heightUnit->setEnabled(useHeight); + form_->changed(); } diff --git a/src/frontends/qt2/lengthcombo.C b/src/frontends/qt2/lengthcombo.C index 5a726bf119..cb442cdf84 100644 --- a/src/frontends/qt2/lengthcombo.C +++ b/src/frontends/qt2/lengthcombo.C @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author John Levon + * \author Herbert Voss * * Full author contact details are available in file CREDITS */ @@ -14,64 +15,29 @@ #pragma implementation #endif -#include "gettext.h" - #include "lengthcombo.h" - #include +#include "lengthcommon.h" +#include "gettext.h" + LengthCombo::LengthCombo(QWidget * parent, char * name) : QComboBox(parent, name) { - // FIXME: check these should all be here, I think not - insertItem(_("cm")); - insertItem(_("in")); - insertItem(_("pt")); - insertItem(_("mm")); - insertItem(_("pc")); - insertItem(_("ex")); - insertItem(_("em")); - insertItem(_("sp")); - insertItem(_("bp")); - insertItem(_("dd")); - insertItem(_("cc")); - insertItem(_("mu")); - insertItem(_("%p")); - insertItem(_("%c")); - insertItem(_("%l")); + for (int i=0; i < num_units; i++) + insertItem(unit_name_gui[i]); connect(this, SIGNAL(activated(int)), this, SLOT(has_activated(int))); - QWhatsThis::add(this, _("FIXME - describe the units.")); + QWhatsThis::add(this, _("Choose one of the units or relative lengths")); } LyXLength::UNIT LengthCombo::currentLengthItem() const { - LyXLength::UNIT unit; - int i = currentItem(); - switch (i) { - default: - case 0: unit = LyXLength::CM; break; - case 1: unit = LyXLength::IN; break; - case 2: unit = LyXLength::PT; break; - case 3: unit = LyXLength::MM; break; - case 4: unit = LyXLength::PC; break; - case 5: unit = LyXLength::EX; break; - case 6: unit = LyXLength::EM; break; - case 7: unit = LyXLength::SP; break; - case 8: unit = LyXLength::BP; break; - case 9: unit = LyXLength::DD; break; - case 10: unit = LyXLength::CC; break; - case 11: unit = LyXLength::MU; break; - case 12: unit = LyXLength::PPW; break; - case 13: unit = LyXLength::PCW; break; - case 14: unit = LyXLength::PLW; break; - // FIXME: LyXLength::PTW ? - }; - return unit; + return static_cast(currentItem()); } @@ -83,25 +49,12 @@ void LengthCombo::has_activated(int) void LengthCombo::setCurrentItem(LyXLength::UNIT unit) { - int i; - switch (unit) { - default: - case LyXLength::CM: i = 0; break; - case LyXLength::IN: i = 1; break; - case LyXLength::PT: i = 2; break; - case LyXLength::MM: i = 3; break; - case LyXLength::PC: i = 4; break; - case LyXLength::EX: i = 5; break; - case LyXLength::EM: i = 6; break; - case LyXLength::SP: i = 7; break; - case LyXLength::BP: i = 8; break; - case LyXLength::DD: i = 9; break; - case LyXLength::CC: i = 10; break; - case LyXLength::MU: i = 11; break; - case LyXLength::PPW: i = 12; break; - case LyXLength::PCW: i = 13; break; - case LyXLength::PLW: i = 14; break; - // FIXME: LyXLength::PTW ? - } - QComboBox::setCurrentItem(i); + QComboBox::setCurrentItem(int(unit)); } + + +void LengthCombo::setEnabled(bool b) +{ + QComboBox::setEnabled(b); +} + diff --git a/src/frontends/qt2/lengthcombo.h b/src/frontends/qt2/lengthcombo.h index 93b8b64f48..239070a692 100644 --- a/src/frontends/qt2/lengthcombo.h +++ b/src/frontends/qt2/lengthcombo.h @@ -30,9 +30,11 @@ public: /// set the current item virtual void setCurrentItem(LyXLength::UNIT unit); - /// get the current item LyXLength::UNIT currentLengthItem() const; + /// enable the widget + virtual void setEnabled(bool b); + protected slots: virtual void has_activated(int index); signals: diff --git a/src/frontends/qt2/ui/QGraphicsDialog.ui b/src/frontends/qt2/ui/QGraphicsDialog.ui index d75210e025..b6fb8e5deb 100644 --- a/src/frontends/qt2/ui/QGraphicsDialog.ui +++ b/src/frontends/qt2/ui/QGraphicsDialog.ui @@ -340,11 +340,33 @@ - QComboBox + LengthCombo name heightUnit + + sizePolicy + + 3 + 0 + + + + minimumSize + + 80 + 22 + + + + focusPolicy + StrongFocus + + + toolTip + Units of height value + @@ -601,7 +623,7 @@ toolTip - Clip to bounding box (FIXME: what ??) + Clip to bounding box values @@ -1176,6 +1198,29 @@ + + + LengthCombo +
lengthcombo.h
+ + -1 + -1 + + 0 + + 5 + 5 + + image0 + selectionChanged(LyXLength::UNIT) +
+
+ + + image0 + 789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758 + + subfigure @@ -1225,48 +1270,6 @@ QGraphicsDialogBase change_bb() - - lbY - textChanged(const QString&) - QGraphicsDialogBase - change_bb() - - - rtX - textChanged(const QString&) - QGraphicsDialogBase - change_bb() - - - rtY - textChanged(const QString&) - QGraphicsDialogBase - change_bb() - - - lbXunit - activated(int) - QGraphicsDialogBase - change_bb() - - - lbYunit - activated(int) - QGraphicsDialogBase - change_bb() - - - rtXunit - activated(int) - QGraphicsDialogBase - change_bb() - - - rtYunit - activated(int) - QGraphicsDialogBase - change_bb() - showCB activated(int) @@ -1333,12 +1336,6 @@ QGraphicsDialogBase change_adaptor() - - heightUnit - activated(int) - QGraphicsDialogBase - change_adaptor() - angle textChanged(const QString&) @@ -1351,35 +1348,59 @@ QGraphicsDialogBase change_adaptor() + + getPB + clicked() + QGraphicsDialogBase + getBB_clicked() + + + getPB + clicked() + QGraphicsDialogBase + change_adaptor() + + + lbY + textChanged(const QString&) + QGraphicsDialogBase + change_bb() + rtX textChanged(const QString&) QGraphicsDialogBase - change_adaptor() + change_bb() rtY textChanged(const QString&) QGraphicsDialogBase - change_adaptor() + change_bb() - lbY - textChanged(const QString&) + lbXunit + activated(int) QGraphicsDialogBase - change_adaptor() + change_bb() - getPB - clicked() + lbYunit + activated(int) QGraphicsDialogBase - getBB_clicked() + change_bb() - getPB - clicked() + rtXunit + activated(int) QGraphicsDialogBase - change_adaptor() + change_bb() + + + rtYunit + activated(int) + QGraphicsDialogBase + change_bb() browse_clicked() getBB_clicked() diff --git a/src/lengthcommon.C b/src/lengthcommon.C index cc35cef07c..071cda6e44 100644 --- a/src/lengthcommon.C +++ b/src/lengthcommon.C @@ -2,15 +2,48 @@ #include "lengthcommon.h" +#include "gettext.h" + + int const num_units = LyXLength::UNIT_NONE; // I am not sure if "mu" should be possible to select (Lgb) + +// unit_name is for compatibility. Can be deleted when all works well. +// means, when we have full language support for the lengths +// in all gui's (Herbert 2002-11-01) char const * unit_name[num_units] = { - "sp", "pt", "bp", "dd", "mm", "pc", "cc", "cm", - "in", "ex", "em", "mu", + "sp", "pt", "bp", "dd", "mm", "pc", + "cc", "cm", "in", "ex", "em", "mu", "text%", "col%", "page%", "line%", "theight%", "pheight%" }; +// the latex units +char const * unit_name_ltx[num_units] = { + "sp", "pt", "bp", "dd", "mm", "pc", + "cc", "cm", "in", "ex", "em", "mu", + // in 1.4 the following names should be used. then no + // translation into the latex ones are needed +// "textheight", "columnwidth", "pagewidth", "linewidth", +// "textheight", "pageheight" }; + "text%", "col%", "page%", "line%", + "theight%", "pheight%" }; + +// the LyX gui units +char const * unit_name_gui[num_units] = { + N_("sp"), N_("pt"), N_("bp"), N_("dd"), N_("mm"), N_("pc"), + N_("cc"), N_("cm"), N_("in"), N_("ex"), N_("em"), N_("mu"), + N_("text%"), N_("col%"), N_("page%"), N_("line%"), + N_("theight%"), N_("pheight%") }; + + // this one maybe better ???? but there can be problems with + // xforms (Herbert) +// N_("textwidth%"), N_("columnwidth%"), N_("pagewidth%"), N_("linewidth%"), +// N_("textheight%"), N_("pageheight%") }; + + // or altenative this ones +// N_("twidth%"), N_("cwidth%"), N_("pwidth%"), N_("lwidth%"), +// N_("theight%"), N_("pheight%") }; LyXLength::UNIT unitFromString(string const & data) { @@ -19,3 +52,4 @@ LyXLength::UNIT unitFromString(string const & data) ++i; return static_cast(i); } + diff --git a/src/lengthcommon.h b/src/lengthcommon.h index 57095514ba..ac4eec1670 100644 --- a/src/lengthcommon.h +++ b/src/lengthcommon.h @@ -15,8 +15,11 @@ extern int const num_units; * FIXME: I am not sure if "mu" should be possible to select (Lgb) */ extern char const * unit_name[]; +extern char const * unit_name_gui[]; +extern char const * unit_name_ltx[]; /// return the unit given a string representation such as "cm" LyXLength::UNIT unitFromString(string const & data); + #endif // LENGTH_COMMON_H