2006-03-05 17:24:44 +00:00
|
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
|
* \file GuiGraphics.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 Edwin Leuven
|
|
|
|
|
* \author Herbert Vo<EFBFBD>
|
2007-04-05 14:58:15 +00:00
|
|
|
|
* \author Richard Heck
|
2006-03-05 17:24:44 +00:00
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
|
#include "GuiGraphics.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
#include "ControlGraphics.h"
|
2007-08-31 22:16:11 +00:00
|
|
|
|
#include "debug.h"
|
2007-04-26 03:53:02 +00:00
|
|
|
|
#include "LengthCombo.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#include "lengthcommon.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "LyXRC.h"
|
2007-08-31 22:16:11 +00:00
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
#include "Validator.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-25 17:53:54 +00:00
|
|
|
|
#include "controllers/frontend_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetGraphicsParams.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
#include "support/lyxlib.h"
|
2007-01-12 03:19:58 +00:00
|
|
|
|
#include "support/os.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-11-03 11:24:27 +00:00
|
|
|
|
#include <QCheckBox>
|
2007-08-31 22:16:11 +00:00
|
|
|
|
#include <QCloseEvent>
|
2006-11-03 11:24:27 +00:00
|
|
|
|
#include <QLabel>
|
2007-08-31 22:16:11 +00:00
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QValidator>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cmath>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
using lyx::support::float_equal;
|
|
|
|
|
using lyx::support::token;
|
|
|
|
|
|
2007-01-12 03:19:58 +00:00
|
|
|
|
using lyx::support::os::internal_path;
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
|
using std::floor;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
|
template<class Pair>
|
|
|
|
|
std::vector<typename Pair::first_type> const
|
|
|
|
|
getFirst(std::vector<Pair> const & pr)
|
|
|
|
|
{
|
|
|
|
|
std::vector<typename Pair::first_type> tmp(pr.size());
|
|
|
|
|
std::transform(pr.begin(), pr.end(), tmp.begin(),
|
|
|
|
|
boost::bind(&Pair::first, _1));
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
GuiGraphicsDialog::GuiGraphicsDialog(LyXView & lv)
|
|
|
|
|
: GuiDialog(lv, "graphics")
|
2007-08-31 22:16:11 +00:00
|
|
|
|
{
|
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
setViewTitle(_("Graphics"));
|
|
|
|
|
setController(new ControlGraphics(*this));
|
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
|
//main buttons
|
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()));
|
|
|
|
|
connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
|
|
|
|
//graphics pane
|
|
|
|
|
connect(filename, SIGNAL(textChanged(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(WidthCB, SIGNAL( clicked()),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(HeightCB, SIGNAL( clicked()),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(Width, SIGNAL(textChanged(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(Height, SIGNAL(textChanged(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(aspectratio, SIGNAL(stateChanged(int)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(angle, SIGNAL(textChanged(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(origin, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(scaleCB, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(Scale, SIGNAL(textChanged(const QString &)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(rotateOrderCB, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
|
|
filename->setValidator(new PathValidator(true, filename));
|
|
|
|
|
setFocusProxy(filename);
|
|
|
|
|
|
|
|
|
|
QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
|
|
|
|
|
scaleValidator->setBottom(0);
|
|
|
|
|
scaleValidator->setDecimals(256); //I guess that will do
|
|
|
|
|
Scale->setValidator(scaleValidator);
|
|
|
|
|
Height->setValidator(unsignedLengthAutoValidator(Height));
|
|
|
|
|
Width->setValidator(unsignedLengthAutoValidator(Width));
|
|
|
|
|
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
|
|
|
|
|
|
|
|
|
|
//clipping pane
|
|
|
|
|
connect(clip, SIGNAL(stateChanged(int)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(lbY, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(lbYunit, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(rtY, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(rtYunit, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(lbX, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(lbXunit, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(rtX, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(rtXunit, SIGNAL(activated(int)),
|
|
|
|
|
this, SLOT(change_bb()));
|
|
|
|
|
connect(getPB, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
|
|
|
|
|
lbX->setValidator(new QDoubleValidator(lbX));
|
|
|
|
|
lbY->setValidator(new QDoubleValidator(lbY));
|
|
|
|
|
rtX->setValidator(new QDoubleValidator(rtX));
|
|
|
|
|
rtY->setValidator(new QDoubleValidator(rtY));
|
|
|
|
|
|
|
|
|
|
//extra options pane
|
|
|
|
|
connect(latexoptions, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(draftCB, SIGNAL(stateChanged(int)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(unzipCB, SIGNAL(stateChanged(int)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
// FIXME: we should connect to clicked() when we move to Qt 4.2 because
|
|
|
|
|
// the toggled(bool) signal is also trigged when we update the widgets
|
|
|
|
|
// (rgh-4/07) this isn't as much or a problem as it was, because we're now
|
|
|
|
|
// using blockSignals() to keep from triggering that signal when we call
|
|
|
|
|
// setChecked(). Note, too, that clicked() would get called whenever it
|
|
|
|
|
// is clicked, even right clicked (I think), not just whenever it is
|
|
|
|
|
// toggled.
|
|
|
|
|
connect(subfigure, SIGNAL(toggled(bool)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(subcaption, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(displayGB, SIGNAL(toggled(bool)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(showCB, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
connect(displayscale, SIGNAL(textChanged(const QString&)),
|
|
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
|
displayscale->setValidator(new QIntValidator(displayscale));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
|
|
|
|
bc().setOK(okPB);
|
|
|
|
|
bc().setApply(applyPB);
|
|
|
|
|
bc().setRestore(restorePB);
|
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
|
|
|
|
|
|
bc().addReadOnly(latexoptions);
|
|
|
|
|
bc().addReadOnly(subfigure);
|
|
|
|
|
bc().addReadOnly(filenameL);
|
|
|
|
|
bc().addReadOnly(filename);
|
|
|
|
|
bc().addReadOnly(browsePB);
|
|
|
|
|
bc().addReadOnly(unzipCB);
|
|
|
|
|
bc().addReadOnly(bbFrame);
|
|
|
|
|
bc().addReadOnly(draftCB);
|
|
|
|
|
bc().addReadOnly(clip);
|
|
|
|
|
bc().addReadOnly(unzipCB);
|
|
|
|
|
bc().addReadOnly(displayGB);
|
|
|
|
|
bc().addReadOnly(sizeGB);
|
|
|
|
|
bc().addReadOnly(rotationGB);
|
|
|
|
|
bc().addReadOnly(latexoptions);
|
|
|
|
|
bc().addReadOnly(getPB);
|
|
|
|
|
bc().addReadOnly(rotateOrderCB);
|
|
|
|
|
|
|
|
|
|
// initialize the length validator
|
|
|
|
|
bc().addCheckedLineEdit(Scale, scaleCB);
|
|
|
|
|
bc().addCheckedLineEdit(Width, WidthCB);
|
|
|
|
|
bc().addCheckedLineEdit(Height, HeightCB);
|
|
|
|
|
bc().addCheckedLineEdit(displayscale, scaleLA);
|
|
|
|
|
bc().addCheckedLineEdit(angle, angleL);
|
|
|
|
|
bc().addCheckedLineEdit(lbX, xL);
|
|
|
|
|
bc().addCheckedLineEdit(lbY, yL);
|
|
|
|
|
bc().addCheckedLineEdit(rtX, xL_2);
|
|
|
|
|
bc().addCheckedLineEdit(rtY, yL_2);
|
|
|
|
|
bc().addCheckedLineEdit(filename, filenameL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ControlGraphics & GuiGraphicsDialog::controller() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<ControlGraphics &>(GuiDialog::controller());
|
2007-08-31 22:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::change_adaptor()
|
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::change_bb()
|
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
controller().bbChanged = true;
|
2007-08-31 22:16:11 +00:00
|
|
|
|
LYXERR(Debug::GRAPHICS)
|
|
|
|
|
<< "[controller().bb_Changed set to true]\n";
|
2007-09-05 20:33:29 +00:00
|
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::closeEvent(QCloseEvent * e)
|
|
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
|
slotClose();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
e->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::on_browsePB_clicked()
|
|
|
|
|
{
|
|
|
|
|
docstring const str =
|
2007-09-05 20:33:29 +00:00
|
|
|
|
controller().browse(qstring_to_ucs4(filename->text()));
|
2007-08-31 22:16:11 +00:00
|
|
|
|
if(!str.empty()){
|
|
|
|
|
filename->setText(toqstr(str));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::on_getPB_clicked()
|
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
getBB();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::on_editPB_clicked()
|
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
controller().editGraphics();
|
2007-08-31 22:16:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::on_filename_textChanged(const QString & filename)
|
|
|
|
|
{
|
|
|
|
|
editPB->setDisabled(filename.isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::setAutoText()
|
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
if (scaleCB->isChecked())
|
|
|
|
|
return;
|
2007-08-31 22:16:11 +00:00
|
|
|
|
if (!Scale->isEnabled() && Scale->text() != "100")
|
|
|
|
|
Scale->setText(QString("auto"));
|
|
|
|
|
|
|
|
|
|
setAutoTextCB(WidthCB, Width, widthUnit);
|
|
|
|
|
setAutoTextCB(HeightCB, Height, heightUnit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::on_scaleCB_toggled(bool setScale)
|
|
|
|
|
{
|
|
|
|
|
Scale->setEnabled(setScale);
|
|
|
|
|
if (setScale) {
|
|
|
|
|
Scale->setText("100");
|
|
|
|
|
Scale->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WidthCB->setDisabled(setScale);
|
|
|
|
|
WidthCB->blockSignals(true);
|
|
|
|
|
WidthCB->setChecked(false);
|
|
|
|
|
WidthCB->blockSignals(false);
|
|
|
|
|
Width->setEnabled(false);
|
|
|
|
|
widthUnit->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
HeightCB->setDisabled(setScale);
|
|
|
|
|
HeightCB->blockSignals(true);
|
|
|
|
|
HeightCB->setChecked(false);
|
|
|
|
|
HeightCB->blockSignals(false);
|
|
|
|
|
Height->setEnabled(false);
|
|
|
|
|
heightUnit->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
aspectratio->setDisabled(true);
|
|
|
|
|
aspectratio->setChecked(true);
|
|
|
|
|
|
|
|
|
|
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
|
|
|
|
|
HeightCB->isChecked() ||
|
|
|
|
|
scaleCB->isChecked()) &&
|
|
|
|
|
(angle->text() != "0"));
|
|
|
|
|
|
|
|
|
|
setAutoText();
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
|
void GuiGraphicsDialog::on_WidthCB_toggled(bool setWidth)
|
|
|
|
|
{
|
|
|
|
|
Width->setEnabled(setWidth);
|
|
|
|
|
widthUnit->setEnabled(setWidth);
|
|
|
|
|
if (setWidth)
|
|
|
|
|
Width->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
|
|
bool const setHeight = HeightCB->isChecked();
|
|
|
|
|
aspectratio->setEnabled(setWidth && setHeight);
|
|
|
|
|
aspectratio->blockSignals(true);
|
|
|
|
|
aspectratio->setChecked(!(setWidth && setHeight));
|
|
|
|
|
aspectratio->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
scaleCB->setEnabled(!setWidth && !setHeight);
|
|
|
|
|
//already will be unchecked, so don't need to do that
|
|
|
|
|
Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
|
|
|
|
|
&& scaleCB->isChecked()); //should be false, but let's check
|
|
|
|
|
rotateOrderCB->setEnabled((setWidth || setHeight ||
|
|
|
|
|
scaleCB->isChecked()) &&
|
|
|
|
|
(angle->text() != "0"));
|
|
|
|
|
|
|
|
|
|
setAutoText();
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 08:19:43 +00:00
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
|
void GuiGraphicsDialog::on_HeightCB_toggled(bool setHeight)
|
|
|
|
|
{
|
|
|
|
|
Height->setEnabled(setHeight);
|
|
|
|
|
heightUnit->setEnabled(setHeight);
|
|
|
|
|
if (setHeight)
|
|
|
|
|
Height->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
|
|
bool const setWidth = WidthCB->isChecked();
|
|
|
|
|
aspectratio->setEnabled(setWidth && setHeight);
|
|
|
|
|
aspectratio->blockSignals(true);
|
|
|
|
|
aspectratio->setChecked(!(setWidth && setHeight));
|
|
|
|
|
aspectratio->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
scaleCB->setEnabled(!setWidth && !setHeight);
|
|
|
|
|
//already unchecked
|
|
|
|
|
Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
|
|
|
|
|
&& scaleCB->isChecked()); //should be false
|
|
|
|
|
rotateOrderCB->setEnabled((setWidth || setHeight ||
|
|
|
|
|
scaleCB->isChecked()) &&
|
|
|
|
|
(angle->text() != "0"));
|
|
|
|
|
|
|
|
|
|
setAutoText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphicsDialog::on_angle_textChanged(const QString & filename)
|
|
|
|
|
{
|
|
|
|
|
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
|
|
|
|
|
HeightCB->isChecked() ||
|
|
|
|
|
scaleCB->isChecked()) &&
|
|
|
|
|
(filename != "0"));
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
// returns the number of the string s in the vector v
|
2007-09-02 08:19:43 +00:00
|
|
|
|
static int getItemNo(const vector<string> & v, string const & s)
|
|
|
|
|
{
|
2006-03-05 17:24:44 +00:00
|
|
|
|
vector<string>::const_iterator cit =
|
|
|
|
|
find(v.begin(), v.end(), s);
|
|
|
|
|
return (cit != v.end()) ? int(cit - v.begin()) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
void GuiGraphicsDialog::update_contents()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
// clear and fill in the comboboxes
|
2006-10-21 00:16:43 +00:00
|
|
|
|
vector<string> const bb_units = frontend::getBBUnits();
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbXunit->clear();
|
|
|
|
|
lbYunit->clear();
|
|
|
|
|
rtXunit->clear();
|
|
|
|
|
rtYunit->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
for (vector<string>::const_iterator it = bb_units.begin();
|
|
|
|
|
it != bb_units.end(); ++it) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbXunit->addItem(toqstr(*it));
|
|
|
|
|
lbYunit->addItem(toqstr(*it));
|
|
|
|
|
rtXunit->addItem(toqstr(*it));
|
|
|
|
|
rtYunit->addItem(toqstr(*it));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InsetGraphicsParams & igp = controller().params();
|
|
|
|
|
|
|
|
|
|
// set the right default unit
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length::UNIT unitDefault = 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
|
|
|
|
unitDefault = Length::IN;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string const name =
|
2007-09-10 22:32:59 +00:00
|
|
|
|
igp.filename.outputFilename(controller().bufferFilepath());
|
2007-09-05 20:33:29 +00:00
|
|
|
|
filename->setText(toqstr(name));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// set the bounding box values
|
|
|
|
|
if (igp.bb.empty()) {
|
|
|
|
|
string const bb = controller().readBB(igp.filename.absFilename());
|
|
|
|
|
// the values from the file always have the bigpoint-unit bp
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbX->setText(toqstr(token(bb, ' ', 0)));
|
|
|
|
|
lbY->setText(toqstr(token(bb, ' ', 1)));
|
|
|
|
|
rtX->setText(toqstr(token(bb, ' ', 2)));
|
|
|
|
|
rtY->setText(toqstr(token(bb, ' ', 3)));
|
|
|
|
|
lbXunit->setCurrentIndex(0);
|
|
|
|
|
lbYunit->setCurrentIndex(0);
|
|
|
|
|
rtXunit->setCurrentIndex(0);
|
|
|
|
|
rtYunit->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
controller().bbChanged = false;
|
|
|
|
|
} else {
|
|
|
|
|
// get the values from the inset
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length anyLength;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
string const xl(token(igp.bb, ' ', 0));
|
|
|
|
|
string const yl(token(igp.bb, ' ', 1));
|
|
|
|
|
string const xr(token(igp.bb, ' ', 2));
|
|
|
|
|
string const yr(token(igp.bb, ' ', 3));
|
|
|
|
|
if (isValidLength(xl, &anyLength)) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbX->setText(toqstr(convert<string>(anyLength.value())));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} else {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbX->setText(toqstr(xl));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
if (isValidLength(yl, &anyLength)) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbY->setText(toqstr(convert<string>(anyLength.value())));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} else {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbY->setText(toqstr(xl));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
if (isValidLength(xr, &anyLength)) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rtX->setText(toqstr(convert<string>(anyLength.value())));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} else {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rtX->setText(toqstr(xl));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
if (isValidLength(yr, &anyLength)) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rtY->setText(toqstr(convert<string>(anyLength.value())));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
string const unit(unit_name[anyLength.unit()]);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} else {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rtY->setText(toqstr(xl));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
controller().bbChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the draft and clip mode
|
2007-09-05 20:33:29 +00:00
|
|
|
|
draftCB->setChecked(igp.draft);
|
|
|
|
|
clip->setChecked(igp.clip);
|
|
|
|
|
unzipCB->setChecked(igp.noUnzip);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// Update the subcaption check button and input field
|
2007-09-05 20:33:29 +00:00
|
|
|
|
subfigure->setChecked(igp.subcaption);
|
|
|
|
|
subcaption->setText(toqstr(igp.subcaptionText));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
int item = 0;
|
|
|
|
|
switch (igp.display) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
case graphics::DefaultDisplay: item = 0; break;
|
|
|
|
|
case graphics::MonochromeDisplay: item = 1; break;
|
|
|
|
|
case graphics::GrayscaleDisplay: item = 2; break;
|
|
|
|
|
case graphics::ColorDisplay: item = 3; break;
|
|
|
|
|
case graphics::NoDisplay: item = 0; break;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
2007-09-05 20:33:29 +00:00
|
|
|
|
showCB->setCurrentIndex(item);
|
|
|
|
|
displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
|
|
|
|
|
displayGB->setChecked(igp.display != graphics::NoDisplay);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-11-03 11:24:27 +00:00
|
|
|
|
// the output section (width/height)
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
Scale->setText(toqstr(igp.scale));
|
2007-04-05 14:58:15 +00:00
|
|
|
|
//igp.scale defaults to 100, so we treat it as empty
|
|
|
|
|
bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
|
2007-09-05 20:33:29 +00:00
|
|
|
|
scaleCB->blockSignals(true);
|
|
|
|
|
scaleCB->setChecked(scaleChecked);
|
|
|
|
|
scaleCB->blockSignals(false);
|
|
|
|
|
Scale->setEnabled(scaleChecked);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lengthAutoToWidgets(Width, widthUnit, igp.width,
|
2007-04-05 14:58:15 +00:00
|
|
|
|
unitDefault);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bool const widthChecked = !Width->text().isEmpty() &&
|
|
|
|
|
Width->text() != "auto";
|
|
|
|
|
WidthCB->blockSignals(true);
|
|
|
|
|
WidthCB->setChecked(widthChecked);
|
|
|
|
|
WidthCB->blockSignals(false);
|
|
|
|
|
Width->setEnabled(widthChecked);
|
|
|
|
|
widthUnit->setEnabled(widthChecked);
|
|
|
|
|
|
|
|
|
|
lengthAutoToWidgets(Height, heightUnit, igp.height,
|
2007-04-05 14:58:15 +00:00
|
|
|
|
unitDefault);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bool const heightChecked = !Height->text().isEmpty()
|
|
|
|
|
&& Height->text() != "auto";
|
|
|
|
|
HeightCB->blockSignals(true);
|
|
|
|
|
HeightCB->setChecked(heightChecked);
|
|
|
|
|
HeightCB->blockSignals(false);
|
|
|
|
|
Height->setEnabled(heightChecked);
|
|
|
|
|
heightUnit->setEnabled(heightChecked);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
scaleCB->setEnabled(!widthChecked && !heightChecked);
|
|
|
|
|
WidthCB->setEnabled(!scaleChecked);
|
|
|
|
|
HeightCB->setEnabled(!scaleChecked);
|
|
|
|
|
aspectratio->setEnabled(widthChecked && heightChecked);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
setAutoText();
|
2006-11-03 11:24:27 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
angle->setText(toqstr(igp.rotateAngle));
|
|
|
|
|
rotateOrderCB->setChecked(igp.scaleBeforeRotation);
|
2007-06-25 13:49:51 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
|
|
|
|
|
&& igp.rotateAngle != "0");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
origin->clear();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
vector<RotationOriginPair> origindata = getRotationOriginData();
|
2006-12-22 10:06:40 +00:00
|
|
|
|
vector<docstring> const origin_lang = getFirst(origindata);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
origin_ltx = getSecond(origindata);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-12-22 10:06:40 +00:00
|
|
|
|
for (vector<docstring>::const_iterator it = origin_lang.begin();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
it != origin_lang.end(); ++it)
|
2007-09-05 20:33:29 +00:00
|
|
|
|
origin->addItem(toqstr(*it));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
if (!igp.rotateOrigin.empty())
|
2007-09-05 20:33:29 +00:00
|
|
|
|
origin->setCurrentIndex(
|
2006-03-05 17:24:44 +00:00
|
|
|
|
getItemNo(origin_ltx, igp.rotateOrigin));
|
|
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
|
origin->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2006-04-06 21:04:27 +00:00
|
|
|
|
// disable edit button when no filename is present
|
2007-09-05 20:33:29 +00:00
|
|
|
|
editPB->setDisabled(filename->text().isEmpty());
|
2006-04-06 21:04:27 +00:00
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
//// latex section
|
2007-09-05 20:33:29 +00:00
|
|
|
|
latexoptions->setText(toqstr(igp.special));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
void GuiGraphicsDialog::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
InsetGraphicsParams & igp = controller().params();
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.filename.set(internal_path(fromqstr(filename->text())),
|
2007-09-10 22:32:59 +00:00
|
|
|
|
controller().bufferFilepath());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
// the bb section
|
|
|
|
|
igp.bb.erase();
|
|
|
|
|
if (controller().bbChanged) {
|
|
|
|
|
string bb;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
string lbXs = fromqstr(lbX->text());
|
|
|
|
|
string lbYs = fromqstr(lbY->text());
|
|
|
|
|
string rtXs = fromqstr(rtX->text());
|
|
|
|
|
string rtYs = fromqstr(rtY->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
int bb_sum =
|
2007-09-05 20:33:29 +00:00
|
|
|
|
convert<int>(lbXs) + convert<int>(lbYs) +
|
|
|
|
|
convert<int>(rtXs) + convert<int>(rtXs);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (bb_sum) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
if (lbXs.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
|
bb = "0 ";
|
|
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
|
|
|
|
|
if (lbYs.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
|
bb += "0 ";
|
|
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
|
|
|
|
|
if (rtXs.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
|
bb += "0 ";
|
|
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
|
|
|
|
|
if (rtYs.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
|
bb += '0';
|
|
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bb += (rtYs + fromqstr(rtYunit->currentText()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
igp.bb = bb;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.draft = draftCB->isChecked();
|
|
|
|
|
igp.clip = clip->isChecked();
|
|
|
|
|
igp.subcaption = subfigure->isChecked();
|
|
|
|
|
igp.subcaptionText = fromqstr(subcaption->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
switch (showCB->currentIndex()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
case 0: igp.display = graphics::DefaultDisplay; break;
|
|
|
|
|
case 1: igp.display = graphics::MonochromeDisplay; break;
|
|
|
|
|
case 2: igp.display = graphics::GrayscaleDisplay; break;
|
|
|
|
|
case 3: igp.display = graphics::ColorDisplay; break;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
default:;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
if (!displayGB->isChecked())
|
2006-10-21 00:16:43 +00:00
|
|
|
|
igp.display = graphics::NoDisplay;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
|
2007-04-05 14:58:15 +00:00
|
|
|
|
//the graphics section
|
2007-09-05 20:33:29 +00:00
|
|
|
|
if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
|
|
|
|
|
igp.scale = fromqstr(Scale->text());
|
2007-04-28 12:58:49 +00:00
|
|
|
|
igp.width = Length("0pt");
|
|
|
|
|
igp.height = Length("0pt");
|
2007-04-05 14:58:15 +00:00
|
|
|
|
igp.keepAspectRatio = false;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
} else {
|
2006-11-03 11:24:27 +00:00
|
|
|
|
igp.scale = string();
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.width = WidthCB->isChecked() ?
|
|
|
|
|
//Note that this works even if Width is "auto", since in
|
2007-04-05 14:58:15 +00:00
|
|
|
|
//that case we get "0pt".
|
2007-09-05 20:33:29 +00:00
|
|
|
|
Length(widgetsToLength(Width, widthUnit)):
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length("0pt");
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.height = HeightCB->isChecked() ?
|
|
|
|
|
Length(widgetsToLength(Height, heightUnit)) :
|
2007-04-28 12:58:49 +00:00
|
|
|
|
Length("0pt");
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.keepAspectRatio = aspectratio->isEnabled() &&
|
|
|
|
|
aspectratio->isChecked() &&
|
2007-04-05 14:58:15 +00:00
|
|
|
|
igp.width.value() > 0 && igp.height.value() > 0;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
2006-11-03 11:24:27 +00:00
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.noUnzip = unzipCB->isChecked();
|
|
|
|
|
igp.lyxscale = displayscale->text().toInt();
|
|
|
|
|
igp.rotateAngle = fromqstr(angle->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
|
double rotAngle = convert<double>(igp.rotateAngle);
|
|
|
|
|
if (std::abs(rotAngle) > 360.0) {
|
|
|
|
|
rotAngle -= 360.0 * floor(rotAngle / 360.0);
|
|
|
|
|
igp.rotateAngle = convert<string>(rotAngle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// save the latex name for the origin. If it is the default
|
|
|
|
|
// then origin_ltx returns ""
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.rotateOrigin = origin_ltx[origin->currentIndex()];
|
|
|
|
|
igp.scaleBeforeRotation = rotateOrderCB->isChecked();
|
2007-06-25 13:49:51 +00:00
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
// more latex options
|
2007-09-05 20:33:29 +00:00
|
|
|
|
igp.special = fromqstr(latexoptions->text());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
void GuiGraphicsDialog::getBB()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
string const fn = fromqstr(filename->text());
|
|
|
|
|
if (!fn.empty()) {
|
|
|
|
|
string const bb = controller().readBB(fn);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
if (!bb.empty()) {
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbX->setText(toqstr(token(bb, ' ', 0)));
|
|
|
|
|
lbY->setText(toqstr(token(bb, ' ', 1)));
|
|
|
|
|
rtX->setText(toqstr(token(bb, ' ', 2)));
|
|
|
|
|
rtY->setText(toqstr(token(bb, ' ', 3)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
// the default units for the bb values when reading
|
|
|
|
|
// it from the file
|
2007-09-05 20:33:29 +00:00
|
|
|
|
lbXunit->setCurrentIndex(0);
|
|
|
|
|
lbYunit->setCurrentIndex(0);
|
|
|
|
|
rtXunit->setCurrentIndex(0);
|
|
|
|
|
rtYunit->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
controller().bbChanged = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
bool GuiGraphicsDialog::isValid()
|
2006-03-05 17:24:44 +00:00
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
|
return !filename->text().isEmpty();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "GuiGraphics_moc.cpp"
|
|
|
|
|
|