#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"
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
-static string autostr = N_("automatically");
+static string const autostr = N_("automatically");
} // namespace anon
}
-template<class Pair>
-vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
-{
- size_t const n = pr.size();
- vector<typename Pair::first_type> tmp(n);
- for (size_t i = 0; i != n; ++i)
- tmp[i] = pr[i].first;
- return tmp;
-}
-
-
-///
-template<class Pair>
-vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
-{
- size_t const n = pr.size();
- vector<typename Pair::second_type> 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<docstring, string> RotationOriginPair;
-///
-vector<RotationOriginPair> getRotationOriginData()
-{
- static vector<RotationOriginPair> 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"))
+ : GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
{
setupUi(this);
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)),
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()));
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
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));
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);
}
-void GuiGraphics::change_group(int index)
+void GuiGraphics::changeGroup(int /* index */)
{
QString const new_group = groupCO->itemData(
groupCO->currentIndex()).toString();
}
-void GuiGraphics::change_bb()
+void GuiGraphics::changeBB()
{
bbChanged = true;
LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
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();
}
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()
(angle->text() != "0"));
setAutoText();
+ updateAspectRatioStatus();
}
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()
(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_aspectratio_toggled(bool aspectratio)
+{
+ if (aspectratio) {
+ 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"));
+ }
}
(filename != "0"));
}
-// returns the number of the string s in the vector v
-static int itemNumber(const vector<string> & v, string const & s)
-{
- vector<string>::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[[unit of measure]]") };
size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
- vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
lbXunit->clear();
lbYunit->clear();
rtXunit->clear();
rtYunit->clear();
- for (vector<string>::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();
- //lyxerr << bufferFilepath();
+ //lyxerr << bufferFilePath();
string const name =
- igp.filename.outputFilename(fromqstr(bufferFilepath()));
+ igp.filename.outputFileName(fromqstr(bufferFilePath()));
filename->setText(toqstr(name));
// set the bounding box values
- if (igp.bb.empty()) {
- string const bb = readBoundingBox(igp.filename.absFilename());
+ if (igp.bbox.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);
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)) {
- lbX->setText(toqstr(convert<string>(anyLength.value())));
- string const unit = unit_name[anyLength.unit()];
- lbXunit->setCurrentIndex(itemNumber(units, unit));
- } else {
- lbX->setText(toqstr(xl));
- }
- if (isValidLength(yl, &anyLength)) {
- lbY->setText(toqstr(convert<string>(anyLength.value())));
- string const unit = unit_name[anyLength.unit()];
- lbYunit->setCurrentIndex(itemNumber(units, unit));
- } else {
- lbY->setText(toqstr(xl));
- }
- if (isValidLength(xr, &anyLength)) {
- rtX->setText(toqstr(convert<string>(anyLength.value())));
- string const unit = unit_name[anyLength.unit()];
- rtXunit->setCurrentIndex(itemNumber(units, unit));
- } else {
- rtX->setText(toqstr(xl));
- }
- if (isValidLength(yr, &anyLength)) {
- rtY->setText(toqstr(convert<string>(anyLength.value())));
- string const unit = unit_name[anyLength.unit()];
- rtYunit->setCurrentIndex(itemNumber(units, 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<string>(igp.lyxscale)));
// 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);
set<string>::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())
scaleCB->setEnabled(!widthChecked && !heightChecked);
WidthCB->setEnabled(!scaleChecked);
HeightCB->setEnabled(!scaleChecked);
- aspectratio->setEnabled(widthChecked && heightChecked);
setAutoText();
+ updateAspectRatioStatus();
- angle->setText(toqstr(igp.rotateAngle));
+ doubleToWidget(angle, igp.rotateAngle);
rotateOrderCB->setChecked(igp.scaleBeforeRotation);
rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
origin->clear();
- vector<RotationOriginPair> origindata = getRotationOriginData();
- vector<docstring> const origin_lang = getFirst(origindata);
- origin_ltx = getSecond(origindata);
-
- for (vector<docstring>::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();
}
{
InsetGraphicsParams & igp = params_;
- igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
+ igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
// the bb section
- igp.bb.erase();
+ igp.bbox = graphics::BoundingBox();
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<int>(lbXs) + convert<int>(lbYs) +
convert<int>(rtXs) + convert<int>(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()));
}
}
//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;
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 = fromqstr(angle->text());
+ igp.rotateAngle = widgetToDoubleStr(angle);
- double rotAngle = convert<double>(igp.rotateAngle);
+ double rotAngle = widgetToDouble(angle);
if (abs(rotAngle) > 360.0) {
rotAngle -= 360.0 * floor(rotAngle / 360.0);
igp.rotateAngle = convert<string>(rotAngle);
// 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
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);
QString const title = qt_("Select graphics file");
// Does user clipart directory exist?
- string clipdir = addName(package().user_support().absFilename(), "clipart");
+ string clipdir = addName(package().user_support().absFileName(), "clipart");
FileName clip(clipdir);
// bail out to system clipart directory
if (!clip.isDirectory())
- clipdir = addName(package().system_support().absFilename(), "clipart");
+ clipdir = addName(package().system_support().absFileName(), "clipart");
- return browseRelFile(in_name, bufferFilepath(),
+ return browseRelToParent(in_name, bufferFilePath(),
title, fileFilters(QString()), false,
qt_("Clipart|#C#c"), toqstr(clipdir),
qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
string GuiGraphics::readBoundingBox(string const & file)
{
- FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilepath()));
+ 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
- string const bb = readBB_from_PSFile(abs_file);
+ string const bb = graphics::readBB_from_PSFile(abs_file);
if (!bb.empty())
return bb;
bool GuiGraphics::isFileNameValid(string const & fname) const
{
// It may be that the filename is relative.
- return support::makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
+ return support::makeAbsPath(fname, fromqstr(bufferFilePath())).isReadableFile();
}