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")
141 setViewTitle(_("Graphics"));
144 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
145 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
146 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
147 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
150 connect(filename, SIGNAL(textChanged(const QString &)),
151 this, SLOT(change_adaptor()));
152 connect(WidthCB, SIGNAL( clicked()),
153 this, SLOT(change_adaptor()));
154 connect(HeightCB, SIGNAL( clicked()),
155 this, SLOT(change_adaptor()));
156 connect(Width, SIGNAL(textChanged(const QString &)),
157 this, SLOT(change_adaptor()));
158 connect(Height, SIGNAL(textChanged(const QString &)),
159 this, SLOT(change_adaptor()));
160 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
161 this, SLOT(change_adaptor()));
162 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
163 this, SLOT(change_adaptor()));
164 connect(aspectratio, SIGNAL(stateChanged(int)),
165 this, SLOT(change_adaptor()));
166 connect(angle, SIGNAL(textChanged(const QString &)),
167 this, SLOT(change_adaptor()));
168 connect(origin, SIGNAL(activated(int)),
169 this, SLOT(change_adaptor()));
170 connect(scaleCB, SIGNAL(clicked()),
171 this, SLOT(change_adaptor()));
172 connect(Scale, SIGNAL(textChanged(const QString &)),
173 this, SLOT(change_adaptor()));
174 connect(rotateOrderCB, SIGNAL(clicked()),
175 this, SLOT(change_adaptor()));
177 filename->setValidator(new PathValidator(true, filename));
178 setFocusProxy(filename);
180 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
181 scaleValidator->setBottom(0);
182 scaleValidator->setDecimals(256); //I guess that will do
183 Scale->setValidator(scaleValidator);
184 Height->setValidator(unsignedLengthAutoValidator(Height));
185 Width->setValidator(unsignedLengthAutoValidator(Width));
186 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
189 connect(clip, SIGNAL(stateChanged(int)),
190 this, SLOT(change_adaptor()));
191 connect(lbY, SIGNAL(textChanged(const QString&)),
192 this, SLOT(change_bb()));
193 connect(lbYunit, SIGNAL(activated(int)),
194 this, SLOT(change_bb()));
195 connect(rtY, SIGNAL(textChanged(const QString&)),
196 this, SLOT(change_bb()));
197 connect(rtYunit, SIGNAL(activated(int)),
198 this, SLOT(change_bb()));
199 connect(lbX, SIGNAL(textChanged(const QString&)),
200 this, SLOT(change_bb()));
201 connect(lbXunit, SIGNAL(activated(int)),
202 this, SLOT(change_bb()));
203 connect(rtX, SIGNAL(textChanged(const QString&)),
204 this, SLOT(change_bb()));
205 connect(rtXunit, SIGNAL(activated(int)),
206 this, SLOT(change_bb()));
207 connect(getPB, SIGNAL(clicked()),
208 this, SLOT(change_adaptor()));
210 lbX->setValidator(new QDoubleValidator(lbX));
211 lbY->setValidator(new QDoubleValidator(lbY));
212 rtX->setValidator(new QDoubleValidator(rtX));
213 rtY->setValidator(new QDoubleValidator(rtY));
216 connect(latexoptions, SIGNAL(textChanged(const QString&)),
217 this, SLOT(change_adaptor()));
218 connect(draftCB, SIGNAL(stateChanged(int)),
219 this, SLOT(change_adaptor()));
220 connect(unzipCB, SIGNAL(stateChanged(int)),
221 this, SLOT(change_adaptor()));
222 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
223 // the toggled(bool) signal is also trigged when we update the widgets
224 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
225 // using blockSignals() to keep from triggering that signal when we call
226 // setChecked(). Note, too, that clicked() would get called whenever it
227 // is clicked, even right clicked (I think), not just whenever it is
229 connect(subfigure, SIGNAL(toggled(bool)),
230 this, SLOT(change_adaptor()));
231 connect(subcaption, SIGNAL(textChanged(const QString&)),
232 this, SLOT(change_adaptor()));
233 connect(displayGB, SIGNAL(toggled(bool)),
234 this, SLOT(change_adaptor()));
235 connect(showCB, SIGNAL(currentIndexChanged(int)),
236 this, SLOT(change_adaptor()));
237 connect(displayscale, SIGNAL(textChanged(const QString&)),
238 this, SLOT(change_adaptor()));
239 displayscale->setValidator(new QIntValidator(displayscale));
241 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
243 bc().setApply(applyPB);
244 bc().setRestore(restorePB);
245 bc().setCancel(closePB);
247 bc().addReadOnly(latexoptions);
248 bc().addReadOnly(subfigure);
249 bc().addReadOnly(filenameL);
250 bc().addReadOnly(filename);
251 bc().addReadOnly(browsePB);
252 bc().addReadOnly(unzipCB);
253 bc().addReadOnly(bbFrame);
254 bc().addReadOnly(draftCB);
255 bc().addReadOnly(clip);
256 bc().addReadOnly(unzipCB);
257 bc().addReadOnly(displayGB);
258 bc().addReadOnly(sizeGB);
259 bc().addReadOnly(rotationGB);
260 bc().addReadOnly(latexoptions);
261 bc().addReadOnly(getPB);
262 bc().addReadOnly(rotateOrderCB);
264 // initialize the length validator
265 bc().addCheckedLineEdit(Scale, scaleCB);
266 bc().addCheckedLineEdit(Width, WidthCB);
267 bc().addCheckedLineEdit(Height, HeightCB);
268 bc().addCheckedLineEdit(displayscale, scaleLA);
269 bc().addCheckedLineEdit(angle, angleL);
270 bc().addCheckedLineEdit(lbX, xL);
271 bc().addCheckedLineEdit(lbY, yL);
272 bc().addCheckedLineEdit(rtX, xL_2);
273 bc().addCheckedLineEdit(rtY, yL_2);
274 bc().addCheckedLineEdit(filename, filenameL);
278 void GuiGraphics::change_adaptor()
284 void GuiGraphics::change_bb()
287 LYXERR(Debug::GRAPHICS) << "[bb_Changed set to true]\n";
292 void GuiGraphics::closeEvent(QCloseEvent * e)
295 GuiDialog::closeEvent(e);
299 void GuiGraphics::on_browsePB_clicked()
301 docstring const str = browse(qstring_to_ucs4(filename->text()));
303 filename->setText(toqstr(str));
304 embedCB->setCheckState(Qt::Unchecked);
310 void GuiGraphics::on_getPB_clicked()
316 void GuiGraphics::on_editPB_clicked()
322 void GuiGraphics::on_filename_textChanged(const QString & filename)
324 editPB->setDisabled(filename.isEmpty());
328 void GuiGraphics::setAutoText()
330 if (scaleCB->isChecked())
332 if (!Scale->isEnabled() && Scale->text() != "100")
333 Scale->setText(QString("auto"));
335 setAutoTextCB(WidthCB, Width, widthUnit);
336 setAutoTextCB(HeightCB, Height, heightUnit);
340 void GuiGraphics::on_scaleCB_toggled(bool setScale)
342 Scale->setEnabled(setScale);
344 Scale->setText("100");
345 Scale->setFocus(Qt::OtherFocusReason);
348 WidthCB->setDisabled(setScale);
349 WidthCB->blockSignals(true);
350 WidthCB->setChecked(false);
351 WidthCB->blockSignals(false);
352 Width->setEnabled(false);
353 widthUnit->setEnabled(false);
355 HeightCB->setDisabled(setScale);
356 HeightCB->blockSignals(true);
357 HeightCB->setChecked(false);
358 HeightCB->blockSignals(false);
359 Height->setEnabled(false);
360 heightUnit->setEnabled(false);
362 aspectratio->setDisabled(true);
363 aspectratio->setChecked(true);
365 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
366 HeightCB->isChecked() ||
367 scaleCB->isChecked()) &&
368 (angle->text() != "0"));
374 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
376 Width->setEnabled(setWidth);
377 widthUnit->setEnabled(setWidth);
379 Width->setFocus(Qt::OtherFocusReason);
381 bool const setHeight = HeightCB->isChecked();
382 aspectratio->setEnabled(setWidth && setHeight);
383 aspectratio->blockSignals(true);
384 aspectratio->setChecked(!(setWidth && setHeight));
385 aspectratio->blockSignals(false);
387 scaleCB->setEnabled(!setWidth && !setHeight);
388 //already will be unchecked, so don't need to do that
389 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
390 && scaleCB->isChecked()); //should be false, but let's check
391 rotateOrderCB->setEnabled((setWidth || setHeight ||
392 scaleCB->isChecked()) &&
393 (angle->text() != "0"));
399 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
401 Height->setEnabled(setHeight);
402 heightUnit->setEnabled(setHeight);
404 Height->setFocus(Qt::OtherFocusReason);
406 bool const setWidth = WidthCB->isChecked();
407 aspectratio->setEnabled(setWidth && setHeight);
408 aspectratio->blockSignals(true);
409 aspectratio->setChecked(!(setWidth && setHeight));
410 aspectratio->blockSignals(false);
412 scaleCB->setEnabled(!setWidth && !setHeight);
414 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
415 && scaleCB->isChecked()); //should be false
416 rotateOrderCB->setEnabled((setWidth || setHeight ||
417 scaleCB->isChecked()) &&
418 (angle->text() != "0"));
424 void GuiGraphics::on_angle_textChanged(const QString & filename)
426 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
427 HeightCB->isChecked() ||
428 scaleCB->isChecked()) &&
432 // returns the number of the string s in the vector v
433 static int getItemNo(const vector<string> & v, string const & s)
435 vector<string>::const_iterator cit =
436 find(v.begin(), v.end(), s);
437 return (cit != v.end()) ? int(cit - v.begin()) : 0;
441 void GuiGraphics::updateContents()
443 // clear and fill in the comboboxes
444 vector<string> const bb_units = frontend::getBBUnits();
449 for (vector<string>::const_iterator it = bb_units.begin();
450 it != bb_units.end(); ++it) {
451 lbXunit->addItem(toqstr(*it));
452 lbYunit->addItem(toqstr(*it));
453 rtXunit->addItem(toqstr(*it));
454 rtYunit->addItem(toqstr(*it));
457 InsetGraphicsParams & igp = params_;
459 // set the right default unit
460 Length::UNIT unitDefault = Length::CM;
461 switch (lyxrc.default_papersize) {
464 case PAPER_USEXECUTIVE:
465 unitDefault = Length::IN;
472 igp.filename.outputFilename(bufferFilepath());
473 filename->setText(toqstr(name));
474 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
476 // set the bounding box values
477 if (igp.bb.empty()) {
478 string const bb = readBB(igp.filename.absFilename());
479 // the values from the file always have the bigpoint-unit bp
480 lbX->setText(toqstr(token(bb, ' ', 0)));
481 lbY->setText(toqstr(token(bb, ' ', 1)));
482 rtX->setText(toqstr(token(bb, ' ', 2)));
483 rtY->setText(toqstr(token(bb, ' ', 3)));
484 lbXunit->setCurrentIndex(0);
485 lbYunit->setCurrentIndex(0);
486 rtXunit->setCurrentIndex(0);
487 rtYunit->setCurrentIndex(0);
490 // get the values from the inset
492 string const xl = token(igp.bb, ' ', 0);
493 string const yl = token(igp.bb, ' ', 1);
494 string const xr = token(igp.bb, ' ', 2);
495 string const yr = token(igp.bb, ' ', 3);
496 if (isValidLength(xl, &anyLength)) {
497 lbX->setText(toqstr(convert<string>(anyLength.value())));
498 string const unit(unit_name[anyLength.unit()]);
499 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
501 lbX->setText(toqstr(xl));
503 if (isValidLength(yl, &anyLength)) {
504 lbY->setText(toqstr(convert<string>(anyLength.value())));
505 string const unit(unit_name[anyLength.unit()]);
506 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
508 lbY->setText(toqstr(xl));
510 if (isValidLength(xr, &anyLength)) {
511 rtX->setText(toqstr(convert<string>(anyLength.value())));
512 string const unit(unit_name[anyLength.unit()]);
513 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
515 rtX->setText(toqstr(xl));
517 if (isValidLength(yr, &anyLength)) {
518 rtY->setText(toqstr(convert<string>(anyLength.value())));
519 string const unit(unit_name[anyLength.unit()]);
520 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
522 rtY->setText(toqstr(xl));
527 // Update the draft and clip mode
528 draftCB->setChecked(igp.draft);
529 clip->setChecked(igp.clip);
530 unzipCB->setChecked(igp.noUnzip);
532 // Update the subcaption check button and input field
533 subfigure->setChecked(igp.subcaption);
534 subcaption->setText(toqstr(igp.subcaptionText));
537 switch (igp.display) {
538 case graphics::DefaultDisplay: item = 0; break;
539 case graphics::MonochromeDisplay: item = 1; break;
540 case graphics::GrayscaleDisplay: item = 2; break;
541 case graphics::ColorDisplay: item = 3; break;
542 case graphics::NoDisplay: item = 0; break;
544 showCB->setCurrentIndex(item);
545 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
546 displayGB->setChecked(igp.display != graphics::NoDisplay);
548 // the output section (width/height)
550 Scale->setText(toqstr(igp.scale));
551 //igp.scale defaults to 100, so we treat it as empty
552 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
553 scaleCB->blockSignals(true);
554 scaleCB->setChecked(scaleChecked);
555 scaleCB->blockSignals(false);
556 Scale->setEnabled(scaleChecked);
558 lengthAutoToWidgets(Width, widthUnit, igp.width,
560 bool const widthChecked = !Width->text().isEmpty() &&
561 Width->text() != "auto";
562 WidthCB->blockSignals(true);
563 WidthCB->setChecked(widthChecked);
564 WidthCB->blockSignals(false);
565 Width->setEnabled(widthChecked);
566 widthUnit->setEnabled(widthChecked);
568 lengthAutoToWidgets(Height, heightUnit, igp.height,
570 bool const heightChecked = !Height->text().isEmpty()
571 && Height->text() != "auto";
572 HeightCB->blockSignals(true);
573 HeightCB->setChecked(heightChecked);
574 HeightCB->blockSignals(false);
575 Height->setEnabled(heightChecked);
576 heightUnit->setEnabled(heightChecked);
578 scaleCB->setEnabled(!widthChecked && !heightChecked);
579 WidthCB->setEnabled(!scaleChecked);
580 HeightCB->setEnabled(!scaleChecked);
581 aspectratio->setEnabled(widthChecked && heightChecked);
585 angle->setText(toqstr(igp.rotateAngle));
586 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
588 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
589 && igp.rotateAngle != "0");
593 vector<RotationOriginPair> origindata = getRotationOriginData();
594 vector<docstring> const origin_lang = getFirst(origindata);
595 origin_ltx = getSecond(origindata);
597 for (vector<docstring>::const_iterator it = origin_lang.begin();
598 it != origin_lang.end(); ++it)
599 origin->addItem(toqstr(*it));
601 if (!igp.rotateOrigin.empty())
602 origin->setCurrentIndex(
603 getItemNo(origin_ltx, igp.rotateOrigin));
605 origin->setCurrentIndex(0);
607 // disable edit button when no filename is present
608 editPB->setDisabled(filename->text().isEmpty());
611 latexoptions->setText(toqstr(igp.special));
615 void GuiGraphics::applyView()
617 InsetGraphicsParams & igp = params_;
619 igp.filename.set(internal_path(fromqstr(filename->text())),
621 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
627 string lbXs = fromqstr(lbX->text());
628 string lbYs = fromqstr(lbY->text());
629 string rtXs = fromqstr(rtX->text());
630 string rtYs = fromqstr(rtY->text());
632 convert<int>(lbXs) + convert<int>(lbYs) +
633 convert<int>(rtXs) + convert<int>(rtXs);
638 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
642 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
646 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
650 bb += (rtYs + fromqstr(rtYunit->currentText()));
655 igp.draft = draftCB->isChecked();
656 igp.clip = clip->isChecked();
657 igp.subcaption = subfigure->isChecked();
658 igp.subcaptionText = fromqstr(subcaption->text());
660 switch (showCB->currentIndex()) {
661 case 0: igp.display = graphics::DefaultDisplay; break;
662 case 1: igp.display = graphics::MonochromeDisplay; break;
663 case 2: igp.display = graphics::GrayscaleDisplay; break;
664 case 3: igp.display = graphics::ColorDisplay; break;
668 if (!displayGB->isChecked())
669 igp.display = graphics::NoDisplay;
671 //the graphics section
672 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
673 igp.scale = fromqstr(Scale->text());
674 igp.width = Length("0pt");
675 igp.height = Length("0pt");
676 igp.keepAspectRatio = false;
678 igp.scale = string();
679 igp.width = WidthCB->isChecked() ?
680 //Note that this works even if Width is "auto", since in
681 //that case we get "0pt".
682 Length(widgetsToLength(Width, widthUnit)):
684 igp.height = HeightCB->isChecked() ?
685 Length(widgetsToLength(Height, heightUnit)) :
687 igp.keepAspectRatio = aspectratio->isEnabled() &&
688 aspectratio->isChecked() &&
689 igp.width.value() > 0 && igp.height.value() > 0;
692 igp.noUnzip = unzipCB->isChecked();
693 igp.lyxscale = displayscale->text().toInt();
694 igp.rotateAngle = fromqstr(angle->text());
696 double rotAngle = convert<double>(igp.rotateAngle);
697 if (std::abs(rotAngle) > 360.0) {
698 rotAngle -= 360.0 * floor(rotAngle / 360.0);
699 igp.rotateAngle = convert<string>(rotAngle);
702 // save the latex name for the origin. If it is the default
703 // then origin_ltx returns ""
704 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
705 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
707 // more latex options
708 igp.special = fromqstr(latexoptions->text());
712 void GuiGraphics::getBB()
714 string const fn = fromqstr(filename->text());
716 string const bb = readBB(fn);
718 lbX->setText(toqstr(token(bb, ' ', 0)));
719 lbY->setText(toqstr(token(bb, ' ', 1)));
720 rtX->setText(toqstr(token(bb, ' ', 2)));
721 rtY->setText(toqstr(token(bb, ' ', 3)));
722 // the default units for the bb values when reading
724 lbXunit->setCurrentIndex(0);
725 lbYunit->setCurrentIndex(0);
726 rtXunit->setCurrentIndex(0);
727 rtYunit->setCurrentIndex(0);
734 bool GuiGraphics::isValid()
736 return !filename->text().isEmpty();
740 bool GuiGraphics::initialiseParams(string const & data)
742 InsetGraphicsMailer::string2params(data, buffer(), params_);
747 void GuiGraphics::clearParams()
749 params_ = InsetGraphicsParams();
753 void GuiGraphics::dispatchParams()
755 InsetGraphicsParams tmp_params(params_);
757 InsetGraphicsMailer::params2string(tmp_params, buffer());
758 dispatch(FuncRequest(getLfun(), lfun));
762 docstring const GuiGraphics::browse(docstring const & in_name) const
764 docstring const title = _("Select graphics file");
766 // Does user clipart directory exist?
767 string clipdir = addName(package().user_support().absFilename(), "clipart");
768 string const encoded_clipdir = FileName(clipdir).toFilesystemEncoding();
769 if (!(fs::exists(encoded_clipdir) && fs::is_directory(encoded_clipdir)))
770 // No - bail out to system clipart directory
771 clipdir = addName(package().system_support().absFilename(), "clipart");
772 pair<docstring, docstring> dir1(_("Clipart|#C#c"), from_utf8(clipdir));
773 pair<docstring, docstring> dir2(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
774 // Show the file browser dialog
775 return browseRelFile(in_name, from_utf8(bufferFilepath()),
776 title, FileFilterList(), false, dir1, dir2);
780 string const GuiGraphics::readBB(string const & file)
782 FileName const abs_file(makeAbsPath(file, bufferFilepath()));
784 // try to get it from the file, if possible. Zipped files are
785 // unzipped in the readBB_from_PSFile-Function
786 string const bb = readBB_from_PSFile(abs_file);
790 // we don't, so ask the Graphics Cache if it has loaded the file
794 graphics::Cache & gc = graphics::Cache::get();
795 if (gc.inCache(abs_file)) {
796 graphics::Image const * image = gc.item(abs_file)->image();
799 width = image->getWidth();
800 height = image->getHeight();
804 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
808 bool GuiGraphics::isFilenameValid(string const & fname) const
810 // It may be that the filename is relative.
811 FileName const name(makeAbsPath(fname, bufferFilepath()));
812 return isFileReadable(name);
816 void GuiGraphics::editGraphics()
818 dialog().applyView();
820 InsetGraphicsMailer::params2string(params_, buffer());
821 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
827 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
828 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
830 // These are the strings that are stored in the LyX file and which
831 // correspond to the LaTeX identifiers shown in the comments at the
833 char const * const rorigin_lyx_strs[] = {
834 // the LaTeX default is leftBaseline
836 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
837 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
838 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
840 // These are the strings, corresponding to the above, that the GUI should
841 // use. Note that they can/should be translated.
842 char const * const rorigin_gui_strs[] = {
844 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
845 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
846 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
848 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
853 vector<string> const getBBUnits()
855 return vector<string>(bb_units, bb_units + bb_size);
859 vector<RotationOriginPair> getRotationOriginData()
861 static vector<RotationOriginPair> data;
865 data.resize(rorigin_size);
866 for (size_type i = 0; i < rorigin_size; ++i) {
867 data[i] = make_pair(_(rorigin_gui_strs[i]),
868 rorigin_lyx_strs[i]);
875 Dialog * createGuiGraphics(LyXView & lv) { return new GuiGraphics(lv); }
878 } // namespace frontend
881 #include "GuiGraphics_moc.cpp"