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(embedCB, SIGNAL(toggled(bool)),
131 this, SLOT(change_adaptor()));
132 connect(WidthCB, SIGNAL( clicked()),
133 this, SLOT(change_adaptor()));
134 connect(HeightCB, SIGNAL( clicked()),
135 this, SLOT(change_adaptor()));
136 connect(Width, SIGNAL(textChanged(const QString &)),
137 this, SLOT(change_adaptor()));
138 connect(Height, SIGNAL(textChanged(const QString &)),
139 this, SLOT(change_adaptor()));
140 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
141 this, SLOT(change_adaptor()));
142 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
143 this, SLOT(change_adaptor()));
144 connect(aspectratio, SIGNAL(stateChanged(int)),
145 this, SLOT(change_adaptor()));
146 connect(angle, SIGNAL(textChanged(const QString &)),
147 this, SLOT(change_adaptor()));
148 connect(origin, SIGNAL(activated(int)),
149 this, SLOT(change_adaptor()));
150 connect(scaleCB, SIGNAL(clicked()),
151 this, SLOT(change_adaptor()));
152 connect(Scale, SIGNAL(textChanged(const QString &)),
153 this, SLOT(change_adaptor()));
154 connect(rotateOrderCB, SIGNAL(clicked()),
155 this, SLOT(change_adaptor()));
157 filename->setValidator(new PathValidator(true, filename));
158 setFocusProxy(filename);
160 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
161 scaleValidator->setBottom(0);
162 scaleValidator->setDecimals(256); //I guess that will do
163 Scale->setValidator(scaleValidator);
164 Height->setValidator(unsignedLengthAutoValidator(Height));
165 Width->setValidator(unsignedLengthAutoValidator(Width));
166 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
169 connect(clip, SIGNAL(stateChanged(int)),
170 this, SLOT(change_adaptor()));
171 connect(lbY, SIGNAL(textChanged(const QString&)),
172 this, SLOT(change_bb()));
173 connect(lbYunit, SIGNAL(activated(int)),
174 this, SLOT(change_bb()));
175 connect(rtY, SIGNAL(textChanged(const QString&)),
176 this, SLOT(change_bb()));
177 connect(rtYunit, SIGNAL(activated(int)),
178 this, SLOT(change_bb()));
179 connect(lbX, SIGNAL(textChanged(const QString&)),
180 this, SLOT(change_bb()));
181 connect(lbXunit, SIGNAL(activated(int)),
182 this, SLOT(change_bb()));
183 connect(rtX, SIGNAL(textChanged(const QString&)),
184 this, SLOT(change_bb()));
185 connect(rtXunit, SIGNAL(activated(int)),
186 this, SLOT(change_bb()));
187 connect(getPB, SIGNAL(clicked()),
188 this, SLOT(change_adaptor()));
190 lbX->setValidator(new QDoubleValidator(lbX));
191 lbY->setValidator(new QDoubleValidator(lbY));
192 rtX->setValidator(new QDoubleValidator(rtX));
193 rtY->setValidator(new QDoubleValidator(rtY));
196 connect(latexoptions, SIGNAL(textChanged(const QString&)),
197 this, SLOT(change_adaptor()));
198 connect(draftCB, SIGNAL(stateChanged(int)),
199 this, SLOT(change_adaptor()));
200 connect(unzipCB, SIGNAL(stateChanged(int)),
201 this, SLOT(change_adaptor()));
202 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
203 // the toggled(bool) signal is also trigged when we update the widgets
204 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
205 // using blockSignals() to keep from triggering that signal when we call
206 // setChecked(). Note, too, that clicked() would get called whenever it
207 // is clicked, even right clicked (I think), not just whenever it is
209 connect(subfigure, SIGNAL(toggled(bool)),
210 this, SLOT(change_adaptor()));
211 connect(subcaption, SIGNAL(textChanged(const QString&)),
212 this, SLOT(change_adaptor()));
213 connect(displayGB, SIGNAL(toggled(bool)),
214 this, SLOT(change_adaptor()));
215 connect(showCB, SIGNAL(currentIndexChanged(int)),
216 this, SLOT(change_adaptor()));
217 connect(displayscale, SIGNAL(textChanged(const QString&)),
218 this, SLOT(change_adaptor()));
219 displayscale->setValidator(new QIntValidator(displayscale));
221 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
223 bc().setApply(applyPB);
224 bc().setRestore(restorePB);
225 bc().setCancel(closePB);
227 bc().addReadOnly(latexoptions);
228 bc().addReadOnly(subfigure);
229 bc().addReadOnly(filenameL);
230 bc().addReadOnly(filename);
231 bc().addReadOnly(browsePB);
232 bc().addReadOnly(unzipCB);
233 bc().addReadOnly(bbFrame);
234 bc().addReadOnly(draftCB);
235 bc().addReadOnly(clip);
236 bc().addReadOnly(unzipCB);
237 bc().addReadOnly(displayGB);
238 bc().addReadOnly(sizeGB);
239 bc().addReadOnly(rotationGB);
240 bc().addReadOnly(latexoptions);
241 bc().addReadOnly(getPB);
242 bc().addReadOnly(rotateOrderCB);
244 // initialize the length validator
245 bc().addCheckedLineEdit(Scale, scaleCB);
246 bc().addCheckedLineEdit(Width, WidthCB);
247 bc().addCheckedLineEdit(Height, HeightCB);
248 bc().addCheckedLineEdit(displayscale, scaleLA);
249 bc().addCheckedLineEdit(angle, angleL);
250 bc().addCheckedLineEdit(lbX, xL);
251 bc().addCheckedLineEdit(lbY, yL);
252 bc().addCheckedLineEdit(rtX, xL_2);
253 bc().addCheckedLineEdit(rtY, yL_2);
254 bc().addCheckedLineEdit(filename, filenameL);
258 void GuiGraphics::change_adaptor()
264 void GuiGraphics::change_bb()
267 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
272 void GuiGraphics::closeEvent(QCloseEvent * e)
275 GuiDialog::closeEvent(e);
279 void GuiGraphics::on_browsePB_clicked()
281 docstring const str = browse(qstring_to_ucs4(filename->text()));
283 filename->setText(toqstr(str));
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());
304 EmbeddedFile file = EmbeddedFile(fromqstr(filename), bufferFilepath());
308 void GuiGraphics::setAutoText()
310 if (scaleCB->isChecked())
312 if (!Scale->isEnabled() && Scale->text() != "100")
313 Scale->setText(QString("auto"));
315 setAutoTextCB(WidthCB, Width, widthUnit);
316 setAutoTextCB(HeightCB, Height, heightUnit);
320 void GuiGraphics::on_scaleCB_toggled(bool setScale)
322 Scale->setEnabled(setScale);
324 Scale->setText("100");
325 Scale->setFocus(Qt::OtherFocusReason);
328 WidthCB->setDisabled(setScale);
329 WidthCB->blockSignals(true);
330 WidthCB->setChecked(false);
331 WidthCB->blockSignals(false);
332 Width->setEnabled(false);
333 widthUnit->setEnabled(false);
335 HeightCB->setDisabled(setScale);
336 HeightCB->blockSignals(true);
337 HeightCB->setChecked(false);
338 HeightCB->blockSignals(false);
339 Height->setEnabled(false);
340 heightUnit->setEnabled(false);
342 aspectratio->setDisabled(true);
343 aspectratio->setChecked(true);
345 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
346 HeightCB->isChecked() ||
347 scaleCB->isChecked()) &&
348 (angle->text() != "0"));
354 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
356 Width->setEnabled(setWidth);
357 widthUnit->setEnabled(setWidth);
359 Width->setFocus(Qt::OtherFocusReason);
361 bool const setHeight = HeightCB->isChecked();
362 aspectratio->setEnabled(setWidth && setHeight);
363 aspectratio->blockSignals(true);
364 aspectratio->setChecked(!(setWidth && setHeight));
365 aspectratio->blockSignals(false);
367 scaleCB->setEnabled(!setWidth && !setHeight);
368 //already will be unchecked, so don't need to do that
369 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
370 && scaleCB->isChecked()); //should be false, but let's check
371 rotateOrderCB->setEnabled((setWidth || setHeight ||
372 scaleCB->isChecked()) &&
373 (angle->text() != "0"));
379 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
381 Height->setEnabled(setHeight);
382 heightUnit->setEnabled(setHeight);
384 Height->setFocus(Qt::OtherFocusReason);
386 bool const setWidth = WidthCB->isChecked();
387 aspectratio->setEnabled(setWidth && setHeight);
388 aspectratio->blockSignals(true);
389 aspectratio->setChecked(!(setWidth && setHeight));
390 aspectratio->blockSignals(false);
392 scaleCB->setEnabled(!setWidth && !setHeight);
394 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
395 && scaleCB->isChecked()); //should be false
396 rotateOrderCB->setEnabled((setWidth || setHeight ||
397 scaleCB->isChecked()) &&
398 (angle->text() != "0"));
404 void GuiGraphics::on_angle_textChanged(const QString & filename)
406 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
407 HeightCB->isChecked() ||
408 scaleCB->isChecked()) &&
412 // returns the number of the string s in the vector v
413 static int getItemNo(const vector<string> & v, string const & s)
415 vector<string>::const_iterator cit =
416 find(v.begin(), v.end(), s);
417 return (cit != v.end()) ? int(cit - v.begin()) : 0;
421 void GuiGraphics::updateContents()
423 // clear and fill in the comboboxes
424 vector<string> const bb_units = frontend::getBBUnits();
429 for (vector<string>::const_iterator it = bb_units.begin();
430 it != bb_units.end(); ++it) {
431 lbXunit->addItem(toqstr(*it));
432 lbYunit->addItem(toqstr(*it));
433 rtXunit->addItem(toqstr(*it));
434 rtYunit->addItem(toqstr(*it));
437 InsetGraphicsParams & igp = params_;
439 // set the right default unit
440 Length::UNIT unitDefault = Length::CM;
441 switch (lyxrc.default_papersize) {
444 case PAPER_USEXECUTIVE:
445 unitDefault = Length::IN;
452 igp.filename.outputFilename(bufferFilepath());
453 filename->setText(toqstr(name));
454 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
456 // set the bounding box values
457 if (igp.bb.empty()) {
458 string const bb = readBB(igp.filename.absFilename());
459 // the values from the file always have the bigpoint-unit bp
460 lbX->setText(toqstr(token(bb, ' ', 0)));
461 lbY->setText(toqstr(token(bb, ' ', 1)));
462 rtX->setText(toqstr(token(bb, ' ', 2)));
463 rtY->setText(toqstr(token(bb, ' ', 3)));
464 lbXunit->setCurrentIndex(0);
465 lbYunit->setCurrentIndex(0);
466 rtXunit->setCurrentIndex(0);
467 rtYunit->setCurrentIndex(0);
470 // get the values from the inset
472 string const xl = token(igp.bb, ' ', 0);
473 string const yl = token(igp.bb, ' ', 1);
474 string const xr = token(igp.bb, ' ', 2);
475 string const yr = token(igp.bb, ' ', 3);
476 if (isValidLength(xl, &anyLength)) {
477 lbX->setText(toqstr(convert<string>(anyLength.value())));
478 string const unit(unit_name[anyLength.unit()]);
479 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
481 lbX->setText(toqstr(xl));
483 if (isValidLength(yl, &anyLength)) {
484 lbY->setText(toqstr(convert<string>(anyLength.value())));
485 string const unit(unit_name[anyLength.unit()]);
486 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
488 lbY->setText(toqstr(xl));
490 if (isValidLength(xr, &anyLength)) {
491 rtX->setText(toqstr(convert<string>(anyLength.value())));
492 string const unit(unit_name[anyLength.unit()]);
493 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
495 rtX->setText(toqstr(xl));
497 if (isValidLength(yr, &anyLength)) {
498 rtY->setText(toqstr(convert<string>(anyLength.value())));
499 string const unit(unit_name[anyLength.unit()]);
500 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
502 rtY->setText(toqstr(xl));
507 // Update the draft and clip mode
508 draftCB->setChecked(igp.draft);
509 clip->setChecked(igp.clip);
510 unzipCB->setChecked(igp.noUnzip);
512 // Update the subcaption check button and input field
513 subfigure->setChecked(igp.subcaption);
514 subcaption->setText(toqstr(igp.subcaptionText));
517 switch (igp.display) {
518 case graphics::DefaultDisplay: item = 0; break;
519 case graphics::MonochromeDisplay: item = 1; break;
520 case graphics::GrayscaleDisplay: item = 2; break;
521 case graphics::ColorDisplay: item = 3; break;
522 case graphics::NoDisplay: item = 0; break;
524 showCB->setCurrentIndex(item);
525 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
526 displayGB->setChecked(igp.display != graphics::NoDisplay);
528 // the output section (width/height)
530 Scale->setText(toqstr(igp.scale));
531 //igp.scale defaults to 100, so we treat it as empty
532 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
533 scaleCB->blockSignals(true);
534 scaleCB->setChecked(scaleChecked);
535 scaleCB->blockSignals(false);
536 Scale->setEnabled(scaleChecked);
538 lengthAutoToWidgets(Width, widthUnit, igp.width,
540 bool const widthChecked = !Width->text().isEmpty() &&
541 Width->text() != "auto";
542 WidthCB->blockSignals(true);
543 WidthCB->setChecked(widthChecked);
544 WidthCB->blockSignals(false);
545 Width->setEnabled(widthChecked);
546 widthUnit->setEnabled(widthChecked);
548 lengthAutoToWidgets(Height, heightUnit, igp.height,
550 bool const heightChecked = !Height->text().isEmpty()
551 && Height->text() != "auto";
552 HeightCB->blockSignals(true);
553 HeightCB->setChecked(heightChecked);
554 HeightCB->blockSignals(false);
555 Height->setEnabled(heightChecked);
556 heightUnit->setEnabled(heightChecked);
558 scaleCB->setEnabled(!widthChecked && !heightChecked);
559 WidthCB->setEnabled(!scaleChecked);
560 HeightCB->setEnabled(!scaleChecked);
561 aspectratio->setEnabled(widthChecked && heightChecked);
565 angle->setText(toqstr(igp.rotateAngle));
566 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
568 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
569 && igp.rotateAngle != "0");
573 vector<RotationOriginPair> origindata = getRotationOriginData();
574 vector<docstring> const origin_lang = getFirst(origindata);
575 origin_ltx = getSecond(origindata);
577 for (vector<docstring>::const_iterator it = origin_lang.begin();
578 it != origin_lang.end(); ++it)
579 origin->addItem(toqstr(*it));
581 if (!igp.rotateOrigin.empty())
582 origin->setCurrentIndex(
583 getItemNo(origin_ltx, igp.rotateOrigin));
585 origin->setCurrentIndex(0);
587 // disable edit button when no filename is present
588 editPB->setDisabled(filename->text().isEmpty());
591 latexoptions->setText(toqstr(igp.special));
595 void GuiGraphics::applyView()
597 InsetGraphicsParams & igp = params_;
599 igp.filename.set(fromqstr(filename->text()), bufferFilepath());
600 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
606 string lbXs = fromqstr(lbX->text());
607 string lbYs = fromqstr(lbY->text());
608 string rtXs = fromqstr(rtX->text());
609 string rtYs = fromqstr(rtY->text());
611 convert<int>(lbXs) + convert<int>(lbYs) +
612 convert<int>(rtXs) + convert<int>(rtXs);
617 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
621 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
625 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
629 bb += (rtYs + fromqstr(rtYunit->currentText()));
634 igp.draft = draftCB->isChecked();
635 igp.clip = clip->isChecked();
636 igp.subcaption = subfigure->isChecked();
637 igp.subcaptionText = fromqstr(subcaption->text());
639 switch (showCB->currentIndex()) {
640 case 0: igp.display = graphics::DefaultDisplay; break;
641 case 1: igp.display = graphics::MonochromeDisplay; break;
642 case 2: igp.display = graphics::GrayscaleDisplay; break;
643 case 3: igp.display = graphics::ColorDisplay; break;
647 if (!displayGB->isChecked())
648 igp.display = graphics::NoDisplay;
650 //the graphics section
651 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
652 igp.scale = fromqstr(Scale->text());
653 igp.width = Length("0pt");
654 igp.height = Length("0pt");
655 igp.keepAspectRatio = false;
657 igp.scale = string();
658 igp.width = WidthCB->isChecked() ?
659 //Note that this works even if Width is "auto", since in
660 //that case we get "0pt".
661 Length(widgetsToLength(Width, widthUnit)):
663 igp.height = HeightCB->isChecked() ?
664 Length(widgetsToLength(Height, heightUnit)) :
666 igp.keepAspectRatio = aspectratio->isEnabled() &&
667 aspectratio->isChecked() &&
668 igp.width.value() > 0 && igp.height.value() > 0;
671 igp.noUnzip = unzipCB->isChecked();
672 igp.lyxscale = displayscale->text().toInt();
673 igp.rotateAngle = fromqstr(angle->text());
675 double rotAngle = convert<double>(igp.rotateAngle);
676 if (abs(rotAngle) > 360.0) {
677 rotAngle -= 360.0 * floor(rotAngle / 360.0);
678 igp.rotateAngle = convert<string>(rotAngle);
681 // save the latex name for the origin. If it is the default
682 // then origin_ltx returns ""
683 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
684 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
686 // more latex options
687 igp.special = fromqstr(latexoptions->text());
691 void GuiGraphics::getBB()
693 string const fn = fromqstr(filename->text());
696 string const bb = readBB(fn);
700 lbX->setText(toqstr(token(bb, ' ', 0)));
701 lbY->setText(toqstr(token(bb, ' ', 1)));
702 rtX->setText(toqstr(token(bb, ' ', 2)));
703 rtY->setText(toqstr(token(bb, ' ', 3)));
704 // the default units for the bb values when reading
706 lbXunit->setCurrentIndex(0);
707 lbYunit->setCurrentIndex(0);
708 rtXunit->setCurrentIndex(0);
709 rtYunit->setCurrentIndex(0);
713 bool GuiGraphics::isValid()
715 return !filename->text().isEmpty();
719 bool GuiGraphics::initialiseParams(string const & data)
721 InsetGraphicsMailer::string2params(data, buffer(), params_);
726 void GuiGraphics::clearParams()
728 params_ = InsetGraphicsParams();
732 void GuiGraphics::dispatchParams()
734 InsetGraphicsParams tmp_params(params_);
736 InsetGraphicsMailer::params2string(tmp_params, buffer());
737 dispatch(FuncRequest(getLfun(), lfun));
741 docstring const GuiGraphics::browse(docstring const & in_name) const
743 docstring const title = _("Select graphics file");
745 // Does user clipart directory exist?
746 string clipdir = addName(package().user_support().absFilename(), "clipart");
747 FileName clip(clipdir);
749 // bail out to system clipart directory
750 if (!(clip.exists() && clip.isDirectory()))
751 clipdir = addName(package().system_support().absFilename(), "clipart");
753 return browseRelFile(in_name, from_utf8(bufferFilepath()),
754 title, FileFilterList(), false,
755 _("Clipart|#C#c"), from_utf8(clipdir),
756 _("Documents|#o#O"), from_utf8(lyxrc.document_path));
760 string const GuiGraphics::readBB(string const & file)
762 FileName const abs_file = makeAbsPath(file, bufferFilepath());
764 // try to get it from the file, if possible. Zipped files are
765 // unzipped in the readBB_from_PSFile-Function
766 string const bb = readBB_from_PSFile(abs_file);
770 // we don't, so ask the Graphics Cache if it has loaded the file
774 graphics::Cache & gc = graphics::Cache::get();
775 if (gc.inCache(abs_file)) {
776 graphics::Image const * image = gc.item(abs_file)->image();
779 width = image->width();
780 height = image->height();
784 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
788 bool GuiGraphics::isFilenameValid(string const & fname) const
790 // It may be that the filename is relative.
791 return makeAbsPath(fname, bufferFilepath()).isReadableFile();
795 void GuiGraphics::editGraphics()
799 InsetGraphicsMailer::params2string(params_, buffer());
800 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
806 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
807 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
809 // These are the strings that are stored in the LyX file and which
810 // correspond to the LaTeX identifiers shown in the comments at the
812 char const * const rorigin_lyx_strs[] = {
813 // the LaTeX default is leftBaseline
815 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
816 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
817 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
819 // These are the strings, corresponding to the above, that the GUI should
820 // use. Note that they can/should be translated.
821 char const * const rorigin_gui_strs[] = {
823 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
824 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
825 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
827 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
832 vector<string> const getBBUnits()
834 return vector<string>(bb_units, bb_units + bb_size);
838 vector<RotationOriginPair> getRotationOriginData()
840 static vector<RotationOriginPair> data;
844 data.resize(rorigin_size);
845 for (size_type i = 0; i < rorigin_size; ++i) {
846 data[i] = make_pair(_(rorigin_gui_strs[i]),
847 rorigin_lyx_strs[i]);
854 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
857 } // namespace frontend
860 #include "GuiGraphics_moc.cpp"