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/FileFilterList.h"
36 #include "support/filetools.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39 #include "support/os.h"
40 #include "support/Package.h"
41 #include "support/types.h"
46 #include <QPushButton>
53 using namespace lyx::support;
57 // These are the strings that are stored in the LyX file and which
58 // correspond to the LaTeX identifiers shown in the comments at the
60 char const * const rorigin_lyx_strs[] = {
61 // the LaTeX default is leftBaseline
63 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
64 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
65 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
67 // These are the strings, corresponding to the above, that the GUI should
68 // use. Note that they can/should be translated.
69 char const * const rorigin_gui_strs[] = {
71 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
72 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
73 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
75 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
83 //FIXME setAutoTextCB should really take an argument, as indicated, that
84 //determines what text is to be written for "auto". But making
85 //that work involves more extensive revisions than we now want
86 //to make, since "auto" also appears in updateContents() (see
88 //The right way to do this, I think, would be to define a class
89 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
90 //the checkbox, line edit, and length combo together, and then made e.g.
91 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
92 //Perhaps even the validator could be exposed through it.
94 * sets a checkbox-line edit-length combo group, using "text" if the
95 * checkbox is unchecked and clearing the line edit if it previously
98 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
99 LengthCombo * lengthCombo/*, string text = "auto"*/)
101 if (!checkBox->isChecked())
102 lengthToWidgets(lineEdit, lengthCombo,
103 "auto", lengthCombo->currentLengthItem());
104 else if (lineEdit->text() == "auto")
105 lengthToWidgets(lineEdit, lengthCombo, string(),
106 lengthCombo->currentLengthItem());
111 vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
113 size_t const n = pr.size();
114 vector<typename Pair::first_type> tmp(n);
115 for (size_t i = 0; i != n; ++i)
116 tmp[i] = pr[i].first;
123 vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
125 size_t const n = pr.size();
126 vector<typename Pair::second_type> tmp(n);
127 for (size_t i = 0; i != n; ++i)
128 tmp[i] = pr[i].second;
133 /// The (tranlated) GUI string and it's LaTeX equivalent.
134 typedef pair<docstring, string> RotationOriginPair;
136 vector<RotationOriginPair> getRotationOriginData()
138 static vector<RotationOriginPair> data;
142 data.resize(rorigin_size);
143 for (size_type i = 0; i < rorigin_size; ++i) {
144 data[i] = make_pair(_(rorigin_gui_strs[i]),
145 rorigin_lyx_strs[i]);
154 GuiGraphics::GuiGraphics(GuiView & lv)
155 : GuiDialog(lv, "graphics", qt_("Graphics"))
160 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
161 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
162 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
163 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
166 connect(filename, SIGNAL(textChanged(const QString &)),
167 this, SLOT(change_adaptor()));
168 connect(WidthCB, SIGNAL( clicked()),
169 this, SLOT(change_adaptor()));
170 connect(HeightCB, SIGNAL( clicked()),
171 this, SLOT(change_adaptor()));
172 connect(Width, SIGNAL(textChanged(const QString &)),
173 this, SLOT(change_adaptor()));
174 connect(Height, SIGNAL(textChanged(const QString &)),
175 this, SLOT(change_adaptor()));
176 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
177 this, SLOT(change_adaptor()));
178 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
179 this, SLOT(change_adaptor()));
180 connect(aspectratio, SIGNAL(stateChanged(int)),
181 this, SLOT(change_adaptor()));
182 connect(angle, SIGNAL(textChanged(const QString &)),
183 this, SLOT(change_adaptor()));
184 connect(origin, SIGNAL(activated(int)),
185 this, SLOT(change_adaptor()));
186 connect(scaleCB, SIGNAL(clicked()),
187 this, SLOT(change_adaptor()));
188 connect(Scale, SIGNAL(textChanged(const QString &)),
189 this, SLOT(change_adaptor()));
190 connect(rotateOrderCB, SIGNAL(clicked()),
191 this, SLOT(change_adaptor()));
193 filename->setValidator(new PathValidator(true, filename));
194 setFocusProxy(filename);
196 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
197 scaleValidator->setBottom(0);
198 scaleValidator->setDecimals(256); //I guess that will do
199 Scale->setValidator(scaleValidator);
200 Height->setValidator(unsignedLengthAutoValidator(Height));
201 Width->setValidator(unsignedLengthAutoValidator(Width));
202 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
205 connect(clip, SIGNAL(stateChanged(int)),
206 this, SLOT(change_adaptor()));
207 connect(lbY, SIGNAL(textChanged(const QString&)),
208 this, SLOT(change_bb()));
209 connect(lbYunit, SIGNAL(activated(int)),
210 this, SLOT(change_bb()));
211 connect(rtY, SIGNAL(textChanged(const QString&)),
212 this, SLOT(change_bb()));
213 connect(rtYunit, SIGNAL(activated(int)),
214 this, SLOT(change_bb()));
215 connect(lbX, SIGNAL(textChanged(const QString&)),
216 this, SLOT(change_bb()));
217 connect(lbXunit, SIGNAL(activated(int)),
218 this, SLOT(change_bb()));
219 connect(rtX, SIGNAL(textChanged(const QString&)),
220 this, SLOT(change_bb()));
221 connect(rtXunit, SIGNAL(activated(int)),
222 this, SLOT(change_bb()));
223 connect(getPB, SIGNAL(clicked()),
224 this, SLOT(change_adaptor()));
226 lbX->setValidator(new QDoubleValidator(lbX));
227 lbY->setValidator(new QDoubleValidator(lbY));
228 rtX->setValidator(new QDoubleValidator(rtX));
229 rtY->setValidator(new QDoubleValidator(rtY));
232 connect(latexoptions, SIGNAL(textChanged(const QString&)),
233 this, SLOT(change_adaptor()));
234 connect(draftCB, SIGNAL(stateChanged(int)),
235 this, SLOT(change_adaptor()));
236 connect(unzipCB, SIGNAL(stateChanged(int)),
237 this, SLOT(change_adaptor()));
238 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
239 // the toggled(bool) signal is also trigged when we update the widgets
240 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
241 // using blockSignals() to keep from triggering that signal when we call
242 // setChecked(). Note, too, that clicked() would get called whenever it
243 // is clicked, even right clicked (I think), not just whenever it is
245 connect(displayGB, SIGNAL(toggled(bool)),
246 this, SLOT(change_adaptor()));
247 connect(showCB, SIGNAL(currentIndexChanged(int)),
248 this, SLOT(change_adaptor()));
249 connect(displayscale, SIGNAL(textChanged(const QString&)),
250 this, SLOT(change_adaptor()));
251 displayscale->setValidator(new QIntValidator(displayscale));
253 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
255 bc().setApply(applyPB);
256 bc().setRestore(restorePB);
257 bc().setCancel(closePB);
259 bc().addReadOnly(latexoptions);
260 bc().addReadOnly(filenameL);
261 bc().addReadOnly(filename);
262 bc().addReadOnly(browsePB);
263 bc().addReadOnly(unzipCB);
264 bc().addReadOnly(bbFrame);
265 bc().addReadOnly(draftCB);
266 bc().addReadOnly(clip);
267 bc().addReadOnly(unzipCB);
268 bc().addReadOnly(displayGB);
269 bc().addReadOnly(sizeGB);
270 bc().addReadOnly(rotationGB);
271 bc().addReadOnly(latexoptions);
272 bc().addReadOnly(getPB);
273 bc().addReadOnly(rotateOrderCB);
275 // initialize the length validator
276 bc().addCheckedLineEdit(Scale, scaleCB);
277 bc().addCheckedLineEdit(Width, WidthCB);
278 bc().addCheckedLineEdit(Height, HeightCB);
279 bc().addCheckedLineEdit(displayscale, scaleLA);
280 bc().addCheckedLineEdit(angle, angleL);
281 bc().addCheckedLineEdit(lbX, xL);
282 bc().addCheckedLineEdit(lbY, yL);
283 bc().addCheckedLineEdit(rtX, xL_2);
284 bc().addCheckedLineEdit(rtY, yL_2);
285 bc().addCheckedLineEdit(filename, filenameL);
289 void GuiGraphics::change_adaptor()
295 void GuiGraphics::change_bb()
298 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
303 void GuiGraphics::on_browsePB_clicked()
305 QString const str = browse(filename->text());
306 if (!str.isEmpty()) {
307 filename->setText(str);
313 void GuiGraphics::on_getPB_clicked()
319 void GuiGraphics::on_filename_textChanged(const QString & filename)
321 EmbeddedFile file = EmbeddedFile(fromqstr(filename), fromqstr(bufferFilepath()));
325 void GuiGraphics::setAutoText()
327 if (scaleCB->isChecked())
329 if (!Scale->isEnabled() && Scale->text() != "100")
330 Scale->setText(QString("auto"));
332 setAutoTextCB(WidthCB, Width, widthUnit);
333 setAutoTextCB(HeightCB, Height, heightUnit);
337 void GuiGraphics::on_scaleCB_toggled(bool setScale)
339 Scale->setEnabled(setScale);
341 Scale->setText("100");
342 Scale->setFocus(Qt::OtherFocusReason);
345 WidthCB->setDisabled(setScale);
346 WidthCB->blockSignals(true);
347 WidthCB->setChecked(false);
348 WidthCB->blockSignals(false);
349 Width->setEnabled(false);
350 widthUnit->setEnabled(false);
352 HeightCB->setDisabled(setScale);
353 HeightCB->blockSignals(true);
354 HeightCB->setChecked(false);
355 HeightCB->blockSignals(false);
356 Height->setEnabled(false);
357 heightUnit->setEnabled(false);
359 aspectratio->setDisabled(true);
360 aspectratio->setChecked(true);
362 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
363 HeightCB->isChecked() ||
364 scaleCB->isChecked()) &&
365 (angle->text() != "0"));
371 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
373 Width->setEnabled(setWidth);
374 widthUnit->setEnabled(setWidth);
376 Width->setFocus(Qt::OtherFocusReason);
378 bool const setHeight = HeightCB->isChecked();
379 aspectratio->setEnabled(setWidth && setHeight);
380 aspectratio->blockSignals(true);
381 aspectratio->setChecked(!(setWidth && setHeight));
382 aspectratio->blockSignals(false);
384 scaleCB->setEnabled(!setWidth && !setHeight);
385 //already will be unchecked, so don't need to do that
386 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
387 && scaleCB->isChecked()); //should be false, but let's check
388 rotateOrderCB->setEnabled((setWidth || setHeight ||
389 scaleCB->isChecked()) &&
390 (angle->text() != "0"));
396 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
398 Height->setEnabled(setHeight);
399 heightUnit->setEnabled(setHeight);
401 Height->setFocus(Qt::OtherFocusReason);
403 bool const setWidth = WidthCB->isChecked();
404 aspectratio->setEnabled(setWidth && setHeight);
405 aspectratio->blockSignals(true);
406 aspectratio->setChecked(!(setWidth && setHeight));
407 aspectratio->blockSignals(false);
409 scaleCB->setEnabled(!setWidth && !setHeight);
411 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
412 && scaleCB->isChecked()); //should be false
413 rotateOrderCB->setEnabled((setWidth || setHeight ||
414 scaleCB->isChecked()) &&
415 (angle->text() != "0"));
421 void GuiGraphics::on_angle_textChanged(const QString & filename)
423 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
424 HeightCB->isChecked() ||
425 scaleCB->isChecked()) &&
429 // returns the number of the string s in the vector v
430 static int itemNumber(const vector<string> & v, string const & s)
432 vector<string>::const_iterator cit =
433 find(v.begin(), v.end(), s);
434 return (cit != v.end()) ? int(cit - v.begin()) : 0;
438 void GuiGraphics::updateContents()
440 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
441 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
443 vector<string> const units = vector<string>(bb_units, bb_units + bb_size);
448 for (vector<string>::const_iterator it = units.begin();
449 it != units.end(); ++it) {
450 lbXunit->addItem(toqstr(*it));
451 lbYunit->addItem(toqstr(*it));
452 rtXunit->addItem(toqstr(*it));
453 rtYunit->addItem(toqstr(*it));
456 InsetGraphicsParams & igp = params_;
458 // set the right default unit
459 Length::UNIT unitDefault = Length::CM;
460 switch (lyxrc.default_papersize) {
463 case PAPER_USEXECUTIVE:
464 unitDefault = Length::IN;
471 igp.filename.outputFilename(fromqstr(bufferFilepath()));
472 filename->setText(toqstr(name));
474 // set the bounding box values
475 if (igp.bb.empty()) {
476 string const bb = readBoundingBox(igp.filename.absFilename());
477 // the values from the file always have the bigpoint-unit bp
478 lbX->setText(toqstr(token(bb, ' ', 0)));
479 lbY->setText(toqstr(token(bb, ' ', 1)));
480 rtX->setText(toqstr(token(bb, ' ', 2)));
481 rtY->setText(toqstr(token(bb, ' ', 3)));
482 lbXunit->setCurrentIndex(0);
483 lbYunit->setCurrentIndex(0);
484 rtXunit->setCurrentIndex(0);
485 rtYunit->setCurrentIndex(0);
488 // get the values from the inset
490 string const xl = token(igp.bb, ' ', 0);
491 string const yl = token(igp.bb, ' ', 1);
492 string const xr = token(igp.bb, ' ', 2);
493 string const yr = token(igp.bb, ' ', 3);
494 if (isValidLength(xl, &anyLength)) {
495 lbX->setText(toqstr(convert<string>(anyLength.value())));
496 string const unit = unit_name[anyLength.unit()];
497 lbXunit->setCurrentIndex(itemNumber(units, unit));
499 lbX->setText(toqstr(xl));
501 if (isValidLength(yl, &anyLength)) {
502 lbY->setText(toqstr(convert<string>(anyLength.value())));
503 string const unit = unit_name[anyLength.unit()];
504 lbYunit->setCurrentIndex(itemNumber(units, unit));
506 lbY->setText(toqstr(xl));
508 if (isValidLength(xr, &anyLength)) {
509 rtX->setText(toqstr(convert<string>(anyLength.value())));
510 string const unit = unit_name[anyLength.unit()];
511 rtXunit->setCurrentIndex(itemNumber(units, unit));
513 rtX->setText(toqstr(xl));
515 if (isValidLength(yr, &anyLength)) {
516 rtY->setText(toqstr(convert<string>(anyLength.value())));
517 string const unit = unit_name[anyLength.unit()];
518 rtYunit->setCurrentIndex(itemNumber(units, unit));
520 rtY->setText(toqstr(xl));
525 // Update the draft and clip mode
526 draftCB->setChecked(igp.draft);
527 clip->setChecked(igp.clip);
528 unzipCB->setChecked(igp.noUnzip);
531 switch (igp.display) {
532 case graphics::DefaultDisplay: item = 0; break;
533 case graphics::MonochromeDisplay: item = 1; break;
534 case graphics::GrayscaleDisplay: item = 2; break;
535 case graphics::ColorDisplay: item = 3; break;
536 case graphics::NoDisplay: item = 0; break;
538 showCB->setCurrentIndex(item);
539 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
540 displayGB->setChecked(igp.display != graphics::NoDisplay);
542 // the output section (width/height)
544 Scale->setText(toqstr(igp.scale));
545 //igp.scale defaults to 100, so we treat it as empty
546 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
547 scaleCB->blockSignals(true);
548 scaleCB->setChecked(scaleChecked);
549 scaleCB->blockSignals(false);
550 Scale->setEnabled(scaleChecked);
552 lengthAutoToWidgets(Width, widthUnit, igp.width,
554 bool const widthChecked = !Width->text().isEmpty() &&
555 Width->text() != "auto";
556 WidthCB->blockSignals(true);
557 WidthCB->setChecked(widthChecked);
558 WidthCB->blockSignals(false);
559 Width->setEnabled(widthChecked);
560 widthUnit->setEnabled(widthChecked);
562 lengthAutoToWidgets(Height, heightUnit, igp.height,
564 bool const heightChecked = !Height->text().isEmpty()
565 && Height->text() != "auto";
566 HeightCB->blockSignals(true);
567 HeightCB->setChecked(heightChecked);
568 HeightCB->blockSignals(false);
569 Height->setEnabled(heightChecked);
570 heightUnit->setEnabled(heightChecked);
572 scaleCB->setEnabled(!widthChecked && !heightChecked);
573 WidthCB->setEnabled(!scaleChecked);
574 HeightCB->setEnabled(!scaleChecked);
575 aspectratio->setEnabled(widthChecked && heightChecked);
579 angle->setText(toqstr(igp.rotateAngle));
580 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
582 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
583 && igp.rotateAngle != "0");
587 vector<RotationOriginPair> origindata = getRotationOriginData();
588 vector<docstring> const origin_lang = getFirst(origindata);
589 origin_ltx = getSecond(origindata);
591 for (vector<docstring>::const_iterator it = origin_lang.begin();
592 it != origin_lang.end(); ++it)
593 origin->addItem(toqstr(*it));
595 if (!igp.rotateOrigin.empty())
596 origin->setCurrentIndex(itemNumber(origin_ltx, igp.rotateOrigin));
598 origin->setCurrentIndex(0);
601 latexoptions->setText(toqstr(igp.special));
605 void GuiGraphics::applyView()
607 InsetGraphicsParams & igp = params_;
609 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
615 string lbXs = fromqstr(lbX->text());
616 string lbYs = fromqstr(lbY->text());
617 string rtXs = fromqstr(rtX->text());
618 string rtYs = fromqstr(rtY->text());
620 convert<int>(lbXs) + convert<int>(lbYs) +
621 convert<int>(rtXs) + convert<int>(rtXs);
626 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
630 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
634 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
638 bb += (rtYs + fromqstr(rtYunit->currentText()));
643 igp.draft = draftCB->isChecked();
644 igp.clip = clip->isChecked();
646 switch (showCB->currentIndex()) {
647 case 0: igp.display = graphics::DefaultDisplay; break;
648 case 1: igp.display = graphics::MonochromeDisplay; break;
649 case 2: igp.display = graphics::GrayscaleDisplay; break;
650 case 3: igp.display = graphics::ColorDisplay; break;
654 if (!displayGB->isChecked())
655 igp.display = graphics::NoDisplay;
657 //the graphics section
658 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
659 igp.scale = fromqstr(Scale->text());
660 igp.width = Length("0pt");
661 igp.height = Length("0pt");
662 igp.keepAspectRatio = false;
664 igp.scale = string();
665 igp.width = WidthCB->isChecked() ?
666 //Note that this works even if Width is "auto", since in
667 //that case we get "0pt".
668 Length(widgetsToLength(Width, widthUnit)):
670 igp.height = HeightCB->isChecked() ?
671 Length(widgetsToLength(Height, heightUnit)) :
673 igp.keepAspectRatio = aspectratio->isEnabled() &&
674 aspectratio->isChecked() &&
675 igp.width.value() > 0 && igp.height.value() > 0;
678 igp.noUnzip = unzipCB->isChecked();
679 igp.lyxscale = displayscale->text().toInt();
680 igp.rotateAngle = fromqstr(angle->text());
682 double rotAngle = convert<double>(igp.rotateAngle);
683 if (abs(rotAngle) > 360.0) {
684 rotAngle -= 360.0 * floor(rotAngle / 360.0);
685 igp.rotateAngle = convert<string>(rotAngle);
688 // save the latex name for the origin. If it is the default
689 // then origin_ltx returns ""
690 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
691 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
693 // more latex options
694 igp.special = fromqstr(latexoptions->text());
698 void GuiGraphics::getBB()
700 string const fn = fromqstr(filename->text());
703 string const bb = readBoundingBox(fn);
707 lbX->setText(toqstr(token(bb, ' ', 0)));
708 lbY->setText(toqstr(token(bb, ' ', 1)));
709 rtX->setText(toqstr(token(bb, ' ', 2)));
710 rtY->setText(toqstr(token(bb, ' ', 3)));
711 // the default units for the bb values when reading
713 lbXunit->setCurrentIndex(0);
714 lbYunit->setCurrentIndex(0);
715 rtXunit->setCurrentIndex(0);
716 rtYunit->setCurrentIndex(0);
720 bool GuiGraphics::isValid()
722 return !filename->text().isEmpty();
726 bool GuiGraphics::initialiseParams(string const & data)
728 InsetGraphics::string2params(data, buffer(), params_);
733 void GuiGraphics::clearParams()
735 params_ = InsetGraphicsParams();
739 void GuiGraphics::dispatchParams()
741 InsetGraphicsParams tmp_params(params_);
742 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
743 dispatch(FuncRequest(getLfun(), lfun));
747 QString GuiGraphics::browse(QString const & in_name) const
749 QString const title = qt_("Select graphics file");
751 // Does user clipart directory exist?
752 string clipdir = addName(package().user_support().absFilename(), "clipart");
753 FileName clip(clipdir);
755 // bail out to system clipart directory
756 if (!(clip.exists() && clip.isDirectory()))
757 clipdir = addName(package().system_support().absFilename(), "clipart");
759 return browseRelFile(in_name, bufferFilepath(),
760 title, FileFilterList(), false,
761 qt_("Clipart|#C#c"), toqstr(clipdir),
762 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
766 string GuiGraphics::readBoundingBox(string const & file)
768 FileName const abs_file = makeAbsPath(file, fromqstr(bufferFilepath()));
770 // try to get it from the file, if possible. Zipped files are
771 // unzipped in the readBB_from_PSFile-Function
772 string const bb = readBB_from_PSFile(abs_file);
776 // we don't, so ask the Graphics Cache if it has loaded the file
780 graphics::Cache & gc = graphics::Cache::get();
781 if (gc.inCache(abs_file)) {
782 graphics::Image const * image = gc.item(abs_file)->image();
785 width = image->width();
786 height = image->height();
790 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
794 bool GuiGraphics::isFileNameValid(string const & fname) const
796 // It may be that the filename is relative.
797 return makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
801 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
804 } // namespace frontend
807 #include "GuiGraphics_moc.cpp"