X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiExternal.cpp;h=38443e8db5d30872f70a7a4888a6d84d67165084;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=3dee6355242273df203bdb7c6ad6dccf5d3d22b6;hpb=470aba2a0e552f27d55992372c09f15af9725fa8;p=lyx.git diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index 3dee635524..38443e8db5 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -5,6 +5,7 @@ * * \author John Levon * \author Angus Leeming + * \author Asger Alstrup * * Full author contact details are available in file CREDITS. */ @@ -13,99 +14,131 @@ #include "GuiExternal.h" -#include "ControlExternal.h" -#include "lengthcommon.h" +#include "FuncRequest.h" +#include "support/gettext.h" +#include "Length.h" #include "LyXRC.h" +#include "insets/ExternalSupport.h" #include "insets/ExternalTemplate.h" #include "insets/InsetExternal.h" -#include "support/lstrings.h" +#include "graphics/GraphicsCache.h" +#include "graphics/GraphicsCacheItem.h" +#include "graphics/GraphicsImage.h" + #include "support/convert.h" -#include "support/os.h" +#include "support/filetools.h" +#include "support/lstrings.h" #include "support/lyxlib.h" +#include "support/os.h" #include "LengthCombo.h" #include "qt_helpers.h" #include "Validator.h" -#include #include +#include #include #include #include #include -namespace external = lyx::external; +using namespace std; +using namespace lyx::support; + +namespace lyx { +namespace frontend { -using lyx::support::isStrDbl; -using lyx::support::token; -using lyx::support::trim; -using lyx::support::float_equal; +using namespace external; -using lyx::support::os::internal_path; +namespace { -using std::string; -using std::vector; +RotationDataType origins[] = { + RotationData::DEFAULT, + RotationData::TOPLEFT, + RotationData::BOTTOMLEFT, + RotationData::BASELINELEFT, + RotationData::CENTER, + RotationData::TOPCENTER, + RotationData::BOTTOMCENTER, + RotationData::BASELINECENTER, + RotationData::TOPRIGHT, + RotationData::BOTTOMRIGHT, + RotationData::BASELINERIGHT +}; + + +// These are the strings, corresponding to the above, that the GUI should +// use. Note that they can/should be translated. +char const * const origin_gui_strs[] = { + N_("Default"), + N_("Top left"), N_("Bottom left"), N_("Baseline left"), + N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"), + N_("Top right"), N_("Bottom right"), N_("Baseline right") +}; + +external::Template getTemplate(int i) +{ + if (external::TemplateManager::get().getTemplates().empty()) + return Template(); + external::TemplateManager::Templates::const_iterator i1 + = external::TemplateManager::get().getTemplates().begin(); + advance(i1, i); + return i1->second; +} +} // namespace anon -namespace lyx { -namespace frontend { -GuiExternalDialog::GuiExternalDialog(LyXView & lv) - : GuiDialog(lv, "external") +GuiExternal::GuiExternal(GuiView & lv) + : GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false) { setupUi(this); - setViewTitle(_("External Material")); - setController(new ControlExternal(*this)); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(displayCB, SIGNAL(toggled(bool)), - showCO, SLOT(setEnabled(bool))); - connect(displayCB, SIGNAL(toggled(bool)), + /* + connect(displayGB, SIGNAL(toggled(bool)), displayscaleED, SLOT(setEnabled(bool))); - connect(showCO, SIGNAL(activated(const QString&)), - this, SLOT(change_adaptor())); + */ connect(originCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(aspectratioCB, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); connect(browsePB, SIGNAL(clicked()), this, SLOT(browseClicked())); - connect(editPB, SIGNAL(clicked()), - this, SLOT(editClicked())); - connect(externalCO, SIGNAL(activated(const QString &)), + connect(externalCO, SIGNAL(activated(QString)), this, SLOT(templateChanged())); - connect(extraED, SIGNAL(textChanged(const QString &)), - this, SLOT(extraChanged(const QString&))); - connect(extraFormatCO, SIGNAL(activated(const QString &)), - this, SLOT(formatChanged(const QString&))); + connect(extraED, SIGNAL(textChanged(QString)), + this, SLOT(extraChanged(QString))); + connect(extraFormatCO, SIGNAL(activated(QString)), + this, SLOT(formatChanged(QString))); connect(widthUnitCO, SIGNAL(activated(int)), this, SLOT(widthUnitChanged())); connect(heightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), this, SLOT(change_adaptor())); - connect(displayCB, SIGNAL(stateChanged(int)), + connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); - connect(displayscaleED, SIGNAL(textChanged(const QString &)), + connect(displayscaleED, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor())); - connect(angleED, SIGNAL(textChanged(const QString &)), + connect(angleED, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor())); - connect(widthED, SIGNAL(textChanged(const QString &)), + connect(widthED, SIGNAL(textChanged(QString)), this, SLOT(sizeChanged())); - connect(heightED, SIGNAL(textChanged(const QString &)), + connect(heightED, SIGNAL(textChanged(QString)), this, SLOT(sizeChanged())); - connect(fileED, SIGNAL(textChanged(const QString &)), + connect(fileED, SIGNAL(textChanged(QString)), this, SLOT(change_adaptor())); connect(clipCB, SIGNAL(stateChanged(int)), this, SLOT(change_adaptor())); connect(getbbPB, SIGNAL(clicked()), this, SLOT(getbbClicked())); - connect(xrED, SIGNAL(textChanged(const QString &)), this, SLOT(bbChanged())); - connect(ytED, SIGNAL(textChanged(const QString &)), this, SLOT(bbChanged())); - connect(xlED, SIGNAL(textChanged(const QString &)), this, SLOT(bbChanged())); - connect(ybED, SIGNAL(textChanged(const QString &)), this, SLOT(bbChanged())); + connect(xrED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged())); + 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(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); QIntValidator * validator = new QIntValidator(displayscaleED); @@ -132,12 +165,10 @@ GuiExternalDialog::GuiExternalDialog(LyXView & lv) bc().addReadOnly(fileED); bc().addReadOnly(browsePB); - bc().addReadOnly(editPB); bc().addReadOnly(externalCO); bc().addReadOnly(draftCB); bc().addReadOnly(displayscaleED); - bc().addReadOnly(showCO); - bc().addReadOnly(displayCB); + bc().addReadOnly(displayGB); bc().addReadOnly(angleED); bc().addReadOnly(originCO); bc().addReadOnly(heightUnitCO); @@ -164,261 +195,189 @@ GuiExternalDialog::GuiExternalDialog(LyXView & lv) bc().addCheckedLineEdit(ytED, rtLA); bc().addCheckedLineEdit(fileED, fileLA); - std::vector templates(controller().getTemplates()); - - for (std::vector::const_iterator cit = templates.begin(); - cit != templates.end(); ++cit) { - externalCO->addItem(qt_(*cit)); - } + external::TemplateManager::Templates::const_iterator i1, i2; + i1 = external::TemplateManager::get().getTemplates().begin(); + i2 = external::TemplateManager::get().getTemplates().end(); + for (; i1 != i2; ++i1) + externalCO->addItem(qt_(i1->second.lyxName)); // Fill the origins combo - typedef vector Origins; - Origins const & all_origins = external::all_origins(); - for (Origins::size_type i = 0; i != all_origins.size(); ++i) - originCO->addItem(toqstr(external::origin_gui_str(i))); - - // Fill the width combo - widthUnitCO->addItem(qt_("Scale%")); - for (int i = 0; i < num_units; i++) - widthUnitCO->addItem(qt_(unit_name_gui[i])); -} + for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i) + originCO->addItem(qt_(origin_gui_strs[i])); - -ControlExternal & GuiExternalDialog::controller() -{ - return static_cast(GuiDialog::controller()); + // add scale item + widthUnitCO->insertItem(0, qt_("Scale%"), "scale"); } -bool GuiExternalDialog::activateAspectratio() const +bool GuiExternal::activateAspectratio() const { - if (widthUnitCO->currentIndex() == 0) + if (usingScale()) return false; - string const wstr = fromqstr(widthED->text()); - if (wstr.empty()) + QString const wstr = widthED->text(); + if (wstr.isEmpty()) return false; - bool const wIsDbl = isStrDbl(wstr); - if (wIsDbl && float_equal(convert(wstr), 0.0, 0.05)) + bool wIsDbl; + double val = wstr.trimmed().toDouble(&wIsDbl); + if (wIsDbl && float_equal(val, 0.0, 0.05)) return false; Length l; - if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero())) + if (!wIsDbl && (!isValidLength(fromqstr(wstr), &l) || l.zero())) return false; - string const hstr = fromqstr(heightED->text()); - if (hstr.empty()) + QString const hstr = heightED->text(); + if (hstr.isEmpty()) return false; - bool const hIsDbl = isStrDbl(hstr); - if (hIsDbl && float_equal(convert(hstr), 0.0, 0.05)) + bool hIsDbl; + val = hstr.trimmed().toDouble(&hIsDbl); + if (hIsDbl && float_equal(val, 0.0, 0.05)) return false; - if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero())) + if (!hIsDbl && (!isValidLength(fromqstr(hstr), &l) || l.zero())) return false; return true; } -void GuiExternalDialog::bbChanged() +bool GuiExternal::usingScale() const +{ + return (widthUnitCO->itemData( + widthUnitCO->currentIndex()).toString() == "scale"); +} + + +void GuiExternal::bbChanged() { - controller().bbChanged(true); + bbChanged_ = true; changed(); } -void GuiExternalDialog::browseClicked() +void GuiExternal::browseClicked() { int const choice = externalCO->currentIndex(); - docstring const template_name = - from_utf8(controller().getTemplate(choice).lyxName); - docstring const str = - controller().browse(qstring_to_ucs4(fileED->text()), - template_name); - if (!str.empty()) { - fileED->setText(toqstr(str)); + QString const template_name = toqstr(getTemplate(choice).lyxName); + QString const str = browse(fileED->text(), template_name); + if (!str.isEmpty()) { + fileED->setText(str); changed(); } } -void GuiExternalDialog::change_adaptor() +void GuiExternal::change_adaptor() { changed(); } -void GuiExternalDialog::closeEvent(QCloseEvent * e) +void GuiExternal::extraChanged(const QString & text) { - slotClose(); - e->accept(); + extra_[extraFormatCO->currentText()] = text; + changed(); } -void GuiExternalDialog::editClicked() +void GuiExternal::formatChanged(const QString & format) { - controller().editExternal(); + extraED->setText(extra_[format]); } - -void GuiExternalDialog::extraChanged(const QString& text) +void GuiExternal::getbbClicked() { - std::string const format = fromqstr(extraFormatCO->currentText()); - extra_[format] = text; - changed(); -} + xlED->setText("0"); + ybED->setText("0"); + xrED->setText("0"); + ytED->setText("0"); + string const filename = fromqstr(fileED->text()); + if (filename.empty()) + return; -void GuiExternalDialog::formatChanged(const QString& format) -{ - extraED->setText(extra_[fromqstr(format)]); -} + 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); + if (bb.empty()) { + // we don't, so ask the Graphics Cache if it has loaded the file + int width = 0; + int height = 0; + + graphics::Cache & gc = graphics::Cache::get(); + if (gc.inCache(abs_file)) { + graphics::Image const * image = gc.item(abs_file)->image(); + + if (image) { + width = image->width(); + height = image->height(); + } + } + bb = "0 0 " + convert(width) + ' ' + convert(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))); -void GuiExternalDialog::getbbClicked() -{ - getBB(); + bbChanged_ = false; } -void GuiExternalDialog::sizeChanged() +void GuiExternal::sizeChanged() { aspectratioCB->setEnabled(activateAspectratio()); changed(); } -void GuiExternalDialog::templateChanged() +void GuiExternal::templateChanged() { updateTemplate(); changed(); } -void GuiExternalDialog::widthUnitChanged() +void GuiExternal::widthUnitChanged() { - bool useHeight = (widthUnitCO->currentIndex() > 0); - - if (useHeight) - widthED->setValidator(unsignedLengthValidator(widthED)); - else + if (usingScale()) widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED)); + else + widthED->setValidator(unsignedLengthValidator(widthED)); - heightED->setEnabled(useHeight); - heightUnitCO->setEnabled(useHeight); + heightED->setEnabled(!usingScale()); + heightUnitCO->setEnabled(!usingScale()); changed(); } - -namespace { - -Length::UNIT defaultUnit() -{ - Length::UNIT default_unit = Length::CM; - switch (lyxrc.default_papersize) { - case PAPER_USLETTER: - case PAPER_USLEGAL: - case PAPER_USEXECUTIVE: - default_unit = Length::IN; - break; - default: - break; - } - return default_unit; -} - - -void setDisplay(QCheckBox & displayCB, QComboBox & showCO, QLineEdit & scaleED, - external::DisplayType display, unsigned int scale, - bool read_only) -{ - int item = 0; - switch (display) { - case external::DefaultDisplay: - item = 0; - break; - case external::MonochromeDisplay: - item = 1; - break; - case external::GrayscaleDisplay: - item = 2; - break; - case external::ColorDisplay: - item = 3; - break; - case external::PreviewDisplay: - item = 4; - break; - case external::NoDisplay: - item = 0; - break; - } - - showCO.setCurrentIndex(item); - bool const no_display = display == external::NoDisplay; - showCO.setEnabled(!no_display && !read_only); - displayCB.setChecked(!no_display); - scaleED.setEnabled(!no_display && !read_only); - scaleED.setText(QString::number(scale)); -} - - -void getDisplay(external::DisplayType & display, - unsigned int & scale, - QCheckBox const & displayCB, - QComboBox const & showCO, - QLineEdit const & scaleED) -{ - switch (showCO.currentIndex()) { - case 0: - display = external::DefaultDisplay; - break; - case 1: - display = external::MonochromeDisplay; - break; - case 2: - display = external::GrayscaleDisplay; - break; - case 3: - display = external::ColorDisplay; - break; - case 4: - display = external::PreviewDisplay; - break; - } - - if (!displayCB.isChecked()) - display = external::NoDisplay; - - scale = scaleED.text().toInt(); -} - - -void setRotation(QLineEdit & angleED, QComboBox & originCO, - external::RotationData const & data) +static void setRotation(QLineEdit & angleED, QComboBox & originCO, + external::RotationData const & data) { originCO.setCurrentIndex(int(data.origin())); - angleED.setText(toqstr(data.angle)); + doubleToWidget(&angleED, data.angle); } -void getRotation(external::RotationData & data, - QLineEdit const & angleED, QComboBox const & originCO) +static void getRotation(external::RotationData & data, + QLineEdit const & angleED, QComboBox const & originCO) { typedef external::RotationData::OriginType OriginType; data.origin(static_cast(originCO.currentIndex())); - data.angle = fromqstr(angleED.text()); + data.angle = widgetToDoubleStr(&angleED); } -void setSize(QLineEdit & widthED, QComboBox & widthUnitCO, - QLineEdit & heightED, LengthCombo & heightUnitCO, - QCheckBox & aspectratioCB, - external::ResizeData const & data) +static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO, + QLineEdit & heightED, LengthCombo & heightUnitCO, + QCheckBox & aspectratioCB, + external::ResizeData const & data) { bool using_scale = data.usingScale(); - std::string scale = data.scale; + string scale = data.scale; if (data.no_resize()) { // Everything is zero, so default to this! using_scale = true; @@ -426,19 +385,15 @@ void setSize(QLineEdit & widthED, QComboBox & widthUnitCO, } if (using_scale) { - widthED.setText(toqstr(scale)); - widthUnitCO.setCurrentIndex(0); - } else { - widthED.setText(QString::number(data.width.value())); - // Because 'Scale' is position 0... - // Note also that width cannot be zero here, so - // we don't need to worry about the default unit. - widthUnitCO.setCurrentIndex(data.width.unit() + 1); - } + doubleToWidget(&widthED, scale); + widthUnitCO.setCurrentItem("scale"); + } else + lengthToWidgets(&widthED, &widthUnitCO, + data.width.asString(), Length::defaultUnit()); string const h = data.height.zero() ? string() : data.height.asString(); - Length::UNIT default_unit = data.width.zero() ? - defaultUnit() : data.width.unit(); + Length::UNIT const default_unit = data.width.zero() ? + Length::defaultUnit() : data.width.unit(); lengthToWidgets(&heightED, &heightUnitCO, h, default_unit); heightED.setEnabled(!using_scale); @@ -452,44 +407,28 @@ void setSize(QLineEdit & widthED, QComboBox & widthUnitCO, } -void getSize(external::ResizeData & data, - QLineEdit const & widthED, QComboBox const & widthUnitCO, - QLineEdit const & heightED, LengthCombo const & heightUnitCO, - QCheckBox const & aspectratioCB) +static void getSize(external::ResizeData & data, + QLineEdit const & widthED, QComboBox const & widthUnitCO, + QLineEdit const & heightED, LengthCombo const & heightUnitCO, + QCheckBox const & aspectratioCB, bool const scaling) { - string const width = fromqstr(widthED.text()); - - if (widthUnitCO.currentIndex() > 0) { - // Subtract one, because scale is 0. - int const unit = widthUnitCO.currentIndex() - 1; - - Length w; - if (isValidLength(width, &w)) - data.width = w; - else if (isStrDbl(width)) - data.width = Length(convert(width), - static_cast(unit)); - else - data.width = Length(); - - data.scale = string(); - - } else { + if (scaling) { // scaling instead of a width - data.scale = width; + data.scale = widgetToDoubleStr(&widthED); data.width = Length(); + } else { + data.width = Length(widgetsToLength(&widthED, &widthUnitCO)); + data.scale = string(); } - data.height = Length(widgetsToLength(&heightED, &heightUnitCO)); - data.keepAspectRatio = aspectratioCB.isChecked(); } void setCrop(QCheckBox & clipCB, - QLineEdit & xlED, QLineEdit & ybED, - QLineEdit & xrED, QLineEdit & ytED, - external::ClipData const & data) + QLineEdit & xlED, QLineEdit & ybED, + QLineEdit & xrED, QLineEdit & ytED, + external::ClipData const & data) { clipCB.setChecked(data.clip); graphics::BoundingBox const & bbox = data.bbox; @@ -500,11 +439,11 @@ void setCrop(QCheckBox & clipCB, } -void getCrop(external::ClipData & data, - QCheckBox const & clipCB, - QLineEdit const & xlED, QLineEdit const & ybED, - QLineEdit const & xrED, QLineEdit const & ytED, - bool bb_changed) +static void getCrop(external::ClipData & data, + QCheckBox const & clipCB, + QLineEdit const & xlED, QLineEdit const & ybED, + QLineEdit const & xrED, QLineEdit const & ytED, + bool bb_changed) { data.clip = clipCB.isChecked(); @@ -518,79 +457,82 @@ void getCrop(external::ClipData & data, } -void getExtra(external::ExtraData & data, - GuiExternalDialog::MapType const & extra) +void GuiExternal::updateContents() { - typedef GuiExternalDialog::MapType MapType; - MapType::const_iterator it = extra.begin(); - MapType::const_iterator const end = extra.end(); - for (; it != end; ++it) - data.set(it->first, trim(fromqstr(it->second))); -} - -} // namespace anon - - - -void GuiExternalDialog::updateContents() -{ - tab->setCurrentIndex(0); - InsetExternalParams const & params = controller().params(); - string const name = - params.filename.outputFilename(controller().bufferFilepath()); + params_.filename.outputFilename(fromqstr(bufferFilepath())); fileED->setText(toqstr(name)); - externalCO->setCurrentIndex( - controller().getTemplateNumber(params.templatename())); + int index = 0; + external::TemplateManager::Templates::const_iterator i1, i2; + i1 = external::TemplateManager::get().getTemplates().begin(); + i2 = external::TemplateManager::get().getTemplates().end(); + for (int i = 0; i1 != i2; ++i1, ++i) { + if (i1->second.lyxName == params_.templatename()) { + index = i; + break; + } + } + + externalCO->setCurrentIndex(index); updateTemplate(); - draftCB->setChecked(params.draft); + draftCB->setChecked(params_.draft); + + displayGB->setChecked(params_.display); + displayscaleED->setText(QString::number(params_.lyxscale)); + bool scaled = params_.display && !isBufferReadonly() && + (params_.preview_mode != PREVIEW_INSTANT); + displayscaleED->setEnabled(scaled); + scaleLA->setEnabled(scaled); + displayGB->setEnabled(lyxrc.display_graphics); - setDisplay(*displayCB, *showCO, - *displayscaleED, - params.display, params.lyxscale, controller().isBufferReadonly()); - setRotation(*angleED, *originCO, params.rotationdata); + setRotation(*angleED, *originCO, params_.rotationdata); - setSize(*widthED, *widthUnitCO, - *heightED, *heightUnitCO, - *aspectratioCB, - params.resizedata); + setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO, + *aspectratioCB, params_.resizedata); - setCrop(*clipCB, - *xlED, *ybED, - *xrED, *ytED, - params.clipdata); - controller().bbChanged(!params.clipdata.bbox.empty()); + setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED, params_.clipdata); + bbChanged_ = !params_.clipdata.bbox.empty(); isValid(); } -void GuiExternalDialog::updateTemplate() +void GuiExternal::updateTemplate() { - external::Template templ = - controller().getTemplate(externalCO->currentIndex()); + external::Template templ = getTemplate(externalCO->currentIndex()); externalTB->setPlainText(qt_(templ.helpText)); // Ascertain which (if any) transformations the template supports - // and disable tabs hosting unsupported transforms. + // and disable tabs and Group Boxes hosting unsupported transforms. typedef vector TransformIDs; TransformIDs const transformIds = templ.transformIds; 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; - tab->setTabEnabled(tab->indexOf(rotatetab), found); + rotationGB->setEnabled(found); + found = std::find(tr_begin, tr_end, external::Resize) != tr_end; - tab->setTabEnabled(tab->indexOf(scaletab), found); + scaleGB->setEnabled(found); found = std::find(tr_begin, tr_end, external::Clip) != tr_end; - tab->setTabEnabled(tab->indexOf(croptab), found); + cropGB->setEnabled(found); + + tab->setTabEnabled(tab->indexOf(sizetab), + rotationGB->isEnabled() + || scaleGB->isEnabled() + || cropGB->isEnabled()); found = std::find(tr_begin, tr_end, external::Extra) != tr_end; - tab->setTabEnabled(tab->indexOf(optionstab), found); + optionsGB->setEnabled(found); + + bool scaled = displayGB->isChecked() && displayGB->isEnabled() && + !isBufferReadonly() && (templ.preview_mode != PREVIEW_INSTANT); + displayscaleED->setEnabled(scaled); + scaleLA->setEnabled(scaled); if (!found) return; @@ -608,83 +550,103 @@ void GuiExternalDialog::updateTemplate() it->second.option_transformers.end()) continue; string const format = it->first; - string const opt = controller().params().extradata.get(format); + string const opt = params_.extradata.get(format); extraFormatCO->addItem(toqstr(format)); - extra_[format] = toqstr(opt); + extra_[toqstr(format)] = toqstr(opt); } bool const enabled = extraFormatCO->count() > 0; - tab->setTabEnabled( - tab->indexOf(optionstab), enabled); - extraED->setEnabled(enabled && !controller().isBufferReadonly()); + optionsGB->setEnabled(enabled); + extraED->setEnabled(enabled && !isBufferReadonly()); extraFormatCO->setEnabled(enabled); if (enabled) { extraFormatCO->setCurrentIndex(0); - extraED->setText(extra_[fromqstr(extraFormatCO->currentText())]); + extraED->setText(extra_[extraFormatCO->currentText()]); } } -void GuiExternalDialog::applyView() +void GuiExternal::applyView() { - InsetExternalParams params = controller().params(); + params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilepath())); + params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName); - params.filename.set(internal_path(fromqstr(fileED->text())), - controller().bufferFilepath()); + params_.draft = draftCB->isChecked(); + params_.lyxscale = displayscaleED->text().toInt(); + params_.display = displayGB->isChecked(); - params.settemplate(controller().getTemplate( - externalCO->currentIndex()).lyxName); + if (rotationGB->isEnabled()) + getRotation(params_.rotationdata, *angleED, *originCO); - params.draft = draftCB->isChecked(); + if (scaleGB->isEnabled()) + getSize(params_.resizedata, *widthED, *widthUnitCO, + *heightED, *heightUnitCO, *aspectratioCB, usingScale()); - getDisplay(params.display, params.lyxscale, - *displayCB, *showCO, - *displayscaleED); + if (cropGB->isEnabled()) + getCrop(params_.clipdata, *clipCB, *xlED, *ybED, + *xrED, *ytED, bbChanged_); - if (tab->isTabEnabled(tab->indexOf(rotatetab))) - getRotation(params.rotationdata, *angleED, *originCO); + if (optionsGB->isEnabled()) { + MapType::const_iterator it = extra_.begin(); + MapType::const_iterator const end = extra_.end(); + for (; it != end; ++it) + params_.extradata.set(fromqstr(it.key()), fromqstr(it.value().trimmed())); + } +} - if (tab->isTabEnabled(tab->indexOf(scaletab))) - getSize(params.resizedata, *widthED, *widthUnitCO, - *heightED, *heightUnitCO, *aspectratioCB); - if (tab->isTabEnabled(tab->indexOf(croptab))) - getCrop(params.clipdata, *clipCB, *xlED, *ybED, - *xrED, *ytED, controller().bbChanged()); +bool GuiExternal::initialiseParams(string const & data) +{ + InsetExternal::string2params(data, buffer(), params_); + return true; +} - if (tab->isTabEnabled(tab->indexOf(optionstab))) - getExtra(params.extradata, extra_); - controller().setParams(params); +void GuiExternal::clearParams() +{ + params_ = InsetExternalParams(); } -void GuiExternalDialog::getBB() +void GuiExternal::dispatchParams() { - xlED->setText("0"); - ybED->setText("0"); - xrED->setText("0"); - ytED->setText("0"); + string const lfun = InsetExternal::params2string(params_, buffer()); + dispatch(FuncRequest(getLfun(), lfun)); +} - string const filename = fromqstr(fileED->text()); - if (filename.empty()) - return; - string const bb = controller().readBB(filename); - if (bb.empty()) - return; +static QStringList templateFilters(QString const & template_name) +{ + /// Determine the template file extension + external::TemplateManager const & etm = + external::TemplateManager::get(); + external::Template const * const et_ptr = + etm.getTemplateByName(fromqstr(template_name)); - xlED->setText(toqstr(token(bb, ' ', 0))); - ybED->setText(toqstr(token(bb, ' ', 1))); - xrED->setText(toqstr(token(bb, ' ', 2))); - ytED->setText(toqstr(token(bb, ' ', 3))); + return fileFilters(et_ptr ? toqstr(et_ptr->fileRegExp) : QString()); +} - controller().bbChanged(false); + +QString GuiExternal::browse(QString const & input, + QString const & template_name) const +{ + QString const title = qt_("Select external file"); + 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); } + +Dialog * createGuiExternal(GuiView & lv) { return new GuiExternal(lv); } + + } // namespace frontend } // namespace lyx -#include "GuiExternal_moc.cpp" +#include "moc_GuiExternal.cpp"