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 "LengthCombo.h"
22 #include "qt_helpers.h"
23 #include "Validator.h"
25 #include "FuncRequest.h"
27 #include "graphics/GraphicsCache.h"
28 #include "graphics/GraphicsCacheItem.h"
29 #include "graphics/GraphicsImage.h"
31 #include "insets/InsetGraphicsParams.h"
33 #include "support/convert.h"
34 #include "support/debug.h"
35 #include "support/FileFilterList.h"
36 #include "support/filetools.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39 #include "support/os.h"
40 #include "support/Package.h"
41 #include "support/types.h"
43 #include <boost/bind.hpp>
48 #include <QPushButton>
56 using namespace lyx::support;
61 //FIXME setAutoTextCB should really take an argument, as indicated, that
62 //determines what text is to be written for "auto". But making
63 //that work involves more extensive revisions than we now want
64 //to make, since "auto" also appears in updateContents() (see
66 //The right way to do this, I think, would be to define a class
67 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
68 //the checkbox, line edit, and length combo together, and then made e.g.
69 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
70 //Perhaps even the validator could be exposed through it.
72 * sets a checkbox-line edit-length combo group, using "text" if the
73 * checkbox is unchecked and clearing the line edit if it previously
76 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
77 LengthCombo * lengthCombo/*, string text = "auto"*/)
79 if (!checkBox->isChecked())
80 lengthToWidgets(lineEdit, lengthCombo,
81 "auto", lengthCombo->currentLengthItem());
82 else if (lineEdit->text() == "auto")
83 lengthToWidgets(lineEdit, lengthCombo, string(),
84 lengthCombo->currentLengthItem());
88 vector<typename Pair::first_type> const
89 getFirst(vector<Pair> const & pr)
91 vector<typename Pair::first_type> tmp(pr.size());
92 transform(pr.begin(), pr.end(), tmp.begin(),
93 boost::bind(&Pair::first, _1));
99 vector<typename Pair::second_type> const
100 getSecond(vector<Pair> const & pr)
102 vector<typename Pair::second_type> tmp(pr.size());
103 transform(pr.begin(), pr.end(), tmp.begin(),
104 boost::bind(&Pair::second, _1));
108 /// The (tranlated) GUI string and it's LaTeX equivalent.
109 typedef pair<docstring, string> RotationOriginPair;
111 vector<RotationOriginPair> getRotationOriginData();
114 GuiGraphics::GuiGraphics(GuiView & lv)
115 : GuiDialog(lv, "graphics", qt_("Graphics"))
120 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
121 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
122 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
123 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
126 connect(filename, SIGNAL(textChanged(const QString &)),
127 this, SLOT(change_adaptor()));
128 connect(embedCB, SIGNAL(toggled(bool)),
129 this, SLOT(change_adaptor()));
130 connect(WidthCB, SIGNAL( clicked()),
131 this, SLOT(change_adaptor()));
132 connect(HeightCB, SIGNAL( clicked()),
133 this, SLOT(change_adaptor()));
134 connect(Width, SIGNAL(textChanged(const QString &)),
135 this, SLOT(change_adaptor()));
136 connect(Height, SIGNAL(textChanged(const QString &)),
137 this, SLOT(change_adaptor()));
138 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
139 this, SLOT(change_adaptor()));
140 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
141 this, SLOT(change_adaptor()));
142 connect(aspectratio, SIGNAL(stateChanged(int)),
143 this, SLOT(change_adaptor()));
144 connect(angle, SIGNAL(textChanged(const QString &)),
145 this, SLOT(change_adaptor()));
146 connect(origin, SIGNAL(activated(int)),
147 this, SLOT(change_adaptor()));
148 connect(scaleCB, SIGNAL(clicked()),
149 this, SLOT(change_adaptor()));
150 connect(Scale, SIGNAL(textChanged(const QString &)),
151 this, SLOT(change_adaptor()));
152 connect(rotateOrderCB, SIGNAL(clicked()),
153 this, SLOT(change_adaptor()));
155 filename->setValidator(new PathValidator(true, filename));
156 setFocusProxy(filename);
158 QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
159 scaleValidator->setBottom(0);
160 scaleValidator->setDecimals(256); //I guess that will do
161 Scale->setValidator(scaleValidator);
162 Height->setValidator(unsignedLengthAutoValidator(Height));
163 Width->setValidator(unsignedLengthAutoValidator(Width));
164 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
167 connect(clip, SIGNAL(stateChanged(int)),
168 this, SLOT(change_adaptor()));
169 connect(lbY, SIGNAL(textChanged(const QString&)),
170 this, SLOT(change_bb()));
171 connect(lbYunit, SIGNAL(activated(int)),
172 this, SLOT(change_bb()));
173 connect(rtY, SIGNAL(textChanged(const QString&)),
174 this, SLOT(change_bb()));
175 connect(rtYunit, SIGNAL(activated(int)),
176 this, SLOT(change_bb()));
177 connect(lbX, SIGNAL(textChanged(const QString&)),
178 this, SLOT(change_bb()));
179 connect(lbXunit, SIGNAL(activated(int)),
180 this, SLOT(change_bb()));
181 connect(rtX, SIGNAL(textChanged(const QString&)),
182 this, SLOT(change_bb()));
183 connect(rtXunit, SIGNAL(activated(int)),
184 this, SLOT(change_bb()));
185 connect(getPB, SIGNAL(clicked()),
186 this, SLOT(change_adaptor()));
188 lbX->setValidator(new QDoubleValidator(lbX));
189 lbY->setValidator(new QDoubleValidator(lbY));
190 rtX->setValidator(new QDoubleValidator(rtX));
191 rtY->setValidator(new QDoubleValidator(rtY));
194 connect(latexoptions, SIGNAL(textChanged(const QString&)),
195 this, SLOT(change_adaptor()));
196 connect(draftCB, SIGNAL(stateChanged(int)),
197 this, SLOT(change_adaptor()));
198 connect(unzipCB, SIGNAL(stateChanged(int)),
199 this, SLOT(change_adaptor()));
200 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
201 // the toggled(bool) signal is also trigged when we update the widgets
202 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
203 // using blockSignals() to keep from triggering that signal when we call
204 // setChecked(). Note, too, that clicked() would get called whenever it
205 // is clicked, even right clicked (I think), not just whenever it is
207 connect(displayGB, SIGNAL(toggled(bool)),
208 this, SLOT(change_adaptor()));
209 connect(showCB, SIGNAL(currentIndexChanged(int)),
210 this, SLOT(change_adaptor()));
211 connect(displayscale, SIGNAL(textChanged(const QString&)),
212 this, SLOT(change_adaptor()));
213 displayscale->setValidator(new QIntValidator(displayscale));
215 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
217 bc().setApply(applyPB);
218 bc().setRestore(restorePB);
219 bc().setCancel(closePB);
221 bc().addReadOnly(latexoptions);
222 bc().addReadOnly(filenameL);
223 bc().addReadOnly(filename);
224 bc().addReadOnly(browsePB);
225 bc().addReadOnly(unzipCB);
226 bc().addReadOnly(bbFrame);
227 bc().addReadOnly(draftCB);
228 bc().addReadOnly(clip);
229 bc().addReadOnly(unzipCB);
230 bc().addReadOnly(displayGB);
231 bc().addReadOnly(sizeGB);
232 bc().addReadOnly(rotationGB);
233 bc().addReadOnly(latexoptions);
234 bc().addReadOnly(getPB);
235 bc().addReadOnly(rotateOrderCB);
237 // initialize the length validator
238 bc().addCheckedLineEdit(Scale, scaleCB);
239 bc().addCheckedLineEdit(Width, WidthCB);
240 bc().addCheckedLineEdit(Height, HeightCB);
241 bc().addCheckedLineEdit(displayscale, scaleLA);
242 bc().addCheckedLineEdit(angle, angleL);
243 bc().addCheckedLineEdit(lbX, xL);
244 bc().addCheckedLineEdit(lbY, yL);
245 bc().addCheckedLineEdit(rtX, xL_2);
246 bc().addCheckedLineEdit(rtY, yL_2);
247 bc().addCheckedLineEdit(filename, filenameL);
251 void GuiGraphics::change_adaptor()
257 void GuiGraphics::change_bb()
260 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
265 void GuiGraphics::on_browsePB_clicked()
267 docstring const str = browse(qstring_to_ucs4(filename->text()));
269 filename->setText(toqstr(str));
275 void GuiGraphics::on_getPB_clicked()
281 void GuiGraphics::on_editPB_clicked()
287 void GuiGraphics::on_filename_textChanged(const QString & filename)
289 editPB->setDisabled(filename.isEmpty());
290 EmbeddedFile file = EmbeddedFile(fromqstr(filename), bufferFilepath());
294 void GuiGraphics::setAutoText()
296 if (scaleCB->isChecked())
298 if (!Scale->isEnabled() && Scale->text() != "100")
299 Scale->setText(QString("auto"));
301 setAutoTextCB(WidthCB, Width, widthUnit);
302 setAutoTextCB(HeightCB, Height, heightUnit);
306 void GuiGraphics::on_scaleCB_toggled(bool setScale)
308 Scale->setEnabled(setScale);
310 Scale->setText("100");
311 Scale->setFocus(Qt::OtherFocusReason);
314 WidthCB->setDisabled(setScale);
315 WidthCB->blockSignals(true);
316 WidthCB->setChecked(false);
317 WidthCB->blockSignals(false);
318 Width->setEnabled(false);
319 widthUnit->setEnabled(false);
321 HeightCB->setDisabled(setScale);
322 HeightCB->blockSignals(true);
323 HeightCB->setChecked(false);
324 HeightCB->blockSignals(false);
325 Height->setEnabled(false);
326 heightUnit->setEnabled(false);
328 aspectratio->setDisabled(true);
329 aspectratio->setChecked(true);
331 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
332 HeightCB->isChecked() ||
333 scaleCB->isChecked()) &&
334 (angle->text() != "0"));
340 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
342 Width->setEnabled(setWidth);
343 widthUnit->setEnabled(setWidth);
345 Width->setFocus(Qt::OtherFocusReason);
347 bool const setHeight = HeightCB->isChecked();
348 aspectratio->setEnabled(setWidth && setHeight);
349 aspectratio->blockSignals(true);
350 aspectratio->setChecked(!(setWidth && setHeight));
351 aspectratio->blockSignals(false);
353 scaleCB->setEnabled(!setWidth && !setHeight);
354 //already will be unchecked, so don't need to do that
355 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
356 && scaleCB->isChecked()); //should be false, but let's check
357 rotateOrderCB->setEnabled((setWidth || setHeight ||
358 scaleCB->isChecked()) &&
359 (angle->text() != "0"));
365 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
367 Height->setEnabled(setHeight);
368 heightUnit->setEnabled(setHeight);
370 Height->setFocus(Qt::OtherFocusReason);
372 bool const setWidth = WidthCB->isChecked();
373 aspectratio->setEnabled(setWidth && setHeight);
374 aspectratio->blockSignals(true);
375 aspectratio->setChecked(!(setWidth && setHeight));
376 aspectratio->blockSignals(false);
378 scaleCB->setEnabled(!setWidth && !setHeight);
380 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
381 && scaleCB->isChecked()); //should be false
382 rotateOrderCB->setEnabled((setWidth || setHeight ||
383 scaleCB->isChecked()) &&
384 (angle->text() != "0"));
390 void GuiGraphics::on_angle_textChanged(const QString & filename)
392 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
393 HeightCB->isChecked() ||
394 scaleCB->isChecked()) &&
398 // returns the number of the string s in the vector v
399 static int getItemNo(const vector<string> & v, string const & s)
401 vector<string>::const_iterator cit =
402 find(v.begin(), v.end(), s);
403 return (cit != v.end()) ? int(cit - v.begin()) : 0;
407 void GuiGraphics::updateContents()
409 // clear and fill in the comboboxes
410 vector<string> const bb_units = frontend::getBBUnits();
415 for (vector<string>::const_iterator it = bb_units.begin();
416 it != bb_units.end(); ++it) {
417 lbXunit->addItem(toqstr(*it));
418 lbYunit->addItem(toqstr(*it));
419 rtXunit->addItem(toqstr(*it));
420 rtYunit->addItem(toqstr(*it));
423 InsetGraphicsParams & igp = params_;
425 // set the right default unit
426 Length::UNIT unitDefault = Length::CM;
427 switch (lyxrc.default_papersize) {
430 case PAPER_USEXECUTIVE:
431 unitDefault = Length::IN;
438 igp.filename.outputFilename(bufferFilepath());
439 filename->setText(toqstr(name));
440 embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
442 // set the bounding box values
443 if (igp.bb.empty()) {
444 string const bb = readBB(igp.filename.absFilename());
445 // the values from the file always have the bigpoint-unit bp
446 lbX->setText(toqstr(token(bb, ' ', 0)));
447 lbY->setText(toqstr(token(bb, ' ', 1)));
448 rtX->setText(toqstr(token(bb, ' ', 2)));
449 rtY->setText(toqstr(token(bb, ' ', 3)));
450 lbXunit->setCurrentIndex(0);
451 lbYunit->setCurrentIndex(0);
452 rtXunit->setCurrentIndex(0);
453 rtYunit->setCurrentIndex(0);
456 // get the values from the inset
458 string const xl = token(igp.bb, ' ', 0);
459 string const yl = token(igp.bb, ' ', 1);
460 string const xr = token(igp.bb, ' ', 2);
461 string const yr = token(igp.bb, ' ', 3);
462 if (isValidLength(xl, &anyLength)) {
463 lbX->setText(toqstr(convert<string>(anyLength.value())));
464 string const unit(unit_name[anyLength.unit()]);
465 lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
467 lbX->setText(toqstr(xl));
469 if (isValidLength(yl, &anyLength)) {
470 lbY->setText(toqstr(convert<string>(anyLength.value())));
471 string const unit(unit_name[anyLength.unit()]);
472 lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
474 lbY->setText(toqstr(xl));
476 if (isValidLength(xr, &anyLength)) {
477 rtX->setText(toqstr(convert<string>(anyLength.value())));
478 string const unit(unit_name[anyLength.unit()]);
479 rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
481 rtX->setText(toqstr(xl));
483 if (isValidLength(yr, &anyLength)) {
484 rtY->setText(toqstr(convert<string>(anyLength.value())));
485 string const unit(unit_name[anyLength.unit()]);
486 rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
488 rtY->setText(toqstr(xl));
493 // Update the draft and clip mode
494 draftCB->setChecked(igp.draft);
495 clip->setChecked(igp.clip);
496 unzipCB->setChecked(igp.noUnzip);
499 switch (igp.display) {
500 case graphics::DefaultDisplay: item = 0; break;
501 case graphics::MonochromeDisplay: item = 1; break;
502 case graphics::GrayscaleDisplay: item = 2; break;
503 case graphics::ColorDisplay: item = 3; break;
504 case graphics::NoDisplay: item = 0; break;
506 showCB->setCurrentIndex(item);
507 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
508 displayGB->setChecked(igp.display != graphics::NoDisplay);
510 // the output section (width/height)
512 Scale->setText(toqstr(igp.scale));
513 //igp.scale defaults to 100, so we treat it as empty
514 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
515 scaleCB->blockSignals(true);
516 scaleCB->setChecked(scaleChecked);
517 scaleCB->blockSignals(false);
518 Scale->setEnabled(scaleChecked);
520 lengthAutoToWidgets(Width, widthUnit, igp.width,
522 bool const widthChecked = !Width->text().isEmpty() &&
523 Width->text() != "auto";
524 WidthCB->blockSignals(true);
525 WidthCB->setChecked(widthChecked);
526 WidthCB->blockSignals(false);
527 Width->setEnabled(widthChecked);
528 widthUnit->setEnabled(widthChecked);
530 lengthAutoToWidgets(Height, heightUnit, igp.height,
532 bool const heightChecked = !Height->text().isEmpty()
533 && Height->text() != "auto";
534 HeightCB->blockSignals(true);
535 HeightCB->setChecked(heightChecked);
536 HeightCB->blockSignals(false);
537 Height->setEnabled(heightChecked);
538 heightUnit->setEnabled(heightChecked);
540 scaleCB->setEnabled(!widthChecked && !heightChecked);
541 WidthCB->setEnabled(!scaleChecked);
542 HeightCB->setEnabled(!scaleChecked);
543 aspectratio->setEnabled(widthChecked && heightChecked);
547 angle->setText(toqstr(igp.rotateAngle));
548 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
550 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
551 && igp.rotateAngle != "0");
555 vector<RotationOriginPair> origindata = getRotationOriginData();
556 vector<docstring> const origin_lang = getFirst(origindata);
557 origin_ltx = getSecond(origindata);
559 for (vector<docstring>::const_iterator it = origin_lang.begin();
560 it != origin_lang.end(); ++it)
561 origin->addItem(toqstr(*it));
563 if (!igp.rotateOrigin.empty())
564 origin->setCurrentIndex(
565 getItemNo(origin_ltx, igp.rotateOrigin));
567 origin->setCurrentIndex(0);
569 // disable edit button when no filename is present
570 editPB->setDisabled(filename->text().isEmpty());
573 latexoptions->setText(toqstr(igp.special));
577 void GuiGraphics::applyView()
579 InsetGraphicsParams & igp = params_;
581 igp.filename.set(fromqstr(filename->text()), bufferFilepath());
582 igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
588 string lbXs = fromqstr(lbX->text());
589 string lbYs = fromqstr(lbY->text());
590 string rtXs = fromqstr(rtX->text());
591 string rtYs = fromqstr(rtY->text());
593 convert<int>(lbXs) + convert<int>(lbYs) +
594 convert<int>(rtXs) + convert<int>(rtXs);
599 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
603 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
607 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
611 bb += (rtYs + fromqstr(rtYunit->currentText()));
616 igp.draft = draftCB->isChecked();
617 igp.clip = clip->isChecked();
619 switch (showCB->currentIndex()) {
620 case 0: igp.display = graphics::DefaultDisplay; break;
621 case 1: igp.display = graphics::MonochromeDisplay; break;
622 case 2: igp.display = graphics::GrayscaleDisplay; break;
623 case 3: igp.display = graphics::ColorDisplay; break;
627 if (!displayGB->isChecked())
628 igp.display = graphics::NoDisplay;
630 //the graphics section
631 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
632 igp.scale = fromqstr(Scale->text());
633 igp.width = Length("0pt");
634 igp.height = Length("0pt");
635 igp.keepAspectRatio = false;
637 igp.scale = string();
638 igp.width = WidthCB->isChecked() ?
639 //Note that this works even if Width is "auto", since in
640 //that case we get "0pt".
641 Length(widgetsToLength(Width, widthUnit)):
643 igp.height = HeightCB->isChecked() ?
644 Length(widgetsToLength(Height, heightUnit)) :
646 igp.keepAspectRatio = aspectratio->isEnabled() &&
647 aspectratio->isChecked() &&
648 igp.width.value() > 0 && igp.height.value() > 0;
651 igp.noUnzip = unzipCB->isChecked();
652 igp.lyxscale = displayscale->text().toInt();
653 igp.rotateAngle = fromqstr(angle->text());
655 double rotAngle = convert<double>(igp.rotateAngle);
656 if (abs(rotAngle) > 360.0) {
657 rotAngle -= 360.0 * floor(rotAngle / 360.0);
658 igp.rotateAngle = convert<string>(rotAngle);
661 // save the latex name for the origin. If it is the default
662 // then origin_ltx returns ""
663 igp.rotateOrigin = origin_ltx[origin->currentIndex()];
664 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
666 // more latex options
667 igp.special = fromqstr(latexoptions->text());
671 void GuiGraphics::getBB()
673 string const fn = fromqstr(filename->text());
676 string const bb = readBB(fn);
680 lbX->setText(toqstr(token(bb, ' ', 0)));
681 lbY->setText(toqstr(token(bb, ' ', 1)));
682 rtX->setText(toqstr(token(bb, ' ', 2)));
683 rtY->setText(toqstr(token(bb, ' ', 3)));
684 // the default units for the bb values when reading
686 lbXunit->setCurrentIndex(0);
687 lbYunit->setCurrentIndex(0);
688 rtXunit->setCurrentIndex(0);
689 rtYunit->setCurrentIndex(0);
693 bool GuiGraphics::isValid()
695 return !filename->text().isEmpty();
699 bool GuiGraphics::initialiseParams(string const & data)
701 InsetGraphicsMailer::string2params(data, buffer(), params_);
706 void GuiGraphics::clearParams()
708 params_ = InsetGraphicsParams();
712 void GuiGraphics::dispatchParams()
714 InsetGraphicsParams tmp_params(params_);
716 InsetGraphicsMailer::params2string(tmp_params, buffer());
717 dispatch(FuncRequest(getLfun(), lfun));
721 docstring const GuiGraphics::browse(docstring const & in_name) const
723 docstring const title = _("Select graphics file");
725 // Does user clipart directory exist?
726 string clipdir = addName(package().user_support().absFilename(), "clipart");
727 FileName clip(clipdir);
729 // bail out to system clipart directory
730 if (!(clip.exists() && clip.isDirectory()))
731 clipdir = addName(package().system_support().absFilename(), "clipart");
733 return browseRelFile(in_name, from_utf8(bufferFilepath()),
734 title, FileFilterList(), false,
735 _("Clipart|#C#c"), from_utf8(clipdir),
736 _("Documents|#o#O"), from_utf8(lyxrc.document_path));
740 string const GuiGraphics::readBB(string const & file)
742 FileName const abs_file = makeAbsPath(file, bufferFilepath());
744 // try to get it from the file, if possible. Zipped files are
745 // unzipped in the readBB_from_PSFile-Function
746 string const bb = readBB_from_PSFile(abs_file);
750 // we don't, so ask the Graphics Cache if it has loaded the file
754 graphics::Cache & gc = graphics::Cache::get();
755 if (gc.inCache(abs_file)) {
756 graphics::Image const * image = gc.item(abs_file)->image();
759 width = image->width();
760 height = image->height();
764 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
768 bool GuiGraphics::isFilenameValid(string const & fname) const
770 // It may be that the filename is relative.
771 return makeAbsPath(fname, bufferFilepath()).isReadableFile();
775 void GuiGraphics::editGraphics()
779 InsetGraphicsMailer::params2string(params_, buffer());
780 dispatch(FuncRequest(LFUN_GRAPHICS_EDIT, lfun));
786 char const * const bb_units[] = { "bp", "cm", "mm", "in" };
787 size_t const bb_size = sizeof(bb_units) / sizeof(char *);
789 // These are the strings that are stored in the LyX file and which
790 // correspond to the LaTeX identifiers shown in the comments at the
792 char const * const rorigin_lyx_strs[] = {
793 // the LaTeX default is leftBaseline
795 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
796 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
797 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
799 // These are the strings, corresponding to the above, that the GUI should
800 // use. Note that they can/should be translated.
801 char const * const rorigin_gui_strs[] = {
803 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
804 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
805 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
807 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
812 vector<string> const getBBUnits()
814 return vector<string>(bb_units, bb_units + bb_size);
818 vector<RotationOriginPair> getRotationOriginData()
820 static vector<RotationOriginPair> data;
824 data.resize(rorigin_size);
825 for (size_type i = 0; i < rorigin_size; ++i) {
826 data[i] = make_pair(_(rorigin_gui_strs[i]),
827 rorigin_lyx_strs[i]);
834 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
837 } // namespace frontend
840 #include "GuiGraphics_moc.cpp"