2 * \file GuiGraphics.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
10 * \author Richard Kimberly Heck
12 * Full author contact details are available in file CREDITS.
17 #include "GuiGraphics.h"
18 #include "frontends/alert.h"
19 #include "qt_helpers.h"
20 #include "Validator.h"
23 #include "FuncRequest.h"
24 #include "LengthCombo.h"
27 #include "graphics/epstools.h"
28 #include "graphics/GraphicsCache.h"
29 #include "graphics/GraphicsCacheItem.h"
30 #include "graphics/GraphicsImage.h"
32 #include "insets/InsetGraphics.h"
34 #include "support/convert.h"
35 #include "support/debug.h"
36 #include "support/filetools.h"
37 #include "support/gettext.h"
38 #include "support/Length.h"
39 #include "support/lstrings.h"
40 #include "support/os.h"
41 #include "support/Package.h"
42 #include "support/types.h"
47 #include <QPushButton>
54 using namespace lyx::support;
58 // These are the strings that are stored in the LyX file and which
59 // correspond to the LaTeX identifiers shown in the comments at the
61 char const * const rorigin_lyx_strs[] = {
62 // the LaTeX default is leftBaseline
64 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
65 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
66 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
68 // These are the strings, corresponding to the above, that the GUI should
69 // use. Note that they can/should be translated.
70 char const * const rorigin_gui_strs[] = {
72 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
73 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
74 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
76 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
78 static string const autostr = N_("automatically");
86 //FIXME setAutoTextCB should really take an argument, as indicated, that
87 //determines what text is to be written for "auto". But making
88 //that work involves more extensive revisions than we now want
89 //to make, since "auto" also appears in paramsToDialog().
90 //The right way to do this, I think, would be to define a class
91 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
92 //the checkbox, line edit, and length combo together, and then made e.g.
93 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
94 //Perhaps even the validator could be exposed through it.
96 * sets a checkbox-line edit-length combo group, using "text" if the
97 * checkbox is unchecked and clearing the line edit if it previously
100 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
101 LengthCombo * lengthCombo/*, string text = "auto"*/)
103 if (!checkBox->isChecked())
104 lengthToWidgets(lineEdit, lengthCombo,
105 _(autostr), lengthCombo->currentLengthItem());
106 else if (lineEdit->text() == qt_(autostr))
107 lengthToWidgets(lineEdit, lengthCombo, string(),
108 lengthCombo->currentLengthItem());
112 GuiGraphics::GuiGraphics(GuiView & lv)
113 : GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
118 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
119 this, SLOT(slotButtonBox(QAbstractButton *)));
122 connect(filename, SIGNAL(textChanged(const QString &)),
123 this, SLOT(change_adaptor()));
124 connect(WidthCB, SIGNAL(clicked()),
125 this, SLOT(change_adaptor()));
126 connect(HeightCB, SIGNAL(clicked()),
127 this, SLOT(change_adaptor()));
128 connect(Width, SIGNAL(textChanged(const QString &)),
129 this, SLOT(updateAspectRatioStatus()));
130 connect(Width, SIGNAL(textChanged(const QString &)),
131 this, SLOT(change_adaptor()));
132 connect(Height, SIGNAL(textChanged(const QString &)),
133 this, SLOT(updateAspectRatioStatus()));
134 connect(Height, SIGNAL(textChanged(const QString &)),
135 this, SLOT(change_adaptor()));
136 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
137 this, SLOT(change_adaptor()));
138 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
139 this, SLOT(change_adaptor()));
140 connect(aspectratio, SIGNAL(stateChanged(int)),
141 this, SLOT(change_adaptor()));
142 connect(angle, SIGNAL(textChanged(const QString &)),
143 this, SLOT(change_adaptor()));
144 connect(origin, SIGNAL(activated(int)),
145 this, SLOT(change_adaptor()));
146 connect(scaleCB, SIGNAL(clicked()),
147 this, SLOT(change_adaptor()));
148 connect(Scale, SIGNAL(textChanged(const QString &)),
149 this, SLOT(change_adaptor()));
150 connect(rotateOrderCB, SIGNAL(clicked()),
151 this, SLOT(change_adaptor()));
153 filename->setValidator(new PathValidator(true, filename));
154 setFocusProxy(filename);
156 QDoubleValidator * scaleValidator =
157 new DoubleAutoValidator(Scale, qt_(autostr));
158 scaleValidator->setBottom(0);
159 scaleValidator->setDecimals(256); //I guess that will do
160 Scale->setValidator(scaleValidator);
161 Height->setValidator(positiveLengthAutoValidator(Height, qt_(autostr)));
162 Width->setValidator(positiveLengthAutoValidator(Width, qt_(autostr)));
163 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
166 connect(clip, SIGNAL(stateChanged(int)),
167 this, SLOT(change_adaptor()));
168 connect(lbY, SIGNAL(textChanged(const QString &)),
169 this, SLOT(changeBB()));
170 connect(lbYunit, SIGNAL(activated(int)),
171 this, SLOT(changeBB()));
172 connect(rtY, SIGNAL(textChanged(const QString &)),
173 this, SLOT(changeBB()));
174 connect(rtYunit, SIGNAL(activated(int)),
175 this, SLOT(changeBB()));
176 connect(lbX, SIGNAL(textChanged(const QString &)),
177 this, SLOT(changeBB()));
178 connect(lbXunit, SIGNAL(activated(int)),
179 this, SLOT(changeBB()));
180 connect(rtX, SIGNAL(textChanged(const QString &)),
181 this, SLOT(changeBB()));
182 connect(rtXunit, SIGNAL(activated(int)),
183 this, SLOT(changeBB()));
184 connect(getPB, SIGNAL(clicked()),
185 this, SLOT(change_adaptor()));
187 lbX->setValidator(new QDoubleValidator(lbX));
188 lbY->setValidator(new QDoubleValidator(lbY));
189 rtX->setValidator(new QDoubleValidator(rtX));
190 rtY->setValidator(new QDoubleValidator(rtY));
193 connect(latexoptions, SIGNAL(textChanged(const QString &)),
194 this, SLOT(change_adaptor()));
195 connect(draftCB, SIGNAL(stateChanged(int)),
196 this, SLOT(change_adaptor()));
197 connect(displayGB, SIGNAL(clicked(bool)), this, SLOT(change_adaptor()));
198 connect(darkModeCB, SIGNAL(clicked(bool)), this, SLOT(change_adaptor()));
199 connect(displayscale, SIGNAL(textChanged(const QString &)),
200 this, SLOT(change_adaptor()));
201 connect(groupCO, SIGNAL(currentIndexChanged(int)),
202 this, SLOT(changeGroup(int)));
204 displayscale->setValidator(new QIntValidator(displayscale));
206 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
207 bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
208 bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
209 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
210 bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
212 bc().addReadOnly(latexoptions);
213 bc().addReadOnly(filenameL);
214 bc().addReadOnly(filename);
215 bc().addReadOnly(browsePB);
216 bc().addReadOnly(bbFrame);
217 bc().addReadOnly(draftCB);
218 bc().addReadOnly(clip);
219 bc().addReadOnly(displayGB);
220 bc().addReadOnly(darkModeCB);
221 bc().addReadOnly(sizeGB);
222 bc().addReadOnly(rotationGB);
223 bc().addReadOnly(latexoptions);
224 bc().addReadOnly(getPB);
225 bc().addReadOnly(rotateOrderCB);
227 // initialize the length validator
228 bc().addCheckedLineEdit(Scale, scaleCB);
229 bc().addCheckedLineEdit(Width, WidthCB);
230 bc().addCheckedLineEdit(Height, HeightCB);
231 bc().addCheckedLineEdit(displayscale, scaleLA);
232 bc().addCheckedLineEdit(angle, angleL);
233 bc().addCheckedLineEdit(lbX, xL);
234 bc().addCheckedLineEdit(lbY, yL);
235 bc().addCheckedLineEdit(rtX, xL_2);
236 bc().addCheckedLineEdit(rtY, yL_2);
237 bc().addCheckedLineEdit(filename, filenameL);
241 void GuiGraphics::change_adaptor()
247 void GuiGraphics::changeGroup(int /* index */)
249 QString const new_group = groupCO->itemData(
250 groupCO->currentIndex()).toString();
252 // check if the old group consisted only of this member
253 if (current_group_ != fromqstr(new_group)
254 && graphics::countGroupMembers(buffer(), current_group_) == 1) {
255 if (!new_group.isEmpty()) {
256 if (Alert::prompt(_("Dissolve previous group?"),
257 bformat(_("If you assign this graphic to group '%2$s',\n"
258 "the previously assigned group '%1$s' will be dissolved,\n"
259 "because this graphic was its only member.\n"
260 "How do you want to proceed?"),
261 from_utf8(current_group_), qstring_to_ucs4(new_group)),
263 bformat(_("Stick with group '%1$s'"),
264 from_utf8(current_group_)),
265 bformat(_("Assign to group '%1$s' anyway"),
266 qstring_to_ucs4(new_group))) == 0) {
267 groupCO->setCurrentIndex(
268 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
272 if (Alert::prompt(_("Dissolve previous group?"),
273 bformat(_("If you sign off this graphic from group '%1$s',\n"
274 "the group will be dissolved,\n"
275 "because this graphic was its only member.\n"
276 "How do you want to proceed?"),
277 from_utf8(current_group_)),
279 bformat(_("Stick with group '%1$s'"),
280 from_utf8(current_group_)),
281 bformat(_("Sign off from group '%1$s'"),
282 from_utf8(current_group_))) == 0) {
283 groupCO->setCurrentIndex(
284 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
290 if (new_group.isEmpty()) {
295 string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
297 // group does not exist yet
302 // filename might have been changed
303 QString current_filename = filename->text();
305 // group exists: load params into the dialog
306 groupCO->blockSignals(true);
307 InsetGraphics::string2params(grp, buffer(), params_);
308 paramsToDialog(params_);
309 groupCO->blockSignals(false);
312 filename->setText(current_filename);
318 void GuiGraphics::on_newGroupPB_clicked()
321 if (!Alert::askForText(newgroup, _("Enter unique group name:")))
323 if (newgroup.empty())
325 if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
326 Alert::warning(_("Group already defined!"),
327 bformat(_("A graphics group with the name '%1$s' already exists."),
331 groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
332 groupCO->setCurrentIndex(
333 groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
337 void GuiGraphics::changeBB()
340 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
345 void GuiGraphics::on_browsePB_clicked()
347 QString const str = browse(filename->text());
348 if (!str.isEmpty()) {
349 filename->setText(str);
355 void GuiGraphics::on_getPB_clicked()
361 void GuiGraphics::setAutoText()
363 if (scaleCB->isChecked())
365 if (!Scale->isEnabled() && Scale->text() != "100")
366 Scale->setText("100");
368 setAutoTextCB(WidthCB, Width, widthUnit);
369 setAutoTextCB(HeightCB, Height, heightUnit);
373 void GuiGraphics::on_scaleCB_toggled(bool setScale)
375 Scale->setEnabled(setScale);
377 Scale->setText("100");
378 Scale->setFocus(Qt::OtherFocusReason);
381 WidthCB->setDisabled(setScale);
382 WidthCB->blockSignals(true);
383 WidthCB->setChecked(false);
384 WidthCB->blockSignals(false);
385 Width->setEnabled(false);
386 widthUnit->setEnabled(false);
388 HeightCB->setDisabled(setScale);
389 HeightCB->blockSignals(true);
390 HeightCB->setChecked(false);
391 HeightCB->blockSignals(false);
392 Height->setEnabled(false);
393 heightUnit->setEnabled(false);
395 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
396 HeightCB->isChecked() ||
397 scaleCB->isChecked()) &&
398 (angle->text() != "0"));
401 updateAspectRatioStatus();
405 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
407 Width->setEnabled(setWidth);
408 widthUnit->setEnabled(setWidth);
410 Width->setFocus(Qt::OtherFocusReason);
412 bool const setHeight = HeightCB->isChecked();
413 scaleCB->setEnabled(!setWidth && !setHeight);
414 //already will be unchecked, so don't need to do that
415 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
416 && scaleCB->isChecked()); //should be false, but let's check
417 rotateOrderCB->setEnabled((setWidth || setHeight ||
418 scaleCB->isChecked()) &&
419 (angle->text() != "0"));
422 updateAspectRatioStatus();
426 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
428 Height->setEnabled(setHeight);
429 heightUnit->setEnabled(setHeight);
431 Height->setFocus(Qt::OtherFocusReason);
433 bool const setWidth = WidthCB->isChecked();
434 scaleCB->setEnabled(!setWidth && !setHeight);
436 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
437 && scaleCB->isChecked()); //should be false
438 rotateOrderCB->setEnabled((setWidth || setHeight ||
439 scaleCB->isChecked()) &&
440 (angle->text() != "0"));
443 updateAspectRatioStatus();
447 void GuiGraphics::updateAspectRatioStatus()
449 // keepaspectratio only makes sense if both a width _and_ a
450 // height are given, since its function is (see graphics manual):
451 // "If set to true then specifying both 'width' and 'height'
452 // (or 'totalheight') does not distort the figure but scales
453 // such that neither of the specified dimensions is _exceeded_."
454 aspectratio->setEnabled(
455 WidthCB->isChecked() && !Width->text().isEmpty()
456 && Width->text() != qt_(autostr)
457 && HeightCB->isChecked() && !Height->text().isEmpty()
458 && Height->text() != qt_(autostr)
460 if (!aspectratio->isEnabled())
461 aspectratio->setChecked(false);
465 void GuiGraphics::on_aspectratio_toggled(bool aspect_ratio)
468 WidthCB->setText(qt_("Set max. &width:"));
469 HeightCB->setText(qt_("Set max. &height:"));
470 Width->setToolTip(qt_("Maximal width of image in output"));
471 Height->setToolTip(qt_("Maximal height of image in output"));
473 WidthCB->setText(qt_("Set &width:"));
474 HeightCB->setText(qt_("Set &height:"));
475 Width->setToolTip(qt_("Width of image in output"));
476 Height->setToolTip(qt_("Height of image in output"));
481 void GuiGraphics::on_angle_textChanged(const QString & file_name)
483 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
484 HeightCB->isChecked() ||
485 scaleCB->isChecked()) &&
490 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & params)
492 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
493 static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in[[unit of measure]]") };
494 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
501 for (size_t i = 0; i < bb_size; i++) {
502 lbXunit->addItem(qt_(bb_units_gui[i]),
503 toqstr(bb_units[i]));
504 lbYunit->addItem(qt_(bb_units_gui[i]),
505 toqstr(bb_units[i]));
506 rtXunit->addItem(qt_(bb_units_gui[i]),
507 toqstr(bb_units[i]));
508 rtYunit->addItem(qt_(bb_units_gui[i]),
509 toqstr(bb_units[i]));
512 // set the right default unit
513 Length::UNIT const defaultUnit = Length::defaultUnit();
515 //lyxerr << bufferFilePath();
517 params.filename.outputFileName(fromqstr(bufferFilePath()));
518 filename->setText(toqstr(name));
520 // set the bounding box values
521 if (params.bbox.empty()) {
522 string const bb = readBoundingBox(params.filename.absFileName());
523 // the values from the file always have the bigpoint-unit bp
524 doubleToWidget(lbX, token(bb, ' ', 0));
525 doubleToWidget(lbY, token(bb, ' ', 1));
526 doubleToWidget(rtX, token(bb, ' ', 2));
527 doubleToWidget(rtY, token(bb, ' ', 3));
528 lbXunit->setCurrentIndex(0);
529 lbYunit->setCurrentIndex(0);
530 rtXunit->setCurrentIndex(0);
531 rtYunit->setCurrentIndex(0);
534 // get the values from the inset
535 doubleToWidget(lbX, params.bbox.xl.value());
536 string unit = unit_name[params.bbox.xl.unit()];
537 lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
538 doubleToWidget(lbY, params.bbox.yb.value());
539 unit = unit_name[params.bbox.yb.unit()];
540 lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
541 doubleToWidget(rtX, params.bbox.xr.value());
542 unit = unit_name[params.bbox.xr.unit()];
543 rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
544 doubleToWidget(rtY, params.bbox.yt.value());
545 unit = unit_name[params.bbox.yt.unit()];
546 rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
550 // Update the draft and clip mode
551 draftCB->setChecked(params.draft);
552 clip->setChecked(params.clip);
553 darkModeCB->setChecked(params.darkModeSensitive);
554 displayGB->setChecked(params.display);
555 displayscale->setText(toqstr(convert<string>(params.lyxscale)));
557 // the output section (width/height)
559 doubleToWidget(Scale, params.scale);
560 //igp.scale defaults to 100, so we treat it as empty
561 bool const scaleChecked = !params.scale.empty() && params.scale != "100";
562 scaleCB->blockSignals(true);
563 scaleCB->setChecked(scaleChecked);
564 scaleCB->blockSignals(false);
565 Scale->setEnabled(scaleChecked);
566 displayGB->setEnabled(lyxrc.display_graphics);
569 graphics::getGraphicsGroups(buffer(), grp);
570 set<string>::const_iterator it = grp.begin();
571 set<string>::const_iterator end = grp.end();
572 groupCO->blockSignals(true);
574 for (; it != end; ++it)
575 groupCO->addItem(toqstr(*it), toqstr(*it));
576 groupCO->insertItem(0, qt_("None"), QString());
577 if (params.groupId.empty())
578 groupCO->setCurrentIndex(0);
580 groupCO->setCurrentIndex(
581 groupCO->findData(toqstr(params.groupId), Qt::MatchExactly));
582 groupCO->blockSignals(false);
584 if (params.width.value() == 0)
585 lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
587 lengthToWidgets(Width, widthUnit, params.width, defaultUnit);
589 bool const widthChecked = !Width->text().isEmpty() &&
590 Width->text() != qt_(autostr);
591 WidthCB->blockSignals(true);
592 WidthCB->setChecked(widthChecked);
593 WidthCB->blockSignals(false);
594 Width->setEnabled(widthChecked);
595 widthUnit->setEnabled(widthChecked);
597 if (params.height.value() == 0)
598 lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
600 lengthToWidgets(Height, heightUnit, params.height, defaultUnit);
602 bool const heightChecked = !Height->text().isEmpty()
603 && Height->text() != qt_(autostr);
604 HeightCB->blockSignals(true);
605 HeightCB->setChecked(heightChecked);
606 HeightCB->blockSignals(false);
607 Height->setEnabled(heightChecked);
608 heightUnit->setEnabled(heightChecked);
610 scaleCB->setEnabled(!widthChecked && !heightChecked);
611 WidthCB->setEnabled(!scaleChecked);
612 HeightCB->setEnabled(!scaleChecked);
615 updateAspectRatioStatus();
617 doubleToWidget(angle, params.rotateAngle);
618 rotateOrderCB->setChecked(params.scaleBeforeRotation);
620 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
621 && params.rotateAngle != "0");
625 for (size_t i = 0; i < rorigin_size; i++) {
626 origin->addItem(qt_(rorigin_gui_strs[i]),
627 toqstr(rorigin_lyx_strs[i]));
630 if (!params.rotateOrigin.empty())
631 origin->setCurrentIndex(origin->findData(toqstr(params.rotateOrigin)));
633 origin->setCurrentIndex(0);
636 latexoptions->setText(toqstr(params.special));
638 filename->setFocus();
642 void GuiGraphics::applyView()
644 InsetGraphicsParams & igp = params_;
646 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
649 igp.bbox = graphics::BoundingBox();
651 string lbXs = widgetToDoubleStr(lbX);
652 string lbYs = widgetToDoubleStr(lbY);
653 string rtXs = widgetToDoubleStr(rtX);
654 string rtYs = widgetToDoubleStr(rtY);
656 convert<int>(lbXs) + convert<int>(lbYs) +
657 convert<int>(rtXs) + convert<int>(rtXs);
661 igp.bbox.xl = Length(lbXs + fromqstr(lbXunit->currentText()));
664 igp.bbox.yb = Length(lbYs + fromqstr(lbYunit->currentText()));
667 igp.bbox.xr = Length(rtXs + fromqstr(rtXunit->currentText()));
670 igp.bbox.yt = Length(rtYs + fromqstr(rtYunit->currentText()));
674 igp.draft = draftCB->isChecked();
675 igp.clip = clip->isChecked();
676 igp.display = displayGB->isChecked();
677 igp.darkModeSensitive = darkModeCB->isChecked();
679 //the graphics section
680 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
681 igp.scale = widgetToDoubleStr(Scale);
682 igp.width = Length("0pt");
683 igp.height = Length("0pt");
684 igp.keepAspectRatio = false;
686 igp.scale = string();
687 igp.width = WidthCB->isChecked() ?
688 //Note that this works even if Width is "auto", since in
689 //that case we get "0pt".
690 Length(widgetsToLength(Width, widthUnit)):
692 igp.height = HeightCB->isChecked() ?
693 Length(widgetsToLength(Height, heightUnit)) :
695 igp.keepAspectRatio = aspectratio->isChecked();
698 igp.lyxscale = displayscale->text().toInt();
699 igp.rotateAngle = widgetToDoubleStr(angle);
701 double rotAngle = widgetToDouble(angle);
702 if (abs(rotAngle) > 360.0) {
703 rotAngle -= 360.0 * floor(rotAngle / 360.0);
704 igp.rotateAngle = convert<string>(rotAngle);
707 // save the latex name for the origin. If it is the default
708 // then origin_ltx returns ""
710 fromqstr(origin->itemData(origin->currentIndex()).toString());
711 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
713 // more latex options
714 igp.special = fromqstr(latexoptions->text());
716 igp.groupId = fromqstr(groupCO->itemData(
717 groupCO->currentIndex()).toString());
718 current_group_ = igp.groupId;
722 void GuiGraphics::getBB()
724 string const fn = fromqstr(filename->text());
727 string const bb = readBoundingBox(fn);
731 doubleToWidget(lbX, token(bb, ' ', 0));
732 doubleToWidget(lbY, token(bb, ' ', 1));
733 doubleToWidget(rtX, token(bb, ' ', 2));
734 doubleToWidget(rtY, token(bb, ' ', 3));
735 // the default units for the bb values when reading
737 lbXunit->setCurrentIndex(0);
738 lbYunit->setCurrentIndex(0);
739 rtXunit->setCurrentIndex(0);
740 rtYunit->setCurrentIndex(0);
744 bool GuiGraphics::isValid()
746 return !filename->text().isEmpty();
750 bool GuiGraphics::initialiseParams(string const & sdata)
752 InsetGraphics::string2params(sdata, buffer(), params_);
753 paramsToDialog(params_);
754 current_group_ = params_.groupId;
759 void GuiGraphics::clearParams()
761 params_ = InsetGraphicsParams();
765 void GuiGraphics::dispatchParams()
767 InsetGraphicsParams tmp_params(params_);
768 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
769 dispatch(FuncRequest(getLfun(), lfun));
774 QString GuiGraphics::browse(QString const & in_name) const
776 QString const title = qt_("Select graphics file");
778 // Does user clipart directory exist?
779 string clipdir = addName(package().user_support().absFileName(), "clipart");
780 FileName fclip(clipdir);
782 // bail out to system clipart directory
783 if (!fclip.isDirectory())
784 clipdir = addName(package().system_support().absFileName(), "clipart");
786 return browseRelToParent(in_name, bufferFilePath(),
787 title, fileFilters(QString()), false,
788 qt_("&Clipart"), toqstr(clipdir),
789 qt_("D&ocuments"), toqstr(lyxrc.document_path));
793 string GuiGraphics::readBoundingBox(string const & file)
795 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath()));
797 // With (E)PS files, try to get it from the file, if possible.
798 // Zipped files are unzipped in the readBB_from_PSFile-Function
799 string const bb = graphics::readBB_from_PSFile(abs_file);
803 // With other formats, we try to read the file dimensions
807 // First ask the Graphics Cache if it has loaded the file
808 graphics::Cache & gc = graphics::Cache::get();
809 if (gc.inCache(abs_file)) {
810 graphics::Image const * image = gc.item(abs_file)->image();
813 width = image->width();
814 height = image->height();
817 // If not, construct a QImage and get the values from that
818 QImage image(toqstr(abs_file.absoluteFilePath()));
819 if (!image.isNull()) {
820 width = image.width();
821 height = image.height();
825 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
829 bool GuiGraphics::isFileNameValid(string const & fname) const
831 // It may be that the filename is relative.
832 return support::makeAbsPath(fname, fromqstr(bufferFilePath())).isReadableFile();
836 } // namespace frontend
839 #include "moc_GuiGraphics.cpp"