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 "support/debug.h"
20 #include "LengthCombo.h"
23 #include "qt_helpers.h"
24 #include "Validator.h"
26 #include "FuncRequest.h"
27 #include "support/gettext.h"
29 #include "graphics/GraphicsCache.h"
30 #include "graphics/GraphicsCacheItem.h"
31 #include "graphics/GraphicsImage.h"
33 #include "insets/InsetGraphicsParams.h"
35 #include "support/convert.h"
36 #include "support/FileFilterList.h"
37 #include "support/filetools.h"
38 #include "support/lstrings.h"
39 #include "support/lyxlib.h"
40 #include "support/os.h"
41 #include "support/Package.h"
42 #include "support/types.h"
44 #include <boost/bind.hpp>
47 #include <QCloseEvent>
50 #include <QPushButton>
62 using support::addName;
63 using support::FileFilterList;
64 using support::FileName;
65 using support::float_equal;
66 using support::makeAbsPath;
67 using support::os::internal_path;
68 using support::package;
69 using support::readBB_from_PSFile;
73 //FIXME setAutoTextCB should really take an argument, as indicated, that
74 //determines what text is to be written for "auto". But making
75 //that work involves more extensive revisions than we now want
76 //to make, since "auto" also appears in updateContents() (see
78 //The right way to do this, I think, would be to define a class
79 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
80 //the checkbox, line edit, and length combo together, and then made e.g.
81 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
82 //Perhaps even the validator could be exposed through it.
84 * sets a checkbox-line edit-length combo group, using "text" if the
85 * checkbox is unchecked and clearing the line edit if it previously
88 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
89 LengthCombo * lengthCombo/*, string text = "auto"*/)
91 if (!checkBox->isChecked())
92 lengthToWidgets(lineEdit, lengthCombo,
93 "auto", lengthCombo->currentLengthItem());
94 else if (lineEdit->text() == "auto")
95 lengthToWidgets(lineEdit, lengthCombo, string(),
96 lengthCombo->currentLengthItem());
100 vector<typename Pair::first_type> const
101 getFirst(vector<Pair> const & pr)
103 vector<typename Pair::first_type> tmp(pr.size());
104 transform(pr.begin(), pr.end(), tmp.begin(),
105 boost::bind(&Pair::first, _1));
111 vector<typename Pair::second_type> const
112 getSecond(vector<Pair> const & pr)
114 vector<typename Pair::second_type> tmp(pr.size());
115 transform(pr.begin(), pr.end(), tmp.begin(),
116 boost::bind(&Pair::second, _1));
120 /// The (tranlated) GUI std::string and it's LaTeX equivalent.
121 typedef std::pair<docstring, std::string> RotationOriginPair;
123 std::vector<RotationOriginPair> getRotationOriginData();
126 GuiGraphics::GuiGraphics(GuiView & lv)
127 : GuiDialog(lv, "graphics")
130 setViewTitle(_("Graphics"));
133 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
134 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
135 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
136 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
139 connect(filename, SIGNAL(textChanged(const QString &)),
140 this, SLOT(change_adaptor()));
141 connect(WidthCB, SIGNAL( clicked()),
142 this, SLOT(change_adaptor()));
143 connect(HeightCB, SIGNAL( clicked()),
144 this, SLOT(change_adaptor()));
145 connect(Width, SIGNAL(textChanged(const QString &)),
146 this, SLOT(change_adaptor()));
147 connect(Height, SIGNAL(textChanged(const QString &)),
148 this, SLOT(change_adaptor()));
149 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
150 this, SLOT(change_adaptor()));
151 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
152 this, SLOT(change_adaptor()));
153 connect(aspectratio, SIGNAL(stateChanged(int)),
154 this, SLOT(change_adaptor()));
155 connect(angle, SIGNAL(textChanged(const QString &)),
156 this, SLOT(change_adaptor()));
157 connect(origin, SIGNAL(activated(int)),
158 this, SLOT(change_adaptor()));
159 connect(scaleCB, SIGNAL(clicked()),
160 this, SLOT(change_adaptor()));
161 connect(Scale, SIGNAL(textChanged(const QString &)),
162 this, SLOT(change_adaptor()));
163 connect(rotateOrderCB, SIGNAL(clicked()),
164 this, SLOT(change_adaptor()));
166 filename->setValidator(new PathValidator(true, filename));
167 setFocusProxy(filename);
169 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
170 scaleValidator->setBottom(0);
171 scaleValidator->setDecimals(256); //I guess that will do
172 Scale->setValidator(scaleValidator);
173 Height->setValidator(unsignedLengthAutoValidator(Height));
174 Width->setValidator(unsignedLengthAutoValidator(Width));
175 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
178 connect(clip, SIGNAL(stateChanged(int)),
179 this, SLOT(change_adaptor()));
180 connect(lbY, SIGNAL(textChanged(const QString&)),
181 this, SLOT(change_bb()));
182 connect(lbYunit, SIGNAL(activated(int)),
183 this, SLOT(change_bb()));
184 connect(rtY, SIGNAL(textChanged(const QString&)),
185 this, SLOT(change_bb()));
186 connect(rtYunit, SIGNAL(activated(int)),
187 this, SLOT(change_bb()));
188 connect(lbX, SIGNAL(textChanged(const QString&)),
189 this, SLOT(change_bb()));
190 connect(lbXunit, SIGNAL(activated(int)),
191 this, SLOT(change_bb()));
192 connect(rtX, SIGNAL(textChanged(const QString&)),
193 this, SLOT(change_bb()));
194 connect(rtXunit, SIGNAL(activated(int)),
195 this, SLOT(change_bb()));
196 connect(getPB, SIGNAL(clicked()),
197 this, SLOT(change_adaptor()));
199 lbX->setValidator(new QDoubleValidator(lbX));
200 lbY->setValidator(new QDoubleValidator(lbY));
201 rtX->setValidator(new QDoubleValidator(rtX));
202 rtY->setValidator(new QDoubleValidator(rtY));
205 connect(latexoptions, SIGNAL(textChanged(const QString&)),
206 this, SLOT(change_adaptor()));
207 connect(draftCB, SIGNAL(stateChanged(int)),
208 this, SLOT(change_adaptor()));
209 connect(unzipCB, SIGNAL(stateChanged(int)),
210 this, SLOT(change_adaptor()));
211 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
212 // the toggled(bool) signal is also trigged when we update the widgets
213 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
214 // using blockSignals() to keep from triggering that signal when we call
215 // setChecked(). Note, too, that clicked() would get called whenever it
216 // is clicked, even right clicked (I think), not just whenever it is
218 connect(subfigure, SIGNAL(toggled(bool)),
219 this, SLOT(change_adaptor()));
220 connect(subcaption, SIGNAL(textChanged(const QString&)),
221 this, SLOT(change_adaptor()));
222 connect(displayGB, SIGNAL(toggled(bool)),
223 this, SLOT(change_adaptor()));
224 connect(showCB, SIGNAL(currentIndexChanged(int)),
225 this, SLOT(change_adaptor()));
226 connect(displayscale, SIGNAL(textChanged(const QString&)),
227 this, SLOT(change_adaptor()));
228 displayscale->setValidator(new QIntValidator(displayscale));
230 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
232 bc().setApply(applyPB);
233 bc().setRestore(restorePB);
234 bc().setCancel(closePB);
236 bc().addReadOnly(latexoptions);
237 bc().addReadOnly(subfigure);
238 bc().addReadOnly(filenameL);
239 bc().addReadOnly(filename);
240 bc().addReadOnly(browsePB);
241 bc().addReadOnly(unzipCB);
242 bc().addReadOnly(bbFrame);
243 bc().addReadOnly(draftCB);
244 bc().addReadOnly(clip);
245 bc().addReadOnly(unzipCB);
246 bc().addReadOnly(displayGB);
247 bc().addReadOnly(sizeGB);
248 bc().addReadOnly(rotationGB);
249 bc().addReadOnly(latexoptions);
250 bc().addReadOnly(getPB);
251 bc().addReadOnly(rotateOrderCB);
253 // initialize the length validator
254 bc().addCheckedLineEdit(Scale, scaleCB);
255 bc().addCheckedLineEdit(Width, WidthCB);
256 bc().addCheckedLineEdit(Height, HeightCB);
257 bc().addCheckedLineEdit(displayscale, scaleLA);
258 bc().addCheckedLineEdit(angle, angleL);
259 bc().addCheckedLineEdit(lbX, xL);
260 bc().addCheckedLineEdit(lbY, yL);
261 bc().addCheckedLineEdit(rtX, xL_2);
262 bc().addCheckedLineEdit(rtY, yL_2);
263 bc().addCheckedLineEdit(filename, filenameL);
267 void GuiGraphics::change_adaptor()
273 void GuiGraphics::change_bb()
276 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
281 void GuiGraphics::closeEvent(QCloseEvent * e)
284 GuiDialog::closeEvent(e);
288 void GuiGraphics::on_browsePB_clicked()
290 docstring const str = browse(qstring_to_ucs4(filename->text()));
292 filename->setText(toqstr(str));
293 embedCB->setCheckState(Qt::Unchecked);
299 void GuiGraphics::on_getPB_clicked()
305 void GuiGraphics::on_editPB_clicked()
311 void GuiGraphics::on_filename_textChanged(const QString & filename)
313 editPB->setDisabled(filename.isEmpty());
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 getItemNo(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 // clear and fill in the comboboxes
433 vector<string> const bb_units = frontend::getBBUnits();
438 for (vector<string>::const_iterator it = bb_units.begin();
439 it != bb_units.end(); ++it) {
440 lbXunit->addItem(toqstr(*it));
441 lbYunit->addItem(toqstr(*it));
442 rtXunit->addItem(toqstr(*it));
443 rtYunit->addItem(toqstr(*it));
446 InsetGraphicsParams & igp = params_;
448 // set the right default unit
449 Length::UNIT unitDefault = Length::CM;
450 switch (lyxrc.default_papersize) {
453 case PAPER_USEXECUTIVE:
454 unitDefault = Length::IN;
461 igp.filename.outputFilename(bufferFilepath());
462 filename->setText(toqstr(name));
463 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
465 // set the bounding box values
466 if (igp.bb.empty()) {
467 string const bb = readBB(igp.filename.absFilename());
468 // the values from the file always have the bigpoint-unit bp
469 lbX->setText(toqstr(token(bb, ' ', 0)));
470 lbY->setText(toqstr(token(bb, ' ', 1)));
471 rtX->setText(toqstr(token(bb, ' ', 2)));
472 rtY->setText(toqstr(token(bb, ' ', 3)));
473 lbXunit->setCurrentIndex(0);
474 lbYunit->setCurrentIndex(0);
475 rtXunit->setCurrentIndex(0);
476 rtYunit->setCurrentIndex(0);
479 // get the values from the inset
481 string const xl = token(igp.bb, ' ', 0);
482 string const yl = token(igp.bb, ' ', 1);
483 string const xr = token(igp.bb, ' ', 2);
484 string const yr = token(igp.bb, ' ', 3);
485 if (isValidLength(xl, &anyLength)) {
486 lbX->setText(toqstr(convert<string>(anyLength.value())));
487 string const unit(unit_name[anyLength.unit()]);
488 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
490 lbX->setText(toqstr(xl));
492 if (isValidLength(yl, &anyLength)) {
493 lbY->setText(toqstr(convert<string>(anyLength.value())));
494 string const unit(unit_name[anyLength.unit()]);
495 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
497 lbY->setText(toqstr(xl));
499 if (isValidLength(xr, &anyLength)) {
500 rtX->setText(toqstr(convert<string>(anyLength.value())));
501 string const unit(unit_name[anyLength.unit()]);
502 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
504 rtX->setText(toqstr(xl));
506 if (isValidLength(yr, &anyLength)) {
507 rtY->setText(toqstr(convert<string>(anyLength.value())));
508 string const unit(unit_name[anyLength.unit()]);
509 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
511 rtY->setText(toqstr(xl));
516 // Update the draft and clip mode
517 draftCB->setChecked(igp.draft);
518 clip->setChecked(igp.clip);
519 unzipCB->setChecked(igp.noUnzip);
521 // Update the subcaption check button and input field
522 subfigure->setChecked(igp.subcaption);
523 subcaption->setText(toqstr(igp.subcaptionText));
526 switch (igp.display) {
527 case graphics::DefaultDisplay: item = 0; break;
528 case graphics::MonochromeDisplay: item = 1; break;
529 case graphics::GrayscaleDisplay: item = 2; break;
530 case graphics::ColorDisplay: item = 3; break;
531 case graphics::NoDisplay: item = 0; break;
533 showCB->setCurrentIndex(item);
534 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
535 displayGB->setChecked(igp.display != graphics::NoDisplay);
537 // the output section (width/height)
539 Scale->setText(toqstr(igp.scale));
540 //igp.scale defaults to 100, so we treat it as empty
541 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
542 scaleCB->blockSignals(true);
543 scaleCB->setChecked(scaleChecked);
544 scaleCB->blockSignals(false);
545 Scale->setEnabled(scaleChecked);
547 lengthAutoToWidgets(Width, widthUnit, igp.width,
549 bool const widthChecked = !Width->text().isEmpty() &&
550 Width->text() != "auto";
551 WidthCB->blockSignals(true);
552 WidthCB->setChecked(widthChecked);
553 WidthCB->blockSignals(false);
554 Width->setEnabled(widthChecked);
555 widthUnit->setEnabled(widthChecked);
557 lengthAutoToWidgets(Height, heightUnit, igp.height,
559 bool const heightChecked = !Height->text().isEmpty()
560 && Height->text() != "auto";
561 HeightCB->blockSignals(true);
562 HeightCB->setChecked(heightChecked);
563 HeightCB->blockSignals(false);
564 Height->setEnabled(heightChecked);
565 heightUnit->setEnabled(heightChecked);
567 scaleCB->setEnabled(!widthChecked && !heightChecked);
568 WidthCB->setEnabled(!scaleChecked);
569 HeightCB->setEnabled(!scaleChecked);
570 aspectratio->setEnabled(widthChecked && heightChecked);
574 angle->setText(toqstr(igp.rotateAngle));
575 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
577 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
578 && igp.rotateAngle != "0");
582 vector<RotationOriginPair> origindata = getRotationOriginData();
583 vector<docstring> const origin_lang = getFirst(origindata);
584 origin_ltx = getSecond(origindata);
586 for (vector<docstring>::const_iterator it = origin_lang.begin();
587 it != origin_lang.end(); ++it)
588 origin->addItem(toqstr(*it));
590 if (!igp.rotateOrigin.empty())
591 origin->setCurrentIndex(
592 getItemNo(origin_ltx, igp.rotateOrigin));
594 origin->setCurrentIndex(0);
596 // disable edit button when no filename is present
597 editPB->setDisabled(filename->text().isEmpty());
600 latexoptions->setText(toqstr(igp.special));
604 void GuiGraphics::applyView()
606 InsetGraphicsParams & igp = params_;
608 igp.filename.set(fromqstr(filename->text()), bufferFilepath());
609 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
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();
645 igp.subcaption = subfigure->isChecked();
646 igp.subcaptionText = fromqstr(subcaption->text());
648 switch (showCB->currentIndex()) {
649 case 0: igp.display = graphics::DefaultDisplay; break;
650 case 1: igp.display = graphics::MonochromeDisplay; break;
651 case 2: igp.display = graphics::GrayscaleDisplay; break;
652 case 3: igp.display = graphics::ColorDisplay; break;
656 if (!displayGB->isChecked())
657 igp.display = graphics::NoDisplay;
659 //the graphics section
660 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
661 igp.scale = fromqstr(Scale->text());
662 igp.width = Length("0pt");
663 igp.height = Length("0pt");
664 igp.keepAspectRatio = false;
666 igp.scale = string();
667 igp.width = WidthCB->isChecked() ?
668 //Note that this works even if Width is "auto", since in
669 //that case we get "0pt".
670 Length(widgetsToLength(Width, widthUnit)):
672 igp.height = HeightCB->isChecked() ?
673 Length(widgetsToLength(Height, heightUnit)) :
675 igp.keepAspectRatio = aspectratio->isEnabled() &&
676 aspectratio->isChecked() &&
677 igp.width.value() > 0 && igp.height.value() > 0;
680 igp.noUnzip = unzipCB->isChecked();
681 igp.lyxscale = displayscale->text().toInt();
682 igp.rotateAngle = fromqstr(angle->text());
684 double rotAngle = convert<double>(igp.rotateAngle);
685 if (std::abs(rotAngle) > 360.0) {
686 rotAngle -= 360.0 * floor(rotAngle / 360.0);
687 igp.rotateAngle = convert<string>(rotAngle);
690 // save the latex name for the origin. If it is the default
691 // then origin_ltx returns ""
692 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
693 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
695 // more latex options
696 igp.special = fromqstr(latexoptions->text());
700 void GuiGraphics::getBB()
702 string const fn = fromqstr(filename->text());
705 string const bb = readBB(fn);
709 lbX->setText(toqstr(token(bb, ' ', 0)));
710 lbY->setText(toqstr(token(bb, ' ', 1)));
711 rtX->setText(toqstr(token(bb, ' ', 2)));
712 rtY->setText(toqstr(token(bb, ' ', 3)));
713 // the default units for the bb values when reading
715 lbXunit->setCurrentIndex(0);
716 lbYunit->setCurrentIndex(0);
717 rtXunit->setCurrentIndex(0);
718 rtYunit->setCurrentIndex(0);
722 bool GuiGraphics::isValid()
724 return !filename->text().isEmpty();
728 bool GuiGraphics::initialiseParams(string const & data)
730 InsetGraphicsMailer::string2params(data, buffer(), params_);
735 void GuiGraphics::clearParams()
737 params_ = InsetGraphicsParams();
741 void GuiGraphics::dispatchParams()
743 InsetGraphicsParams tmp_params(params_);
745 InsetGraphicsMailer::params2string(tmp_params, buffer());
746 dispatch(FuncRequest(getLfun(), lfun));
750 docstring const GuiGraphics::browse(docstring const & in_name) const
752 docstring const title = _("Select graphics file");
754 // Does user clipart directory exist?
755 string clipdir = addName(package().user_support().absFilename(), "clipart");
756 FileName clip(clipdir);
758 // bail out to system clipart directory
759 if (!(clip.exists() && clip.isDirectory()))
760 clipdir = addName(package().system_support().absFilename(), "clipart");
762 return browseRelFile(in_name, from_utf8(bufferFilepath()),
763 title, FileFilterList(), false,
764 _("Clipart|#C#c"), from_utf8(clipdir),
765 _("Documents|#o#O"), from_utf8(lyxrc.document_path));
769 string const GuiGraphics::readBB(string const & file)
771 FileName const abs_file = makeAbsPath(file, bufferFilepath());
773 // try to get it from the file, if possible. Zipped files are
774 // unzipped in the readBB_from_PSFile-Function
775 string const bb = readBB_from_PSFile(abs_file);
779 // we don't, so ask the Graphics Cache if it has loaded the file
783 graphics::Cache & gc = graphics::Cache::get();
784 if (gc.inCache(abs_file)) {
785 graphics::Image const * image = gc.item(abs_file)->image();
788 width = image->width();
789 height = image->height();
793 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
797 bool GuiGraphics::isFilenameValid(string const & fname) const
799 // It may be that the filename is relative.
800 return makeAbsPath(fname, bufferFilepath()).isReadableFile();
804 void GuiGraphics::editGraphics()
808 InsetGraphicsMailer::params2string(params_, buffer());
809 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
815 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
816 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
818 // These are the strings that are stored in the LyX file and which
819 // correspond to the LaTeX identifiers shown in the comments at the
821 char const * const rorigin_lyx_strs[] = {
822 // the LaTeX default is leftBaseline
824 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
825 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
826 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
828 // These are the strings, corresponding to the above, that the GUI should
829 // use. Note that they can/should be translated.
830 char const * const rorigin_gui_strs[] = {
832 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
833 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
834 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
836 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
841 vector<string> const getBBUnits()
843 return vector<string>(bb_units, bb_units + bb_size);
847 vector<RotationOriginPair> getRotationOriginData()
849 static vector<RotationOriginPair> data;
853 data.resize(rorigin_size);
854 for (size_type i = 0; i < rorigin_size; ++i) {
855 data[i] = make_pair(_(rorigin_gui_strs[i]),
856 rorigin_lyx_strs[i]);
863 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
866 } // namespace frontend
869 #include "GuiGraphics_moc.cpp"