From e78763de40a4445af9c6c057f7d02943666e5b5d Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 7 Nov 2002 00:21:28 +0000 Subject: [PATCH] QGraphics fixes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5592 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/ChangeLog | 4 + src/frontends/controllers/ControlGraphics.C | 2 + src/frontends/qt2/ChangeLog | 13 + src/frontends/qt2/QGraphics.C | 143 +++- src/frontends/qt2/QGraphics.h | 10 +- src/frontends/qt2/QGraphicsDialog.C | 26 +- src/frontends/qt2/QGraphicsDialog.h | 4 +- src/frontends/qt2/ui/QGraphicsDialog.ui | 887 ++++++++------------ src/frontends/xforms/ChangeLog | 5 + src/frontends/xforms/FormGraphics.C | 4 +- 10 files changed, 519 insertions(+), 579 deletions(-) diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 0b094d62ad..ae4c266f2d 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,7 @@ +2002-11-01 Herbert Voss + + * ControlGraphics.C: "Default" is now a part of the rotate-list + 2002-11-04 Lars Gullik Bjønnes * lyx_gui.h: do not use std:: on string diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 38e0f14ae2..a6f9713c03 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -145,6 +145,7 @@ size_t const bb_size = sizeof(bb_units) / sizeof(char *); // end of each line. char const * const rorigin_lyx_strs[] = { // the LaTeX default is leftBaseline + "", "leftTop", "leftBottom", "leftBaseline", // lt lb lB "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB @@ -152,6 +153,7 @@ char const * const rorigin_lyx_strs[] = { // These are the strings, corresponding to the above, that the GUI should // use. Note that they can/should be translated. char const * const rorigin_gui_strs[] = { + N_("Default"), N_("Top left"), N_("Bottom left"), N_("Left baseline"), N_("Center"), N_("Top center"), N_("Bottom center"), N_("Center baseline"), N_("Top right"), N_("Bottom right"), N_("Right baseline") }; diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 60ee7f6681..0d745646fe 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,16 @@ +2002-11-07 John Levon + + * QGraphics.[Ch]: + * QGraphicsDialog.[Ch]: + * ui/QGraphicsDialog.ui: various fixes so it actually + works + +2002-11-01 Herbert Voss + + * QGraphics.[Ch]: + * QGraphicsDialog.[Ch]: + * ui/QGraphicsDialog.ui: get scale/rotate working + 2002-11-04 Angus Leeming * QGraphics.C (update_contents): controller.getUnits() -> diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index 0aa6feed65..4be626a1ce 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -18,7 +18,7 @@ #include "QtLyXView.h" #include "ControlGraphics.h" - +#include "controllers/helper_funcs.h" #include "support/lstrings.h" #include "support/FileInfo.h" #include "support/filetools.h" @@ -97,24 +97,19 @@ void QGraphics::build_dialog() bc().addReadOnly(dialog_->origin); bc().addReadOnly(dialog_->latexoptions); bc().addReadOnly(dialog_->getPB); -} - - -namespace { -int getItemNo(vector v, string const & s) { - vector::const_iterator cit = - find(v.begin(), v.end(), s); - return (cit != v.end()) ? int(cit - v.begin()) : 0; -} + 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); + } -} - - -void QGraphics::update_contents() -{ // clear and fill in the comboboxes - vector const bb_units = frnt::getBBUnits(); + vector const bb_units = getBBUnits(); dialog_->lbXunit->clear(); dialog_->lbYunit->clear(); dialog_->rtXunit->clear(); @@ -127,24 +122,53 @@ void QGraphics::update_contents() 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; +} + +// returns the number of the unit in the array unit_name, +// which is defined in lengthcommon.C +int getUnitNo(string const & s) { + int i = 0; + while (i < num_units && s != unit_name[i]) + ++i; + return (i < num_units) ? i : 0; +} + +} + + +void QGraphics::update_contents() +{ InsetGraphicsParams & igp = controller().params(); // set the right default unit - string unit = "cm"; + string unitDefault("cm"); switch (lyxrc.default_papersize) { case BufferParams::PAPER_DEFAULT: break; case BufferParams::PAPER_USLETTER: case BufferParams::PAPER_LEGALPAPER: case BufferParams::PAPER_EXECUTIVEPAPER: - unit = "in"; + unitDefault = "in"; break; case BufferParams::PAPER_A3PAPER: case BufferParams::PAPER_A4PAPER: case BufferParams::PAPER_A5PAPER: case BufferParams::PAPER_B5PAPER: - unit = "cm"; + unitDefault = "cm"; break; } @@ -162,6 +186,7 @@ void QGraphics::update_contents() } 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,20 +245,46 @@ void QGraphics::update_contents() dialog_->displayscale->setEnabled(igp.display != grfx::NoDisplay && !readOnly()); dialog_->displayscale->setText(tostr(igp.lyxscale).c_str()); - dialog_->widthUnit->setCurrentItem(igp.width.unit()); - dialog_->heightUnit->setCurrentItem(igp.height.unit()); + // the output section + // 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); + } + 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()); + dialog_->widthUnit->setCurrentItem(0); + } 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); + } + 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)); + + // enable height input in case of non "Scale%" as width-unit + bool use_height = (dialog_->widthUnit->currentItem() > 0); + dialog_->height->setEnabled(use_height); + dialog_->heightUnit->setEnabled(use_height); + dialog_->aspectratio->setChecked(igp.keepAspectRatio); - // Update the rotate angle dialog_->angle->setText(tostr(igp.rotateAngle).c_str()); - if (igp.rotateOrigin.empty()) { - dialog_->origin->setCurrentItem(0); - } else { - // FIXME fl_set_choice_text(special_->choice_origin,igp.rotateOrigin.c_str()); - } + if (!igp.rotateOrigin.empty()) + dialog_->origin->setCurrentItem( + ::getItemNo(origin_ltx, igp.rotateOrigin)); - // latex options + //// latex section dialog_->latexoptions->setText(igp.special.c_str()); } @@ -248,7 +299,7 @@ void QGraphics::apply() if (!controller().bbChanged) { // don't write anything igp.bb.erase(); - } else { + } else if (dialog_->clip->isChecked()) { string bb; string lbX(dialog_->lbX->text()); string lbY(dialog_->lbY->text()); @@ -291,9 +342,19 @@ void QGraphics::apply() igp.display = grfx::NoDisplay; string value(dialog_->width->text()); - igp.width = LyXLength(strToDbl(value), dialog_->widthUnit->currentLengthItem()); + if (dialog_->widthUnit->currentItem() > 0) { + // width/height combination + string const unit(dialog_->widthUnit->currentText()); + igp.width = LyXLength(value + unit); + igp.scale = 0.0; + } else { + // scaling instead of a width + igp.scale = strToDbl(value); + igp.width = LyXLength(); + } value = string(dialog_->height->text()); - igp.height = LyXLength(strToDbl(value), dialog_->heightUnit->currentLengthItem()); + string const unit = string(dialog_->heightUnit->currentText()); + igp.height = LyXLength(value + unit); igp.keepAspectRatio = dialog_->aspectratio->isChecked(); @@ -307,24 +368,16 @@ void QGraphics::apply() while (igp.rotateAngle > 360.0) igp.rotateAngle -= 360.0; - if ((dialog_->origin->currentItem()) > 0) - igp.rotateOrigin = dialog_->origin->currentText(); - else - igp.rotateOrigin.erase(); - + // save the latex name for the origin. If it is the default + // then origin_ltx returns "" + igp.rotateOrigin = origin_ltx[dialog_->origin->currentItem()]; + + // more latex options igp.special = dialog_->latexoptions->text(); } -void QGraphics::browse() -{ - string const & name = controller().Browse(dialog_->filename->text().latin1()); - if (!name.empty()) - dialog_->filename->setText(name.c_str()); -} - - -void QGraphics::get() +void QGraphics::getBB() { string const filename(dialog_->filename->text()); if (!filename.empty()) { diff --git a/src/frontends/qt2/QGraphics.h b/src/frontends/qt2/QGraphics.h index c73a3223b1..70cb175a17 100644 --- a/src/frontends/qt2/QGraphics.h +++ b/src/frontends/qt2/QGraphics.h @@ -5,6 +5,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 */ @@ -40,11 +41,12 @@ private: virtual void update_contents(); /// build the dialog virtual void build_dialog(); - - /// browse for a file - void browse(); /// get bounding box from file - void get(); + void getBB(); + + /// Store the LaTeX names for the rotation origins. + std::vector origin_ltx; + }; #endif // QGRAPHICS_H diff --git a/src/frontends/qt2/QGraphicsDialog.C b/src/frontends/qt2/QGraphicsDialog.C index 4cf2e05ea1..a391702110 100644 --- a/src/frontends/qt2/QGraphicsDialog.C +++ b/src/frontends/qt2/QGraphicsDialog.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 */ @@ -16,12 +17,15 @@ #include "ControlGraphics.h" #include "debug.h" +#include "gettext.h" #include "LString.h" #include #include #include #include +#include +#include #include "QGraphicsDialog.h" #include "QGraphics.h" @@ -64,6 +68,14 @@ void QGraphicsDialog::change_bb() } +void QGraphicsDialog::change_WUnit() +{ + bool useHeight = (widthUnit->currentItem() > 0); + height->setEnabled(useHeight); + heightUnit->setEnabled(useHeight); +} + + void QGraphicsDialog::closeEvent(QCloseEvent * e) { form_->slotWMHide(); @@ -73,10 +85,18 @@ void QGraphicsDialog::closeEvent(QCloseEvent * e) void QGraphicsDialog::browse_clicked() { - form_->browse(); + QString file = QFileDialog::getOpenFileName( + QString::null, _("Files (*)"), + this, 0, _("Select a graphic file")); + if (!file.isNull()) { + string const name = file.latin1(); + filename->setText(name.c_str()); + form_->changed(); + } } -void QGraphicsDialog::get_clicked() + +void QGraphicsDialog::getBB_clicked() { - form_->get(); + form_->getBB(); } diff --git a/src/frontends/qt2/QGraphicsDialog.h b/src/frontends/qt2/QGraphicsDialog.h index 113b9b2700..b7c60d0ba5 100644 --- a/src/frontends/qt2/QGraphicsDialog.h +++ b/src/frontends/qt2/QGraphicsDialog.h @@ -5,6 +5,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 */ @@ -29,8 +30,9 @@ public: protected slots: virtual void change_adaptor(); virtual void change_bb(); + virtual void change_WUnit(); virtual void browse_clicked(); - virtual void get_clicked(); + virtual void getBB_clicked(); protected: virtual void closeEvent(QCloseEvent * e); private: diff --git a/src/frontends/qt2/ui/QGraphicsDialog.ui b/src/frontends/qt2/ui/QGraphicsDialog.ui index ae491fa6ca..d75210e025 100644 --- a/src/frontends/qt2/ui/QGraphicsDialog.ui +++ b/src/frontends/qt2/ui/QGraphicsDialog.ui @@ -13,8 +13,8 @@ 0 0 - 426 - 484 + 379 + 390 @@ -54,7 +54,7 @@ title &Graphics - + margin 11 @@ -63,7 +63,7 @@ spacing 6 - + QLayoutWidget name @@ -125,361 +125,7 @@ - - QGroupBox - - name - rotateGB - - - title - Rotation - - - - margin - 11 - - - spacing - 6 - - - QLabel - - name - angleL_2 - - - text - A&ngle: - - - buddy - angle - - - toolTip - Angle to rotate image by - - - - QLineEdit - - name - angle - - - sizePolicy - - 3 - 0 - - - - toolTip - Angle to rotate image by - - - - QLabel - - name - originL_2 - - - text - &Origin: - - - buddy - origin - - - toolTip - The origin of the rotation - - - - QComboBox - - - text - default - - - - - text - Top left - - - - - text - Bottom left - - - - - text - Left baseline - - - - - text - Center - - - - - text - Top center - - - - - text - Bottom center - - - - - text - Center baseline - - - - - text - Top right - - - - - text - Bottom right - - - - - text - Right baseline - - - - - text - Reference point - - - - name - origin - - - toolTip - The origin of the rotation - - - - - - QGroupBox - - name - GroupBox11 - - - title - Output - - - - margin - 11 - - - spacing - 6 - - - QLabel - - name - sizeheightL_2 - - - enabled - true - - - text - &Height - - - buddy - height - - - - QLayoutWidget - - name - Layout19_2 - - - - margin - 0 - - - spacing - 6 - - - QLineEdit - - name - height - - - enabled - true - - - toolTip - Height of image in output - - - - LengthCombo - - name - heightUnit - - - enabled - true - - - minimumSize - - 50 - 0 - - - - focusPolicy - StrongFocus - - - toolTip - Height unit - - - - - - QLabel - - name - sizewidthL_2 - - - enabled - true - - - text - &Width - - - buddy - width - - - - QLayoutWidget - - name - Layout18_2 - - - - margin - 0 - - - spacing - 6 - - - QLineEdit - - name - width - - - enabled - true - - - toolTip - Width of image in output - - - - LengthCombo - - name - widthUnit - - - enabled - true - - - minimumSize - - 50 - 0 - - - - focusPolicy - StrongFocus - - - toolTip - Width unit - - - - - - QCheckBox - - name - aspectratio - - - enabled - true - - - text - &Maintain aspect ratio - - - toolTip - Maintain aspect ratio with largest dimension - - - - - + QGroupBox name @@ -629,7 +275,285 @@ - + + QGroupBox + + name + GroupBox11 + + + title + Output + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout7 + + + + margin + 0 + + + spacing + 6 + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 6 + + + QLineEdit + + name + height + + + enabled + true + + + toolTip + Height of image in output + + + + QComboBox + + name + heightUnit + + + + + + QLabel + + name + sizeheightL_2 + + + enabled + true + + + text + &Height + + + buddy + height + + + + QLayoutWidget + + name + Layout3 + + + + margin + 0 + + + spacing + 6 + + + QLineEdit + + name + width + + + enabled + true + + + toolTip + Width of image in output + + + + QComboBox + + name + widthUnit + + + + + + QLabel + + name + sizewidthL_2 + + + enabled + true + + + text + &Width + + + buddy + width + + + + + + QCheckBox + + name + aspectratio + + + enabled + true + + + text + &Maintain aspect ratio + + + toolTip + Maintain aspect ratio with largest dimension + + + + + + QGroupBox + + name + rotateGB + + + title + Rotation + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout6 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + angleL_2 + + + text + A&ngle: + + + buddy + angle + + + toolTip + Angle to rotate image by + + + + QLineEdit + + name + angle + + + sizePolicy + + 3 + 0 + + + + toolTip + Angle to rotate image by + + + + QLabel + + name + originL_2 + + + text + &Origin: + + + buddy + origin + + + toolTip + The origin of the rotation + + + + QComboBox + + name + origin + + + toolTip + The origin of the rotation + + + + + + + QWidget @@ -641,7 +565,7 @@ title &Clipping - + margin 11 @@ -650,7 +574,75 @@ spacing 6 - + + QLayoutWidget + + name + Layout7 + + + + margin + 0 + + + spacing + 6 + + + QCheckBox + + name + clip + + + text + Clip to &bounding box + + + toolTip + Clip to bounding box (FIXME: what ??) + + + + + name + Spacer48 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + getPB + + + text + &Get from file + + + toolTip + Get bounding box from the (EPS) file + + + + + QFrame name @@ -719,24 +711,6 @@ QComboBox - - - text - pt - - - - - text - cm - - - - - text - in - - name rtYunit @@ -762,24 +736,6 @@ QComboBox - - - text - pt - - - - - text - cm - - - - - text - in - - name rtXunit @@ -787,24 +743,6 @@ QComboBox - - - text - pt - - - - - text - cm - - - - - text - in - - name lbXunit @@ -823,24 +761,6 @@ QComboBox - - - text - pt - - - - - text - cm - - - - - text - in - - name lbYunit @@ -892,22 +812,7 @@ - - QPushButton - - name - getPB - - - text - &Get from file - - - toolTip - Get bounding box from the EPS file - - - + name Spacer48_2 @@ -928,43 +833,7 @@ - - - name - Spacer48 - - - orientation - Horizontal - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - - - QCheckBox - - name - clip - - - text - Clip to &bounding box - - - toolTip - Clip to bounding box (FIXME: what ??) - - - + QWidget @@ -1307,29 +1176,6 @@ - - - LengthCombo -
lengthcombo.h
- - -1 - -1 - - 0 - - 5 - 5 - - image0 - selectionChanged(LyXLength::UNIT) -
-
- - - image0 - 789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758 - - subfigure @@ -1441,15 +1287,9 @@ widthUnit - selectionChanged(LyXLength::UNIT) + activated(int) QGraphicsDialogBase - change_adaptor() - - - heightUnit - selectionChanged(LyXLength::UNIT) - QGraphicsDialogBase - change_adaptor() + change_WUnit() aspectratio @@ -1494,8 +1334,8 @@ change_adaptor() - height - returnPressed() + heightUnit + activated(int) QGraphicsDialogBase change_adaptor() @@ -1533,7 +1373,7 @@ getPB clicked() QGraphicsDialogBase - get_clicked() + getBB_clicked() getPB @@ -1542,9 +1382,10 @@ change_adaptor() browse_clicked() - get_clicked() + getBB_clicked() change_adaptor() change_bb() + change_WUnit() TabWidget @@ -1554,9 +1395,7 @@ showCB displayscale width - widthUnit height - heightUnit aspectratio angle origin diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 37bf47a5ed..b876af7d85 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2002-10-31 Herbert Voss + + * FormGraphics.C (build, apply): get the rotate-list from the + controller + 2002-11-04 Angus Leeming * FormGraphics.C (build): Use frnt::getBBUnits(). diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index 6e4c2ea402..40dcb9ecb5 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -234,7 +234,7 @@ void FormGraphics::build() // Store the identifiers for later origins_ = getSecond(origindata); - string const choice = "Default|" + getStringFromVector(getFirst(origindata), "|"); + string const choice = getStringFromVector(getFirst(origindata), "|"); fl_addto_choice(extra_->choice_origin, choice.c_str()); // set up the tooltips for the extra section @@ -397,7 +397,7 @@ void FormGraphics::apply() if (origin_pos == 1) { igp.rotateOrigin.erase(); } else { - igp.rotateOrigin = origins_[origin_pos - 2]; + igp.rotateOrigin = origins_[origin_pos - 1]; } igp.subcaption = fl_get_button(extra_->check_subcaption);