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"
25 #include "frontend_helpers.h"
27 #include "FuncRequest.h"
30 #include "graphics/GraphicsCache.h"
31 #include "graphics/GraphicsCacheItem.h"
32 #include "graphics/GraphicsImage.h"
34 #include "insets/InsetGraphicsParams.h"
36 #include "support/convert.h"
37 #include "support/FileFilterList.h"
38 #include "support/filetools.h"
39 #include "support/lstrings.h"
40 #include "support/lyxlib.h"
41 #include "support/os.h"
42 #include "support/Package.h"
43 #include "support/types.h"
45 #include <boost/bind.hpp>
48 #include <QCloseEvent>
51 #include <QPushButton>
58 #ifndef CXX_GLOBAL_CSTD
72 using support::addName;
73 using support::FileFilterList;
74 using support::FileName;
75 using support::float_equal;
76 using support::makeAbsPath;
77 using support::os::internal_path;
78 using support::package;
79 using support::readBB_from_PSFile;
83 //FIXME setAutoTextCB should really take an argument, as indicated, that
84 //determines what text is to be written for "auto". But making
85 //that work involves more extensive revisions than we now want
86 //to make, since "auto" also appears in updateContents() (see
88 //The right way to do this, I think, would be to define a class
89 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
90 //the checkbox, line edit, and length combo together, and then made e.g.
91 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
92 //Perhaps even the validator could be exposed through it.
94 * sets a checkbox-line edit-length combo group, using "text" if the
95 * checkbox is unchecked and clearing the line edit if it previously
98 void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
99 LengthCombo * lengthCombo/*, string text = "auto"*/)
101 if (!checkBox->isChecked())
102 lengthToWidgets(lineEdit, lengthCombo,
103 "auto", lengthCombo->currentLengthItem());
104 else if (lineEdit->text() == "auto")
105 lengthToWidgets(lineEdit, lengthCombo, string(),
106 lengthCombo->currentLengthItem());
112 vector<typename Pair::first_type> const
113 getFirst(vector<Pair> const & pr)
115 vector<typename Pair::first_type> tmp(pr.size());
116 transform(pr.begin(), pr.end(), tmp.begin(),
117 boost::bind(&Pair::first, _1));
123 vector<typename Pair::second_type> const
124 getSecond(vector<Pair> const & pr)
126 vector<typename Pair::second_type> tmp(pr.size());
127 transform(pr.begin(), pr.end(), tmp.begin(),
128 boost::bind(&Pair::second, _1));
132 GuiGraphics::GuiGraphics(LyXView & lv)
133 : GuiDialog(lv, "graphics")
136 setViewTitle(_("Graphics"));
139 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
140 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
141 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
142 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
145 connect(filename, SIGNAL(textChanged(const QString &)),
146 this, SLOT(change_adaptor()));
147 connect(WidthCB, SIGNAL( clicked()),
148 this, SLOT(change_adaptor()));
149 connect(HeightCB, SIGNAL( clicked()),
150 this, SLOT(change_adaptor()));
151 connect(Width, SIGNAL(textChanged(const QString &)),
152 this, SLOT(change_adaptor()));
153 connect(Height, SIGNAL(textChanged(const QString &)),
154 this, SLOT(change_adaptor()));
155 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
156 this, SLOT(change_adaptor()));
157 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
158 this, SLOT(change_adaptor()));
159 connect(aspectratio, SIGNAL(stateChanged(int)),
160 this, SLOT(change_adaptor()));
161 connect(angle, SIGNAL(textChanged(const QString &)),
162 this, SLOT(change_adaptor()));
163 connect(origin, SIGNAL(activated(int)),
164 this, SLOT(change_adaptor()));
165 connect(scaleCB, SIGNAL(clicked()),
166 this, SLOT(change_adaptor()));
167 connect(Scale, SIGNAL(textChanged(const QString &)),
168 this, SLOT(change_adaptor()));
169 connect(rotateOrderCB, SIGNAL(clicked()),
170 this, SLOT(change_adaptor()));
172 filename->setValidator(new PathValidator(true, filename));
173 setFocusProxy(filename);
175 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
176 scaleValidator->setBottom(0);
177 scaleValidator->setDecimals(256); //I guess that will do
178 Scale->setValidator(scaleValidator);
179 Height->setValidator(unsignedLengthAutoValidator(Height));
180 Width->setValidator(unsignedLengthAutoValidator(Width));
181 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
184 connect(clip, SIGNAL(stateChanged(int)),
185 this, SLOT(change_adaptor()));
186 connect(lbY, SIGNAL(textChanged(const QString&)),
187 this, SLOT(change_bb()));
188 connect(lbYunit, SIGNAL(activated(int)),
189 this, SLOT(change_bb()));
190 connect(rtY, SIGNAL(textChanged(const QString&)),
191 this, SLOT(change_bb()));
192 connect(rtYunit, SIGNAL(activated(int)),
193 this, SLOT(change_bb()));
194 connect(lbX, SIGNAL(textChanged(const QString&)),
195 this, SLOT(change_bb()));
196 connect(lbXunit, SIGNAL(activated(int)),
197 this, SLOT(change_bb()));
198 connect(rtX, SIGNAL(textChanged(const QString&)),
199 this, SLOT(change_bb()));
200 connect(rtXunit, SIGNAL(activated(int)),
201 this, SLOT(change_bb()));
202 connect(getPB, SIGNAL(clicked()),
203 this, SLOT(change_adaptor()));
205 lbX->setValidator(new QDoubleValidator(lbX));
206 lbY->setValidator(new QDoubleValidator(lbY));
207 rtX->setValidator(new QDoubleValidator(rtX));
208 rtY->setValidator(new QDoubleValidator(rtY));
211 connect(latexoptions, SIGNAL(textChanged(const QString&)),
212 this, SLOT(change_adaptor()));
213 connect(draftCB, SIGNAL(stateChanged(int)),
214 this, SLOT(change_adaptor()));
215 connect(unzipCB, SIGNAL(stateChanged(int)),
216 this, SLOT(change_adaptor()));
217 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
218 // the toggled(bool) signal is also trigged when we update the widgets
219 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
220 // using blockSignals() to keep from triggering that signal when we call
221 // setChecked(). Note, too, that clicked() would get called whenever it
222 // is clicked, even right clicked (I think), not just whenever it is
224 connect(subfigure, SIGNAL(toggled(bool)),
225 this, SLOT(change_adaptor()));
226 connect(subcaption, SIGNAL(textChanged(const QString&)),
227 this, SLOT(change_adaptor()));
228 connect(displayGB, SIGNAL(toggled(bool)),
229 this, SLOT(change_adaptor()));
230 connect(showCB, SIGNAL(currentIndexChanged(int)),
231 this, SLOT(change_adaptor()));
232 connect(displayscale, SIGNAL(textChanged(const QString&)),
233 this, SLOT(change_adaptor()));
234 displayscale->setValidator(new QIntValidator(displayscale));
236 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
238 bc().setApply(applyPB);
239 bc().setRestore(restorePB);
240 bc().setCancel(closePB);
242 bc().addReadOnly(latexoptions);
243 bc().addReadOnly(subfigure);
244 bc().addReadOnly(filenameL);
245 bc().addReadOnly(filename);
246 bc().addReadOnly(browsePB);
247 bc().addReadOnly(unzipCB);
248 bc().addReadOnly(bbFrame);
249 bc().addReadOnly(draftCB);
250 bc().addReadOnly(clip);
251 bc().addReadOnly(unzipCB);
252 bc().addReadOnly(displayGB);
253 bc().addReadOnly(sizeGB);
254 bc().addReadOnly(rotationGB);
255 bc().addReadOnly(latexoptions);
256 bc().addReadOnly(getPB);
257 bc().addReadOnly(rotateOrderCB);
259 // initialize the length validator
260 bc().addCheckedLineEdit(Scale, scaleCB);
261 bc().addCheckedLineEdit(Width, WidthCB);
262 bc().addCheckedLineEdit(Height, HeightCB);
263 bc().addCheckedLineEdit(displayscale, scaleLA);
264 bc().addCheckedLineEdit(angle, angleL);
265 bc().addCheckedLineEdit(lbX, xL);
266 bc().addCheckedLineEdit(lbY, yL);
267 bc().addCheckedLineEdit(rtX, xL_2);
268 bc().addCheckedLineEdit(rtY, yL_2);
269 bc().addCheckedLineEdit(filename, filenameL);
273 void GuiGraphics::change_adaptor()
279 void GuiGraphics::change_bb()
282 LYXERR(Debug::GRAPHICS) << "[bb_Changed set to true]\n";
287 void GuiGraphics::closeEvent(QCloseEvent * e)
290 GuiDialog::closeEvent(e);
294 void GuiGraphics::on_browsePB_clicked()
296 docstring const str = browse(qstring_to_ucs4(filename->text()));
298 filename->setText(toqstr(str));
299 embedCB->setCheckState(Qt::Unchecked);
305 void GuiGraphics::on_getPB_clicked()
311 void GuiGraphics::on_editPB_clicked()
317 void GuiGraphics::on_filename_textChanged(const QString & filename)
319 editPB->setDisabled(filename.isEmpty());
323 void GuiGraphics::setAutoText()
325 if (scaleCB->isChecked())
327 if (!Scale->isEnabled() && Scale->text() != "100")
328 Scale->setText(QString("auto"));
330 setAutoTextCB(WidthCB, Width, widthUnit);
331 setAutoTextCB(HeightCB, Height, heightUnit);
335 void GuiGraphics::on_scaleCB_toggled(bool setScale)
337 Scale->setEnabled(setScale);
339 Scale->setText("100");
340 Scale->setFocus(Qt::OtherFocusReason);
343 WidthCB->setDisabled(setScale);
344 WidthCB->blockSignals(true);
345 WidthCB->setChecked(false);
346 WidthCB->blockSignals(false);
347 Width->setEnabled(false);
348 widthUnit->setEnabled(false);
350 HeightCB->setDisabled(setScale);
351 HeightCB->blockSignals(true);
352 HeightCB->setChecked(false);
353 HeightCB->blockSignals(false);
354 Height->setEnabled(false);
355 heightUnit->setEnabled(false);
357 aspectratio->setDisabled(true);
358 aspectratio->setChecked(true);
360 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
361 HeightCB->isChecked() ||
362 scaleCB->isChecked()) &&
363 (angle->text() != "0"));
369 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
371 Width->setEnabled(setWidth);
372 widthUnit->setEnabled(setWidth);
374 Width->setFocus(Qt::OtherFocusReason);
376 bool const setHeight = HeightCB->isChecked();
377 aspectratio->setEnabled(setWidth && setHeight);
378 aspectratio->blockSignals(true);
379 aspectratio->setChecked(!(setWidth && setHeight));
380 aspectratio->blockSignals(false);
382 scaleCB->setEnabled(!setWidth && !setHeight);
383 //already will be unchecked, so don't need to do that
384 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
385 && scaleCB->isChecked()); //should be false, but let's check
386 rotateOrderCB->setEnabled((setWidth || setHeight ||
387 scaleCB->isChecked()) &&
388 (angle->text() != "0"));
394 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
396 Height->setEnabled(setHeight);
397 heightUnit->setEnabled(setHeight);
399 Height->setFocus(Qt::OtherFocusReason);
401 bool const setWidth = WidthCB->isChecked();
402 aspectratio->setEnabled(setWidth && setHeight);
403 aspectratio->blockSignals(true);
404 aspectratio->setChecked(!(setWidth && setHeight));
405 aspectratio->blockSignals(false);
407 scaleCB->setEnabled(!setWidth && !setHeight);
409 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
410 && scaleCB->isChecked()); //should be false
411 rotateOrderCB->setEnabled((setWidth || setHeight ||
412 scaleCB->isChecked()) &&
413 (angle->text() != "0"));
419 void GuiGraphics::on_angle_textChanged(const QString & filename)
421 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
422 HeightCB->isChecked() ||
423 scaleCB->isChecked()) &&
427 // returns the number of the string s in the vector v
428 static int getItemNo(const vector<string> & v, string const & s)
430 vector<string>::const_iterator cit =
431 find(v.begin(), v.end(), s);
432 return (cit != v.end()) ? int(cit - v.begin()) : 0;
436 void GuiGraphics::updateContents()
438 // clear and fill in the comboboxes
439 vector<string> const bb_units = frontend::getBBUnits();
444 for (vector<string>::const_iterator it = bb_units.begin();
445 it != bb_units.end(); ++it) {
446 lbXunit->addItem(toqstr(*it));
447 lbYunit->addItem(toqstr(*it));
448 rtXunit->addItem(toqstr(*it));
449 rtYunit->addItem(toqstr(*it));
452 InsetGraphicsParams & igp = params_;
454 // set the right default unit
455 Length::UNIT unitDefault = Length::CM;
456 switch (lyxrc.default_papersize) {
459 case PAPER_USEXECUTIVE:
460 unitDefault = Length::IN;
467 igp.filename.outputFilename(bufferFilepath());
468 filename->setText(toqstr(name));
469 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
471 // set the bounding box values
472 if (igp.bb.empty()) {
473 string const bb = readBB(igp.filename.absFilename());
474 // the values from the file always have the bigpoint-unit bp
475 lbX->setText(toqstr(token(bb, ' ', 0)));
476 lbY->setText(toqstr(token(bb, ' ', 1)));
477 rtX->setText(toqstr(token(bb, ' ', 2)));
478 rtY->setText(toqstr(token(bb, ' ', 3)));
479 lbXunit->setCurrentIndex(0);
480 lbYunit->setCurrentIndex(0);
481 rtXunit->setCurrentIndex(0);
482 rtYunit->setCurrentIndex(0);
485 // get the values from the inset
487 string const xl = token(igp.bb, ' ', 0);
488 string const yl = token(igp.bb, ' ', 1);
489 string const xr = token(igp.bb, ' ', 2);
490 string const yr = token(igp.bb, ' ', 3);
491 if (isValidLength(xl, &anyLength)) {
492 lbX->setText(toqstr(convert<string>(anyLength.value())));
493 string const unit(unit_name[anyLength.unit()]);
494 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
496 lbX->setText(toqstr(xl));
498 if (isValidLength(yl, &anyLength)) {
499 lbY->setText(toqstr(convert<string>(anyLength.value())));
500 string const unit(unit_name[anyLength.unit()]);
501 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
503 lbY->setText(toqstr(xl));
505 if (isValidLength(xr, &anyLength)) {
506 rtX->setText(toqstr(convert<string>(anyLength.value())));
507 string const unit(unit_name[anyLength.unit()]);
508 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
510 rtX->setText(toqstr(xl));
512 if (isValidLength(yr, &anyLength)) {
513 rtY->setText(toqstr(convert<string>(anyLength.value())));
514 string const unit(unit_name[anyLength.unit()]);
515 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
517 rtY->setText(toqstr(xl));
522 // Update the draft and clip mode
523 draftCB->setChecked(igp.draft);
524 clip->setChecked(igp.clip);
525 unzipCB->setChecked(igp.noUnzip);
527 // Update the subcaption check button and input field
528 subfigure->setChecked(igp.subcaption);
529 subcaption->setText(toqstr(igp.subcaptionText));
532 switch (igp.display) {
533 case graphics::DefaultDisplay: item = 0; break;
534 case graphics::MonochromeDisplay: item = 1; break;
535 case graphics::GrayscaleDisplay: item = 2; break;
536 case graphics::ColorDisplay: item = 3; break;
537 case graphics::NoDisplay: item = 0; break;
539 showCB->setCurrentIndex(item);
540 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
541 displayGB->setChecked(igp.display != graphics::NoDisplay);
543 // the output section (width/height)
545 Scale->setText(toqstr(igp.scale));
546 //igp.scale defaults to 100, so we treat it as empty
547 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
548 scaleCB->blockSignals(true);
549 scaleCB->setChecked(scaleChecked);
550 scaleCB->blockSignals(false);
551 Scale->setEnabled(scaleChecked);
553 lengthAutoToWidgets(Width, widthUnit, igp.width,
555 bool const widthChecked = !Width->text().isEmpty() &&
556 Width->text() != "auto";
557 WidthCB->blockSignals(true);
558 WidthCB->setChecked(widthChecked);
559 WidthCB->blockSignals(false);
560 Width->setEnabled(widthChecked);
561 widthUnit->setEnabled(widthChecked);
563 lengthAutoToWidgets(Height, heightUnit, igp.height,
565 bool const heightChecked = !Height->text().isEmpty()
566 && Height->text() != "auto";
567 HeightCB->blockSignals(true);
568 HeightCB->setChecked(heightChecked);
569 HeightCB->blockSignals(false);
570 Height->setEnabled(heightChecked);
571 heightUnit->setEnabled(heightChecked);
573 scaleCB->setEnabled(!widthChecked && !heightChecked);
574 WidthCB->setEnabled(!scaleChecked);
575 HeightCB->setEnabled(!scaleChecked);
576 aspectratio->setEnabled(widthChecked && heightChecked);
580 angle->setText(toqstr(igp.rotateAngle));
581 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
583 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
584 && igp.rotateAngle != "0");
588 vector<RotationOriginPair> origindata = getRotationOriginData();
589 vector<docstring> const origin_lang = getFirst(origindata);
590 origin_ltx = getSecond(origindata);
592 for (vector<docstring>::const_iterator it = origin_lang.begin();
593 it != origin_lang.end(); ++it)
594 origin->addItem(toqstr(*it));
596 if (!igp.rotateOrigin.empty())
597 origin->setCurrentIndex(
598 getItemNo(origin_ltx, igp.rotateOrigin));
600 origin->setCurrentIndex(0);
602 // disable edit button when no filename is present
603 editPB->setDisabled(filename->text().isEmpty());
606 latexoptions->setText(toqstr(igp.special));
610 void GuiGraphics::applyView()
612 InsetGraphicsParams & igp = params_;
614 igp.filename.set(internal_path(fromqstr(filename->text())),
616 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
622 string lbXs = fromqstr(lbX->text());
623 string lbYs = fromqstr(lbY->text());
624 string rtXs = fromqstr(rtX->text());
625 string rtYs = fromqstr(rtY->text());
627 convert<int>(lbXs) + convert<int>(lbYs) +
628 convert<int>(rtXs) + convert<int>(rtXs);
633 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
637 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
641 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
645 bb += (rtYs + fromqstr(rtYunit->currentText()));
650 igp.draft = draftCB->isChecked();
651 igp.clip = clip->isChecked();
652 igp.subcaption = subfigure->isChecked();
653 igp.subcaptionText = fromqstr(subcaption->text());
655 switch (showCB->currentIndex()) {
656 case 0: igp.display = graphics::DefaultDisplay; break;
657 case 1: igp.display = graphics::MonochromeDisplay; break;
658 case 2: igp.display = graphics::GrayscaleDisplay; break;
659 case 3: igp.display = graphics::ColorDisplay; break;
663 if (!displayGB->isChecked())
664 igp.display = graphics::NoDisplay;
666 //the graphics section
667 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
668 igp.scale = fromqstr(Scale->text());
669 igp.width = Length("0pt");
670 igp.height = Length("0pt");
671 igp.keepAspectRatio = false;
673 igp.scale = string();
674 igp.width = WidthCB->isChecked() ?
675 //Note that this works even if Width is "auto", since in
676 //that case we get "0pt".
677 Length(widgetsToLength(Width, widthUnit)):
679 igp.height = HeightCB->isChecked() ?
680 Length(widgetsToLength(Height, heightUnit)) :
682 igp.keepAspectRatio = aspectratio->isEnabled() &&
683 aspectratio->isChecked() &&
684 igp.width.value() > 0 && igp.height.value() > 0;
687 igp.noUnzip = unzipCB->isChecked();
688 igp.lyxscale = displayscale->text().toInt();
689 igp.rotateAngle = fromqstr(angle->text());
691 double rotAngle = convert<double>(igp.rotateAngle);
692 if (std::abs(rotAngle) > 360.0) {
693 rotAngle -= 360.0 * floor(rotAngle / 360.0);
694 igp.rotateAngle = convert<string>(rotAngle);
697 // save the latex name for the origin. If it is the default
698 // then origin_ltx returns ""
699 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
700 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
702 // more latex options
703 igp.special = fromqstr(latexoptions->text());
707 void GuiGraphics::getBB()
709 string const fn = fromqstr(filename->text());
711 string const bb = readBB(fn);
713 lbX->setText(toqstr(token(bb, ' ', 0)));
714 lbY->setText(toqstr(token(bb, ' ', 1)));
715 rtX->setText(toqstr(token(bb, ' ', 2)));
716 rtY->setText(toqstr(token(bb, ' ', 3)));
717 // the default units for the bb values when reading
719 lbXunit->setCurrentIndex(0);
720 lbYunit->setCurrentIndex(0);
721 rtXunit->setCurrentIndex(0);
722 rtYunit->setCurrentIndex(0);
729 bool GuiGraphics::isValid()
731 return !filename->text().isEmpty();
735 bool GuiGraphics::initialiseParams(string const & data)
737 InsetGraphicsMailer::string2params(data, buffer(), params_);
742 void GuiGraphics::clearParams()
744 params_ = InsetGraphicsParams();
748 void GuiGraphics::dispatchParams()
750 InsetGraphicsParams tmp_params(params_);
752 InsetGraphicsMailer::params2string(tmp_params, buffer());
753 dispatch(FuncRequest(getLfun(), lfun));
757 docstring const GuiGraphics::browse(docstring const & in_name) const
759 docstring const title = _("Select graphics file");
761 // Does user clipart directory exist?
762 string clipdir = addName(package().user_support().absFilename(), "clipart");
763 FileName clip(clipdir);
764 if (!clip.exists() && clip.isDirectory())
765 // No - bail out to system clipart directory
766 clipdir = addName(package().system_support().absFilename(), "clipart");
767 pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
768 pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
769 // Show the file browser dialog
770 return browseRelFile(in_name, from_utf8(bufferFilepath()),
771 title, FileFilterList(), false, dir1, dir2);
775 string const GuiGraphics::readBB(string const & file)
777 FileName const abs_file = makeAbsPath(file, bufferFilepath());
779 // try to get it from the file, if possible. Zipped files are
780 // unzipped in the readBB_from_PSFile-Function
781 string const bb = readBB_from_PSFile(abs_file);
785 // we don't, so ask the Graphics Cache if it has loaded the file
789 graphics::Cache & gc = graphics::Cache::get();
790 if (gc.inCache(abs_file)) {
791 graphics::Image const * image = gc.item(abs_file)->image();
794 width = image->getWidth();
795 height = image->getHeight();
799 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
803 bool GuiGraphics::isFilenameValid(string const & fname) const
805 // It may be that the filename is relative.
806 return makeAbsPath(fname, bufferFilepath()).isReadable();
810 void GuiGraphics::editGraphics()
814 InsetGraphicsMailer::params2string(params_, buffer());
815 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
821 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
822 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
824 // These are the strings that are stored in the LyX file and which
825 // correspond to the LaTeX identifiers shown in the comments at the
827 char const * const rorigin_lyx_strs[] = {
828 // the LaTeX default is leftBaseline
830 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
831 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
832 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
834 // These are the strings, corresponding to the above, that the GUI should
835 // use. Note that they can/should be translated.
836 char const * const rorigin_gui_strs[] = {
838 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
839 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
840 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
842 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
847 vector<string> const getBBUnits()
849 return vector<string>(bb_units, bb_units + bb_size);
853 vector<RotationOriginPair> getRotationOriginData()
855 static vector<RotationOriginPair> data;
859 data.resize(rorigin_size);
860 for (size_type i = 0; i < rorigin_size; ++i) {
861 data[i] = make_pair(_(rorigin_gui_strs[i]),
862 rorigin_lyx_strs[i]);
869 Dialog * createGuiGraphics(LyXView & lv) { return new GuiGraphics(lv); }
872 } // namespace frontend
875 #include "GuiGraphics_moc.cpp"