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>
47 #include <boost/filesystem/operations.hpp>
50 #include <QCloseEvent>
53 #include <QPushButton>
60 #ifndef CXX_GLOBAL_CSTD
71 namespace fs = boost::filesystem;
76 using support::addName;
77 using support::FileFilterList;
78 using support::FileName;
79 using support::float_equal;
80 using support::isFileReadable;
81 using support::makeAbsPath;
82 using support::os::internal_path;
83 using support::package;
84 using support::readBB_from_PSFile;
88 //FIXME setAutoTextCB should really take an argument, as indicated, that
89 //determines what text is to be written for "auto". But making
90 //that work involves more extensive revisions than we now want
91 //to make, since "auto" also appears in updateContents() (see
93 //The right way to do this, I think, would be to define a class
94 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
95 //the checkbox, line edit, and length combo together, and then made e.g.
96 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
97 //Perhaps even the validator could be exposed through it.
99 * sets a checkbox-line edit-length combo group, using "text" if the
100 * checkbox is unchecked and clearing the line edit if it previously
103 void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
104 LengthCombo * lengthCombo/*, string text = "auto"*/)
106 if (!checkBox->isChecked())
107 lengthToWidgets(lineEdit, lengthCombo,
108 "auto", lengthCombo->currentLengthItem());
109 else if (lineEdit->text() == "auto")
110 lengthToWidgets(lineEdit, lengthCombo, string(),
111 lengthCombo->currentLengthItem());
117 vector<typename Pair::first_type> const
118 getFirst(vector<Pair> const & pr)
120 vector<typename Pair::first_type> tmp(pr.size());
121 transform(pr.begin(), pr.end(), tmp.begin(),
122 boost::bind(&Pair::first, _1));
128 vector<typename Pair::second_type> const
129 getSecond(vector<Pair> const & pr)
131 vector<typename Pair::second_type> tmp(pr.size());
132 transform(pr.begin(), pr.end(), tmp.begin(),
133 boost::bind(&Pair::second, _1));
137 GuiGraphics::GuiGraphics(LyXView & lv)
138 : GuiDialog(lv, "graphics"), Controller(this)
141 setViewTitle(_("Graphics"));
142 setController(this, false);
145 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
146 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
147 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
148 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
151 connect(filename, SIGNAL(textChanged(const QString &)),
152 this, SLOT(change_adaptor()));
153 connect(WidthCB, SIGNAL( clicked()),
154 this, SLOT(change_adaptor()));
155 connect(HeightCB, SIGNAL( clicked()),
156 this, SLOT(change_adaptor()));
157 connect(Width, SIGNAL(textChanged(const QString &)),
158 this, SLOT(change_adaptor()));
159 connect(Height, SIGNAL(textChanged(const QString &)),
160 this, SLOT(change_adaptor()));
161 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
162 this, SLOT(change_adaptor()));
163 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
164 this, SLOT(change_adaptor()));
165 connect(aspectratio, SIGNAL(stateChanged(int)),
166 this, SLOT(change_adaptor()));
167 connect(angle, SIGNAL(textChanged(const QString &)),
168 this, SLOT(change_adaptor()));
169 connect(origin, SIGNAL(activated(int)),
170 this, SLOT(change_adaptor()));
171 connect(scaleCB, SIGNAL(clicked()),
172 this, SLOT(change_adaptor()));
173 connect(Scale, SIGNAL(textChanged(const QString &)),
174 this, SLOT(change_adaptor()));
175 connect(rotateOrderCB, SIGNAL(clicked()),
176 this, SLOT(change_adaptor()));
178 filename->setValidator(new PathValidator(true, filename));
179 setFocusProxy(filename);
181 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
182 scaleValidator->setBottom(0);
183 scaleValidator->setDecimals(256); //I guess that will do
184 Scale->setValidator(scaleValidator);
185 Height->setValidator(unsignedLengthAutoValidator(Height));
186 Width->setValidator(unsignedLengthAutoValidator(Width));
187 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
190 connect(clip, SIGNAL(stateChanged(int)),
191 this, SLOT(change_adaptor()));
192 connect(lbY, SIGNAL(textChanged(const QString&)),
193 this, SLOT(change_bb()));
194 connect(lbYunit, SIGNAL(activated(int)),
195 this, SLOT(change_bb()));
196 connect(rtY, SIGNAL(textChanged(const QString&)),
197 this, SLOT(change_bb()));
198 connect(rtYunit, SIGNAL(activated(int)),
199 this, SLOT(change_bb()));
200 connect(lbX, SIGNAL(textChanged(const QString&)),
201 this, SLOT(change_bb()));
202 connect(lbXunit, SIGNAL(activated(int)),
203 this, SLOT(change_bb()));
204 connect(rtX, SIGNAL(textChanged(const QString&)),
205 this, SLOT(change_bb()));
206 connect(rtXunit, SIGNAL(activated(int)),
207 this, SLOT(change_bb()));
208 connect(getPB, SIGNAL(clicked()),
209 this, SLOT(change_adaptor()));
211 lbX->setValidator(new QDoubleValidator(lbX));
212 lbY->setValidator(new QDoubleValidator(lbY));
213 rtX->setValidator(new QDoubleValidator(rtX));
214 rtY->setValidator(new QDoubleValidator(rtY));
217 connect(latexoptions, SIGNAL(textChanged(const QString&)),
218 this, SLOT(change_adaptor()));
219 connect(draftCB, SIGNAL(stateChanged(int)),
220 this, SLOT(change_adaptor()));
221 connect(unzipCB, SIGNAL(stateChanged(int)),
222 this, SLOT(change_adaptor()));
223 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
224 // the toggled(bool) signal is also trigged when we update the widgets
225 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
226 // using blockSignals() to keep from triggering that signal when we call
227 // setChecked(). Note, too, that clicked() would get called whenever it
228 // is clicked, even right clicked (I think), not just whenever it is
230 connect(subfigure, SIGNAL(toggled(bool)),
231 this, SLOT(change_adaptor()));
232 connect(subcaption, SIGNAL(textChanged(const QString&)),
233 this, SLOT(change_adaptor()));
234 connect(displayGB, SIGNAL(toggled(bool)),
235 this, SLOT(change_adaptor()));
236 connect(showCB, SIGNAL(currentIndexChanged(int)),
237 this, SLOT(change_adaptor()));
238 connect(displayscale, SIGNAL(textChanged(const QString&)),
239 this, SLOT(change_adaptor()));
240 displayscale->setValidator(new QIntValidator(displayscale));
242 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
244 bc().setApply(applyPB);
245 bc().setRestore(restorePB);
246 bc().setCancel(closePB);
248 bc().addReadOnly(latexoptions);
249 bc().addReadOnly(subfigure);
250 bc().addReadOnly(filenameL);
251 bc().addReadOnly(filename);
252 bc().addReadOnly(browsePB);
253 bc().addReadOnly(unzipCB);
254 bc().addReadOnly(bbFrame);
255 bc().addReadOnly(draftCB);
256 bc().addReadOnly(clip);
257 bc().addReadOnly(unzipCB);
258 bc().addReadOnly(displayGB);
259 bc().addReadOnly(sizeGB);
260 bc().addReadOnly(rotationGB);
261 bc().addReadOnly(latexoptions);
262 bc().addReadOnly(getPB);
263 bc().addReadOnly(rotateOrderCB);
265 // initialize the length validator
266 bc().addCheckedLineEdit(Scale, scaleCB);
267 bc().addCheckedLineEdit(Width, WidthCB);
268 bc().addCheckedLineEdit(Height, HeightCB);
269 bc().addCheckedLineEdit(displayscale, scaleLA);
270 bc().addCheckedLineEdit(angle, angleL);
271 bc().addCheckedLineEdit(lbX, xL);
272 bc().addCheckedLineEdit(lbY, yL);
273 bc().addCheckedLineEdit(rtX, xL_2);
274 bc().addCheckedLineEdit(rtY, yL_2);
275 bc().addCheckedLineEdit(filename, filenameL);
279 void GuiGraphics::change_adaptor()
285 void GuiGraphics::change_bb()
288 LYXERR(Debug::GRAPHICS) << "[bb_Changed set to true]\n";
293 void GuiGraphics::closeEvent(QCloseEvent * e)
296 GuiDialog::closeEvent(e);
300 void GuiGraphics::on_browsePB_clicked()
302 docstring const str = browse(qstring_to_ucs4(filename->text()));
304 filename->setText(toqstr(str));
305 embedCB->setCheckState(Qt::Unchecked);
311 void GuiGraphics::on_getPB_clicked()
317 void GuiGraphics::on_editPB_clicked()
323 void GuiGraphics::on_filename_textChanged(const QString & filename)
325 editPB->setDisabled(filename.isEmpty());
329 void GuiGraphics::setAutoText()
331 if (scaleCB->isChecked())
333 if (!Scale->isEnabled() && Scale->text() != "100")
334 Scale->setText(QString("auto"));
336 setAutoTextCB(WidthCB, Width, widthUnit);
337 setAutoTextCB(HeightCB, Height, heightUnit);
341 void GuiGraphics::on_scaleCB_toggled(bool setScale)
343 Scale->setEnabled(setScale);
345 Scale->setText("100");
346 Scale->setFocus(Qt::OtherFocusReason);
349 WidthCB->setDisabled(setScale);
350 WidthCB->blockSignals(true);
351 WidthCB->setChecked(false);
352 WidthCB->blockSignals(false);
353 Width->setEnabled(false);
354 widthUnit->setEnabled(false);
356 HeightCB->setDisabled(setScale);
357 HeightCB->blockSignals(true);
358 HeightCB->setChecked(false);
359 HeightCB->blockSignals(false);
360 Height->setEnabled(false);
361 heightUnit->setEnabled(false);
363 aspectratio->setDisabled(true);
364 aspectratio->setChecked(true);
366 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
367 HeightCB->isChecked() ||
368 scaleCB->isChecked()) &&
369 (angle->text() != "0"));
375 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
377 Width->setEnabled(setWidth);
378 widthUnit->setEnabled(setWidth);
380 Width->setFocus(Qt::OtherFocusReason);
382 bool const setHeight = HeightCB->isChecked();
383 aspectratio->setEnabled(setWidth && setHeight);
384 aspectratio->blockSignals(true);
385 aspectratio->setChecked(!(setWidth && setHeight));
386 aspectratio->blockSignals(false);
388 scaleCB->setEnabled(!setWidth && !setHeight);
389 //already will be unchecked, so don't need to do that
390 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
391 && scaleCB->isChecked()); //should be false, but let's check
392 rotateOrderCB->setEnabled((setWidth || setHeight ||
393 scaleCB->isChecked()) &&
394 (angle->text() != "0"));
400 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
402 Height->setEnabled(setHeight);
403 heightUnit->setEnabled(setHeight);
405 Height->setFocus(Qt::OtherFocusReason);
407 bool const setWidth = WidthCB->isChecked();
408 aspectratio->setEnabled(setWidth && setHeight);
409 aspectratio->blockSignals(true);
410 aspectratio->setChecked(!(setWidth && setHeight));
411 aspectratio->blockSignals(false);
413 scaleCB->setEnabled(!setWidth && !setHeight);
415 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
416 && scaleCB->isChecked()); //should be false
417 rotateOrderCB->setEnabled((setWidth || setHeight ||
418 scaleCB->isChecked()) &&
419 (angle->text() != "0"));
425 void GuiGraphics::on_angle_textChanged(const QString & filename)
427 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
428 HeightCB->isChecked() ||
429 scaleCB->isChecked()) &&
433 // returns the number of the string s in the vector v
434 static int getItemNo(const vector<string> & v, string const & s)
436 vector<string>::const_iterator cit =
437 find(v.begin(), v.end(), s);
438 return (cit != v.end()) ? int(cit - v.begin()) : 0;
442 void GuiGraphics::updateContents()
444 // clear and fill in the comboboxes
445 vector<string> const bb_units = frontend::getBBUnits();
450 for (vector<string>::const_iterator it = bb_units.begin();
451 it != bb_units.end(); ++it) {
452 lbXunit->addItem(toqstr(*it));
453 lbYunit->addItem(toqstr(*it));
454 rtXunit->addItem(toqstr(*it));
455 rtYunit->addItem(toqstr(*it));
458 InsetGraphicsParams & igp = params_;
460 // set the right default unit
461 Length::UNIT unitDefault = Length::CM;
462 switch (lyxrc.default_papersize) {
465 case PAPER_USEXECUTIVE:
466 unitDefault = Length::IN;
473 igp.filename.outputFilename(bufferFilepath());
474 filename->setText(toqstr(name));
475 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
477 // set the bounding box values
478 if (igp.bb.empty()) {
479 string const bb = readBB(igp.filename.absFilename());
480 // the values from the file always have the bigpoint-unit bp
481 lbX->setText(toqstr(token(bb, ' ', 0)));
482 lbY->setText(toqstr(token(bb, ' ', 1)));
483 rtX->setText(toqstr(token(bb, ' ', 2)));
484 rtY->setText(toqstr(token(bb, ' ', 3)));
485 lbXunit->setCurrentIndex(0);
486 lbYunit->setCurrentIndex(0);
487 rtXunit->setCurrentIndex(0);
488 rtYunit->setCurrentIndex(0);
491 // get the values from the inset
493 string const xl = token(igp.bb, ' ', 0);
494 string const yl = token(igp.bb, ' ', 1);
495 string const xr = token(igp.bb, ' ', 2);
496 string const yr = token(igp.bb, ' ', 3);
497 if (isValidLength(xl, &anyLength)) {
498 lbX->setText(toqstr(convert<string>(anyLength.value())));
499 string const unit(unit_name[anyLength.unit()]);
500 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
502 lbX->setText(toqstr(xl));
504 if (isValidLength(yl, &anyLength)) {
505 lbY->setText(toqstr(convert<string>(anyLength.value())));
506 string const unit(unit_name[anyLength.unit()]);
507 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
509 lbY->setText(toqstr(xl));
511 if (isValidLength(xr, &anyLength)) {
512 rtX->setText(toqstr(convert<string>(anyLength.value())));
513 string const unit(unit_name[anyLength.unit()]);
514 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
516 rtX->setText(toqstr(xl));
518 if (isValidLength(yr, &anyLength)) {
519 rtY->setText(toqstr(convert<string>(anyLength.value())));
520 string const unit(unit_name[anyLength.unit()]);
521 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
523 rtY->setText(toqstr(xl));
528 // Update the draft and clip mode
529 draftCB->setChecked(igp.draft);
530 clip->setChecked(igp.clip);
531 unzipCB->setChecked(igp.noUnzip);
533 // Update the subcaption check button and input field
534 subfigure->setChecked(igp.subcaption);
535 subcaption->setText(toqstr(igp.subcaptionText));
538 switch (igp.display) {
539 case graphics::DefaultDisplay: item = 0; break;
540 case graphics::MonochromeDisplay: item = 1; break;
541 case graphics::GrayscaleDisplay: item = 2; break;
542 case graphics::ColorDisplay: item = 3; break;
543 case graphics::NoDisplay: item = 0; break;
545 showCB->setCurrentIndex(item);
546 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
547 displayGB->setChecked(igp.display != graphics::NoDisplay);
549 // the output section (width/height)
551 Scale->setText(toqstr(igp.scale));
552 //igp.scale defaults to 100, so we treat it as empty
553 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
554 scaleCB->blockSignals(true);
555 scaleCB->setChecked(scaleChecked);
556 scaleCB->blockSignals(false);
557 Scale->setEnabled(scaleChecked);
559 lengthAutoToWidgets(Width, widthUnit, igp.width,
561 bool const widthChecked = !Width->text().isEmpty() &&
562 Width->text() != "auto";
563 WidthCB->blockSignals(true);
564 WidthCB->setChecked(widthChecked);
565 WidthCB->blockSignals(false);
566 Width->setEnabled(widthChecked);
567 widthUnit->setEnabled(widthChecked);
569 lengthAutoToWidgets(Height, heightUnit, igp.height,
571 bool const heightChecked = !Height->text().isEmpty()
572 && Height->text() != "auto";
573 HeightCB->blockSignals(true);
574 HeightCB->setChecked(heightChecked);
575 HeightCB->blockSignals(false);
576 Height->setEnabled(heightChecked);
577 heightUnit->setEnabled(heightChecked);
579 scaleCB->setEnabled(!widthChecked && !heightChecked);
580 WidthCB->setEnabled(!scaleChecked);
581 HeightCB->setEnabled(!scaleChecked);
582 aspectratio->setEnabled(widthChecked && heightChecked);
586 angle->setText(toqstr(igp.rotateAngle));
587 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
589 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
590 && igp.rotateAngle != "0");
594 vector<RotationOriginPair> origindata = getRotationOriginData();
595 vector<docstring> const origin_lang = getFirst(origindata);
596 origin_ltx = getSecond(origindata);
598 for (vector<docstring>::const_iterator it = origin_lang.begin();
599 it != origin_lang.end(); ++it)
600 origin->addItem(toqstr(*it));
602 if (!igp.rotateOrigin.empty())
603 origin->setCurrentIndex(
604 getItemNo(origin_ltx, igp.rotateOrigin));
606 origin->setCurrentIndex(0);
608 // disable edit button when no filename is present
609 editPB->setDisabled(filename->text().isEmpty());
612 latexoptions->setText(toqstr(igp.special));
616 void GuiGraphics::applyView()
618 InsetGraphicsParams & igp = params_;
620 igp.filename.set(internal_path(fromqstr(filename->text())),
622 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
628 string lbXs = fromqstr(lbX->text());
629 string lbYs = fromqstr(lbY->text());
630 string rtXs = fromqstr(rtX->text());
631 string rtYs = fromqstr(rtY->text());
633 convert<int>(lbXs) + convert<int>(lbYs) +
634 convert<int>(rtXs) + convert<int>(rtXs);
639 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
643 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
647 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
651 bb += (rtYs + fromqstr(rtYunit->currentText()));
656 igp.draft = draftCB->isChecked();
657 igp.clip = clip->isChecked();
658 igp.subcaption = subfigure->isChecked();
659 igp.subcaptionText = fromqstr(subcaption->text());
661 switch (showCB->currentIndex()) {
662 case 0: igp.display = graphics::DefaultDisplay; break;
663 case 1: igp.display = graphics::MonochromeDisplay; break;
664 case 2: igp.display = graphics::GrayscaleDisplay; break;
665 case 3: igp.display = graphics::ColorDisplay; break;
669 if (!displayGB->isChecked())
670 igp.display = graphics::NoDisplay;
672 //the graphics section
673 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
674 igp.scale = fromqstr(Scale->text());
675 igp.width = Length("0pt");
676 igp.height = Length("0pt");
677 igp.keepAspectRatio = false;
679 igp.scale = string();
680 igp.width = WidthCB->isChecked() ?
681 //Note that this works even if Width is "auto", since in
682 //that case we get "0pt".
683 Length(widgetsToLength(Width, widthUnit)):
685 igp.height = HeightCB->isChecked() ?
686 Length(widgetsToLength(Height, heightUnit)) :
688 igp.keepAspectRatio = aspectratio->isEnabled() &&
689 aspectratio->isChecked() &&
690 igp.width.value() > 0 && igp.height.value() > 0;
693 igp.noUnzip = unzipCB->isChecked();
694 igp.lyxscale = displayscale->text().toInt();
695 igp.rotateAngle = fromqstr(angle->text());
697 double rotAngle = convert<double>(igp.rotateAngle);
698 if (std::abs(rotAngle) > 360.0) {
699 rotAngle -= 360.0 * floor(rotAngle / 360.0);
700 igp.rotateAngle = convert<string>(rotAngle);
703 // save the latex name for the origin. If it is the default
704 // then origin_ltx returns ""
705 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
706 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
708 // more latex options
709 igp.special = fromqstr(latexoptions->text());
713 void GuiGraphics::getBB()
715 string const fn = fromqstr(filename->text());
717 string const bb = readBB(fn);
719 lbX->setText(toqstr(token(bb, ' ', 0)));
720 lbY->setText(toqstr(token(bb, ' ', 1)));
721 rtX->setText(toqstr(token(bb, ' ', 2)));
722 rtY->setText(toqstr(token(bb, ' ', 3)));
723 // the default units for the bb values when reading
725 lbXunit->setCurrentIndex(0);
726 lbYunit->setCurrentIndex(0);
727 rtXunit->setCurrentIndex(0);
728 rtYunit->setCurrentIndex(0);
735 bool GuiGraphics::isValid()
737 return !filename->text().isEmpty();
741 bool GuiGraphics::initialiseParams(string const & data)
743 InsetGraphicsMailer::string2params(data, buffer(), params_);
748 void GuiGraphics::clearParams()
750 params_ = InsetGraphicsParams();
754 void GuiGraphics::dispatchParams()
756 InsetGraphicsParams tmp_params(params_);
758 InsetGraphicsMailer::params2string(tmp_params, buffer());
759 dispatch(FuncRequest(getLfun(), lfun));
763 docstring const GuiGraphics::browse(docstring const & in_name) const
765 docstring const title = _("Select graphics file");
767 // Does user clipart directory exist?
768 string clipdir = addName(package().user_support().absFilename(), "clipart");
769 string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
770 if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
771 // No - bail out to system clipart directory
772 clipdir = addName(package().system_support().absFilename(), "clipart");
773 pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
774 pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
775 // Show the file browser dialog
776 return browseRelFile(in_name, from_utf8(bufferFilepath()),
777 title, FileFilterList(), false, dir1, dir2);
781 string const GuiGraphics::readBB(string const & file)
783 FileName const abs_file(makeAbsPath(file, bufferFilepath()));
785 // try to get it from the file, if possible. Zipped files are
786 // unzipped in the readBB_from_PSFile-Function
787 string const bb = readBB_from_PSFile(abs_file);
791 // we don't, so ask the Graphics Cache if it has loaded the file
795 graphics::Cache & gc = graphics::Cache::get();
796 if (gc.inCache(abs_file)) {
797 graphics::Image const * image = gc.item(abs_file)->image();
800 width = image->getWidth();
801 height = image->getHeight();
805 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
809 bool GuiGraphics::isFilenameValid(string const & fname) const
811 // It may be that the filename is relative.
812 FileName const name(makeAbsPath(fname, bufferFilepath()));
813 return isFileReadable(name);
817 void GuiGraphics::editGraphics()
819 dialog().applyView();
821 InsetGraphicsMailer::params2string(params_, buffer());
822 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
828 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
829 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
831 // These are the strings that are stored in the LyX file and which
832 // correspond to the LaTeX identifiers shown in the comments at the
834 char const * const rorigin_lyx_strs[] = {
835 // the LaTeX default is leftBaseline
837 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
838 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
839 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
841 // These are the strings, corresponding to the above, that the GUI should
842 // use. Note that they can/should be translated.
843 char const * const rorigin_gui_strs[] = {
845 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
846 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
847 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
849 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
854 vector<string> const getBBUnits()
856 return vector<string>(bb_units, bb_units + bb_size);
860 vector<RotationOriginPair> getRotationOriginData()
862 static vector<RotationOriginPair> data;
866 data.resize(rorigin_size);
867 for (size_type i = 0; i < rorigin_size; ++i) {
868 data[i] = make_pair(_(rorigin_gui_strs[i]),
869 rorigin_lyx_strs[i]);
876 Dialog * createGuiGraphics(LyXView & lv) { return new GuiGraphics(lv); }
879 } // namespace frontend
882 #include "GuiGraphics_moc.cpp"