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