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"))
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(updateAspectRatioStatus()));
132 connect(Width, SIGNAL(textChanged(const QString &)),
133 this, SLOT(change_adaptor()));
134 connect(Height, SIGNAL(textChanged(const QString &)),
135 this, SLOT(updateAspectRatioStatus()));
136 connect(Height, SIGNAL(textChanged(const QString &)),
137 this, SLOT(change_adaptor()));
138 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
139 this, SLOT(change_adaptor()));
140 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
141 this, SLOT(change_adaptor()));
142 connect(aspectratio, SIGNAL(stateChanged(int)),
143 this, SLOT(change_adaptor()));
144 connect(angle, SIGNAL(textChanged(const QString &)),
145 this, SLOT(change_adaptor()));
146 connect(origin, SIGNAL(activated(int)),
147 this, SLOT(change_adaptor()));
148 connect(scaleCB, SIGNAL(clicked()),
149 this, SLOT(change_adaptor()));
150 connect(Scale, SIGNAL(textChanged(const QString &)),
151 this, SLOT(change_adaptor()));
152 connect(rotateOrderCB, SIGNAL(clicked()),
153 this, SLOT(change_adaptor()));
155 filename->setValidator(new PathValidator(true, filename));
156 setFocusProxy(filename);
158 QDoubleValidator * scaleValidator =
159 new DoubleAutoValidator(Scale, qt_(autostr));
160 scaleValidator->setBottom(0);
161 scaleValidator->setDecimals(256); //I guess that will do
162 Scale->setValidator(scaleValidator);
163 Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
164 Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
165 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
168 connect(clip, SIGNAL(stateChanged(int)),
169 this, SLOT(change_adaptor()));
170 connect(lbY, SIGNAL(textChanged(const QString&)),
171 this, SLOT(changeBB()));
172 connect(lbYunit, SIGNAL(activated(int)),
173 this, SLOT(changeBB()));
174 connect(rtY, SIGNAL(textChanged(const QString&)),
175 this, SLOT(changeBB()));
176 connect(rtYunit, SIGNAL(activated(int)),
177 this, SLOT(changeBB()));
178 connect(lbX, SIGNAL(textChanged(const QString&)),
179 this, SLOT(changeBB()));
180 connect(lbXunit, SIGNAL(activated(int)),
181 this, SLOT(changeBB()));
182 connect(rtX, SIGNAL(textChanged(const QString&)),
183 this, SLOT(changeBB()));
184 connect(rtXunit, SIGNAL(activated(int)),
185 this, SLOT(changeBB()));
186 connect(getPB, SIGNAL(clicked()),
187 this, SLOT(change_adaptor()));
189 lbX->setValidator(new QDoubleValidator(lbX));
190 lbY->setValidator(new QDoubleValidator(lbY));
191 rtX->setValidator(new QDoubleValidator(rtX));
192 rtY->setValidator(new QDoubleValidator(rtY));
195 connect(latexoptions, SIGNAL(textChanged(const QString&)),
196 this, SLOT(change_adaptor()));
197 connect(draftCB, SIGNAL(stateChanged(int)),
198 this, SLOT(change_adaptor()));
199 connect(unzipCB, SIGNAL(stateChanged(int)),
200 this, SLOT(change_adaptor()));
201 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
202 // the toggled(bool) signal is also trigged when we update the widgets
203 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
204 // using blockSignals() to keep from triggering that signal when we call
205 // setChecked(). Note, too, that clicked() would get called whenever it
206 // is clicked, even right clicked (I think), not just whenever it is
208 connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
209 connect(displayscale, SIGNAL(textChanged(const QString&)),
210 this, SLOT(change_adaptor()));
211 connect(groupCO, SIGNAL(currentIndexChanged(int)),
212 this, SLOT(changeGroup(int)));
214 displayscale->setValidator(new QIntValidator(displayscale));
216 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
218 bc().setApply(applyPB);
219 bc().setRestore(restorePB);
220 bc().setCancel(closePB);
222 bc().addReadOnly(latexoptions);
223 bc().addReadOnly(filenameL);
224 bc().addReadOnly(filename);
225 bc().addReadOnly(browsePB);
226 bc().addReadOnly(unzipCB);
227 bc().addReadOnly(bbFrame);
228 bc().addReadOnly(draftCB);
229 bc().addReadOnly(clip);
230 bc().addReadOnly(unzipCB);
231 bc().addReadOnly(displayGB);
232 bc().addReadOnly(sizeGB);
233 bc().addReadOnly(rotationGB);
234 bc().addReadOnly(latexoptions);
235 bc().addReadOnly(getPB);
236 bc().addReadOnly(rotateOrderCB);
238 // initialize the length validator
239 bc().addCheckedLineEdit(Scale, scaleCB);
240 bc().addCheckedLineEdit(Width, WidthCB);
241 bc().addCheckedLineEdit(Height, HeightCB);
242 bc().addCheckedLineEdit(displayscale, scaleLA);
243 bc().addCheckedLineEdit(angle, angleL);
244 bc().addCheckedLineEdit(lbX, xL);
245 bc().addCheckedLineEdit(lbY, yL);
246 bc().addCheckedLineEdit(rtX, xL_2);
247 bc().addCheckedLineEdit(rtY, yL_2);
248 bc().addCheckedLineEdit(filename, filenameL);
252 void GuiGraphics::change_adaptor()
258 void GuiGraphics::changeGroup(int /* index */)
260 QString const new_group = groupCO->itemData(
261 groupCO->currentIndex()).toString();
263 // check if the old group consisted only of this member
264 if (current_group_ != fromqstr(new_group)
265 && graphics::countGroupMembers(buffer(), current_group_) == 1) {
266 if (!new_group.isEmpty()) {
267 if (Alert::prompt(_("Dissolve previous group?"),
268 bformat(_("If you assign this graphic to group '%2$s',\n"
269 "the previously assigned group '%1$s' will be dissolved,\n"
270 "because this graphic was its only member.\n"
271 "How do you want to proceed?"),
272 from_utf8(current_group_), qstring_to_ucs4(new_group)),
274 bformat(_("Stick with group '%1$s'"),
275 from_utf8(current_group_)),
276 bformat(_("Assign to group '%1$s' anyway"),
277 qstring_to_ucs4(new_group))) == 0) {
278 groupCO->setCurrentIndex(
279 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
283 if (Alert::prompt(_("Dissolve previous group?"),
284 bformat(_("If you sign off this graphic from group '%1$s',\n"
285 "the group will be dissolved,\n"
286 "because this graphic was its only member.\n"
287 "How do you want to proceed?"),
288 from_utf8(current_group_)),
290 bformat(_("Stick with group '%1$s'"),
291 from_utf8(current_group_)),
292 bformat(_("Sign off from group '%1$s'"),
293 from_utf8(current_group_))) == 0) {
294 groupCO->setCurrentIndex(
295 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
301 if (new_group.isEmpty()) {
306 string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
308 // group does not exist yet
313 // filename might have been changed
314 QString current_filename = filename->text();
316 // group exists: load params into the dialog
317 groupCO->blockSignals(true);
318 InsetGraphics::string2params(grp, buffer(), params_);
319 paramsToDialog(params_);
320 groupCO->blockSignals(false);
323 filename->setText(current_filename);
329 void GuiGraphics::on_newGroupPB_clicked()
332 if (!Alert::askForText(newgroup, _("Enter unique group name:")))
334 if (newgroup.empty())
336 if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
337 Alert::warning(_("Group already defined!"),
338 bformat(_("A graphics group with the name '%1$s' already exists."),
342 groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
343 groupCO->setCurrentIndex(
344 groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
348 void GuiGraphics::changeBB()
351 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
356 void GuiGraphics::on_browsePB_clicked()
358 QString const str = browse(filename->text());
359 if (!str.isEmpty()) {
360 filename->setText(str);
366 void GuiGraphics::on_getPB_clicked()
372 void GuiGraphics::setAutoText()
374 if (scaleCB->isChecked())
376 if (!Scale->isEnabled() && Scale->text() != "100")
377 Scale->setText(qt_(autostr));
379 setAutoTextCB(WidthCB, Width, widthUnit);
380 setAutoTextCB(HeightCB, Height, heightUnit);
384 void GuiGraphics::on_scaleCB_toggled(bool setScale)
386 Scale->setEnabled(setScale);
388 Scale->setText("100");
389 Scale->setFocus(Qt::OtherFocusReason);
392 WidthCB->setDisabled(setScale);
393 WidthCB->blockSignals(true);
394 WidthCB->setChecked(false);
395 WidthCB->blockSignals(false);
396 Width->setEnabled(false);
397 widthUnit->setEnabled(false);
399 HeightCB->setDisabled(setScale);
400 HeightCB->blockSignals(true);
401 HeightCB->setChecked(false);
402 HeightCB->blockSignals(false);
403 Height->setEnabled(false);
404 heightUnit->setEnabled(false);
406 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
407 HeightCB->isChecked() ||
408 scaleCB->isChecked()) &&
409 (angle->text() != "0"));
412 updateAspectRatioStatus();
416 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
418 Width->setEnabled(setWidth);
419 widthUnit->setEnabled(setWidth);
421 Width->setFocus(Qt::OtherFocusReason);
423 bool const setHeight = HeightCB->isChecked();
424 scaleCB->setEnabled(!setWidth && !setHeight);
425 //already will be unchecked, so don't need to do that
426 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
427 && scaleCB->isChecked()); //should be false, but let's check
428 rotateOrderCB->setEnabled((setWidth || setHeight ||
429 scaleCB->isChecked()) &&
430 (angle->text() != "0"));
433 updateAspectRatioStatus();
437 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
439 Height->setEnabled(setHeight);
440 heightUnit->setEnabled(setHeight);
442 Height->setFocus(Qt::OtherFocusReason);
444 bool const setWidth = WidthCB->isChecked();
445 scaleCB->setEnabled(!setWidth && !setHeight);
447 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
448 && scaleCB->isChecked()); //should be false
449 rotateOrderCB->setEnabled((setWidth || setHeight ||
450 scaleCB->isChecked()) &&
451 (angle->text() != "0"));
454 updateAspectRatioStatus();
458 void GuiGraphics::updateAspectRatioStatus()
460 // keepaspectratio only makes sense if both a width _and_ a
461 // height are given, since its function is (see graphics manual):
462 // "If set to true then specifying both 'width' and 'height'
463 // (or 'totalheight') does not distort the figure but scales
464 // such that neither of the specified dimensions is _exceeded_."
465 aspectratio->setEnabled(
466 WidthCB->isChecked() && !Width->text().isEmpty()
467 && Width->text() != qt_(autostr)
468 && HeightCB->isChecked() && !Height->text().isEmpty()
469 && Height->text() != qt_(autostr)
471 if (!aspectratio->isEnabled())
472 aspectratio->setChecked(false);
476 void GuiGraphics::on_aspectratio_toggled(bool aspectratio)
479 WidthCB->setText(qt_("Set max. &width:"));
480 HeightCB->setText(qt_("Set max. &height:"));
481 Width->setToolTip(qt_("Maximal width of image in output"));
482 Height->setToolTip(qt_("Maximal height of image in output"));
484 WidthCB->setText(qt_("Set &width:"));
485 HeightCB->setText(qt_("Set &height:"));
486 Width->setToolTip(qt_("Width of image in output"));
487 Height->setToolTip(qt_("Height of image in output"));
492 void GuiGraphics::on_angle_textChanged(const QString & filename)
494 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
495 HeightCB->isChecked() ||
496 scaleCB->isChecked()) &&
501 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
503 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
504 static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in[[unit of measure]]") };
505 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
512 for (size_t i = 0; i < bb_size; i++) {
513 lbXunit->addItem(qt_(bb_units_gui[i]),
514 toqstr(bb_units[i]));
515 lbYunit->addItem(qt_(bb_units_gui[i]),
516 toqstr(bb_units[i]));
517 rtXunit->addItem(qt_(bb_units_gui[i]),
518 toqstr(bb_units[i]));
519 rtYunit->addItem(qt_(bb_units_gui[i]),
520 toqstr(bb_units[i]));
523 // set the right default unit
524 Length::UNIT const defaultUnit = Length::defaultUnit();
526 //lyxerr << bufferFilePath();
528 igp.filename.outputFileName(fromqstr(bufferFilePath()));
529 filename->setText(toqstr(name));
531 // set the bounding box values
532 if (igp.bb.empty()) {
533 string const bb = readBoundingBox(igp.filename.absFileName());
534 // the values from the file always have the bigpoint-unit bp
535 doubleToWidget(lbX, token(bb, ' ', 0));
536 doubleToWidget(lbY, token(bb, ' ', 1));
537 doubleToWidget(rtX, token(bb, ' ', 2));
538 doubleToWidget(rtY, token(bb, ' ', 3));
539 lbXunit->setCurrentIndex(0);
540 lbYunit->setCurrentIndex(0);
541 rtXunit->setCurrentIndex(0);
542 rtYunit->setCurrentIndex(0);
545 // get the values from the inset
547 string const xl = token(igp.bb, ' ', 0);
548 string const yl = token(igp.bb, ' ', 1);
549 string const xr = token(igp.bb, ' ', 2);
550 string const yr = token(igp.bb, ' ', 3);
551 if (isValidLength(xl, &anyLength)) {
552 doubleToWidget(lbX, anyLength.value());
553 string const unit = unit_name[anyLength.unit()];
554 lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
556 lbX->setText(toqstr(xl));
558 if (isValidLength(yl, &anyLength)) {
559 doubleToWidget(lbY, anyLength.value());
560 string const unit = unit_name[anyLength.unit()];
561 lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
563 lbY->setText(toqstr(xl));
565 if (isValidLength(xr, &anyLength)) {
566 doubleToWidget(rtX, anyLength.value());
567 string const unit = unit_name[anyLength.unit()];
568 rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
570 rtX->setText(toqstr(xl));
572 if (isValidLength(yr, &anyLength)) {
573 doubleToWidget(rtY, anyLength.value());
574 string const unit = unit_name[anyLength.unit()];
575 rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
577 rtY->setText(toqstr(xl));
582 // Update the draft and clip mode
583 draftCB->setChecked(igp.draft);
584 clip->setChecked(igp.clip);
585 unzipCB->setChecked(igp.noUnzip);
586 displayGB->setChecked(igp.display);
587 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
589 // the output section (width/height)
591 doubleToWidget(Scale, igp.scale);
592 //igp.scale defaults to 100, so we treat it as empty
593 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
594 scaleCB->blockSignals(true);
595 scaleCB->setChecked(scaleChecked);
596 scaleCB->blockSignals(false);
597 Scale->setEnabled(scaleChecked);
598 displayGB->setEnabled(lyxrc.display_graphics);
601 graphics::getGraphicsGroups(buffer(), grp);
602 set<string>::const_iterator it = grp.begin();
603 set<string>::const_iterator end = grp.end();
604 groupCO->blockSignals(true);
606 for (; it != end; ++it)
607 groupCO->addItem(toqstr(*it), toqstr(*it));
608 groupCO->insertItem(0, qt_("None"), QString());
609 if (igp.groupId.empty())
610 groupCO->setCurrentIndex(0);
612 groupCO->setCurrentIndex(
613 groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
614 groupCO->blockSignals(false);
616 if (igp.width.value() == 0)
617 lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
619 lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
621 bool const widthChecked = !Width->text().isEmpty() &&
622 Width->text() != qt_(autostr);
623 WidthCB->blockSignals(true);
624 WidthCB->setChecked(widthChecked);
625 WidthCB->blockSignals(false);
626 Width->setEnabled(widthChecked);
627 widthUnit->setEnabled(widthChecked);
629 if (igp.height.value() == 0)
630 lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
632 lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
634 bool const heightChecked = !Height->text().isEmpty()
635 && Height->text() != qt_(autostr);
636 HeightCB->blockSignals(true);
637 HeightCB->setChecked(heightChecked);
638 HeightCB->blockSignals(false);
639 Height->setEnabled(heightChecked);
640 heightUnit->setEnabled(heightChecked);
642 scaleCB->setEnabled(!widthChecked && !heightChecked);
643 WidthCB->setEnabled(!scaleChecked);
644 HeightCB->setEnabled(!scaleChecked);
647 updateAspectRatioStatus();
649 doubleToWidget(angle, igp.rotateAngle);
650 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
652 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
653 && igp.rotateAngle != "0");
657 for (size_t i = 0; i < rorigin_size; i++) {
658 origin->addItem(qt_(rorigin_gui_strs[i]),
659 toqstr(rorigin_lyx_strs[i]));
662 if (!igp.rotateOrigin.empty())
663 origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
665 origin->setCurrentIndex(0);
668 latexoptions->setText(toqstr(igp.special));
670 filename->setFocus();
674 void GuiGraphics::applyView()
676 InsetGraphicsParams & igp = params_;
678 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
684 string lbXs = widgetToDoubleStr(lbX);
685 string lbYs = widgetToDoubleStr(lbY);
686 string rtXs = widgetToDoubleStr(rtX);
687 string rtYs = widgetToDoubleStr(rtY);
689 convert<int>(lbXs) + convert<int>(lbYs) +
690 convert<int>(rtXs) + convert<int>(rtXs);
695 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
699 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
703 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
707 bb += (rtYs + fromqstr(rtYunit->currentText()));
712 igp.draft = draftCB->isChecked();
713 igp.clip = clip->isChecked();
714 igp.display = displayGB->isChecked();
716 //the graphics section
717 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
718 igp.scale = widgetToDoubleStr(Scale);
719 igp.width = Length("0pt");
720 igp.height = Length("0pt");
721 igp.keepAspectRatio = false;
723 igp.scale = string();
724 igp.width = WidthCB->isChecked() ?
725 //Note that this works even if Width is "auto", since in
726 //that case we get "0pt".
727 Length(widgetsToLength(Width, widthUnit)):
729 igp.height = HeightCB->isChecked() ?
730 Length(widgetsToLength(Height, heightUnit)) :
732 igp.keepAspectRatio = aspectratio->isChecked();
735 igp.noUnzip = unzipCB->isChecked();
736 igp.lyxscale = displayscale->text().toInt();
737 igp.rotateAngle = widgetToDoubleStr(angle);
739 double rotAngle = widgetToDouble(angle);
740 if (abs(rotAngle) > 360.0) {
741 rotAngle -= 360.0 * floor(rotAngle / 360.0);
742 igp.rotateAngle = convert<string>(rotAngle);
745 // save the latex name for the origin. If it is the default
746 // then origin_ltx returns ""
748 fromqstr(origin->itemData(origin->currentIndex()).toString());
749 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
751 // more latex options
752 igp.special = fromqstr(latexoptions->text());
754 igp.groupId = fromqstr(groupCO->itemData(
755 groupCO->currentIndex()).toString());
756 current_group_ = igp.groupId;
760 void GuiGraphics::getBB()
762 string const fn = fromqstr(filename->text());
765 string const bb = readBoundingBox(fn);
769 doubleToWidget(lbX, token(bb, ' ', 0));
770 doubleToWidget(lbY, token(bb, ' ', 1));
771 doubleToWidget(rtX, token(bb, ' ', 2));
772 doubleToWidget(rtY, token(bb, ' ', 3));
773 // the default units for the bb values when reading
775 lbXunit->setCurrentIndex(0);
776 lbYunit->setCurrentIndex(0);
777 rtXunit->setCurrentIndex(0);
778 rtYunit->setCurrentIndex(0);
782 bool GuiGraphics::isValid()
784 return !filename->text().isEmpty();
788 bool GuiGraphics::initialiseParams(string const & data)
790 InsetGraphics::string2params(data, buffer(), params_);
791 paramsToDialog(params_);
792 current_group_ = params_.groupId;
797 void GuiGraphics::clearParams()
799 params_ = InsetGraphicsParams();
803 void GuiGraphics::dispatchParams()
805 InsetGraphicsParams tmp_params(params_);
806 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
807 dispatch(FuncRequest(getLfun(), lfun));
811 QString GuiGraphics::browse(QString const & in_name) const
813 QString const title = qt_("Select graphics file");
815 // Does user clipart directory exist?
816 string clipdir = addName(package().user_support().absFileName(), "clipart");
817 FileName clip(clipdir);
819 // bail out to system clipart directory
820 if (!clip.isDirectory())
821 clipdir = addName(package().system_support().absFileName(), "clipart");
823 return browseRelToParent(in_name, bufferFilePath(),
824 title, fileFilters(QString()), false,
825 qt_("Clipart|#C#c"), toqstr(clipdir),
826 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
830 string GuiGraphics::readBoundingBox(string const & file)
832 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath()));
834 // try to get it from the file, if possible. Zipped files are
835 // unzipped in the readBB_from_PSFile-Function
836 string const bb = graphics::readBB_from_PSFile(abs_file);
840 // we don't, so ask the Graphics Cache if it has loaded the file
844 graphics::Cache & gc = graphics::Cache::get();
845 if (gc.inCache(abs_file)) {
846 graphics::Image const * image = gc.item(abs_file)->image();
849 width = image->width();
850 height = image->height();
854 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
858 bool GuiGraphics::isFileNameValid(string const & fname) const
860 // It may be that the filename is relative.
861 return support::makeAbsPath(fname, fromqstr(bufferFilePath())).isReadableFile();
865 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
868 } // namespace frontend
871 #include "moc_GuiGraphics.cpp"