X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffrontends%2Fqt4%2FGuiGraphics.cpp;h=b6bbaeac3fb13860c7a7049a4b0b01ec7c378af7;hb=1f5186b2a77e53cdb9ed6009aa45df99e4106f52;hp=de5c01ff9be369c6d68e89a41ff30358c5b4b289;hpb=61fa96cbae28945398bb35b2c81b7ccdc0d5b742;p=lyx.git diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index de5c01ff9b..b6bbaeac3f 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -24,8 +24,8 @@ #include "LengthCombo.h" #include "Length.h" #include "LyXRC.h" -#include "Undo.h" +#include "graphics/epstools.h" #include "graphics/GraphicsCache.h" #include "graphics/GraphicsCacheItem.h" #include "graphics/GraphicsImage.h" @@ -75,9 +75,9 @@ char const * const rorigin_gui_strs[] = { size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *); -static string autostr = N_("automatically"); +static string const autostr = N_("automatically"); -} // namespace anon +} // namespace namespace lyx { @@ -110,15 +110,13 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit, GuiGraphics::GuiGraphics(GuiView & lv) - : GuiDialog(lv, "graphics", qt_("Graphics")) + : GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false) { setupUi(this); - + //main buttons - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore())); + connect(buttonBox, SIGNAL(clicked(QAbstractButton *)), + this, SLOT(slotButtonBox(QAbstractButton *))); //graphics pane connect(filename, SIGNAL(textChanged(const QString &)), @@ -127,8 +125,12 @@ GuiGraphics::GuiGraphics(GuiView & lv) this, SLOT(change_adaptor())); connect(HeightCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(Width, SIGNAL(textChanged(const QString &)), + this, SLOT(updateAspectRatioStatus())); connect(Width, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); + connect(Height, SIGNAL(textChanged(const QString &)), + this, SLOT(updateAspectRatioStatus())); connect(Height, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)), @@ -151,7 +153,7 @@ GuiGraphics::GuiGraphics(GuiView & lv) filename->setValidator(new PathValidator(true, filename)); setFocusProxy(filename); - QDoubleValidator * scaleValidator = + QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale, qt_(autostr)); scaleValidator->setBottom(0); scaleValidator->setDecimals(256); //I guess that will do @@ -163,19 +165,19 @@ GuiGraphics::GuiGraphics(GuiView & lv) //clipping pane connect(clip, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); - connect(lbY, SIGNAL(textChanged(const QString&)), + connect(lbY, SIGNAL(textChanged(const QString &)), this, SLOT(changeBB())); connect(lbYunit, SIGNAL(activated(int)), this, SLOT(changeBB())); - connect(rtY, SIGNAL(textChanged(const QString&)), + connect(rtY, SIGNAL(textChanged(const QString &)), this, SLOT(changeBB())); connect(rtYunit, SIGNAL(activated(int)), this, SLOT(changeBB())); - connect(lbX, SIGNAL(textChanged(const QString&)), + connect(lbX, SIGNAL(textChanged(const QString &)), this, SLOT(changeBB())); connect(lbXunit, SIGNAL(activated(int)), this, SLOT(changeBB())); - connect(rtX, SIGNAL(textChanged(const QString&)), + connect(rtX, SIGNAL(textChanged(const QString &)), this, SLOT(changeBB())); connect(rtXunit, SIGNAL(activated(int)), this, SLOT(changeBB())); @@ -188,12 +190,10 @@ GuiGraphics::GuiGraphics(GuiView & lv) rtY->setValidator(new QDoubleValidator(rtY)); //extra options pane - connect(latexoptions, SIGNAL(textChanged(const QString&)), + connect(latexoptions, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); connect(draftCB, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); - connect(unzipCB, SIGNAL(stateChanged(int)), - this, SLOT(change_adaptor())); // FIXME: we should connect to clicked() when we move to Qt 4.2 because // the toggled(bool) signal is also trigged when we update the widgets // (rgh-4/07) this isn't as much or a problem as it was, because we're now @@ -202,7 +202,7 @@ GuiGraphics::GuiGraphics(GuiView & lv) // is clicked, even right clicked (I think), not just whenever it is // toggled. connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); - connect(displayscale, SIGNAL(textChanged(const QString&)), + connect(displayscale, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); connect(groupCO, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGroup(int))); @@ -210,20 +210,18 @@ GuiGraphics::GuiGraphics(GuiView & lv) displayscale->setValidator(new QIntValidator(displayscale)); bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - bc().setOK(okPB); - bc().setApply(applyPB); - bc().setRestore(restorePB); - bc().setCancel(closePB); + bc().setOK(buttonBox->button(QDialogButtonBox::Ok)); + bc().setApply(buttonBox->button(QDialogButtonBox::Apply)); + bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel)); + bc().setRestore(buttonBox->button(QDialogButtonBox::Reset)); bc().addReadOnly(latexoptions); bc().addReadOnly(filenameL); bc().addReadOnly(filename); bc().addReadOnly(browsePB); - bc().addReadOnly(unzipCB); bc().addReadOnly(bbFrame); bc().addReadOnly(draftCB); bc().addReadOnly(clip); - bc().addReadOnly(unzipCB); bc().addReadOnly(displayGB); bc().addReadOnly(sizeGB); bc().addReadOnly(rotationGB); @@ -255,12 +253,12 @@ void GuiGraphics::changeGroup(int /* index */) { QString const new_group = groupCO->itemData( groupCO->currentIndex()).toString(); - + // check if the old group consisted only of this member if (current_group_ != fromqstr(new_group) && graphics::countGroupMembers(buffer(), current_group_) == 1) { if (!new_group.isEmpty()) { - if (Alert::prompt(_("Dissolve previous group?"), + if (Alert::prompt(_("Dissolve previous group?"), bformat(_("If you assign this graphic to group '%2$s',\n" "the previously assigned group '%1$s' will be dissolved,\n" "because this graphic was its only member.\n" @@ -276,7 +274,7 @@ void GuiGraphics::changeGroup(int /* index */) return; } } else { - if (Alert::prompt(_("Dissolve previous group?"), + if (Alert::prompt(_("Dissolve previous group?"), bformat(_("If you sign off this graphic from group '%1$s',\n" "the group will be dissolved,\n" "because this graphic was its only member.\n" @@ -292,7 +290,7 @@ void GuiGraphics::changeGroup(int /* index */) return; } } - } + } if (new_group.isEmpty()) { changed(); @@ -305,7 +303,7 @@ void GuiGraphics::changeGroup(int /* index */) changed(); return; } - + // filename might have been changed QString current_filename = filename->text(); @@ -314,7 +312,7 @@ void GuiGraphics::changeGroup(int /* index */) InsetGraphics::string2params(grp, buffer(), params_); paramsToDialog(params_); groupCO->blockSignals(false); - + // reset filename filename->setText(current_filename); @@ -330,7 +328,7 @@ void GuiGraphics::on_newGroupPB_clicked() if (newgroup.empty()) return; if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) { - Alert::warning(_("Group already defined!"), + Alert::warning(_("Group already defined!"), bformat(_("A graphics group with the name '%1$s' already exists."), newgroup)); return; @@ -399,15 +397,13 @@ void GuiGraphics::on_scaleCB_toggled(bool setScale) Height->setEnabled(false); heightUnit->setEnabled(false); - aspectratio->setDisabled(true); - aspectratio->setChecked(true); - rotateOrderCB->setEnabled((WidthCB->isChecked() || HeightCB->isChecked() || scaleCB->isChecked()) && (angle->text() != "0")); setAutoText(); + updateAspectRatioStatus(); } @@ -419,11 +415,6 @@ void GuiGraphics::on_WidthCB_toggled(bool setWidth) Width->setFocus(Qt::OtherFocusReason); bool const setHeight = HeightCB->isChecked(); - aspectratio->setEnabled(setWidth && setHeight); - aspectratio->blockSignals(true); - aspectratio->setChecked(!(setWidth && setHeight)); - aspectratio->blockSignals(false); - scaleCB->setEnabled(!setWidth && !setHeight); //already will be unchecked, so don't need to do that Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() @@ -433,6 +424,7 @@ void GuiGraphics::on_WidthCB_toggled(bool setWidth) (angle->text() != "0")); setAutoText(); + updateAspectRatioStatus(); } @@ -444,11 +436,6 @@ void GuiGraphics::on_HeightCB_toggled(bool setHeight) Height->setFocus(Qt::OtherFocusReason); bool const setWidth = WidthCB->isChecked(); - aspectratio->setEnabled(setWidth && setHeight); - aspectratio->blockSignals(true); - aspectratio->setChecked(!(setWidth && setHeight)); - aspectratio->blockSignals(false); - scaleCB->setEnabled(!setWidth && !setHeight); //already unchecked Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled() @@ -458,29 +445,64 @@ void GuiGraphics::on_HeightCB_toggled(bool setHeight) (angle->text() != "0")); setAutoText(); + updateAspectRatioStatus(); +} + + +void GuiGraphics::updateAspectRatioStatus() +{ + // keepaspectratio only makes sense if both a width _and_ a + // height are given, since its function is (see graphics manual): + // "If set to true then specifying both 'width' and 'height' + // (or 'totalheight') does not distort the figure but scales + // such that neither of the specified dimensions is _exceeded_." + aspectratio->setEnabled( + WidthCB->isChecked() && !Width->text().isEmpty() + && Width->text() != qt_(autostr) + && HeightCB->isChecked() && !Height->text().isEmpty() + && Height->text() != qt_(autostr) + ); + if (!aspectratio->isEnabled()) + aspectratio->setChecked(false); } -void GuiGraphics::on_angle_textChanged(const QString & filename) +void GuiGraphics::on_aspectratio_toggled(bool aspect_ratio) +{ + if (aspect_ratio) { + WidthCB->setText(qt_("Set max. &width:")); + HeightCB->setText(qt_("Set max. &height:")); + Width->setToolTip(qt_("Maximal width of image in output")); + Height->setToolTip(qt_("Maximal height of image in output")); + } else { + WidthCB->setText(qt_("Set &width:")); + HeightCB->setText(qt_("Set &height:")); + Width->setToolTip(qt_("Width of image in output")); + Height->setToolTip(qt_("Height of image in output")); + } +} + + +void GuiGraphics::on_angle_textChanged(const QString & file_name) { rotateOrderCB->setEnabled((WidthCB->isChecked() || HeightCB->isChecked() || scaleCB->isChecked()) && - (filename != "0")); + (file_name != "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") }; + static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in[[unit of measure]]") }; size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]); lbXunit->clear(); lbYunit->clear(); rtXunit->clear(); rtYunit->clear(); - + for (size_t i = 0; i < bb_size; i++) { lbXunit->addItem(qt_(bb_units_gui[i]), toqstr(bb_units[i])); @@ -491,7 +513,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) rtYunit->addItem(qt_(bb_units_gui[i]), toqstr(bb_units[i])); } - + // set the right default unit Length::UNIT const defaultUnit = Length::defaultUnit(); @@ -501,7 +523,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) filename->setText(toqstr(name)); // set the bounding box values - if (igp.bb.empty()) { + if (igp.bbox.empty()) { string const bb = readBoundingBox(igp.filename.absFileName()); // the values from the file always have the bigpoint-unit bp doubleToWidget(lbX, token(bb, ' ', 0)); @@ -515,46 +537,24 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) bbChanged = false; } else { // get the values from the inset - Length anyLength; - string const xl = token(igp.bb, ' ', 0); - string const yl = token(igp.bb, ' ', 1); - string const xr = token(igp.bb, ' ', 2); - string const yr = token(igp.bb, ' ', 3); - if (isValidLength(xl, &anyLength)) { - doubleToWidget(lbX, anyLength.value()); - string const unit = unit_name[anyLength.unit()]; - lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit))); - } else { - lbX->setText(toqstr(xl)); - } - if (isValidLength(yl, &anyLength)) { - doubleToWidget(lbY, anyLength.value()); - string const unit = unit_name[anyLength.unit()]; - lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit))); - } else { - lbY->setText(toqstr(xl)); - } - if (isValidLength(xr, &anyLength)) { - doubleToWidget(rtX, anyLength.value()); - string const unit = unit_name[anyLength.unit()]; - rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit))); - } else { - rtX->setText(toqstr(xl)); - } - if (isValidLength(yr, &anyLength)) { - doubleToWidget(rtY, anyLength.value()); - string const unit = unit_name[anyLength.unit()]; - rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit))); - } else { - rtY->setText(toqstr(xl)); - } + doubleToWidget(lbX, igp.bbox.xl.value()); + string unit = unit_name[igp.bbox.xl.unit()]; + lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit))); + doubleToWidget(lbY, igp.bbox.yb.value()); + unit = unit_name[igp.bbox.yb.unit()]; + lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit))); + doubleToWidget(rtX, igp.bbox.xr.value()); + unit = unit_name[igp.bbox.xr.unit()]; + rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit))); + doubleToWidget(rtY, igp.bbox.yt.value()); + unit = unit_name[igp.bbox.yt.unit()]; + rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit))); bbChanged = true; } // Update the draft and clip mode draftCB->setChecked(igp.draft); clip->setChecked(igp.clip); - unzipCB->setChecked(igp.noUnzip); displayGB->setChecked(igp.display); displayscale->setText(toqstr(convert(igp.lyxscale))); @@ -575,7 +575,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) set::const_iterator end = grp.end(); groupCO->blockSignals(true); groupCO->clear(); - for (; it != end; it++) + for (; it != end; ++it) groupCO->addItem(toqstr(*it), toqstr(*it)); groupCO->insertItem(0, qt_("None"), QString()); if (igp.groupId.empty()) @@ -614,9 +614,9 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) scaleCB->setEnabled(!widthChecked && !heightChecked); WidthCB->setEnabled(!scaleChecked); HeightCB->setEnabled(!scaleChecked); - aspectratio->setEnabled(widthChecked && heightChecked); setAutoText(); + updateAspectRatioStatus(); doubleToWidget(angle, igp.rotateAngle); rotateOrderCB->setChecked(igp.scaleBeforeRotation); @@ -650,9 +650,8 @@ void GuiGraphics::applyView() igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath())); // the bb section - igp.bb.erase(); + igp.bbox = graphics::BoundingBox(); if (bbChanged) { - string bb; string lbXs = widgetToDoubleStr(lbX); string lbYs = widgetToDoubleStr(lbY); string rtXs = widgetToDoubleStr(rtX); @@ -662,22 +661,17 @@ void GuiGraphics::applyView() convert(rtXs) + convert(rtXs); if (bb_sum) { if (lbXs.empty()) - bb = "0 "; - else - bb = lbXs + fromqstr(lbXunit->currentText()) + ' '; + lbXs = "0"; + igp.bbox.xl = Length(lbXs + fromqstr(lbXunit->currentText())); if (lbYs.empty()) - bb += "0 "; - else - bb += (lbYs + fromqstr(lbYunit->currentText()) + ' '); + lbYs = "0"; + igp.bbox.yb = Length(lbYs + fromqstr(lbYunit->currentText())); if (rtXs.empty()) - bb += "0 "; - else - bb += (rtXs + fromqstr(rtXunit->currentText()) + ' '); + rtXs = "0"; + igp.bbox.xr = Length(rtXs + fromqstr(rtXunit->currentText())); if (rtYs.empty()) - bb += '0'; - else - bb += (rtYs + fromqstr(rtYunit->currentText())); - igp.bb = bb; + rtYs = "0"; + igp.bbox.yt = Length(rtYs + fromqstr(rtYunit->currentText())); } } @@ -701,12 +695,9 @@ void GuiGraphics::applyView() igp.height = HeightCB->isChecked() ? Length(widgetsToLength(Height, heightUnit)) : Length("0pt"); - igp.keepAspectRatio = aspectratio->isEnabled() && - aspectratio->isChecked() && - igp.width.value() > 0 && igp.height.value() > 0; + igp.keepAspectRatio = aspectratio->isChecked(); } - igp.noUnzip = unzipCB->isChecked(); igp.lyxscale = displayscale->text().toInt(); igp.rotateAngle = widgetToDoubleStr(angle); @@ -759,9 +750,9 @@ bool GuiGraphics::isValid() } -bool GuiGraphics::initialiseParams(string const & data) +bool GuiGraphics::initialiseParams(string const & sdata) { - InsetGraphics::string2params(data, buffer(), params_); + InsetGraphics::string2params(sdata, buffer(), params_); paramsToDialog(params_); current_group_ = params_.groupId; return true; @@ -788,16 +779,16 @@ QString GuiGraphics::browse(QString const & in_name) const // Does user clipart directory exist? string clipdir = addName(package().user_support().absFileName(), "clipart"); - FileName clip(clipdir); + FileName fclip(clipdir); // bail out to system clipart directory - if (!clip.isDirectory()) + if (!fclip.isDirectory()) clipdir = addName(package().system_support().absFileName(), "clipart"); - return browseRelFile(in_name, bufferFilePath(), - title, fileFilters(QString()), false, - qt_("Clipart|#C#c"), toqstr(clipdir), - qt_("Documents|#o#O"), toqstr(lyxrc.document_path)); + return browseRelToParent(in_name, bufferFilePath(), + title, fileFilters(QString()), false, + qt_("&Clipart"), toqstr(clipdir), + qt_("D&ocuments"), toqstr(lyxrc.document_path)); } @@ -807,7 +798,7 @@ string GuiGraphics::readBoundingBox(string const & file) // try to get it from the file, if possible. Zipped files are // unzipped in the readBB_from_PSFile-Function - string const bb = readBB_from_PSFile(abs_file); + string const bb = graphics::readBB_from_PSFile(abs_file); if (!bb.empty()) return bb;