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());
113 vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
115 size_t const n = pr.size();
116 vector<typename Pair::first_type> tmp(n);
117 for (size_t i = 0; i != n; ++i)
118 tmp[i] = pr[i].first;
125 vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
127 size_t const n = pr.size();
128 vector<typename Pair::second_type> tmp(n);
129 for (size_t i = 0; i != n; ++i)
130 tmp[i] = pr[i].second;
135 /// The (tranlated) GUI string and it's LaTeX equivalent.
136 typedef pair<docstring, string> RotationOriginPair;
138 vector<RotationOriginPair> getRotationOriginData()
140 static vector<RotationOriginPair> data;
144 data.resize(rorigin_size);
145 for (size_type i = 0; i < rorigin_size; ++i) {
146 data[i] = make_pair(_(rorigin_gui_strs[i]),
147 rorigin_lyx_strs[i]);
155 GuiGraphics::GuiGraphics(GuiView & lv)
156 : GuiDialog(lv, "graphics", qt_("Graphics"))
161 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
162 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
163 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
164 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
167 connect(filename, SIGNAL(textChanged(const QString &)),
168 this, SLOT(change_adaptor()));
169 connect(WidthCB, SIGNAL(clicked()),
170 this, SLOT(change_adaptor()));
171 connect(HeightCB, SIGNAL(clicked()),
172 this, SLOT(change_adaptor()));
173 connect(Width, SIGNAL(textChanged(const QString &)),
174 this, SLOT(change_adaptor()));
175 connect(Height, SIGNAL(textChanged(const QString &)),
176 this, SLOT(change_adaptor()));
177 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
178 this, SLOT(change_adaptor()));
179 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
180 this, SLOT(change_adaptor()));
181 connect(aspectratio, SIGNAL(stateChanged(int)),
182 this, SLOT(change_adaptor()));
183 connect(angle, SIGNAL(textChanged(const QString &)),
184 this, SLOT(change_adaptor()));
185 connect(origin, SIGNAL(activated(int)),
186 this, SLOT(change_adaptor()));
187 connect(scaleCB, SIGNAL(clicked()),
188 this, SLOT(change_adaptor()));
189 connect(Scale, SIGNAL(textChanged(const QString &)),
190 this, SLOT(change_adaptor()));
191 connect(rotateOrderCB, SIGNAL(clicked()),
192 this, SLOT(change_adaptor()));
194 filename->setValidator(new PathValidator(true, filename));
195 setFocusProxy(filename);
197 QDoubleValidator * scaleValidator =
198 new DoubleAutoValidator(Scale, qt_(autostr));
199 scaleValidator->setBottom(0);
200 scaleValidator->setDecimals(256); //I guess that will do
201 Scale->setValidator(scaleValidator);
202 Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
203 Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
204 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
207 connect(clip, SIGNAL(stateChanged(int)),
208 this, SLOT(change_adaptor()));
209 connect(lbY, SIGNAL(textChanged(const QString&)),
210 this, SLOT(change_bb()));
211 connect(lbYunit, SIGNAL(activated(int)),
212 this, SLOT(change_bb()));
213 connect(rtY, SIGNAL(textChanged(const QString&)),
214 this, SLOT(change_bb()));
215 connect(rtYunit, SIGNAL(activated(int)),
216 this, SLOT(change_bb()));
217 connect(lbX, SIGNAL(textChanged(const QString&)),
218 this, SLOT(change_bb()));
219 connect(lbXunit, SIGNAL(activated(int)),
220 this, SLOT(change_bb()));
221 connect(rtX, SIGNAL(textChanged(const QString&)),
222 this, SLOT(change_bb()));
223 connect(rtXunit, SIGNAL(activated(int)),
224 this, SLOT(change_bb()));
225 connect(getPB, SIGNAL(clicked()),
226 this, SLOT(change_adaptor()));
228 lbX->setValidator(new QDoubleValidator(lbX));
229 lbY->setValidator(new QDoubleValidator(lbY));
230 rtX->setValidator(new QDoubleValidator(rtX));
231 rtY->setValidator(new QDoubleValidator(rtY));
234 connect(latexoptions, SIGNAL(textChanged(const QString&)),
235 this, SLOT(change_adaptor()));
236 connect(draftCB, SIGNAL(stateChanged(int)),
237 this, SLOT(change_adaptor()));
238 connect(unzipCB, SIGNAL(stateChanged(int)),
239 this, SLOT(change_adaptor()));
240 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
241 // the toggled(bool) signal is also trigged when we update the widgets
242 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
243 // using blockSignals() to keep from triggering that signal when we call
244 // setChecked(). Note, too, that clicked() would get called whenever it
245 // is clicked, even right clicked (I think), not just whenever it is
247 connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
248 connect(displayscale, SIGNAL(textChanged(const QString&)),
249 this, SLOT(change_adaptor()));
250 connect(groupCO, SIGNAL(currentIndexChanged(int)),
251 this, SLOT(change_group(int)));
253 displayscale->setValidator(new QIntValidator(displayscale));
255 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
257 bc().setApply(applyPB);
258 bc().setRestore(restorePB);
259 bc().setCancel(closePB);
261 bc().addReadOnly(latexoptions);
262 bc().addReadOnly(filenameL);
263 bc().addReadOnly(filename);
264 bc().addReadOnly(browsePB);
265 bc().addReadOnly(unzipCB);
266 bc().addReadOnly(bbFrame);
267 bc().addReadOnly(draftCB);
268 bc().addReadOnly(clip);
269 bc().addReadOnly(unzipCB);
270 bc().addReadOnly(displayGB);
271 bc().addReadOnly(sizeGB);
272 bc().addReadOnly(rotationGB);
273 bc().addReadOnly(latexoptions);
274 bc().addReadOnly(getPB);
275 bc().addReadOnly(rotateOrderCB);
277 // initialize the length validator
278 bc().addCheckedLineEdit(Scale, scaleCB);
279 bc().addCheckedLineEdit(Width, WidthCB);
280 bc().addCheckedLineEdit(Height, HeightCB);
281 bc().addCheckedLineEdit(displayscale, scaleLA);
282 bc().addCheckedLineEdit(angle, angleL);
283 bc().addCheckedLineEdit(lbX, xL);
284 bc().addCheckedLineEdit(lbY, yL);
285 bc().addCheckedLineEdit(rtX, xL_2);
286 bc().addCheckedLineEdit(rtY, yL_2);
287 bc().addCheckedLineEdit(filename, filenameL);
291 void GuiGraphics::change_adaptor()
297 void GuiGraphics::change_group(int /* index */)
299 QString const new_group = groupCO->itemData(
300 groupCO->currentIndex()).toString();
302 // check if the old group consisted only of this member
303 if (current_group_ != fromqstr(new_group)
304 && graphics::countGroupMembers(buffer(), current_group_) == 1) {
305 if (!new_group.isEmpty()) {
306 if (Alert::prompt(_("Dissolve previous group?"),
307 bformat(_("If you assign this graphic to group '%2$s',\n"
308 "the previously assigned group '%1$s' will be dissolved,\n"
309 "because this graphic was its only member.\n"
310 "How do you want to proceed?"),
311 from_utf8(current_group_), qstring_to_ucs4(new_group)),
313 bformat(_("Stick with group '%1$s'"),
314 from_utf8(current_group_)),
315 bformat(_("Assign to group '%1$s' anyway"),
316 qstring_to_ucs4(new_group))) == 0) {
317 groupCO->setCurrentIndex(
318 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
322 if (Alert::prompt(_("Dissolve previous group?"),
323 bformat(_("If you sign off this graphic from group '%1$s',\n"
324 "the group will be dissolved,\n"
325 "because this graphic was its only member.\n"
326 "How do you want to proceed?"),
327 from_utf8(current_group_)),
329 bformat(_("Stick with group '%1$s'"),
330 from_utf8(current_group_)),
331 bformat(_("Sign off from group '%1$s'"),
332 from_utf8(current_group_))) == 0) {
333 groupCO->setCurrentIndex(
334 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
340 if (new_group.isEmpty()) {
345 string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
347 // group does not exist yet
352 // filename might have been changed
353 QString current_filename = filename->text();
355 // group exists: load params into the dialog
356 groupCO->blockSignals(true);
357 InsetGraphics::string2params(grp, buffer(), params_);
358 paramsToDialog(params_);
359 groupCO->blockSignals(false);
362 filename->setText(current_filename);
368 void GuiGraphics::on_newGroupPB_clicked()
371 if (!Alert::askForText(newgroup, _("Enter unique group name:")))
373 if (newgroup.empty())
375 if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
376 Alert::warning(_("Group already defined!"),
377 bformat(_("A graphics group with the name '%1$s' already exists."),
381 groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
382 groupCO->setCurrentIndex(
383 groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
387 void GuiGraphics::change_bb()
390 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
395 void GuiGraphics::on_browsePB_clicked()
397 QString const str = browse(filename->text());
398 if (!str.isEmpty()) {
399 filename->setText(str);
405 void GuiGraphics::on_getPB_clicked()
411 void GuiGraphics::setAutoText()
413 if (scaleCB->isChecked())
415 if (!Scale->isEnabled() && Scale->text() != "100")
416 Scale->setText(qt_(autostr));
418 setAutoTextCB(WidthCB, Width, widthUnit);
419 setAutoTextCB(HeightCB, Height, heightUnit);
423 void GuiGraphics::on_scaleCB_toggled(bool setScale)
425 Scale->setEnabled(setScale);
427 Scale->setText("100");
428 Scale->setFocus(Qt::OtherFocusReason);
431 WidthCB->setDisabled(setScale);
432 WidthCB->blockSignals(true);
433 WidthCB->setChecked(false);
434 WidthCB->blockSignals(false);
435 Width->setEnabled(false);
436 widthUnit->setEnabled(false);
438 HeightCB->setDisabled(setScale);
439 HeightCB->blockSignals(true);
440 HeightCB->setChecked(false);
441 HeightCB->blockSignals(false);
442 Height->setEnabled(false);
443 heightUnit->setEnabled(false);
445 aspectratio->setDisabled(true);
446 aspectratio->setChecked(true);
448 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
449 HeightCB->isChecked() ||
450 scaleCB->isChecked()) &&
451 (angle->text() != "0"));
457 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
459 Width->setEnabled(setWidth);
460 widthUnit->setEnabled(setWidth);
462 Width->setFocus(Qt::OtherFocusReason);
464 bool const setHeight = HeightCB->isChecked();
465 aspectratio->setEnabled(setWidth && setHeight);
466 aspectratio->blockSignals(true);
467 aspectratio->setChecked(!(setWidth && setHeight));
468 aspectratio->blockSignals(false);
470 scaleCB->setEnabled(!setWidth && !setHeight);
471 //already will be unchecked, so don't need to do that
472 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
473 && scaleCB->isChecked()); //should be false, but let's check
474 rotateOrderCB->setEnabled((setWidth || setHeight ||
475 scaleCB->isChecked()) &&
476 (angle->text() != "0"));
482 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
484 Height->setEnabled(setHeight);
485 heightUnit->setEnabled(setHeight);
487 Height->setFocus(Qt::OtherFocusReason);
489 bool const setWidth = WidthCB->isChecked();
490 aspectratio->setEnabled(setWidth && setHeight);
491 aspectratio->blockSignals(true);
492 aspectratio->setChecked(!(setWidth && setHeight));
493 aspectratio->blockSignals(false);
495 scaleCB->setEnabled(!setWidth && !setHeight);
497 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
498 && scaleCB->isChecked()); //should be false
499 rotateOrderCB->setEnabled((setWidth || setHeight ||
500 scaleCB->isChecked()) &&
501 (angle->text() != "0"));
507 void GuiGraphics::on_angle_textChanged(const QString & filename)
509 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
510 HeightCB->isChecked() ||
511 scaleCB->isChecked()) &&
515 // returns the number of the string s in the vector v
516 static int itemNumber(const vector<string> & v, string const & s)
518 vector<string>::const_iterator cit =
519 find(v.begin(), v.end(), s);
520 return (cit != v.end()) ? int(cit - v.begin()) : 0;
524 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
526 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
527 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
529 vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
534 for (vector<string>::const_iterator it = units.begin();
535 it != units.end(); ++it) {
536 lbXunit->addItem(toqstr(*it));
537 lbYunit->addItem(toqstr(*it));
538 rtXunit->addItem(toqstr(*it));
539 rtYunit->addItem(toqstr(*it));
542 // set the right default unit
543 Length::UNIT const defaultUnit = Length::defaultUnit();
545 //lyxerr << bufferFilepath();
547 igp.filename.outputFilename(fromqstr(bufferFilepath()));
548 filename->setText(toqstr(name));
550 // set the bounding box values
551 if (igp.bb.empty()) {
552 string const bb = readBoundingBox(igp.filename.absFilename());
553 // the values from the file always have the bigpoint-unit bp
554 lbX->setText(toqstr(token(bb, ' ', 0)));
555 lbY->setText(toqstr(token(bb, ' ', 1)));
556 rtX->setText(toqstr(token(bb, ' ', 2)));
557 rtY->setText(toqstr(token(bb, ' ', 3)));
558 lbXunit->setCurrentIndex(0);
559 lbYunit->setCurrentIndex(0);
560 rtXunit->setCurrentIndex(0);
561 rtYunit->setCurrentIndex(0);
564 // get the values from the inset
566 string const xl = token(igp.bb, ' ', 0);
567 string const yl = token(igp.bb, ' ', 1);
568 string const xr = token(igp.bb, ' ', 2);
569 string const yr = token(igp.bb, ' ', 3);
570 if (isValidLength(xl, &anyLength)) {
571 lbX->setText(toqstr(convert<string>(anyLength.value())));
572 string const unit = unit_name[anyLength.unit()];
573 lbXunit->setCurrentIndex(itemNumber(units, unit));
575 lbX->setText(toqstr(xl));
577 if (isValidLength(yl, &anyLength)) {
578 lbY->setText(toqstr(convert<string>(anyLength.value())));
579 string const unit = unit_name[anyLength.unit()];
580 lbYunit->setCurrentIndex(itemNumber(units, unit));
582 lbY->setText(toqstr(xl));
584 if (isValidLength(xr, &anyLength)) {
585 rtX->setText(toqstr(convert<string>(anyLength.value())));
586 string const unit = unit_name[anyLength.unit()];
587 rtXunit->setCurrentIndex(itemNumber(units, unit));
589 rtX->setText(toqstr(xl));
591 if (isValidLength(yr, &anyLength)) {
592 rtY->setText(toqstr(convert<string>(anyLength.value())));
593 string const unit = unit_name[anyLength.unit()];
594 rtYunit->setCurrentIndex(itemNumber(units, unit));
596 rtY->setText(toqstr(xl));
601 // Update the draft and clip mode
602 draftCB->setChecked(igp.draft);
603 clip->setChecked(igp.clip);
604 unzipCB->setChecked(igp.noUnzip);
605 displayGB->setChecked(igp.display);
606 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
608 // the output section (width/height)
610 Scale->setText(toqstr(igp.scale));
611 //igp.scale defaults to 100, so we treat it as empty
612 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
613 scaleCB->blockSignals(true);
614 scaleCB->setChecked(scaleChecked);
615 scaleCB->blockSignals(false);
616 Scale->setEnabled(scaleChecked);
617 displayGB->setEnabled(lyxrc.display_graphics);
620 graphics::getGraphicsGroups(buffer(), grp);
621 set<string>::const_iterator it = grp.begin();
622 set<string>::const_iterator end = grp.end();
623 groupCO->blockSignals(true);
625 for (; it != end; it++)
626 groupCO->addItem(toqstr(*it), toqstr(*it));
627 groupCO->insertItem(0, qt_("None"), QString());
628 if (igp.groupId.empty())
629 groupCO->setCurrentIndex(0);
631 groupCO->setCurrentIndex(
632 groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
633 groupCO->blockSignals(false);
635 if (igp.width.value() == 0)
636 lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
638 lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
640 bool const widthChecked = !Width->text().isEmpty() &&
641 Width->text() != qt_(autostr);
642 WidthCB->blockSignals(true);
643 WidthCB->setChecked(widthChecked);
644 WidthCB->blockSignals(false);
645 Width->setEnabled(widthChecked);
646 widthUnit->setEnabled(widthChecked);
648 if (igp.height.value() == 0)
649 lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
651 lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
653 bool const heightChecked = !Height->text().isEmpty()
654 && Height->text() != qt_(autostr);
655 HeightCB->blockSignals(true);
656 HeightCB->setChecked(heightChecked);
657 HeightCB->blockSignals(false);
658 Height->setEnabled(heightChecked);
659 heightUnit->setEnabled(heightChecked);
661 scaleCB->setEnabled(!widthChecked && !heightChecked);
662 WidthCB->setEnabled(!scaleChecked);
663 HeightCB->setEnabled(!scaleChecked);
664 aspectratio->setEnabled(widthChecked && heightChecked);
668 angle->setText(toqstr(igp.rotateAngle));
669 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
671 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
672 && igp.rotateAngle != "0");
676 vector<RotationOriginPair> origindata = getRotationOriginData();
677 vector<docstring> const origin_lang = getFirst(origindata);
678 origin_ltx = getSecond(origindata);
680 for (vector<docstring>::const_iterator it = origin_lang.begin();
681 it != origin_lang.end(); ++it)
682 origin->addItem(toqstr(*it));
684 if (!igp.rotateOrigin.empty())
685 origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
687 origin->setCurrentIndex(0);
690 latexoptions->setText(toqstr(igp.special));
694 void GuiGraphics::applyView()
696 InsetGraphicsParams & igp = params_;
698 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
704 string lbXs = fromqstr(lbX->text());
705 string lbYs = fromqstr(lbY->text());
706 string rtXs = fromqstr(rtX->text());
707 string rtYs = fromqstr(rtY->text());
709 convert<int>(lbXs) + convert<int>(lbYs) +
710 convert<int>(rtXs) + convert<int>(rtXs);
715 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
719 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
723 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
727 bb += (rtYs + fromqstr(rtYunit->currentText()));
732 igp.draft = draftCB->isChecked();
733 igp.clip = clip->isChecked();
734 igp.display = displayGB->isChecked();
736 //the graphics section
737 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
738 igp.scale = fromqstr(Scale->text());
739 igp.width = Length("0pt");
740 igp.height = Length("0pt");
741 igp.keepAspectRatio = false;
743 igp.scale = string();
744 igp.width = WidthCB->isChecked() ?
745 //Note that this works even if Width is "auto", since in
746 //that case we get "0pt".
747 Length(widgetsToLength(Width, widthUnit)):
749 igp.height = HeightCB->isChecked() ?
750 Length(widgetsToLength(Height, heightUnit)) :
752 igp.keepAspectRatio = aspectratio->isEnabled() &&
753 aspectratio->isChecked() &&
754 igp.width.value() > 0 && igp.height.value() > 0;
757 igp.noUnzip = unzipCB->isChecked();
758 igp.lyxscale = displayscale->text().toInt();
759 igp.rotateAngle = fromqstr(angle->text());
761 double rotAngle = convert<double>(igp.rotateAngle);
762 if (abs(rotAngle) > 360.0) {
763 rotAngle -= 360.0 * floor(rotAngle / 360.0);
764 igp.rotateAngle = convert<string>(rotAngle);
767 // save the latex name for the origin. If it is the default
768 // then origin_ltx returns ""
769 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
770 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
772 // more latex options
773 igp.special = fromqstr(latexoptions->text());
775 igp.groupId = fromqstr(groupCO->itemData(
776 groupCO->currentIndex()).toString());
777 current_group_ = igp.groupId;
781 void GuiGraphics::getBB()
783 string const fn = fromqstr(filename->text());
786 string const bb = readBoundingBox(fn);
790 lbX->setText(toqstr(token(bb, ' ', 0)));
791 lbY->setText(toqstr(token(bb, ' ', 1)));
792 rtX->setText(toqstr(token(bb, ' ', 2)));
793 rtY->setText(toqstr(token(bb, ' ', 3)));
794 // the default units for the bb values when reading
796 lbXunit->setCurrentIndex(0);
797 lbYunit->setCurrentIndex(0);
798 rtXunit->setCurrentIndex(0);
799 rtYunit->setCurrentIndex(0);
803 bool GuiGraphics::isValid()
805 return !filename->text().isEmpty();
809 bool GuiGraphics::initialiseParams(string const & data)
811 InsetGraphics::string2params(data, buffer(), params_);
812 paramsToDialog(params_);
813 current_group_ = params_.groupId;
818 void GuiGraphics::clearParams()
820 params_ = InsetGraphicsParams();
824 void GuiGraphics::dispatchParams()
826 InsetGraphicsParams tmp_params(params_);
827 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
828 dispatch(FuncRequest(getLfun(), lfun));
832 QString GuiGraphics::browse(QString const & in_name) const
834 QString const title = qt_("Select graphics file");
836 // Does user clipart directory exist?
837 string clipdir = addName(package().user_support().absFilename(), "clipart");
838 FileName clip(clipdir);
840 // bail out to system clipart directory
841 if (!clip.isDirectory())
842 clipdir = addName(package().system_support().absFilename(), "clipart");
844 return browseRelFile(in_name, bufferFilepath(),
845 title, fileFilters(QString()), false,
846 qt_("Clipart|#C#c"), toqstr(clipdir),
847 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
851 string GuiGraphics::readBoundingBox(string const & file)
853 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilepath()));
855 // try to get it from the file, if possible. Zipped files are
856 // unzipped in the readBB_from_PSFile-Function
857 string const bb = readBB_from_PSFile(abs_file);
861 // we don't, so ask the Graphics Cache if it has loaded the file
865 graphics::Cache & gc = graphics::Cache::get();
866 if (gc.inCache(abs_file)) {
867 graphics::Image const * image = gc.item(abs_file)->image();
870 width = image->width();
871 height = image->height();
875 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
879 bool GuiGraphics::isFileNameValid(string const & fname) const
881 // It may be that the filename is relative.
882 return support::makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
886 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
889 } // namespace frontend
892 #include "moc_GuiGraphics.cpp"