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 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"
28 #include "graphics/epstools.h"
29 #include "graphics/GraphicsCache.h"
30 #include "graphics/GraphicsCacheItem.h"
31 #include "graphics/GraphicsImage.h"
33 #include "insets/InsetGraphics.h"
35 #include "support/convert.h"
36 #include "support/debug.h"
37 #include "support/filetools.h"
38 #include "support/gettext.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(unsignedLengthAutoValidator(Height, qt_(autostr)));
162 Width->setValidator(unsignedLengthAutoValidator(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 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
198 // the toggled(bool) signal is also triggered when we update the widgets
199 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
200 // using blockSignals() to keep from triggering that signal when we call
201 // setChecked(). Note, too, that clicked() would get called whenever it
202 // is clicked, even right clicked (I think), not just whenever it is
204 connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
205 connect(displayscale, SIGNAL(textChanged(const QString &)),
206 this, SLOT(change_adaptor()));
207 connect(groupCO, SIGNAL(currentIndexChanged(int)),
208 this, SLOT(changeGroup(int)));
210 displayscale->setValidator(new QIntValidator(displayscale));
212 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
213 bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
214 bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
215 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
216 bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
218 bc().addReadOnly(latexoptions);
219 bc().addReadOnly(filenameL);
220 bc().addReadOnly(filename);
221 bc().addReadOnly(browsePB);
222 bc().addReadOnly(bbFrame);
223 bc().addReadOnly(draftCB);
224 bc().addReadOnly(clip);
225 bc().addReadOnly(displayGB);
226 bc().addReadOnly(sizeGB);
227 bc().addReadOnly(rotationGB);
228 bc().addReadOnly(latexoptions);
229 bc().addReadOnly(getPB);
230 bc().addReadOnly(rotateOrderCB);
232 // initialize the length validator
233 bc().addCheckedLineEdit(Scale, scaleCB);
234 bc().addCheckedLineEdit(Width, WidthCB);
235 bc().addCheckedLineEdit(Height, HeightCB);
236 bc().addCheckedLineEdit(displayscale, scaleLA);
237 bc().addCheckedLineEdit(angle, angleL);
238 bc().addCheckedLineEdit(lbX, xL);
239 bc().addCheckedLineEdit(lbY, yL);
240 bc().addCheckedLineEdit(rtX, xL_2);
241 bc().addCheckedLineEdit(rtY, yL_2);
242 bc().addCheckedLineEdit(filename, filenameL);
246 void GuiGraphics::change_adaptor()
252 void GuiGraphics::changeGroup(int /* index */)
254 QString const new_group = groupCO->itemData(
255 groupCO->currentIndex()).toString();
257 // check if the old group consisted only of this member
258 if (current_group_ != fromqstr(new_group)
259 && graphics::countGroupMembers(buffer(), current_group_) == 1) {
260 if (!new_group.isEmpty()) {
261 if (Alert::prompt(_("Dissolve previous group?"),
262 bformat(_("If you assign this graphic to group '%2$s',\n"
263 "the previously assigned group '%1$s' will be dissolved,\n"
264 "because this graphic was its only member.\n"
265 "How do you want to proceed?"),
266 from_utf8(current_group_), qstring_to_ucs4(new_group)),
268 bformat(_("Stick with group '%1$s'"),
269 from_utf8(current_group_)),
270 bformat(_("Assign to group '%1$s' anyway"),
271 qstring_to_ucs4(new_group))) == 0) {
272 groupCO->setCurrentIndex(
273 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
277 if (Alert::prompt(_("Dissolve previous group?"),
278 bformat(_("If you sign off this graphic from group '%1$s',\n"
279 "the group will be dissolved,\n"
280 "because this graphic was its only member.\n"
281 "How do you want to proceed?"),
282 from_utf8(current_group_)),
284 bformat(_("Stick with group '%1$s'"),
285 from_utf8(current_group_)),
286 bformat(_("Sign off from group '%1$s'"),
287 from_utf8(current_group_))) == 0) {
288 groupCO->setCurrentIndex(
289 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
295 if (new_group.isEmpty()) {
300 string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
302 // group does not exist yet
307 // filename might have been changed
308 QString current_filename = filename->text();
310 // group exists: load params into the dialog
311 groupCO->blockSignals(true);
312 InsetGraphics::string2params(grp, buffer(), params_);
313 paramsToDialog(params_);
314 groupCO->blockSignals(false);
317 filename->setText(current_filename);
323 void GuiGraphics::on_newGroupPB_clicked()
326 if (!Alert::askForText(newgroup, _("Enter unique group name:")))
328 if (newgroup.empty())
330 if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
331 Alert::warning(_("Group already defined!"),
332 bformat(_("A graphics group with the name '%1$s' already exists."),
336 groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
337 groupCO->setCurrentIndex(
338 groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
342 void GuiGraphics::changeBB()
345 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
350 void GuiGraphics::on_browsePB_clicked()
352 QString const str = browse(filename->text());
353 if (!str.isEmpty()) {
354 filename->setText(str);
360 void GuiGraphics::on_getPB_clicked()
366 void GuiGraphics::setAutoText()
368 if (scaleCB->isChecked())
370 if (!Scale->isEnabled() && Scale->text() != "100")
371 Scale->setText(qt_(autostr));
373 setAutoTextCB(WidthCB, Width, widthUnit);
374 setAutoTextCB(HeightCB, Height, heightUnit);
378 void GuiGraphics::on_scaleCB_toggled(bool setScale)
380 Scale->setEnabled(setScale);
382 Scale->setText("100");
383 Scale->setFocus(Qt::OtherFocusReason);
386 WidthCB->setDisabled(setScale);
387 WidthCB->blockSignals(true);
388 WidthCB->setChecked(false);
389 WidthCB->blockSignals(false);
390 Width->setEnabled(false);
391 widthUnit->setEnabled(false);
393 HeightCB->setDisabled(setScale);
394 HeightCB->blockSignals(true);
395 HeightCB->setChecked(false);
396 HeightCB->blockSignals(false);
397 Height->setEnabled(false);
398 heightUnit->setEnabled(false);
400 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
401 HeightCB->isChecked() ||
402 scaleCB->isChecked()) &&
403 (angle->text() != "0"));
406 updateAspectRatioStatus();
410 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
412 Width->setEnabled(setWidth);
413 widthUnit->setEnabled(setWidth);
415 Width->setFocus(Qt::OtherFocusReason);
417 bool const setHeight = HeightCB->isChecked();
418 scaleCB->setEnabled(!setWidth && !setHeight);
419 //already will be unchecked, so don't need to do that
420 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
421 && scaleCB->isChecked()); //should be false, but let's check
422 rotateOrderCB->setEnabled((setWidth || setHeight ||
423 scaleCB->isChecked()) &&
424 (angle->text() != "0"));
427 updateAspectRatioStatus();
431 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
433 Height->setEnabled(setHeight);
434 heightUnit->setEnabled(setHeight);
436 Height->setFocus(Qt::OtherFocusReason);
438 bool const setWidth = WidthCB->isChecked();
439 scaleCB->setEnabled(!setWidth && !setHeight);
441 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
442 && scaleCB->isChecked()); //should be false
443 rotateOrderCB->setEnabled((setWidth || setHeight ||
444 scaleCB->isChecked()) &&
445 (angle->text() != "0"));
448 updateAspectRatioStatus();
452 void GuiGraphics::updateAspectRatioStatus()
454 // keepaspectratio only makes sense if both a width _and_ a
455 // height are given, since its function is (see graphics manual):
456 // "If set to true then specifying both 'width' and 'height'
457 // (or 'totalheight') does not distort the figure but scales
458 // such that neither of the specified dimensions is _exceeded_."
459 aspectratio->setEnabled(
460 WidthCB->isChecked() && !Width->text().isEmpty()
461 && Width->text() != qt_(autostr)
462 && HeightCB->isChecked() && !Height->text().isEmpty()
463 && Height->text() != qt_(autostr)
465 if (!aspectratio->isEnabled())
466 aspectratio->setChecked(false);
470 void GuiGraphics::on_aspectratio_toggled(bool aspect_ratio)
473 WidthCB->setText(qt_("Set max. &width:"));
474 HeightCB->setText(qt_("Set max. &height:"));
475 Width->setToolTip(qt_("Maximal width of image in output"));
476 Height->setToolTip(qt_("Maximal height of image in output"));
478 WidthCB->setText(qt_("Set &width:"));
479 HeightCB->setText(qt_("Set &height:"));
480 Width->setToolTip(qt_("Width of image in output"));
481 Height->setToolTip(qt_("Height of image in output"));
486 void GuiGraphics::on_angle_textChanged(const QString & file_name)
488 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
489 HeightCB->isChecked() ||
490 scaleCB->isChecked()) &&
495 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
497 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
498 static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in[[unit of measure]]") };
499 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
506 for (size_t i = 0; i < bb_size; i++) {
507 lbXunit->addItem(qt_(bb_units_gui[i]),
508 toqstr(bb_units[i]));
509 lbYunit->addItem(qt_(bb_units_gui[i]),
510 toqstr(bb_units[i]));
511 rtXunit->addItem(qt_(bb_units_gui[i]),
512 toqstr(bb_units[i]));
513 rtYunit->addItem(qt_(bb_units_gui[i]),
514 toqstr(bb_units[i]));
517 // set the right default unit
518 Length::UNIT const defaultUnit = Length::defaultUnit();
520 //lyxerr << bufferFilePath();
522 igp.filename.outputFileName(fromqstr(bufferFilePath()));
523 filename->setText(toqstr(name));
525 // set the bounding box values
526 if (igp.bbox.empty()) {
527 string const bb = readBoundingBox(igp.filename.absFileName());
528 // the values from the file always have the bigpoint-unit bp
529 doubleToWidget(lbX, token(bb, ' ', 0));
530 doubleToWidget(lbY, token(bb, ' ', 1));
531 doubleToWidget(rtX, token(bb, ' ', 2));
532 doubleToWidget(rtY, token(bb, ' ', 3));
533 lbXunit->setCurrentIndex(0);
534 lbYunit->setCurrentIndex(0);
535 rtXunit->setCurrentIndex(0);
536 rtYunit->setCurrentIndex(0);
539 // get the values from the inset
540 doubleToWidget(lbX, igp.bbox.xl.value());
541 string unit = unit_name[igp.bbox.xl.unit()];
542 lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
543 doubleToWidget(lbY, igp.bbox.yb.value());
544 unit = unit_name[igp.bbox.yb.unit()];
545 lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
546 doubleToWidget(rtX, igp.bbox.xr.value());
547 unit = unit_name[igp.bbox.xr.unit()];
548 rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
549 doubleToWidget(rtY, igp.bbox.yt.value());
550 unit = unit_name[igp.bbox.yt.unit()];
551 rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
555 // Update the draft and clip mode
556 draftCB->setChecked(igp.draft);
557 clip->setChecked(igp.clip);
558 displayGB->setChecked(igp.display);
559 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
561 // the output section (width/height)
563 doubleToWidget(Scale, igp.scale);
564 //igp.scale defaults to 100, so we treat it as empty
565 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
566 scaleCB->blockSignals(true);
567 scaleCB->setChecked(scaleChecked);
568 scaleCB->blockSignals(false);
569 Scale->setEnabled(scaleChecked);
570 displayGB->setEnabled(lyxrc.display_graphics);
573 graphics::getGraphicsGroups(buffer(), grp);
574 set<string>::const_iterator it = grp.begin();
575 set<string>::const_iterator end = grp.end();
576 groupCO->blockSignals(true);
578 for (; it != end; ++it)
579 groupCO->addItem(toqstr(*it), toqstr(*it));
580 groupCO->insertItem(0, qt_("None"), QString());
581 if (igp.groupId.empty())
582 groupCO->setCurrentIndex(0);
584 groupCO->setCurrentIndex(
585 groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
586 groupCO->blockSignals(false);
588 if (igp.width.value() == 0)
589 lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
591 lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
593 bool const widthChecked = !Width->text().isEmpty() &&
594 Width->text() != qt_(autostr);
595 WidthCB->blockSignals(true);
596 WidthCB->setChecked(widthChecked);
597 WidthCB->blockSignals(false);
598 Width->setEnabled(widthChecked);
599 widthUnit->setEnabled(widthChecked);
601 if (igp.height.value() == 0)
602 lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
604 lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
606 bool const heightChecked = !Height->text().isEmpty()
607 && Height->text() != qt_(autostr);
608 HeightCB->blockSignals(true);
609 HeightCB->setChecked(heightChecked);
610 HeightCB->blockSignals(false);
611 Height->setEnabled(heightChecked);
612 heightUnit->setEnabled(heightChecked);
614 scaleCB->setEnabled(!widthChecked && !heightChecked);
615 WidthCB->setEnabled(!scaleChecked);
616 HeightCB->setEnabled(!scaleChecked);
619 updateAspectRatioStatus();
621 doubleToWidget(angle, igp.rotateAngle);
622 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
624 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
625 && igp.rotateAngle != "0");
629 for (size_t i = 0; i < rorigin_size; i++) {
630 origin->addItem(qt_(rorigin_gui_strs[i]),
631 toqstr(rorigin_lyx_strs[i]));
634 if (!igp.rotateOrigin.empty())
635 origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
637 origin->setCurrentIndex(0);
640 latexoptions->setText(toqstr(igp.special));
642 filename->setFocus();
646 void GuiGraphics::applyView()
648 InsetGraphicsParams & igp = params_;
650 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
653 igp.bbox = graphics::BoundingBox();
655 string lbXs = widgetToDoubleStr(lbX);
656 string lbYs = widgetToDoubleStr(lbY);
657 string rtXs = widgetToDoubleStr(rtX);
658 string rtYs = widgetToDoubleStr(rtY);
660 convert<int>(lbXs) + convert<int>(lbYs) +
661 convert<int>(rtXs) + convert<int>(rtXs);
665 igp.bbox.xl = Length(lbXs + fromqstr(lbXunit->currentText()));
668 igp.bbox.yb = Length(lbYs + fromqstr(lbYunit->currentText()));
671 igp.bbox.xr = Length(rtXs + fromqstr(rtXunit->currentText()));
674 igp.bbox.yt = Length(rtYs + fromqstr(rtYunit->currentText()));
678 igp.draft = draftCB->isChecked();
679 igp.clip = clip->isChecked();
680 igp.display = displayGB->isChecked();
682 //the graphics section
683 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
684 igp.scale = widgetToDoubleStr(Scale);
685 igp.width = Length("0pt");
686 igp.height = Length("0pt");
687 igp.keepAspectRatio = false;
689 igp.scale = string();
690 igp.width = WidthCB->isChecked() ?
691 //Note that this works even if Width is "auto", since in
692 //that case we get "0pt".
693 Length(widgetsToLength(Width, widthUnit)):
695 igp.height = HeightCB->isChecked() ?
696 Length(widgetsToLength(Height, heightUnit)) :
698 igp.keepAspectRatio = aspectratio->isChecked();
701 igp.lyxscale = displayscale->text().toInt();
702 igp.rotateAngle = widgetToDoubleStr(angle);
704 double rotAngle = widgetToDouble(angle);
705 if (abs(rotAngle) > 360.0) {
706 rotAngle -= 360.0 * floor(rotAngle / 360.0);
707 igp.rotateAngle = convert<string>(rotAngle);
710 // save the latex name for the origin. If it is the default
711 // then origin_ltx returns ""
713 fromqstr(origin->itemData(origin->currentIndex()).toString());
714 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
716 // more latex options
717 igp.special = fromqstr(latexoptions->text());
719 igp.groupId = fromqstr(groupCO->itemData(
720 groupCO->currentIndex()).toString());
721 current_group_ = igp.groupId;
725 void GuiGraphics::getBB()
727 string const fn = fromqstr(filename->text());
730 string const bb = readBoundingBox(fn);
734 doubleToWidget(lbX, token(bb, ' ', 0));
735 doubleToWidget(lbY, token(bb, ' ', 1));
736 doubleToWidget(rtX, token(bb, ' ', 2));
737 doubleToWidget(rtY, token(bb, ' ', 3));
738 // the default units for the bb values when reading
740 lbXunit->setCurrentIndex(0);
741 lbYunit->setCurrentIndex(0);
742 rtXunit->setCurrentIndex(0);
743 rtYunit->setCurrentIndex(0);
747 bool GuiGraphics::isValid()
749 return !filename->text().isEmpty();
753 bool GuiGraphics::initialiseParams(string const & sdata)
755 InsetGraphics::string2params(sdata, buffer(), params_);
756 paramsToDialog(params_);
757 current_group_ = params_.groupId;
762 void GuiGraphics::clearParams()
764 params_ = InsetGraphicsParams();
768 void GuiGraphics::dispatchParams()
770 InsetGraphicsParams tmp_params(params_);
771 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
772 dispatch(FuncRequest(getLfun(), lfun));
776 QString GuiGraphics::browse(QString const & in_name) const
778 QString const title = qt_("Select graphics file");
780 // Does user clipart directory exist?
781 string clipdir = addName(package().user_support().absFileName(), "clipart");
782 FileName fclip(clipdir);
784 // bail out to system clipart directory
785 if (!fclip.isDirectory())
786 clipdir = addName(package().system_support().absFileName(), "clipart");
788 return browseRelToParent(in_name, bufferFilePath(),
789 title, fileFilters(QString()), false,
790 qt_("&Clipart"), toqstr(clipdir),
791 qt_("D&ocuments"), toqstr(lyxrc.document_path));
795 string GuiGraphics::readBoundingBox(string const & file)
797 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath()));
799 // try to get it from the file, if possible. Zipped files are
800 // unzipped in the readBB_from_PSFile-Function
801 string const bb = graphics::readBB_from_PSFile(abs_file);
805 // we don't, so ask the Graphics Cache if it has loaded the file
809 graphics::Cache & gc = graphics::Cache::get();
810 if (gc.inCache(abs_file)) {
811 graphics::Image const * image = gc.item(abs_file)->image();
814 width = image->width();
815 height = image->height();
819 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
823 bool GuiGraphics::isFileNameValid(string const & fname) const
825 // It may be that the filename is relative.
826 return support::makeAbsPath(fname, fromqstr(bufferFilePath())).isReadableFile();
830 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
833 } // namespace frontend
836 #include "moc_GuiGraphics.cpp"