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