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/os.h"
40 #include "support/Package.h"
41 #include "support/types.h"
43 #include <boost/bind.hpp>
46 #include <QCloseEvent>
49 #include <QPushButton>
57 using namespace lyx::support;
62 //FIXME setAutoTextCB should really take an argument, as indicated, that
63 //determines what text is to be written for "auto". But making
64 //that work involves more extensive revisions than we now want
65 //to make, since "auto" also appears in updateContents() (see
67 //The right way to do this, I think, would be to define a class
68 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
69 //the checkbox, line edit, and length combo together, and then made e.g.
70 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
71 //Perhaps even the validator could be exposed through it.
73 * sets a checkbox-line edit-length combo group, using "text" if the
74 * checkbox is unchecked and clearing the line edit if it previously
77 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
78 LengthCombo * lengthCombo/*, string text = "auto"*/)
80 if (!checkBox->isChecked())
81 lengthToWidgets(lineEdit, lengthCombo,
82 "auto", lengthCombo->currentLengthItem());
83 else if (lineEdit->text() == "auto")
84 lengthToWidgets(lineEdit, lengthCombo, string(),
85 lengthCombo->currentLengthItem());
89 vector<typename Pair::first_type> const
90 getFirst(vector<Pair> const & pr)
92 vector<typename Pair::first_type> tmp(pr.size());
93 transform(pr.begin(), pr.end(), tmp.begin(),
94 boost::bind(&Pair::first, _1));
100 vector<typename Pair::second_type> const
101 getSecond(vector<Pair> const & pr)
103 vector<typename Pair::second_type> tmp(pr.size());
104 transform(pr.begin(), pr.end(), tmp.begin(),
105 boost::bind(&Pair::second, _1));
109 /// The (tranlated) GUI string and it's LaTeX equivalent.
110 typedef pair<docstring, string> RotationOriginPair;
112 vector<RotationOriginPair> getRotationOriginData();
115 GuiGraphics::GuiGraphics(GuiView & lv)
116 : GuiDialog(lv, "graphics")
119 setViewTitle(_("Graphics"));
122 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
123 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
124 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
125 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
128 connect(filename, SIGNAL(textChanged(const QString &)),
129 this, SLOT(change_adaptor()));
130 connect(WidthCB, SIGNAL( clicked()),
131 this, SLOT(change_adaptor()));
132 connect(HeightCB, SIGNAL( clicked()),
133 this, SLOT(change_adaptor()));
134 connect(Width, SIGNAL(textChanged(const QString &)),
135 this, SLOT(change_adaptor()));
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 = new DoubleAutoValidator(Scale);
159 scaleValidator->setBottom(0);
160 scaleValidator->setDecimals(256); //I guess that will do
161 Scale->setValidator(scaleValidator);
162 Height->setValidator(unsignedLengthAutoValidator(Height));
163 Width->setValidator(unsignedLengthAutoValidator(Width));
164 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
167 connect(clip, SIGNAL(stateChanged(int)),
168 this, SLOT(change_adaptor()));
169 connect(lbY, SIGNAL(textChanged(const QString&)),
170 this, SLOT(change_bb()));
171 connect(lbYunit, SIGNAL(activated(int)),
172 this, SLOT(change_bb()));
173 connect(rtY, SIGNAL(textChanged(const QString&)),
174 this, SLOT(change_bb()));
175 connect(rtYunit, SIGNAL(activated(int)),
176 this, SLOT(change_bb()));
177 connect(lbX, SIGNAL(textChanged(const QString&)),
178 this, SLOT(change_bb()));
179 connect(lbXunit, SIGNAL(activated(int)),
180 this, SLOT(change_bb()));
181 connect(rtX, SIGNAL(textChanged(const QString&)),
182 this, SLOT(change_bb()));
183 connect(rtXunit, SIGNAL(activated(int)),
184 this, SLOT(change_bb()));
185 connect(getPB, SIGNAL(clicked()),
186 this, SLOT(change_adaptor()));
188 lbX->setValidator(new QDoubleValidator(lbX));
189 lbY->setValidator(new QDoubleValidator(lbY));
190 rtX->setValidator(new QDoubleValidator(rtX));
191 rtY->setValidator(new QDoubleValidator(rtY));
194 connect(latexoptions, SIGNAL(textChanged(const QString&)),
195 this, SLOT(change_adaptor()));
196 connect(draftCB, SIGNAL(stateChanged(int)),
197 this, SLOT(change_adaptor()));
198 connect(unzipCB, SIGNAL(stateChanged(int)),
199 this, SLOT(change_adaptor()));
200 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
201 // the toggled(bool) signal is also trigged when we update the widgets
202 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
203 // using blockSignals() to keep from triggering that signal when we call
204 // setChecked(). Note, too, that clicked() would get called whenever it
205 // is clicked, even right clicked (I think), not just whenever it is
207 connect(subfigure, SIGNAL(toggled(bool)),
208 this, SLOT(change_adaptor()));
209 connect(subcaption, SIGNAL(textChanged(const QString&)),
210 this, SLOT(change_adaptor()));
211 connect(displayGB, SIGNAL(toggled(bool)),
212 this, SLOT(change_adaptor()));
213 connect(showCB, SIGNAL(currentIndexChanged(int)),
214 this, SLOT(change_adaptor()));
215 connect(displayscale, SIGNAL(textChanged(const QString&)),
216 this, SLOT(change_adaptor()));
217 displayscale->setValidator(new QIntValidator(displayscale));
219 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
221 bc().setApply(applyPB);
222 bc().setRestore(restorePB);
223 bc().setCancel(closePB);
225 bc().addReadOnly(latexoptions);
226 bc().addReadOnly(subfigure);
227 bc().addReadOnly(filenameL);
228 bc().addReadOnly(filename);
229 bc().addReadOnly(browsePB);
230 bc().addReadOnly(unzipCB);
231 bc().addReadOnly(bbFrame);
232 bc().addReadOnly(draftCB);
233 bc().addReadOnly(clip);
234 bc().addReadOnly(unzipCB);
235 bc().addReadOnly(displayGB);
236 bc().addReadOnly(sizeGB);
237 bc().addReadOnly(rotationGB);
238 bc().addReadOnly(latexoptions);
239 bc().addReadOnly(getPB);
240 bc().addReadOnly(rotateOrderCB);
242 // initialize the length validator
243 bc().addCheckedLineEdit(Scale, scaleCB);
244 bc().addCheckedLineEdit(Width, WidthCB);
245 bc().addCheckedLineEdit(Height, HeightCB);
246 bc().addCheckedLineEdit(displayscale, scaleLA);
247 bc().addCheckedLineEdit(angle, angleL);
248 bc().addCheckedLineEdit(lbX, xL);
249 bc().addCheckedLineEdit(lbY, yL);
250 bc().addCheckedLineEdit(rtX, xL_2);
251 bc().addCheckedLineEdit(rtY, yL_2);
252 bc().addCheckedLineEdit(filename, filenameL);
256 void GuiGraphics::change_adaptor()
262 void GuiGraphics::change_bb()
265 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
270 void GuiGraphics::closeEvent(QCloseEvent * e)
273 GuiDialog::closeEvent(e);
277 void GuiGraphics::on_browsePB_clicked()
279 docstring const str = browse(qstring_to_ucs4(filename->text()));
281 filename->setText(toqstr(str));
282 embedCB->setCheckState(Qt::Unchecked);
288 void GuiGraphics::on_getPB_clicked()
294 void GuiGraphics::on_editPB_clicked()
300 void GuiGraphics::on_filename_textChanged(const QString & filename)
302 editPB->setDisabled(filename.isEmpty());
306 void GuiGraphics::setAutoText()
308 if (scaleCB->isChecked())
310 if (!Scale->isEnabled() && Scale->text() != "100")
311 Scale->setText(QString("auto"));
313 setAutoTextCB(WidthCB, Width, widthUnit);
314 setAutoTextCB(HeightCB, Height, heightUnit);
318 void GuiGraphics::on_scaleCB_toggled(bool setScale)
320 Scale->setEnabled(setScale);
322 Scale->setText("100");
323 Scale->setFocus(Qt::OtherFocusReason);
326 WidthCB->setDisabled(setScale);
327 WidthCB->blockSignals(true);
328 WidthCB->setChecked(false);
329 WidthCB->blockSignals(false);
330 Width->setEnabled(false);
331 widthUnit->setEnabled(false);
333 HeightCB->setDisabled(setScale);
334 HeightCB->blockSignals(true);
335 HeightCB->setChecked(false);
336 HeightCB->blockSignals(false);
337 Height->setEnabled(false);
338 heightUnit->setEnabled(false);
340 aspectratio->setDisabled(true);
341 aspectratio->setChecked(true);
343 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
344 HeightCB->isChecked() ||
345 scaleCB->isChecked()) &&
346 (angle->text() != "0"));
352 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
354 Width->setEnabled(setWidth);
355 widthUnit->setEnabled(setWidth);
357 Width->setFocus(Qt::OtherFocusReason);
359 bool const setHeight = HeightCB->isChecked();
360 aspectratio->setEnabled(setWidth && setHeight);
361 aspectratio->blockSignals(true);
362 aspectratio->setChecked(!(setWidth && setHeight));
363 aspectratio->blockSignals(false);
365 scaleCB->setEnabled(!setWidth && !setHeight);
366 //already will be unchecked, so don't need to do that
367 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
368 && scaleCB->isChecked()); //should be false, but let's check
369 rotateOrderCB->setEnabled((setWidth || setHeight ||
370 scaleCB->isChecked()) &&
371 (angle->text() != "0"));
377 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
379 Height->setEnabled(setHeight);
380 heightUnit->setEnabled(setHeight);
382 Height->setFocus(Qt::OtherFocusReason);
384 bool const setWidth = WidthCB->isChecked();
385 aspectratio->setEnabled(setWidth && setHeight);
386 aspectratio->blockSignals(true);
387 aspectratio->setChecked(!(setWidth && setHeight));
388 aspectratio->blockSignals(false);
390 scaleCB->setEnabled(!setWidth && !setHeight);
392 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
393 && scaleCB->isChecked()); //should be false
394 rotateOrderCB->setEnabled((setWidth || setHeight ||
395 scaleCB->isChecked()) &&
396 (angle->text() != "0"));
402 void GuiGraphics::on_angle_textChanged(const QString & filename)
404 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
405 HeightCB->isChecked() ||
406 scaleCB->isChecked()) &&
410 // returns the number of the string s in the vector v
411 static int getItemNo(const vector<string> & v, string const & s)
413 vector<string>::const_iterator cit =
414 find(v.begin(), v.end(), s);
415 return (cit != v.end()) ? int(cit - v.begin()) : 0;
419 void GuiGraphics::updateContents()
421 // clear and fill in the comboboxes
422 vector<string> const bb_units = frontend::getBBUnits();
427 for (vector<string>::const_iterator it = bb_units.begin();
428 it != bb_units.end(); ++it) {
429 lbXunit->addItem(toqstr(*it));
430 lbYunit->addItem(toqstr(*it));
431 rtXunit->addItem(toqstr(*it));
432 rtYunit->addItem(toqstr(*it));
435 InsetGraphicsParams & igp = params_;
437 // set the right default unit
438 Length::UNIT unitDefault = Length::CM;
439 switch (lyxrc.default_papersize) {
442 case PAPER_USEXECUTIVE:
443 unitDefault = Length::IN;
450 igp.filename.outputFilename(bufferFilepath());
451 filename->setText(toqstr(name));
452 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
454 // set the bounding box values
455 if (igp.bb.empty()) {
456 string const bb = readBB(igp.filename.absFilename());
457 // the values from the file always have the bigpoint-unit bp
458 lbX->setText(toqstr(token(bb, ' ', 0)));
459 lbY->setText(toqstr(token(bb, ' ', 1)));
460 rtX->setText(toqstr(token(bb, ' ', 2)));
461 rtY->setText(toqstr(token(bb, ' ', 3)));
462 lbXunit->setCurrentIndex(0);
463 lbYunit->setCurrentIndex(0);
464 rtXunit->setCurrentIndex(0);
465 rtYunit->setCurrentIndex(0);
468 // get the values from the inset
470 string const xl = token(igp.bb, ' ', 0);
471 string const yl = token(igp.bb, ' ', 1);
472 string const xr = token(igp.bb, ' ', 2);
473 string const yr = token(igp.bb, ' ', 3);
474 if (isValidLength(xl, &anyLength)) {
475 lbX->setText(toqstr(convert<string>(anyLength.value())));
476 string const unit(unit_name[anyLength.unit()]);
477 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
479 lbX->setText(toqstr(xl));
481 if (isValidLength(yl, &anyLength)) {
482 lbY->setText(toqstr(convert<string>(anyLength.value())));
483 string const unit(unit_name[anyLength.unit()]);
484 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
486 lbY->setText(toqstr(xl));
488 if (isValidLength(xr, &anyLength)) {
489 rtX->setText(toqstr(convert<string>(anyLength.value())));
490 string const unit(unit_name[anyLength.unit()]);
491 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
493 rtX->setText(toqstr(xl));
495 if (isValidLength(yr, &anyLength)) {
496 rtY->setText(toqstr(convert<string>(anyLength.value())));
497 string const unit(unit_name[anyLength.unit()]);
498 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
500 rtY->setText(toqstr(xl));
505 // Update the draft and clip mode
506 draftCB->setChecked(igp.draft);
507 clip->setChecked(igp.clip);
508 unzipCB->setChecked(igp.noUnzip);
510 // Update the subcaption check button and input field
511 subfigure->setChecked(igp.subcaption);
512 subcaption->setText(toqstr(igp.subcaptionText));
515 switch (igp.display) {
516 case graphics::DefaultDisplay: item = 0; break;
517 case graphics::MonochromeDisplay: item = 1; break;
518 case graphics::GrayscaleDisplay: item = 2; break;
519 case graphics::ColorDisplay: item = 3; break;
520 case graphics::NoDisplay: item = 0; break;
522 showCB->setCurrentIndex(item);
523 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
524 displayGB->setChecked(igp.display != graphics::NoDisplay);
526 // the output section (width/height)
528 Scale->setText(toqstr(igp.scale));
529 //igp.scale defaults to 100, so we treat it as empty
530 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
531 scaleCB->blockSignals(true);
532 scaleCB->setChecked(scaleChecked);
533 scaleCB->blockSignals(false);
534 Scale->setEnabled(scaleChecked);
536 lengthAutoToWidgets(Width, widthUnit, igp.width,
538 bool const widthChecked = !Width->text().isEmpty() &&
539 Width->text() != "auto";
540 WidthCB->blockSignals(true);
541 WidthCB->setChecked(widthChecked);
542 WidthCB->blockSignals(false);
543 Width->setEnabled(widthChecked);
544 widthUnit->setEnabled(widthChecked);
546 lengthAutoToWidgets(Height, heightUnit, igp.height,
548 bool const heightChecked = !Height->text().isEmpty()
549 && Height->text() != "auto";
550 HeightCB->blockSignals(true);
551 HeightCB->setChecked(heightChecked);
552 HeightCB->blockSignals(false);
553 Height->setEnabled(heightChecked);
554 heightUnit->setEnabled(heightChecked);
556 scaleCB->setEnabled(!widthChecked && !heightChecked);
557 WidthCB->setEnabled(!scaleChecked);
558 HeightCB->setEnabled(!scaleChecked);
559 aspectratio->setEnabled(widthChecked && heightChecked);
563 angle->setText(toqstr(igp.rotateAngle));
564 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
566 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
567 && igp.rotateAngle != "0");
571 vector<RotationOriginPair> origindata = getRotationOriginData();
572 vector<docstring> const origin_lang = getFirst(origindata);
573 origin_ltx = getSecond(origindata);
575 for (vector<docstring>::const_iterator it = origin_lang.begin();
576 it != origin_lang.end(); ++it)
577 origin->addItem(toqstr(*it));
579 if (!igp.rotateOrigin.empty())
580 origin->setCurrentIndex(
581 getItemNo(origin_ltx, igp.rotateOrigin));
583 origin->setCurrentIndex(0);
585 // disable edit button when no filename is present
586 editPB->setDisabled(filename->text().isEmpty());
589 latexoptions->setText(toqstr(igp.special));
593 void GuiGraphics::applyView()
595 InsetGraphicsParams & igp = params_;
597 igp.filename.set(fromqstr(filename->text()), bufferFilepath());
598 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
604 string lbXs = fromqstr(lbX->text());
605 string lbYs = fromqstr(lbY->text());
606 string rtXs = fromqstr(rtX->text());
607 string rtYs = fromqstr(rtY->text());
609 convert<int>(lbXs) + convert<int>(lbYs) +
610 convert<int>(rtXs) + convert<int>(rtXs);
615 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
619 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
623 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
627 bb += (rtYs + fromqstr(rtYunit->currentText()));
632 igp.draft = draftCB->isChecked();
633 igp.clip = clip->isChecked();
634 igp.subcaption = subfigure->isChecked();
635 igp.subcaptionText = fromqstr(subcaption->text());
637 switch (showCB->currentIndex()) {
638 case 0: igp.display = graphics::DefaultDisplay; break;
639 case 1: igp.display = graphics::MonochromeDisplay; break;
640 case 2: igp.display = graphics::GrayscaleDisplay; break;
641 case 3: igp.display = graphics::ColorDisplay; break;
645 if (!displayGB->isChecked())
646 igp.display = graphics::NoDisplay;
648 //the graphics section
649 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
650 igp.scale = fromqstr(Scale->text());
651 igp.width = Length("0pt");
652 igp.height = Length("0pt");
653 igp.keepAspectRatio = false;
655 igp.scale = string();
656 igp.width = WidthCB->isChecked() ?
657 //Note that this works even if Width is "auto", since in
658 //that case we get "0pt".
659 Length(widgetsToLength(Width, widthUnit)):
661 igp.height = HeightCB->isChecked() ?
662 Length(widgetsToLength(Height, heightUnit)) :
664 igp.keepAspectRatio = aspectratio->isEnabled() &&
665 aspectratio->isChecked() &&
666 igp.width.value() > 0 && igp.height.value() > 0;
669 igp.noUnzip = unzipCB->isChecked();
670 igp.lyxscale = displayscale->text().toInt();
671 igp.rotateAngle = fromqstr(angle->text());
673 double rotAngle = convert<double>(igp.rotateAngle);
674 if (abs(rotAngle) > 360.0) {
675 rotAngle -= 360.0 * floor(rotAngle / 360.0);
676 igp.rotateAngle = convert<string>(rotAngle);
679 // save the latex name for the origin. If it is the default
680 // then origin_ltx returns ""
681 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
682 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
684 // more latex options
685 igp.special = fromqstr(latexoptions->text());
689 void GuiGraphics::getBB()
691 string const fn = fromqstr(filename->text());
694 string const bb = readBB(fn);
698 lbX->setText(toqstr(token(bb, ' ', 0)));
699 lbY->setText(toqstr(token(bb, ' ', 1)));
700 rtX->setText(toqstr(token(bb, ' ', 2)));
701 rtY->setText(toqstr(token(bb, ' ', 3)));
702 // the default units for the bb values when reading
704 lbXunit->setCurrentIndex(0);
705 lbYunit->setCurrentIndex(0);
706 rtXunit->setCurrentIndex(0);
707 rtYunit->setCurrentIndex(0);
711 bool GuiGraphics::isValid()
713 return !filename->text().isEmpty();
717 bool GuiGraphics::initialiseParams(string const & data)
719 InsetGraphicsMailer::string2params(data, buffer(), params_);
724 void GuiGraphics::clearParams()
726 params_ = InsetGraphicsParams();
730 void GuiGraphics::dispatchParams()
732 InsetGraphicsParams tmp_params(params_);
734 InsetGraphicsMailer::params2string(tmp_params, buffer());
735 dispatch(FuncRequest(getLfun(), lfun));
739 docstring const GuiGraphics::browse(docstring const & in_name) const
741 docstring const title = _("Select graphics file");
743 // Does user clipart directory exist?
744 string clipdir = addName(package().user_support().absFilename(), "clipart");
745 FileName clip(clipdir);
747 // bail out to system clipart directory
748 if (!(clip.exists() && clip.isDirectory()))
749 clipdir = addName(package().system_support().absFilename(), "clipart");
751 return browseRelFile(in_name, from_utf8(bufferFilepath()),
752 title, FileFilterList(), false,
753 _("Clipart|#C#c"), from_utf8(clipdir),
754 _("Documents|#o#O"), from_utf8(lyxrc.document_path));
758 string const GuiGraphics::readBB(string const & file)
760 FileName const abs_file = makeAbsPath(file, bufferFilepath());
762 // try to get it from the file, if possible. Zipped files are
763 // unzipped in the readBB_from_PSFile-Function
764 string const bb = readBB_from_PSFile(abs_file);
768 // we don't, so ask the Graphics Cache if it has loaded the file
772 graphics::Cache & gc = graphics::Cache::get();
773 if (gc.inCache(abs_file)) {
774 graphics::Image const * image = gc.item(abs_file)->image();
777 width = image->width();
778 height = image->height();
782 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
786 bool GuiGraphics::isFilenameValid(string const & fname) const
788 // It may be that the filename is relative.
789 return makeAbsPath(fname, bufferFilepath()).isReadableFile();
793 void GuiGraphics::editGraphics()
797 InsetGraphicsMailer::params2string(params_, buffer());
798 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
804 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
805 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
807 // These are the strings that are stored in the LyX file and which
808 // correspond to the LaTeX identifiers shown in the comments at the
810 char const * const rorigin_lyx_strs[] = {
811 // the LaTeX default is leftBaseline
813 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
814 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
815 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
817 // These are the strings, corresponding to the above, that the GUI should
818 // use. Note that they can/should be translated.
819 char const * const rorigin_gui_strs[] = {
821 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
822 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
823 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
825 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
830 vector<string> const getBBUnits()
832 return vector<string>(bb_units, bb_units + bb_size);
836 vector<RotationOriginPair> getRotationOriginData()
838 static vector<RotationOriginPair> data;
842 data.resize(rorigin_size);
843 for (size_type i = 0; i < rorigin_size; ++i) {
844 data[i] = make_pair(_(rorigin_gui_strs[i]),
845 rorigin_lyx_strs[i]);
852 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
855 } // namespace frontend
858 #include "GuiGraphics_moc.cpp"