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"
19 #include "LengthCombo.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
25 #include "FuncRequest.h"
27 #include "graphics/GraphicsCache.h"
28 #include "graphics/GraphicsCacheItem.h"
29 #include "graphics/GraphicsImage.h"
31 #include "insets/InsetGraphicsParams.h"
33 #include "support/convert.h"
34 #include "support/debug.h"
35 #include "support/filetools.h"
36 #include "support/gettext.h"
37 #include "support/lstrings.h"
38 #include "support/os.h"
39 #include "support/Package.h"
40 #include "support/types.h"
45 #include <QPushButton>
52 using namespace lyx::support;
56 // These are the strings that are stored in the LyX file and which
57 // correspond to the LaTeX identifiers shown in the comments at the
59 char const * const rorigin_lyx_strs[] = {
60 // the LaTeX default is leftBaseline
62 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
63 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
64 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
66 // These are the strings, corresponding to the above, that the GUI should
67 // use. Note that they can/should be translated.
68 char const * const rorigin_gui_strs[] = {
70 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
71 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
72 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
74 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
82 //FIXME setAutoTextCB should really take an argument, as indicated, that
83 //determines what text is to be written for "auto". But making
84 //that work involves more extensive revisions than we now want
85 //to make, since "auto" also appears in updateContents() (see
87 //The right way to do this, I think, would be to define a class
88 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
89 //the checkbox, line edit, and length combo together, and then made e.g.
90 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
91 //Perhaps even the validator could be exposed through it.
93 * sets a checkbox-line edit-length combo group, using "text" if the
94 * checkbox is unchecked and clearing the line edit if it previously
97 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
98 LengthCombo * lengthCombo/*, string text = "auto"*/)
100 if (!checkBox->isChecked())
101 lengthToWidgets(lineEdit, lengthCombo,
102 "auto", lengthCombo->currentLengthItem());
103 else if (lineEdit->text() == "auto")
104 lengthToWidgets(lineEdit, lengthCombo, string(),
105 lengthCombo->currentLengthItem());
110 vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
112 size_t const n = pr.size();
113 vector<typename Pair::first_type> tmp(n);
114 for (size_t i = 0; i != n; ++i)
115 tmp[i] = pr[i].first;
122 vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
124 size_t const n = pr.size();
125 vector<typename Pair::second_type> tmp(n);
126 for (size_t i = 0; i != n; ++i)
127 tmp[i] = pr[i].second;
132 /// The (tranlated) GUI string and it's LaTeX equivalent.
133 typedef pair<docstring, string> RotationOriginPair;
135 vector<RotationOriginPair> getRotationOriginData()
137 static vector<RotationOriginPair> data;
141 data.resize(rorigin_size);
142 for (size_type i = 0; i < rorigin_size; ++i) {
143 data[i] = make_pair(_(rorigin_gui_strs[i]),
144 rorigin_lyx_strs[i]);
152 GuiGraphics::GuiGraphics(GuiView & lv)
153 : GuiDialog(lv, "graphics", qt_("Graphics"))
158 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
159 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
160 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
161 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
164 connect(filename, SIGNAL(textChanged(const QString &)),
165 this, SLOT(change_adaptor()));
166 connect(WidthCB, SIGNAL( clicked()),
167 this, SLOT(change_adaptor()));
168 connect(HeightCB, SIGNAL( clicked()),
169 this, SLOT(change_adaptor()));
170 connect(Width, SIGNAL(textChanged(const QString &)),
171 this, SLOT(change_adaptor()));
172 connect(Height, SIGNAL(textChanged(const QString &)),
173 this, SLOT(change_adaptor()));
174 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
175 this, SLOT(change_adaptor()));
176 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
177 this, SLOT(change_adaptor()));
178 connect(aspectratio, SIGNAL(stateChanged(int)),
179 this, SLOT(change_adaptor()));
180 connect(angle, SIGNAL(textChanged(const QString &)),
181 this, SLOT(change_adaptor()));
182 connect(origin, SIGNAL(activated(int)),
183 this, SLOT(change_adaptor()));
184 connect(scaleCB, SIGNAL(clicked()),
185 this, SLOT(change_adaptor()));
186 connect(Scale, SIGNAL(textChanged(const QString &)),
187 this, SLOT(change_adaptor()));
188 connect(rotateOrderCB, SIGNAL(clicked()),
189 this, SLOT(change_adaptor()));
191 filename->setValidator(new PathValidator(true, filename));
192 setFocusProxy(filename);
194 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
195 scaleValidator->setBottom(0);
196 scaleValidator->setDecimals(256); //I guess that will do
197 Scale->setValidator(scaleValidator);
198 Height->setValidator(unsignedLengthAutoValidator(Height));
199 Width->setValidator(unsignedLengthAutoValidator(Width));
200 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
203 connect(clip, SIGNAL(stateChanged(int)),
204 this, SLOT(change_adaptor()));
205 connect(lbY, SIGNAL(textChanged(const QString&)),
206 this, SLOT(change_bb()));
207 connect(lbYunit, SIGNAL(activated(int)),
208 this, SLOT(change_bb()));
209 connect(rtY, SIGNAL(textChanged(const QString&)),
210 this, SLOT(change_bb()));
211 connect(rtYunit, SIGNAL(activated(int)),
212 this, SLOT(change_bb()));
213 connect(lbX, SIGNAL(textChanged(const QString&)),
214 this, SLOT(change_bb()));
215 connect(lbXunit, SIGNAL(activated(int)),
216 this, SLOT(change_bb()));
217 connect(rtX, SIGNAL(textChanged(const QString&)),
218 this, SLOT(change_bb()));
219 connect(rtXunit, SIGNAL(activated(int)),
220 this, SLOT(change_bb()));
221 connect(getPB, SIGNAL(clicked()),
222 this, SLOT(change_adaptor()));
224 lbX->setValidator(new QDoubleValidator(lbX));
225 lbY->setValidator(new QDoubleValidator(lbY));
226 rtX->setValidator(new QDoubleValidator(rtX));
227 rtY->setValidator(new QDoubleValidator(rtY));
230 connect(latexoptions, SIGNAL(textChanged(const QString&)),
231 this, SLOT(change_adaptor()));
232 connect(draftCB, SIGNAL(stateChanged(int)),
233 this, SLOT(change_adaptor()));
234 connect(unzipCB, SIGNAL(stateChanged(int)),
235 this, SLOT(change_adaptor()));
236 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
237 // the toggled(bool) signal is also trigged when we update the widgets
238 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
239 // using blockSignals() to keep from triggering that signal when we call
240 // setChecked(). Note, too, that clicked() would get called whenever it
241 // is clicked, even right clicked (I think), not just whenever it is
243 connect(displayGB, SIGNAL(toggled(bool)),
244 this, SLOT(change_adaptor()));
245 connect(showCB, SIGNAL(currentIndexChanged(int)),
246 this, SLOT(change_adaptor()));
247 connect(displayscale, SIGNAL(textChanged(const QString&)),
248 this, SLOT(change_adaptor()));
249 displayscale->setValidator(new QIntValidator(displayscale));
251 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
253 bc().setApply(applyPB);
254 bc().setRestore(restorePB);
255 bc().setCancel(closePB);
257 bc().addReadOnly(latexoptions);
258 bc().addReadOnly(filenameL);
259 bc().addReadOnly(filename);
260 bc().addReadOnly(browsePB);
261 bc().addReadOnly(unzipCB);
262 bc().addReadOnly(bbFrame);
263 bc().addReadOnly(draftCB);
264 bc().addReadOnly(clip);
265 bc().addReadOnly(unzipCB);
266 bc().addReadOnly(displayGB);
267 bc().addReadOnly(sizeGB);
268 bc().addReadOnly(rotationGB);
269 bc().addReadOnly(latexoptions);
270 bc().addReadOnly(getPB);
271 bc().addReadOnly(rotateOrderCB);
273 // initialize the length validator
274 bc().addCheckedLineEdit(Scale, scaleCB);
275 bc().addCheckedLineEdit(Width, WidthCB);
276 bc().addCheckedLineEdit(Height, HeightCB);
277 bc().addCheckedLineEdit(displayscale, scaleLA);
278 bc().addCheckedLineEdit(angle, angleL);
279 bc().addCheckedLineEdit(lbX, xL);
280 bc().addCheckedLineEdit(lbY, yL);
281 bc().addCheckedLineEdit(rtX, xL_2);
282 bc().addCheckedLineEdit(rtY, yL_2);
283 bc().addCheckedLineEdit(filename, filenameL);
287 void GuiGraphics::change_adaptor()
293 void GuiGraphics::change_bb()
296 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
301 void GuiGraphics::on_browsePB_clicked()
303 QString const str = browse(filename->text());
304 if (!str.isEmpty()) {
305 filename->setText(str);
311 void GuiGraphics::on_getPB_clicked()
317 void GuiGraphics::setAutoText()
319 if (scaleCB->isChecked())
321 if (!Scale->isEnabled() && Scale->text() != "100")
322 Scale->setText(QString("auto"));
324 setAutoTextCB(WidthCB, Width, widthUnit);
325 setAutoTextCB(HeightCB, Height, heightUnit);
329 void GuiGraphics::on_scaleCB_toggled(bool setScale)
331 Scale->setEnabled(setScale);
333 Scale->setText("100");
334 Scale->setFocus(Qt::OtherFocusReason);
337 WidthCB->setDisabled(setScale);
338 WidthCB->blockSignals(true);
339 WidthCB->setChecked(false);
340 WidthCB->blockSignals(false);
341 Width->setEnabled(false);
342 widthUnit->setEnabled(false);
344 HeightCB->setDisabled(setScale);
345 HeightCB->blockSignals(true);
346 HeightCB->setChecked(false);
347 HeightCB->blockSignals(false);
348 Height->setEnabled(false);
349 heightUnit->setEnabled(false);
351 aspectratio->setDisabled(true);
352 aspectratio->setChecked(true);
354 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
355 HeightCB->isChecked() ||
356 scaleCB->isChecked()) &&
357 (angle->text() != "0"));
363 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
365 Width->setEnabled(setWidth);
366 widthUnit->setEnabled(setWidth);
368 Width->setFocus(Qt::OtherFocusReason);
370 bool const setHeight = HeightCB->isChecked();
371 aspectratio->setEnabled(setWidth && setHeight);
372 aspectratio->blockSignals(true);
373 aspectratio->setChecked(!(setWidth && setHeight));
374 aspectratio->blockSignals(false);
376 scaleCB->setEnabled(!setWidth && !setHeight);
377 //already will be unchecked, so don't need to do that
378 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
379 && scaleCB->isChecked()); //should be false, but let's check
380 rotateOrderCB->setEnabled((setWidth || setHeight ||
381 scaleCB->isChecked()) &&
382 (angle->text() != "0"));
388 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
390 Height->setEnabled(setHeight);
391 heightUnit->setEnabled(setHeight);
393 Height->setFocus(Qt::OtherFocusReason);
395 bool const setWidth = WidthCB->isChecked();
396 aspectratio->setEnabled(setWidth && setHeight);
397 aspectratio->blockSignals(true);
398 aspectratio->setChecked(!(setWidth && setHeight));
399 aspectratio->blockSignals(false);
401 scaleCB->setEnabled(!setWidth && !setHeight);
403 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
404 && scaleCB->isChecked()); //should be false
405 rotateOrderCB->setEnabled((setWidth || setHeight ||
406 scaleCB->isChecked()) &&
407 (angle->text() != "0"));
413 void GuiGraphics::on_angle_textChanged(const QString & filename)
415 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
416 HeightCB->isChecked() ||
417 scaleCB->isChecked()) &&
421 // returns the number of the string s in the vector v
422 static int itemNumber(const vector<string> & v, string const & s)
424 vector<string>::const_iterator cit =
425 find(v.begin(), v.end(), s);
426 return (cit != v.end()) ? int(cit - v.begin()) : 0;
430 void GuiGraphics::updateContents()
432 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
433 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
435 vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
440 for (vector<string>::const_iterator it = units.begin();
441 it != units.end(); ++it) {
442 lbXunit->addItem(toqstr(*it));
443 lbYunit->addItem(toqstr(*it));
444 rtXunit->addItem(toqstr(*it));
445 rtYunit->addItem(toqstr(*it));
448 InsetGraphicsParams & igp = params_;
450 // set the right default unit
451 Length::UNIT unitDefault = Length::CM;
452 switch (lyxrc.default_papersize) {
455 case PAPER_USEXECUTIVE:
456 unitDefault = Length::IN;
462 lyxerr << bufferFilepath();
464 igp.filename.outputFilename(fromqstr(bufferFilepath()));
465 filename->setText(toqstr(name));
467 // set the bounding box values
468 if (igp.bb.empty()) {
469 string const bb = readBoundingBox(igp.filename.absFilename());
470 // the values from the file always have the bigpoint-unit bp
471 lbX->setText(toqstr(token(bb, ' ', 0)));
472 lbY->setText(toqstr(token(bb, ' ', 1)));
473 rtX->setText(toqstr(token(bb, ' ', 2)));
474 rtY->setText(toqstr(token(bb, ' ', 3)));
475 lbXunit->setCurrentIndex(0);
476 lbYunit->setCurrentIndex(0);
477 rtXunit->setCurrentIndex(0);
478 rtYunit->setCurrentIndex(0);
481 // get the values from the inset
483 string const xl = token(igp.bb, ' ', 0);
484 string const yl = token(igp.bb, ' ', 1);
485 string const xr = token(igp.bb, ' ', 2);
486 string const yr = token(igp.bb, ' ', 3);
487 if (isValidLength(xl, &anyLength)) {
488 lbX->setText(toqstr(convert<string>(anyLength.value())));
489 string const unit = unit_name[anyLength.unit()];
490 lbXunit->setCurrentIndex(itemNumber(units, unit));
492 lbX->setText(toqstr(xl));
494 if (isValidLength(yl, &anyLength)) {
495 lbY->setText(toqstr(convert<string>(anyLength.value())));
496 string const unit = unit_name[anyLength.unit()];
497 lbYunit->setCurrentIndex(itemNumber(units, unit));
499 lbY->setText(toqstr(xl));
501 if (isValidLength(xr, &anyLength)) {
502 rtX->setText(toqstr(convert<string>(anyLength.value())));
503 string const unit = unit_name[anyLength.unit()];
504 rtXunit->setCurrentIndex(itemNumber(units, unit));
506 rtX->setText(toqstr(xl));
508 if (isValidLength(yr, &anyLength)) {
509 rtY->setText(toqstr(convert<string>(anyLength.value())));
510 string const unit = unit_name[anyLength.unit()];
511 rtYunit->setCurrentIndex(itemNumber(units, unit));
513 rtY->setText(toqstr(xl));
518 // Update the draft and clip mode
519 draftCB->setChecked(igp.draft);
520 clip->setChecked(igp.clip);
521 unzipCB->setChecked(igp.noUnzip);
524 switch (igp.display) {
525 case graphics::DefaultDisplay: item = 0; break;
526 case graphics::MonochromeDisplay: item = 1; break;
527 case graphics::GrayscaleDisplay: item = 2; break;
528 case graphics::ColorDisplay: item = 3; break;
529 case graphics::NoDisplay: item = 0; break;
531 showCB->setCurrentIndex(item);
532 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
533 displayGB->setChecked(igp.display != graphics::NoDisplay);
535 // the output section (width/height)
537 Scale->setText(toqstr(igp.scale));
538 //igp.scale defaults to 100, so we treat it as empty
539 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
540 scaleCB->blockSignals(true);
541 scaleCB->setChecked(scaleChecked);
542 scaleCB->blockSignals(false);
543 Scale->setEnabled(scaleChecked);
545 lengthAutoToWidgets(Width, widthUnit, igp.width,
547 bool const widthChecked = !Width->text().isEmpty() &&
548 Width->text() != "auto";
549 WidthCB->blockSignals(true);
550 WidthCB->setChecked(widthChecked);
551 WidthCB->blockSignals(false);
552 Width->setEnabled(widthChecked);
553 widthUnit->setEnabled(widthChecked);
555 lengthAutoToWidgets(Height, heightUnit, igp.height,
557 bool const heightChecked = !Height->text().isEmpty()
558 && Height->text() != "auto";
559 HeightCB->blockSignals(true);
560 HeightCB->setChecked(heightChecked);
561 HeightCB->blockSignals(false);
562 Height->setEnabled(heightChecked);
563 heightUnit->setEnabled(heightChecked);
565 scaleCB->setEnabled(!widthChecked && !heightChecked);
566 WidthCB->setEnabled(!scaleChecked);
567 HeightCB->setEnabled(!scaleChecked);
568 aspectratio->setEnabled(widthChecked && heightChecked);
572 angle->setText(toqstr(igp.rotateAngle));
573 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
575 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
576 && igp.rotateAngle != "0");
580 vector<RotationOriginPair> origindata = getRotationOriginData();
581 vector<docstring> const origin_lang = getFirst(origindata);
582 origin_ltx = getSecond(origindata);
584 for (vector<docstring>::const_iterator it = origin_lang.begin();
585 it != origin_lang.end(); ++it)
586 origin->addItem(toqstr(*it));
588 if (!igp.rotateOrigin.empty())
589 origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
591 origin->setCurrentIndex(0);
594 latexoptions->setText(toqstr(igp.special));
598 void GuiGraphics::applyView()
600 InsetGraphicsParams & igp = params_;
602 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
608 string lbXs = fromqstr(lbX->text());
609 string lbYs = fromqstr(lbY->text());
610 string rtXs = fromqstr(rtX->text());
611 string rtYs = fromqstr(rtY->text());
613 convert<int>(lbXs) + convert<int>(lbYs) +
614 convert<int>(rtXs) + convert<int>(rtXs);
619 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
623 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
627 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
631 bb += (rtYs + fromqstr(rtYunit->currentText()));
636 igp.draft = draftCB->isChecked();
637 igp.clip = clip->isChecked();
639 switch (showCB->currentIndex()) {
640 case 0: igp.display = graphics::DefaultDisplay; break;
641 case 1: igp.display = graphics::MonochromeDisplay; break;
642 case 2: igp.display = graphics::GrayscaleDisplay; break;
643 case 3: igp.display = graphics::ColorDisplay; break;
647 if (!displayGB->isChecked())
648 igp.display = graphics::NoDisplay;
650 //the graphics section
651 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
652 igp.scale = fromqstr(Scale->text());
653 igp.width = Length("0pt");
654 igp.height = Length("0pt");
655 igp.keepAspectRatio = false;
657 igp.scale = string();
658 igp.width = WidthCB->isChecked() ?
659 //Note that this works even if Width is "auto", since in
660 //that case we get "0pt".
661 Length(widgetsToLength(Width, widthUnit)):
663 igp.height = HeightCB->isChecked() ?
664 Length(widgetsToLength(Height, heightUnit)) :
666 igp.keepAspectRatio = aspectratio->isEnabled() &&
667 aspectratio->isChecked() &&
668 igp.width.value() > 0 && igp.height.value() > 0;
671 igp.noUnzip = unzipCB->isChecked();
672 igp.lyxscale = displayscale->text().toInt();
673 igp.rotateAngle = fromqstr(angle->text());
675 double rotAngle = convert<double>(igp.rotateAngle);
676 if (abs(rotAngle) > 360.0) {
677 rotAngle -= 360.0 * floor(rotAngle / 360.0);
678 igp.rotateAngle = convert<string>(rotAngle);
681 // save the latex name for the origin. If it is the default
682 // then origin_ltx returns ""
683 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
684 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
686 // more latex options
687 igp.special = fromqstr(latexoptions->text());
691 void GuiGraphics::getBB()
693 string const fn = fromqstr(filename->text());
696 string const bb = readBoundingBox(fn);
700 lbX->setText(toqstr(token(bb, ' ', 0)));
701 lbY->setText(toqstr(token(bb, ' ', 1)));
702 rtX->setText(toqstr(token(bb, ' ', 2)));
703 rtY->setText(toqstr(token(bb, ' ', 3)));
704 // the default units for the bb values when reading
706 lbXunit->setCurrentIndex(0);
707 lbYunit->setCurrentIndex(0);
708 rtXunit->setCurrentIndex(0);
709 rtYunit->setCurrentIndex(0);
713 bool GuiGraphics::isValid()
715 return !filename->text().isEmpty();
719 bool GuiGraphics::initialiseParams(string const & data)
721 InsetGraphics::string2params(data, buffer(), params_);
726 void GuiGraphics::clearParams()
728 params_ = InsetGraphicsParams();
732 void GuiGraphics::dispatchParams()
734 InsetGraphicsParams tmp_params(params_);
735 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
736 dispatch(FuncRequest(getLfun(), lfun));
740 QString GuiGraphics::browse(QString const & in_name) const
742 QString const title = qt_("Select graphics file");
744 // Does user clipart directory exist?
745 string clipdir = addName(package().user_support().absFilename(), "clipart");
746 FileName clip(clipdir);
748 // bail out to system clipart directory
749 if (!clip.isDirectory())
750 clipdir = addName(package().system_support().absFilename(), "clipart");
752 return browseRelFile(in_name, bufferFilepath(),
753 title, fileFilters(QString()), false,
754 qt_("Clipart|#C#c"), toqstr(clipdir),
755 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
759 string GuiGraphics::readBoundingBox(string const & file)
761 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilepath()));
763 // try to get it from the file, if possible. Zipped files are
764 // unzipped in the readBB_from_PSFile-Function
765 string const bb = readBB_from_PSFile(abs_file);
769 // we don't, so ask the Graphics Cache if it has loaded the file
773 graphics::Cache & gc = graphics::Cache::get();
774 if (gc.inCache(abs_file)) {
775 graphics::Image const * image = gc.item(abs_file)->image();
778 width = image->width();
779 height = image->height();
783 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
787 bool GuiGraphics::isFileNameValid(string const & fname) const
789 // It may be that the filename is relative.
790 return support::makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
794 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
797 } // namespace frontend
800 #include "GuiGraphics_moc.cpp"