*
* \author John Levon
* \author Angus Leeming
+ * \author Asger Alstrup
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include "lengthcommon.h"
-#include "LyXRC.h"
+#include "GuiExternal.h"
-#include "controllers/ButtonController.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/FileFilterList.h"
+#include "support/filetools.h"
+#include "support/lstrings.h"
#include "support/lyxlib.h"
-
-#include "GuiExternal.h"
-#include "Qt2BC.h"
+#include "support/os.h"
#include "LengthCombo.h"
#include "qt_helpers.h"
#include "Validator.h"
+#include <QCheckBox>
#include <QLineEdit>
#include <QPushButton>
-#include <QCheckBox>
#include <QTabWidget>
#include <QTextBrowser>
-namespace external = lyx::external;
-
-using lyx::support::isStrDbl;
-using lyx::support::token;
-using lyx::support::trim;
-using lyx::support::float_equal;
+using namespace std;
+using namespace lyx::support;
-using lyx::support::os::internal_path;
+namespace lyx {
+namespace frontend {
-using std::string;
-using std::vector;
-using std::find;
+using namespace external;
+namespace {
-namespace lyx {
-namespace frontend {
+RotationDataType origins_array[] = {
+ RotationData::DEFAULT,
+ RotationData::TOPLEFT,
+ RotationData::BOTTOMLEFT,
+ RotationData::BASELINELEFT,
+ RotationData::CENTER,
+ RotationData::TOPCENTER,
+ RotationData::BOTTOMCENTER,
+ RotationData::BASELINECENTER,
+ RotationData::TOPRIGHT,
+ RotationData::BOTTOMRIGHT,
+ RotationData::BASELINERIGHT
+};
+
+
+size_type const origins_array_size =
+sizeof(origins_array) / sizeof(origins_array[0]);
+
+vector<external::RotationDataType> const
+all_origins(origins_array, origins_array + origins_array_size);
+
+// 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")
+};
-/////////////////////////////////////////////////////////////////////
-//
-// GuiExternalDialog
-//
-/////////////////////////////////////////////////////////////////////
+} // namespace anon
-GuiExternalDialog::GuiExternalDialog(GuiExternal * form)
- : form_(form)
+GuiExternal::GuiExternal(GuiView & lv)
+ : GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
{
setupUi(this);
- connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
+
+ 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)),
displayscaleED, SLOT(setEnabled(bool)));
- connect(showCO, SIGNAL(activated(const QString&)),
+ connect(showCO, SIGNAL(activated(QString)),
this, SLOT(change_adaptor()));
connect(originCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
this, SLOT(change_adaptor()));
connect(browsePB, SIGNAL(clicked()),
this, SLOT(browseClicked()));
+ connect(embedCB, SIGNAL(toggled(bool)),
+ this, SLOT(change_adaptor()));
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)),
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);
heightED->setValidator(unsignedLengthValidator(heightED));
setFocusProxy(fileED);
-}
+ bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
+
+ bc().setOK(okPB);
+ bc().setApply(applyPB);
+ bc().setCancel(closePB);
+
+ 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(angleED);
+ bc().addReadOnly(originCO);
+ bc().addReadOnly(heightUnitCO);
+ bc().addReadOnly(heightED);
+ bc().addReadOnly(aspectratioCB);
+ bc().addReadOnly(widthUnitCO);
+ bc().addReadOnly(widthED);
+ bc().addReadOnly(clipCB);
+ bc().addReadOnly(getbbPB);
+ bc().addReadOnly(ytED);
+ bc().addReadOnly(xlED);
+ bc().addReadOnly(xrED);
+ bc().addReadOnly(ybED);
+ bc().addReadOnly(extraFormatCO);
+ bc().addReadOnly(extraED);
+
+ bc().addCheckedLineEdit(angleED, angleLA);
+ bc().addCheckedLineEdit(displayscaleED, scaleLA);
+ bc().addCheckedLineEdit(heightED, heightLA);
+ bc().addCheckedLineEdit(widthED, widthLA);
+ bc().addCheckedLineEdit(xlED, lbLA);
+ bc().addCheckedLineEdit(ybED, lbLA);
+ bc().addCheckedLineEdit(xrED, rtLA);
+ bc().addCheckedLineEdit(ytED, rtLA);
+ bc().addCheckedLineEdit(fileED, fileLA);
+
+ vector<string> templates = getTemplates();
+
+ for (vector<string>::const_iterator cit = templates.begin();
+ cit != templates.end(); ++cit) {
+ externalCO->addItem(qt_(*cit));
+ }
-void GuiExternalDialog::show()
-{
- QDialog::show();
-}
+ // Fill the origins combo
+ for (size_t i = 0; i != all_origins.size(); ++i)
+ originCO->addItem(qt_(origin_gui_strs[i]));
+ // Fill the width combo
+ widthUnitCO->addItem(qt_("Scale%"));
+ for (int i = 0; i < num_units; i++)
+ widthUnitCO->addItem(qt_(unit_name_gui[i]));
+}
-bool GuiExternalDialog::activateAspectratio() const
+bool GuiExternal::activateAspectratio() const
{
if (widthUnitCO->currentIndex() == 0)
return false;
}
-void GuiExternalDialog::bbChanged()
+void GuiExternal::bbChanged()
{
- form_->controller().bbChanged(true);
- form_->changed();
+ bbChanged_ = true;
+ changed();
}
-void GuiExternalDialog::browseClicked()
+void GuiExternal::browseClicked()
{
int const choice = externalCO->currentIndex();
- docstring const template_name =
- from_utf8(form_->controller().getTemplate(choice).lyxName);
- docstring const str =
- form_->controller().browse(qstring_to_ucs4(fileED->text()),
- template_name);
+ docstring const template_name = from_utf8(getTemplate(choice).lyxName);
+ docstring const str = browse(qstring_to_ucs4(fileED->text()), template_name);
if (!str.empty()) {
fileED->setText(toqstr(str));
- form_->changed();
+ changed();
}
}
-void GuiExternalDialog::change_adaptor()
+void GuiExternal::change_adaptor()
{
- form_->changed();
+ changed();
}
-void GuiExternalDialog::closeEvent(QCloseEvent * e)
+void GuiExternal::editClicked()
{
- form_->slotWMHide();
- e->accept();
+ editExternal();
}
-void GuiExternalDialog::editClicked()
-{
- form_->controller().editExternal();
-}
-
-
-void GuiExternalDialog::extraChanged(const QString& text)
+void GuiExternal::extraChanged(const QString& text)
{
- std::string const format = fromqstr(extraFormatCO->currentText());
- form_->extra_[format] = text;
- form_->changed();
+ string const format = fromqstr(extraFormatCO->currentText());
+ extra_[format] = text;
+ changed();
}
-void GuiExternalDialog::formatChanged(const QString& format)
+void GuiExternal::formatChanged(const QString& format)
{
- extraED->setText(form_->extra_[fromqstr(format)]);
+ extraED->setText(extra_[fromqstr(format)]);
}
-void GuiExternalDialog::getbbClicked()
+void GuiExternal::getbbClicked()
{
- form_->getBB();
+ getBB();
}
-void GuiExternalDialog::sizeChanged()
+void GuiExternal::sizeChanged()
{
aspectratioCB->setEnabled(activateAspectratio());
- form_->changed();
+ changed();
}
-void GuiExternalDialog::templateChanged()
+void GuiExternal::templateChanged()
{
- form_->updateTemplate();
- form_->changed();
+ updateTemplate();
+ changed();
}
-void GuiExternalDialog::widthUnitChanged()
+void GuiExternal::widthUnitChanged()
{
bool useHeight = (widthUnitCO->currentIndex() > 0);
heightED->setEnabled(useHeight);
heightUnitCO->setEnabled(useHeight);
- form_->changed();
+ changed();
}
-/////////////////////////////////////////////////////////////////////
-//
-// GuiExternal
-//
-/////////////////////////////////////////////////////////////////////
-
-namespace {
-
-Length::UNIT defaultUnit()
+static Length::UNIT defaultUnit()
{
Length::UNIT default_unit = Length::CM;
switch (lyxrc.default_papersize) {
}
-void setDisplay(QCheckBox & displayCB, QComboBox & showCO, QLineEdit & scaleED,
- external::DisplayType display, unsigned int scale,
- bool read_only)
+static void setDisplay(
+ QCheckBox & displayCB, QComboBox & showCO, QLineEdit & scaleED,
+ external::DisplayType display, unsigned int scale, bool read_only)
{
int item = 0;
switch (display) {
showCO.setEnabled(!no_display && !read_only);
displayCB.setChecked(!no_display);
scaleED.setEnabled(!no_display && !read_only);
- scaleED.setText(toqstr(convert<string>(scale)));
+ scaleED.setText(QString::number(scale));
}
-void getDisplay(external::DisplayType & display,
+static void getDisplay(external::DisplayType & display,
unsigned int & scale,
QCheckBox const & displayCB,
QComboBox const & showCO,
if (!displayCB.isChecked())
display = external::NoDisplay;
- scale = convert<int>(fromqstr(scaleED.text()));
+ 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));
}
-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;
}
-void setSize(QLineEdit & widthED, QComboBox & widthUnitCO,
- QLineEdit & heightED, LengthCombo & heightUnitCO,
- QCheckBox & aspectratioCB,
- external::ResizeData const & data)
+static void setSize(QLineEdit & widthED, QComboBox & 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;
widthED.setText(toqstr(scale));
widthUnitCO.setCurrentIndex(0);
} else {
- widthED.setText(toqstr(convert<string>(data.width.value())));
+ 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.
}
-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)
{
string const width = fromqstr(widthED.text());
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;
- xlED.setText(toqstr(convert<string>(bbox.xl)));
- ybED.setText(toqstr(convert<string>(bbox.yb)));
- xrED.setText(toqstr(convert<string>(bbox.xr)));
- ytED.setText(toqstr(convert<string>(bbox.yt)));
+ xlED.setText(QString::number(bbox.xl));
+ ybED.setText(QString::number(bbox.yb));
+ xrED.setText(QString::number(bbox.xr));
+ ytED.setText(QString::number(bbox.yt));
}
-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();
if (!bb_changed)
return;
- data.bbox.xl = convert<int>(fromqstr(xlED.text()));
- data.bbox.yb = convert<int>(fromqstr(ybED.text()));
- data.bbox.xr = convert<int>(fromqstr(xrED.text()));
- data.bbox.yt = convert<int>(fromqstr(ytED.text()));
+ data.bbox.xl = xlED.text().toInt();
+ data.bbox.yb = ybED.text().toInt();
+ data.bbox.xr = xrED.text().toInt();
+ data.bbox.yt = ytED.text().toInt();
}
-void getExtra(external::ExtraData & data,
+static void getExtra(external::ExtraData & data,
GuiExternal::MapType const & extra)
{
typedef GuiExternal::MapType MapType;
- MapType::const_iterator it = extra.begin();
+ 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
-
-
-GuiExternal::GuiExternal(Dialog & parent)
- : GuiView<GuiExternalDialog>(parent, _("External Material"))
-{}
-
-
-void GuiExternal::build_dialog()
-{
- dialog_.reset(new GuiExternalDialog(this));
-
- bcview().setOK(dialog_->okPB);
- bcview().setApply(dialog_->applyPB);
- bcview().setCancel(dialog_->closePB);
-
- bcview().addReadOnly(dialog_->fileED);
- bcview().addReadOnly(dialog_->browsePB);
- bcview().addReadOnly(dialog_->editPB);
- bcview().addReadOnly(dialog_->externalCO);
- bcview().addReadOnly(dialog_->draftCB);
- bcview().addReadOnly(dialog_->displayscaleED);
- bcview().addReadOnly(dialog_->showCO);
- bcview().addReadOnly(dialog_->displayCB);
- bcview().addReadOnly(dialog_->angleED);
- bcview().addReadOnly(dialog_->originCO);
- bcview().addReadOnly(dialog_->heightUnitCO);
- bcview().addReadOnly(dialog_->heightED);
- bcview().addReadOnly(dialog_->aspectratioCB);
- bcview().addReadOnly(dialog_->widthUnitCO);
- bcview().addReadOnly(dialog_->widthED);
- bcview().addReadOnly(dialog_->clipCB);
- bcview().addReadOnly(dialog_->getbbPB);
- bcview().addReadOnly(dialog_->ytED);
- bcview().addReadOnly(dialog_->xlED);
- bcview().addReadOnly(dialog_->xrED);
- bcview().addReadOnly(dialog_->ybED);
- bcview().addReadOnly(dialog_->extraFormatCO);
- bcview().addReadOnly(dialog_->extraED);
-
- addCheckedLineEdit(bcview(), dialog_->angleED, dialog_->angleLA);
- addCheckedLineEdit(bcview(), dialog_->displayscaleED, dialog_->scaleLA);
- addCheckedLineEdit(bcview(), dialog_->heightED, dialog_->heightLA);
- addCheckedLineEdit(bcview(), dialog_->widthED, dialog_->widthLA);
- addCheckedLineEdit(bcview(), dialog_->xlED, dialog_->lbLA);
- addCheckedLineEdit(bcview(), dialog_->ybED, dialog_->lbLA);
- addCheckedLineEdit(bcview(), dialog_->xrED, dialog_->rtLA);
- addCheckedLineEdit(bcview(), dialog_->ytED, dialog_->rtLA);
- addCheckedLineEdit(bcview(), dialog_->fileED, dialog_->fileLA);
-
- std::vector<string> templates(controller().getTemplates());
-
- for (std::vector<string>::const_iterator cit = templates.begin();
- cit != templates.end(); ++cit) {
- dialog_->externalCO->addItem(qt_(*cit));
- }
-
- // Fill the origins combo
- typedef vector<external::RotationDataType> Origins;
- Origins const & all_origins = external::all_origins();
- for (Origins::size_type i = 0; i != all_origins.size(); ++i)
- dialog_->originCO->addItem(toqstr(external::origin_gui_str(i)));
-
- // Fill the width combo
- dialog_->widthUnitCO->addItem(qt_("Scale%"));
- for (int i = 0; i < num_units; i++)
- dialog_->widthUnitCO->addItem(qt_(unit_name_gui[i]));
-}
-
-void GuiExternal::update_contents()
+void GuiExternal::updateContents()
{
- dialog_->tab->setCurrentIndex(0);
- InsetExternalParams const & params = controller().params();
+ tab->setCurrentIndex(0);
string const name =
- params.filename.outputFilename(kernel().bufferFilepath());
- dialog_->fileED->setText(toqstr(name));
+ params_.filename.outputFilename(bufferFilepath());
+ fileED->setText(toqstr(name));
+ embedCB->setCheckState(params_.filename.embedded() ? Qt::Checked : Qt::Unchecked);
- dialog_->externalCO->setCurrentIndex(
- controller().getTemplateNumber(params.templatename()));
+ externalCO->setCurrentIndex(getTemplateNumber(params_.templatename()));
updateTemplate();
- dialog_->draftCB->setChecked(params.draft);
+ draftCB->setChecked(params_.draft);
- setDisplay(*dialog_->displayCB, *dialog_->showCO,
- *dialog_->displayscaleED,
- params.display, params.lyxscale, readOnly());
+ setDisplay(*displayCB, *showCO, *displayscaleED,
+ params_.display, params_.lyxscale, isBufferReadonly());
- setRotation(*dialog_->angleED, *dialog_->originCO, params.rotationdata);
+ setRotation(*angleED, *originCO, params_.rotationdata);
- setSize(*dialog_->widthED, *dialog_->widthUnitCO,
- *dialog_->heightED, *dialog_->heightUnitCO,
- *dialog_->aspectratioCB,
- params.resizedata);
+ setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO,
+ *aspectratioCB, params_.resizedata);
- setCrop(*dialog_->clipCB,
- *dialog_->xlED, *dialog_->ybED,
- *dialog_->xrED, *dialog_->ytED,
- params.clipdata);
- controller().bbChanged(!params.clipdata.bbox.empty());
+ setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED, params_.clipdata);
+ bbChanged_ = !params_.clipdata.bbox.empty();
isValid();
}
void GuiExternal::updateTemplate()
{
- external::Template templ =
- controller().getTemplate(dialog_->externalCO->currentIndex());
- dialog_->externalTB->setPlainText(qt_(templ.helpText));
+ 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.
TransformIDs::const_iterator tr_begin = transformIds.begin();
TransformIDs::const_iterator const tr_end = transformIds.end();
- bool found = find(tr_begin, tr_end, external::Rotate) != tr_end;
- dialog_->tab->setTabEnabled(
- dialog_->tab->indexOf(dialog_->rotatetab), found);
- found = find(tr_begin, tr_end, external::Resize) != tr_end;
- dialog_->tab->setTabEnabled(
- dialog_->tab->indexOf(dialog_->scaletab), found);
+ bool found = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
+ tab->setTabEnabled(tab->indexOf(rotatetab), found);
+ found = std::find(tr_begin, tr_end, external::Resize) != tr_end;
+ tab->setTabEnabled(tab->indexOf(scaletab), found);
- found = find(tr_begin, tr_end, external::Clip) != tr_end;
- dialog_->tab->setTabEnabled(
- dialog_->tab->indexOf(dialog_->croptab), found);
+ found = std::find(tr_begin, tr_end, external::Clip) != tr_end;
+ tab->setTabEnabled(tab->indexOf(croptab), found);
- found = find(tr_begin, tr_end, external::Extra) != tr_end;
- dialog_->tab->setTabEnabled(
- dialog_->tab->indexOf(dialog_->optionstab), found);
+ found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
+ tab->setTabEnabled(tab->indexOf(optionstab), found);
if (!found)
return;
// Ascertain whether the template has any formats supporting
// the 'Extra' option
- QLineEdit * const extraED = dialog_->extraED;
- QComboBox * const extraCB = dialog_->extraFormatCO;
-
extra_.clear();
extraED->clear();
- extraCB->clear();
+ extraFormatCO->clear();
external::Template::Formats::const_iterator it = templ.formats.begin();
external::Template::Formats::const_iterator end = templ.formats.end();
it->second.option_transformers.end())
continue;
string const format = it->first;
- string const opt = controller().params().extradata.get(format);
- extraCB->addItem(toqstr(format));
+ string const opt = params_.extradata.get(format);
+ extraFormatCO->addItem(toqstr(format));
extra_[format] = toqstr(opt);
}
- bool const enabled = extraCB->count() > 0;
+ bool const enabled = extraFormatCO->count() > 0;
- dialog_->tab->setTabEnabled(
- dialog_->tab->indexOf(dialog_->optionstab), enabled);
- extraED->setEnabled(enabled && !kernel().isBufferReadonly());
- extraCB->setEnabled(enabled);
+ tab->setTabEnabled(
+ tab->indexOf(optionstab), enabled);
+ extraED->setEnabled(enabled && !isBufferReadonly());
+ extraFormatCO->setEnabled(enabled);
if (enabled) {
- extraCB->setCurrentIndex(0);
- extraED->setText(extra_[fromqstr(extraCB->currentText())]);
+ extraFormatCO->setCurrentIndex(0);
+ extraED->setText(extra_[fromqstr(extraFormatCO->currentText())]);
}
}
-void GuiExternal::apply()
+void GuiExternal::applyView()
{
- InsetExternalParams params = controller().params();
-
- params.filename.set(internal_path(fromqstr(dialog_->fileED->text())),
- kernel().bufferFilepath());
-
- params.settemplate(controller().getTemplate(
- dialog_->externalCO->currentIndex()).lyxName);
+ params_.filename.set(fromqstr(fileED->text()), bufferFilepath());
+ params_.filename.setEmbed(embedCB->checkState() == Qt::Checked);
- params.draft = dialog_->draftCB->isChecked();
+ params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
- getDisplay(params.display, params.lyxscale,
- *dialog_->displayCB, *dialog_->showCO,
- *dialog_->displayscaleED);
+ params_.draft = draftCB->isChecked();
- if (dialog_->tab->isTabEnabled(
- dialog_->tab->indexOf(dialog_->rotatetab)))
- getRotation(params.rotationdata,
- *dialog_->angleED, *dialog_->originCO);
+ getDisplay(params_.display, params_.lyxscale,
+ *displayCB, *showCO,
+ *displayscaleED);
- if (dialog_->tab->isTabEnabled(
- dialog_->tab->indexOf(dialog_->scaletab)))
- getSize(params.resizedata,
- *dialog_->widthED, *dialog_->widthUnitCO,
- *dialog_->heightED, *dialog_->heightUnitCO,
- *dialog_->aspectratioCB);
+ if (tab->isTabEnabled(tab->indexOf(rotatetab)))
+ getRotation(params_.rotationdata, *angleED, *originCO);
- if (dialog_->tab->isTabEnabled(
- dialog_->tab->indexOf(dialog_->croptab)))
- getCrop(params.clipdata,
- *dialog_->clipCB,
- *dialog_->xlED, *dialog_->ybED,
- *dialog_->xrED, *dialog_->ytED,
- controller().bbChanged());
+ if (tab->isTabEnabled(tab->indexOf(scaletab)))
+ getSize(params_.resizedata, *widthED, *widthUnitCO,
+ *heightED, *heightUnitCO, *aspectratioCB);
- if (dialog_->tab->isTabEnabled(
- dialog_->tab->indexOf(dialog_->optionstab)))
- getExtra(params.extradata, extra_);
+ if (tab->isTabEnabled(tab->indexOf(croptab)))
+ getCrop(params_.clipdata, *clipCB, *xlED, *ybED,
+ *xrED, *ytED, bbChanged_);
- controller().setParams(params);
+ if (tab->isTabEnabled(tab->indexOf(optionstab)))
+ getExtra(params_.extradata, extra_);
}
void GuiExternal::getBB()
{
- dialog_->xlED->setText("0");
- dialog_->ybED->setText("0");
- dialog_->xrED->setText("0");
- dialog_->ytED->setText("0");
+ xlED->setText("0");
+ ybED->setText("0");
+ xrED->setText("0");
+ ytED->setText("0");
- string const filename = fromqstr(dialog_->fileED->text());
+ string const filename = fromqstr(fileED->text());
if (filename.empty())
return;
- string const bb = controller().readBB(filename);
+ string const bb = readBB(filename);
if (bb.empty())
return;
- dialog_->xlED->setText(toqstr(token(bb, ' ', 0)));
- dialog_->ybED->setText(toqstr(token(bb, ' ', 1)));
- dialog_->xrED->setText(toqstr(token(bb, ' ', 2)));
- dialog_->ytED->setText(toqstr(token(bb, ' ', 3)));
+ xlED->setText(toqstr(token(bb, ' ', 0)));
+ ybED->setText(toqstr(token(bb, ' ', 1)));
+ xrED->setText(toqstr(token(bb, ' ', 2)));
+ ytED->setText(toqstr(token(bb, ' ', 3)));
- controller().bbChanged(false);
+ bbChanged_ = false;
}
+
+bool GuiExternal::initialiseParams(string const & data)
+{
+ InsetExternalMailer::string2params(data, buffer(), params_);
+ return true;
+}
+
+
+void GuiExternal::clearParams()
+{
+ params_ = InsetExternalParams();
+}
+
+
+void GuiExternal::dispatchParams()
+{
+ string const lfun = InsetExternalMailer::params2string(params_, buffer());
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+void GuiExternal::editExternal()
+{
+ applyView();
+ string const lfun = InsetExternalMailer::params2string(params_, buffer());
+ dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
+}
+
+
+vector<string> const GuiExternal::getTemplates() const
+{
+ vector<string> result;
+
+ external::TemplateManager::Templates::const_iterator i1, i2;
+ i1 = external::TemplateManager::get().getTemplates().begin();
+ i2 = external::TemplateManager::get().getTemplates().end();
+
+ for (; i1 != i2; ++i1) {
+ result.push_back(i1->second.lyxName);
+ }
+ return result;
+}
+
+
+int GuiExternal::getTemplateNumber(string const & name) const
+{
+ 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 == name)
+ return i;
+ }
+
+ // we can get here if a LyX document has a template not installed
+ // on this machine.
+ return -1;
+}
+
+
+external::Template GuiExternal::getTemplate(int i) const
+{
+ external::TemplateManager::Templates::const_iterator i1
+ = external::TemplateManager::get().getTemplates().begin();
+
+ advance(i1, i);
+
+ return i1->second;
+}
+
+
+string const
+GuiExternal::getTemplateFilters(string const & template_name) const
+{
+ /// Determine the template file extension
+ external::TemplateManager const & etm =
+ external::TemplateManager::get();
+ external::Template const * const et_ptr =
+ etm.getTemplateByName(template_name);
+
+ if (et_ptr)
+ return et_ptr->fileRegExp;
+
+ return string();
+}
+
+
+docstring const GuiExternal::browse(docstring const & input,
+ docstring const & template_name) const
+{
+ docstring const title = _("Select external file");
+
+ docstring const bufpath = from_utf8(bufferFilepath());
+ FileFilterList const filter =
+ FileFilterList(from_utf8(getTemplateFilters(to_utf8(template_name))));
+
+ docstring const label1 = _("Documents|#o#O");
+ docstring const dir1 = from_utf8(lyxrc.document_path);
+
+ return browseRelFile(input, bufpath, title, filter, false, label1, dir1);
+}
+
+
+string const GuiExternal::readBB(string const & file)
+{
+ FileName const abs_file(makeAbsPath(file, 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);
+ if (!bb.empty())
+ return bb;
+
+ // 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();
+ }
+ }
+
+ return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
+}
+
+
+Dialog * createGuiExternal(GuiView & lv) { return new GuiExternal(lv); }
+
+
} // namespace frontend
} // namespace lyx