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", qt_("Graphics"))
121 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
122 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
123 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
124 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
127 connect(filename, SIGNAL(textChanged(const QString &)),
128 this, SLOT(change_adaptor()));
129 connect(embedCB, SIGNAL(toggled(bool)),
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::on_browsePB_clicked()
273 docstring const str = browse(qstring_to_ucs4(filename->text()));
275 filename->setText(toqstr(str));
281 void GuiGraphics::on_getPB_clicked()
287 void GuiGraphics::on_editPB_clicked()
293 void GuiGraphics::on_filename_textChanged(const QString & filename)
295 editPB->setDisabled(filename.isEmpty());
296 EmbeddedFile file = EmbeddedFile(fromqstr(filename), bufferFilepath());
300 void GuiGraphics::setAutoText()
302 if (scaleCB->isChecked())
304 if (!Scale->isEnabled() && Scale->text() != "100")
305 Scale->setText(QString("auto"));
307 setAutoTextCB(WidthCB, Width, widthUnit);
308 setAutoTextCB(HeightCB, Height, heightUnit);
312 void GuiGraphics::on_scaleCB_toggled(bool setScale)
314 Scale->setEnabled(setScale);
316 Scale->setText("100");
317 Scale->setFocus(Qt::OtherFocusReason);
320 WidthCB->setDisabled(setScale);
321 WidthCB->blockSignals(true);
322 WidthCB->setChecked(false);
323 WidthCB->blockSignals(false);
324 Width->setEnabled(false);
325 widthUnit->setEnabled(false);
327 HeightCB->setDisabled(setScale);
328 HeightCB->blockSignals(true);
329 HeightCB->setChecked(false);
330 HeightCB->blockSignals(false);
331 Height->setEnabled(false);
332 heightUnit->setEnabled(false);
334 aspectratio->setDisabled(true);
335 aspectratio->setChecked(true);
337 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
338 HeightCB->isChecked() ||
339 scaleCB->isChecked()) &&
340 (angle->text() != "0"));
346 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
348 Width->setEnabled(setWidth);
349 widthUnit->setEnabled(setWidth);
351 Width->setFocus(Qt::OtherFocusReason);
353 bool const setHeight = HeightCB->isChecked();
354 aspectratio->setEnabled(setWidth && setHeight);
355 aspectratio->blockSignals(true);
356 aspectratio->setChecked(!(setWidth && setHeight));
357 aspectratio->blockSignals(false);
359 scaleCB->setEnabled(!setWidth && !setHeight);
360 //already will be unchecked, so don't need to do that
361 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
362 && scaleCB->isChecked()); //should be false, but let's check
363 rotateOrderCB->setEnabled((setWidth || setHeight ||
364 scaleCB->isChecked()) &&
365 (angle->text() != "0"));
371 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
373 Height->setEnabled(setHeight);
374 heightUnit->setEnabled(setHeight);
376 Height->setFocus(Qt::OtherFocusReason);
378 bool const setWidth = WidthCB->isChecked();
379 aspectratio->setEnabled(setWidth && setHeight);
380 aspectratio->blockSignals(true);
381 aspectratio->setChecked(!(setWidth && setHeight));
382 aspectratio->blockSignals(false);
384 scaleCB->setEnabled(!setWidth && !setHeight);
386 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
387 && scaleCB->isChecked()); //should be false
388 rotateOrderCB->setEnabled((setWidth || setHeight ||
389 scaleCB->isChecked()) &&
390 (angle->text() != "0"));
396 void GuiGraphics::on_angle_textChanged(const QString & filename)
398 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
399 HeightCB->isChecked() ||
400 scaleCB->isChecked()) &&
404 // returns the number of the string s in the vector v
405 static int getItemNo(const vector<string> & v, string const & s)
407 vector<string>::const_iterator cit =
408 find(v.begin(), v.end(), s);
409 return (cit != v.end()) ? int(cit - v.begin()) : 0;
413 void GuiGraphics::updateContents()
415 // clear and fill in the comboboxes
416 vector<string> const bb_units = frontend::getBBUnits();
421 for (vector<string>::const_iterator it = bb_units.begin();
422 it != bb_units.end(); ++it) {
423 lbXunit->addItem(toqstr(*it));
424 lbYunit->addItem(toqstr(*it));
425 rtXunit->addItem(toqstr(*it));
426 rtYunit->addItem(toqstr(*it));
429 InsetGraphicsParams & igp = params_;
431 // set the right default unit
432 Length::UNIT unitDefault = Length::CM;
433 switch (lyxrc.default_papersize) {
436 case PAPER_USEXECUTIVE:
437 unitDefault = Length::IN;
444 igp.filename.outputFilename(bufferFilepath());
445 filename->setText(toqstr(name));
446 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
448 // set the bounding box values
449 if (igp.bb.empty()) {
450 string const bb = readBB(igp.filename.absFilename());
451 // the values from the file always have the bigpoint-unit bp
452 lbX->setText(toqstr(token(bb, ' ', 0)));
453 lbY->setText(toqstr(token(bb, ' ', 1)));
454 rtX->setText(toqstr(token(bb, ' ', 2)));
455 rtY->setText(toqstr(token(bb, ' ', 3)));
456 lbXunit->setCurrentIndex(0);
457 lbYunit->setCurrentIndex(0);
458 rtXunit->setCurrentIndex(0);
459 rtYunit->setCurrentIndex(0);
462 // get the values from the inset
464 string const xl = token(igp.bb, ' ', 0);
465 string const yl = token(igp.bb, ' ', 1);
466 string const xr = token(igp.bb, ' ', 2);
467 string const yr = token(igp.bb, ' ', 3);
468 if (isValidLength(xl, &anyLength)) {
469 lbX->setText(toqstr(convert<string>(anyLength.value())));
470 string const unit(unit_name[anyLength.unit()]);
471 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
473 lbX->setText(toqstr(xl));
475 if (isValidLength(yl, &anyLength)) {
476 lbY->setText(toqstr(convert<string>(anyLength.value())));
477 string const unit(unit_name[anyLength.unit()]);
478 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
480 lbY->setText(toqstr(xl));
482 if (isValidLength(xr, &anyLength)) {
483 rtX->setText(toqstr(convert<string>(anyLength.value())));
484 string const unit(unit_name[anyLength.unit()]);
485 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
487 rtX->setText(toqstr(xl));
489 if (isValidLength(yr, &anyLength)) {
490 rtY->setText(toqstr(convert<string>(anyLength.value())));
491 string const unit(unit_name[anyLength.unit()]);
492 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
494 rtY->setText(toqstr(xl));
499 // Update the draft and clip mode
500 draftCB->setChecked(igp.draft);
501 clip->setChecked(igp.clip);
502 unzipCB->setChecked(igp.noUnzip);
504 // Update the subcaption check button and input field
505 subfigure->setChecked(igp.subcaption);
506 subcaption->setText(toqstr(igp.subcaptionText));
509 switch (igp.display) {
510 case graphics::DefaultDisplay: item = 0; break;
511 case graphics::MonochromeDisplay: item = 1; break;
512 case graphics::GrayscaleDisplay: item = 2; break;
513 case graphics::ColorDisplay: item = 3; break;
514 case graphics::NoDisplay: item = 0; break;
516 showCB->setCurrentIndex(item);
517 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
518 displayGB->setChecked(igp.display != graphics::NoDisplay);
520 // the output section (width/height)
522 Scale->setText(toqstr(igp.scale));
523 //igp.scale defaults to 100, so we treat it as empty
524 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
525 scaleCB->blockSignals(true);
526 scaleCB->setChecked(scaleChecked);
527 scaleCB->blockSignals(false);
528 Scale->setEnabled(scaleChecked);
530 lengthAutoToWidgets(Width, widthUnit, igp.width,
532 bool const widthChecked = !Width->text().isEmpty() &&
533 Width->text() != "auto";
534 WidthCB->blockSignals(true);
535 WidthCB->setChecked(widthChecked);
536 WidthCB->blockSignals(false);
537 Width->setEnabled(widthChecked);
538 widthUnit->setEnabled(widthChecked);
540 lengthAutoToWidgets(Height, heightUnit, igp.height,
542 bool const heightChecked = !Height->text().isEmpty()
543 && Height->text() != "auto";
544 HeightCB->blockSignals(true);
545 HeightCB->setChecked(heightChecked);
546 HeightCB->blockSignals(false);
547 Height->setEnabled(heightChecked);
548 heightUnit->setEnabled(heightChecked);
550 scaleCB->setEnabled(!widthChecked && !heightChecked);
551 WidthCB->setEnabled(!scaleChecked);
552 HeightCB->setEnabled(!scaleChecked);
553 aspectratio->setEnabled(widthChecked && heightChecked);
557 angle->setText(toqstr(igp.rotateAngle));
558 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
560 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
561 && igp.rotateAngle != "0");
565 vector<RotationOriginPair> origindata = getRotationOriginData();
566 vector<docstring> const origin_lang = getFirst(origindata);
567 origin_ltx = getSecond(origindata);
569 for (vector<docstring>::const_iterator it = origin_lang.begin();
570 it != origin_lang.end(); ++it)
571 origin->addItem(toqstr(*it));
573 if (!igp.rotateOrigin.empty())
574 origin->setCurrentIndex(
575 getItemNo(origin_ltx, igp.rotateOrigin));
577 origin->setCurrentIndex(0);
579 // disable edit button when no filename is present
580 editPB->setDisabled(filename->text().isEmpty());
583 latexoptions->setText(toqstr(igp.special));
587 void GuiGraphics::applyView()
589 InsetGraphicsParams & igp = params_;
591 igp.filename.set(fromqstr(filename->text()), bufferFilepath());
592 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
598 string lbXs = fromqstr(lbX->text());
599 string lbYs = fromqstr(lbY->text());
600 string rtXs = fromqstr(rtX->text());
601 string rtYs = fromqstr(rtY->text());
603 convert<int>(lbXs) + convert<int>(lbYs) +
604 convert<int>(rtXs) + convert<int>(rtXs);
609 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
613 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
617 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
621 bb += (rtYs + fromqstr(rtYunit->currentText()));
626 igp.draft = draftCB->isChecked();
627 igp.clip = clip->isChecked();
628 igp.subcaption = subfigure->isChecked();
629 igp.subcaptionText = fromqstr(subcaption->text());
631 switch (showCB->currentIndex()) {
632 case 0: igp.display = graphics::DefaultDisplay; break;
633 case 1: igp.display = graphics::MonochromeDisplay; break;
634 case 2: igp.display = graphics::GrayscaleDisplay; break;
635 case 3: igp.display = graphics::ColorDisplay; break;
639 if (!displayGB->isChecked())
640 igp.display = graphics::NoDisplay;
642 //the graphics section
643 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
644 igp.scale = fromqstr(Scale->text());
645 igp.width = Length("0pt");
646 igp.height = Length("0pt");
647 igp.keepAspectRatio = false;
649 igp.scale = string();
650 igp.width = WidthCB->isChecked() ?
651 //Note that this works even if Width is "auto", since in
652 //that case we get "0pt".
653 Length(widgetsToLength(Width, widthUnit)):
655 igp.height = HeightCB->isChecked() ?
656 Length(widgetsToLength(Height, heightUnit)) :
658 igp.keepAspectRatio = aspectratio->isEnabled() &&
659 aspectratio->isChecked() &&
660 igp.width.value() > 0 && igp.height.value() > 0;
663 igp.noUnzip = unzipCB->isChecked();
664 igp.lyxscale = displayscale->text().toInt();
665 igp.rotateAngle = fromqstr(angle->text());
667 double rotAngle = convert<double>(igp.rotateAngle);
668 if (abs(rotAngle) > 360.0) {
669 rotAngle -= 360.0 * floor(rotAngle / 360.0);
670 igp.rotateAngle = convert<string>(rotAngle);
673 // save the latex name for the origin. If it is the default
674 // then origin_ltx returns ""
675 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
676 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
678 // more latex options
679 igp.special = fromqstr(latexoptions->text());
683 void GuiGraphics::getBB()
685 string const fn = fromqstr(filename->text());
688 string const bb = readBB(fn);
692 lbX->setText(toqstr(token(bb, ' ', 0)));
693 lbY->setText(toqstr(token(bb, ' ', 1)));
694 rtX->setText(toqstr(token(bb, ' ', 2)));
695 rtY->setText(toqstr(token(bb, ' ', 3)));
696 // the default units for the bb values when reading
698 lbXunit->setCurrentIndex(0);
699 lbYunit->setCurrentIndex(0);
700 rtXunit->setCurrentIndex(0);
701 rtYunit->setCurrentIndex(0);
705 bool GuiGraphics::isValid()
707 return !filename->text().isEmpty();
711 bool GuiGraphics::initialiseParams(string const & data)
713 InsetGraphicsMailer::string2params(data, buffer(), params_);
718 void GuiGraphics::clearParams()
720 params_ = InsetGraphicsParams();
724 void GuiGraphics::dispatchParams()
726 InsetGraphicsParams tmp_params(params_);
728 InsetGraphicsMailer::params2string(tmp_params, buffer());
729 dispatch(FuncRequest(getLfun(), lfun));
733 docstring const GuiGraphics::browse(docstring const & in_name) const
735 docstring const title = _("Select graphics file");
737 // Does user clipart directory exist?
738 string clipdir = addName(package().user_support().absFilename(), "clipart");
739 FileName clip(clipdir);
741 // bail out to system clipart directory
742 if (!(clip.exists() && clip.isDirectory()))
743 clipdir = addName(package().system_support().absFilename(), "clipart");
745 return browseRelFile(in_name, from_utf8(bufferFilepath()),
746 title, FileFilterList(), false,
747 _("Clipart|#C#c"), from_utf8(clipdir),
748 _("Documents|#o#O"), from_utf8(lyxrc.document_path));
752 string const GuiGraphics::readBB(string const & file)
754 FileName const abs_file = makeAbsPath(file, bufferFilepath());
756 // try to get it from the file, if possible. Zipped files are
757 // unzipped in the readBB_from_PSFile-Function
758 string const bb = readBB_from_PSFile(abs_file);
762 // we don't, so ask the Graphics Cache if it has loaded the file
766 graphics::Cache & gc = graphics::Cache::get();
767 if (gc.inCache(abs_file)) {
768 graphics::Image const * image = gc.item(abs_file)->image();
771 width = image->width();
772 height = image->height();
776 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
780 bool GuiGraphics::isFilenameValid(string const & fname) const
782 // It may be that the filename is relative.
783 return makeAbsPath(fname, bufferFilepath()).isReadableFile();
787 void GuiGraphics::editGraphics()
791 InsetGraphicsMailer::params2string(params_, buffer());
792 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
798 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
799 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
801 // These are the strings that are stored in the LyX file and which
802 // correspond to the LaTeX identifiers shown in the comments at the
804 char const * const rorigin_lyx_strs[] = {
805 // the LaTeX default is leftBaseline
807 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
808 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
809 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
811 // These are the strings, corresponding to the above, that the GUI should
812 // use. Note that they can/should be translated.
813 char const * const rorigin_gui_strs[] = {
815 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
816 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
817 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
819 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
824 vector<string> const getBBUnits()
826 return vector<string>(bb_units, bb_units + bb_size);
830 vector<RotationOriginPair> getRotationOriginData()
832 static vector<RotationOriginPair> data;
836 data.resize(rorigin_size);
837 for (size_type i = 0; i < rorigin_size; ++i) {
838 data[i] = make_pair(_(rorigin_gui_strs[i]),
839 rorigin_lyx_strs[i]);
846 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
849 } // namespace frontend
852 #include "GuiGraphics_moc.cpp"