]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiGraphics.cpp
Why would boost::array<Bullet, 4> be better than Bullet[4]?
[features.git] / src / frontends / qt4 / GuiGraphics.cpp
1 /**
2  * \file GuiGraphics.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Edwin Leuven
8  * \author Herbert Voß
9  * \author Richard Heck
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "GuiGraphics.h"
17
18 #include "ControlGraphics.h"
19 #include "debug.h"
20 #include "LengthCombo.h"
21 #include "lengthcommon.h"
22 #include "LyXRC.h"
23 #include "qt_helpers.h"
24 #include "Validator.h"
25
26 #include "insets/InsetGraphicsParams.h"
27
28 #include "support/convert.h"
29 #include "support/lstrings.h"
30 #include "support/lyxlib.h"
31 #include "support/os.h"
32
33 #include <boost/bind.hpp>
34
35 #include <QCheckBox>
36 #include <QCloseEvent>
37 #include <QLabel>
38 #include <QLineEdit>
39 #include <QPushButton>
40 #include <QValidator>
41
42 #include <algorithm>
43 #include <cmath>
44 #include <utility>
45
46 using lyx::support::float_equal;
47 using lyx::support::token;
48
49 using lyx::support::os::internal_path;
50
51 #ifndef CXX_GLOBAL_CSTD
52 using std::floor;
53 #endif
54
55 using std::vector;
56 using std::string;
57
58
59 namespace lyx {
60 namespace frontend {
61
62
63 //FIXME setAutoTextCB should really take an argument, as indicated, that
64 //determines what text is to be written for "auto". But making
65 //that work involves more extensive revisions than we now want
66 //to make, since "auto" also appears in updateContents() (see
67 //GuiGraphics.cpp).
68 //The right way to do this, I think, would be to define a class
69 //checkedLengthSet (and a partnering labeledLengthSete) that encapsulated
70 //the checkbox, line edit, and length combo together, and then made e.g.
71 //lengthToWidgets, widgetsToLength, etc, all public methods of that class.
72 //Perhaps even the validator could be exposed through it.
73 /**
74  * sets a checkbox-line edit-length combo group, using "text" if the
75  * checkbox is unchecked and clearing the line edit if it previously
76  * said "text".
77 */
78 void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
79         LengthCombo * lengthCombo/*, string text = "auto"*/)
80 {
81         if (!checkBox->isChecked())
82                 lengthToWidgets(lineEdit, lengthCombo,
83                                 "auto", lengthCombo->currentLengthItem());
84         else if (lineEdit->text() == "auto")
85                 lengthToWidgets(lineEdit, lengthCombo, string(),
86                                 lengthCombo->currentLengthItem());
87 }
88
89
90
91 template<class Pair>
92 std::vector<typename Pair::first_type> const
93 getFirst(std::vector<Pair> const & pr)
94 {
95         std::vector<typename Pair::first_type> tmp(pr.size());
96         std::transform(pr.begin(), pr.end(), tmp.begin(),
97                        boost::bind(&Pair::first, _1));
98         return tmp;
99 }
100
101 ///
102 template<class Pair>
103 std::vector<typename Pair::second_type> const
104 getSecond(std::vector<Pair> const & pr)
105 {
106          std::vector<typename Pair::second_type> tmp(pr.size());
107          std::transform(pr.begin(), pr.end(), tmp.begin(),
108                                          boost::bind(&Pair::second, _1));
109          return tmp;
110 }
111
112 GuiGraphicsDialog::GuiGraphicsDialog(LyXView & lv)
113         : GuiDialog(lv, "graphics")
114 {
115         setupUi(this);
116         setViewTitle(_("Graphics"));
117         setController(new ControlGraphics(*this));
118
119         //main buttons
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()));
124
125         //graphics pane
126         connect(filename, SIGNAL(textChanged(const QString &)),
127                 this, SLOT(change_adaptor()));
128         connect(WidthCB, SIGNAL( clicked()),
129                 this, SLOT(change_adaptor()));
130         connect(HeightCB, SIGNAL( clicked()),
131                 this, SLOT(change_adaptor()));
132         connect(Width, SIGNAL(textChanged(const QString &)),
133                 this, SLOT(change_adaptor()));
134         connect(Height, SIGNAL(textChanged(const QString &)),
135                 this, SLOT(change_adaptor()));
136         connect(heightUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
137                 this, SLOT(change_adaptor()));
138         connect(widthUnit, SIGNAL(selectionChanged(lyx::Length::UNIT)),
139                 this, SLOT(change_adaptor()));
140         connect(aspectratio, SIGNAL(stateChanged(int)),
141                 this, SLOT(change_adaptor()));
142         connect(angle, SIGNAL(textChanged(const QString &)),
143                 this, SLOT(change_adaptor()));
144         connect(origin, SIGNAL(activated(int)),
145                 this, SLOT(change_adaptor()));
146         connect(scaleCB, SIGNAL(clicked()),
147                 this, SLOT(change_adaptor()));
148         connect(Scale, SIGNAL(textChanged(const QString &)),
149                 this, SLOT(change_adaptor()));
150         connect(rotateOrderCB, SIGNAL(clicked()),
151                 this, SLOT(change_adaptor()));
152
153         filename->setValidator(new PathValidator(true, filename));
154         setFocusProxy(filename);
155
156         QDoubleValidator * scaleValidator = new DoubleAutoValidator(Scale);
157         scaleValidator->setBottom(0);
158         scaleValidator->setDecimals(256); //I guess that will do
159         Scale->setValidator(scaleValidator);
160         Height->setValidator(unsignedLengthAutoValidator(Height));
161         Width->setValidator(unsignedLengthAutoValidator(Width));
162         angle->setValidator(new QDoubleValidator(-360, 360, 2, angle));
163
164         //clipping pane
165         connect(clip, SIGNAL(stateChanged(int)),
166                 this, SLOT(change_adaptor()));
167         connect(lbY, SIGNAL(textChanged(const QString&)),
168                 this, SLOT(change_bb()));
169         connect(lbYunit, SIGNAL(activated(int)),
170                 this, SLOT(change_bb()));
171         connect(rtY, SIGNAL(textChanged(const QString&)),
172                 this, SLOT(change_bb()));
173         connect(rtYunit, SIGNAL(activated(int)),
174                 this, SLOT(change_bb()));
175         connect(lbX, SIGNAL(textChanged(const QString&)),
176                 this, SLOT(change_bb()));
177         connect(lbXunit, SIGNAL(activated(int)),
178                 this, SLOT(change_bb()));
179         connect(rtX, SIGNAL(textChanged(const QString&)),
180                 this, SLOT(change_bb()));
181         connect(rtXunit, SIGNAL(activated(int)),
182                 this, SLOT(change_bb()));
183         connect(getPB, SIGNAL(clicked()),
184                 this, SLOT(change_adaptor()));
185
186         lbX->setValidator(new QDoubleValidator(lbX));
187         lbY->setValidator(new QDoubleValidator(lbY));
188         rtX->setValidator(new QDoubleValidator(rtX));
189         rtY->setValidator(new QDoubleValidator(rtY));
190
191         //extra options pane
192         connect(latexoptions, SIGNAL(textChanged(const QString&)),
193                 this, SLOT(change_adaptor()));
194         connect(draftCB, SIGNAL(stateChanged(int)),
195                 this, SLOT(change_adaptor()));
196         connect(unzipCB, SIGNAL(stateChanged(int)),
197                 this, SLOT(change_adaptor()));
198         // FIXME: we should connect to clicked() when we move to Qt 4.2 because
199         // the toggled(bool) signal is also trigged when we update the widgets
200         // (rgh-4/07) this isn't as much or a problem as it was, because we're now
201         // using blockSignals() to keep from triggering that signal when we call
202         // setChecked(). Note, too, that clicked() would get called whenever it
203         // is clicked, even right clicked (I think), not just whenever it is
204         // toggled.
205         connect(subfigure, SIGNAL(toggled(bool)),
206                 this, SLOT(change_adaptor()));
207         connect(subcaption, SIGNAL(textChanged(const QString&)),
208                 this, SLOT(change_adaptor()));
209         connect(displayGB, SIGNAL(toggled(bool)),
210                 this, SLOT(change_adaptor()));
211         connect(showCB, SIGNAL(currentIndexChanged(int)),
212                 this, SLOT(change_adaptor()));
213         connect(displayscale, SIGNAL(textChanged(const QString&)),
214                 this, SLOT(change_adaptor()));
215         displayscale->setValidator(new QIntValidator(displayscale));
216
217         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
218         bc().setOK(okPB);
219         bc().setApply(applyPB);
220         bc().setRestore(restorePB);
221         bc().setCancel(closePB);
222
223         bc().addReadOnly(latexoptions);
224         bc().addReadOnly(subfigure);
225         bc().addReadOnly(filenameL);
226         bc().addReadOnly(filename);
227         bc().addReadOnly(browsePB);
228         bc().addReadOnly(unzipCB);
229         bc().addReadOnly(bbFrame);
230         bc().addReadOnly(draftCB);
231         bc().addReadOnly(clip);
232         bc().addReadOnly(unzipCB);
233         bc().addReadOnly(displayGB);
234         bc().addReadOnly(sizeGB);
235         bc().addReadOnly(rotationGB);
236         bc().addReadOnly(latexoptions);
237         bc().addReadOnly(getPB);
238         bc().addReadOnly(rotateOrderCB);
239
240         // initialize the length validator
241         bc().addCheckedLineEdit(Scale, scaleCB);
242         bc().addCheckedLineEdit(Width, WidthCB);
243         bc().addCheckedLineEdit(Height, HeightCB);
244         bc().addCheckedLineEdit(displayscale, scaleLA);
245         bc().addCheckedLineEdit(angle, angleL);
246         bc().addCheckedLineEdit(lbX, xL);
247         bc().addCheckedLineEdit(lbY, yL);
248         bc().addCheckedLineEdit(rtX, xL_2);
249         bc().addCheckedLineEdit(rtY, yL_2);
250         bc().addCheckedLineEdit(filename, filenameL);
251 }
252
253
254 ControlGraphics & GuiGraphicsDialog::controller()
255 {
256         return static_cast<ControlGraphics &>(GuiDialog::controller());
257 }
258
259
260 void GuiGraphicsDialog::change_adaptor()
261 {
262         changed();
263 }
264
265
266 void GuiGraphicsDialog::change_bb()
267 {
268         controller().bbChanged = true;
269         LYXERR(Debug::GRAPHICS)
270                 << "[controller().bb_Changed set to true]\n";
271         changed();
272 }
273
274
275 void GuiGraphicsDialog::closeEvent(QCloseEvent * e)
276 {
277         slotClose();
278         e->accept();
279 }
280
281
282 void GuiGraphicsDialog::on_browsePB_clicked()
283 {
284         docstring const str =
285                 controller().browse(qstring_to_ucs4(filename->text()));
286         if(!str.empty()){
287                 filename->setText(toqstr(str));
288                 embedCB->setCheckState(Qt::Unchecked);
289                 changed();
290         }
291 }
292
293
294 void GuiGraphicsDialog::on_getPB_clicked()
295 {
296         getBB();
297 }
298
299
300 void GuiGraphicsDialog::on_editPB_clicked()
301 {
302         controller().editGraphics();
303 }
304
305
306 void GuiGraphicsDialog::on_filename_textChanged(const QString & filename)
307 {
308         editPB->setDisabled(filename.isEmpty());
309 }
310
311
312 void GuiGraphicsDialog::setAutoText()
313 {
314         if (scaleCB->isChecked())
315                 return;
316         if (!Scale->isEnabled() && Scale->text() != "100")
317                 Scale->setText(QString("auto"));
318
319         setAutoTextCB(WidthCB, Width, widthUnit);
320         setAutoTextCB(HeightCB, Height, heightUnit);
321 }
322
323
324 void GuiGraphicsDialog::on_scaleCB_toggled(bool setScale)
325 {
326         Scale->setEnabled(setScale);
327         if (setScale) {
328                 Scale->setText("100");
329                 Scale->setFocus(Qt::OtherFocusReason);
330         }
331
332         WidthCB->setDisabled(setScale);
333         WidthCB->blockSignals(true);
334         WidthCB->setChecked(false);
335         WidthCB->blockSignals(false);
336         Width->setEnabled(false);
337         widthUnit->setEnabled(false);
338
339         HeightCB->setDisabled(setScale);
340         HeightCB->blockSignals(true);
341         HeightCB->setChecked(false);
342         HeightCB->blockSignals(false);
343         Height->setEnabled(false);
344         heightUnit->setEnabled(false);
345
346         aspectratio->setDisabled(true);
347         aspectratio->setChecked(true);
348
349         rotateOrderCB->setEnabled((WidthCB->isChecked() ||
350                                  HeightCB->isChecked() ||
351                                  scaleCB->isChecked()) &&
352                                  (angle->text() != "0"));
353
354         setAutoText();
355 }
356
357
358 void GuiGraphicsDialog::on_WidthCB_toggled(bool setWidth)
359 {
360         Width->setEnabled(setWidth);
361         widthUnit->setEnabled(setWidth);
362         if (setWidth)
363                 Width->setFocus(Qt::OtherFocusReason);
364
365         bool const setHeight = HeightCB->isChecked();
366         aspectratio->setEnabled(setWidth && setHeight);
367         aspectratio->blockSignals(true);
368         aspectratio->setChecked(!(setWidth && setHeight));
369         aspectratio->blockSignals(false);
370
371         scaleCB->setEnabled(!setWidth && !setHeight);
372         //already will be unchecked, so don't need to do that
373         Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
374                         && scaleCB->isChecked()); //should be false, but let's check
375         rotateOrderCB->setEnabled((setWidth || setHeight ||
376                                  scaleCB->isChecked()) &&
377                                  (angle->text() != "0"));
378
379         setAutoText();
380 }
381
382
383 void GuiGraphicsDialog::on_HeightCB_toggled(bool setHeight)
384 {
385         Height->setEnabled(setHeight);
386         heightUnit->setEnabled(setHeight);
387         if (setHeight)
388                 Height->setFocus(Qt::OtherFocusReason);
389
390         bool const setWidth = WidthCB->isChecked();
391         aspectratio->setEnabled(setWidth && setHeight);
392         aspectratio->blockSignals(true);
393         aspectratio->setChecked(!(setWidth && setHeight));
394         aspectratio->blockSignals(false);
395
396         scaleCB->setEnabled(!setWidth && !setHeight);
397         //already unchecked
398         Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
399                 && scaleCB->isChecked()); //should be false
400         rotateOrderCB->setEnabled((setWidth || setHeight ||
401                                  scaleCB->isChecked()) &&
402                                  (angle->text() != "0"));
403
404         setAutoText();
405 }
406
407
408 void GuiGraphicsDialog::on_angle_textChanged(const QString & filename)
409 {
410         rotateOrderCB->setEnabled((WidthCB->isChecked() ||
411                                  HeightCB->isChecked() ||
412                                  scaleCB->isChecked()) &&
413                                  (filename != "0"));
414 }
415
416 // returns the number of the string s in the vector v
417 static int getItemNo(const vector<string> & v, string const & s)
418 {
419         vector<string>::const_iterator cit =
420                     find(v.begin(), v.end(), s);
421         return (cit != v.end()) ? int(cit - v.begin()) : 0;
422 }
423
424
425 void GuiGraphicsDialog::updateContents()
426 {
427         // clear and fill in the comboboxes
428         vector<string> const bb_units = frontend::getBBUnits();
429         lbXunit->clear();
430         lbYunit->clear();
431         rtXunit->clear();
432         rtYunit->clear();
433         for (vector<string>::const_iterator it = bb_units.begin();
434             it != bb_units.end(); ++it) {
435                 lbXunit->addItem(toqstr(*it));
436                 lbYunit->addItem(toqstr(*it));
437                 rtXunit->addItem(toqstr(*it));
438                 rtYunit->addItem(toqstr(*it));
439         }
440
441         InsetGraphicsParams & igp = controller().params();
442
443         // set the right default unit
444         Length::UNIT unitDefault = Length::CM;
445         switch (lyxrc.default_papersize) {
446                 case PAPER_USLETTER:
447                 case PAPER_USLEGAL:
448                 case PAPER_USEXECUTIVE:
449                         unitDefault = Length::IN;
450                         break;
451                 default:
452                         break;
453         }
454
455         string const name =
456                 igp.filename.outputFilename(controller().bufferFilepath());
457         filename->setText(toqstr(name));
458     embedCB->setCheckState(igp.filename.embedded() ? Qt::Checked : Qt::Unchecked);
459
460         // set the bounding box values
461         if (igp.bb.empty()) {
462                 string const bb = controller().readBB(igp.filename.absFilename());
463                 // the values from the file always have the bigpoint-unit bp
464                 lbX->setText(toqstr(token(bb, ' ', 0)));
465                 lbY->setText(toqstr(token(bb, ' ', 1)));
466                 rtX->setText(toqstr(token(bb, ' ', 2)));
467                 rtY->setText(toqstr(token(bb, ' ', 3)));
468                 lbXunit->setCurrentIndex(0);
469                 lbYunit->setCurrentIndex(0);
470                 rtXunit->setCurrentIndex(0);
471                 rtYunit->setCurrentIndex(0);
472                 controller().bbChanged = false;
473         } else {
474                 // get the values from the inset
475                 Length anyLength;
476                 string const xl(token(igp.bb, ' ', 0));
477                 string const yl(token(igp.bb, ' ', 1));
478                 string const xr(token(igp.bb, ' ', 2));
479                 string const yr(token(igp.bb, ' ', 3));
480                 if (isValidLength(xl, &anyLength)) {
481                         lbX->setText(toqstr(convert<string>(anyLength.value())));
482                         string const unit(unit_name[anyLength.unit()]);
483                         lbXunit->setCurrentIndex(getItemNo(bb_units, unit));
484                 } else {
485                         lbX->setText(toqstr(xl));
486                 }
487                 if (isValidLength(yl, &anyLength)) {
488                         lbY->setText(toqstr(convert<string>(anyLength.value())));
489                         string const unit(unit_name[anyLength.unit()]);
490                         lbYunit->setCurrentIndex(getItemNo(bb_units, unit));
491                 } else {
492                         lbY->setText(toqstr(xl));
493                 }
494                 if (isValidLength(xr, &anyLength)) {
495                         rtX->setText(toqstr(convert<string>(anyLength.value())));
496                         string const unit(unit_name[anyLength.unit()]);
497                         rtXunit->setCurrentIndex(getItemNo(bb_units, unit));
498                 } else {
499                         rtX->setText(toqstr(xl));
500                 }
501                 if (isValidLength(yr, &anyLength)) {
502                         rtY->setText(toqstr(convert<string>(anyLength.value())));
503                         string const unit(unit_name[anyLength.unit()]);
504                         rtYunit->setCurrentIndex(getItemNo(bb_units, unit));
505                 } else {
506                         rtY->setText(toqstr(xl));
507                 }
508                 controller().bbChanged = true;
509         }
510
511         // Update the draft and clip mode
512         draftCB->setChecked(igp.draft);
513         clip->setChecked(igp.clip);
514         unzipCB->setChecked(igp.noUnzip);
515
516         // Update the subcaption check button and input field
517         subfigure->setChecked(igp.subcaption);
518         subcaption->setText(toqstr(igp.subcaptionText));
519
520         int item = 0;
521         switch (igp.display) {
522                 case graphics::DefaultDisplay: item = 0; break;
523                 case graphics::MonochromeDisplay: item = 1; break;
524                 case graphics::GrayscaleDisplay: item = 2; break;
525                 case graphics::ColorDisplay: item = 3; break;
526                 case graphics::NoDisplay: item = 0; break;
527         }
528         showCB->setCurrentIndex(item);
529         displayscale->setText(toqstr(convert<string>(igp.lyxscale)));
530         displayGB->setChecked(igp.display != graphics::NoDisplay);
531
532         // the output section (width/height)
533
534         Scale->setText(toqstr(igp.scale));
535         //igp.scale defaults to 100, so we treat it as empty
536         bool const scaleChecked = !igp.scale.empty() && igp.scale != "100";
537         scaleCB->blockSignals(true);
538         scaleCB->setChecked(scaleChecked);
539         scaleCB->blockSignals(false);
540         Scale->setEnabled(scaleChecked);
541
542         lengthAutoToWidgets(Width, widthUnit, igp.width,
543                 unitDefault);
544         bool const widthChecked = !Width->text().isEmpty() &&
545                 Width->text() != "auto";
546         WidthCB->blockSignals(true);
547         WidthCB->setChecked(widthChecked);
548         WidthCB->blockSignals(false);
549         Width->setEnabled(widthChecked);
550         widthUnit->setEnabled(widthChecked);
551
552         lengthAutoToWidgets(Height, heightUnit, igp.height,
553                 unitDefault);
554         bool const heightChecked = !Height->text().isEmpty()
555                 && Height->text() != "auto";
556         HeightCB->blockSignals(true);
557         HeightCB->setChecked(heightChecked);
558         HeightCB->blockSignals(false);
559         Height->setEnabled(heightChecked);
560         heightUnit->setEnabled(heightChecked);
561
562         scaleCB->setEnabled(!widthChecked && !heightChecked);
563         WidthCB->setEnabled(!scaleChecked);
564         HeightCB->setEnabled(!scaleChecked);
565         aspectratio->setEnabled(widthChecked && heightChecked);
566
567         setAutoText();
568
569         angle->setText(toqstr(igp.rotateAngle));
570         rotateOrderCB->setChecked(igp.scaleBeforeRotation);
571
572         rotateOrderCB->setEnabled( (widthChecked || heightChecked || scaleChecked)
573                 && igp.rotateAngle != "0");
574
575         origin->clear();
576
577         vector<RotationOriginPair> origindata = getRotationOriginData();
578         vector<docstring> const origin_lang = getFirst(origindata);
579         origin_ltx = getSecond(origindata);
580
581         for (vector<docstring>::const_iterator it = origin_lang.begin();
582             it != origin_lang.end(); ++it)
583                 origin->addItem(toqstr(*it));
584
585         if (!igp.rotateOrigin.empty())
586                 origin->setCurrentIndex(
587                         getItemNo(origin_ltx, igp.rotateOrigin));
588         else
589                 origin->setCurrentIndex(0);
590
591         // disable edit button when no filename is present
592         editPB->setDisabled(filename->text().isEmpty());
593
594         //// latex section
595         latexoptions->setText(toqstr(igp.special));
596 }
597
598
599 void GuiGraphicsDialog::applyView()
600 {
601         InsetGraphicsParams & igp = controller().params();
602
603         igp.filename.set(internal_path(fromqstr(filename->text())),
604                          controller().bufferFilepath());
605         igp.filename.setEmbed(embedCB->checkState() == Qt::Checked);
606
607         // the bb section
608         igp.bb.erase();
609         if (controller().bbChanged) {
610                 string bb;
611                 string lbXs = fromqstr(lbX->text());
612                 string lbYs = fromqstr(lbY->text());
613                 string rtXs = fromqstr(rtX->text());
614                 string rtYs = fromqstr(rtY->text());
615                 int bb_sum =
616                         convert<int>(lbXs) + convert<int>(lbYs) +
617                         convert<int>(rtXs) + convert<int>(rtXs);
618                 if (bb_sum) {
619                         if (lbXs.empty())
620                                 bb = "0 ";
621                         else
622                                 bb = lbXs + fromqstr(lbXunit->currentText()) + ' ';
623                         if (lbYs.empty())
624                                 bb += "0 ";
625                         else
626                                 bb += (lbYs + fromqstr(lbYunit->currentText()) + ' ');
627                         if (rtXs.empty())
628                                 bb += "0 ";
629                         else
630                                 bb += (rtXs + fromqstr(rtXunit->currentText()) + ' ');
631                         if (rtYs.empty())
632                                 bb += '0';
633                         else
634                                 bb += (rtYs + fromqstr(rtYunit->currentText()));
635                         igp.bb = bb;
636                 }
637         }
638
639         igp.draft = draftCB->isChecked();
640         igp.clip = clip->isChecked();
641         igp.subcaption = subfigure->isChecked();
642         igp.subcaptionText = fromqstr(subcaption->text());
643
644         switch (showCB->currentIndex()) {
645                 case 0: igp.display = graphics::DefaultDisplay; break;
646                 case 1: igp.display = graphics::MonochromeDisplay; break;
647                 case 2: igp.display = graphics::GrayscaleDisplay; break;
648                 case 3: igp.display = graphics::ColorDisplay; break;
649                 default:;
650         }
651
652         if (!displayGB->isChecked())
653                 igp.display = graphics::NoDisplay;
654
655         //the graphics section
656         if (scaleCB->isChecked() && !Scale->text().isEmpty()) {
657                 igp.scale = fromqstr(Scale->text());
658                 igp.width = Length("0pt");
659                 igp.height = Length("0pt");
660                 igp.keepAspectRatio = false;
661         } else {
662                 igp.scale = string();
663                 igp.width = WidthCB->isChecked() ?
664                         //Note that this works even if Width is "auto", since in
665                         //that case we get "0pt".
666                         Length(widgetsToLength(Width, widthUnit)):
667                         Length("0pt");
668                 igp.height = HeightCB->isChecked() ?
669                         Length(widgetsToLength(Height, heightUnit)) :
670                         Length("0pt");
671                 igp.keepAspectRatio = aspectratio->isEnabled() &&
672                         aspectratio->isChecked() &&
673                         igp.width.value() > 0 && igp.height.value() > 0;
674         }
675
676         igp.noUnzip = unzipCB->isChecked();
677         igp.lyxscale = displayscale->text().toInt();
678         igp.rotateAngle = fromqstr(angle->text());
679
680         double rotAngle = convert<double>(igp.rotateAngle);
681         if (std::abs(rotAngle) > 360.0) {
682                 rotAngle -= 360.0 * floor(rotAngle / 360.0);
683                 igp.rotateAngle = convert<string>(rotAngle);
684         }
685
686         // save the latex name for the origin. If it is the default
687         // then origin_ltx returns ""
688         igp.rotateOrigin = origin_ltx[origin->currentIndex()];
689         igp.scaleBeforeRotation = rotateOrderCB->isChecked();
690
691         // more latex options
692         igp.special = fromqstr(latexoptions->text());
693 }
694
695
696 void GuiGraphicsDialog::getBB()
697 {
698         string const fn = fromqstr(filename->text());
699         if (!fn.empty()) {
700                 string const bb = controller().readBB(fn);
701                 if (!bb.empty()) {
702                         lbX->setText(toqstr(token(bb, ' ', 0)));
703                         lbY->setText(toqstr(token(bb, ' ', 1)));
704                         rtX->setText(toqstr(token(bb, ' ', 2)));
705                         rtY->setText(toqstr(token(bb, ' ', 3)));
706                         // the default units for the bb values when reading
707                         // it from the file
708                         lbXunit->setCurrentIndex(0);
709                         lbYunit->setCurrentIndex(0);
710                         rtXunit->setCurrentIndex(0);
711                         rtYunit->setCurrentIndex(0);
712                 }
713                 controller().bbChanged = false;
714         }
715 }
716
717
718 bool GuiGraphicsDialog::isValid()
719 {
720         return !filename->text().isEmpty();
721 }
722
723 } // namespace frontend
724 } // namespace lyx
725
726
727 #include "GuiGraphics_moc.cpp"
728