#include "GuiExternal.h"
+#include "Buffer.h"
#include "FuncRequest.h"
#include "support/gettext.h"
#include "Length.h"
#include "insets/ExternalTemplate.h"
#include "insets/InsetExternal.h"
+#include "graphics/epstools.h"
#include "graphics/GraphicsCache.h"
#include "graphics/GraphicsCacheItem.h"
#include "graphics/GraphicsImage.h"
connect(ytED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
connect(xlED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
connect(ybED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
+ connect(xrUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(bbChanged()));
+ connect(ytUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(bbChanged()));
+ connect(xlUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(bbChanged()));
+ connect(ybUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
+ this, SLOT(bbChanged()));
connect(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
QIntValidator * validator = new QIntValidator(displayscaleED);
angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
- xlED->setValidator(new QIntValidator(xlED));
- ybED->setValidator(new QIntValidator(ybED));
- xrED->setValidator(new QIntValidator(xrED));
- ytED->setValidator(new QIntValidator(ytED));
+ xlED->setValidator(unsignedLengthValidator(xlED));
+ ybED->setValidator(unsignedLengthValidator(ybED));
+ xrED->setValidator(unsignedLengthValidator(xrED));
+ ytED->setValidator(unsignedLengthValidator(ytED));
widthED->setValidator(unsignedLengthValidator(widthED));
heightED->setValidator(unsignedLengthValidator(heightED));
bc().addReadOnly(xlED);
bc().addReadOnly(xrED);
bc().addReadOnly(ybED);
+ bc().addReadOnly(ytUnitCO);
+ bc().addReadOnly(xlUnitCO);
+ bc().addReadOnly(xrUnitCO);
+ bc().addReadOnly(ybUnitCO);
bc().addReadOnly(extraFormatCO);
bc().addReadOnly(extraED);
i1 = external::TemplateManager::get().getTemplates().begin();
i2 = external::TemplateManager::get().getTemplates().end();
for (; i1 != i2; ++i1)
- externalCO->addItem(qt_(i1->second.lyxName));
+ externalCO->addItem(qt_(i1->second.guiName));
// Fill the origins combo
for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i)
// add scale item
widthUnitCO->insertItem(0, qt_("Scale%"), "scale");
+
+ // remove all units from bb that depend on font or other dimensions
+ // we cannot use these, since we need to compare against absolute
+ // values from the image file.
+ xlUnitCO->noPercents();
+ xlUnitCO->removeFontDependent();
+ xrUnitCO->noPercents();
+ xrUnitCO->removeFontDependent();
+ ytUnitCO->noPercents();
+ ytUnitCO->removeFontDependent();
+ ybUnitCO->noPercents();
+ ybUnitCO->removeFontDependent();
}
if (filename.empty())
return;
- FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilepath())));
+ FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilePath())));
// try to get it from the file, if possible
- string bb = readBB_from_PSFile(abs_file);
+ string bb = graphics::readBB_from_PSFile(abs_file);
if (bb.empty()) {
// we don't, so ask the Graphics Cache if it has loaded the file
int width = 0;
bb = "0 0 " + convert<string>(width) + ' ' + convert<string>(height);
}
- xlED->setText(toqstr(token(bb, ' ', 0)));
- ybED->setText(toqstr(token(bb, ' ', 1)));
- xrED->setText(toqstr(token(bb, ' ', 2)));
- ytED->setText(toqstr(token(bb, ' ', 3)));
+ doubleToWidget(xlED, token(bb, ' ', 0));
+ doubleToWidget(ybED, token(bb, ' ', 1));
+ doubleToWidget(xrED, token(bb, ' ', 2));
+ doubleToWidget(ytED, token(bb, ' ', 3));
+ // the values from the file always have the bigpoint-unit bp
+ xlUnitCO->setCurrentIndex(0);
+ ybUnitCO->setCurrentIndex(0);
+ xrUnitCO->setCurrentIndex(0);
+ ytUnitCO->setCurrentIndex(0);
bbChanged_ = false;
}
void setCrop(QCheckBox & clipCB,
QLineEdit & xlED, QLineEdit & ybED,
QLineEdit & xrED, QLineEdit & ytED,
+ LengthCombo & xlUnitCO, LengthCombo & ybUnitCO,
+ LengthCombo & xrUnitCO, LengthCombo & ytUnitCO,
external::ClipData const & data)
{
clipCB.setChecked(data.clip);
- graphics::BoundingBox const & bbox = data.bbox;
- xlED.setText(QString::number(bbox.xl));
- ybED.setText(QString::number(bbox.yb));
- xrED.setText(QString::number(bbox.xr));
- ytED.setText(QString::number(bbox.yt));
+ Length::UNIT const default_unit = data.bbox.xl.zero() ?
+ Length::defaultUnit() : data.bbox.xl.unit();
+ lengthToWidgets(&xlED, &xlUnitCO, data.bbox.xl, default_unit);
+ lengthToWidgets(&ybED, &ybUnitCO, data.bbox.yb, default_unit);
+ lengthToWidgets(&xrED, &xrUnitCO, data.bbox.xr, default_unit);
+ lengthToWidgets(&ytED, &ytUnitCO, data.bbox.yt, default_unit);
}
QCheckBox const & clipCB,
QLineEdit const & xlED, QLineEdit const & ybED,
QLineEdit const & xrED, QLineEdit const & ytED,
+ LengthCombo const & xlUnitCO, LengthCombo const & ybUnitCO,
+ LengthCombo const & xrUnitCO, LengthCombo const & ytUnitCO,
bool bb_changed)
{
data.clip = clipCB.isChecked();
if (!bb_changed)
return;
- data.bbox.xl = xlED.text().toInt();
- data.bbox.yb = ybED.text().toInt();
- data.bbox.xr = xrED.text().toInt();
- data.bbox.yt = ytED.text().toInt();
+ data.bbox.xl = Length(widgetsToLength(&xlED, &xlUnitCO));
+ data.bbox.yb = Length(widgetsToLength(&ybED, &ybUnitCO));
+ data.bbox.xr = Length(widgetsToLength(&xrED, &xrUnitCO));
+ data.bbox.yt = Length(widgetsToLength(&ytED, &ytUnitCO));
}
void GuiExternal::updateContents()
{
string const name =
- params_.filename.outputFilename(fromqstr(bufferFilepath()));
+ params_.filename.outputFileName(fromqstr(bufferFilePath()));
fileED->setText(toqstr(name));
int index = 0;
setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO,
*aspectratioCB, params_.resizedata);
- setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED, params_.clipdata);
+ setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED,
+ *xlUnitCO, *ybUnitCO, *xrUnitCO, *ytUnitCO, params_.clipdata);
bbChanged_ = !params_.clipdata.bbox.empty();
isValid();
void GuiExternal::updateTemplate()
{
external::Template templ = getTemplate(externalCO->currentIndex());
- externalTB->setPlainText(qt_(templ.helpText));
+ externalTB->setPlainText(toqstr(translateIfPossible(templ.helpText)));
// Ascertain which (if any) transformations the template supports
// and disable tabs and Group Boxes hosting unsupported transforms.
TransformIDs::const_iterator tr_begin = transformIds.begin();
TransformIDs::const_iterator const tr_end = transformIds.end();
- bool found = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
- rotationGB->setEnabled(found);
+ bool rotate = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
+ rotationGB->setEnabled(rotate);
- found = std::find(tr_begin, tr_end, external::Resize) != tr_end;
- scaleGB->setEnabled(found);
+ bool resize = std::find(tr_begin, tr_end, external::Resize) != tr_end;
+ scaleGB->setEnabled(resize);
- found = std::find(tr_begin, tr_end, external::Clip) != tr_end;
- cropGB->setEnabled(found);
+ bool clip = std::find(tr_begin, tr_end, external::Clip) != tr_end;
+ cropGB->setEnabled(clip);
- tab->setTabEnabled(tab->indexOf(sizetab),
- rotationGB->isEnabled()
- || scaleGB->isEnabled()
- || cropGB->isEnabled());
+ sizetab->setEnabled(rotate || resize || clip);
+ tab->setTabEnabled(tab->indexOf(sizetab), rotate || resize || clip);
- found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
+ bool found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
optionsGB->setEnabled(found);
bool scaled = displayGB->isChecked() && displayGB->isEnabled() &&
void GuiExternal::applyView()
{
- params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilepath()));
+ params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilePath()));
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
params_.draft = draftCB->isChecked();
*heightED, *heightUnitCO, *aspectratioCB, usingScale());
if (cropGB->isEnabled())
- getCrop(params_.clipdata, *clipCB, *xlED, *ybED,
- *xrED, *ytED, bbChanged_);
+ getCrop(params_.clipdata, *clipCB, *xlED, *ybED, *xrED, *ytED,
+ *xlUnitCO, *ybUnitCO, *xrUnitCO, *ytUnitCO, bbChanged_);
if (optionsGB->isEnabled()) {
MapType::const_iterator it = extra_.begin();
external::Template const * const et_ptr =
etm.getTemplateByName(fromqstr(template_name));
- return fileFilters(et_ptr ? toqstr(et_ptr->fileRegExp) : QString());
+ string filter;
+ if (et_ptr && et_ptr->fileRegExp != "" && et_ptr->fileRegExp != "*") {
+ filter += et_ptr->guiName;
+ filter += " (";
+ filter += et_ptr->fileRegExp;
+ filter += ")";
+ }
+ return fileFilters(toqstr(filter));
}
QString const & template_name) const
{
QString const title = qt_("Select external file");
- QString const bufpath = bufferFilepath();
+ QString const bufpath = bufferFilePath();
QStringList const filter = templateFilters(template_name);
QString const label1 = qt_("Documents|#o#O");
QString const dir1 = toqstr(lyxrc.document_path);
- return browseRelFile(input, bufpath, title, filter, false, label1, dir1);
+ return browseRelToParent(input, bufpath, title, filter, false, label1, dir1);
}