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.
|
|
|
|
*
|
2007-10-06 22:16:14 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author John Levon
|
|
|
|
* \author Edwin Leuven
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Herbert Voß
|
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"
|
2009-01-16 14:54:25 +00:00
|
|
|
#include "frontends/alert.h"
|
2007-08-31 22:16:11 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
#include "Validator.h"
|
2007-10-06 22:16:14 +00:00
|
|
|
|
2008-09-23 21:57:23 +00:00
|
|
|
#include "Buffer.h"
|
2007-10-06 22:16:14 +00:00
|
|
|
#include "FuncRequest.h"
|
2008-09-23 21:57:23 +00:00
|
|
|
#include "LengthCombo.h"
|
|
|
|
#include "Length.h"
|
|
|
|
#include "LyXRC.h"
|
2007-10-06 22:16:14 +00:00
|
|
|
|
2012-02-15 20:50:52 +00:00
|
|
|
#include "graphics/epstools.h"
|
2007-10-06 22:16:14 +00:00
|
|
|
#include "graphics/GraphicsCache.h"
|
|
|
|
#include "graphics/GraphicsCacheItem.h"
|
|
|
|
#include "graphics/GraphicsImage.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-06 15:18:50 +00:00
|
|
|
#include "insets/InsetGraphics.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
#include "support/convert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-10-06 22:16:14 +00:00
|
|
|
#include "support/filetools.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-01-12 03:19:58 +00:00
|
|
|
#include "support/os.h"
|
2007-10-06 22:16:14 +00:00
|
|
|
#include "support/Package.h"
|
|
|
|
#include "support/types.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-11-03 11:24:27 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#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 <cmath>
|
2007-09-15 15:42:22 +00:00
|
|
|
#include <utility>
|
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-10-06 22:16:14 +00:00
|
|
|
|
2008-04-18 18:53:43 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// These are the strings that are stored in the LyX file and which
|
|
|
|
// correspond to the LaTeX identifiers shown in the comments at the
|
|
|
|
// end of each line.
|
|
|
|
char const * const rorigin_lyx_strs[] = {
|
|
|
|
// the LaTeX default is leftBaseline
|
|
|
|
"",
|
|
|
|
"leftTop", "leftBottom", "leftBaseline", // lt lb lB
|
|
|
|
"center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
|
|
|
|
"rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
|
|
|
|
|
|
|
|
// These are the strings, corresponding to the above, that the GUI should
|
|
|
|
// use. Note that they can/should be translated.
|
|
|
|
char const * const rorigin_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") };
|
|
|
|
|
|
|
|
size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
|
|
|
|
|
2013-10-07 22:59:05 +00:00
|
|
|
static string const autostr = N_("automatically");
|
2009-01-14 17:53:31 +00:00
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2008-04-18 18:53:43 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-09-15 15:42:22 +00:00
|
|
|
//FIXME setAutoTextCB should really take an argument, as indicated, that
|
|
|
|
//determines what text is to be written for "auto". But making
|
|
|
|
//that work involves more extensive revisions than we now want
|
2008-05-06 15:18:50 +00:00
|
|
|
//to make, since "auto" also appears in paramsToDialog().
|
2007-09-15 15:42:22 +00:00
|
|
|
//The right way to do this, I think, would be to define a class
|
|
|
|
//checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
|
|
|
|
//the checkbox, line edit, and length combo together, and then made e.g.
|
|
|
|
//lengthToWidgets, widgetsToLength, etc, all public methods of that class.
|
|
|
|
//Perhaps even the validator could be exposed through it.
|
|
|
|
/**
|
|
|
|
* sets a checkbox-line edit-length combo group, using "text" if the
|
|
|
|
* checkbox is unchecked and clearing the line edit if it previously
|
|
|
|
* said "text".
|
|
|
|
*/
|
2007-11-05 22:20:23 +00:00
|
|
|
static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
|
2007-09-15 15:42:22 +00:00
|
|
|
LengthCombo * lengthCombo/*, string text = "auto"*/)
|
|
|
|
{
|
|
|
|
if (!checkBox->isChecked())
|
|
|
|
lengthToWidgets(lineEdit, lengthCombo,
|
2009-01-14 17:53:31 +00:00
|
|
|
_(autostr), lengthCombo->currentLengthItem());
|
|
|
|
else if (lineEdit->text() == qt_(autostr))
|
2007-09-15 15:42:22 +00:00
|
|
|
lengthToWidgets(lineEdit, lengthCombo, string(),
|
|
|
|
lengthCombo->currentLengthItem());
|
|
|
|
}
|
|
|
|
|
2008-03-08 08:20:36 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiGraphics::GuiGraphics(GuiView & lv)
|
2016-06-12 03:39:45 +00:00
|
|
|
: GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
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()));
|
2009-01-13 21:09:47 +00:00
|
|
|
connect(WidthCB, SIGNAL(clicked()),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2009-01-13 21:09:47 +00:00
|
|
|
connect(HeightCB, SIGNAL(clicked()),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2015-01-04 09:05:42 +00:00
|
|
|
connect(Width, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updateAspectRatioStatus()));
|
2007-08-31 22:16:11 +00:00
|
|
|
connect(Width, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2015-01-04 09:05:42 +00:00
|
|
|
connect(Height, SIGNAL(textChanged(const QString &)),
|
|
|
|
this, SLOT(updateAspectRatioStatus()));
|
2007-08-31 22:16:11 +00:00
|
|
|
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));
|
2009-11-06 15:56:15 +00:00
|
|
|
setFocusProxy(filename);
|
2007-08-31 22:16:11 +00:00
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
QDoubleValidator * scaleValidator =
|
2009-01-14 17:53:31 +00:00
|
|
|
new DoubleAutoValidator(Scale, qt_(autostr));
|
2007-08-31 22:16:11 +00:00
|
|
|
scaleValidator->setBottom(0);
|
|
|
|
scaleValidator->setDecimals(256); //I guess that will do
|
|
|
|
Scale->setValidator(scaleValidator);
|
2009-01-14 17:53:31 +00:00
|
|
|
Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
|
|
|
|
Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
|
2007-08-31 22:16:11 +00:00
|
|
|
angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
|
|
|
|
|
|
|
|
//clipping pane
|
|
|
|
connect(clip, SIGNAL(stateChanged(int)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2017-07-17 20:23:17 +00:00
|
|
|
connect(lbY, SIGNAL(textChanged(const QString &)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2007-08-31 22:16:11 +00:00
|
|
|
connect(lbYunit, SIGNAL(activated(int)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2017-07-17 20:23:17 +00:00
|
|
|
connect(rtY, SIGNAL(textChanged(const QString &)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2007-08-31 22:16:11 +00:00
|
|
|
connect(rtYunit, SIGNAL(activated(int)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2017-07-17 20:23:17 +00:00
|
|
|
connect(lbX, SIGNAL(textChanged(const QString &)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2007-08-31 22:16:11 +00:00
|
|
|
connect(lbXunit, SIGNAL(activated(int)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2017-07-17 20:23:17 +00:00
|
|
|
connect(rtX, SIGNAL(textChanged(const QString &)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2007-08-31 22:16:11 +00:00
|
|
|
connect(rtXunit, SIGNAL(activated(int)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeBB()));
|
2007-08-31 22:16:11 +00:00
|
|
|
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
|
2017-07-17 20:23:17 +00:00
|
|
|
connect(latexoptions, SIGNAL(textChanged(const QString &)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
|
|
|
connect(draftCB, 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.
|
2008-06-13 07:34:55 +00:00
|
|
|
connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
|
2017-07-17 20:23:17 +00:00
|
|
|
connect(displayscale, SIGNAL(textChanged(const QString &)),
|
2007-08-31 22:16:11 +00:00
|
|
|
this, SLOT(change_adaptor()));
|
2009-01-16 14:54:25 +00:00
|
|
|
connect(groupCO, SIGNAL(currentIndexChanged(int)),
|
2009-05-23 08:01:38 +00:00
|
|
|
this, SLOT(changeGroup(int)));
|
2009-01-16 14:54:25 +00:00
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
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(filenameL);
|
|
|
|
bc().addReadOnly(filename);
|
|
|
|
bc().addReadOnly(browsePB);
|
|
|
|
bc().addReadOnly(bbFrame);
|
|
|
|
bc().addReadOnly(draftCB);
|
|
|
|
bc().addReadOnly(clip);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::change_adaptor()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 08:01:38 +00:00
|
|
|
void GuiGraphics::changeGroup(int /* index */)
|
2009-01-14 15:10:15 +00:00
|
|
|
{
|
2009-01-17 08:02:52 +00:00
|
|
|
QString const new_group = groupCO->itemData(
|
2009-01-16 14:54:25 +00:00
|
|
|
groupCO->currentIndex()).toString();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-01-17 08:02:52 +00:00
|
|
|
// check if the old group consisted only of this member
|
|
|
|
if (current_group_ != fromqstr(new_group)
|
|
|
|
&& graphics::countGroupMembers(buffer(), current_group_) == 1) {
|
|
|
|
if (!new_group.isEmpty()) {
|
2017-07-03 17:53:14 +00:00
|
|
|
if (Alert::prompt(_("Dissolve previous group?"),
|
2009-01-17 08:02:52 +00:00
|
|
|
bformat(_("If you assign this graphic to group '%2$s',\n"
|
|
|
|
"the previously assigned group '%1$s' will be dissolved,\n"
|
|
|
|
"because this graphic was its only member.\n"
|
|
|
|
"How do you want to proceed?"),
|
|
|
|
from_utf8(current_group_), qstring_to_ucs4(new_group)),
|
|
|
|
0, 0,
|
|
|
|
bformat(_("Stick with group '%1$s'"),
|
|
|
|
from_utf8(current_group_)),
|
|
|
|
bformat(_("Assign to group '%1$s' anyway"),
|
|
|
|
qstring_to_ucs4(new_group))) == 0) {
|
|
|
|
groupCO->setCurrentIndex(
|
|
|
|
groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-03 17:53:14 +00:00
|
|
|
if (Alert::prompt(_("Dissolve previous group?"),
|
2009-01-17 08:02:52 +00:00
|
|
|
bformat(_("If you sign off this graphic from group '%1$s',\n"
|
|
|
|
"the group will be dissolved,\n"
|
|
|
|
"because this graphic was its only member.\n"
|
|
|
|
"How do you want to proceed?"),
|
|
|
|
from_utf8(current_group_)),
|
|
|
|
0, 0,
|
|
|
|
bformat(_("Stick with group '%1$s'"),
|
|
|
|
from_utf8(current_group_)),
|
|
|
|
bformat(_("Sign off from group '%1$s'"),
|
|
|
|
from_utf8(current_group_))) == 0) {
|
|
|
|
groupCO->setCurrentIndex(
|
|
|
|
groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
}
|
2009-01-16 14:54:25 +00:00
|
|
|
|
2009-01-17 08:02:52 +00:00
|
|
|
if (new_group.isEmpty()) {
|
2009-01-16 14:54:25 +00:00
|
|
|
changed();
|
2009-01-14 15:10:15 +00:00
|
|
|
return;
|
2009-01-16 14:54:25 +00:00
|
|
|
}
|
2009-01-14 15:10:15 +00:00
|
|
|
|
2009-01-17 08:02:52 +00:00
|
|
|
string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
|
2009-01-16 14:54:25 +00:00
|
|
|
if (grp.empty()) {
|
|
|
|
// group does not exist yet
|
|
|
|
changed();
|
|
|
|
return;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-01-16 14:54:25 +00:00
|
|
|
// filename might have been changed
|
|
|
|
QString current_filename = filename->text();
|
2009-01-14 15:10:15 +00:00
|
|
|
|
2009-01-16 14:54:25 +00:00
|
|
|
// group exists: load params into the dialog
|
|
|
|
groupCO->blockSignals(true);
|
2009-01-16 15:58:42 +00:00
|
|
|
InsetGraphics::string2params(grp, buffer(), params_);
|
|
|
|
paramsToDialog(params_);
|
2009-01-16 14:54:25 +00:00
|
|
|
groupCO->blockSignals(false);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-01-16 14:54:25 +00:00
|
|
|
// reset filename
|
|
|
|
filename->setText(current_filename);
|
2009-01-14 15:10:15 +00:00
|
|
|
|
2009-01-16 14:54:25 +00:00
|
|
|
changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphics::on_newGroupPB_clicked()
|
|
|
|
{
|
|
|
|
docstring newgroup;
|
|
|
|
if (!Alert::askForText(newgroup, _("Enter unique group name:")))
|
|
|
|
return;
|
|
|
|
if (newgroup.empty())
|
|
|
|
return;
|
|
|
|
if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
|
2017-07-03 17:53:14 +00:00
|
|
|
Alert::warning(_("Group already defined!"),
|
2009-01-16 14:54:25 +00:00
|
|
|
bformat(_("A graphics group with the name '%1$s' already exists."),
|
|
|
|
newgroup));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
|
|
|
|
groupCO->setCurrentIndex(
|
|
|
|
groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
|
2009-01-14 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 08:01:38 +00:00
|
|
|
void GuiGraphics::changeBB()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2007-10-06 22:16:14 +00:00
|
|
|
bbChanged = true;
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::on_browsePB_clicked()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const str = browse(filename->text());
|
|
|
|
if (!str.isEmpty()) {
|
|
|
|
filename->setText(str);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::on_getPB_clicked()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
getBB();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::setAutoText()
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
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")
|
2009-01-14 17:53:31 +00:00
|
|
|
Scale->setText(qt_(autostr));
|
2007-08-31 22:16:11 +00:00
|
|
|
|
|
|
|
setAutoTextCB(WidthCB, Width, widthUnit);
|
|
|
|
setAutoTextCB(HeightCB, Height, heightUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::on_scaleCB_toggled(bool setScale)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
|
|
|
|
HeightCB->isChecked() ||
|
|
|
|
scaleCB->isChecked()) &&
|
|
|
|
(angle->text() != "0"));
|
|
|
|
|
|
|
|
setAutoText();
|
2015-01-04 09:05:42 +00:00
|
|
|
updateAspectRatioStatus();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::on_WidthCB_toggled(bool setWidth)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
Width->setEnabled(setWidth);
|
|
|
|
widthUnit->setEnabled(setWidth);
|
|
|
|
if (setWidth)
|
|
|
|
Width->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
bool const setHeight = HeightCB->isChecked();
|
|
|
|
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();
|
2015-01-04 09:05:42 +00:00
|
|
|
updateAspectRatioStatus();
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 08:19:43 +00:00
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::on_HeightCB_toggled(bool setHeight)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
Height->setEnabled(setHeight);
|
|
|
|
heightUnit->setEnabled(setHeight);
|
|
|
|
if (setHeight)
|
|
|
|
Height->setFocus(Qt::OtherFocusReason);
|
|
|
|
|
|
|
|
bool const setWidth = WidthCB->isChecked();
|
|
|
|
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();
|
2015-01-04 09:05:42 +00:00
|
|
|
updateAspectRatioStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphics::updateAspectRatioStatus()
|
|
|
|
{
|
|
|
|
// keepaspectratio only makes sense if both a width _and_ a
|
|
|
|
// height are given, since its function is (see graphics manual):
|
|
|
|
// "If set to true then specifying both 'width' and 'height'
|
|
|
|
// (or 'totalheight') does not distort the figure but scales
|
|
|
|
// such that neither of the specified dimensions is _exceeded_."
|
|
|
|
aspectratio->setEnabled(
|
|
|
|
WidthCB->isChecked() && !Width->text().isEmpty()
|
|
|
|
&& Width->text() != qt_(autostr)
|
|
|
|
&& HeightCB->isChecked() && !Height->text().isEmpty()
|
|
|
|
&& Height->text() != qt_(autostr)
|
|
|
|
);
|
|
|
|
if (!aspectratio->isEnabled())
|
|
|
|
aspectratio->setChecked(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphics::on_aspectratio_toggled(bool aspectratio)
|
|
|
|
{
|
|
|
|
if (aspectratio) {
|
|
|
|
WidthCB->setText(qt_("Set max. &width:"));
|
|
|
|
HeightCB->setText(qt_("Set max. &height:"));
|
|
|
|
Width->setToolTip(qt_("Maximal width of image in output"));
|
|
|
|
Height->setToolTip(qt_("Maximal height of image in output"));
|
|
|
|
} else {
|
|
|
|
WidthCB->setText(qt_("Set &width:"));
|
|
|
|
HeightCB->setText(qt_("Set &height:"));
|
|
|
|
Width->setToolTip(qt_("Width of image in output"));
|
|
|
|
Height->setToolTip(qt_("Height of image in output"));
|
|
|
|
}
|
2007-08-31 22:16:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::on_angle_textChanged(const QString & filename)
|
2007-08-31 22:16:11 +00:00
|
|
|
{
|
|
|
|
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
|
|
|
|
HeightCB->isChecked() ||
|
|
|
|
scaleCB->isChecked()) &&
|
|
|
|
(filename != "0"));
|
|
|
|
}
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-05-06 15:18:50 +00:00
|
|
|
void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2008-04-18 18:53:43 +00:00
|
|
|
static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
|
2010-11-30 00:55:34 +00:00
|
|
|
static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in[[unit of measure]]") };
|
2008-04-18 18:53:43 +00:00
|
|
|
size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
lbXunit->clear();
|
|
|
|
lbYunit->clear();
|
|
|
|
rtXunit->clear();
|
|
|
|
rtYunit->clear();
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-07-12 17:54:35 +00:00
|
|
|
for (size_t i = 0; i < bb_size; i++) {
|
2009-07-12 15:44:26 +00:00
|
|
|
lbXunit->addItem(qt_(bb_units_gui[i]),
|
|
|
|
toqstr(bb_units[i]));
|
|
|
|
lbYunit->addItem(qt_(bb_units_gui[i]),
|
|
|
|
toqstr(bb_units[i]));
|
|
|
|
rtXunit->addItem(qt_(bb_units_gui[i]),
|
|
|
|
toqstr(bb_units[i]));
|
|
|
|
rtYunit->addItem(qt_(bb_units_gui[i]),
|
|
|
|
toqstr(bb_units[i]));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
// set the right default unit
|
2009-02-06 21:24:13 +00:00
|
|
|
Length::UNIT const defaultUnit = Length::defaultUnit();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-04-21 01:19:30 +00:00
|
|
|
//lyxerr << bufferFilePath();
|
2006-03-05 17:24:44 +00:00
|
|
|
string const name =
|
2010-04-21 01:19:30 +00:00
|
|
|
igp.filename.outputFileName(fromqstr(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
|
2015-07-18 15:02:54 +00:00
|
|
|
if (igp.bbox.empty()) {
|
2010-04-21 01:19:09 +00:00
|
|
|
string const bb = readBoundingBox(igp.filename.absFileName());
|
2006-03-05 17:24:44 +00:00
|
|
|
// the values from the file always have the bigpoint-unit bp
|
2009-07-12 15:44:26 +00:00
|
|
|
doubleToWidget(lbX, token(bb, ' ', 0));
|
|
|
|
doubleToWidget(lbY, token(bb, ' ', 1));
|
|
|
|
doubleToWidget(rtX, token(bb, ' ', 2));
|
|
|
|
doubleToWidget(rtY, token(bb, ' ', 3));
|
2007-09-05 20:33:29 +00:00
|
|
|
lbXunit->setCurrentIndex(0);
|
|
|
|
lbYunit->setCurrentIndex(0);
|
|
|
|
rtXunit->setCurrentIndex(0);
|
|
|
|
rtYunit->setCurrentIndex(0);
|
2007-10-06 22:16:14 +00:00
|
|
|
bbChanged = false;
|
2006-03-05 17:24:44 +00:00
|
|
|
} else {
|
|
|
|
// get the values from the inset
|
2015-07-18 15:02:54 +00:00
|
|
|
doubleToWidget(lbX, igp.bbox.xl.value());
|
|
|
|
string unit = unit_name[igp.bbox.xl.unit()];
|
|
|
|
lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
|
|
|
|
doubleToWidget(lbY, igp.bbox.yb.value());
|
|
|
|
unit = unit_name[igp.bbox.yb.unit()];
|
|
|
|
lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
|
|
|
|
doubleToWidget(rtX, igp.bbox.xr.value());
|
|
|
|
unit = unit_name[igp.bbox.xr.unit()];
|
|
|
|
rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
|
|
|
|
doubleToWidget(rtY, igp.bbox.yt.value());
|
|
|
|
unit = unit_name[igp.bbox.yt.unit()];
|
|
|
|
rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
|
2007-10-06 22:16:14 +00:00
|
|
|
bbChanged = true;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the draft and clip mode
|
2007-09-05 20:33:29 +00:00
|
|
|
draftCB->setChecked(igp.draft);
|
|
|
|
clip->setChecked(igp.clip);
|
2008-06-13 07:34:55 +00:00
|
|
|
displayGB->setChecked(igp.display);
|
2007-09-05 20:33:29 +00:00
|
|
|
displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
|
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
|
|
|
|
2009-07-12 15:44:26 +00:00
|
|
|
doubleToWidget(Scale, 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);
|
2008-06-13 07:34:55 +00:00
|
|
|
displayGB->setEnabled(lyxrc.display_graphics);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2009-01-14 15:10:15 +00:00
|
|
|
set<string> grp;
|
|
|
|
graphics::getGraphicsGroups(buffer(), grp);
|
|
|
|
set<string>::const_iterator it = grp.begin();
|
|
|
|
set<string>::const_iterator end = grp.end();
|
2009-01-16 14:54:25 +00:00
|
|
|
groupCO->blockSignals(true);
|
|
|
|
groupCO->clear();
|
2012-05-28 20:41:32 +00:00
|
|
|
for (; it != end; ++it)
|
2009-01-16 14:54:25 +00:00
|
|
|
groupCO->addItem(toqstr(*it), toqstr(*it));
|
|
|
|
groupCO->insertItem(0, qt_("None"), QString());
|
2009-01-14 15:10:15 +00:00
|
|
|
if (igp.groupId.empty())
|
2009-01-16 14:54:25 +00:00
|
|
|
groupCO->setCurrentIndex(0);
|
2009-01-14 15:10:15 +00:00
|
|
|
else
|
2009-01-16 14:54:25 +00:00
|
|
|
groupCO->setCurrentIndex(
|
|
|
|
groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
|
|
|
|
groupCO->blockSignals(false);
|
2008-05-06 21:13:09 +00:00
|
|
|
|
2009-01-14 17:53:31 +00:00
|
|
|
if (igp.width.value() == 0)
|
2009-02-06 21:24:13 +00:00
|
|
|
lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
|
2009-01-14 17:53:31 +00:00
|
|
|
else
|
2009-02-06 21:24:13 +00:00
|
|
|
lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
|
2009-01-14 17:53:31 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bool const widthChecked = !Width->text().isEmpty() &&
|
2009-01-14 17:53:31 +00:00
|
|
|
Width->text() != qt_(autostr);
|
2007-09-05 20:33:29 +00:00
|
|
|
WidthCB->blockSignals(true);
|
|
|
|
WidthCB->setChecked(widthChecked);
|
|
|
|
WidthCB->blockSignals(false);
|
|
|
|
Width->setEnabled(widthChecked);
|
|
|
|
widthUnit->setEnabled(widthChecked);
|
|
|
|
|
2009-01-14 17:53:31 +00:00
|
|
|
if (igp.height.value() == 0)
|
2009-02-06 21:24:13 +00:00
|
|
|
lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
|
2009-01-14 17:53:31 +00:00
|
|
|
else
|
2009-02-06 21:24:13 +00:00
|
|
|
lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
|
2009-01-14 17:53:31 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
bool const heightChecked = !Height->text().isEmpty()
|
2009-01-14 17:53:31 +00:00
|
|
|
&& Height->text() != qt_(autostr);
|
2007-09-05 20:33:29 +00:00
|
|
|
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);
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
setAutoText();
|
2015-01-04 09:05:42 +00:00
|
|
|
updateAspectRatioStatus();
|
2006-11-03 11:24:27 +00:00
|
|
|
|
2009-07-12 15:44:26 +00:00
|
|
|
doubleToWidget(angle, igp.rotateAngle);
|
2007-09-05 20:33:29 +00:00
|
|
|
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
|
|
|
|
2009-07-12 17:54:35 +00:00
|
|
|
for (size_t i = 0; i < rorigin_size; i++) {
|
2009-07-12 15:44:26 +00:00
|
|
|
origin->addItem(qt_(rorigin_gui_strs[i]),
|
|
|
|
toqstr(rorigin_lyx_strs[i]));
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
if (!igp.rotateOrigin.empty())
|
2009-07-12 15:44:26 +00:00
|
|
|
origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
|
2006-03-05 17:24:44 +00:00
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
origin->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-04-20 03:08:11 +00:00
|
|
|
// latex section
|
2007-09-05 20:33:29 +00:00
|
|
|
latexoptions->setText(toqstr(igp.special));
|
2009-11-06 15:22:17 +00:00
|
|
|
// cf bug #3852
|
|
|
|
filename->setFocus();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::applyView()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 22:16:14 +00:00
|
|
|
InsetGraphicsParams & igp = params_;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2010-04-21 01:19:30 +00:00
|
|
|
igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// the bb section
|
2015-07-18 15:02:54 +00:00
|
|
|
igp.bbox = graphics::BoundingBox();
|
2007-10-06 22:16:14 +00:00
|
|
|
if (bbChanged) {
|
2009-07-12 15:44:26 +00:00
|
|
|
string lbXs = widgetToDoubleStr(lbX);
|
|
|
|
string lbYs = widgetToDoubleStr(lbY);
|
|
|
|
string rtXs = widgetToDoubleStr(rtX);
|
|
|
|
string rtYs = widgetToDoubleStr(rtY);
|
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())
|
2015-07-18 15:02:54 +00:00
|
|
|
lbXs = "0";
|
|
|
|
igp.bbox.xl = Length(lbXs + fromqstr(lbXunit->currentText()));
|
2007-09-05 20:33:29 +00:00
|
|
|
if (lbYs.empty())
|
2015-07-18 15:02:54 +00:00
|
|
|
lbYs = "0";
|
|
|
|
igp.bbox.yb = Length(lbYs + fromqstr(lbYunit->currentText()));
|
2007-09-05 20:33:29 +00:00
|
|
|
if (rtXs.empty())
|
2015-07-18 15:02:54 +00:00
|
|
|
rtXs = "0";
|
|
|
|
igp.bbox.xr = Length(rtXs + fromqstr(rtXunit->currentText()));
|
2007-09-05 20:33:29 +00:00
|
|
|
if (rtYs.empty())
|
2015-07-18 15:02:54 +00:00
|
|
|
rtYs = "0";
|
|
|
|
igp.bbox.yt = Length(rtYs + fromqstr(rtYunit->currentText()));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
igp.draft = draftCB->isChecked();
|
|
|
|
igp.clip = clip->isChecked();
|
2008-06-13 07:34:55 +00:00
|
|
|
igp.display = displayGB->isChecked();
|
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()) {
|
2009-07-12 15:44:26 +00:00
|
|
|
igp.scale = widgetToDoubleStr(Scale);
|
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");
|
2015-01-04 09:05:42 +00:00
|
|
|
igp.keepAspectRatio = aspectratio->isChecked();
|
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.lyxscale = displayscale->text().toInt();
|
2009-07-12 15:44:26 +00:00
|
|
|
igp.rotateAngle = widgetToDoubleStr(angle);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-07-12 15:44:26 +00:00
|
|
|
double rotAngle = widgetToDouble(angle);
|
2007-12-12 19:28:07 +00:00
|
|
|
if (abs(rotAngle) > 360.0) {
|
2006-03-05 17:24:44 +00:00
|
|
|
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 ""
|
2009-07-12 15:44:26 +00:00
|
|
|
igp.rotateOrigin =
|
|
|
|
fromqstr(origin->itemData(origin->currentIndex()).toString());
|
2007-09-05 20:33:29 +00:00
|
|
|
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());
|
2008-05-06 21:13:09 +00:00
|
|
|
|
2009-01-16 14:54:25 +00:00
|
|
|
igp.groupId = fromqstr(groupCO->itemData(
|
|
|
|
groupCO->currentIndex()).toString());
|
2009-01-17 08:02:52 +00:00
|
|
|
current_group_ = igp.groupId;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
void GuiGraphics::getBB()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
string const fn = fromqstr(filename->text());
|
2007-11-23 22:15:17 +00:00
|
|
|
if (fn.empty())
|
|
|
|
return;
|
2008-04-18 18:53:43 +00:00
|
|
|
string const bb = readBoundingBox(fn);
|
2007-11-23 22:15:17 +00:00
|
|
|
bbChanged = false;
|
|
|
|
if (bb.empty())
|
|
|
|
return;
|
2009-07-12 15:44:26 +00:00
|
|
|
doubleToWidget(lbX, token(bb, ' ', 0));
|
|
|
|
doubleToWidget(lbY, token(bb, ' ', 1));
|
|
|
|
doubleToWidget(rtX, token(bb, ' ', 2));
|
|
|
|
doubleToWidget(rtY, token(bb, ' ', 3));
|
2007-11-23 22:15:17 +00:00
|
|
|
// the default units for the bb values when reading
|
|
|
|
// it from the file
|
|
|
|
lbXunit->setCurrentIndex(0);
|
|
|
|
lbYunit->setCurrentIndex(0);
|
|
|
|
rtXunit->setCurrentIndex(0);
|
|
|
|
rtYunit->setCurrentIndex(0);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
bool GuiGraphics::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
|
|
|
}
|
|
|
|
|
2007-10-06 22:16:14 +00:00
|
|
|
|
|
|
|
bool GuiGraphics::initialiseParams(string const & data)
|
|
|
|
{
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetGraphics::string2params(data, buffer(), params_);
|
2008-05-06 15:18:50 +00:00
|
|
|
paramsToDialog(params_);
|
2009-01-17 08:02:52 +00:00
|
|
|
current_group_ = params_.groupId;
|
2007-10-06 22:16:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphics::clearParams()
|
|
|
|
{
|
|
|
|
params_ = InsetGraphicsParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiGraphics::dispatchParams()
|
|
|
|
{
|
|
|
|
InsetGraphicsParams tmp_params(params_);
|
2008-03-27 22:26:24 +00:00
|
|
|
string const lfun = InsetGraphics::params2string(tmp_params, buffer());
|
2007-10-06 22:16:14 +00:00
|
|
|
dispatch(FuncRequest(getLfun(), lfun));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 00:07:19 +00:00
|
|
|
QString GuiGraphics::browse(QString const & in_name) const
|
2007-10-06 22:16:14 +00:00
|
|
|
{
|
2008-03-06 00:07:19 +00:00
|
|
|
QString const title = qt_("Select graphics file");
|
2007-10-06 22:16:14 +00:00
|
|
|
|
|
|
|
// Does user clipart directory exist?
|
2010-04-21 01:19:09 +00:00
|
|
|
string clipdir = addName(package().user_support().absFileName(), "clipart");
|
2007-10-18 21:10:35 +00:00
|
|
|
FileName clip(clipdir);
|
2007-10-28 16:32:20 +00:00
|
|
|
|
|
|
|
// bail out to system clipart directory
|
2008-04-18 19:17:11 +00:00
|
|
|
if (!clip.isDirectory())
|
2010-04-21 01:19:09 +00:00
|
|
|
clipdir = addName(package().system_support().absFileName(), "clipart");
|
2007-10-28 16:32:20 +00:00
|
|
|
|
2011-06-01 13:18:08 +00:00
|
|
|
return browseRelToParent(in_name, bufferFilePath(),
|
2017-07-03 17:53:14 +00:00
|
|
|
title, fileFilters(QString()), false,
|
2008-03-06 00:07:19 +00:00
|
|
|
qt_("Clipart|#C#c"), toqstr(clipdir),
|
|
|
|
qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
|
2007-10-06 22:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-18 18:53:43 +00:00
|
|
|
string GuiGraphics::readBoundingBox(string const & file)
|
2007-10-06 22:16:14 +00:00
|
|
|
{
|
2010-04-21 01:19:30 +00:00
|
|
|
FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath()));
|
2007-10-06 22:16:14 +00:00
|
|
|
|
|
|
|
// try to get it from the file, if possible. Zipped files are
|
|
|
|
// unzipped in the readBB_from_PSFile-Function
|
2012-02-15 20:50:52 +00:00
|
|
|
string const bb = graphics::readBB_from_PSFile(abs_file);
|
2007-10-06 22:16:14 +00:00
|
|
|
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) {
|
2007-11-23 22:15:17 +00:00
|
|
|
width = image->width();
|
|
|
|
height = image->height();
|
2007-10-06 22:16:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-18 18:53:43 +00:00
|
|
|
bool GuiGraphics::isFileNameValid(string const & fname) const
|
2007-10-06 22:16:14 +00:00
|
|
|
{
|
|
|
|
// It may be that the filename is relative.
|
2010-04-21 01:19:30 +00:00
|
|
|
return support::makeAbsPath(fname, fromqstr(bufferFilePath())).isReadableFile();
|
2007-10-06 22:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
|
2007-10-06 22:16:14 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-08-31 22:16:11 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiGraphics.cpp"
|