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"
18 #include "frontends/alert.h"
19 #include "qt_helpers.h"
20 #include "Validator.h"
23 #include "FuncRequest.h"
24 #include "LengthCombo.h"
28 #include "graphics/GraphicsCache.h"
29 #include "graphics/GraphicsCacheItem.h"
30 #include "graphics/GraphicsImage.h"
32 #include "insets/InsetGraphics.h"
34 #include "support/convert.h"
35 #include "support/debug.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"
46 #include <QPushButton>
53 using namespace lyx::support;
57 // These are the strings that are stored in the LyX file and which
58 // correspond to the LaTeX identifiers shown in the comments at the
60 char const * const rorigin_lyx_strs[] = {
61 // the LaTeX default is leftBaseline
63 "leftTop", "leftBottom", "leftBaseline", // lt lb lB
64 "center", "centerTop", "centerBottom", "centerBaseline", // c ct cb cB
65 "rightTop", "rightBottom", "rightBaseline" }; // rt rb rB
67 // These are the strings, corresponding to the above, that the GUI should
68 // use. Note that they can/should be translated.
69 char const * const rorigin_gui_strs[] = {
71 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
72 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
73 N_("Top right"), N_("Bottom right"), N_("Baseline right") };
75 size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *);
77 static string autostr = N_("automatically");
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 paramsToDialog().
89 //The right way to do this, I think, would be to define a class
90 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
91 //the checkbox, line edit, and length combo together, and then made e.g.
92 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
93 //Perhaps even the validator could be exposed through it.
95 * sets a checkbox-line edit-length combo group, using "text" if the
96 * checkbox is unchecked and clearing the line edit if it previously
99 static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
100 LengthCombo * lengthCombo/*, string text = "auto"*/)
102 if (!checkBox->isChecked())
103 lengthToWidgets(lineEdit, lengthCombo,
104 _(autostr), lengthCombo->currentLengthItem());
105 else if (lineEdit->text() == qt_(autostr))
106 lengthToWidgets(lineEdit, lengthCombo, string(),
107 lengthCombo->currentLengthItem());
111 GuiGraphics::GuiGraphics(GuiView & lv)
112 : GuiDialog(lv, "graphics", qt_("Graphics"))
117 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
118 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
119 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
120 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
123 connect(filename, SIGNAL(textChanged(const QString &)),
124 this, SLOT(change_adaptor()));
125 connect(WidthCB, SIGNAL(clicked()),
126 this, SLOT(change_adaptor()));
127 connect(HeightCB, SIGNAL(clicked()),
128 this, SLOT(change_adaptor()));
129 connect(Width, SIGNAL(textChanged(const QString &)),
130 this, SLOT(change_adaptor()));
131 connect(Height, SIGNAL(textChanged(const QString &)),
132 this, SLOT(change_adaptor()));
133 connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
134 this, SLOT(change_adaptor()));
135 connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
136 this, SLOT(change_adaptor()));
137 connect(aspectratio, SIGNAL(stateChanged(int)),
138 this, SLOT(change_adaptor()));
139 connect(angle, SIGNAL(textChanged(const QString &)),
140 this, SLOT(change_adaptor()));
141 connect(origin, SIGNAL(activated(int)),
142 this, SLOT(change_adaptor()));
143 connect(scaleCB, SIGNAL(clicked()),
144 this, SLOT(change_adaptor()));
145 connect(Scale, SIGNAL(textChanged(const QString &)),
146 this, SLOT(change_adaptor()));
147 connect(rotateOrderCB, SIGNAL(clicked()),
148 this, SLOT(change_adaptor()));
150 filename->setValidator(new PathValidator(true, filename));
151 setFocusProxy(filename);
153 QDoubleValidator * scaleValidator =
154 new DoubleAutoValidator(Scale, qt_(autostr));
155 scaleValidator->setBottom(0);
156 scaleValidator->setDecimals(256); //I guess that will do
157 Scale->setValidator(scaleValidator);
158 Height->setValidator(unsignedLengthAutoValidator(Height, qt_(autostr)));
159 Width->setValidator(unsignedLengthAutoValidator(Width, qt_(autostr)));
160 angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
163 connect(clip, SIGNAL(stateChanged(int)),
164 this, SLOT(change_adaptor()));
165 connect(lbY, SIGNAL(textChanged(const QString&)),
166 this, SLOT(changeBB()));
167 connect(lbYunit, SIGNAL(activated(int)),
168 this, SLOT(changeBB()));
169 connect(rtY, SIGNAL(textChanged(const QString&)),
170 this, SLOT(changeBB()));
171 connect(rtYunit, SIGNAL(activated(int)),
172 this, SLOT(changeBB()));
173 connect(lbX, SIGNAL(textChanged(const QString&)),
174 this, SLOT(changeBB()));
175 connect(lbXunit, SIGNAL(activated(int)),
176 this, SLOT(changeBB()));
177 connect(rtX, SIGNAL(textChanged(const QString&)),
178 this, SLOT(changeBB()));
179 connect(rtXunit, SIGNAL(activated(int)),
180 this, SLOT(changeBB()));
181 connect(getPB, SIGNAL(clicked()),
182 this, SLOT(change_adaptor()));
184 lbX->setValidator(new QDoubleValidator(lbX));
185 lbY->setValidator(new QDoubleValidator(lbY));
186 rtX->setValidator(new QDoubleValidator(rtX));
187 rtY->setValidator(new QDoubleValidator(rtY));
190 connect(latexoptions, SIGNAL(textChanged(const QString&)),
191 this, SLOT(change_adaptor()));
192 connect(draftCB, SIGNAL(stateChanged(int)),
193 this, SLOT(change_adaptor()));
194 connect(unzipCB, SIGNAL(stateChanged(int)),
195 this, SLOT(change_adaptor()));
196 // FIXME: we should connect to clicked() when we move to Qt 4.2 because
197 // the toggled(bool) signal is also trigged when we update the widgets
198 // (rgh-4/07) this isn't as much or a problem as it was, because we're now
199 // using blockSignals() to keep from triggering that signal when we call
200 // setChecked(). Note, too, that clicked() would get called whenever it
201 // is clicked, even right clicked (I think), not just whenever it is
203 connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
204 connect(displayscale, SIGNAL(textChanged(const QString&)),
205 this, SLOT(change_adaptor()));
206 connect(groupCO, SIGNAL(currentIndexChanged(int)),
207 this, SLOT(changeGroup(int)));
209 displayscale->setValidator(new QIntValidator(displayscale));
211 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
213 bc().setApply(applyPB);
214 bc().setRestore(restorePB);
215 bc().setCancel(closePB);
217 bc().addReadOnly(latexoptions);
218 bc().addReadOnly(filenameL);
219 bc().addReadOnly(filename);
220 bc().addReadOnly(browsePB);
221 bc().addReadOnly(unzipCB);
222 bc().addReadOnly(bbFrame);
223 bc().addReadOnly(draftCB);
224 bc().addReadOnly(clip);
225 bc().addReadOnly(unzipCB);
226 bc().addReadOnly(displayGB);
227 bc().addReadOnly(sizeGB);
228 bc().addReadOnly(rotationGB);
229 bc().addReadOnly(latexoptions);
230 bc().addReadOnly(getPB);
231 bc().addReadOnly(rotateOrderCB);
233 // initialize the length validator
234 bc().addCheckedLineEdit(Scale, scaleCB);
235 bc().addCheckedLineEdit(Width, WidthCB);
236 bc().addCheckedLineEdit(Height, HeightCB);
237 bc().addCheckedLineEdit(displayscale, scaleLA);
238 bc().addCheckedLineEdit(angle, angleL);
239 bc().addCheckedLineEdit(lbX, xL);
240 bc().addCheckedLineEdit(lbY, yL);
241 bc().addCheckedLineEdit(rtX, xL_2);
242 bc().addCheckedLineEdit(rtY, yL_2);
243 bc().addCheckedLineEdit(filename, filenameL);
247 void GuiGraphics::change_adaptor()
253 void GuiGraphics::changeGroup(int /* index */)
255 QString const new_group = groupCO->itemData(
256 groupCO->currentIndex()).toString();
258 // check if the old group consisted only of this member
259 if (current_group_ != fromqstr(new_group)
260 && graphics::countGroupMembers(buffer(), current_group_) == 1) {
261 if (!new_group.isEmpty()) {
262 if (Alert::prompt(_("Dissolve previous group?"),
263 bformat(_("If you assign this graphic to group '%2$s',\n"
264 "the previously assigned group '%1$s' will be dissolved,\n"
265 "because this graphic was its only member.\n"
266 "How do you want to proceed?"),
267 from_utf8(current_group_), qstring_to_ucs4(new_group)),
269 bformat(_("Stick with group '%1$s'"),
270 from_utf8(current_group_)),
271 bformat(_("Assign to group '%1$s' anyway"),
272 qstring_to_ucs4(new_group))) == 0) {
273 groupCO->setCurrentIndex(
274 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
278 if (Alert::prompt(_("Dissolve previous group?"),
279 bformat(_("If you sign off this graphic from group '%1$s',\n"
280 "the group will be dissolved,\n"
281 "because this graphic was its only member.\n"
282 "How do you want to proceed?"),
283 from_utf8(current_group_)),
285 bformat(_("Stick with group '%1$s'"),
286 from_utf8(current_group_)),
287 bformat(_("Sign off from group '%1$s'"),
288 from_utf8(current_group_))) == 0) {
289 groupCO->setCurrentIndex(
290 groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
296 if (new_group.isEmpty()) {
301 string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
303 // group does not exist yet
308 // filename might have been changed
309 QString current_filename = filename->text();
311 // group exists: load params into the dialog
312 groupCO->blockSignals(true);
313 InsetGraphics::string2params(grp, buffer(), params_);
314 paramsToDialog(params_);
315 groupCO->blockSignals(false);
318 filename->setText(current_filename);
324 void GuiGraphics::on_newGroupPB_clicked()
327 if (!Alert::askForText(newgroup, _("Enter unique group name:")))
329 if (newgroup.empty())
331 if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
332 Alert::warning(_("Group already defined!"),
333 bformat(_("A graphics group with the name '%1$s' already exists."),
337 groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
338 groupCO->setCurrentIndex(
339 groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
343 void GuiGraphics::changeBB()
346 LYXERR(Debug::GRAPHICS, "[bb_Changed set to true]");
351 void GuiGraphics::on_browsePB_clicked()
353 QString const str = browse(filename->text());
354 if (!str.isEmpty()) {
355 filename->setText(str);
361 void GuiGraphics::on_getPB_clicked()
367 void GuiGraphics::setAutoText()
369 if (scaleCB->isChecked())
371 if (!Scale->isEnabled() && Scale->text() != "100")
372 Scale->setText(qt_(autostr));
374 setAutoTextCB(WidthCB, Width, widthUnit);
375 setAutoTextCB(HeightCB, Height, heightUnit);
379 void GuiGraphics::on_scaleCB_toggled(bool setScale)
381 Scale->setEnabled(setScale);
383 Scale->setText("100");
384 Scale->setFocus(Qt::OtherFocusReason);
387 WidthCB->setDisabled(setScale);
388 WidthCB->blockSignals(true);
389 WidthCB->setChecked(false);
390 WidthCB->blockSignals(false);
391 Width->setEnabled(false);
392 widthUnit->setEnabled(false);
394 HeightCB->setDisabled(setScale);
395 HeightCB->blockSignals(true);
396 HeightCB->setChecked(false);
397 HeightCB->blockSignals(false);
398 Height->setEnabled(false);
399 heightUnit->setEnabled(false);
401 aspectratio->setDisabled(true);
402 aspectratio->setChecked(true);
404 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
405 HeightCB->isChecked() ||
406 scaleCB->isChecked()) &&
407 (angle->text() != "0"));
413 void GuiGraphics::on_WidthCB_toggled(bool setWidth)
415 Width->setEnabled(setWidth);
416 widthUnit->setEnabled(setWidth);
418 Width->setFocus(Qt::OtherFocusReason);
420 bool const setHeight = HeightCB->isChecked();
421 aspectratio->setEnabled(setWidth && setHeight);
422 aspectratio->blockSignals(true);
423 aspectratio->setChecked(!(setWidth && setHeight));
424 aspectratio->blockSignals(false);
426 scaleCB->setEnabled(!setWidth && !setHeight);
427 //already will be unchecked, so don't need to do that
428 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
429 && scaleCB->isChecked()); //should be false, but let's check
430 rotateOrderCB->setEnabled((setWidth || setHeight ||
431 scaleCB->isChecked()) &&
432 (angle->text() != "0"));
438 void GuiGraphics::on_HeightCB_toggled(bool setHeight)
440 Height->setEnabled(setHeight);
441 heightUnit->setEnabled(setHeight);
443 Height->setFocus(Qt::OtherFocusReason);
445 bool const setWidth = WidthCB->isChecked();
446 aspectratio->setEnabled(setWidth && setHeight);
447 aspectratio->blockSignals(true);
448 aspectratio->setChecked(!(setWidth && setHeight));
449 aspectratio->blockSignals(false);
451 scaleCB->setEnabled(!setWidth && !setHeight);
453 Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
454 && scaleCB->isChecked()); //should be false
455 rotateOrderCB->setEnabled((setWidth || setHeight ||
456 scaleCB->isChecked()) &&
457 (angle->text() != "0"));
463 void GuiGraphics::on_angle_textChanged(const QString & filename)
465 rotateOrderCB->setEnabled((WidthCB->isChecked() ||
466 HeightCB->isChecked() ||
467 scaleCB->isChecked()) &&
472 void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
474 static char const * const bb_units[] = { "bp", "cm", "mm", "in" };
475 static char const * const bb_units_gui[] = { N_("bp"), N_("cm"), N_("mm"), N_("in[[unit of measure]]") };
476 size_t const bb_size = sizeof(bb_units) / sizeof(bb_units[0]);
483 for (size_t i = 0; i < bb_size; i++) {
484 lbXunit->addItem(qt_(bb_units_gui[i]),
485 toqstr(bb_units[i]));
486 lbYunit->addItem(qt_(bb_units_gui[i]),
487 toqstr(bb_units[i]));
488 rtXunit->addItem(qt_(bb_units_gui[i]),
489 toqstr(bb_units[i]));
490 rtYunit->addItem(qt_(bb_units_gui[i]),
491 toqstr(bb_units[i]));
494 // set the right default unit
495 Length::UNIT const defaultUnit = Length::defaultUnit();
497 //lyxerr << bufferFilePath();
499 igp.filename.outputFileName(fromqstr(bufferFilePath()));
500 filename->setText(toqstr(name));
502 // set the bounding box values
503 if (igp.bb.empty()) {
504 string const bb = readBoundingBox(igp.filename.absFileName());
505 // the values from the file always have the bigpoint-unit bp
506 doubleToWidget(lbX, token(bb, ' ', 0));
507 doubleToWidget(lbY, token(bb, ' ', 1));
508 doubleToWidget(rtX, token(bb, ' ', 2));
509 doubleToWidget(rtY, token(bb, ' ', 3));
510 lbXunit->setCurrentIndex(0);
511 lbYunit->setCurrentIndex(0);
512 rtXunit->setCurrentIndex(0);
513 rtYunit->setCurrentIndex(0);
516 // get the values from the inset
518 string const xl = token(igp.bb, ' ', 0);
519 string const yl = token(igp.bb, ' ', 1);
520 string const xr = token(igp.bb, ' ', 2);
521 string const yr = token(igp.bb, ' ', 3);
522 if (isValidLength(xl, &anyLength)) {
523 doubleToWidget(lbX, anyLength.value());
524 string const unit = unit_name[anyLength.unit()];
525 lbXunit->setCurrentIndex(lbXunit->findData(toqstr(unit)));
527 lbX->setText(toqstr(xl));
529 if (isValidLength(yl, &anyLength)) {
530 doubleToWidget(lbY, anyLength.value());
531 string const unit = unit_name[anyLength.unit()];
532 lbYunit->setCurrentIndex(lbYunit->findData(toqstr(unit)));
534 lbY->setText(toqstr(xl));
536 if (isValidLength(xr, &anyLength)) {
537 doubleToWidget(rtX, anyLength.value());
538 string const unit = unit_name[anyLength.unit()];
539 rtXunit->setCurrentIndex(rtXunit->findData(toqstr(unit)));
541 rtX->setText(toqstr(xl));
543 if (isValidLength(yr, &anyLength)) {
544 doubleToWidget(rtY, anyLength.value());
545 string const unit = unit_name[anyLength.unit()];
546 rtYunit->setCurrentIndex(rtYunit->findData(toqstr(unit)));
548 rtY->setText(toqstr(xl));
553 // Update the draft and clip mode
554 draftCB->setChecked(igp.draft);
555 clip->setChecked(igp.clip);
556 unzipCB->setChecked(igp.noUnzip);
557 displayGB->setChecked(igp.display);
558 displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
560 // the output section (width/height)
562 doubleToWidget(Scale, igp.scale);
563 //igp.scale defaults to 100, so we treat it as empty
564 bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
565 scaleCB->blockSignals(true);
566 scaleCB->setChecked(scaleChecked);
567 scaleCB->blockSignals(false);
568 Scale->setEnabled(scaleChecked);
569 displayGB->setEnabled(lyxrc.display_graphics);
572 graphics::getGraphicsGroups(buffer(), grp);
573 set<string>::const_iterator it = grp.begin();
574 set<string>::const_iterator end = grp.end();
575 groupCO->blockSignals(true);
577 for (; it != end; it++)
578 groupCO->addItem(toqstr(*it), toqstr(*it));
579 groupCO->insertItem(0, qt_("None"), QString());
580 if (igp.groupId.empty())
581 groupCO->setCurrentIndex(0);
583 groupCO->setCurrentIndex(
584 groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
585 groupCO->blockSignals(false);
587 if (igp.width.value() == 0)
588 lengthToWidgets(Width, widthUnit, _(autostr), defaultUnit);
590 lengthToWidgets(Width, widthUnit, igp.width, defaultUnit);
592 bool const widthChecked = !Width->text().isEmpty() &&
593 Width->text() != qt_(autostr);
594 WidthCB->blockSignals(true);
595 WidthCB->setChecked(widthChecked);
596 WidthCB->blockSignals(false);
597 Width->setEnabled(widthChecked);
598 widthUnit->setEnabled(widthChecked);
600 if (igp.height.value() == 0)
601 lengthToWidgets(Height, heightUnit, _(autostr), defaultUnit);
603 lengthToWidgets(Height, heightUnit, igp.height, defaultUnit);
605 bool const heightChecked = !Height->text().isEmpty()
606 && Height->text() != qt_(autostr);
607 HeightCB->blockSignals(true);
608 HeightCB->setChecked(heightChecked);
609 HeightCB->blockSignals(false);
610 Height->setEnabled(heightChecked);
611 heightUnit->setEnabled(heightChecked);
613 scaleCB->setEnabled(!widthChecked && !heightChecked);
614 WidthCB->setEnabled(!scaleChecked);
615 HeightCB->setEnabled(!scaleChecked);
616 aspectratio->setEnabled(widthChecked && heightChecked);
620 doubleToWidget(angle, igp.rotateAngle);
621 rotateOrderCB->setChecked(igp.scaleBeforeRotation);
623 rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
624 && igp.rotateAngle != "0");
628 for (size_t i = 0; i < rorigin_size; i++) {
629 origin->addItem(qt_(rorigin_gui_strs[i]),
630 toqstr(rorigin_lyx_strs[i]));
633 if (!igp.rotateOrigin.empty())
634 origin->setCurrentIndex(origin->findData(toqstr(igp.rotateOrigin)));
636 origin->setCurrentIndex(0);
639 latexoptions->setText(toqstr(igp.special));
641 filename->setFocus();
645 void GuiGraphics::applyView()
647 InsetGraphicsParams & igp = params_;
649 igp.filename.set(fromqstr(filename->text()), fromqstr(bufferFilePath()));
655 string lbXs = widgetToDoubleStr(lbX);
656 string lbYs = widgetToDoubleStr(lbY);
657 string rtXs = widgetToDoubleStr(rtX);
658 string rtYs = widgetToDoubleStr(rtY);
660 convert<int>(lbXs) + convert<int>(lbYs) +
661 convert<int>(rtXs) + convert<int>(rtXs);
666 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
670 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
674 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
678 bb += (rtYs + fromqstr(rtYunit->currentText()));
683 igp.draft = draftCB->isChecked();
684 igp.clip = clip->isChecked();
685 igp.display = displayGB->isChecked();
687 //the graphics section
688 if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
689 igp.scale = widgetToDoubleStr(Scale);
690 igp.width = Length("0pt");
691 igp.height = Length("0pt");
692 igp.keepAspectRatio = false;
694 igp.scale = string();
695 igp.width = WidthCB->isChecked() ?
696 //Note that this works even if Width is "auto", since in
697 //that case we get "0pt".
698 Length(widgetsToLength(Width, widthUnit)):
700 igp.height = HeightCB->isChecked() ?
701 Length(widgetsToLength(Height, heightUnit)) :
703 igp.keepAspectRatio = aspectratio->isEnabled() &&
704 aspectratio->isChecked() &&
705 igp.width.value() > 0 && igp.height.value() > 0;
708 igp.noUnzip = unzipCB->isChecked();
709 igp.lyxscale = displayscale->text().toInt();
710 igp.rotateAngle = widgetToDoubleStr(angle);
712 double rotAngle = widgetToDouble(angle);
713 if (abs(rotAngle) > 360.0) {
714 rotAngle -= 360.0 * floor(rotAngle / 360.0);
715 igp.rotateAngle = convert<string>(rotAngle);
718 // save the latex name for the origin. If it is the default
719 // then origin_ltx returns ""
721 fromqstr(origin->itemData(origin->currentIndex()).toString());
722 igp.scaleBeforeRotation = rotateOrderCB->isChecked();
724 // more latex options
725 igp.special = fromqstr(latexoptions->text());
727 igp.groupId = fromqstr(groupCO->itemData(
728 groupCO->currentIndex()).toString());
729 current_group_ = igp.groupId;
733 void GuiGraphics::getBB()
735 string const fn = fromqstr(filename->text());
738 string const bb = readBoundingBox(fn);
742 doubleToWidget(lbX, token(bb, ' ', 0));
743 doubleToWidget(lbY, token(bb, ' ', 1));
744 doubleToWidget(rtX, token(bb, ' ', 2));
745 doubleToWidget(rtY, token(bb, ' ', 3));
746 // the default units for the bb values when reading
748 lbXunit->setCurrentIndex(0);
749 lbYunit->setCurrentIndex(0);
750 rtXunit->setCurrentIndex(0);
751 rtYunit->setCurrentIndex(0);
755 bool GuiGraphics::isValid()
757 return !filename->text().isEmpty();
761 bool GuiGraphics::initialiseParams(string const & data)
763 InsetGraphics::string2params(data, buffer(), params_);
764 paramsToDialog(params_);
765 current_group_ = params_.groupId;
770 void GuiGraphics::clearParams()
772 params_ = InsetGraphicsParams();
776 void GuiGraphics::dispatchParams()
778 InsetGraphicsParams tmp_params(params_);
779 string const lfun = InsetGraphics::params2string(tmp_params, buffer());
780 dispatch(FuncRequest(getLfun(), lfun));
784 QString GuiGraphics::browse(QString const & in_name) const
786 QString const title = qt_("Select graphics file");
788 // Does user clipart directory exist?
789 string clipdir = addName(package().user_support().absFileName(), "clipart");
790 FileName clip(clipdir);
792 // bail out to system clipart directory
793 if (!clip.isDirectory())
794 clipdir = addName(package().system_support().absFileName(), "clipart");
796 return browseRelFile(in_name, bufferFilePath(),
797 title, fileFilters(QString()), false,
798 qt_("Clipart|#C#c"), toqstr(clipdir),
799 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
803 string GuiGraphics::readBoundingBox(string const & file)
805 FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath()));
807 // try to get it from the file, if possible. Zipped files are
808 // unzipped in the readBB_from_PSFile-Function
809 string const bb = readBB_from_PSFile(abs_file);
813 // we don't, so ask the Graphics Cache if it has loaded the file
817 graphics::Cache & gc = graphics::Cache::get();
818 if (gc.inCache(abs_file)) {
819 graphics::Image const * image = gc.item(abs_file)->image();
822 width = image->width();
823 height = image->height();
827 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
831 bool GuiGraphics::isFileNameValid(string const & fname) const
833 // It may be that the filename is relative.
834 return support::makeAbsPath(fname, fromqstr(bufferFilePath())).isReadableFile();
838 Dialog * createGuiGraphics(GuiView & lv) { return new GuiGraphics(lv); }
841 } // namespace frontend
844 #include "moc_GuiGraphics.cpp"