From 5707a390415ea3e2f4c25b843405df1c1d6bc6b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Wed, 14 Jan 2009 15:47:25 +0000 Subject: [PATCH] * GuiExternal.{cpp,h}: * ExternalUi.ui: - use LengthCombo for width unit. - use reliable item data, instead of doing manual recounts. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28164 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiExternal.cpp | 69 ++++++++++---------------- src/frontends/qt4/GuiExternal.h | 2 + src/frontends/qt4/ui/ExternalUi.ui | 78 ++++++++++++++---------------- 3 files changed, 63 insertions(+), 86 deletions(-) diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index 39db68d51f..d5c14b8d7d 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -203,16 +203,14 @@ GuiExternal::GuiExternal(GuiView & lv) for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i) originCO->addItem(qt_(origin_gui_strs[i])); - // Fill the width combo - widthUnitCO->addItem(qt_("Scale%")); - for (int i = 0; i < num_units; i++) - widthUnitCO->addItem(qt_(unit_name_gui[i])); + // add scale item + widthUnitCO->insertItem(0, qt_("Scale%"), "scale"); } bool GuiExternal::activateAspectratio() const { - if (widthUnitCO->currentIndex() == 0) + if (usingScale()) return false; string const wstr = fromqstr(widthED->text()); @@ -238,6 +236,13 @@ bool GuiExternal::activateAspectratio() const } +bool GuiExternal::usingScale() const +{ + return (widthUnitCO->itemData( + widthUnitCO->currentIndex()).toString() == "scale"); +} + + void GuiExternal::bbChanged() { bbChanged_ = true; @@ -333,15 +338,13 @@ void GuiExternal::templateChanged() void GuiExternal::widthUnitChanged() { - bool useHeight = (widthUnitCO->currentIndex() > 0); - - if (useHeight) - widthED->setValidator(unsignedLengthValidator(widthED)); - else + if (usingScale()) widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED)); + else + widthED->setValidator(unsignedLengthValidator(widthED)); - heightED->setEnabled(useHeight); - heightUnitCO->setEnabled(useHeight); + heightED->setEnabled(!usingScale()); + heightUnitCO->setEnabled(!usingScale()); changed(); } @@ -380,7 +383,7 @@ static void getRotation(external::RotationData & data, } -static void setSize(QLineEdit & widthED, QComboBox & widthUnitCO, +static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO, QLineEdit & heightED, LengthCombo & heightUnitCO, QCheckBox & aspectratioCB, external::ResizeData const & data) @@ -395,14 +398,10 @@ static void setSize(QLineEdit & widthED, QComboBox & widthUnitCO, if (using_scale) { widthED.setText(toqstr(scale)); - widthUnitCO.setCurrentIndex(0); - } else { - widthED.setText(QString::number(data.width.value())); - // Because 'Scale' is position 0... - // Note also that width cannot be zero here, so - // we don't need to worry about the default unit. - widthUnitCO.setCurrentIndex(data.width.unit() + 1); - } + widthUnitCO.setCurrentItem("scale"); + } else + lengthToWidgets(&widthED, &widthUnitCO, + data.width.asString(), defaultUnit()); string const h = data.height.zero() ? string() : data.height.asString(); Length::UNIT default_unit = data.width.zero() ? @@ -423,33 +422,19 @@ static void setSize(QLineEdit & widthED, QComboBox & widthUnitCO, static void getSize(external::ResizeData & data, QLineEdit const & widthED, QComboBox const & widthUnitCO, QLineEdit const & heightED, LengthCombo const & heightUnitCO, - QCheckBox const & aspectratioCB) + QCheckBox const & aspectratioCB, bool const scaling) { string const width = fromqstr(widthED.text()); - if (widthUnitCO.currentIndex() > 0) { - // Subtract one, because scale is 0. - int const unit = widthUnitCO.currentIndex() - 1; - - Length w; - if (isValidLength(width, &w)) - data.width = w; - else if (isStrDbl(width)) - data.width = Length(convert(width), - static_cast(unit)); - else - data.width = Length(); - - data.scale = string(); - - } else { + if (scaling) { // scaling instead of a width data.scale = width; data.width = Length(); + } else { + data.width = Length(widgetsToLength(&widthED, &widthUnitCO)); + data.scale = string(); } - data.height = Length(widgetsToLength(&heightED, &heightUnitCO)); - data.keepAspectRatio = aspectratioCB.isChecked(); } @@ -488,8 +473,6 @@ static void getCrop(external::ClipData & data, void GuiExternal::updateContents() { - tab->setCurrentIndex(0); - string const name = params_.filename.outputFilename(fromqstr(bufferFilepath())); fileED->setText(toqstr(name)); @@ -613,7 +596,7 @@ void GuiExternal::applyView() if (scaleGB->isEnabled()) getSize(params_.resizedata, *widthED, *widthUnitCO, - *heightED, *heightUnitCO, *aspectratioCB); + *heightED, *heightUnitCO, *aspectratioCB, usingScale()); if (cropGB->isEnabled()) getCrop(params_.clipdata, *clipCB, *xlED, *ybED, diff --git a/src/frontends/qt4/GuiExternal.h b/src/frontends/qt4/GuiExternal.h index 19d730f0bb..e1157e977c 100644 --- a/src/frontends/qt4/GuiExternal.h +++ b/src/frontends/qt4/GuiExternal.h @@ -54,6 +54,8 @@ private: void updateContents(); /// Helper function called when the template is changed. void updateTemplate(); + /// + bool usingScale() const; /// bool initialiseParams(std::string const & data); diff --git a/src/frontends/qt4/ui/ExternalUi.ui b/src/frontends/qt4/ui/ExternalUi.ui index 82fd52dcbf..703d215fbd 100644 --- a/src/frontends/qt4/ui/ExternalUi.ui +++ b/src/frontends/qt4/ui/ExternalUi.ui @@ -28,17 +28,9 @@ - 2 + 0 - - - 0 - 0 - 362 - 375 - - F&ile @@ -109,7 +101,7 @@ QSizePolicy::Preferred - + 20 20 @@ -120,7 +112,9 @@ - + + 0 + 0 0 0 @@ -136,18 +130,16 @@ - - - 0 - 0 - 362 - 375 - - LaTe&X and LyX options - + + + 9 + + + 6 + @@ -214,7 +206,13 @@ p, li { white-space: pre-wrap; } true - + + + 9 + + + 6 + @@ -234,7 +232,9 @@ p, li { white-space: pre-wrap; } true - + + 0 + 0 0 0 @@ -245,11 +245,11 @@ p, li { white-space: pre-wrap; } - + Qt::Horizontal - + 40 20 @@ -265,7 +265,7 @@ p, li { white-space: pre-wrap; } Qt::Vertical - + 81 196 @@ -276,14 +276,6 @@ p, li { white-space: pre-wrap; } - - - 0 - 0 - 362 - 375 - - Si&ze and Rotation @@ -317,7 +309,7 @@ p, li { white-space: pre-wrap; } QSizePolicy::Expanding - + 20 20 @@ -336,7 +328,9 @@ p, li { white-space: pre-wrap; } - + + 0 + 0 0 0 @@ -406,7 +400,7 @@ p, li { white-space: pre-wrap; } - + @@ -547,7 +541,7 @@ p, li { white-space: pre-wrap; } Qt::Horizontal - + 43 18 @@ -577,12 +571,12 @@ p, li { white-space: pre-wrap; } - - 6 - 0 + + 6 + @@ -591,7 +585,7 @@ p, li { white-space: pre-wrap; } QSizePolicy::Expanding - + 20 20 @@ -635,8 +629,6 @@ p, li { white-space: pre-wrap; } - tab - displayscaleLA -- 2.39.2