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"
20 #include "LengthCombo.h"
23 #include "qt_helpers.h"
24 #include "Validator.h"
26 #include "FuncRequest.h"
28 #include "graphics/GraphicsCache.h"
29 #include "graphics/GraphicsCacheItem.h"
30 #include "graphics/GraphicsImage.h"
32 #include "frontends/alert.h"
34 #include "insets/InsetGraphicsParams.h"
36 #include "support/convert.h"
37 #include "support/debug.h"
38 #include "support/ExceptionMessage.h"
39 #include "support/FileFilterList.h"
40 #include "support/filetools.h"
41 #include "support/gettext.h"
42 #include "support/lstrings.h"
43 #include "support/os.h"
44 #include "support/Package.h"
45 #include "support/types.h"
50 #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());
90 vector<typename Pair::first_type> getFirst(vector<Pair> const & pr)
92 size_t const n = pr.size();
93 vector<typename Pair::first_type> tmp(n);
94 for (size_t i = 0; i != n; ++i)
102 vector<typename Pair::second_type> getSecond(vector<Pair> const & pr)
104 size_t const n = pr.size();
105 vector<typename Pair::second_type> tmp(n);
106 for (size_t i = 0; i != n; ++i)
107 tmp[i] = pr[i].second;
112 /// The (tranlated) GUI string and it's LaTeX equivalent.
113 typedef pair<docstring, string> RotationOriginPair;
115 vector<RotationOriginPair> getRotationOriginData();
118 GuiGraphics::GuiGraphics(GuiView & lv)
119 : GuiDialog(lv, "graphics", qt_("Graphics"))
124 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
125 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
126 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
127 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
130 connect(filename, SIGNAL(textChanged(const QString &)),
131 this, SLOT(change_adaptor()));
132 connect(embedCB, SIGNAL(toggled(bool)),
133 this, SLOT(change_adaptor()));
134 connect(WidthCB, SIGNAL( clicked()),
135 this, SLOT(change_adaptor()));
136 connect(HeightCB, SIGNAL( clicked()),
137 this, SLOT(change_adaptor()));
138 connect(Width, SIGNAL(textChanged(const QString &)),
139 this, SLOT(change_adaptor()));
140 connect(Height, SIGNAL(textChanged(const QString &)),
141 this, SLOT(change_adaptor()));
142 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
143 this, SLOT(change_adaptor()));
144 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
145 this, SLOT(change_adaptor()));
146 connect(aspectratio, SIGNAL(stateChanged(int)),
147 this, SLOT(change_adaptor()));
148 connect(angle, SIGNAL(textChanged(const QString &)),
149 this, SLOT(change_adaptor()));
150 connect(origin, SIGNAL(activated(int)),
151 this, SLOT(change_adaptor()));
152 connect(scaleCB, SIGNAL(clicked()),
153 this, SLOT(change_adaptor()));
154 connect(Scale, SIGNAL(textChanged(const QString &)),
155 this, SLOT(change_adaptor()));
156 connect(rotateOrderCB, SIGNAL(clicked()),
157 this, SLOT(change_adaptor()));
159 filename->setValidator(new PathValidator(true, filename));
160 setFocusProxy(filename);
162 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
163 scaleValidator->setBottom(0);
164 scaleValidator->setDecimals(256); //I guess that will do
165 Scale->setValidator(scaleValidator);
166 Height->setValidator(unsignedLengthAutoValidator(Height));
167 Width->setValidator(unsignedLengthAutoValidator(Width));
168 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
171 connect(clip, SIGNAL(stateChanged(int)),
172 this, SLOT(change_adaptor()));
173 connect(lbY, SIGNAL(textChanged(const QString&)),
174 this, SLOT(change_bb()));
175 connect(lbYunit, SIGNAL(activated(int)),
176 this, SLOT(change_bb()));
177 connect(rtY, SIGNAL(textChanged(const QString&)),
178 this, SLOT(change_bb()));
179 connect(rtYunit, SIGNAL(activated(int)),
180 this, SLOT(change_bb()));
181 connect(lbX, SIGNAL(textChanged(const QString&)),
182 this, SLOT(change_bb()));
183 connect(lbXunit, SIGNAL(activated(int)),
184 this, SLOT(change_bb()));
185 connect(rtX, SIGNAL(textChanged(const QString&)),
186 this, SLOT(change_bb()));
187 connect(rtXunit, SIGNAL(activated(int)),
188 this, SLOT(change_bb()));
189 connect(getPB, SIGNAL(clicked()),
190 this, SLOT(change_adaptor()));
192 lbX->setValidator(new QDoubleValidator(lbX));
193 lbY->setValidator(new QDoubleValidator(lbY));
194 rtX->setValidator(new QDoubleValidator(rtX));
195 rtY->setValidator(new QDoubleValidator(rtY));
198 connect(latexoptions, SIGNAL(textChanged(const QString&)),
199 this, SLOT(change_adaptor()));
200 connect(draftCB, SIGNAL(stateChanged(int)),
201 this, SLOT(change_adaptor()));
202 connect(unzipCB, SIGNAL(stateChanged(int)),
203 this, SLOT(change_adaptor()));
204 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
205 // the toggled(bool) signal is also trigged when we update the widgets
206 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
207 // using blockSignals() to keep from triggering that signal when we call
208 // setChecked(). Note, too, that clicked() would get called whenever it
209 // is clicked, even right clicked (I think), not just whenever it is
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(filenameL);
227 bc().addReadOnly(filename);
228 bc().addReadOnly(browsePB);
229 bc().addReadOnly(unzipCB);
230 bc().addReadOnly(bbFrame);
231 bc().addReadOnly(draftCB);
232 bc().addReadOnly(clip);
233 bc().addReadOnly(unzipCB);
234 bc().addReadOnly(displayGB);
235 bc().addReadOnly(sizeGB);
236 bc().addReadOnly(rotationGB);
237 bc().addReadOnly(latexoptions);
238 bc().addReadOnly(getPB);
239 bc().addReadOnly(rotateOrderCB);
241 // initialize the length validator
242 bc().addCheckedLineEdit(Scale, scaleCB);
243 bc().addCheckedLineEdit(Width, WidthCB);
244 bc().addCheckedLineEdit(Height, HeightCB);
245 bc().addCheckedLineEdit(displayscale, scaleLA);
246 bc().addCheckedLineEdit(angle, angleL);
247 bc().addCheckedLineEdit(lbX, xL);
248 bc().addCheckedLineEdit(lbY, yL);
249 bc().addCheckedLineEdit(rtX, xL_2);
250 bc().addCheckedLineEdit(rtY, yL_2);
251 bc().addCheckedLineEdit(filename, filenameL);
255 void GuiGraphics::change_adaptor()
261 void GuiGraphics::change_bb()
264 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
269 void GuiGraphics::on_browsePB_clicked()
271 QString const str = browse(filename->text());
272 if (!str.isEmpty()) {
273 filename->setText(str);
279 void GuiGraphics::on_getPB_clicked()
285 void GuiGraphics::on_filename_textChanged(const QString & filename)
287 EmbeddedFile file = EmbeddedFile(fromqstr(filename), fromqstr(bufferFilepath()));
291 void GuiGraphics::setAutoText()
293 if (scaleCB->isChecked())
295 if (!Scale->isEnabled() && Scale->text() != "100")
296 Scale->setText(QString("auto"));
298 setAutoTextCB(WidthCB, Width, widthUnit);
299 setAutoTextCB(HeightCB, Height, heightUnit);
303 void GuiGraphics::on_scaleCB_toggled(bool setScale)
305 Scale->setEnabled(setScale);
307 Scale->setText("100");
308 Scale->setFocus(Qt::OtherFocusReason);
311 WidthCB->setDisabled(setScale);
312 WidthCB->blockSignals(true);
313 WidthCB->setChecked(false);
314 WidthCB->blockSignals(false);
315 Width->setEnabled(false);
316 widthUnit->setEnabled(false);
318 HeightCB->setDisabled(setScale);
319 HeightCB->blockSignals(true);
320 HeightCB->setChecked(false);
321 HeightCB->blockSignals(false);
322 Height->setEnabled(false);
323 heightUnit->setEnabled(false);
325 aspectratio->setDisabled(true);
326 aspectratio->setChecked(true);
328 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
329 HeightCB->isChecked() ||
330 scaleCB->isChecked()) &&
331 (angle->text() != "0"));
337 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
339 Width->setEnabled(setWidth);
340 widthUnit->setEnabled(setWidth);
342 Width->setFocus(Qt::OtherFocusReason);
344 bool const setHeight = HeightCB->isChecked();
345 aspectratio->setEnabled(setWidth && setHeight);
346 aspectratio->blockSignals(true);
347 aspectratio->setChecked(!(setWidth && setHeight));
348 aspectratio->blockSignals(false);
350 scaleCB->setEnabled(!setWidth && !setHeight);
351 //already will be unchecked, so don't need to do that
352 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
353 && scaleCB->isChecked()); //should be false, but let's check
354 rotateOrderCB->setEnabled((setWidth || setHeight ||
355 scaleCB->isChecked()) &&
356 (angle->text() != "0"));
362 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
364 Height->setEnabled(setHeight);
365 heightUnit->setEnabled(setHeight);
367 Height->setFocus(Qt::OtherFocusReason);
369 bool const setWidth = WidthCB->isChecked();
370 aspectratio->setEnabled(setWidth && setHeight);
371 aspectratio->blockSignals(true);
372 aspectratio->setChecked(!(setWidth && setHeight));
373 aspectratio->blockSignals(false);
375 scaleCB->setEnabled(!setWidth && !setHeight);
377 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
378 && scaleCB->isChecked()); //should be false
379 rotateOrderCB->setEnabled((setWidth || setHeight ||
380 scaleCB->isChecked()) &&
381 (angle->text() != "0"));
387 void GuiGraphics::on_angle_textChanged(const QString & filename)
389 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
390 HeightCB->isChecked() ||
391 scaleCB->isChecked()) &&
395 // returns the number of the string s in the vector v
396 static int getItemNo(const vector<string> & v, string const & s)
398 vector<string>::const_iterator cit =
399 find(v.begin(), v.end(), s);
400 return (cit != v.end()) ? int(cit - v.begin()) : 0;
404 void GuiGraphics::updateContents()
406 // clear and fill in the comboboxes
407 vector<string> const bb_units = frontend::getBBUnits();
412 for (vector<string>::const_iterator it = bb_units.begin();
413 it != bb_units.end(); ++it) {
414 lbXunit->addItem(toqstr(*it));
415 lbYunit->addItem(toqstr(*it));
416 rtXunit->addItem(toqstr(*it));
417 rtYunit->addItem(toqstr(*it));
420 InsetGraphicsParams & igp = params_;
422 // set the right default unit
423 Length::UNIT unitDefault = Length::CM;
424 switch (lyxrc.default_papersize) {
427 case PAPER_USEXECUTIVE:
428 unitDefault = Length::IN;
435 igp.filename.outputFilename(fromqstr(bufferFilepath()));
436 filename->setText(toqstr(name));
437 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
439 // set the bounding box values
440 if (igp.bb.empty()) {
441 string const bb = readBB(igp.filename.absFilename());
442 // the values from the file always have the bigpoint-unit bp
443 lbX->setText(toqstr(token(bb, ' ', 0)));
444 lbY->setText(toqstr(token(bb, ' ', 1)));
445 rtX->setText(toqstr(token(bb, ' ', 2)));
446 rtY->setText(toqstr(token(bb, ' ', 3)));
447 lbXunit->setCurrentIndex(0);
448 lbYunit->setCurrentIndex(0);
449 rtXunit->setCurrentIndex(0);
450 rtYunit->setCurrentIndex(0);
453 // get the values from the inset
455 string const xl = token(igp.bb, ' ', 0);
456 string const yl = token(igp.bb, ' ', 1);
457 string const xr = token(igp.bb, ' ', 2);
458 string const yr = token(igp.bb, ' ', 3);
459 if (isValidLength(xl, &anyLength)) {
460 lbX->setText(toqstr(convert<string>(anyLength.value())));
461 string const unit(unit_name[anyLength.unit()]);
462 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
464 lbX->setText(toqstr(xl));
466 if (isValidLength(yl, &anyLength)) {
467 lbY->setText(toqstr(convert<string>(anyLength.value())));
468 string const unit(unit_name[anyLength.unit()]);
469 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
471 lbY->setText(toqstr(xl));
473 if (isValidLength(xr, &anyLength)) {
474 rtX->setText(toqstr(convert<string>(anyLength.value())));
475 string const unit(unit_name[anyLength.unit()]);
476 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
478 rtX->setText(toqstr(xl));
480 if (isValidLength(yr, &anyLength)) {
481 rtY->setText(toqstr(convert<string>(anyLength.value())));
482 string const unit(unit_name[anyLength.unit()]);
483 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
485 rtY->setText(toqstr(xl));
490 // Update the draft and clip mode
491 draftCB->setChecked(igp.draft);
492 clip->setChecked(igp.clip);
493 unzipCB->setChecked(igp.noUnzip);
496 switch (igp.display) {
497 case graphics::DefaultDisplay: item = 0; break;
498 case graphics::MonochromeDisplay: item = 1; break;
499 case graphics::GrayscaleDisplay: item = 2; break;
500 case graphics::ColorDisplay: item = 3; break;
501 case graphics::NoDisplay: item = 0; break;
503 showCB->setCurrentIndex(item);
504 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
505 displayGB->setChecked(igp.display != graphics::NoDisplay);
507 // the output section (width/height)
509 Scale->setText(toqstr(igp.scale));
510 //igp.scale defaults to 100, so we treat it as empty
511 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
512 scaleCB->blockSignals(true);
513 scaleCB->setChecked(scaleChecked);
514 scaleCB->blockSignals(false);
515 Scale->setEnabled(scaleChecked);
517 lengthAutoToWidgets(Width, widthUnit, igp.width,
519 bool const widthChecked = !Width->text().isEmpty() &&
520 Width->text() != "auto";
521 WidthCB->blockSignals(true);
522 WidthCB->setChecked(widthChecked);
523 WidthCB->blockSignals(false);
524 Width->setEnabled(widthChecked);
525 widthUnit->setEnabled(widthChecked);
527 lengthAutoToWidgets(Height, heightUnit, igp.height,
529 bool const heightChecked = !Height->text().isEmpty()
530 && Height->text() != "auto";
531 HeightCB->blockSignals(true);
532 HeightCB->setChecked(heightChecked);
533 HeightCB->blockSignals(false);
534 Height->setEnabled(heightChecked);
535 heightUnit->setEnabled(heightChecked);
537 scaleCB->setEnabled(!widthChecked && !heightChecked);
538 WidthCB->setEnabled(!scaleChecked);
539 HeightCB->setEnabled(!scaleChecked);
540 aspectratio->setEnabled(widthChecked && heightChecked);
544 angle->setText(toqstr(igp.rotateAngle));
545 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
547 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
548 && igp.rotateAngle != "0");
552 vector<RotationOriginPair> origindata = getRotationOriginData();
553 vector<docstring> const origin_lang = getFirst(origindata);
554 origin_ltx = getSecond(origindata);
556 for (vector<docstring>::const_iterator it = origin_lang.begin();
557 it != origin_lang.end(); ++it)
558 origin->addItem(toqstr(*it));
560 if (!igp.rotateOrigin.empty())
561 origin->setCurrentIndex(
562 getItemNo(origin_ltx, igp.rotateOrigin));
564 origin->setCurrentIndex(0);
567 latexoptions->setText(toqstr(igp.special));
571 void GuiGraphics::applyView()
573 InsetGraphicsParams & igp = params_;
575 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilepath()));
577 Buffer & buf = buffer();
578 EmbeddedFile file(fromqstr(filename->text()), buf.filePath());
579 file.setEmbed(embedCB->checkState() == Qt::Checked);
580 // move file around if needed, an exception may be raised.
581 file.enable(buf.embedded(), &buf, true);
582 // if things are OK..., embed igp.filename
583 igp.filename.setEmbed(file.embedded());
584 } catch (ExceptionMessage const & message) {
585 Alert::error(message.title_, message.details_);
587 igp.filename.setEmbed(false);
594 string lbXs = fromqstr(lbX->text());
595 string lbYs = fromqstr(lbY->text());
596 string rtXs = fromqstr(rtX->text());
597 string rtYs = fromqstr(rtY->text());
599 convert<int>(lbXs) + convert<int>(lbYs) +
600 convert<int>(rtXs) + convert<int>(rtXs);
605 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
609 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
613 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
617 bb += (rtYs + fromqstr(rtYunit->currentText()));
622 igp.draft = draftCB->isChecked();
623 igp.clip = clip->isChecked();
625 switch (showCB->currentIndex()) {
626 case 0: igp.display = graphics::DefaultDisplay; break;
627 case 1: igp.display = graphics::MonochromeDisplay; break;
628 case 2: igp.display = graphics::GrayscaleDisplay; break;
629 case 3: igp.display = graphics::ColorDisplay; break;
633 if (!displayGB->isChecked())
634 igp.display = graphics::NoDisplay;
636 //the graphics section
637 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
638 igp.scale = fromqstr(Scale->text());
639 igp.width = Length("0pt");
640 igp.height = Length("0pt");
641 igp.keepAspectRatio = false;
643 igp.scale = string();
644 igp.width = WidthCB->isChecked() ?
645 //Note that this works even if Width is "auto", since in
646 //that case we get "0pt".
647 Length(widgetsToLength(Width, widthUnit)):
649 igp.height = HeightCB->isChecked() ?
650 Length(widgetsToLength(Height, heightUnit)) :
652 igp.keepAspectRatio = aspectratio->isEnabled() &&
653 aspectratio->isChecked() &&
654 igp.width.value() > 0 && igp.height.value() > 0;
657 igp.noUnzip = unzipCB->isChecked();
658 igp.lyxscale = displayscale->text().toInt();
659 igp.rotateAngle = fromqstr(angle->text());
661 double rotAngle = convert<double>(igp.rotateAngle);
662 if (abs(rotAngle) > 360.0) {
663 rotAngle -= 360.0 * floor(rotAngle / 360.0);
664 igp.rotateAngle = convert<string>(rotAngle);
667 // save the latex name for the origin. If it is the default
668 // then origin_ltx returns ""
669 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
670 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
672 // more latex options
673 igp.special = fromqstr(latexoptions->text());
677 void GuiGraphics::getBB()
679 string const fn = fromqstr(filename->text());
682 string const bb = readBB(fn);
686 lbX->setText(toqstr(token(bb, ' ', 0)));
687 lbY->setText(toqstr(token(bb, ' ', 1)));
688 rtX->setText(toqstr(token(bb, ' ', 2)));
689 rtY->setText(toqstr(token(bb, ' ', 3)));
690 // the default units for the bb values when reading
692 lbXunit->setCurrentIndex(0);
693 lbYunit->setCurrentIndex(0);
694 rtXunit->setCurrentIndex(0);
695 rtYunit->setCurrentIndex(0);
699 bool GuiGraphics::isValid()
701 return !filename->text().isEmpty();
705 bool GuiGraphics::initialiseParams(string const & data)
707 InsetGraphicsMailer::string2params(data, buffer(), params_);
712 void GuiGraphics::clearParams()
714 params_ = InsetGraphicsParams();
718 void GuiGraphics::dispatchParams()
720 InsetGraphicsParams tmp_params(params_);
722 InsetGraphicsMailer::params2string(tmp_params, buffer());
723 dispatch(FuncRequest(getLfun(), lfun));
727 QString GuiGraphics::browse(QString const & in_name) const
729 QString const title = qt_("Select graphics file");
731 // Does user clipart directory exist?
732 string clipdir = addName(package().user_support().absFilename(), "clipart");
733 FileName clip(clipdir);
735 // bail out to system clipart directory
736 if (!(clip.exists() && clip.isDirectory()))
737 clipdir = addName(package().system_support().absFilename(), "clipart");
739 return browseRelFile(in_name, bufferFilepath(),
740 title, FileFilterList(), false,
741 qt_("Clipart|#C#c"), toqstr(clipdir),
742 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
746 string const GuiGraphics::readBB(string const & file)
748 FileName const abs_file = makeAbsPath(file, fromqstr(bufferFilepath()));
750 // try to get it from the file, if possible. Zipped files are
751 // unzipped in the readBB_from_PSFile-Function
752 string const bb = readBB_from_PSFile(abs_file);
756 // we don't, so ask the Graphics Cache if it has loaded the file
760 graphics::Cache & gc = graphics::Cache::get();
761 if (gc.inCache(abs_file)) {
762 graphics::Image const * image = gc.item(abs_file)->image();
765 width = image->width();
766 height = image->height();
770 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
774 bool GuiGraphics::isFilenameValid(string const & fname) const
776 // It may be that the filename is relative.
777 return makeAbsPath(fname, fromqstr(bufferFilepath())).isReadableFile();
783 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
784 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
786 // These are the strings that are stored in the LyX file and which
787 // correspond to the LaTeX identifiers shown in the comments at the
789 char const * const rorigin_lyx_strs[] = {
790 // the LaTeX default is leftBaseline
792 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
793 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
794 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
796 // These are the strings, corresponding to the above, that the GUI should
797 // use. Note that they can/should be translated.
798 char const * const rorigin_gui_strs[] = {
800 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
801 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
802 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
804 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
809 vector<string> const getBBUnits()
811 return vector<string>(bb_units, bb_units + bb_size);
815 vector<RotationOriginPair> getRotationOriginData()
817 static vector<RotationOriginPair> data;
821 data.resize(rorigin_size);
822 for (size_type i = 0; i < rorigin_size; ++i) {
823 data[i] = make_pair(_(rorigin_gui_strs[i]),
824 rorigin_lyx_strs[i]);
831 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
834 } // namespace frontend
837 #include "GuiGraphics_moc.cpp"