X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiGraphics.cpp;h=6801f4c5d009fbb88c3687f435f575bae2f4c1ee;hb=5cb80b867f4a59c3253487652ba74a29ad5b3f0f;hp=b6bbaeac3fb13860c7a7049a4b0b01ec7c378af7;hpb=c293be56bd12c5dc46e5cedd2828e33918fccef7;p=lyx.git diff --git a/src/frontends/qt/GuiGraphics.cpp b/src/frontends/qt/GuiGraphics.cpp index b6bbaeac3f..6801f4c5d0 100644 --- a/src/frontends/qt/GuiGraphics.cpp +++ b/src/frontends/qt/GuiGraphics.cpp @@ -7,7 +7,7 @@ * \author John Levon * \author Edwin Leuven * \author Herbert Voß - * \author Richard Heck + * \author Richard Kimberly Heck * * Full author contact details are available in file CREDITS. */ @@ -22,7 +22,6 @@ #include "Buffer.h" #include "FuncRequest.h" #include "LengthCombo.h" -#include "Length.h" #include "LyXRC.h" #include "graphics/epstools.h" @@ -36,6 +35,7 @@ #include "support/debug.h" #include "support/filetools.h" #include "support/gettext.h" +#include "support/Length.h" #include "support/lstrings.h" #include "support/os.h" #include "support/Package.h" @@ -158,8 +158,8 @@ GuiGraphics::GuiGraphics(GuiView & lv) scaleValidator->setBottom(0); scaleValidator->setDecimals(256); //I guess that will do Scale->setValidator(scaleValidator); - Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr))); - Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr))); + Height->setValidator(positiveLengthAutoValidator(Height, qt_(autostr))); + Width->setValidator(positiveLengthAutoValidator(Width, qt_(autostr))); angle->setValidator(new QDoubleValidator(-360, 360, 2, angle)); //clipping pane @@ -194,20 +194,14 @@ GuiGraphics::GuiGraphics(GuiView & lv) this, SLOT(change_adaptor())); connect(draftCB, 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 - // using blockSignals() to keep from triggering that signal when we call - // setChecked(). Note, too, that clicked() would get called whenever it - // is clicked, even right clicked (I think), not just whenever it is - // toggled. - connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); + connect(displayGB, SIGNAL(clicked(bool)), this, SLOT(change_adaptor())); + connect(darkModeCB, SIGNAL(clicked(bool)), this, SLOT(change_adaptor())); connect(displayscale, SIGNAL(textChanged(const QString &)), this, SLOT(change_adaptor())); connect(groupCO, SIGNAL(currentIndexChanged(int)), this, SLOT(changeGroup(int))); - displayscale->setValidator(new QIntValidator(displayscale)); + displayscale->setValidator(new QIntValidator(1, 1000, displayscale)); bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); bc().setOK(buttonBox->button(QDialogButtonBox::Ok)); @@ -223,23 +217,39 @@ GuiGraphics::GuiGraphics(GuiView & lv) bc().addReadOnly(draftCB); bc().addReadOnly(clip); bc().addReadOnly(displayGB); + bc().addReadOnly(darkModeCB); bc().addReadOnly(sizeGB); bc().addReadOnly(rotationGB); bc().addReadOnly(latexoptions); bc().addReadOnly(getPB); bc().addReadOnly(rotateOrderCB); - // initialize the length validator + // Add validated widgets to those that will be + // visually marked if invalid bc().addCheckedLineEdit(Scale, scaleCB); bc().addCheckedLineEdit(Width, WidthCB); bc().addCheckedLineEdit(Height, HeightCB); - bc().addCheckedLineEdit(displayscale, scaleLA); bc().addCheckedLineEdit(angle, angleL); + bc().addCheckedLineEdit(filename, filenameL); + bc().addCheckedLineEdit(displayscale, scaleLA); bc().addCheckedLineEdit(lbX, xL); bc().addCheckedLineEdit(lbY, yL); bc().addCheckedLineEdit(rtX, xL_2); bc().addCheckedLineEdit(rtY, yL_2); - bc().addCheckedLineEdit(filename, filenameL); + + // We also mark the tabs the widgets are in + int tabindex = tabWidget->indexOf(Graphics); + bc().addCheckedLineEdit(Scale, tabWidget, tabindex); + bc().addCheckedLineEdit(Width, tabWidget, tabindex); + bc().addCheckedLineEdit(Height, tabWidget, tabindex); + bc().addCheckedLineEdit(angle, tabWidget, tabindex); + bc().addCheckedLineEdit(filename, tabWidget, tabindex); + bc().addCheckedLineEdit(displayscale, tabWidget, tabWidget->indexOf(ExtraOptions)); + tabindex = tabWidget->indexOf(Clipping); + bc().addCheckedLineEdit(lbX, tabWidget, tabindex); + bc().addCheckedLineEdit(lbY, tabWidget, tabindex); + bc().addCheckedLineEdit(rtX, tabWidget, tabindex); + bc().addCheckedLineEdit(rtY, tabWidget, tabindex); } @@ -341,8 +351,9 @@ void GuiGraphics::on_newGroupPB_clicked() void GuiGraphics::changeBB() { - bbChanged = true; - LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]"); + bbChanged = isChangedBB(); + getPB->setEnabled(bbChanged); + LYXERR(Debug::GRAPHICS, "[bb_Changed set to " << bbChanged << "]"); changed(); } @@ -352,6 +363,10 @@ void GuiGraphics::on_browsePB_clicked() QString const str = browse(filename->text()); if (!str.isEmpty()) { filename->setText(str); + // read in the bb values of the new file + // if there was no explicit custom viewport + if (!bbChanged) + getBB(); changed(); } } @@ -360,6 +375,7 @@ void GuiGraphics::on_browsePB_clicked() void GuiGraphics::on_getPB_clicked() { getBB(); + bbChanged = false; } @@ -368,7 +384,7 @@ void GuiGraphics::setAutoText() if (scaleCB->isChecked()) return; if (!Scale->isEnabled() && Scale->text() != "100") - Scale->setText(qt_(autostr)); + Scale->setText("100"); setAutoTextCB(WidthCB, Width, widthUnit); setAutoTextCB(HeightCB, Height, heightUnit); @@ -492,7 +508,7 @@ void GuiGraphics::on_angle_textChanged(const QString & file_name) } -void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) +void GuiGraphics::paramsToDialog(InsetGraphicsParams const & params) { 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[[unit of measure]]") }; @@ -519,12 +535,12 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) //lyxerr << bufferFilePath(); string const name = - igp.filename.outputFileName(fromqstr(bufferFilePath())); + params.filename.outputFileName(fromqstr(bufferFilePath())); filename->setText(toqstr(name)); // set the bounding box values - if (igp.bbox.empty()) { - string const bb = readBoundingBox(igp.filename.absFileName()); + if (params.bbox.empty()) { + string const bb = readBoundingBox(params.filename.absFileName()); // the values from the file always have the bigpoint-unit bp doubleToWidget(lbX, token(bb, ' ', 0)); doubleToWidget(lbY, token(bb, ' ', 1)); @@ -537,32 +553,33 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) bbChanged = false; } else { // get the values from the inset - doubleToWidget(lbX, igp.bbox.xl.value()); - string unit = unit_name[igp.bbox.xl.unit()]; + doubleToWidget(lbX, params.bbox.xl.value()); + string unit = unit_name[params.bbox.xl.unit()]; lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit))); - doubleToWidget(lbY, igp.bbox.yb.value()); - unit = unit_name[igp.bbox.yb.unit()]; + doubleToWidget(lbY, params.bbox.yb.value()); + unit = unit_name[params.bbox.yb.unit()]; lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit))); - doubleToWidget(rtX, igp.bbox.xr.value()); - unit = unit_name[igp.bbox.xr.unit()]; + doubleToWidget(rtX, params.bbox.xr.value()); + unit = unit_name[params.bbox.xr.unit()]; rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit))); - doubleToWidget(rtY, igp.bbox.yt.value()); - unit = unit_name[igp.bbox.yt.unit()]; + doubleToWidget(rtY, params.bbox.yt.value()); + unit = unit_name[params.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); - displayGB->setChecked(igp.display); - displayscale->setText(toqstr(convert(igp.lyxscale))); + draftCB->setChecked(params.draft); + clip->setChecked(params.clip); + darkModeCB->setChecked(params.darkModeSensitive); + displayGB->setChecked(params.display); + displayscale->setText(toqstr(convert(params.lyxscale))); // the output section (width/height) - doubleToWidget(Scale, igp.scale); + doubleToWidget(Scale, params.scale); //igp.scale defaults to 100, so we treat it as empty - bool const scaleChecked = !igp.scale.empty() && igp.scale != "100"; + bool const scaleChecked = !params.scale.empty() && params.scale != "100"; scaleCB->blockSignals(true); scaleCB->setChecked(scaleChecked); scaleCB->blockSignals(false); @@ -578,17 +595,17 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) for (; it != end; ++it) groupCO->addItem(toqstr(*it), toqstr(*it)); groupCO->insertItem(0, qt_("None"), QString()); - if (igp.groupId.empty()) + if (params.groupId.empty()) groupCO->setCurrentIndex(0); else groupCO->setCurrentIndex( - groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly)); + groupCO->findData(toqstr(params.groupId), Qt::MatchExactly)); groupCO->blockSignals(false); - if (igp.width.value() == 0) + if (params.width.value() == 0) lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit); else - lengthToWidgets(Width, widthUnit, igp.width, defaultUnit); + lengthToWidgets(Width, widthUnit, params.width, defaultUnit); bool const widthChecked = !Width->text().isEmpty() && Width->text() != qt_(autostr); @@ -598,10 +615,10 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) Width->setEnabled(widthChecked); widthUnit->setEnabled(widthChecked); - if (igp.height.value() == 0) + if (params.height.value() == 0) lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit); else - lengthToWidgets(Height, heightUnit, igp.height, defaultUnit); + lengthToWidgets(Height, heightUnit, params.height, defaultUnit); bool const heightChecked = !Height->text().isEmpty() && Height->text() != qt_(autostr); @@ -618,11 +635,11 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) setAutoText(); updateAspectRatioStatus(); - doubleToWidget(angle, igp.rotateAngle); - rotateOrderCB->setChecked(igp.scaleBeforeRotation); + doubleToWidget(angle, params.rotateAngle); + rotateOrderCB->setChecked(params.scaleBeforeRotation); rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked) - && igp.rotateAngle != "0"); + && params.rotateAngle != "0"); origin->clear(); @@ -631,13 +648,13 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) toqstr(rorigin_lyx_strs[i])); } - if (!igp.rotateOrigin.empty()) - origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin))); + if (!params.rotateOrigin.empty()) + origin->setCurrentIndex(origin->findData(toqstr(params.rotateOrigin))); else origin->setCurrentIndex(0); // latex section - latexoptions->setText(toqstr(igp.special)); + latexoptions->setText(toqstr(params.special)); // cf bug #3852 filename->setFocus(); } @@ -678,6 +695,7 @@ void GuiGraphics::applyView() igp.draft = draftCB->isChecked(); igp.clip = clip->isChecked(); igp.display = displayGB->isChecked(); + igp.darkModeSensitive = darkModeCB->isChecked(); //the graphics section if (scaleCB->isChecked() && !Scale->text().isEmpty()) { @@ -744,6 +762,37 @@ void GuiGraphics::getBB() } +bool GuiGraphics::isChangedBB() +{ + string const fn = fromqstr(filename->text()); + if (fn.empty()) + return false; + + string const bb = readBoundingBox(fn); + if (bb.empty()) + return false; + + // Compare orig bb values with the set ones + if (Length(token(bb, ' ', 0) + "bp") != + Length(widgetToDoubleStr(lbX) + fromqstr(lbXunit->currentText()))) + return true; + + if (Length(token(bb, ' ', 1) + "bp") != + Length(widgetToDoubleStr(lbY) + fromqstr(lbYunit->currentText()))) + return true; + + if (Length(token(bb, ' ', 2) + "bp") != + Length(widgetToDoubleStr(rtX) + fromqstr(rtXunit->currentText()))) + return true; + + if (Length(token(bb, ' ', 3) + "bp") != + Length(widgetToDoubleStr(rtY) + fromqstr(rtYunit->currentText()))) + return true; + + return false; +} + + bool GuiGraphics::isValid() { return !filename->text().isEmpty(); @@ -770,6 +819,7 @@ void GuiGraphics::dispatchParams() InsetGraphicsParams tmp_params(params_); string const lfun = InsetGraphics::params2string(tmp_params, buffer()); dispatch(FuncRequest(getLfun(), lfun)); + connectToNewInset(); } @@ -796,16 +846,17 @@ string GuiGraphics::readBoundingBox(string const & file) { FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath())); - // try to get it from the file, if possible. Zipped files are - // unzipped in the readBB_from_PSFile-Function + // With (E)PS files, try to get it from the file, if possible. + // Zipped files are unzipped in the readBB_from_PSFile-Function string const bb = graphics::readBB_from_PSFile(abs_file); if (!bb.empty()) return bb; - // we don't, so ask the Graphics Cache if it has loaded the file + // With other formats, we try to read the file dimensions int width = 0; int height = 0; + // First ask the Graphics Cache if it has loaded the file graphics::Cache & gc = graphics::Cache::get(); if (gc.inCache(abs_file)) { graphics::Image const * image = gc.item(abs_file)->image(); @@ -814,6 +865,13 @@ string GuiGraphics::readBoundingBox(string const & file) width = image->width(); height = image->height(); } + } else { + // If not, construct a QImage and get the values from that + QImage image(toqstr(abs_file.absoluteFilePath())); + if (!image.isNull()) { + width = image.width(); + height = image.height(); + } } return ("0 0 " + convert(width) + ' ' + convert(height)); @@ -827,9 +885,6 @@ bool GuiGraphics::isFileNameValid(string const & fname) const } -Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); } - - } // namespace frontend } // namespace lyx