X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiGraphics.cpp;h=e89bd4cfe6467e0e050ea0d0c88df64609a2b07a;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=00d4c3567af988d62ba059aed8fab7fdf6010299;hpb=29117ed90974bcea60aa8d7ca5a29584194e6ef0;p=lyx.git diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 00d4c3567a..e89bd4cfe6 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -109,49 +109,6 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, } -template -vector getFirst(vector const & pr) -{ - size_t const n = pr.size(); - vector tmp(n); - for (size_t i = 0; i != n; ++i) - tmp[i] = pr[i].first; - return tmp; -} - - -/// -template -vector getSecond(vector const & pr) -{ - size_t const n = pr.size(); - vector tmp(n); - for (size_t i = 0; i != n; ++i) - tmp[i] = pr[i].second; - return tmp; -} - - -/// The (tranlated) GUI string and it's LaTeX equivalent. -typedef pair RotationOriginPair; -/// -vector getRotationOriginData() -{ - static vector data; - if (!data.empty()) - return data; - - data.resize(rorigin_size); - for (size_type i = 0; i < rorigin_size; ++i) { - data[i] = make_pair(_(rorigin_gui_strs[i]), - rorigin_lyx_strs[i]); - } - - return data; -} - - - GuiGraphics::GuiGraphics(GuiView & lv) : GuiDialog(lv, "graphics", qt_("Graphics")) { @@ -207,21 +164,21 @@ GuiGraphics::GuiGraphics(GuiView & lv) connect(clip, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); connect(lbY, SIGNAL(textChanged(const QString&)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(lbYunit, SIGNAL(activated(int)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(rtY, SIGNAL(textChanged(const QString&)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(rtYunit, SIGNAL(activated(int)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(lbX, SIGNAL(textChanged(const QString&)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(lbXunit, SIGNAL(activated(int)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(rtX, SIGNAL(textChanged(const QString&)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(rtXunit, SIGNAL(activated(int)), - this, SLOT(change_bb())); + this, SLOT(changeBB())); connect(getPB, SIGNAL(clicked()), this, SLOT(change_adaptor())); @@ -248,7 +205,7 @@ GuiGraphics::GuiGraphics(GuiView & lv) connect(displayscale, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(groupCO, SIGNAL(currentIndexChanged(int)), - this, SLOT(change_group(int))); + this, SLOT(changeGroup(int))); displayscale->setValidator(new QIntValidator(displayscale)); @@ -294,7 +251,7 @@ void GuiGraphics::change_adaptor() } - void GuiGraphics::change_group(int /* index */) +void GuiGraphics::changeGroup(int /* index */) { QString const new_group = groupCO->itemData( groupCO->currentIndex()).toString(); @@ -384,7 +341,7 @@ void GuiGraphics::on_newGroupPB_clicked() } -void GuiGraphics::change_bb() +void GuiGraphics::changeBB() { bbChanged = true; LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]"); @@ -512,33 +469,29 @@ void GuiGraphics::on_angle_textChanged(const QString & filename) (filename != "0")); } -// returns the number of the string s in the vector v -static int itemNumber(const vector & v, string const & s) -{ - vector::const_iterator cit = - find(v.begin(), v.end(), s); - return (cit != v.end()) ? int(cit - v.begin()) : 0; -} - void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) { static char const * const bb_units[] = { "bp", "cm", "mm", "in" }; + static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in") }; size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]); - vector const units = vector(bb_units, bb_units + bb_size); lbXunit->clear(); lbYunit->clear(); rtXunit->clear(); rtYunit->clear(); - for (vector::const_iterator it = units.begin(); - it != units.end(); ++it) { - lbXunit->addItem(toqstr(*it)); - lbYunit->addItem(toqstr(*it)); - rtXunit->addItem(toqstr(*it)); - rtYunit->addItem(toqstr(*it)); + + for (size_t i = 0; i < bb_size; i++) { + lbXunit->addItem(qt_(bb_units_gui[i]), + toqstr(bb_units[i])); + lbYunit->addItem(qt_(bb_units_gui[i]), + toqstr(bb_units[i])); + rtXunit->addItem(qt_(bb_units_gui[i]), + toqstr(bb_units[i])); + rtYunit->addItem(qt_(bb_units_gui[i]), + toqstr(bb_units[i])); } - + // set the right default unit Length::UNIT const defaultUnit = Length::defaultUnit(); @@ -551,10 +504,10 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) if (igp.bb.empty()) { string const bb = readBoundingBox(igp.filename.absFilename()); // the values from the file always have the bigpoint-unit bp - lbX->setText(toqstr(token(bb, ' ', 0))); - lbY->setText(toqstr(token(bb, ' ', 1))); - rtX->setText(toqstr(token(bb, ' ', 2))); - rtY->setText(toqstr(token(bb, ' ', 3))); + doubleToWidget(lbX, token(bb, ' ', 0)); + doubleToWidget(lbY, token(bb, ' ', 1)); + doubleToWidget(rtX, token(bb, ' ', 2)); + doubleToWidget(rtY, token(bb, ' ', 3)); lbXunit->setCurrentIndex(0); lbYunit->setCurrentIndex(0); rtXunit->setCurrentIndex(0); @@ -568,30 +521,30 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) string const xr = token(igp.bb, ' ', 2); string const yr = token(igp.bb, ' ', 3); if (isValidLength(xl, &anyLength)) { - lbX->setText(toqstr(convert(anyLength.value()))); + doubleToWidget(lbX, anyLength.value()); string const unit = unit_name[anyLength.unit()]; - lbXunit->setCurrentIndex(itemNumber(units, unit)); + lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit))); } else { lbX->setText(toqstr(xl)); } if (isValidLength(yl, &anyLength)) { - lbY->setText(toqstr(convert(anyLength.value()))); + doubleToWidget(lbY, anyLength.value()); string const unit = unit_name[anyLength.unit()]; - lbYunit->setCurrentIndex(itemNumber(units, unit)); + lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit))); } else { lbY->setText(toqstr(xl)); } if (isValidLength(xr, &anyLength)) { - rtX->setText(toqstr(convert(anyLength.value()))); + doubleToWidget(rtX, anyLength.value()); string const unit = unit_name[anyLength.unit()]; - rtXunit->setCurrentIndex(itemNumber(units, unit)); + rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit))); } else { rtX->setText(toqstr(xl)); } if (isValidLength(yr, &anyLength)) { - rtY->setText(toqstr(convert(anyLength.value()))); + doubleToWidget(rtY, anyLength.value()); string const unit = unit_name[anyLength.unit()]; - rtYunit->setCurrentIndex(itemNumber(units, unit)); + rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit))); } else { rtY->setText(toqstr(xl)); } @@ -607,7 +560,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) // the output section (width/height) - Scale->setText(toqstr(igp.scale)); + doubleToWidget(Scale, igp.scale); //igp.scale defaults to 100, so we treat it as empty bool const scaleChecked = !igp.scale.empty() && igp.scale != "100"; scaleCB->blockSignals(true); @@ -665,7 +618,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) setAutoText(); - angle->setText(toqstr(igp.rotateAngle)); + doubleToWidget(angle, igp.rotateAngle); rotateOrderCB->setChecked(igp.scaleBeforeRotation); rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked) @@ -673,21 +626,20 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) origin->clear(); - vector origindata = getRotationOriginData(); - vector const origin_lang = getFirst(origindata); - origin_ltx = getSecond(origindata); - - for (vector::const_iterator it = origin_lang.begin(); - it != origin_lang.end(); ++it) - origin->addItem(toqstr(*it)); + for (size_t i = 0; i < rorigin_size; i++) { + origin->addItem(qt_(rorigin_gui_strs[i]), + toqstr(rorigin_lyx_strs[i])); + } if (!igp.rotateOrigin.empty()) - origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin)); + origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin))); else origin->setCurrentIndex(0); // latex section latexoptions->setText(toqstr(igp.special)); + // cf bug #3852 + filename->setFocus(); } @@ -701,10 +653,10 @@ void GuiGraphics::applyView() igp.bb.erase(); if (bbChanged) { string bb; - string lbXs = fromqstr(lbX->text()); - string lbYs = fromqstr(lbY->text()); - string rtXs = fromqstr(rtX->text()); - string rtYs = fromqstr(rtY->text()); + string lbXs = widgetToDoubleStr(lbX); + string lbYs = widgetToDoubleStr(lbY); + string rtXs = widgetToDoubleStr(rtX); + string rtYs = widgetToDoubleStr(rtY); int bb_sum = convert(lbXs) + convert(lbYs) + convert(rtXs) + convert(rtXs); @@ -735,7 +687,7 @@ void GuiGraphics::applyView() //the graphics section if (scaleCB->isChecked() && !Scale->text().isEmpty()) { - igp.scale = fromqstr(Scale->text()); + igp.scale = widgetToDoubleStr(Scale); igp.width = Length("0pt"); igp.height = Length("0pt"); igp.keepAspectRatio = false; @@ -756,9 +708,9 @@ void GuiGraphics::applyView() igp.noUnzip = unzipCB->isChecked(); igp.lyxscale = displayscale->text().toInt(); - igp.rotateAngle = fromqstr(angle->text()); + igp.rotateAngle = widgetToDoubleStr(angle); - double rotAngle = convert(igp.rotateAngle); + double rotAngle = widgetToDouble(angle); if (abs(rotAngle) > 360.0) { rotAngle -= 360.0 * floor(rotAngle / 360.0); igp.rotateAngle = convert(rotAngle); @@ -766,7 +718,8 @@ void GuiGraphics::applyView() // save the latex name for the origin. If it is the default // then origin_ltx returns "" - igp.rotateOrigin = origin_ltx[origin->currentIndex()]; + igp.rotateOrigin = + fromqstr(origin->itemData(origin->currentIndex()).toString()); igp.scaleBeforeRotation = rotateOrderCB->isChecked(); // more latex options @@ -787,10 +740,10 @@ void GuiGraphics::getBB() bbChanged = false; if (bb.empty()) return; - lbX->setText(toqstr(token(bb, ' ', 0))); - lbY->setText(toqstr(token(bb, ' ', 1))); - rtX->setText(toqstr(token(bb, ' ', 2))); - rtY->setText(toqstr(token(bb, ' ', 3))); + doubleToWidget(lbX, token(bb, ' ', 0)); + doubleToWidget(lbY, token(bb, ' ', 1)); + doubleToWidget(rtX, token(bb, ' ', 2)); + doubleToWidget(rtY, token(bb, ' ', 3)); // the default units for the bb values when reading // it from the file lbXunit->setCurrentIndex(0);