* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
+ * \author Angus Leeming
* \author John Levon
* \author Edwin Leuven
* \author Herbert Voß
#include "GuiGraphics.h"
-#include "debug.h"
#include "LengthCombo.h"
-#include "lengthcommon.h"
+#include "Length.h"
#include "LyXRC.h"
#include "qt_helpers.h"
#include "Validator.h"
-#include "controllers/frontend_helpers.h"
+#include "FuncRequest.h"
+
+#include "graphics/GraphicsCache.h"
+#include "graphics/GraphicsCacheItem.h"
+#include "graphics/GraphicsImage.h"
#include "insets/InsetGraphicsParams.h"
#include "support/convert.h"
+#include "support/debug.h"
+#include "support/FileFilterList.h"
+#include "support/filetools.h"
+#include "support/gettext.h"
#include "support/lstrings.h"
-#include "support/lyxlib.h"
#include "support/os.h"
+#include "support/Package.h"
+#include "support/types.h"
#include <QCheckBox>
-#include <QCloseEvent>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QValidator>
-#include <algorithm>
#include <cmath>
+#include <utility>
+
+using namespace std;
+using namespace lyx::support;
-using lyx::support::float_equal;
-using lyx::support::token;
+namespace {
-using lyx::support::os::internal_path;
+// 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
-#ifndef CXX_GLOBAL_CSTD
-using std::floor;
-#endif
+// 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") };
-using std::vector;
-using std::string;
+size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
+
+} // namespace anon
namespace lyx {
namespace frontend {
+//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
+//to make, since "auto" also appears in updateContents() (see
+//GuiGraphics.cpp).
+//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".
+*/
+static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
+ LengthCombo * lengthCombo/*, string text = "auto"*/)
+{
+ if (!checkBox->isChecked())
+ lengthToWidgets(lineEdit, lengthCombo,
+ "auto", lengthCombo->currentLengthItem());
+ else if (lineEdit->text() == "auto")
+ lengthToWidgets(lineEdit, lengthCombo, string(),
+ lengthCombo->currentLengthItem());
+}
+
+
+template<class Pair>
+vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
+{
+ size_t const n = pr.size();
+ vector<typename Pair::first_type> tmp(n);
+ for (size_t i = 0; i != n; ++i)
+ tmp[i] = pr[i].first;
+ return tmp;
+}
+
+///
template<class Pair>
-std::vector<typename Pair::first_type> const
-getFirst(std::vector<Pair> const & pr)
+vector<typename Pair::second_type> getSecond(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));
+ size_t const n = pr.size();
+ vector<typename Pair::second_type> tmp(n);
+ for (size_t i = 0; i != n; ++i)
+ tmp[i] = pr[i].second;
return tmp;
}
-GuiGraphicsDialog::GuiGraphicsDialog(GuiGraphics * form)
- : form_(form)
+
+/// The (tranlated) GUI string and it's LaTeX equivalent.
+typedef pair<docstring, string> RotationOriginPair;
+///
+vector<RotationOriginPair> getRotationOriginData()
+{
+ static vector<RotationOriginPair> data;
+ if (!data.empty())
+ return data;
+
+ data.resize(rorigin_size);
+ for (size_type i = 0; i < rorigin_size; ++i) {
+ data[i] = make_pair(_(rorigin_gui_strs[i]),
+ rorigin_lyx_strs[i]);
+ }
+
+ return data;
+}
+
+
+
+GuiGraphics::GuiGraphics(GuiView & lv)
+ : GuiDialog(lv, "graphics", qt_("Graphics"))
{
setupUi(this);
+
//main buttons
- connect(okPB, SIGNAL(clicked()),
- form, SLOT(slotOK()));
- connect(applyPB, SIGNAL(clicked()),
- form, SLOT(slotApply()));
- connect(closePB, SIGNAL(clicked()),
- form, SLOT(slotClose()));
- connect(restorePB, SIGNAL(clicked()),
- form, SLOT(slotRestore()));
+ 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()));
//graphics pane
connect(filename, SIGNAL(textChanged(const QString &)),
// 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)),
connect(displayscale, SIGNAL(textChanged(const QString&)),
this, SLOT(change_adaptor()));
displayscale->setValidator(new QIntValidator(displayscale));
-}
-
-
-void GuiGraphicsDialog::showView()
-{
- QDialog::show();
-}
+ 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(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);
-void GuiGraphicsDialog::change_adaptor()
-{
- form_->changed();
+ // 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);
}
-void GuiGraphicsDialog::change_bb()
+void GuiGraphics::change_adaptor()
{
- form_->controller().bbChanged = true;
- LYXERR(Debug::GRAPHICS)
- << "[controller().bb_Changed set to true]\n";
- form_->changed();
+ changed();
}
-void GuiGraphicsDialog::closeEvent(QCloseEvent * e)
+void GuiGraphics::change_bb()
{
- form_->slotWMHide();
- e->accept();
+ bbChanged = true;
+ LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
+ changed();
}
-void GuiGraphicsDialog::on_browsePB_clicked()
+void GuiGraphics::on_browsePB_clicked()
{
- docstring const str =
- form_->controller().browse(qstring_to_ucs4(filename->text()));
- if(!str.empty()){
- filename->setText(toqstr(str));
- form_->changed();
+ QString const str = browse(filename->text());
+ if (!str.isEmpty()) {
+ filename->setText(str);
+ changed();
}
}
-void GuiGraphicsDialog::on_getPB_clicked()
+void GuiGraphics::on_getPB_clicked()
{
- form_->getBB();
+ getBB();
}
-void GuiGraphicsDialog::on_editPB_clicked()
+void GuiGraphics::setAutoText()
{
- form_->controller().editGraphics();
-}
-
-
-void GuiGraphicsDialog::on_filename_textChanged(const QString & filename)
-{
- editPB->setDisabled(filename.isEmpty());
-}
-
-
-void GuiGraphicsDialog::setAutoText()
-{
- if (scaleCB->isChecked()) return;
+ if (scaleCB->isChecked())
+ return;
if (!Scale->isEnabled() && Scale->text() != "100")
Scale->setText(QString("auto"));
}
-void GuiGraphicsDialog::on_scaleCB_toggled(bool setScale)
+void GuiGraphics::on_scaleCB_toggled(bool setScale)
{
Scale->setEnabled(setScale);
if (setScale) {
setAutoText();
}
-void GuiGraphicsDialog::on_WidthCB_toggled(bool setWidth)
+
+void GuiGraphics::on_WidthCB_toggled(bool setWidth)
{
Width->setEnabled(setWidth);
widthUnit->setEnabled(setWidth);
}
-void GuiGraphicsDialog::on_HeightCB_toggled(bool setHeight)
+void GuiGraphics::on_HeightCB_toggled(bool setHeight)
{
Height->setEnabled(setHeight);
heightUnit->setEnabled(setHeight);
}
-void GuiGraphicsDialog::on_angle_textChanged(const QString & filename)
+void GuiGraphics::on_angle_textChanged(const QString & filename)
{
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
HeightCB->isChecked() ||
(filename != "0"));
}
-
-GuiGraphics::GuiGraphics(GuiDialog & parent)
- : GuiView<GuiGraphicsDialog>(parent, _("Graphics"))
-{
-}
-
-
-void GuiGraphics::build_dialog()
-{
- dialog_.reset(new GuiGraphicsDialog(this));
-
- bc().setOK(dialog_->okPB);
- bc().setApply(dialog_->applyPB);
- bc().setRestore(dialog_->restorePB);
- bc().setCancel(dialog_->closePB);
-
- bc().addReadOnly(dialog_->latexoptions);
- bc().addReadOnly(dialog_->subfigure);
- bc().addReadOnly(dialog_->filenameL);
- bc().addReadOnly(dialog_->filename);
- bc().addReadOnly(dialog_->browsePB);
- bc().addReadOnly(dialog_->unzipCB);
- bc().addReadOnly(dialog_->bbFrame);
- bc().addReadOnly(dialog_->draftCB);
- bc().addReadOnly(dialog_->clip);
- bc().addReadOnly(dialog_->unzipCB);
- bc().addReadOnly(dialog_->displayGB);
- bc().addReadOnly(dialog_->sizeGB);
- bc().addReadOnly(dialog_->rotationGB);
- bc().addReadOnly(dialog_->latexoptions);
- bc().addReadOnly(dialog_->getPB);
- bc().addReadOnly(dialog_->rotateOrderCB);
-
- // initialize the length validator
- bc().addCheckedLineEdit(dialog_->Scale, dialog_->scaleCB);
- bc().addCheckedLineEdit(dialog_->Width, dialog_->WidthCB);
- bc().addCheckedLineEdit(dialog_->Height, dialog_->HeightCB);
- bc().addCheckedLineEdit(dialog_->displayscale, dialog_->scaleLA);
- bc().addCheckedLineEdit(dialog_->angle, dialog_->angleL);
- bc().addCheckedLineEdit(dialog_->lbX, dialog_->xL);
- bc().addCheckedLineEdit(dialog_->lbY, dialog_->yL);
- bc().addCheckedLineEdit(dialog_->rtX, dialog_->xL_2);
- bc().addCheckedLineEdit(dialog_->rtY, dialog_->yL_2);
- bc().addCheckedLineEdit(dialog_->filename, dialog_->filenameL);
-}
-
-
// returns the number of the string s in the vector v
-static int getItemNo(const vector<string> & v, string const & s)
+static int itemNumber(const vector<string> & v, string const & s)
{
vector<string>::const_iterator cit =
find(v.begin(), v.end(), s);
return (cit != v.end()) ? int(cit - v.begin()) : 0;
}
-template<class Pair>
-std::vector<typename Pair::second_type> const
-getSecond(std::vector<Pair> const & pr)
-{
- std::vector<typename Pair::second_type> tmp(pr.size());
- std::transform(pr.begin(), pr.end(), tmp.begin(),
- boost::bind(&Pair::second, _1));
- return tmp;
-}
-
-void GuiGraphics::update_contents()
+void GuiGraphics::updateContents()
{
- // clear and fill in the comboboxes
- vector<string> const bb_units = frontend::getBBUnits();
- dialog_->lbXunit->clear();
- dialog_->lbYunit->clear();
- dialog_->rtXunit->clear();
- dialog_->rtYunit->clear();
- for (vector<string>::const_iterator it = bb_units.begin();
- it != bb_units.end(); ++it) {
- dialog_->lbXunit->addItem(toqstr(*it));
- dialog_->lbYunit->addItem(toqstr(*it));
- dialog_->rtXunit->addItem(toqstr(*it));
- dialog_->rtYunit->addItem(toqstr(*it));
+ static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
+ size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
+
+ vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
+ lbXunit->clear();
+ lbYunit->clear();
+ rtXunit->clear();
+ rtYunit->clear();
+ for (vector<string>::const_iterator it = units.begin();
+ it != units.end(); ++it) {
+ lbXunit->addItem(toqstr(*it));
+ lbYunit->addItem(toqstr(*it));
+ rtXunit->addItem(toqstr(*it));
+ rtYunit->addItem(toqstr(*it));
}
- InsetGraphicsParams & igp = controller().params();
+ InsetGraphicsParams & igp = params_;
// set the right default unit
Length::UNIT unitDefault = Length::CM;
}
string const name =
- igp.filename.outputFilename(kernel().bufferFilepath());
- dialog_->filename->setText(toqstr(name));
+ igp.filename.outputFilename(fromqstr(bufferFilepath()));
+ filename->setText(toqstr(name));
// set the bounding box values
if (igp.bb.empty()) {
- string const bb = controller().readBB(igp.filename.absFilename());
+ string const bb = readBoundingBox(igp.filename.absFilename());
// the values from the file always have the bigpoint-unit bp
- dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
- dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
- dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
- dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
- dialog_->lbXunit->setCurrentIndex(0);
- dialog_->lbYunit->setCurrentIndex(0);
- dialog_->rtXunit->setCurrentIndex(0);
- dialog_->rtYunit->setCurrentIndex(0);
- controller().bbChanged = false;
+ 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);
+ bbChanged = false;
} else {
// get the values from the inset
Length anyLength;
- 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));
+ 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)) {
- dialog_->lbX->setText(toqstr(convert<string>(anyLength.value())));
- string const unit(unit_name[anyLength.unit()]);
- dialog_->lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
+ lbX->setText(toqstr(convert<string>(anyLength.value())));
+ string const unit = unit_name[anyLength.unit()];
+ lbXunit->setCurrentIndex(itemNumber(units, unit));
} else {
- dialog_->lbX->setText(toqstr(xl));
+ lbX->setText(toqstr(xl));
}
if (isValidLength(yl, &anyLength)) {
- dialog_->lbY->setText(toqstr(convert<string>(anyLength.value())));
- string const unit(unit_name[anyLength.unit()]);
- dialog_->lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
+ lbY->setText(toqstr(convert<string>(anyLength.value())));
+ string const unit = unit_name[anyLength.unit()];
+ lbYunit->setCurrentIndex(itemNumber(units, unit));
} else {
- dialog_->lbY->setText(toqstr(xl));
+ lbY->setText(toqstr(xl));
}
if (isValidLength(xr, &anyLength)) {
- dialog_->rtX->setText(toqstr(convert<string>(anyLength.value())));
- string const unit(unit_name[anyLength.unit()]);
- dialog_->rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
+ rtX->setText(toqstr(convert<string>(anyLength.value())));
+ string const unit = unit_name[anyLength.unit()];
+ rtXunit->setCurrentIndex(itemNumber(units, unit));
} else {
- dialog_->rtX->setText(toqstr(xl));
+ rtX->setText(toqstr(xl));
}
if (isValidLength(yr, &anyLength)) {
- dialog_->rtY->setText(toqstr(convert<string>(anyLength.value())));
- string const unit(unit_name[anyLength.unit()]);
- dialog_->rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
+ rtY->setText(toqstr(convert<string>(anyLength.value())));
+ string const unit = unit_name[anyLength.unit()];
+ rtYunit->setCurrentIndex(itemNumber(units, unit));
} else {
- dialog_->rtY->setText(toqstr(xl));
+ rtY->setText(toqstr(xl));
}
- controller().bbChanged = true;
+ bbChanged = true;
}
// Update the draft and clip mode
- dialog_->draftCB->setChecked(igp.draft);
- dialog_->clip->setChecked(igp.clip);
- dialog_->unzipCB->setChecked(igp.noUnzip);
-
- // Update the subcaption check button and input field
- dialog_->subfigure->setChecked(igp.subcaption);
- dialog_->subcaption->setText(toqstr(igp.subcaptionText));
+ draftCB->setChecked(igp.draft);
+ clip->setChecked(igp.clip);
+ unzipCB->setChecked(igp.noUnzip);
int item = 0;
switch (igp.display) {
case graphics::ColorDisplay: item = 3; break;
case graphics::NoDisplay: item = 0; break;
}
- dialog_->showCB->setCurrentIndex(item);
- dialog_->displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
- dialog_->displayGB->setChecked(igp.display != graphics::NoDisplay);
+ showCB->setCurrentIndex(item);
+ displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
+ displayGB->setChecked(igp.display != graphics::NoDisplay);
// the output section (width/height)
- dialog_->Scale->setText(toqstr(igp.scale));
+ Scale->setText(toqstr(igp.scale));
//igp.scale defaults to 100, so we treat it as empty
bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
- dialog_->scaleCB->blockSignals(true);
- dialog_->scaleCB->setChecked(scaleChecked);
- dialog_->scaleCB->blockSignals(false);
- dialog_->Scale->setEnabled(scaleChecked);
+ scaleCB->blockSignals(true);
+ scaleCB->setChecked(scaleChecked);
+ scaleCB->blockSignals(false);
+ Scale->setEnabled(scaleChecked);
- lengthAutoToWidgets(dialog_->Width, dialog_->widthUnit, igp.width,
+ lengthAutoToWidgets(Width, widthUnit, igp.width,
unitDefault);
- bool const widthChecked = !dialog_->Width->text().isEmpty() &&
- dialog_->Width->text() != "auto";
- dialog_->WidthCB->blockSignals(true);
- dialog_->WidthCB->setChecked(widthChecked);
- dialog_->WidthCB->blockSignals(false);
- dialog_->Width->setEnabled(widthChecked);
- dialog_->widthUnit->setEnabled(widthChecked);
-
- lengthAutoToWidgets(dialog_->Height, dialog_->heightUnit, igp.height,
+ 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,
unitDefault);
- bool const heightChecked = !dialog_->Height->text().isEmpty()
- && dialog_->Height->text() != "auto";
- dialog_->HeightCB->blockSignals(true);
- dialog_->HeightCB->setChecked(heightChecked);
- dialog_->HeightCB->blockSignals(false);
- dialog_->Height->setEnabled(heightChecked);
- dialog_->heightUnit->setEnabled(heightChecked);
+ bool const heightChecked = !Height->text().isEmpty()
+ && Height->text() != "auto";
+ HeightCB->blockSignals(true);
+ HeightCB->setChecked(heightChecked);
+ HeightCB->blockSignals(false);
+ Height->setEnabled(heightChecked);
+ heightUnit->setEnabled(heightChecked);
- dialog_->scaleCB->setEnabled(!widthChecked && !heightChecked);
- dialog_->WidthCB->setEnabled(!scaleChecked);
- dialog_->HeightCB->setEnabled(!scaleChecked);
- dialog_->aspectratio->setEnabled(widthChecked && heightChecked);
+ scaleCB->setEnabled(!widthChecked && !heightChecked);
+ WidthCB->setEnabled(!scaleChecked);
+ HeightCB->setEnabled(!scaleChecked);
+ aspectratio->setEnabled(widthChecked && heightChecked);
- dialog_->setAutoText();
+ setAutoText();
- dialog_->angle->setText(toqstr(igp.rotateAngle));
- dialog_->rotateOrderCB->setChecked(igp.scaleBeforeRotation);
+ angle->setText(toqstr(igp.rotateAngle));
+ rotateOrderCB->setChecked(igp.scaleBeforeRotation);
- dialog_->rotateOrderCB->setEnabled((widthChecked ||
- heightChecked ||
- scaleChecked) &&
- (igp.rotateAngle != "0"));
+ rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
+ && igp.rotateAngle != "0");
- dialog_->origin->clear();
+ origin->clear();
vector<RotationOriginPair> origindata = getRotationOriginData();
vector<docstring> const origin_lang = getFirst(origindata);
- GuiGraphics::origin_ltx = getSecond(origindata);
+ origin_ltx = getSecond(origindata);
for (vector<docstring>::const_iterator it = origin_lang.begin();
it != origin_lang.end(); ++it)
- dialog_->origin->addItem(toqstr(*it));
+ origin->addItem(toqstr(*it));
if (!igp.rotateOrigin.empty())
- dialog_->origin->setCurrentIndex(
- getItemNo(origin_ltx, igp.rotateOrigin));
+ origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
else
- dialog_->origin->setCurrentIndex(0);
-
- // disable edit button when no filename is present
- dialog_->editPB->setDisabled(dialog_->filename->text().isEmpty());
+ origin->setCurrentIndex(0);
- //// latex section
- dialog_->latexoptions->setText(toqstr(igp.special));
+ // latex section
+ latexoptions->setText(toqstr(igp.special));
}
void GuiGraphics::applyView()
{
- InsetGraphicsParams & igp = controller().params();
+ InsetGraphicsParams & igp = params_;
- igp.filename.set(internal_path(fromqstr(dialog_->filename->text())),
- kernel().bufferFilepath());
+ igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
// the bb section
igp.bb.erase();
- if (controller().bbChanged) {
+ if (bbChanged) {
string bb;
- string lbX(fromqstr(dialog_->lbX->text()));
- string lbY(fromqstr(dialog_->lbY->text()));
- string rtX(fromqstr(dialog_->rtX->text()));
- string rtY(fromqstr(dialog_->rtY->text()));
+ string lbXs = fromqstr(lbX->text());
+ string lbYs = fromqstr(lbY->text());
+ string rtXs = fromqstr(rtX->text());
+ string rtYs = fromqstr(rtY->text());
int bb_sum =
- convert<int>(lbX) + convert<int>(lbY) +
- convert<int>(rtX) + convert<int>(rtX);
+ convert<int>(lbXs) + convert<int>(lbYs) +
+ convert<int>(rtXs) + convert<int>(rtXs);
if (bb_sum) {
- if (lbX.empty())
+ if (lbXs.empty())
bb = "0 ";
else
- bb = lbX + fromqstr(dialog_->lbXunit->currentText()) + ' ';
- if (lbY.empty())
+ bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
+ if (lbYs.empty())
bb += "0 ";
else
- bb += (lbY + fromqstr(dialog_->lbYunit->currentText()) + ' ');
- if (rtX.empty())
+ bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
+ if (rtXs.empty())
bb += "0 ";
else
- bb += (rtX + fromqstr(dialog_->rtXunit->currentText()) + ' ');
- if (rtY.empty())
+ bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
+ if (rtYs.empty())
bb += '0';
else
- bb += (rtY + fromqstr(dialog_->rtYunit->currentText()));
+ bb += (rtYs + fromqstr(rtYunit->currentText()));
igp.bb = bb;
}
}
- igp.draft = dialog_->draftCB->isChecked();
- igp.clip = dialog_->clip->isChecked();
- igp.subcaption = dialog_->subfigure->isChecked();
- igp.subcaptionText = fromqstr(dialog_->subcaption->text());
+ igp.draft = draftCB->isChecked();
+ igp.clip = clip->isChecked();
- switch (dialog_->showCB->currentIndex()) {
+ switch (showCB->currentIndex()) {
case 0: igp.display = graphics::DefaultDisplay; break;
case 1: igp.display = graphics::MonochromeDisplay; break;
case 2: igp.display = graphics::GrayscaleDisplay; break;
default:;
}
- if (!dialog_->displayGB->isChecked())
+ if (!displayGB->isChecked())
igp.display = graphics::NoDisplay;
//the graphics section
- if (dialog_->scaleCB->isChecked() && !dialog_->Scale->text().isEmpty()) {
- igp.scale = fromqstr(dialog_->Scale->text());
+ if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
+ igp.scale = fromqstr(Scale->text());
igp.width = Length("0pt");
igp.height = Length("0pt");
igp.keepAspectRatio = false;
} else {
igp.scale = string();
- igp.width = dialog_->WidthCB->isChecked() ?
- //Note that this works even if dialog_->Width is "auto", since in
+ igp.width = WidthCB->isChecked() ?
+ //Note that this works even if Width is "auto", since in
//that case we get "0pt".
- Length(widgetsToLength(dialog_->Width, dialog_->widthUnit)):
+ Length(widgetsToLength(Width, widthUnit)):
Length("0pt");
- igp.height = dialog_->HeightCB->isChecked() ?
- Length(widgetsToLength(dialog_->Height, dialog_->heightUnit)) :
+ igp.height = HeightCB->isChecked() ?
+ Length(widgetsToLength(Height, heightUnit)) :
Length("0pt");
- igp.keepAspectRatio = dialog_->aspectratio->isEnabled() &&
- dialog_->aspectratio->isChecked() &&
+ igp.keepAspectRatio = aspectratio->isEnabled() &&
+ aspectratio->isChecked() &&
igp.width.value() > 0 && igp.height.value() > 0;
}
- igp.noUnzip = dialog_->unzipCB->isChecked();
-
- igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));
-
- igp.rotateAngle = fromqstr(dialog_->angle->text());
+ igp.noUnzip = unzipCB->isChecked();
+ igp.lyxscale = displayscale->text().toInt();
+ igp.rotateAngle = fromqstr(angle->text());
double rotAngle = convert<double>(igp.rotateAngle);
- if (std::abs(rotAngle) > 360.0) {
+ if (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 ""
- igp.rotateOrigin =
- GuiGraphics::origin_ltx[dialog_->origin->currentIndex()];
-
- igp.scaleBeforeRotation = dialog_->rotateOrderCB->isChecked();
+ igp.rotateOrigin = origin_ltx[origin->currentIndex()];
+ igp.scaleBeforeRotation = rotateOrderCB->isChecked();
// more latex options
- igp.special = fromqstr(dialog_->latexoptions->text());
+ igp.special = fromqstr(latexoptions->text());
}
void GuiGraphics::getBB()
{
- string const filename(fromqstr(dialog_->filename->text()));
- if (!filename.empty()) {
- string const bb(controller().readBB(filename));
- if (!bb.empty()) {
- dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
- dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
- dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
- dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
- // the default units for the bb values when reading
- // it from the file
- dialog_->lbXunit->setCurrentIndex(0);
- dialog_->lbYunit->setCurrentIndex(0);
- dialog_->rtXunit->setCurrentIndex(0);
- dialog_->rtYunit->setCurrentIndex(0);
+ string const fn = fromqstr(filename->text());
+ if (fn.empty())
+ return;
+ string const bb = readBoundingBox(fn);
+ bbChanged = false;
+ if (bb.empty())
+ return;
+ lbX->setText(toqstr(token(bb, ' ', 0)));
+ lbY->setText(toqstr(token(bb, ' ', 1)));
+ rtX->setText(toqstr(token(bb, ' ', 2)));
+ rtY->setText(toqstr(token(bb, ' ', 3)));
+ // 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);
+}
+
+
+bool GuiGraphics::isValid()
+{
+ return !filename->text().isEmpty();
+}
+
+
+bool GuiGraphics::initialiseParams(string const & data)
+{
+ InsetGraphics::string2params(data, buffer(), params_);
+ return true;
+}
+
+
+void GuiGraphics::clearParams()
+{
+ params_ = InsetGraphicsParams();
+}
+
+
+void GuiGraphics::dispatchParams()
+{
+ InsetGraphicsParams tmp_params(params_);
+ string const lfun = InsetGraphics::params2string(tmp_params, buffer());
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+QString GuiGraphics::browse(QString const & in_name) const
+{
+ QString const title = qt_("Select graphics file");
+
+ // Does user clipart directory exist?
+ string clipdir = addName(package().user_support().absFilename(), "clipart");
+ FileName clip(clipdir);
+
+ // bail out to system clipart directory
+ if (!clip.isDirectory())
+ clipdir = addName(package().system_support().absFilename(), "clipart");
+
+ return browseRelFile(in_name, bufferFilepath(),
+ title, FileFilterList(), false,
+ qt_("Clipart|#C#c"), toqstr(clipdir),
+ qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+}
+
+
+string GuiGraphics::readBoundingBox(string const & file)
+{
+ FileName const abs_file = makeAbsPath(file, fromqstr(bufferFilepath()));
+
+ // try to get it from the file, if possible. Zipped files are
+ // unzipped in the readBB_from_PSFile-Function
+ string const bb = readBB_from_PSFile(abs_file);
+ if (!bb.empty())
+ return bb;
+
+ // we don't, so ask the Graphics Cache if it has loaded the file
+ int width = 0;
+ int height = 0;
+
+ graphics::Cache & gc = graphics::Cache::get();
+ if (gc.inCache(abs_file)) {
+ graphics::Image const * image = gc.item(abs_file)->image();
+
+ if (image) {
+ width = image->width();
+ height = image->height();
}
- controller().bbChanged = false;
}
+
+ return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
}
-bool GuiGraphics::isValid()
+bool GuiGraphics::isFileNameValid(string const & fname) const
{
- return !dialog_->filename->text().isEmpty();
+ // It may be that the filename is relative.
+ return makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
}
+
+Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
+
+
} // namespace frontend
} // namespace lyx
-
#include "GuiGraphics_moc.cpp"
-