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::isFileReadable;
78 using support::makeAbsPath;
79 using support::os::internal_path;
80 using support::package;
81 using support::readBB_from_PSFile;
85 //FIXME setAutoTextCB should really take an argument, as indicated, that
86 //determines what text is to be written for "auto". But making
87 //that work involves more extensive revisions than we now want
88 //to make, since "auto" also appears in updateContents() (see
90 //The right way to do this, I think, would be to define a class
91 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
92 //the checkbox, line edit, and length combo together, and then made e.g.
93 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
94 //Perhaps even the validator could be exposed through it.
96 * sets a checkbox-line edit-length combo group, using "text" if the
97 * checkbox is unchecked and clearing the line edit if it previously
100 void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
101 LengthCombo * lengthCombo/*, string text = "auto"*/)
103 if (!checkBox->isChecked())
104 lengthToWidgets(lineEdit, lengthCombo,
105 "auto", lengthCombo->currentLengthItem());
106 else if (lineEdit->text() == "auto")
107 lengthToWidgets(lineEdit, lengthCombo, string(),
108 lengthCombo->currentLengthItem());
114 vector<typename Pair::first_type> const
115 getFirst(vector<Pair> const & pr)
117 vector<typename Pair::first_type> tmp(pr.size());
118 transform(pr.begin(), pr.end(), tmp.begin(),
119 boost::bind(&Pair::first, _1));
125 vector<typename Pair::second_type> const
126 getSecond(vector<Pair> const & pr)
128 vector<typename Pair::second_type> tmp(pr.size());
129 transform(pr.begin(), pr.end(), tmp.begin(),
130 boost::bind(&Pair::second, _1));
134 GuiGraphics::GuiGraphics(LyXView & lv)
135 : GuiDialog(lv, "graphics")
138 setViewTitle(_("Graphics"));
141 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
142 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
143 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
144 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
147 connect(filename, SIGNAL(textChanged(const QString &)),
148 this, SLOT(change_adaptor()));
149 connect(WidthCB, SIGNAL( clicked()),
150 this, SLOT(change_adaptor()));
151 connect(HeightCB, SIGNAL( clicked()),
152 this, SLOT(change_adaptor()));
153 connect(Width, SIGNAL(textChanged(const QString &)),
154 this, SLOT(change_adaptor()));
155 connect(Height, SIGNAL(textChanged(const QString &)),
156 this, SLOT(change_adaptor()));
157 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
158 this, SLOT(change_adaptor()));
159 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
160 this, SLOT(change_adaptor()));
161 connect(aspectratio, SIGNAL(stateChanged(int)),
162 this, SLOT(change_adaptor()));
163 connect(angle, SIGNAL(textChanged(const QString &)),
164 this, SLOT(change_adaptor()));
165 connect(origin, SIGNAL(activated(int)),
166 this, SLOT(change_adaptor()));
167 connect(scaleCB, SIGNAL(clicked()),
168 this, SLOT(change_adaptor()));
169 connect(Scale, SIGNAL(textChanged(const QString &)),
170 this, SLOT(change_adaptor()));
171 connect(rotateOrderCB, SIGNAL(clicked()),
172 this, SLOT(change_adaptor()));
174 filename->setValidator(new PathValidator(true, filename));
175 setFocusProxy(filename);
177 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
178 scaleValidator->setBottom(0);
179 scaleValidator->setDecimals(256); //I guess that will do
180 Scale->setValidator(scaleValidator);
181 Height->setValidator(unsignedLengthAutoValidator(Height));
182 Width->setValidator(unsignedLengthAutoValidator(Width));
183 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
186 connect(clip, SIGNAL(stateChanged(int)),
187 this, SLOT(change_adaptor()));
188 connect(lbY, SIGNAL(textChanged(const QString&)),
189 this, SLOT(change_bb()));
190 connect(lbYunit, SIGNAL(activated(int)),
191 this, SLOT(change_bb()));
192 connect(rtY, SIGNAL(textChanged(const QString&)),
193 this, SLOT(change_bb()));
194 connect(rtYunit, SIGNAL(activated(int)),
195 this, SLOT(change_bb()));
196 connect(lbX, SIGNAL(textChanged(const QString&)),
197 this, SLOT(change_bb()));
198 connect(lbXunit, SIGNAL(activated(int)),
199 this, SLOT(change_bb()));
200 connect(rtX, SIGNAL(textChanged(const QString&)),
201 this, SLOT(change_bb()));
202 connect(rtXunit, SIGNAL(activated(int)),
203 this, SLOT(change_bb()));
204 connect(getPB, SIGNAL(clicked()),
205 this, SLOT(change_adaptor()));
207 lbX->setValidator(new QDoubleValidator(lbX));
208 lbY->setValidator(new QDoubleValidator(lbY));
209 rtX->setValidator(new QDoubleValidator(rtX));
210 rtY->setValidator(new QDoubleValidator(rtY));
213 connect(latexoptions, SIGNAL(textChanged(const QString&)),
214 this, SLOT(change_adaptor()));
215 connect(draftCB, SIGNAL(stateChanged(int)),
216 this, SLOT(change_adaptor()));
217 connect(unzipCB, SIGNAL(stateChanged(int)),
218 this, SLOT(change_adaptor()));
219 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
220 // the toggled(bool) signal is also trigged when we update the widgets
221 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
222 // using blockSignals() to keep from triggering that signal when we call
223 // setChecked(). Note, too, that clicked() would get called whenever it
224 // is clicked, even right clicked (I think), not just whenever it is
226 connect(subfigure, SIGNAL(toggled(bool)),
227 this, SLOT(change_adaptor()));
228 connect(subcaption, SIGNAL(textChanged(const QString&)),
229 this, SLOT(change_adaptor()));
230 connect(displayGB, SIGNAL(toggled(bool)),
231 this, SLOT(change_adaptor()));
232 connect(showCB, SIGNAL(currentIndexChanged(int)),
233 this, SLOT(change_adaptor()));
234 connect(displayscale, SIGNAL(textChanged(const QString&)),
235 this, SLOT(change_adaptor()));
236 displayscale->setValidator(new QIntValidator(displayscale));
238 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
240 bc().setApply(applyPB);
241 bc().setRestore(restorePB);
242 bc().setCancel(closePB);
244 bc().addReadOnly(latexoptions);
245 bc().addReadOnly(subfigure);
246 bc().addReadOnly(filenameL);
247 bc().addReadOnly(filename);
248 bc().addReadOnly(browsePB);
249 bc().addReadOnly(unzipCB);
250 bc().addReadOnly(bbFrame);
251 bc().addReadOnly(draftCB);
252 bc().addReadOnly(clip);
253 bc().addReadOnly(unzipCB);
254 bc().addReadOnly(displayGB);
255 bc().addReadOnly(sizeGB);
256 bc().addReadOnly(rotationGB);
257 bc().addReadOnly(latexoptions);
258 bc().addReadOnly(getPB);
259 bc().addReadOnly(rotateOrderCB);
261 // initialize the length validator
262 bc().addCheckedLineEdit(Scale, scaleCB);
263 bc().addCheckedLineEdit(Width, WidthCB);
264 bc().addCheckedLineEdit(Height, HeightCB);
265 bc().addCheckedLineEdit(displayscale, scaleLA);
266 bc().addCheckedLineEdit(angle, angleL);
267 bc().addCheckedLineEdit(lbX, xL);
268 bc().addCheckedLineEdit(lbY, yL);
269 bc().addCheckedLineEdit(rtX, xL_2);
270 bc().addCheckedLineEdit(rtY, yL_2);
271 bc().addCheckedLineEdit(filename, filenameL);
275 void GuiGraphics::change_adaptor()
281 void GuiGraphics::change_bb()
284 LYXERR(Debug::GRAPHICS) << "[bb_Changed set to true]\n";
289 void GuiGraphics::closeEvent(QCloseEvent * e)
292 GuiDialog::closeEvent(e);
296 void GuiGraphics::on_browsePB_clicked()
298 docstring const str = browse(qstring_to_ucs4(filename->text()));
300 filename->setText(toqstr(str));
301 embedCB->setCheckState(Qt::Unchecked);
307 void GuiGraphics::on_getPB_clicked()
313 void GuiGraphics::on_editPB_clicked()
319 void GuiGraphics::on_filename_textChanged(const QString & filename)
321 editPB->setDisabled(filename.isEmpty());
325 void GuiGraphics::setAutoText()
327 if (scaleCB->isChecked())
329 if (!Scale->isEnabled() && Scale->text() != "100")
330 Scale->setText(QString("auto"));
332 setAutoTextCB(WidthCB, Width, widthUnit);
333 setAutoTextCB(HeightCB, Height, heightUnit);
337 void GuiGraphics::on_scaleCB_toggled(bool setScale)
339 Scale->setEnabled(setScale);
341 Scale->setText("100");
342 Scale->setFocus(Qt::OtherFocusReason);
345 WidthCB->setDisabled(setScale);
346 WidthCB->blockSignals(true);
347 WidthCB->setChecked(false);
348 WidthCB->blockSignals(false);
349 Width->setEnabled(false);
350 widthUnit->setEnabled(false);
352 HeightCB->setDisabled(setScale);
353 HeightCB->blockSignals(true);
354 HeightCB->setChecked(false);
355 HeightCB->blockSignals(false);
356 Height->setEnabled(false);
357 heightUnit->setEnabled(false);
359 aspectratio->setDisabled(true);
360 aspectratio->setChecked(true);
362 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
363 HeightCB->isChecked() ||
364 scaleCB->isChecked()) &&
365 (angle->text() != "0"));
371 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
373 Width->setEnabled(setWidth);
374 widthUnit->setEnabled(setWidth);
376 Width->setFocus(Qt::OtherFocusReason);
378 bool const setHeight = HeightCB->isChecked();
379 aspectratio->setEnabled(setWidth && setHeight);
380 aspectratio->blockSignals(true);
381 aspectratio->setChecked(!(setWidth && setHeight));
382 aspectratio->blockSignals(false);
384 scaleCB->setEnabled(!setWidth && !setHeight);
385 //already will be unchecked, so don't need to do that
386 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
387 && scaleCB->isChecked()); //should be false, but let's check
388 rotateOrderCB->setEnabled((setWidth || setHeight ||
389 scaleCB->isChecked()) &&
390 (angle->text() != "0"));
396 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
398 Height->setEnabled(setHeight);
399 heightUnit->setEnabled(setHeight);
401 Height->setFocus(Qt::OtherFocusReason);
403 bool const setWidth = WidthCB->isChecked();
404 aspectratio->setEnabled(setWidth && setHeight);
405 aspectratio->blockSignals(true);
406 aspectratio->setChecked(!(setWidth && setHeight));
407 aspectratio->blockSignals(false);
409 scaleCB->setEnabled(!setWidth && !setHeight);
411 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
412 && scaleCB->isChecked()); //should be false
413 rotateOrderCB->setEnabled((setWidth || setHeight ||
414 scaleCB->isChecked()) &&
415 (angle->text() != "0"));
421 void GuiGraphics::on_angle_textChanged(const QString & filename)
423 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
424 HeightCB->isChecked() ||
425 scaleCB->isChecked()) &&
429 // returns the number of the string s in the vector v
430 static int getItemNo(const vector<string> & v, string const & s)
432 vector<string>::const_iterator cit =
433 find(v.begin(), v.end(), s);
434 return (cit != v.end()) ? int(cit - v.begin()) : 0;
438 void GuiGraphics::updateContents()
440 // clear and fill in the comboboxes
441 vector<string> const bb_units = frontend::getBBUnits();
446 for (vector<string>::const_iterator it = bb_units.begin();
447 it != bb_units.end(); ++it) {
448 lbXunit->addItem(toqstr(*it));
449 lbYunit->addItem(toqstr(*it));
450 rtXunit->addItem(toqstr(*it));
451 rtYunit->addItem(toqstr(*it));
454 InsetGraphicsParams & igp = params_;
456 // set the right default unit
457 Length::UNIT unitDefault = Length::CM;
458 switch (lyxrc.default_papersize) {
461 case PAPER_USEXECUTIVE:
462 unitDefault = Length::IN;
469 igp.filename.outputFilename(bufferFilepath());
470 filename->setText(toqstr(name));
471 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
473 // set the bounding box values
474 if (igp.bb.empty()) {
475 string const bb = readBB(igp.filename.absFilename());
476 // the values from the file always have the bigpoint-unit bp
477 lbX->setText(toqstr(token(bb, ' ', 0)));
478 lbY->setText(toqstr(token(bb, ' ', 1)));
479 rtX->setText(toqstr(token(bb, ' ', 2)));
480 rtY->setText(toqstr(token(bb, ' ', 3)));
481 lbXunit->setCurrentIndex(0);
482 lbYunit->setCurrentIndex(0);
483 rtXunit->setCurrentIndex(0);
484 rtYunit->setCurrentIndex(0);
487 // get the values from the inset
489 string const xl = token(igp.bb, ' ', 0);
490 string const yl = token(igp.bb, ' ', 1);
491 string const xr = token(igp.bb, ' ', 2);
492 string const yr = token(igp.bb, ' ', 3);
493 if (isValidLength(xl, &anyLength)) {
494 lbX->setText(toqstr(convert<string>(anyLength.value())));
495 string const unit(unit_name[anyLength.unit()]);
496 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
498 lbX->setText(toqstr(xl));
500 if (isValidLength(yl, &anyLength)) {
501 lbY->setText(toqstr(convert<string>(anyLength.value())));
502 string const unit(unit_name[anyLength.unit()]);
503 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
505 lbY->setText(toqstr(xl));
507 if (isValidLength(xr, &anyLength)) {
508 rtX->setText(toqstr(convert<string>(anyLength.value())));
509 string const unit(unit_name[anyLength.unit()]);
510 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
512 rtX->setText(toqstr(xl));
514 if (isValidLength(yr, &anyLength)) {
515 rtY->setText(toqstr(convert<string>(anyLength.value())));
516 string const unit(unit_name[anyLength.unit()]);
517 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
519 rtY->setText(toqstr(xl));
524 // Update the draft and clip mode
525 draftCB->setChecked(igp.draft);
526 clip->setChecked(igp.clip);
527 unzipCB->setChecked(igp.noUnzip);
529 // Update the subcaption check button and input field
530 subfigure->setChecked(igp.subcaption);
531 subcaption->setText(toqstr(igp.subcaptionText));
534 switch (igp.display) {
535 case graphics::DefaultDisplay: item = 0; break;
536 case graphics::MonochromeDisplay: item = 1; break;
537 case graphics::GrayscaleDisplay: item = 2; break;
538 case graphics::ColorDisplay: item = 3; break;
539 case graphics::NoDisplay: item = 0; break;
541 showCB->setCurrentIndex(item);
542 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
543 displayGB->setChecked(igp.display != graphics::NoDisplay);
545 // the output section (width/height)
547 Scale->setText(toqstr(igp.scale));
548 //igp.scale defaults to 100, so we treat it as empty
549 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
550 scaleCB->blockSignals(true);
551 scaleCB->setChecked(scaleChecked);
552 scaleCB->blockSignals(false);
553 Scale->setEnabled(scaleChecked);
555 lengthAutoToWidgets(Width, widthUnit, igp.width,
557 bool const widthChecked = !Width->text().isEmpty() &&
558 Width->text() != "auto";
559 WidthCB->blockSignals(true);
560 WidthCB->setChecked(widthChecked);
561 WidthCB->blockSignals(false);
562 Width->setEnabled(widthChecked);
563 widthUnit->setEnabled(widthChecked);
565 lengthAutoToWidgets(Height, heightUnit, igp.height,
567 bool const heightChecked = !Height->text().isEmpty()
568 && Height->text() != "auto";
569 HeightCB->blockSignals(true);
570 HeightCB->setChecked(heightChecked);
571 HeightCB->blockSignals(false);
572 Height->setEnabled(heightChecked);
573 heightUnit->setEnabled(heightChecked);
575 scaleCB->setEnabled(!widthChecked && !heightChecked);
576 WidthCB->setEnabled(!scaleChecked);
577 HeightCB->setEnabled(!scaleChecked);
578 aspectratio->setEnabled(widthChecked && heightChecked);
582 angle->setText(toqstr(igp.rotateAngle));
583 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
585 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
586 && igp.rotateAngle != "0");
590 vector<RotationOriginPair> origindata = getRotationOriginData();
591 vector<docstring> const origin_lang = getFirst(origindata);
592 origin_ltx = getSecond(origindata);
594 for (vector<docstring>::const_iterator it = origin_lang.begin();
595 it != origin_lang.end(); ++it)
596 origin->addItem(toqstr(*it));
598 if (!igp.rotateOrigin.empty())
599 origin->setCurrentIndex(
600 getItemNo(origin_ltx, igp.rotateOrigin));
602 origin->setCurrentIndex(0);
604 // disable edit button when no filename is present
605 editPB->setDisabled(filename->text().isEmpty());
608 latexoptions->setText(toqstr(igp.special));
612 void GuiGraphics::applyView()
614 InsetGraphicsParams & igp = params_;
616 igp.filename.set(internal_path(fromqstr(filename->text())),
618 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
624 string lbXs = fromqstr(lbX->text());
625 string lbYs = fromqstr(lbY->text());
626 string rtXs = fromqstr(rtX->text());
627 string rtYs = fromqstr(rtY->text());
629 convert<int>(lbXs) + convert<int>(lbYs) +
630 convert<int>(rtXs) + convert<int>(rtXs);
635 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
639 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
643 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
647 bb += (rtYs + fromqstr(rtYunit->currentText()));
652 igp.draft = draftCB->isChecked();
653 igp.clip = clip->isChecked();
654 igp.subcaption = subfigure->isChecked();
655 igp.subcaptionText = fromqstr(subcaption->text());
657 switch (showCB->currentIndex()) {
658 case 0: igp.display = graphics::DefaultDisplay; break;
659 case 1: igp.display = graphics::MonochromeDisplay; break;
660 case 2: igp.display = graphics::GrayscaleDisplay; break;
661 case 3: igp.display = graphics::ColorDisplay; break;
665 if (!displayGB->isChecked())
666 igp.display = graphics::NoDisplay;
668 //the graphics section
669 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
670 igp.scale = fromqstr(Scale->text());
671 igp.width = Length("0pt");
672 igp.height = Length("0pt");
673 igp.keepAspectRatio = false;
675 igp.scale = string();
676 igp.width = WidthCB->isChecked() ?
677 //Note that this works even if Width is "auto", since in
678 //that case we get "0pt".
679 Length(widgetsToLength(Width, widthUnit)):
681 igp.height = HeightCB->isChecked() ?
682 Length(widgetsToLength(Height, heightUnit)) :
684 igp.keepAspectRatio = aspectratio->isEnabled() &&
685 aspectratio->isChecked() &&
686 igp.width.value() > 0 && igp.height.value() > 0;
689 igp.noUnzip = unzipCB->isChecked();
690 igp.lyxscale = displayscale->text().toInt();
691 igp.rotateAngle = fromqstr(angle->text());
693 double rotAngle = convert<double>(igp.rotateAngle);
694 if (std::abs(rotAngle) > 360.0) {
695 rotAngle -= 360.0 * floor(rotAngle / 360.0);
696 igp.rotateAngle = convert<string>(rotAngle);
699 // save the latex name for the origin. If it is the default
700 // then origin_ltx returns ""
701 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
702 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
704 // more latex options
705 igp.special = fromqstr(latexoptions->text());
709 void GuiGraphics::getBB()
711 string const fn = fromqstr(filename->text());
713 string const bb = readBB(fn);
715 lbX->setText(toqstr(token(bb, ' ', 0)));
716 lbY->setText(toqstr(token(bb, ' ', 1)));
717 rtX->setText(toqstr(token(bb, ' ', 2)));
718 rtY->setText(toqstr(token(bb, ' ', 3)));
719 // the default units for the bb values when reading
721 lbXunit->setCurrentIndex(0);
722 lbYunit->setCurrentIndex(0);
723 rtXunit->setCurrentIndex(0);
724 rtYunit->setCurrentIndex(0);
731 bool GuiGraphics::isValid()
733 return !filename->text().isEmpty();
737 bool GuiGraphics::initialiseParams(string const & data)
739 InsetGraphicsMailer::string2params(data, buffer(), params_);
744 void GuiGraphics::clearParams()
746 params_ = InsetGraphicsParams();
750 void GuiGraphics::dispatchParams()
752 InsetGraphicsParams tmp_params(params_);
754 InsetGraphicsMailer::params2string(tmp_params, buffer());
755 dispatch(FuncRequest(getLfun(), lfun));
759 docstring const GuiGraphics::browse(docstring const & in_name) const
761 docstring const title = _("Select graphics file");
763 // Does user clipart directory exist?
764 string clipdir = addName(package().user_support().absFilename(), "clipart");
765 FileName clip(clipdir);
766 if (!clip.exists() && clip.isDirectory())
767 // No - bail out to system clipart directory
768 clipdir = addName(package().system_support().absFilename(), "clipart");
769 pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
770 pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
771 // Show the file browser dialog
772 return browseRelFile(in_name, from_utf8(bufferFilepath()),
773 title, FileFilterList(), false, dir1, dir2);
777 string const GuiGraphics::readBB(string const & file)
779 FileName const abs_file(makeAbsPath(file, bufferFilepath()));
781 // try to get it from the file, if possible. Zipped files are
782 // unzipped in the readBB_from_PSFile-Function
783 string const bb = readBB_from_PSFile(abs_file);
787 // we don't, so ask the Graphics Cache if it has loaded the file
791 graphics::Cache & gc = graphics::Cache::get();
792 if (gc.inCache(abs_file)) {
793 graphics::Image const * image = gc.item(abs_file)->image();
796 width = image->getWidth();
797 height = image->getHeight();
801 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
805 bool GuiGraphics::isFilenameValid(string const & fname) const
807 // It may be that the filename is relative.
808 return isFileReadable(makeAbsPath(fname, bufferFilepath()));
812 void GuiGraphics::editGraphics()
816 InsetGraphicsMailer::params2string(params_, buffer());
817 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
823 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
824 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
826 // These are the strings that are stored in the LyX file and which
827 // correspond to the LaTeX identifiers shown in the comments at the
829 char const * const rorigin_lyx_strs[] = {
830 // the LaTeX default is leftBaseline
832 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
833 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
834 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
836 // These are the strings, corresponding to the above, that the GUI should
837 // use. Note that they can/should be translated.
838 char const * const rorigin_gui_strs[] = {
840 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
841 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
842 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
844 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
849 vector<string> const getBBUnits()
851 return vector<string>(bb_units, bb_units + bb_size);
855 vector<RotationOriginPair> getRotationOriginData()
857 static vector<RotationOriginPair> data;
861 data.resize(rorigin_size);
862 for (size_type i = 0; i < rorigin_size; ++i) {
863 data[i] = make_pair(_(rorigin_gui_strs[i]),
864 rorigin_lyx_strs[i]);
871 Dialog * createGuiGraphics(LyXView & lv) { return new GuiGraphics(lv); }
874 } // namespace frontend
877 #include "GuiGraphics_moc.cpp"