2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiExternal.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Angus Leeming
|
2007-10-07 08:55:20 +00:00
|
|
|
* \author Asger Alstrup
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
#include "GuiExternal.h"
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.h"
|
2007-10-24 22:55:02 +00:00
|
|
|
#include "Length.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "insets/ExternalSupport.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "insets/ExternalTemplate.h"
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/InsetExternal.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "graphics/GraphicsCache.h"
|
|
|
|
#include "graphics/GraphicsCacheItem.h"
|
|
|
|
#include "graphics/GraphicsImage.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/convert.h"
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "support/lstrings.h"
|
2007-04-25 08:42:22 +00:00
|
|
|
#include "support/lyxlib.h"
|
2007-10-07 08:55:20 +00:00
|
|
|
#include "support/os.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "LengthCombo.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
#include "Validator.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
#include <QCheckBox>
|
2008-04-28 06:19:25 +00:00
|
|
|
#include <QGroupBox>
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QTextBrowser>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
using namespace external;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2008-04-18 20:14:20 +00:00
|
|
|
RotationDataType origins[] = {
|
2007-10-07 08:55:20 +00:00
|
|
|
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")
|
|
|
|
};
|
|
|
|
|
2008-04-18 19:39:15 +00:00
|
|
|
external::Template getTemplate(int i)
|
|
|
|
{
|
2009-10-09 12:40:34 +00:00
|
|
|
if (external::TemplateManager::get().getTemplates().empty())
|
|
|
|
return Template();
|
2008-04-18 19:39:15 +00:00
|
|
|
external::TemplateManager::Templates::const_iterator i1
|
|
|
|
= external::TemplateManager::get().getTemplates().begin();
|
|
|
|
advance(i1, i);
|
|
|
|
return i1->second;
|
|
|
|
}
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiExternal::GuiExternal(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-04-25 16:39:21 +00:00
|
|
|
|
2008-06-13 07:34:55 +00:00
|
|
|
/*
|
2008-04-28 06:19:25 +00:00
|
|
|
connect(displayGB, SIGNAL(toggled(bool)),
|
2007-04-25 16:39:21 +00:00
|
|
|
displayscaleED, SLOT(setEnabled(bool)));
|
2008-06-13 07:34:55 +00:00
|
|
|
*/
|
2007-04-25 16:39:21 +00:00
|
|
|
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()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(externalCO, SIGNAL(activated(QString)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(templateChanged()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(extraED, SIGNAL(textChanged(QString)),
|
|
|
|
this, SLOT(extraChanged(QString)));
|
|
|
|
connect(extraFormatCO, SIGNAL(activated(QString)),
|
|
|
|
this, SLOT(formatChanged(QString)));
|
2007-04-25 16:39:21 +00:00
|
|
|
connect(widthUnitCO, SIGNAL(activated(int)),
|
|
|
|
this, SLOT(widthUnitChanged()));
|
2007-04-28 12:58:49 +00:00
|
|
|
connect(heightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2008-04-28 06:19:25 +00:00
|
|
|
connect(displayGB, SIGNAL(toggled(bool)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(displayscaleED, SIGNAL(textChanged(QString)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(angleED, SIGNAL(textChanged(QString)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(widthED, SIGNAL(textChanged(QString)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(sizeChanged()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(heightED, SIGNAL(textChanged(QString)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(sizeChanged()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(fileED, SIGNAL(textChanged(QString)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(clipCB, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(getbbPB, SIGNAL(clicked()), this, SLOT(getbbClicked()));
|
2007-10-07 08:55:20 +00:00
|
|
|
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()));
|
2007-04-25 16:39:21 +00:00
|
|
|
connect(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
|
2007-04-25 08:42:22 +00:00
|
|
|
|
|
|
|
QIntValidator * validator = new QIntValidator(displayscaleED);
|
|
|
|
validator->setBottom(1);
|
|
|
|
displayscaleED->setValidator(validator);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
widthED->setValidator(unsignedLengthValidator(widthED));
|
|
|
|
heightED->setValidator(unsignedLengthValidator(heightED));
|
|
|
|
|
|
|
|
setFocusProxy(fileED);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
|
|
|
|
|
|
|
bc().setOK(okPB);
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
|
|
|
|
bc().addReadOnly(fileED);
|
|
|
|
bc().addReadOnly(browsePB);
|
|
|
|
bc().addReadOnly(externalCO);
|
|
|
|
bc().addReadOnly(draftCB);
|
|
|
|
bc().addReadOnly(displayscaleED);
|
2008-04-28 06:19:25 +00:00
|
|
|
bc().addReadOnly(displayGB);
|
2007-09-05 20:33:29 +00:00
|
|
|
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);
|
|
|
|
|
2008-04-18 19:39:15 +00:00
|
|
|
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));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
// Fill the origins combo
|
2008-04-18 20:14:20 +00:00
|
|
|
for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i)
|
2007-10-07 08:55:20 +00:00
|
|
|
originCO->addItem(qt_(origin_gui_strs[i]));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2009-01-14 15:47:25 +00:00
|
|
|
// add scale item
|
|
|
|
widthUnitCO->insertItem(0, qt_("Scale%"), "scale");
|
2007-09-05 20:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
bool GuiExternal::activateAspectratio() const
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2009-01-14 15:47:25 +00:00
|
|
|
if (usingScale())
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
|
|
|
|
2009-07-12 15:44:26 +00:00
|
|
|
QString const wstr = widthED->text();
|
|
|
|
if (wstr.isEmpty())
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
2009-07-12 15:44:26 +00:00
|
|
|
bool wIsDbl;
|
|
|
|
double val = wstr.trimmed().toDouble(&wIsDbl);
|
|
|
|
if (wIsDbl && float_equal(val, 0.0, 0.05))
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
2007-04-28 12:58:49 +00:00
|
|
|
Length l;
|
2009-07-12 15:44:26 +00:00
|
|
|
if (!wIsDbl && (!isValidLength(fromqstr(wstr), &l) || l.zero()))
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
|
|
|
|
2009-07-12 15:44:26 +00:00
|
|
|
QString const hstr = heightED->text();
|
|
|
|
if (hstr.isEmpty())
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
2009-07-12 15:44:26 +00:00
|
|
|
bool hIsDbl;
|
|
|
|
val = hstr.trimmed().toDouble(&hIsDbl);
|
|
|
|
if (hIsDbl && float_equal(val, 0.0, 0.05))
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
2009-07-12 15:44:26 +00:00
|
|
|
if (!hIsDbl && (!isValidLength(fromqstr(hstr), &l) || l.zero()))
|
2007-04-25 08:42:22 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-14 15:47:25 +00:00
|
|
|
bool GuiExternal::usingScale() const
|
|
|
|
{
|
|
|
|
return (widthUnitCO->itemData(
|
|
|
|
widthUnitCO->currentIndex()).toString() == "scale");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::bbChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2007-10-07 08:55:20 +00:00
|
|
|
bbChanged_ = true;
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::browseClicked()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
int const choice = externalCO->currentIndex();
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const template_name = toqstr(getTemplate(choice).lyxName);
|
|
|
|
QString const str = browse(fileED->text(), template_name);
|
|
|
|
if (!str.isEmpty()) {
|
|
|
|
fileED->setText(str);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-05-14 12:43:17 +00:00
|
|
|
}
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::change_adaptor()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-18 19:17:11 +00:00
|
|
|
void GuiExternal::extraChanged(const QString & text)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-04-18 19:17:11 +00:00
|
|
|
extra_[extraFormatCO->currentText()] = text;
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-18 19:17:11 +00:00
|
|
|
void GuiExternal::formatChanged(const QString & format)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-04-18 19:17:11 +00:00
|
|
|
extraED->setText(extra_[format]);
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::getbbClicked()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2008-04-18 20:14:20 +00:00
|
|
|
xlED->setText("0");
|
|
|
|
ybED->setText("0");
|
|
|
|
xrED->setText("0");
|
|
|
|
ytED->setText("0");
|
|
|
|
|
|
|
|
string const filename = fromqstr(fileED->text());
|
|
|
|
if (filename.empty())
|
|
|
|
return;
|
|
|
|
|
2010-04-21 01:19:30 +00:00
|
|
|
FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilePath())));
|
2008-04-18 20:14:20 +00:00
|
|
|
|
|
|
|
// 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<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)));
|
|
|
|
|
|
|
|
bbChanged_ = false;
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::sizeChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
aspectratioCB->setEnabled(activateAspectratio());
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::templateChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
updateTemplate();
|
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::widthUnitChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
2009-01-14 15:47:25 +00:00
|
|
|
if (usingScale())
|
2007-04-25 08:42:22 +00:00
|
|
|
widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
|
2009-01-14 15:47:25 +00:00
|
|
|
else
|
|
|
|
widthED->setValidator(unsignedLengthValidator(widthED));
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2009-01-14 15:47:25 +00:00
|
|
|
heightED->setEnabled(!usingScale());
|
|
|
|
heightUnitCO->setEnabled(!usingScale());
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
static void setRotation(QLineEdit & angleED, QComboBox & originCO,
|
|
|
|
external::RotationData const & data)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-17 08:54:12 +00:00
|
|
|
originCO.setCurrentIndex(int(data.origin()));
|
2009-07-12 15:44:26 +00:00
|
|
|
doubleToWidget(&angleED, data.angle);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
static void getRotation(external::RotationData & data,
|
|
|
|
QLineEdit const & angleED, QComboBox const & originCO)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
typedef external::RotationData::OriginType OriginType;
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
data.origin(static_cast<OriginType>(originCO.currentIndex()));
|
2009-07-12 15:44:26 +00:00
|
|
|
data.angle = widgetToDoubleStr(&angleED);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-14 15:47:25 +00:00
|
|
|
static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO,
|
2007-10-07 08:55:20 +00:00
|
|
|
QLineEdit & heightED, LengthCombo & heightUnitCO,
|
|
|
|
QCheckBox & aspectratioCB,
|
|
|
|
external::ResizeData const & data)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
bool using_scale = data.usingScale();
|
2007-12-12 19:28:07 +00:00
|
|
|
string scale = data.scale;
|
2006-03-05 17:24:44 +00:00
|
|
|
if (data.no_resize()) {
|
|
|
|
// Everything is zero, so default to this!
|
|
|
|
using_scale = true;
|
|
|
|
scale = "100";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (using_scale) {
|
2009-07-12 15:44:26 +00:00
|
|
|
doubleToWidget(&widthED, scale);
|
2009-01-14 15:47:25 +00:00
|
|
|
widthUnitCO.setCurrentItem("scale");
|
|
|
|
} else
|
|
|
|
lengthToWidgets(&widthED, &widthUnitCO,
|
2009-02-06 21:24:13 +00:00
|
|
|
data.width.asString(), Length::defaultUnit());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
string const h = data.height.zero() ? string() : data.height.asString();
|
2009-02-06 21:24:13 +00:00
|
|
|
Length::UNIT const default_unit = data.width.zero() ?
|
|
|
|
Length::defaultUnit() : data.width.unit();
|
2006-03-05 17:24:44 +00:00
|
|
|
lengthToWidgets(&heightED, &heightUnitCO, h, default_unit);
|
|
|
|
|
|
|
|
heightED.setEnabled(!using_scale);
|
|
|
|
heightUnitCO.setEnabled(!using_scale);
|
|
|
|
|
|
|
|
aspectratioCB.setChecked(data.keepAspectRatio);
|
|
|
|
|
|
|
|
bool const disable_aspectRatio = using_scale ||
|
|
|
|
data.width.zero() || data.height.zero();
|
|
|
|
aspectratioCB.setEnabled(!disable_aspectRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
static void getSize(external::ResizeData & data,
|
|
|
|
QLineEdit const & widthED, QComboBox const & widthUnitCO,
|
|
|
|
QLineEdit const & heightED, LengthCombo const & heightUnitCO,
|
2009-01-14 15:47:25 +00:00
|
|
|
QCheckBox const & aspectratioCB, bool const scaling)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2009-01-14 15:47:25 +00:00
|
|
|
if (scaling) {
|
2006-03-05 17:24:44 +00:00
|
|
|
// scaling instead of a width
|
2009-07-12 15:44:26 +00:00
|
|
|
data.scale = widgetToDoubleStr(&widthED);
|
2007-04-28 12:58:49 +00:00
|
|
|
data.width = Length();
|
2009-01-14 15:47:25 +00:00
|
|
|
} else {
|
|
|
|
data.width = Length(widgetsToLength(&widthED, &widthUnitCO));
|
|
|
|
data.scale = string();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2007-04-28 12:58:49 +00:00
|
|
|
data.height = Length(widgetsToLength(&heightED, &heightUnitCO));
|
2006-03-05 17:24:44 +00:00
|
|
|
data.keepAspectRatio = aspectratioCB.isChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setCrop(QCheckBox & clipCB,
|
2007-10-07 08:55:20 +00:00
|
|
|
QLineEdit & xlED, QLineEdit & ybED,
|
|
|
|
QLineEdit & xrED, QLineEdit & ytED,
|
|
|
|
external::ClipData const & data)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
clipCB.setChecked(data.clip);
|
|
|
|
graphics::BoundingBox const & bbox = data.bbox;
|
2007-09-11 18:33:42 +00:00
|
|
|
xlED.setText(QString::number(bbox.xl));
|
|
|
|
ybED.setText(QString::number(bbox.yb));
|
|
|
|
xrED.setText(QString::number(bbox.xr));
|
|
|
|
ytED.setText(QString::number(bbox.yt));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
static void getCrop(external::ClipData & data,
|
|
|
|
QCheckBox const & clipCB,
|
|
|
|
QLineEdit const & xlED, QLineEdit const & ybED,
|
|
|
|
QLineEdit const & xrED, QLineEdit const & ytED,
|
|
|
|
bool bb_changed)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
data.clip = clipCB.isChecked();
|
|
|
|
|
|
|
|
if (!bb_changed)
|
|
|
|
return;
|
|
|
|
|
2007-09-11 18:33:42 +00:00
|
|
|
data.bbox.xl = xlED.text().toInt();
|
|
|
|
data.bbox.yb = ybED.text().toInt();
|
|
|
|
data.bbox.xr = xrED.text().toInt();
|
|
|
|
data.bbox.yt = ytED.text().toInt();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
string const name =
|
2010-04-21 01:19:30 +00:00
|
|
|
params_.filename.outputFileName(fromqstr(bufferFilePath()));
|
2007-09-05 20:33:29 +00:00
|
|
|
fileED->setText(toqstr(name));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-10-09 12:08:47 +00:00
|
|
|
int index = 0;
|
2008-04-18 19:39:15 +00:00
|
|
|
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);
|
2006-03-05 17:24:44 +00:00
|
|
|
updateTemplate();
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
draftCB->setChecked(params_.draft);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-06-13 07:34:55 +00:00
|
|
|
displayGB->setChecked(params_.display);
|
|
|
|
displayscaleED->setText(QString::number(params_.lyxscale));
|
2008-12-20 13:09:36 +00:00
|
|
|
bool scaled = params_.display && !isBufferReadonly() &&
|
|
|
|
(params_.preview_mode != PREVIEW_INSTANT);
|
|
|
|
displayscaleED->setEnabled(scaled);
|
|
|
|
scaleLA->setEnabled(scaled);
|
2008-12-20 10:06:31 +00:00
|
|
|
displayGB->setEnabled(lyxrc.display_graphics);
|
2008-12-20 13:09:36 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
setRotation(*angleED, *originCO, params_.rotationdata);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO,
|
|
|
|
*aspectratioCB, params_.resizedata);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED, params_.clipdata);
|
|
|
|
bbChanged_ = !params_.clipdata.bbox.empty();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::updateTemplate()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-07 08:55:20 +00:00
|
|
|
external::Template templ = getTemplate(externalCO->currentIndex());
|
2007-09-05 20:33:29 +00:00
|
|
|
externalTB->setPlainText(qt_(templ.helpText));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Ascertain which (if any) transformations the template supports
|
2008-04-28 06:19:25 +00:00
|
|
|
// and disable tabs and Group Boxes hosting unsupported transforms.
|
2006-03-05 17:24:44 +00:00
|
|
|
typedef vector<external::TransformID> TransformIDs;
|
|
|
|
TransformIDs const transformIds = templ.transformIds;
|
|
|
|
TransformIDs::const_iterator tr_begin = transformIds.begin();
|
|
|
|
TransformIDs::const_iterator const tr_end = transformIds.end();
|
|
|
|
|
2011-07-31 18:39:51 +00:00
|
|
|
bool rotate = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
|
|
|
|
rotationGB->setEnabled(rotate);
|
2008-04-28 06:19:25 +00:00
|
|
|
|
2011-07-31 18:39:51 +00:00
|
|
|
bool resize = std::find(tr_begin, tr_end, external::Resize) != tr_end;
|
|
|
|
scaleGB->setEnabled(resize);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2011-07-31 18:39:51 +00:00
|
|
|
bool clip = std::find(tr_begin, tr_end, external::Clip) != tr_end;
|
|
|
|
cropGB->setEnabled(clip);
|
2008-04-28 06:19:25 +00:00
|
|
|
|
2011-07-31 18:39:51 +00:00
|
|
|
sizetab->setEnabled(rotate || resize || clip);
|
|
|
|
tab->setTabEnabled(tab->indexOf(sizetab), rotate || resize || clip);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2011-07-31 18:39:51 +00:00
|
|
|
bool found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
|
2008-04-28 06:19:25 +00:00
|
|
|
optionsGB->setEnabled(found);
|
2008-12-20 13:09:36 +00:00
|
|
|
|
|
|
|
bool scaled = displayGB->isChecked() && displayGB->isEnabled() &&
|
|
|
|
!isBufferReadonly() && (templ.preview_mode != PREVIEW_INSTANT);
|
|
|
|
displayscaleED->setEnabled(scaled);
|
|
|
|
scaleLA->setEnabled(scaled);
|
2006-08-17 08:54:12 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
if (!found)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ascertain whether the template has any formats supporting
|
|
|
|
// the 'Extra' option
|
|
|
|
extra_.clear();
|
|
|
|
extraED->clear();
|
2007-09-05 20:33:29 +00:00
|
|
|
extraFormatCO->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
external::Template::Formats::const_iterator it = templ.formats.begin();
|
|
|
|
external::Template::Formats::const_iterator end = templ.formats.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (it->second.option_transformers.find(external::Extra) ==
|
|
|
|
it->second.option_transformers.end())
|
|
|
|
continue;
|
|
|
|
string const format = it->first;
|
2007-10-07 08:55:20 +00:00
|
|
|
string const opt = params_.extradata.get(format);
|
2007-09-05 20:33:29 +00:00
|
|
|
extraFormatCO->addItem(toqstr(format));
|
2008-04-18 19:17:11 +00:00
|
|
|
extra_[toqstr(format)] = toqstr(opt);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bool const enabled = extraFormatCO->count() > 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-04-28 06:19:25 +00:00
|
|
|
optionsGB->setEnabled(enabled);
|
2007-10-07 08:55:20 +00:00
|
|
|
extraED->setEnabled(enabled && !isBufferReadonly());
|
2007-09-05 20:33:29 +00:00
|
|
|
extraFormatCO->setEnabled(enabled);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
if (enabled) {
|
2007-09-05 20:33:29 +00:00
|
|
|
extraFormatCO->setCurrentIndex(0);
|
2008-04-18 19:17:11 +00:00
|
|
|
extraED->setText(extra_[extraFormatCO->currentText()]);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
void GuiExternal::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2010-04-21 01:19:30 +00:00
|
|
|
params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilePath()));
|
2007-10-07 08:55:20 +00:00
|
|
|
params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
params_.draft = draftCB->isChecked();
|
2008-04-18 20:14:20 +00:00
|
|
|
params_.lyxscale = displayscaleED->text().toInt();
|
2008-06-13 07:34:55 +00:00
|
|
|
params_.display = displayGB->isChecked();
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-04-28 06:19:25 +00:00
|
|
|
if (rotationGB->isEnabled())
|
2007-10-07 08:55:20 +00:00
|
|
|
getRotation(params_.rotationdata, *angleED, *originCO);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-04-28 06:19:25 +00:00
|
|
|
if (scaleGB->isEnabled())
|
2007-10-07 08:55:20 +00:00
|
|
|
getSize(params_.resizedata, *widthED, *widthUnitCO,
|
2009-01-14 15:47:25 +00:00
|
|
|
*heightED, *heightUnitCO, *aspectratioCB, usingScale());
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-04-28 06:19:25 +00:00
|
|
|
if (cropGB->isEnabled())
|
2007-10-07 08:55:20 +00:00
|
|
|
getCrop(params_.clipdata, *clipCB, *xlED, *ybED,
|
|
|
|
*xrED, *ytED, bbChanged_);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2008-04-28 06:19:25 +00:00
|
|
|
if (optionsGB->isEnabled()) {
|
2008-04-18 19:52:16 +00:00
|
|
|
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()));
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
bool GuiExternal::initialiseParams(string const & data)
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetExternal::string2params(data, buffer(), params_);
|
2007-10-07 08:55:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiExternal::clearParams()
|
|
|
|
{
|
|
|
|
params_ = InsetExternalParams();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 08:55:20 +00:00
|
|
|
|
|
|
|
void GuiExternal::dispatchParams()
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
string const lfun = InsetExternal::params2string(params_, buffer());
|
2007-10-07 08:55:20 +00:00
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-20 19:56:01 +00:00
|
|
|
static QStringList templateFilters(QString const & template_name)
|
2007-10-07 08:55:20 +00:00
|
|
|
{
|
|
|
|
/// Determine the template file extension
|
|
|
|
external::TemplateManager const & etm =
|
|
|
|
external::TemplateManager::get();
|
|
|
|
external::Template const * const et_ptr =
|
2008-04-20 19:56:01 +00:00
|
|
|
etm.getTemplateByName(fromqstr(template_name));
|
|
|
|
|
2011-09-13 21:49:52 +00:00
|
|
|
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));
|
2007-10-07 08:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
QString GuiExternal::browse(QString const & input,
|
|
|
|
QString const & template_name) const
|
2007-10-07 08:55:20 +00:00
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const title = qt_("Select external file");
|
2010-04-21 01:19:30 +00:00
|
|
|
QString const bufpath = bufferFilePath();
|
2008-04-20 19:56:01 +00:00
|
|
|
QStringList const filter = templateFilters(template_name);
|
2007-10-07 08:55:20 +00:00
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const label1 = qt_("Documents|#o#O");
|
|
|
|
QString const dir1 = toqstr(lyxrc.document_path);
|
2007-10-07 08:55:20 +00:00
|
|
|
|
2011-06-01 13:18:08 +00:00
|
|
|
return browseRelToParent(input, bufpath, title, filter, false, label1, dir1);
|
2007-10-07 08:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiExternal(GuiView & lv) { return new GuiExternal(lv); }
|
2007-10-07 08:55:20 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiExternal.cpp"
|