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"
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 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"))
118 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
119 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
120 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
121 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
124 connect(filename, SIGNAL(textChanged(const QString &)),
125 this, SLOT(change_adaptor()));
126 connect(WidthCB, SIGNAL(clicked()),
127 this, SLOT(change_adaptor()));
128 connect(HeightCB, SIGNAL(clicked()),
129 this, SLOT(change_adaptor()));
130 connect(Width, SIGNAL(textChanged(const QString &)),
131 this, SLOT(change_adaptor()));
132 connect(Height, SIGNAL(textChanged(const QString &)),
133 this, SLOT(change_adaptor()));
134 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
135 this, SLOT(change_adaptor()));
136 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
137 this, SLOT(change_adaptor()));
138 connect(aspectratio, SIGNAL(stateChanged(int)),
139 this, SLOT(change_adaptor()));
140 connect(angle, SIGNAL(textChanged(const QString &)),
141 this, SLOT(change_adaptor()));
142 connect(origin, SIGNAL(activated(int)),
143 this, SLOT(change_adaptor()));
144 connect(scaleCB, SIGNAL(clicked()),
145 this, SLOT(change_adaptor()));
146 connect(Scale, SIGNAL(textChanged(const QString &)),
147 this, SLOT(change_adaptor()));
148 connect(rotateOrderCB, SIGNAL(clicked()),
149 this, SLOT(change_adaptor()));
151 filename->setValidator(new PathValidator(true, filename));
152 setFocusProxy(filename);
154 QDoubleValidator * scaleValidator =
155 new DoubleAutoValidator(Scale, qt_(autostr));
156 scaleValidator->setBottom(0);
157 scaleValidator->setDecimals(256); //I guess that will do
158 Scale->setValidator(scaleValidator);
159 Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
160 Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
161 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
164 connect(clip, SIGNAL(stateChanged(int)),
165 this, SLOT(change_adaptor()));
166 connect(lbY, SIGNAL(textChanged(const QString&)),
167 this, SLOT(changeBB()));
168 connect(lbYunit, SIGNAL(activated(int)),
169 this, SLOT(changeBB()));
170 connect(rtY, SIGNAL(textChanged(const QString&)),
171 this, SLOT(changeBB()));
172 connect(rtYunit, SIGNAL(activated(int)),
173 this, SLOT(changeBB()));
174 connect(lbX, SIGNAL(textChanged(const QString&)),
175 this, SLOT(changeBB()));
176 connect(lbXunit, SIGNAL(activated(int)),
177 this, SLOT(changeBB()));
178 connect(rtX, SIGNAL(textChanged(const QString&)),
179 this, SLOT(changeBB()));
180 connect(rtXunit, SIGNAL(activated(int)),
181 this, SLOT(changeBB()));
182 connect(getPB, SIGNAL(clicked()),
183 this, SLOT(change_adaptor()));
185 lbX->setValidator(new QDoubleValidator(lbX));
186 lbY->setValidator(new QDoubleValidator(lbY));
187 rtX->setValidator(new QDoubleValidator(rtX));
188 rtY->setValidator(new QDoubleValidator(rtY));
191 connect(latexoptions, SIGNAL(textChanged(const QString&)),
192 this, SLOT(change_adaptor()));
193 connect(draftCB, SIGNAL(stateChanged(int)),
194 this, SLOT(change_adaptor()));
195 connect(unzipCB, 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 trigged 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);
214 bc().setApply(applyPB);
215 bc().setRestore(restorePB);
216 bc().setCancel(closePB);
218 bc().addReadOnly(latexoptions);
219 bc().addReadOnly(filenameL);
220 bc().addReadOnly(filename);
221 bc().addReadOnly(browsePB);
222 bc().addReadOnly(unzipCB);
223 bc().addReadOnly(bbFrame);
224 bc().addReadOnly(draftCB);
225 bc().addReadOnly(clip);
226 bc().addReadOnly(unzipCB);
227 bc().addReadOnly(displayGB);
228 bc().addReadOnly(sizeGB);
229 bc().addReadOnly(rotationGB);
230 bc().addReadOnly(latexoptions);
231 bc().addReadOnly(getPB);
232 bc().addReadOnly(rotateOrderCB);
234 // initialize the length validator
235 bc().addCheckedLineEdit(Scale, scaleCB);
236 bc().addCheckedLineEdit(Width, WidthCB);
237 bc().addCheckedLineEdit(Height, HeightCB);
238 bc().addCheckedLineEdit(displayscale, scaleLA);
239 bc().addCheckedLineEdit(angle, angleL);
240 bc().addCheckedLineEdit(lbX, xL);
241 bc().addCheckedLineEdit(lbY, yL);
242 bc().addCheckedLineEdit(rtX, xL_2);
243 bc().addCheckedLineEdit(rtY, yL_2);
244 bc().addCheckedLineEdit(filename, filenameL);
248 void GuiGraphics::change_adaptor()
254 void GuiGraphics::changeGroup(int /* index */)
256 QString const new_group = groupCO->itemData(
257 groupCO->currentIndex()).toString();
259 // check if the old group consisted only of this member
260 if (current_group_ != fromqstr(new_group)
261 && graphics::countGroupMembers(buffer(), current_group_) == 1) {
262 if (!new_group.isEmpty()) {
263 if (Alert::prompt(_("Dissolve previous group?"),
264 bformat(_("If you assign this graphic to group '%2$s',\n"
265 "the previously assigned group '%1$s' will be dissolved,\n"
266 "because this graphic was its only member.\n"
267 "How do you want to proceed?"),
268 from_utf8(current_group_), qstring_to_ucs4(new_group)),
270 bformat(_("Stick with group '%1$s'"),
271 from_utf8(current_group_)),
272 bformat(_("Assign to group '%1$s' anyway"),
273 qstring_to_ucs4(new_group))) == 0) {
274 groupCO->setCurrentIndex(
275 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
279 if (Alert::prompt(_("Dissolve previous group?"),
280 bformat(_("If you sign off this graphic from group '%1$s',\n"
281 "the group will be dissolved,\n"
282 "because this graphic was its only member.\n"
283 "How do you want to proceed?"),
284 from_utf8(current_group_)),
286 bformat(_("Stick with group '%1$s'"),
287 from_utf8(current_group_)),
288 bformat(_("Sign off from group '%1$s'"),
289 from_utf8(current_group_))) == 0) {
290 groupCO->setCurrentIndex(
291 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
297 if (new_group.isEmpty()) {
302 string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
304 // group does not exist yet
309 // filename might have been changed
310 QString current_filename = filename->text();
312 // group exists: load params into the dialog
313 groupCO->blockSignals(true);
314 InsetGraphics::string2params(grp, buffer(), params_);
315 paramsToDialog(params_);
316 groupCO->blockSignals(false);
319 filename->setText(current_filename);
325 void GuiGraphics::on_newGroupPB_clicked()
328 if (!Alert::askForText(newgroup, _("Enter unique group name:")))
330 if (newgroup.empty())
332 if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
333 Alert::warning(_("Group already defined!"),
334 bformat(_("A graphics group with the name '%1$s' already exists."),
338 groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
339 groupCO->setCurrentIndex(
340 groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
344 void GuiGraphics::changeBB()
347 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
352 void GuiGraphics::on_browsePB_clicked()
354 QString const str = browse(filename->text());
355 if (!str.isEmpty()) {
356 filename->setText(str);
362 void GuiGraphics::on_getPB_clicked()
368 void GuiGraphics::setAutoText()
370 if (scaleCB->isChecked())
372 if (!Scale->isEnabled() && Scale->text() != "100")
373 Scale->setText(qt_(autostr));
375 setAutoTextCB(WidthCB, Width, widthUnit);
376 setAutoTextCB(HeightCB, Height, heightUnit);
380 void GuiGraphics::on_scaleCB_toggled(bool setScale)
382 Scale->setEnabled(setScale);
384 Scale->setText("100");
385 Scale->setFocus(Qt::OtherFocusReason);
388 WidthCB->setDisabled(setScale);
389 WidthCB->blockSignals(true);
390 WidthCB->setChecked(false);
391 WidthCB->blockSignals(false);
392 Width->setEnabled(false);
393 widthUnit->setEnabled(false);
395 HeightCB->setDisabled(setScale);
396 HeightCB->blockSignals(true);
397 HeightCB->setChecked(false);
398 HeightCB->blockSignals(false);
399 Height->setEnabled(false);
400 heightUnit->setEnabled(false);
402 aspectratio->setDisabled(true);
403 aspectratio->setChecked(true);
405 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
406 HeightCB->isChecked() ||
407 scaleCB->isChecked()) &&
408 (angle->text() != "0"));
414 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
416 Width->setEnabled(setWidth);
417 widthUnit->setEnabled(setWidth);
419 Width->setFocus(Qt::OtherFocusReason);
421 bool const setHeight = HeightCB->isChecked();
422 aspectratio->setEnabled(setWidth && setHeight);
423 aspectratio->blockSignals(true);
424 aspectratio->setChecked(!(setWidth && setHeight));
425 aspectratio->blockSignals(false);
427 scaleCB->setEnabled(!setWidth && !setHeight);
428 //already will be unchecked, so don't need to do that
429 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
430 && scaleCB->isChecked()); //should be false, but let's check
431 rotateOrderCB->setEnabled((setWidth || setHeight ||
432 scaleCB->isChecked()) &&
433 (angle->text() != "0"));
439 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
441 Height->setEnabled(setHeight);
442 heightUnit->setEnabled(setHeight);
444 Height->setFocus(Qt::OtherFocusReason);
446 bool const setWidth = WidthCB->isChecked();
447 aspectratio->setEnabled(setWidth && setHeight);
448 aspectratio->blockSignals(true);
449 aspectratio->setChecked(!(setWidth && setHeight));
450 aspectratio->blockSignals(false);
452 scaleCB->setEnabled(!setWidth && !setHeight);
454 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
455 && scaleCB->isChecked()); //should be false
456 rotateOrderCB->setEnabled((setWidth || setHeight ||
457 scaleCB->isChecked()) &&
458 (angle->text() != "0"));
464 void GuiGraphics::on_angle_textChanged(const QString & filename)
466 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
467 HeightCB->isChecked() ||
468 scaleCB->isChecked()) &&
472 // returns the number of the string s in the vector v
473 static int itemNumber(const vector<string> & v, string const & s)
475 vector<string>::const_iterator cit =
476 find(v.begin(), v.end(), s);
477 return (cit != v.end()) ? int(cit - v.begin()) : 0;
481 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
483 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
484 static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in") };
485 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
492 for (int i = 0; i < bb_size; i++) {
493 lbXunit->addItem(qt_(bb_units_gui[i]),
494 toqstr(bb_units[i]));
495 lbYunit->addItem(qt_(bb_units_gui[i]),
496 toqstr(bb_units[i]));
497 rtXunit->addItem(qt_(bb_units_gui[i]),
498 toqstr(bb_units[i]));
499 rtYunit->addItem(qt_(bb_units_gui[i]),
500 toqstr(bb_units[i]));
503 // set the right default unit
504 Length::UNIT const defaultUnit = Length::defaultUnit();
506 //lyxerr << bufferFilepath();
508 igp.filename.outputFilename(fromqstr(bufferFilepath()));
509 filename->setText(toqstr(name));
511 // set the bounding box values
512 if (igp.bb.empty()) {
513 string const bb = readBoundingBox(igp.filename.absFilename());
514 // the values from the file always have the bigpoint-unit bp
515 doubleToWidget(lbX, token(bb, ' ', 0));
516 doubleToWidget(lbY, token(bb, ' ', 1));
517 doubleToWidget(rtX, token(bb, ' ', 2));
518 doubleToWidget(rtY, token(bb, ' ', 3));
519 lbXunit->setCurrentIndex(0);
520 lbYunit->setCurrentIndex(0);
521 rtXunit->setCurrentIndex(0);
522 rtYunit->setCurrentIndex(0);
525 // get the values from the inset
527 string const xl = token(igp.bb, ' ', 0);
528 string const yl = token(igp.bb, ' ', 1);
529 string const xr = token(igp.bb, ' ', 2);
530 string const yr = token(igp.bb, ' ', 3);
531 if (isValidLength(xl, &anyLength)) {
532 doubleToWidget(lbX, anyLength.value());
533 string const unit = unit_name[anyLength.unit()];
534 lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
536 lbX->setText(toqstr(xl));
538 if (isValidLength(yl, &anyLength)) {
539 doubleToWidget(lbY, anyLength.value());
540 string const unit = unit_name[anyLength.unit()];
541 lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
543 lbY->setText(toqstr(xl));
545 if (isValidLength(xr, &anyLength)) {
546 doubleToWidget(rtX, anyLength.value());
547 string const unit = unit_name[anyLength.unit()];
548 rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
550 rtX->setText(toqstr(xl));
552 if (isValidLength(yr, &anyLength)) {
553 doubleToWidget(rtY, anyLength.value());
554 string const unit = unit_name[anyLength.unit()];
555 rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
557 rtY->setText(toqstr(xl));
562 // Update the draft and clip mode
563 draftCB->setChecked(igp.draft);
564 clip->setChecked(igp.clip);
565 unzipCB->setChecked(igp.noUnzip);
566 displayGB->setChecked(igp.display);
567 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
569 // the output section (width/height)
571 doubleToWidget(Scale, igp.scale);
572 //igp.scale defaults to 100, so we treat it as empty
573 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
574 scaleCB->blockSignals(true);
575 scaleCB->setChecked(scaleChecked);
576 scaleCB->blockSignals(false);
577 Scale->setEnabled(scaleChecked);
578 displayGB->setEnabled(lyxrc.display_graphics);
581 graphics::getGraphicsGroups(buffer(), grp);
582 set<string>::const_iterator it = grp.begin();
583 set<string>::const_iterator end = grp.end();
584 groupCO->blockSignals(true);
586 for (; it != end; it++)
587 groupCO->addItem(toqstr(*it), toqstr(*it));
588 groupCO->insertItem(0, qt_("None"), QString());
589 if (igp.groupId.empty())
590 groupCO->setCurrentIndex(0);
592 groupCO->setCurrentIndex(
593 groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
594 groupCO->blockSignals(false);
596 if (igp.width.value() == 0)
597 lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
599 lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
601 bool const widthChecked = !Width->text().isEmpty() &&
602 Width->text() != qt_(autostr);
603 WidthCB->blockSignals(true);
604 WidthCB->setChecked(widthChecked);
605 WidthCB->blockSignals(false);
606 Width->setEnabled(widthChecked);
607 widthUnit->setEnabled(widthChecked);
609 if (igp.height.value() == 0)
610 lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
612 lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
614 bool const heightChecked = !Height->text().isEmpty()
615 && Height->text() != qt_(autostr);
616 HeightCB->blockSignals(true);
617 HeightCB->setChecked(heightChecked);
618 HeightCB->blockSignals(false);
619 Height->setEnabled(heightChecked);
620 heightUnit->setEnabled(heightChecked);
622 scaleCB->setEnabled(!widthChecked && !heightChecked);
623 WidthCB->setEnabled(!scaleChecked);
624 HeightCB->setEnabled(!scaleChecked);
625 aspectratio->setEnabled(widthChecked && heightChecked);
629 doubleToWidget(angle, igp.rotateAngle);
630 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
632 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
633 && igp.rotateAngle != "0");
637 for (int i = 0; i < rorigin_size; i++) {
638 origin->addItem(qt_(rorigin_gui_strs[i]),
639 toqstr(rorigin_lyx_strs[i]));
642 if (!igp.rotateOrigin.empty())
643 origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
645 origin->setCurrentIndex(0);
648 latexoptions->setText(toqstr(igp.special));
652 void GuiGraphics::applyView()
654 InsetGraphicsParams & igp = params_;
656 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
662 string lbXs = widgetToDoubleStr(lbX);
663 string lbYs = widgetToDoubleStr(lbY);
664 string rtXs = widgetToDoubleStr(rtX);
665 string rtYs = widgetToDoubleStr(rtY);
667 convert<int>(lbXs) + convert<int>(lbYs) +
668 convert<int>(rtXs) + convert<int>(rtXs);
673 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
677 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
681 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
685 bb += (rtYs + fromqstr(rtYunit->currentText()));
690 igp.draft = draftCB->isChecked();
691 igp.clip = clip->isChecked();
692 igp.display = displayGB->isChecked();
694 //the graphics section
695 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
696 igp.scale = widgetToDoubleStr(Scale);
697 igp.width = Length("0pt");
698 igp.height = Length("0pt");
699 igp.keepAspectRatio = false;
701 igp.scale = string();
702 igp.width = WidthCB->isChecked() ?
703 //Note that this works even if Width is "auto", since in
704 //that case we get "0pt".
705 Length(widgetsToLength(Width, widthUnit)):
707 igp.height = HeightCB->isChecked() ?
708 Length(widgetsToLength(Height, heightUnit)) :
710 igp.keepAspectRatio = aspectratio->isEnabled() &&
711 aspectratio->isChecked() &&
712 igp.width.value() > 0 && igp.height.value() > 0;
715 igp.noUnzip = unzipCB->isChecked();
716 igp.lyxscale = displayscale->text().toInt();
717 igp.rotateAngle = widgetToDoubleStr(angle);
719 double rotAngle = widgetToDouble(angle);
720 if (abs(rotAngle) > 360.0) {
721 rotAngle -= 360.0 * floor(rotAngle / 360.0);
722 igp.rotateAngle = convert<string>(rotAngle);
725 // save the latex name for the origin. If it is the default
726 // then origin_ltx returns ""
728 fromqstr(origin->itemData(origin->currentIndex()).toString());
729 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
731 // more latex options
732 igp.special = fromqstr(latexoptions->text());
734 igp.groupId = fromqstr(groupCO->itemData(
735 groupCO->currentIndex()).toString());
736 current_group_ = igp.groupId;
740 void GuiGraphics::getBB()
742 string const fn = fromqstr(filename->text());
745 string const bb = readBoundingBox(fn);
749 doubleToWidget(lbX, token(bb, ' ', 0));
750 doubleToWidget(lbY, token(bb, ' ', 1));
751 doubleToWidget(rtX, token(bb, ' ', 2));
752 doubleToWidget(rtY, token(bb, ' ', 3));
753 // the default units for the bb values when reading
755 lbXunit->setCurrentIndex(0);
756 lbYunit->setCurrentIndex(0);
757 rtXunit->setCurrentIndex(0);
758 rtYunit->setCurrentIndex(0);
762 bool GuiGraphics::isValid()
764 return !filename->text().isEmpty();
768 bool GuiGraphics::initialiseParams(string const & data)
770 InsetGraphics::string2params(data, buffer(), params_);
771 paramsToDialog(params_);
772 current_group_ = params_.groupId;
777 void GuiGraphics::clearParams()
779 params_ = InsetGraphicsParams();
783 void GuiGraphics::dispatchParams()
785 InsetGraphicsParams tmp_params(params_);
786 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
787 dispatch(FuncRequest(getLfun(), lfun));
791 QString GuiGraphics::browse(QString const & in_name) const
793 QString const title = qt_("Select graphics file");
795 // Does user clipart directory exist?
796 string clipdir = addName(package().user_support().absFilename(), "clipart");
797 FileName clip(clipdir);
799 // bail out to system clipart directory
800 if (!clip.isDirectory())
801 clipdir = addName(package().system_support().absFilename(), "clipart");
803 return browseRelFile(in_name, bufferFilepath(),
804 title, fileFilters(QString()), false,
805 qt_("Clipart|#C#c"), toqstr(clipdir),
806 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
810 string GuiGraphics::readBoundingBox(string const & file)
812 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilepath()));
814 // try to get it from the file, if possible. Zipped files are
815 // unzipped in the readBB_from_PSFile-Function
816 string const bb = readBB_from_PSFile(abs_file);
820 // we don't, so ask the Graphics Cache if it has loaded the file
824 graphics::Cache & gc = graphics::Cache::get();
825 if (gc.inCache(abs_file)) {
826 graphics::Image const * image = gc.item(abs_file)->image();
829 width = image->width();
830 height = image->height();
834 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
838 bool GuiGraphics::isFileNameValid(string const & fname) const
840 // It may be that the filename is relative.
841 return support::makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
845 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
848 } // namespace frontend
851 #include "moc_GuiGraphics.cpp"