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 "GuiGraphics.h"
21 #include "LengthCombo.h"
22 #include "lengthcommon.h"
24 #include "qt_helpers.h"
25 #include "Validator.h"
26 #include "frontend_helpers.h"
28 #include "FuncRequest.h"
31 #include "graphics/GraphicsCache.h"
32 #include "graphics/GraphicsCacheItem.h"
33 #include "graphics/GraphicsImage.h"
35 #include "insets/InsetGraphicsParams.h"
37 #include "support/convert.h"
38 #include "support/FileFilterList.h"
39 #include "support/filetools.h"
40 #include "support/lstrings.h"
41 #include "support/lyxlib.h"
42 #include "support/os.h"
43 #include "support/Package.h"
44 #include "support/types.h"
46 #include <boost/bind.hpp>
49 #include <QCloseEvent>
52 #include <QPushButton>
59 #ifndef CXX_GLOBAL_CSTD
73 using support::addName;
74 using support::FileFilterList;
75 using support::FileName;
76 using support::float_equal;
77 using support::makeAbsPath;
78 using support::os::internal_path;
79 using support::package;
80 using support::readBB_from_PSFile;
84 //FIXME setAutoTextCB should really take an argument, as indicated, that
85 //determines what text is to be written for "auto". But making
86 //that work involves more extensive revisions than we now want
87 //to make, since "auto" also appears in updateContents() (see
89 //The right way to do this, I think, would be to define a class
90 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
91 //the checkbox, line edit, and length combo together, and then made e.g.
92 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
93 //Perhaps even the validator could be exposed through it.
95 * sets a checkbox-line edit-length combo group, using "text" if the
96 * checkbox is unchecked and clearing the line edit if it previously
99 void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
100 LengthCombo * lengthCombo/*, string text = "auto"*/)
102 if (!checkBox->isChecked())
103 lengthToWidgets(lineEdit, lengthCombo,
104 "auto", lengthCombo->currentLengthItem());
105 else if (lineEdit->text() == "auto")
106 lengthToWidgets(lineEdit, lengthCombo, string(),
107 lengthCombo->currentLengthItem());
113 vector<typename Pair::first_type> const
114 getFirst(vector<Pair> const & pr)
116 vector<typename Pair::first_type> tmp(pr.size());
117 transform(pr.begin(), pr.end(), tmp.begin(),
118 boost::bind(&Pair::first, _1));
124 vector<typename Pair::second_type> const
125 getSecond(vector<Pair> const & pr)
127 vector<typename Pair::second_type> tmp(pr.size());
128 transform(pr.begin(), pr.end(), tmp.begin(),
129 boost::bind(&Pair::second, _1));
133 GuiGraphics::GuiGraphics(LyXView & lv)
134 : GuiDialog(lv, "graphics")
137 setViewTitle(_("Graphics"));
140 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
141 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
142 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
143 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
146 connect(filename, SIGNAL(textChanged(const QString &)),
147 this, SLOT(change_adaptor()));
148 connect(WidthCB, SIGNAL( clicked()),
149 this, SLOT(change_adaptor()));
150 connect(HeightCB, SIGNAL( clicked()),
151 this, SLOT(change_adaptor()));
152 connect(Width, SIGNAL(textChanged(const QString &)),
153 this, SLOT(change_adaptor()));
154 connect(Height, SIGNAL(textChanged(const QString &)),
155 this, SLOT(change_adaptor()));
156 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
157 this, SLOT(change_adaptor()));
158 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
159 this, SLOT(change_adaptor()));
160 connect(aspectratio, SIGNAL(stateChanged(int)),
161 this, SLOT(change_adaptor()));
162 connect(angle, SIGNAL(textChanged(const QString &)),
163 this, SLOT(change_adaptor()));
164 connect(origin, SIGNAL(activated(int)),
165 this, SLOT(change_adaptor()));
166 connect(scaleCB, SIGNAL(clicked()),
167 this, SLOT(change_adaptor()));
168 connect(Scale, SIGNAL(textChanged(const QString &)),
169 this, SLOT(change_adaptor()));
170 connect(rotateOrderCB, SIGNAL(clicked()),
171 this, SLOT(change_adaptor()));
173 filename->setValidator(new PathValidator(true, filename));
174 setFocusProxy(filename);
176 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
177 scaleValidator->setBottom(0);
178 scaleValidator->setDecimals(256); //I guess that will do
179 Scale->setValidator(scaleValidator);
180 Height->setValidator(unsignedLengthAutoValidator(Height));
181 Width->setValidator(unsignedLengthAutoValidator(Width));
182 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
185 connect(clip, SIGNAL(stateChanged(int)),
186 this, SLOT(change_adaptor()));
187 connect(lbY, SIGNAL(textChanged(const QString&)),
188 this, SLOT(change_bb()));
189 connect(lbYunit, SIGNAL(activated(int)),
190 this, SLOT(change_bb()));
191 connect(rtY, SIGNAL(textChanged(const QString&)),
192 this, SLOT(change_bb()));
193 connect(rtYunit, SIGNAL(activated(int)),
194 this, SLOT(change_bb()));
195 connect(lbX, SIGNAL(textChanged(const QString&)),
196 this, SLOT(change_bb()));
197 connect(lbXunit, SIGNAL(activated(int)),
198 this, SLOT(change_bb()));
199 connect(rtX, SIGNAL(textChanged(const QString&)),
200 this, SLOT(change_bb()));
201 connect(rtXunit, SIGNAL(activated(int)),
202 this, SLOT(change_bb()));
203 connect(getPB, SIGNAL(clicked()),
204 this, SLOT(change_adaptor()));
206 lbX->setValidator(new QDoubleValidator(lbX));
207 lbY->setValidator(new QDoubleValidator(lbY));
208 rtX->setValidator(new QDoubleValidator(rtX));
209 rtY->setValidator(new QDoubleValidator(rtY));
212 connect(latexoptions, SIGNAL(textChanged(const QString&)),
213 this, SLOT(change_adaptor()));
214 connect(draftCB, SIGNAL(stateChanged(int)),
215 this, SLOT(change_adaptor()));
216 connect(unzipCB, SIGNAL(stateChanged(int)),
217 this, SLOT(change_adaptor()));
218 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
219 // the toggled(bool) signal is also trigged when we update the widgets
220 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
221 // using blockSignals() to keep from triggering that signal when we call
222 // setChecked(). Note, too, that clicked() would get called whenever it
223 // is clicked, even right clicked (I think), not just whenever it is
225 connect(subfigure, SIGNAL(toggled(bool)),
226 this, SLOT(change_adaptor()));
227 connect(subcaption, SIGNAL(textChanged(const QString&)),
228 this, SLOT(change_adaptor()));
229 connect(displayGB, SIGNAL(toggled(bool)),
230 this, SLOT(change_adaptor()));
231 connect(showCB, SIGNAL(currentIndexChanged(int)),
232 this, SLOT(change_adaptor()));
233 connect(displayscale, SIGNAL(textChanged(const QString&)),
234 this, SLOT(change_adaptor()));
235 displayscale->setValidator(new QIntValidator(displayscale));
237 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
239 bc().setApply(applyPB);
240 bc().setRestore(restorePB);
241 bc().setCancel(closePB);
243 bc().addReadOnly(latexoptions);
244 bc().addReadOnly(subfigure);
245 bc().addReadOnly(filenameL);
246 bc().addReadOnly(filename);
247 bc().addReadOnly(browsePB);
248 bc().addReadOnly(unzipCB);
249 bc().addReadOnly(bbFrame);
250 bc().addReadOnly(draftCB);
251 bc().addReadOnly(clip);
252 bc().addReadOnly(unzipCB);
253 bc().addReadOnly(displayGB);
254 bc().addReadOnly(sizeGB);
255 bc().addReadOnly(rotationGB);
256 bc().addReadOnly(latexoptions);
257 bc().addReadOnly(getPB);
258 bc().addReadOnly(rotateOrderCB);
260 // initialize the length validator
261 bc().addCheckedLineEdit(Scale, scaleCB);
262 bc().addCheckedLineEdit(Width, WidthCB);
263 bc().addCheckedLineEdit(Height, HeightCB);
264 bc().addCheckedLineEdit(displayscale, scaleLA);
265 bc().addCheckedLineEdit(angle, angleL);
266 bc().addCheckedLineEdit(lbX, xL);
267 bc().addCheckedLineEdit(lbY, yL);
268 bc().addCheckedLineEdit(rtX, xL_2);
269 bc().addCheckedLineEdit(rtY, yL_2);
270 bc().addCheckedLineEdit(filename, filenameL);
274 void GuiGraphics::change_adaptor()
280 void GuiGraphics::change_bb()
283 LYXERR(Debug::GRAPHICS) << "[bb_Changed set to true]\n";
288 void GuiGraphics::closeEvent(QCloseEvent * e)
291 GuiDialog::closeEvent(e);
295 void GuiGraphics::on_browsePB_clicked()
297 docstring const str = browse(qstring_to_ucs4(filename->text()));
299 filename->setText(toqstr(str));
300 embedCB->setCheckState(Qt::Unchecked);
306 void GuiGraphics::on_getPB_clicked()
312 void GuiGraphics::on_editPB_clicked()
318 void GuiGraphics::on_filename_textChanged(const QString & filename)
320 editPB->setDisabled(filename.isEmpty());
324 void GuiGraphics::setAutoText()
326 if (scaleCB->isChecked())
328 if (!Scale->isEnabled() && Scale->text() != "100")
329 Scale->setText(QString("auto"));
331 setAutoTextCB(WidthCB, Width, widthUnit);
332 setAutoTextCB(HeightCB, Height, heightUnit);
336 void GuiGraphics::on_scaleCB_toggled(bool setScale)
338 Scale->setEnabled(setScale);
340 Scale->setText("100");
341 Scale->setFocus(Qt::OtherFocusReason);
344 WidthCB->setDisabled(setScale);
345 WidthCB->blockSignals(true);
346 WidthCB->setChecked(false);
347 WidthCB->blockSignals(false);
348 Width->setEnabled(false);
349 widthUnit->setEnabled(false);
351 HeightCB->setDisabled(setScale);
352 HeightCB->blockSignals(true);
353 HeightCB->setChecked(false);
354 HeightCB->blockSignals(false);
355 Height->setEnabled(false);
356 heightUnit->setEnabled(false);
358 aspectratio->setDisabled(true);
359 aspectratio->setChecked(true);
361 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
362 HeightCB->isChecked() ||
363 scaleCB->isChecked()) &&
364 (angle->text() != "0"));
370 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
372 Width->setEnabled(setWidth);
373 widthUnit->setEnabled(setWidth);
375 Width->setFocus(Qt::OtherFocusReason);
377 bool const setHeight = HeightCB->isChecked();
378 aspectratio->setEnabled(setWidth && setHeight);
379 aspectratio->blockSignals(true);
380 aspectratio->setChecked(!(setWidth && setHeight));
381 aspectratio->blockSignals(false);
383 scaleCB->setEnabled(!setWidth && !setHeight);
384 //already will be unchecked, so don't need to do that
385 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
386 && scaleCB->isChecked()); //should be false, but let's check
387 rotateOrderCB->setEnabled((setWidth || setHeight ||
388 scaleCB->isChecked()) &&
389 (angle->text() != "0"));
395 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
397 Height->setEnabled(setHeight);
398 heightUnit->setEnabled(setHeight);
400 Height->setFocus(Qt::OtherFocusReason);
402 bool const setWidth = WidthCB->isChecked();
403 aspectratio->setEnabled(setWidth && setHeight);
404 aspectratio->blockSignals(true);
405 aspectratio->setChecked(!(setWidth && setHeight));
406 aspectratio->blockSignals(false);
408 scaleCB->setEnabled(!setWidth && !setHeight);
410 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
411 && scaleCB->isChecked()); //should be false
412 rotateOrderCB->setEnabled((setWidth || setHeight ||
413 scaleCB->isChecked()) &&
414 (angle->text() != "0"));
420 void GuiGraphics::on_angle_textChanged(const QString & filename)
422 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
423 HeightCB->isChecked() ||
424 scaleCB->isChecked()) &&
428 // returns the number of the string s in the vector v
429 static int getItemNo(const vector<string> & v, string const & s)
431 vector<string>::const_iterator cit =
432 find(v.begin(), v.end(), s);
433 return (cit != v.end()) ? int(cit - v.begin()) : 0;
437 void GuiGraphics::updateContents()
439 // clear and fill in the comboboxes
440 vector<string> const bb_units = frontend::getBBUnits();
445 for (vector<string>::const_iterator it = bb_units.begin();
446 it != bb_units.end(); ++it) {
447 lbXunit->addItem(toqstr(*it));
448 lbYunit->addItem(toqstr(*it));
449 rtXunit->addItem(toqstr(*it));
450 rtYunit->addItem(toqstr(*it));
453 InsetGraphicsParams & igp = params_;
455 // set the right default unit
456 Length::UNIT unitDefault = Length::CM;
457 switch (lyxrc.default_papersize) {
460 case PAPER_USEXECUTIVE:
461 unitDefault = Length::IN;
468 igp.filename.outputFilename(bufferFilepath());
469 filename->setText(toqstr(name));
470 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
472 // set the bounding box values
473 if (igp.bb.empty()) {
474 string const bb = readBB(igp.filename.absFilename());
475 // the values from the file always have the bigpoint-unit bp
476 lbX->setText(toqstr(token(bb, ' ', 0)));
477 lbY->setText(toqstr(token(bb, ' ', 1)));
478 rtX->setText(toqstr(token(bb, ' ', 2)));
479 rtY->setText(toqstr(token(bb, ' ', 3)));
480 lbXunit->setCurrentIndex(0);
481 lbYunit->setCurrentIndex(0);
482 rtXunit->setCurrentIndex(0);
483 rtYunit->setCurrentIndex(0);
486 // get the values from the inset
488 string const xl = token(igp.bb, ' ', 0);
489 string const yl = token(igp.bb, ' ', 1);
490 string const xr = token(igp.bb, ' ', 2);
491 string const yr = token(igp.bb, ' ', 3);
492 if (isValidLength(xl, &anyLength)) {
493 lbX->setText(toqstr(convert<string>(anyLength.value())));
494 string const unit(unit_name[anyLength.unit()]);
495 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
497 lbX->setText(toqstr(xl));
499 if (isValidLength(yl, &anyLength)) {
500 lbY->setText(toqstr(convert<string>(anyLength.value())));
501 string const unit(unit_name[anyLength.unit()]);
502 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
504 lbY->setText(toqstr(xl));
506 if (isValidLength(xr, &anyLength)) {
507 rtX->setText(toqstr(convert<string>(anyLength.value())));
508 string const unit(unit_name[anyLength.unit()]);
509 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
511 rtX->setText(toqstr(xl));
513 if (isValidLength(yr, &anyLength)) {
514 rtY->setText(toqstr(convert<string>(anyLength.value())));
515 string const unit(unit_name[anyLength.unit()]);
516 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
518 rtY->setText(toqstr(xl));
523 // Update the draft and clip mode
524 draftCB->setChecked(igp.draft);
525 clip->setChecked(igp.clip);
526 unzipCB->setChecked(igp.noUnzip);
528 // Update the subcaption check button and input field
529 subfigure->setChecked(igp.subcaption);
530 subcaption->setText(toqstr(igp.subcaptionText));
533 switch (igp.display) {
534 case graphics::DefaultDisplay: item = 0; break;
535 case graphics::MonochromeDisplay: item = 1; break;
536 case graphics::GrayscaleDisplay: item = 2; break;
537 case graphics::ColorDisplay: item = 3; break;
538 case graphics::NoDisplay: item = 0; break;
540 showCB->setCurrentIndex(item);
541 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
542 displayGB->setChecked(igp.display != graphics::NoDisplay);
544 // the output section (width/height)
546 Scale->setText(toqstr(igp.scale));
547 //igp.scale defaults to 100, so we treat it as empty
548 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
549 scaleCB->blockSignals(true);
550 scaleCB->setChecked(scaleChecked);
551 scaleCB->blockSignals(false);
552 Scale->setEnabled(scaleChecked);
554 lengthAutoToWidgets(Width, widthUnit, igp.width,
556 bool const widthChecked = !Width->text().isEmpty() &&
557 Width->text() != "auto";
558 WidthCB->blockSignals(true);
559 WidthCB->setChecked(widthChecked);
560 WidthCB->blockSignals(false);
561 Width->setEnabled(widthChecked);
562 widthUnit->setEnabled(widthChecked);
564 lengthAutoToWidgets(Height, heightUnit, igp.height,
566 bool const heightChecked = !Height->text().isEmpty()
567 && Height->text() != "auto";
568 HeightCB->blockSignals(true);
569 HeightCB->setChecked(heightChecked);
570 HeightCB->blockSignals(false);
571 Height->setEnabled(heightChecked);
572 heightUnit->setEnabled(heightChecked);
574 scaleCB->setEnabled(!widthChecked && !heightChecked);
575 WidthCB->setEnabled(!scaleChecked);
576 HeightCB->setEnabled(!scaleChecked);
577 aspectratio->setEnabled(widthChecked && heightChecked);
581 angle->setText(toqstr(igp.rotateAngle));
582 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
584 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
585 && igp.rotateAngle != "0");
589 vector<RotationOriginPair> origindata = getRotationOriginData();
590 vector<docstring> const origin_lang = getFirst(origindata);
591 origin_ltx = getSecond(origindata);
593 for (vector<docstring>::const_iterator it = origin_lang.begin();
594 it != origin_lang.end(); ++it)
595 origin->addItem(toqstr(*it));
597 if (!igp.rotateOrigin.empty())
598 origin->setCurrentIndex(
599 getItemNo(origin_ltx, igp.rotateOrigin));
601 origin->setCurrentIndex(0);
603 // disable edit button when no filename is present
604 editPB->setDisabled(filename->text().isEmpty());
607 latexoptions->setText(toqstr(igp.special));
611 void GuiGraphics::applyView()
613 InsetGraphicsParams & igp = params_;
615 igp.filename.set(internal_path(fromqstr(filename->text())),
617 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
623 string lbXs = fromqstr(lbX->text());
624 string lbYs = fromqstr(lbY->text());
625 string rtXs = fromqstr(rtX->text());
626 string rtYs = fromqstr(rtY->text());
628 convert<int>(lbXs) + convert<int>(lbYs) +
629 convert<int>(rtXs) + convert<int>(rtXs);
634 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
638 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
642 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
646 bb += (rtYs + fromqstr(rtYunit->currentText()));
651 igp.draft = draftCB->isChecked();
652 igp.clip = clip->isChecked();
653 igp.subcaption = subfigure->isChecked();
654 igp.subcaptionText = fromqstr(subcaption->text());
656 switch (showCB->currentIndex()) {
657 case 0: igp.display = graphics::DefaultDisplay; break;
658 case 1: igp.display = graphics::MonochromeDisplay; break;
659 case 2: igp.display = graphics::GrayscaleDisplay; break;
660 case 3: igp.display = graphics::ColorDisplay; break;
664 if (!displayGB->isChecked())
665 igp.display = graphics::NoDisplay;
667 //the graphics section
668 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
669 igp.scale = fromqstr(Scale->text());
670 igp.width = Length("0pt");
671 igp.height = Length("0pt");
672 igp.keepAspectRatio = false;
674 igp.scale = string();
675 igp.width = WidthCB->isChecked() ?
676 //Note that this works even if Width is "auto", since in
677 //that case we get "0pt".
678 Length(widgetsToLength(Width, widthUnit)):
680 igp.height = HeightCB->isChecked() ?
681 Length(widgetsToLength(Height, heightUnit)) :
683 igp.keepAspectRatio = aspectratio->isEnabled() &&
684 aspectratio->isChecked() &&
685 igp.width.value() > 0 && igp.height.value() > 0;
688 igp.noUnzip = unzipCB->isChecked();
689 igp.lyxscale = displayscale->text().toInt();
690 igp.rotateAngle = fromqstr(angle->text());
692 double rotAngle = convert<double>(igp.rotateAngle);
693 if (std::abs(rotAngle) > 360.0) {
694 rotAngle -= 360.0 * floor(rotAngle / 360.0);
695 igp.rotateAngle = convert<string>(rotAngle);
698 // save the latex name for the origin. If it is the default
699 // then origin_ltx returns ""
700 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
701 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
703 // more latex options
704 igp.special = fromqstr(latexoptions->text());
708 void GuiGraphics::getBB()
710 string const fn = fromqstr(filename->text());
712 string const bb = readBB(fn);
714 lbX->setText(toqstr(token(bb, ' ', 0)));
715 lbY->setText(toqstr(token(bb, ' ', 1)));
716 rtX->setText(toqstr(token(bb, ' ', 2)));
717 rtY->setText(toqstr(token(bb, ' ', 3)));
718 // the default units for the bb values when reading
720 lbXunit->setCurrentIndex(0);
721 lbYunit->setCurrentIndex(0);
722 rtXunit->setCurrentIndex(0);
723 rtYunit->setCurrentIndex(0);
730 bool GuiGraphics::isValid()
732 return !filename->text().isEmpty();
736 bool GuiGraphics::initialiseParams(string const & data)
738 InsetGraphicsMailer::string2params(data, buffer(), params_);
743 void GuiGraphics::clearParams()
745 params_ = InsetGraphicsParams();
749 void GuiGraphics::dispatchParams()
751 InsetGraphicsParams tmp_params(params_);
753 InsetGraphicsMailer::params2string(tmp_params, buffer());
754 dispatch(FuncRequest(getLfun(), lfun));
758 docstring const GuiGraphics::browse(docstring const & in_name) const
760 docstring const title = _("Select graphics file");
762 // Does user clipart directory exist?
763 string clipdir = addName(package().user_support().absFilename(), "clipart");
764 FileName clip(clipdir);
765 if (!clip.exists() && clip.isDirectory())
766 // No - bail out to system clipart directory
767 clipdir = addName(package().system_support().absFilename(), "clipart");
768 pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
769 pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
770 // Show the file browser dialog
771 return browseRelFile(in_name, from_utf8(bufferFilepath()),
772 title, FileFilterList(), false, dir1, dir2);
776 string const GuiGraphics::readBB(string const & file)
778 FileName const abs_file = makeAbsPath(file, bufferFilepath());
780 // try to get it from the file, if possible. Zipped files are
781 // unzipped in the readBB_from_PSFile-Function
782 string const bb = readBB_from_PSFile(abs_file);
786 // we don't, so ask the Graphics Cache if it has loaded the file
790 graphics::Cache & gc = graphics::Cache::get();
791 if (gc.inCache(abs_file)) {
792 graphics::Image const * image = gc.item(abs_file)->image();
795 width = image->getWidth();
796 height = image->getHeight();
800 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
804 bool GuiGraphics::isFilenameValid(string const & fname) const
806 // It may be that the filename is relative.
807 return makeAbsPath(fname, bufferFilepath()).isReadable();
811 void GuiGraphics::editGraphics()
815 InsetGraphicsMailer::params2string(params_, buffer());
816 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
822 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
823 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
825 // These are the strings that are stored in the LyX file and which
826 // correspond to the LaTeX identifiers shown in the comments at the
828 char const * const rorigin_lyx_strs[] = {
829 // the LaTeX default is leftBaseline
831 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
832 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
833 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
835 // These are the strings, corresponding to the above, that the GUI should
836 // use. Note that they can/should be translated.
837 char const * const rorigin_gui_strs[] = {
839 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
840 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
841 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
843 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
848 vector<string> const getBBUnits()
850 return vector<string>(bb_units, bb_units + bb_size);
854 vector<RotationOriginPair> getRotationOriginData()
856 static vector<RotationOriginPair> data;
860 data.resize(rorigin_size);
861 for (size_type i = 0; i < rorigin_size; ++i) {
862 data[i] = make_pair(_(rorigin_gui_strs[i]),
863 rorigin_lyx_strs[i]);
870 Dialog * createGuiGraphics(LyXView & lv) { return new GuiGraphics(lv); }
873 } // namespace frontend
876 #include "GuiGraphics_moc.cpp"