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
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "lengthcommon.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.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
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/convert.h"
|
2007-01-12 03:19:58 +00:00
|
|
|
#include "support/os.h"
|
2007-04-25 08:42:22 +00:00
|
|
|
#include "support/lyxlib.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiExternal.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
|
|
|
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QTextBrowser>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace external = lyx::external;
|
|
|
|
|
|
|
|
using lyx::support::isStrDbl;
|
|
|
|
using lyx::support::token;
|
|
|
|
using lyx::support::trim;
|
2007-04-25 08:42:22 +00:00
|
|
|
using lyx::support::float_equal;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-01-12 03:19:58 +00:00
|
|
|
using lyx::support::os::internal_path;
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using std::find;
|
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-25 08:42:22 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiExternalDialog
|
2007-04-25 08:42:22 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiExternalDialog::GuiExternalDialog(GuiExternal * form)
|
2007-04-25 08:42:22 +00:00
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-04-25 16:39:21 +00:00
|
|
|
connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
|
|
|
|
connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
|
|
|
|
connect(closePB, SIGNAL(clicked()), form, 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&)),
|
|
|
|
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()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(externalCO, SIGNAL(activated(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(templateChanged()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(extraED, SIGNAL(textChanged(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(extraChanged(const QString&)));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(extraFormatCO, SIGNAL(activated(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(formatChanged(const QString&)));
|
|
|
|
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()));
|
|
|
|
connect(displayCB, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(displayscaleED, SIGNAL(textChanged(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(angleED, SIGNAL(textChanged(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(widthED, SIGNAL(textChanged(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(sizeChanged()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(heightED, SIGNAL(textChanged(const QString &)),
|
2007-04-25 16:39:21 +00:00
|
|
|
this, SLOT(sizeChanged()));
|
2007-04-26 07:12:31 +00:00
|
|
|
connect(fileED, SIGNAL(textChanged(const 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-04-26 07:12:31 +00:00
|
|
|
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()));
|
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-03 20:28:26 +00:00
|
|
|
void GuiExternalDialog::showView()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
QDialog::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
bool GuiExternalDialog::activateAspectratio() const
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
if (widthUnitCO->currentIndex() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string const wstr = fromqstr(widthED->text());
|
|
|
|
if (wstr.empty())
|
|
|
|
return false;
|
|
|
|
bool const wIsDbl = isStrDbl(wstr);
|
|
|
|
if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
|
|
|
|
return false;
|
2007-04-28 12:58:49 +00:00
|
|
|
Length l;
|
2007-04-25 08:42:22 +00:00
|
|
|
if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
string const hstr = fromqstr(heightED->text());
|
|
|
|
if (hstr.empty())
|
|
|
|
return false;
|
|
|
|
bool const hIsDbl = isStrDbl(hstr);
|
|
|
|
if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
|
|
|
|
return false;
|
|
|
|
if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::bbChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
form_->controller().bbChanged(true);
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::browseClicked()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
int const choice = externalCO->currentIndex();
|
2007-05-28 22:27:45 +00:00
|
|
|
docstring const template_name =
|
2007-04-25 16:39:21 +00:00
|
|
|
from_utf8(form_->controller().getTemplate(choice).lyxName);
|
2007-04-25 08:42:22 +00:00
|
|
|
docstring const str =
|
|
|
|
form_->controller().browse(qstring_to_ucs4(fileED->text()),
|
|
|
|
template_name);
|
2007-09-02 08:19:43 +00:00
|
|
|
if (!str.empty()) {
|
2007-05-14 12:43:17 +00:00
|
|
|
fileED->setText(toqstr(str));
|
|
|
|
form_->changed();
|
|
|
|
}
|
2007-04-25 08:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::change_adaptor()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::closeEvent(QCloseEvent * e)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::editClicked()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
form_->controller().editExternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::extraChanged(const QString& text)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
std::string const format = fromqstr(extraFormatCO->currentText());
|
|
|
|
form_->extra_[format] = text;
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::formatChanged(const QString& format)
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
extraED->setText(form_->extra_[fromqstr(format)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::getbbClicked()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
form_->getBB();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::sizeChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
aspectratioCB->setEnabled(activateAspectratio());
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::templateChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
form_->updateTemplate();
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternalDialog::widthUnitChanged()
|
2007-04-25 08:42:22 +00:00
|
|
|
{
|
|
|
|
bool useHeight = (widthUnitCO->currentIndex() > 0);
|
|
|
|
|
|
|
|
if (useHeight)
|
|
|
|
widthED->setValidator(unsignedLengthValidator(widthED));
|
|
|
|
else
|
|
|
|
widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
|
|
|
|
|
|
|
|
heightED->setEnabled(useHeight);
|
|
|
|
heightUnitCO->setEnabled(useHeight);
|
|
|
|
form_->changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiExternal
|
2007-04-25 08:42:22 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::UNIT defaultUnit()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::UNIT default_unit = Length::CM;
|
2006-03-05 17:24:44 +00:00
|
|
|
switch (lyxrc.default_papersize) {
|
|
|
|
case PAPER_USLETTER:
|
|
|
|
case PAPER_USLEGAL:
|
|
|
|
case PAPER_USEXECUTIVE:
|
2007-04-28 12:58:49 +00:00
|
|
|
default_unit = Length::IN;
|
2006-03-05 17:24:44 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
showCO.setCurrentIndex(item);
|
2006-03-05 17:24:44 +00:00
|
|
|
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(toqstr(convert<string>(scale)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void getDisplay(external::DisplayType & display,
|
|
|
|
unsigned int & scale,
|
|
|
|
QCheckBox const & displayCB,
|
|
|
|
QComboBox const & showCO,
|
|
|
|
QLineEdit const & scaleED)
|
|
|
|
{
|
2006-08-17 08:54:12 +00:00
|
|
|
switch (showCO.currentIndex()) {
|
2006-03-05 17:24:44 +00:00
|
|
|
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 = convert<int>(fromqstr(scaleED.text()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setRotation(QLineEdit & angleED, QComboBox & originCO,
|
|
|
|
external::RotationData const & data)
|
|
|
|
{
|
2006-08-17 08:54:12 +00:00
|
|
|
originCO.setCurrentIndex(int(data.origin()));
|
2006-03-05 17:24:44 +00:00
|
|
|
angleED.setText(toqstr(data.angle));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void getRotation(external::RotationData & data,
|
|
|
|
QLineEdit const & angleED, QComboBox const & originCO)
|
|
|
|
{
|
|
|
|
typedef external::RotationData::OriginType OriginType;
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
data.origin(static_cast<OriginType>(originCO.currentIndex()));
|
2006-03-05 17:24:44 +00:00
|
|
|
data.angle = fromqstr(angleED.text());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (data.no_resize()) {
|
|
|
|
// Everything is zero, so default to this!
|
|
|
|
using_scale = true;
|
|
|
|
scale = "100";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (using_scale) {
|
|
|
|
widthED.setText(toqstr(scale));
|
2006-08-17 08:54:12 +00:00
|
|
|
widthUnitCO.setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
widthED.setText(toqstr(convert<string>(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.
|
2006-08-17 08:54:12 +00:00
|
|
|
widthUnitCO.setCurrentIndex(data.width.unit() + 1);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string const h = data.height.zero() ? string() : data.height.asString();
|
2007-04-28 12:58:49 +00:00
|
|
|
Length::UNIT default_unit = data.width.zero() ?
|
2006-03-05 17:24:44 +00:00
|
|
|
defaultUnit() : data.width.unit();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
if (widthUnitCO.currentIndex() > 0) {
|
2006-03-05 17:24:44 +00:00
|
|
|
// Subtract one, because scale is 0.
|
2006-08-17 08:54:12 +00:00
|
|
|
int const unit = widthUnitCO.currentIndex() - 1;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-28 12:58:49 +00:00
|
|
|
Length w;
|
2006-03-05 17:24:44 +00:00
|
|
|
if (isValidLength(width, &w))
|
|
|
|
data.width = w;
|
|
|
|
else if (isStrDbl(width))
|
2007-04-28 12:58:49 +00:00
|
|
|
data.width = Length(convert<double>(width),
|
|
|
|
static_cast<Length::UNIT>(unit));
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2007-04-28 12:58:49 +00:00
|
|
|
data.width = Length();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
data.scale = string();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// scaling instead of a width
|
|
|
|
data.scale = width;
|
2007-04-28 12:58:49 +00:00
|
|
|
data.width = Length();
|
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,
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void getExtra(external::ExtraData & data,
|
2007-08-31 05:53:55 +00:00
|
|
|
GuiExternal::MapType const & extra)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
typedef GuiExternal::MapType MapType;
|
2006-03-05 17:24:44 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
GuiExternal::GuiExternal(GuiDialog & parent)
|
2007-08-31 22:16:11 +00:00
|
|
|
: GuiView<GuiExternalDialog>(parent, _("External Material"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternal::build_dialog()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
dialog_.reset(new GuiExternalDialog(this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
|
|
|
bc().setCancel(dialog_->closePB);
|
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->fileED);
|
|
|
|
bc().addReadOnly(dialog_->browsePB);
|
|
|
|
bc().addReadOnly(dialog_->editPB);
|
|
|
|
bc().addReadOnly(dialog_->externalCO);
|
|
|
|
bc().addReadOnly(dialog_->draftCB);
|
|
|
|
bc().addReadOnly(dialog_->displayscaleED);
|
|
|
|
bc().addReadOnly(dialog_->showCO);
|
|
|
|
bc().addReadOnly(dialog_->displayCB);
|
|
|
|
bc().addReadOnly(dialog_->angleED);
|
|
|
|
bc().addReadOnly(dialog_->originCO);
|
|
|
|
bc().addReadOnly(dialog_->heightUnitCO);
|
|
|
|
bc().addReadOnly(dialog_->heightED);
|
|
|
|
bc().addReadOnly(dialog_->aspectratioCB);
|
|
|
|
bc().addReadOnly(dialog_->widthUnitCO);
|
|
|
|
bc().addReadOnly(dialog_->widthED);
|
|
|
|
bc().addReadOnly(dialog_->clipCB);
|
|
|
|
bc().addReadOnly(dialog_->getbbPB);
|
|
|
|
bc().addReadOnly(dialog_->ytED);
|
|
|
|
bc().addReadOnly(dialog_->xlED);
|
|
|
|
bc().addReadOnly(dialog_->xrED);
|
|
|
|
bc().addReadOnly(dialog_->ybED);
|
|
|
|
bc().addReadOnly(dialog_->extraFormatCO);
|
|
|
|
bc().addReadOnly(dialog_->extraED);
|
|
|
|
|
|
|
|
bc().addCheckedLineEdit(dialog_->angleED, dialog_->angleLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->displayscaleED, dialog_->scaleLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->heightED, dialog_->heightLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->widthED, dialog_->widthLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->xlED, dialog_->lbLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->ybED, dialog_->lbLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->xrED, dialog_->rtLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->ytED, dialog_->rtLA);
|
|
|
|
bc().addCheckedLineEdit(dialog_->fileED, dialog_->fileLA);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
std::vector<string> templates(controller().getTemplates());
|
|
|
|
|
|
|
|
for (std::vector<string>::const_iterator cit = templates.begin();
|
|
|
|
cit != templates.end(); ++cit) {
|
2007-06-23 07:50:13 +00:00
|
|
|
dialog_->externalCO->addItem(qt_(*cit));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->originCO->addItem(toqstr(external::origin_gui_str(i)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Fill the width combo
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->widthUnitCO->addItem(qt_("Scale%"));
|
2006-03-05 17:24:44 +00:00
|
|
|
for (int i = 0; i < num_units; i++)
|
2006-12-03 01:11:37 +00:00
|
|
|
dialog_->widthUnitCO->addItem(qt_(unit_name_gui[i]));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternal::update_contents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->tab->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
InsetExternalParams const & params = controller().params();
|
|
|
|
|
|
|
|
string const name =
|
|
|
|
params.filename.outputFilename(kernel().bufferFilepath());
|
|
|
|
dialog_->fileED->setText(toqstr(name));
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->externalCO->setCurrentIndex(
|
2006-03-05 17:24:44 +00:00
|
|
|
controller().getTemplateNumber(params.templatename()));
|
|
|
|
updateTemplate();
|
|
|
|
|
|
|
|
dialog_->draftCB->setChecked(params.draft);
|
|
|
|
|
|
|
|
setDisplay(*dialog_->displayCB, *dialog_->showCO,
|
|
|
|
*dialog_->displayscaleED,
|
|
|
|
params.display, params.lyxscale, readOnly());
|
|
|
|
|
|
|
|
setRotation(*dialog_->angleED, *dialog_->originCO, params.rotationdata);
|
|
|
|
|
|
|
|
setSize(*dialog_->widthED, *dialog_->widthUnitCO,
|
|
|
|
*dialog_->heightED, *dialog_->heightUnitCO,
|
|
|
|
*dialog_->aspectratioCB,
|
|
|
|
params.resizedata);
|
|
|
|
|
|
|
|
setCrop(*dialog_->clipCB,
|
|
|
|
*dialog_->xlED, *dialog_->ybED,
|
|
|
|
*dialog_->xrED, *dialog_->ytED,
|
|
|
|
params.clipdata);
|
|
|
|
controller().bbChanged(!params.clipdata.bbox.empty());
|
|
|
|
|
|
|
|
isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternal::updateTemplate()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
external::Template templ =
|
2006-08-17 08:54:12 +00:00
|
|
|
controller().getTemplate(dialog_->externalCO->currentIndex());
|
2007-06-23 07:50:13 +00:00
|
|
|
dialog_->externalTB->setPlainText(qt_(templ.helpText));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// Ascertain which (if any) transformations the template supports
|
|
|
|
// and disable tabs hosting unsupported transforms.
|
|
|
|
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();
|
|
|
|
|
|
|
|
bool found = find(tr_begin, tr_end, external::Rotate) != tr_end;
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->tab->setTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->rotatetab), found);
|
2006-03-05 17:24:44 +00:00
|
|
|
found = find(tr_begin, tr_end, external::Resize) != tr_end;
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->tab->setTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->scaletab), found);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
found = find(tr_begin, tr_end, external::Clip) != tr_end;
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->tab->setTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->croptab), found);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
found = find(tr_begin, tr_end, external::Extra) != tr_end;
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->tab->setTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->optionstab), found);
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
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;
|
|
|
|
string const opt = controller().params().extradata.get(format);
|
2006-08-17 08:54:12 +00:00
|
|
|
extraCB->addItem(toqstr(format));
|
2006-03-05 17:24:44 +00:00
|
|
|
extra_[format] = toqstr(opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool const enabled = extraCB->count() > 0;
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->tab->setTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->optionstab), enabled);
|
2006-03-05 17:24:44 +00:00
|
|
|
extraED->setEnabled(enabled && !kernel().isBufferReadonly());
|
|
|
|
extraCB->setEnabled(enabled);
|
|
|
|
|
|
|
|
if (enabled) {
|
2006-08-17 08:54:12 +00:00
|
|
|
extraCB->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
extraED->setText(extra_[fromqstr(extraCB->currentText())]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 20:28:26 +00:00
|
|
|
void GuiExternal::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
InsetExternalParams params = controller().params();
|
|
|
|
|
2007-01-18 20:47:27 +00:00
|
|
|
params.filename.set(internal_path(fromqstr(dialog_->fileED->text())),
|
2006-03-05 17:24:44 +00:00
|
|
|
kernel().bufferFilepath());
|
|
|
|
|
|
|
|
params.settemplate(controller().getTemplate(
|
2006-08-17 08:54:12 +00:00
|
|
|
dialog_->externalCO->currentIndex()).lyxName);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
params.draft = dialog_->draftCB->isChecked();
|
|
|
|
|
|
|
|
getDisplay(params.display, params.lyxscale,
|
|
|
|
*dialog_->displayCB, *dialog_->showCO,
|
|
|
|
*dialog_->displayscaleED);
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
if (dialog_->tab->isTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->rotatetab)))
|
2006-03-05 17:24:44 +00:00
|
|
|
getRotation(params.rotationdata,
|
|
|
|
*dialog_->angleED, *dialog_->originCO);
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
if (dialog_->tab->isTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->scaletab)))
|
2006-03-05 17:24:44 +00:00
|
|
|
getSize(params.resizedata,
|
|
|
|
*dialog_->widthED, *dialog_->widthUnitCO,
|
|
|
|
*dialog_->heightED, *dialog_->heightUnitCO,
|
|
|
|
*dialog_->aspectratioCB);
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
if (dialog_->tab->isTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->croptab)))
|
2006-03-05 17:24:44 +00:00
|
|
|
getCrop(params.clipdata,
|
|
|
|
*dialog_->clipCB,
|
|
|
|
*dialog_->xlED, *dialog_->ybED,
|
|
|
|
*dialog_->xrED, *dialog_->ytED,
|
|
|
|
controller().bbChanged());
|
|
|
|
|
2006-08-17 08:54:12 +00:00
|
|
|
if (dialog_->tab->isTabEnabled(
|
|
|
|
dialog_->tab->indexOf(dialog_->optionstab)))
|
2006-03-05 17:24:44 +00:00
|
|
|
getExtra(params.extradata, extra_);
|
|
|
|
|
|
|
|
controller().setParams(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiExternal::getBB()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
dialog_->xlED->setText("0");
|
|
|
|
dialog_->ybED->setText("0");
|
|
|
|
dialog_->xrED->setText("0");
|
|
|
|
dialog_->ytED->setText("0");
|
|
|
|
|
|
|
|
string const filename = fromqstr(dialog_->fileED->text());
|
|
|
|
if (filename.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
string const bb = controller().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)));
|
|
|
|
|
|
|
|
controller().bbChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-25 08:42:22 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiExternal_moc.cpp"
|