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>
58 using namespace lyx::support;
63 //FIXME setAutoTextCB should really take an argument, as indicated, that
64 //determines what text is to be written for "auto". But making
65 //that work involves more extensive revisions than we now want
66 //to make, since "auto" also appears in updateContents() (see
68 //The right way to do this, I think, would be to define a class
69 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
70 //the checkbox, line edit, and length combo together, and then made e.g.
71 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
72 //Perhaps even the validator could be exposed through it.
74 * sets a checkbox-line edit-length combo group, using "text" if the
75 * checkbox is unchecked and clearing the line edit if it previously
78 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
79 LengthCombo * lengthCombo/*, string text = "auto"*/)
81 if (!checkBox->isChecked())
82 lengthToWidgets(lineEdit, lengthCombo,
83 "auto", lengthCombo->currentLengthItem());
84 else if (lineEdit->text() == "auto")
85 lengthToWidgets(lineEdit, lengthCombo, string(),
86 lengthCombo->currentLengthItem());
90 vector<typename Pair::first_type> const
91 getFirst(vector<Pair> const & pr)
93 vector<typename Pair::first_type> tmp(pr.size());
94 transform(pr.begin(), pr.end(), tmp.begin(),
95 boost::bind(&Pair::first, _1));
101 vector<typename Pair::second_type> const
102 getSecond(vector<Pair> const & pr)
104 vector<typename Pair::second_type> tmp(pr.size());
105 transform(pr.begin(), pr.end(), tmp.begin(),
106 boost::bind(&Pair::second, _1));
110 /// The (tranlated) GUI std::string and it's LaTeX equivalent.
111 typedef std::pair<docstring, std::string> RotationOriginPair;
113 std::vector<RotationOriginPair> getRotationOriginData();
116 GuiGraphics::GuiGraphics(GuiView & lv)
117 : GuiDialog(lv, "graphics")
120 setViewTitle(_("Graphics"));
123 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
124 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
125 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
126 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
129 connect(filename, SIGNAL(textChanged(const QString &)),
130 this, SLOT(change_adaptor()));
131 connect(WidthCB, SIGNAL( clicked()),
132 this, SLOT(change_adaptor()));
133 connect(HeightCB, SIGNAL( clicked()),
134 this, SLOT(change_adaptor()));
135 connect(Width, SIGNAL(textChanged(const QString &)),
136 this, SLOT(change_adaptor()));
137 connect(Height, SIGNAL(textChanged(const QString &)),
138 this, SLOT(change_adaptor()));
139 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
140 this, SLOT(change_adaptor()));
141 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
142 this, SLOT(change_adaptor()));
143 connect(aspectratio, SIGNAL(stateChanged(int)),
144 this, SLOT(change_adaptor()));
145 connect(angle, SIGNAL(textChanged(const QString &)),
146 this, SLOT(change_adaptor()));
147 connect(origin, SIGNAL(activated(int)),
148 this, SLOT(change_adaptor()));
149 connect(scaleCB, SIGNAL(clicked()),
150 this, SLOT(change_adaptor()));
151 connect(Scale, SIGNAL(textChanged(const QString &)),
152 this, SLOT(change_adaptor()));
153 connect(rotateOrderCB, SIGNAL(clicked()),
154 this, SLOT(change_adaptor()));
156 filename->setValidator(new PathValidator(true, filename));
157 setFocusProxy(filename);
159 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
160 scaleValidator->setBottom(0);
161 scaleValidator->setDecimals(256); //I guess that will do
162 Scale->setValidator(scaleValidator);
163 Height->setValidator(unsignedLengthAutoValidator(Height));
164 Width->setValidator(unsignedLengthAutoValidator(Width));
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(change_bb()));
172 connect(lbYunit, SIGNAL(activated(int)),
173 this, SLOT(change_bb()));
174 connect(rtY, SIGNAL(textChanged(const QString&)),
175 this, SLOT(change_bb()));
176 connect(rtYunit, SIGNAL(activated(int)),
177 this, SLOT(change_bb()));
178 connect(lbX, SIGNAL(textChanged(const QString&)),
179 this, SLOT(change_bb()));
180 connect(lbXunit, SIGNAL(activated(int)),
181 this, SLOT(change_bb()));
182 connect(rtX, SIGNAL(textChanged(const QString&)),
183 this, SLOT(change_bb()));
184 connect(rtXunit, SIGNAL(activated(int)),
185 this, SLOT(change_bb()));
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(subfigure, SIGNAL(toggled(bool)),
209 this, SLOT(change_adaptor()));
210 connect(subcaption, SIGNAL(textChanged(const QString&)),
211 this, SLOT(change_adaptor()));
212 connect(displayGB, SIGNAL(toggled(bool)),
213 this, SLOT(change_adaptor()));
214 connect(showCB, SIGNAL(currentIndexChanged(int)),
215 this, SLOT(change_adaptor()));
216 connect(displayscale, SIGNAL(textChanged(const QString&)),
217 this, SLOT(change_adaptor()));
218 displayscale->setValidator(new QIntValidator(displayscale));
220 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
222 bc().setApply(applyPB);
223 bc().setRestore(restorePB);
224 bc().setCancel(closePB);
226 bc().addReadOnly(latexoptions);
227 bc().addReadOnly(subfigure);
228 bc().addReadOnly(filenameL);
229 bc().addReadOnly(filename);
230 bc().addReadOnly(browsePB);
231 bc().addReadOnly(unzipCB);
232 bc().addReadOnly(bbFrame);
233 bc().addReadOnly(draftCB);
234 bc().addReadOnly(clip);
235 bc().addReadOnly(unzipCB);
236 bc().addReadOnly(displayGB);
237 bc().addReadOnly(sizeGB);
238 bc().addReadOnly(rotationGB);
239 bc().addReadOnly(latexoptions);
240 bc().addReadOnly(getPB);
241 bc().addReadOnly(rotateOrderCB);
243 // initialize the length validator
244 bc().addCheckedLineEdit(Scale, scaleCB);
245 bc().addCheckedLineEdit(Width, WidthCB);
246 bc().addCheckedLineEdit(Height, HeightCB);
247 bc().addCheckedLineEdit(displayscale, scaleLA);
248 bc().addCheckedLineEdit(angle, angleL);
249 bc().addCheckedLineEdit(lbX, xL);
250 bc().addCheckedLineEdit(lbY, yL);
251 bc().addCheckedLineEdit(rtX, xL_2);
252 bc().addCheckedLineEdit(rtY, yL_2);
253 bc().addCheckedLineEdit(filename, filenameL);
257 void GuiGraphics::change_adaptor()
263 void GuiGraphics::change_bb()
266 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
271 void GuiGraphics::closeEvent(QCloseEvent * e)
274 GuiDialog::closeEvent(e);
278 void GuiGraphics::on_browsePB_clicked()
280 docstring const str = browse(qstring_to_ucs4(filename->text()));
282 filename->setText(toqstr(str));
283 embedCB->setCheckState(Qt::Unchecked);
289 void GuiGraphics::on_getPB_clicked()
295 void GuiGraphics::on_editPB_clicked()
301 void GuiGraphics::on_filename_textChanged(const QString & filename)
303 editPB->setDisabled(filename.isEmpty());
307 void GuiGraphics::setAutoText()
309 if (scaleCB->isChecked())
311 if (!Scale->isEnabled() && Scale->text() != "100")
312 Scale->setText(QString("auto"));
314 setAutoTextCB(WidthCB, Width, widthUnit);
315 setAutoTextCB(HeightCB, Height, heightUnit);
319 void GuiGraphics::on_scaleCB_toggled(bool setScale)
321 Scale->setEnabled(setScale);
323 Scale->setText("100");
324 Scale->setFocus(Qt::OtherFocusReason);
327 WidthCB->setDisabled(setScale);
328 WidthCB->blockSignals(true);
329 WidthCB->setChecked(false);
330 WidthCB->blockSignals(false);
331 Width->setEnabled(false);
332 widthUnit->setEnabled(false);
334 HeightCB->setDisabled(setScale);
335 HeightCB->blockSignals(true);
336 HeightCB->setChecked(false);
337 HeightCB->blockSignals(false);
338 Height->setEnabled(false);
339 heightUnit->setEnabled(false);
341 aspectratio->setDisabled(true);
342 aspectratio->setChecked(true);
344 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
345 HeightCB->isChecked() ||
346 scaleCB->isChecked()) &&
347 (angle->text() != "0"));
353 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
355 Width->setEnabled(setWidth);
356 widthUnit->setEnabled(setWidth);
358 Width->setFocus(Qt::OtherFocusReason);
360 bool const setHeight = HeightCB->isChecked();
361 aspectratio->setEnabled(setWidth && setHeight);
362 aspectratio->blockSignals(true);
363 aspectratio->setChecked(!(setWidth && setHeight));
364 aspectratio->blockSignals(false);
366 scaleCB->setEnabled(!setWidth && !setHeight);
367 //already will be unchecked, so don't need to do that
368 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
369 && scaleCB->isChecked()); //should be false, but let's check
370 rotateOrderCB->setEnabled((setWidth || setHeight ||
371 scaleCB->isChecked()) &&
372 (angle->text() != "0"));
378 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
380 Height->setEnabled(setHeight);
381 heightUnit->setEnabled(setHeight);
383 Height->setFocus(Qt::OtherFocusReason);
385 bool const setWidth = WidthCB->isChecked();
386 aspectratio->setEnabled(setWidth && setHeight);
387 aspectratio->blockSignals(true);
388 aspectratio->setChecked(!(setWidth && setHeight));
389 aspectratio->blockSignals(false);
391 scaleCB->setEnabled(!setWidth && !setHeight);
393 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
394 && scaleCB->isChecked()); //should be false
395 rotateOrderCB->setEnabled((setWidth || setHeight ||
396 scaleCB->isChecked()) &&
397 (angle->text() != "0"));
403 void GuiGraphics::on_angle_textChanged(const QString & filename)
405 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
406 HeightCB->isChecked() ||
407 scaleCB->isChecked()) &&
411 // returns the number of the string s in the vector v
412 static int getItemNo(const vector<string> & v, string const & s)
414 vector<string>::const_iterator cit =
415 find(v.begin(), v.end(), s);
416 return (cit != v.end()) ? int(cit - v.begin()) : 0;
420 void GuiGraphics::updateContents()
422 // clear and fill in the comboboxes
423 vector<string> const bb_units = frontend::getBBUnits();
428 for (vector<string>::const_iterator it = bb_units.begin();
429 it != bb_units.end(); ++it) {
430 lbXunit->addItem(toqstr(*it));
431 lbYunit->addItem(toqstr(*it));
432 rtXunit->addItem(toqstr(*it));
433 rtYunit->addItem(toqstr(*it));
436 InsetGraphicsParams & igp = params_;
438 // set the right default unit
439 Length::UNIT unitDefault = Length::CM;
440 switch (lyxrc.default_papersize) {
443 case PAPER_USEXECUTIVE:
444 unitDefault = Length::IN;
451 igp.filename.outputFilename(bufferFilepath());
452 filename->setText(toqstr(name));
453 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
455 // set the bounding box values
456 if (igp.bb.empty()) {
457 string const bb = readBB(igp.filename.absFilename());
458 // the values from the file always have the bigpoint-unit bp
459 lbX->setText(toqstr(token(bb, ' ', 0)));
460 lbY->setText(toqstr(token(bb, ' ', 1)));
461 rtX->setText(toqstr(token(bb, ' ', 2)));
462 rtY->setText(toqstr(token(bb, ' ', 3)));
463 lbXunit->setCurrentIndex(0);
464 lbYunit->setCurrentIndex(0);
465 rtXunit->setCurrentIndex(0);
466 rtYunit->setCurrentIndex(0);
469 // get the values from the inset
471 string const xl = token(igp.bb, ' ', 0);
472 string const yl = token(igp.bb, ' ', 1);
473 string const xr = token(igp.bb, ' ', 2);
474 string const yr = token(igp.bb, ' ', 3);
475 if (isValidLength(xl, &anyLength)) {
476 lbX->setText(toqstr(convert<string>(anyLength.value())));
477 string const unit(unit_name[anyLength.unit()]);
478 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
480 lbX->setText(toqstr(xl));
482 if (isValidLength(yl, &anyLength)) {
483 lbY->setText(toqstr(convert<string>(anyLength.value())));
484 string const unit(unit_name[anyLength.unit()]);
485 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
487 lbY->setText(toqstr(xl));
489 if (isValidLength(xr, &anyLength)) {
490 rtX->setText(toqstr(convert<string>(anyLength.value())));
491 string const unit(unit_name[anyLength.unit()]);
492 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
494 rtX->setText(toqstr(xl));
496 if (isValidLength(yr, &anyLength)) {
497 rtY->setText(toqstr(convert<string>(anyLength.value())));
498 string const unit(unit_name[anyLength.unit()]);
499 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
501 rtY->setText(toqstr(xl));
506 // Update the draft and clip mode
507 draftCB->setChecked(igp.draft);
508 clip->setChecked(igp.clip);
509 unzipCB->setChecked(igp.noUnzip);
511 // Update the subcaption check button and input field
512 subfigure->setChecked(igp.subcaption);
513 subcaption->setText(toqstr(igp.subcaptionText));
516 switch (igp.display) {
517 case graphics::DefaultDisplay: item = 0; break;
518 case graphics::MonochromeDisplay: item = 1; break;
519 case graphics::GrayscaleDisplay: item = 2; break;
520 case graphics::ColorDisplay: item = 3; break;
521 case graphics::NoDisplay: item = 0; break;
523 showCB->setCurrentIndex(item);
524 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
525 displayGB->setChecked(igp.display != graphics::NoDisplay);
527 // the output section (width/height)
529 Scale->setText(toqstr(igp.scale));
530 //igp.scale defaults to 100, so we treat it as empty
531 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
532 scaleCB->blockSignals(true);
533 scaleCB->setChecked(scaleChecked);
534 scaleCB->blockSignals(false);
535 Scale->setEnabled(scaleChecked);
537 lengthAutoToWidgets(Width, widthUnit, igp.width,
539 bool const widthChecked = !Width->text().isEmpty() &&
540 Width->text() != "auto";
541 WidthCB->blockSignals(true);
542 WidthCB->setChecked(widthChecked);
543 WidthCB->blockSignals(false);
544 Width->setEnabled(widthChecked);
545 widthUnit->setEnabled(widthChecked);
547 lengthAutoToWidgets(Height, heightUnit, igp.height,
549 bool const heightChecked = !Height->text().isEmpty()
550 && Height->text() != "auto";
551 HeightCB->blockSignals(true);
552 HeightCB->setChecked(heightChecked);
553 HeightCB->blockSignals(false);
554 Height->setEnabled(heightChecked);
555 heightUnit->setEnabled(heightChecked);
557 scaleCB->setEnabled(!widthChecked && !heightChecked);
558 WidthCB->setEnabled(!scaleChecked);
559 HeightCB->setEnabled(!scaleChecked);
560 aspectratio->setEnabled(widthChecked && heightChecked);
564 angle->setText(toqstr(igp.rotateAngle));
565 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
567 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
568 && igp.rotateAngle != "0");
572 vector<RotationOriginPair> origindata = getRotationOriginData();
573 vector<docstring> const origin_lang = getFirst(origindata);
574 origin_ltx = getSecond(origindata);
576 for (vector<docstring>::const_iterator it = origin_lang.begin();
577 it != origin_lang.end(); ++it)
578 origin->addItem(toqstr(*it));
580 if (!igp.rotateOrigin.empty())
581 origin->setCurrentIndex(
582 getItemNo(origin_ltx, igp.rotateOrigin));
584 origin->setCurrentIndex(0);
586 // disable edit button when no filename is present
587 editPB->setDisabled(filename->text().isEmpty());
590 latexoptions->setText(toqstr(igp.special));
594 void GuiGraphics::applyView()
596 InsetGraphicsParams & igp = params_;
598 igp.filename.set(fromqstr(filename->text()), bufferFilepath());
599 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
605 string lbXs = fromqstr(lbX->text());
606 string lbYs = fromqstr(lbY->text());
607 string rtXs = fromqstr(rtX->text());
608 string rtYs = fromqstr(rtY->text());
610 convert<int>(lbXs) + convert<int>(lbYs) +
611 convert<int>(rtXs) + convert<int>(rtXs);
616 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
620 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
624 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
628 bb += (rtYs + fromqstr(rtYunit->currentText()));
633 igp.draft = draftCB->isChecked();
634 igp.clip = clip->isChecked();
635 igp.subcaption = subfigure->isChecked();
636 igp.subcaptionText = fromqstr(subcaption->text());
638 switch (showCB->currentIndex()) {
639 case 0: igp.display = graphics::DefaultDisplay; break;
640 case 1: igp.display = graphics::MonochromeDisplay; break;
641 case 2: igp.display = graphics::GrayscaleDisplay; break;
642 case 3: igp.display = graphics::ColorDisplay; break;
646 if (!displayGB->isChecked())
647 igp.display = graphics::NoDisplay;
649 //the graphics section
650 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
651 igp.scale = fromqstr(Scale->text());
652 igp.width = Length("0pt");
653 igp.height = Length("0pt");
654 igp.keepAspectRatio = false;
656 igp.scale = string();
657 igp.width = WidthCB->isChecked() ?
658 //Note that this works even if Width is "auto", since in
659 //that case we get "0pt".
660 Length(widgetsToLength(Width, widthUnit)):
662 igp.height = HeightCB->isChecked() ?
663 Length(widgetsToLength(Height, heightUnit)) :
665 igp.keepAspectRatio = aspectratio->isEnabled() &&
666 aspectratio->isChecked() &&
667 igp.width.value() > 0 && igp.height.value() > 0;
670 igp.noUnzip = unzipCB->isChecked();
671 igp.lyxscale = displayscale->text().toInt();
672 igp.rotateAngle = fromqstr(angle->text());
674 double rotAngle = convert<double>(igp.rotateAngle);
675 if (std::abs(rotAngle) > 360.0) {
676 rotAngle -= 360.0 * floor(rotAngle / 360.0);
677 igp.rotateAngle = convert<string>(rotAngle);
680 // save the latex name for the origin. If it is the default
681 // then origin_ltx returns ""
682 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
683 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
685 // more latex options
686 igp.special = fromqstr(latexoptions->text());
690 void GuiGraphics::getBB()
692 string const fn = fromqstr(filename->text());
695 string const bb = readBB(fn);
699 lbX->setText(toqstr(token(bb, ' ', 0)));
700 lbY->setText(toqstr(token(bb, ' ', 1)));
701 rtX->setText(toqstr(token(bb, ' ', 2)));
702 rtY->setText(toqstr(token(bb, ' ', 3)));
703 // the default units for the bb values when reading
705 lbXunit->setCurrentIndex(0);
706 lbYunit->setCurrentIndex(0);
707 rtXunit->setCurrentIndex(0);
708 rtYunit->setCurrentIndex(0);
712 bool GuiGraphics::isValid()
714 return !filename->text().isEmpty();
718 bool GuiGraphics::initialiseParams(string const & data)
720 InsetGraphicsMailer::string2params(data, buffer(), params_);
725 void GuiGraphics::clearParams()
727 params_ = InsetGraphicsParams();
731 void GuiGraphics::dispatchParams()
733 InsetGraphicsParams tmp_params(params_);
735 InsetGraphicsMailer::params2string(tmp_params, buffer());
736 dispatch(FuncRequest(getLfun(), lfun));
740 docstring const GuiGraphics::browse(docstring const & in_name) const
742 docstring const title = _("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.exists() && clip.isDirectory()))
750 clipdir = addName(package().system_support().absFilename(), "clipart");
752 return browseRelFile(in_name, from_utf8(bufferFilepath()),
753 title, FileFilterList(), false,
754 _("Clipart|#C#c"), from_utf8(clipdir),
755 _("Documents|#o#O"), from_utf8(lyxrc.document_path));
759 string const GuiGraphics::readBB(string const & file)
761 FileName const abs_file = makeAbsPath(file, 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 makeAbsPath(fname, bufferFilepath()).isReadableFile();
794 void GuiGraphics::editGraphics()
798 InsetGraphicsMailer::params2string(params_, buffer());
799 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
805 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
806 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
808 // These are the strings that are stored in the LyX file and which
809 // correspond to the LaTeX identifiers shown in the comments at the
811 char const * const rorigin_lyx_strs[] = {
812 // the LaTeX default is leftBaseline
814 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
815 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
816 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
818 // These are the strings, corresponding to the above, that the GUI should
819 // use. Note that they can/should be translated.
820 char const * const rorigin_gui_strs[] = {
822 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
823 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
824 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
826 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
831 vector<string> const getBBUnits()
833 return vector<string>(bb_units, bb_units + bb_size);
837 vector<RotationOriginPair> getRotationOriginData()
839 static vector<RotationOriginPair> data;
843 data.resize(rorigin_size);
844 for (size_type i = 0; i < rorigin_size; ++i) {
845 data[i] = make_pair(_(rorigin_gui_strs[i]),
846 rorigin_lyx_strs[i]);
853 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
856 } // namespace frontend
859 #include "GuiGraphics_moc.cpp"