]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QDocument.C
1693adbf7b7e5e8d06a06bd997a97ed017336126
[lyx.git] / src / frontends / qt4 / QDocument.C
1 /**
2  * \file QDocument.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "QDocument.h"
14 #include "Qt2BC.h"
15 #include "qt_helpers.h"
16 #include "QBranches.h"
17
18 #include <QCloseEvent>
19
20 #include "FloatPlacement.h"
21 #include "lengthcombo.h"
22 #include "validators.h"
23 #include "panelstack.h"
24 #include "Qt2BC.h"
25 #include "checkedwidgets.h"
26 #include "qt_helpers.h"
27
28 // For latexHighlighter use in the preamble.
29 #include "QViewSource.h"
30
31 #include "bufferparams.h"
32 #include "encoding.h"
33 #include "gettext.h"
34 #include "helper_funcs.h" // getSecond()
35 #include "language.h"
36 #include "lyxrc.h" // defaultUnit
37 #include "lyxtextclasslist.h"
38 #include "tex-strings.h" // tex_graphics
39 #include "Spacing.h"
40
41 #include "frontends/controllers/biblio.h"
42 #include "controllers/ControlDocument.h"
43 #include "controllers/frnt_lang.h"
44
45 #include "support/lstrings.h"
46
47 #include "controllers/ControlDocument.h"
48 #include "controllers/frnt_lang.h"
49
50
51 using lyx::support::token;
52 using lyx::support::bformat;
53 using lyx::support::findToken;
54 using lyx::support::getVectorFromString;
55
56 using std::distance;
57 using std::vector;
58 using std::string;
59
60
61 namespace lyx {
62 namespace frontend {
63
64 /////////////////////////////////////////////////////////////////////
65 //
66 // DocumentDialog
67 //
68 /////////////////////////////////////////////////////////////////////
69
70 QDocumentDialog::QDocumentDialog(QDocument * form)
71         : form_(form),
72         lang_(getSecond(getLanguageData(false)))
73 {
74         setupUi(this);
75
76         connect(okPB, SIGNAL(clicked()), form, SLOT(slotOK()));
77         connect(applyPB, SIGNAL(clicked()), form, SLOT(slotApply()));
78         connect(closePB, SIGNAL(clicked()), form, SLOT(slotClose()));
79         connect(restorePB, SIGNAL(clicked()), form, SLOT(slotRestore()));
80
81         connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
82         connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
83
84         // Manage the restore, ok, apply, restore and cancel/close buttons
85         form_->bcview().setOK(okPB);
86         form_->bcview().setApply(applyPB);
87         form_->bcview().setCancel(closePB);
88         form_->bcview().setRestore(restorePB);
89
90
91         textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
92         // text layout
93         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
94                 this, SLOT(change_adaptor()));
95         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
96                 this, SLOT(setLSpacing(int)));
97         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
98                 this, SLOT(change_adaptor()));
99         connect(textLayoutModule->skipRB, SIGNAL(clicked()),
100                 this, SLOT(change_adaptor()));
101         connect(textLayoutModule->indentRB, SIGNAL(clicked()),
102                 this, SLOT(change_adaptor()));
103         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
104                 this, SLOT(change_adaptor()));
105         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
106                 this, SLOT(change_adaptor()));
107         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
108                 this, SLOT(change_adaptor()));
109         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
110                 this, SLOT(setSkip(int)));
111         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
112                 this, SLOT(enableSkip(bool)));
113         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
114                 this, SLOT(change_adaptor()));
115         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
116                 textLayoutModule->lspacingLE));
117         textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
118                 textLayoutModule->skipLE));
119
120         textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
121         textLayoutModule->skipCO->addItem(qt_("MedSkip"));
122         textLayoutModule->skipCO->addItem(qt_("BigSkip"));
123         textLayoutModule->skipCO->addItem(qt_("Length"));
124         // remove the %-items from the unit choice
125         textLayoutModule->skipLengthCO->noPercents();
126         textLayoutModule->lspacingCO->insertItem(
127                 Spacing::Single, qt_("Single"));
128         textLayoutModule->lspacingCO->insertItem(
129                 Spacing::Onehalf, qt_("OneHalf"));
130         textLayoutModule->lspacingCO->insertItem(
131                 Spacing::Double, qt_("Double"));
132         textLayoutModule->lspacingCO->insertItem(
133                 Spacing::Other, qt_("Custom"));
134
135         // initialize the length validator
136         addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
137
138         fontModule = new UiWidget<Ui::FontUi>;
139         // fonts
140         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
141                 this, SLOT(change_adaptor()));
142         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
143                 this, SLOT(romanChanged(int)));
144         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
145                 this, SLOT(change_adaptor()));
146         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
147                 this, SLOT(sansChanged(int)));
148         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
149                 this, SLOT(change_adaptor()));
150         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
151                 this, SLOT(ttChanged(int)));
152         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
153                 this, SLOT(change_adaptor()));
154         connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
155                 this, SLOT(change_adaptor()));
156         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
157                 this, SLOT(change_adaptor()));
158         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
159                 this, SLOT(change_adaptor()));
160         connect(fontModule->fontScCB, SIGNAL(clicked()),
161                 this, SLOT(change_adaptor()));
162         connect(fontModule->fontOsfCB, SIGNAL(clicked()),
163                 this, SLOT(change_adaptor()));
164
165         for (int n = 0; tex_fonts_roman[n][0]; ++n) {
166                 QString font = toqstr(tex_fonts_roman_gui[n]);
167                 if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
168                         font += qt_(" (not installed)");
169                 fontModule->fontsRomanCO->addItem(font);
170         }
171         for (int n = 0; tex_fonts_sans[n][0]; ++n) {
172                 QString font = toqstr(tex_fonts_sans_gui[n]);
173                 if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
174                         font += qt_(" (not installed)");
175                 fontModule->fontsSansCO->addItem(font);
176         }
177         for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
178                 QString font = toqstr(tex_fonts_monospaced_gui[n]);
179                 if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
180                         font += qt_(" (not installed)");
181                 fontModule->fontsTypewriterCO->addItem(font);
182         }
183
184         fontModule->fontsizeCO->addItem(qt_("default"));
185         fontModule->fontsizeCO->addItem(qt_("10"));
186         fontModule->fontsizeCO->addItem(qt_("11"));
187         fontModule->fontsizeCO->addItem(qt_("12"));
188
189         for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
190                 fontModule->fontsDefaultCO->addItem(
191                         qt_(ControlDocument::fontfamilies_gui[n]));
192
193
194         pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
195         // page layout
196         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
197                 this, SLOT(setCustomPapersize(int)));
198         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
199                 this, SLOT(setCustomPapersize(int)));
200         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
201                 this, SLOT(portraitChanged()));
202         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
203                 this, SLOT(change_adaptor()));
204         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
205                 this, SLOT(change_adaptor()));
206         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
207                 this, SLOT(change_adaptor()));
208         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
209                 this, SLOT(change_adaptor()));
210         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
211                 this, SLOT(change_adaptor()));
212         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
213                 this, SLOT(change_adaptor()));
214         connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
215                 this, SLOT(change_adaptor()));
216         connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
217                 this, SLOT(change_adaptor()));
218         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
219                 this, SLOT(change_adaptor()));
220
221         pageLayoutModule->pagestyleCO->addItem(qt_("default"));
222         pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
223         pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
224         pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
225         pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
226         addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
227                 pageLayoutModule->paperheightL);
228         addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
229                 pageLayoutModule->paperwidthL);
230
231         // paper
232         QComboBox * cb = pageLayoutModule->papersizeCO;
233         cb->addItem(qt_("Default"));
234         cb->addItem(qt_("Custom"));
235         cb->addItem(qt_("US letter"));
236         cb->addItem(qt_("US legal"));
237         cb->addItem(qt_("US executive"));
238         cb->addItem(qt_("A3"));
239         cb->addItem(qt_("A4"));
240         cb->addItem(qt_("A5"));
241         cb->addItem(qt_("B3"));
242         cb->addItem(qt_("B4"));
243         cb->addItem(qt_("B5"));
244         // remove the %-items from the unit choice
245         pageLayoutModule->paperwidthUnitCO->noPercents();
246         pageLayoutModule->paperheightUnitCO->noPercents();
247         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
248                 pageLayoutModule->paperheightLE));
249         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
250                 pageLayoutModule->paperwidthLE));
251
252
253
254
255         marginsModule = new UiWidget<Ui::MarginsUi>;
256         // margins
257         connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
258                 this, SLOT(setCustomMargins(bool)));
259         connect(marginsModule->marginCB, SIGNAL(clicked()),
260                 this, SLOT(change_adaptor()));
261         connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
262                 this, SLOT(change_adaptor()));
263         connect(marginsModule->topUnit, SIGNAL(activated(int)),
264                 this, SLOT(change_adaptor()));
265         connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
266                 this, SLOT(change_adaptor()));
267         connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
268                 this, SLOT(change_adaptor()));
269         connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
270                 this, SLOT(change_adaptor()));
271         connect(marginsModule->innerUnit, SIGNAL(activated(int)),
272                 this, SLOT(change_adaptor()));
273         connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
274                 this, SLOT(change_adaptor()));
275         connect(marginsModule->outerUnit, SIGNAL(activated(int)),
276                 this, SLOT(change_adaptor()));
277         connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
278                 this, SLOT(change_adaptor()));
279         connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
280                 this, SLOT(change_adaptor()));
281         connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
282                 this, SLOT(change_adaptor()));
283         connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
284                 this, SLOT(change_adaptor()));
285         connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
286                 this, SLOT(change_adaptor()));
287         connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
288                 this, SLOT(change_adaptor()));
289         marginsModule->topLE->setValidator(unsignedLengthValidator(
290                 marginsModule->topLE));
291         marginsModule->bottomLE->setValidator(unsignedLengthValidator(
292                 marginsModule->bottomLE));
293         marginsModule->innerLE->setValidator(unsignedLengthValidator(
294                 marginsModule->innerLE));
295         marginsModule->outerLE->setValidator(unsignedLengthValidator(
296                 marginsModule->outerLE));
297         marginsModule->headsepLE->setValidator(unsignedLengthValidator(
298                 marginsModule->headsepLE));
299         marginsModule->headheightLE->setValidator(unsignedLengthValidator(
300                 marginsModule->headheightLE));
301         marginsModule->footskipLE->setValidator(unsignedLengthValidator(
302                 marginsModule->footskipLE));
303
304         addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
305                 marginsModule->topL);
306         addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
307                 marginsModule->bottomL);
308         addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
309                 marginsModule->innerL);
310         addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
311                 marginsModule->outerL);
312         addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
313                 marginsModule->headsepL);
314         addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
315                 marginsModule->headheightL);
316         addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
317                 marginsModule->footskipL);
318
319
320         langModule = new UiWidget<Ui::LanguageUi>;
321         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)),
322                 langModule->encodingL, SLOT(setDisabled(bool)));
323         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)),
324                 langModule->encodingCO, SLOT(setDisabled(bool)));
325         // language & quote
326         connect(langModule->languageCO, SIGNAL(activated(int)),
327                 this, SLOT(change_adaptor()));
328         connect(langModule->defaultencodingCB, SIGNAL(clicked()),
329                 this, SLOT(change_adaptor()));
330         connect(langModule->encodingCO, SIGNAL(activated(int)),
331                 this, SLOT(change_adaptor()));
332         connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
333                 this, SLOT(change_adaptor()));
334         // language & quotes
335         vector<LanguagePair> const langs = getLanguageData(false);
336         vector<LanguagePair>::const_iterator lit  = langs.begin();
337         vector<LanguagePair>::const_iterator lend = langs.end();
338         for (; lit != lend; ++lit) {
339                 langModule->languageCO->addItem(
340                         toqstr(lit->first));
341         }
342
343         // Always put the default encoding in the first position.
344         // It is special because the displayed text is translated.
345         langModule->encodingCO->addItem(qt_("LaTeX default"));
346         Encodings::const_iterator it = encodings.begin();
347         Encodings::const_iterator const end = encodings.end();
348         for (; it != end; ++it)
349                 langModule->encodingCO->addItem(toqstr(it->latexName()));
350
351         langModule->quoteStyleCO->addItem(qt_("``text''"));
352         langModule->quoteStyleCO->addItem(qt_("''text''"));
353         langModule->quoteStyleCO->addItem(qt_(",,text``"));
354         langModule->quoteStyleCO->addItem(qt_(",,text''"));
355         langModule->quoteStyleCO->addItem(qt_("<<text>>"));
356         langModule->quoteStyleCO->addItem(qt_(">>text<<"));
357
358
359
360         numberingModule = new UiWidget<Ui::NumberingUi>;
361         // numbering
362         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
363                 this, SLOT(change_adaptor()));
364         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
365                 this, SLOT(change_adaptor()));
366         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
367                 this, SLOT(updateNumbering()));
368         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
369                 this, SLOT(updateNumbering()));
370         numberingModule->tocTW->setColumnCount(3);
371         numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
372         numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
373         numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
374
375
376         biblioModule = new UiWidget<Ui::BiblioUi>;
377         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
378                 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
379         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
380                 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
381         // biblio
382         connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
383                 this, SLOT(change_adaptor()));
384         connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
385                 this, SLOT(change_adaptor()));
386         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
387                 this, SLOT(change_adaptor()));
388         connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
389                 this, SLOT(change_adaptor()));
390         connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
391                 this, SLOT(change_adaptor()));
392         // biblio
393         biblioModule->citeStyleCO->addItem(qt_("Author-year"));
394         biblioModule->citeStyleCO->addItem(qt_("Numerical"));
395         biblioModule->citeStyleCO->setCurrentIndex(0);
396
397
398
399         mathsModule = new UiWidget<Ui::MathsUi>;
400         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
401                 mathsModule->amsCB, SLOT(setDisabled(bool)));
402         connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
403                 mathsModule->esintCB, SLOT(setDisabled(bool)));
404         // maths
405         connect(mathsModule->amsCB, SIGNAL(clicked()),
406                 this, SLOT(change_adaptor()));
407         connect(mathsModule->amsautoCB, SIGNAL(clicked()),
408                 this, SLOT(change_adaptor()));
409         connect(mathsModule->esintCB, SIGNAL(clicked()),
410                 this, SLOT(change_adaptor()));
411         connect(mathsModule->esintautoCB, SIGNAL(clicked()),
412                 this, SLOT(change_adaptor()));
413
414         latexModule = new UiWidget<Ui::LaTeXUi>;
415         // latex class
416         connect(latexModule->classCO, SIGNAL(activated(int)),
417                 this, SLOT(change_adaptor()));
418         connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
419                 this, SLOT(change_adaptor()));
420         connect(latexModule->psdriverCO, SIGNAL(activated(int)),
421                 this, SLOT(change_adaptor()));
422         connect(latexModule->classCO, SIGNAL(activated(int)),
423                 this, SLOT(classChanged()));
424         // packages
425         for (int n = 0; tex_graphics[n][0]; ++n) {
426                 QString enc = tex_graphics[n];
427                 latexModule->psdriverCO->addItem(enc);
428         }
429         // latex
430         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
431              cit != textclasslist.end(); ++cit) {
432                 if (cit->isTeXClassAvailable()) {
433                         latexModule->classCO->addItem(toqstr(cit->description()));
434                 } else {
435                         docstring item =
436                                 bformat(_("Unavailable: %1$s"), lyx::from_utf8(cit->description()));
437                         latexModule->classCO->addItem(toqstr(item));
438                 }
439         }
440
441         // branches
442         branchesModule = new QBranches;
443         connect(branchesModule, SIGNAL(changed()),
444                 this, SLOT(change_adaptor()));
445
446         // preamble
447         preambleModule = new UiWidget<Ui::PreambleUi>;
448         connect(preambleModule->preambleTE, SIGNAL(textChanged()),
449                 this, SLOT(change_adaptor()));
450         // This is not a memory leak. The object will be destroyed
451         // with preambleModule.
452         (void) new LaTeXHighlighter(preambleModule->preambleTE->document());
453
454
455         // bullets
456         bulletsModule = new BulletsModule;
457         connect(bulletsModule, SIGNAL(changed()),
458                 this, SLOT(change_adaptor()));
459
460
461         // float
462         floatModule = new FloatPlacement;
463         connect(floatModule, SIGNAL(changed()),
464                 this, SLOT(change_adaptor()));
465
466         docPS->addPanel(latexModule, _("Document Class"));
467         docPS->addPanel(fontModule, _("Fonts"));
468         docPS->addPanel(textLayoutModule, _("Text Layout"));
469         docPS->addPanel(pageLayoutModule, _("Page Layout"));
470         docPS->addPanel(marginsModule, _("Page Margins"));
471         docPS->addPanel(langModule, _("Language"));
472         docPS->addPanel(numberingModule, _("Numbering & TOC"));
473         docPS->addPanel(biblioModule, _("Bibliography"));
474         docPS->addPanel(mathsModule, _("Math Options"));
475         docPS->addPanel(floatModule, _("Float Placement"));
476         docPS->addPanel(bulletsModule, _("Bullets"));
477         docPS->addPanel(branchesModule, _("Branches"));
478         docPS->addPanel(preambleModule, _("LaTeX Preamble"));
479         docPS->setCurrentPanel(_("Document Class"));
480 // FIXME: hack to work around resizing bug in Qt >= 4.2
481 // bug verified with Qt 4.2.{0-3} (JSpitzm)
482 #if QT_VERSION >= 0x040200
483         docPS->updateGeometry();
484 #endif
485 }
486
487
488 void QDocumentDialog::showPreamble()
489 {
490         docPS->setCurrentPanel(_("LaTeX Preamble"));
491 }
492
493
494 void QDocumentDialog::saveDefaultClicked()
495 {
496         form_->saveDocDefault();
497 }
498
499
500 void QDocumentDialog::useDefaultsClicked()
501 {
502         form_->useClassDefaults();
503 }
504
505
506 void QDocumentDialog::change_adaptor()
507 {
508         form_->changed();
509 }
510
511
512 void QDocumentDialog::closeEvent(QCloseEvent * e)
513 {
514         form_->slotWMHide();
515         e->accept();
516 }
517
518
519 void QDocumentDialog::setLSpacing(int item)
520 {
521         textLayoutModule->lspacingLE->setEnabled(item == 3);
522 }
523
524
525 void QDocumentDialog::setSkip(int item)
526 {
527         bool const enable = (item == 3);
528         textLayoutModule->skipLE->setEnabled(enable);
529         textLayoutModule->skipLengthCO->setEnabled(enable);
530 }
531
532
533 void QDocumentDialog::enableSkip(bool skip)
534 {
535         textLayoutModule->skipCO->setEnabled(skip);
536         textLayoutModule->skipLE->setEnabled(skip);
537         textLayoutModule->skipLengthCO->setEnabled(skip);
538         if (skip)
539                 setSkip(textLayoutModule->skipCO->currentIndex());
540 }
541
542 void QDocumentDialog::portraitChanged()
543 {
544         setMargins(pageLayoutModule->papersizeCO->currentIndex());
545 }
546
547 void QDocumentDialog::setMargins(bool custom)
548 {
549         marginsModule->marginCB->setChecked(custom);
550         setCustomMargins(custom);
551 }
552
553
554 void QDocumentDialog::setCustomPapersize(int papersize)
555 {
556         bool const custom = (papersize == 1);
557
558         pageLayoutModule->paperwidthL->setEnabled(custom);
559         pageLayoutModule->paperwidthLE->setEnabled(custom);
560         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
561         pageLayoutModule->paperheightL->setEnabled(custom);
562         pageLayoutModule->paperheightLE->setEnabled(custom);
563         pageLayoutModule->paperheightLE->setFocus();
564         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
565 }
566
567
568 void QDocumentDialog::setCustomMargins(bool custom)
569 {
570         marginsModule->topL->setEnabled(!custom);
571         marginsModule->topLE->setEnabled(!custom);
572         marginsModule->topUnit->setEnabled(!custom);
573
574         marginsModule->bottomL->setEnabled(!custom);
575         marginsModule->bottomLE->setEnabled(!custom);
576         marginsModule->bottomUnit->setEnabled(!custom);
577
578         marginsModule->innerL->setEnabled(!custom);
579         marginsModule->innerLE->setEnabled(!custom);
580         marginsModule->innerUnit->setEnabled(!custom);
581
582         marginsModule->outerL->setEnabled(!custom);
583         marginsModule->outerLE->setEnabled(!custom);
584         marginsModule->outerUnit->setEnabled(!custom);
585
586         marginsModule->headheightL->setEnabled(!custom);
587         marginsModule->headheightLE->setEnabled(!custom);
588         marginsModule->headheightUnit->setEnabled(!custom);
589
590         marginsModule->headsepL->setEnabled(!custom);
591         marginsModule->headsepLE->setEnabled(!custom);
592         marginsModule->headsepUnit->setEnabled(!custom);
593
594         marginsModule->footskipL->setEnabled(!custom);
595         marginsModule->footskipLE->setEnabled(!custom);
596         marginsModule->footskipUnit->setEnabled(!custom);
597 }
598
599
600 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
601 {
602         fontModule->fontsizeCO->clear();
603         fontModule->fontsizeCO->addItem(qt_("default"));
604
605         for (int n = 0; !token(items,'|',n).empty(); ++n)
606                 fontModule->fontsizeCO->
607                         addItem(toqstr(token(items,'|',n)));
608
609         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
610                 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
611                         fontModule->fontsizeCO->setCurrentIndex(n);
612                         break;
613                 }
614         }
615 }
616
617
618 void QDocumentDialog::romanChanged(int item)
619 {
620         string const font = tex_fonts_roman[item];
621         
622         fontModule->fontScCB->setEnabled(
623                 form_->controller().providesSC(font));
624         fontModule->fontOsfCB->setEnabled(
625                 form_->controller().providesOSF(font));
626 }
627
628
629 void QDocumentDialog::sansChanged(int item)
630 {
631         string const font = tex_fonts_sans[item];
632         bool scaleable = form_->controller().providesScale(font);
633         fontModule->scaleSansSB->setEnabled(scaleable);
634         fontModule->scaleSansLA->setEnabled(scaleable);
635 }
636
637
638 void QDocumentDialog::ttChanged(int item)
639 {
640         string const font = tex_fonts_monospaced[item];
641         bool scaleable = form_->controller().providesScale(font);
642         fontModule->scaleTypewriterSB->setEnabled(scaleable);
643         fontModule->scaleTypewriterLA->setEnabled(scaleable);
644 }
645
646
647 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
648 {
649         pageLayoutModule->pagestyleCO->clear();
650         pageLayoutModule->pagestyleCO->addItem("default");
651
652         for (int n=0; !token(items,'|',n).empty(); ++n)
653                 pageLayoutModule->pagestyleCO->
654                         addItem(toqstr(token(items,'|',n)));
655
656         for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
657                 if (fromqstr(pageLayoutModule->pagestyleCO->itemText(n))==sel) {
658                         pageLayoutModule->pagestyleCO->setCurrentIndex(n);
659                         break;
660                 }
661         }
662 }
663
664
665 void QDocumentDialog::classChanged()
666 {
667         ControlDocument & cntrl = form_->controller();
668         BufferParams & params = cntrl.params();
669
670         lyx::textclass_type const tc = latexModule->classCO->currentIndex();
671
672         if (form_->controller().loadTextclass(tc)) {
673                 params.textclass = tc;
674                 if (lyxrc.auto_reset_options)
675                         params.useClassDefaults();
676                 form_->update_contents();
677         } else {
678                 latexModule->classCO->setCurrentIndex(params.textclass);
679         }
680 }
681
682
683 void QDocumentDialog::updateNumbering()
684 {
685         LyXTextClass const & tclass =
686                 form_->controller().params().getLyXTextClass();
687
688         numberingModule->tocTW->setUpdatesEnabled(false);
689         numberingModule->tocTW->clear();
690
691         int const depth = numberingModule->depthSL->value();
692         int const toc = numberingModule->tocSL->value();
693         QString const no = qt_("No");
694         QString const yes = qt_("Yes");
695         LyXTextClass::const_iterator end = tclass.end();
696         LyXTextClass::const_iterator cit = tclass.begin();
697         QTreeWidgetItem * item = 0;
698         for ( ; cit != end ; ++cit) {
699                 int const toclevel = (*cit)->toclevel;
700                 if (toclevel != LyXLayout::NOT_IN_TOC 
701                     && (*cit)->labeltype == LABEL_COUNTER) {
702                         item = new QTreeWidgetItem(numberingModule->tocTW);
703                         item->setText(0, qt_((*cit)->name()));
704                         item->setText(1, (toclevel <= depth) ? yes : no);
705                         item->setText(2, (toclevel <= toc) ? yes : no);
706                 }
707         }
708
709         numberingModule->tocTW->setUpdatesEnabled(true);
710         numberingModule->tocTW->update();
711 }
712
713 void QDocumentDialog::apply(BufferParams & params)
714 {
715         // preamble
716         params.preamble =
717                 fromqstr(preambleModule->preambleTE->document()->toPlainText());
718
719         // biblio
720         params.setCiteEngine(biblio::ENGINE_BASIC);
721
722         if (biblioModule->citeNatbibRB->isChecked()) {
723                 bool const use_numerical_citations =
724                         biblioModule->citeStyleCO->currentIndex();
725                 if (use_numerical_citations)
726                         params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
727                 else
728                         params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
729
730         } else if (biblioModule->citeJurabibRB->isChecked())
731                 params.setCiteEngine(biblio::ENGINE_JURABIB);
732
733         params.use_bibtopic =
734                 biblioModule->bibtopicCB->isChecked();
735
736         // language & quotes
737         if (langModule->defaultencodingCB->isChecked()) {
738                 params.inputenc = "auto";
739         } else {
740                 int i = langModule->encodingCO->currentIndex();
741                 if (i == 0)
742                         params.inputenc = "default";
743                 else
744                         params.inputenc =
745                                 fromqstr(langModule->encodingCO->currentText());
746         }
747
748         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
749         switch (langModule->quoteStyleCO->currentIndex()) {
750         case 0:
751                 lga = InsetQuotes::EnglishQ;
752                 break;
753         case 1:
754                 lga = InsetQuotes::SwedishQ;
755                 break;
756         case 2:
757                 lga = InsetQuotes::GermanQ;
758                 break;
759         case 3:
760                 lga = InsetQuotes::PolishQ;
761                 break;
762         case 4:
763                 lga = InsetQuotes::FrenchQ;
764                 break;
765         case 5:
766                 lga = InsetQuotes::DanishQ;
767                 break;
768         }
769         params.quotes_language = lga;
770
771         int const pos = langModule->languageCO->currentIndex();
772         params.language = languages.getLanguage(lang_[pos]);
773
774         // numbering
775         if (params.getLyXTextClass().hasTocLevels()) {
776                 params.tocdepth = numberingModule->tocSL->value();
777                 params.secnumdepth = numberingModule->depthSL->value();
778         }
779
780         // bullets
781         params.user_defined_bullet(0) = bulletsModule->getBullet(0);
782         params.user_defined_bullet(1) = bulletsModule->getBullet(1);
783         params.user_defined_bullet(2) = bulletsModule->getBullet(2);
784         params.user_defined_bullet(3) = bulletsModule->getBullet(3);
785
786         // packages
787         params.graphicsDriver =
788                 fromqstr(latexModule->psdriverCO->currentText());
789
790         if (mathsModule->amsautoCB->isChecked()) {
791                 params.use_amsmath = BufferParams::package_auto;
792         } else {
793                 if (mathsModule->amsCB->isChecked())
794                         params.use_amsmath = BufferParams::package_on;
795                 else
796                         params.use_amsmath = BufferParams::package_off;
797         }
798
799         if (mathsModule->esintautoCB->isChecked())
800                 params.use_esint = BufferParams::package_auto;
801         else {
802                 if (mathsModule->esintCB->isChecked())
803                         params.use_esint = BufferParams::package_on;
804                 else
805                         params.use_esint = BufferParams::package_off;
806         }
807
808         // text layout
809         params.textclass =
810                 latexModule->classCO->currentIndex();
811
812         params.pagestyle =
813                 fromqstr(pageLayoutModule->pagestyleCO->currentText());
814
815         switch (textLayoutModule->lspacingCO->currentIndex()) {
816         case 0:
817                 params.spacing().set(Spacing::Single);
818                 break;
819         case 1:
820                 params.spacing().set(Spacing::Onehalf);
821                 break;
822         case 2:
823                 params.spacing().set(Spacing::Double);
824                 break;
825         case 3:
826                 params.spacing().set(Spacing::Other,
827                         fromqstr(textLayoutModule->lspacingLE->text()));
828                 break;
829         }
830
831         if (textLayoutModule->twoColumnCB->isChecked())
832                 params.columns = 2;
833         else
834                 params.columns = 1;
835
836         if (textLayoutModule->indentRB->isChecked())
837                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
838         else
839                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
840
841         switch (textLayoutModule->skipCO->currentIndex()) {
842         case 0:
843                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
844                 break;
845         case 1:
846                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
847                 break;
848         case 2:
849                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
850                 break;
851         case 3:
852         {
853                 VSpace vs = VSpace(
854                         widgetsToLength(textLayoutModule->skipLE,
855                                 textLayoutModule->skipLengthCO)
856                         );
857                 params.setDefSkip(vs);
858                 break;
859         }
860         default:
861                 // DocumentDefskipCB assures that this never happens
862                 // so Assert then !!!  - jbl
863                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
864                 break;
865         }
866
867         params.options =
868                 fromqstr(latexModule->optionsLE->text());
869
870         params.float_placement = floatModule->get();
871
872         // fonts
873         params.fontsRoman =
874                 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
875
876         params.fontsSans =
877                 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
878
879         params.fontsTypewriter =
880                 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
881
882         params.fontsSansScale = fontModule->scaleSansSB->value();
883
884         params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
885
886         params.fontsSC = fontModule->fontScCB->isChecked();
887
888         params.fontsOSF = fontModule->fontOsfCB->isChecked();
889
890         params.fontsDefaultFamily = ControlDocument::fontfamilies[
891                 fontModule->fontsDefaultCO->currentIndex()];
892
893         if (fontModule->fontsizeCO->currentIndex() == 0)
894                 params.fontsize = "default";
895         else
896                 params.fontsize =
897                         fromqstr(fontModule->fontsizeCO->currentText());
898
899         // paper
900         params.papersize = PAPER_SIZE(
901                 pageLayoutModule->papersizeCO->currentIndex());
902
903         // custom, A3, B3 and B4 paper sizes need geometry
904         int psize = pageLayoutModule->papersizeCO->currentIndex();
905         bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
906
907         params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
908                 pageLayoutModule->paperwidthUnitCO);
909
910         params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
911                 pageLayoutModule->paperheightUnitCO);
912
913         if (pageLayoutModule->facingPagesCB->isChecked())
914                 params.sides = LyXTextClass::TwoSides;
915         else
916                 params.sides = LyXTextClass::OneSide;
917
918         if (pageLayoutModule->landscapeRB->isChecked())
919                 params.orientation = ORIENTATION_LANDSCAPE;
920         else
921                 params.orientation = ORIENTATION_PORTRAIT;
922
923         // margins
924         params.use_geometry =
925                 (!marginsModule->marginCB->isChecked()
926                 || geom_papersize);
927
928         Ui::MarginsUi const * m(marginsModule);
929
930         params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
931
932         params.topmargin = widgetsToLength(m->topLE, m->topUnit);
933
934         params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
935
936         params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
937
938         params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
939
940         params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
941
942         params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
943
944         branchesModule->apply(params);
945 }
946
947 namespace {
948
949 /** Return the position of val in the vector if found.
950     If not found, return 0.
951  */
952 template<class A>
953 typename std::vector<A>::size_type
954 findPos(std::vector<A> const & vec, A const & val)
955 {
956         typename std::vector<A>::const_iterator it =
957                 std::find(vec.begin(), vec.end(), val);
958         if (it == vec.end())
959                 return 0;
960         return distance(vec.begin(), it);
961 }
962
963 } // namespace anom
964
965
966 void QDocumentDialog::updateParams(BufferParams const & params)
967 {
968         // set the default unit
969         // FIXME: move to controller
970         LyXLength::UNIT defaultUnit = LyXLength::CM;
971         switch (lyxrc.default_papersize) {
972                 case PAPER_DEFAULT: break;
973
974                 case PAPER_USLETTER:
975                 case PAPER_USLEGAL:
976                 case PAPER_USEXECUTIVE:
977                         defaultUnit = LyXLength::IN;
978                         break;
979
980                 case PAPER_A3:
981                 case PAPER_A4:
982                 case PAPER_A5:
983                 case PAPER_B3:
984                 case PAPER_B4:
985                 case PAPER_B5:
986                         defaultUnit = LyXLength::CM;
987                         break;
988                 case PAPER_CUSTOM:
989                         break;
990         }
991
992         // preamble
993         QString preamble = toqstr(params.preamble);
994         preambleModule->preambleTE->document()->setPlainText(preamble);
995
996         // biblio
997         biblioModule->citeDefaultRB->setChecked(
998                 params.getEngine() == biblio::ENGINE_BASIC);
999
1000         biblioModule->citeNatbibRB->setChecked(
1001                 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1002                 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1003
1004         biblioModule->citeStyleCO->setCurrentIndex(
1005                 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1006
1007         biblioModule->citeJurabibRB->setChecked(
1008                 params.getEngine() == biblio::ENGINE_JURABIB);
1009
1010         biblioModule->bibtopicCB->setChecked(
1011                 params.use_bibtopic);
1012
1013         // language & quotes
1014         int const pos = int(findPos(lang_,
1015                                     params.language->lang()));
1016         langModule->languageCO->setCurrentIndex(pos);
1017
1018         langModule->quoteStyleCO->setCurrentIndex(
1019                 params.quotes_language);
1020
1021         langModule->defaultencodingCB->setChecked(true);
1022
1023         if (params.inputenc != "auto") {
1024                 langModule->defaultencodingCB->setChecked(false);
1025                 if (params.inputenc == "default") {
1026                         langModule->encodingCO->setCurrentIndex(0);
1027                 } else {
1028                         int const i = langModule->encodingCO->findText(
1029                                         toqstr(params.inputenc));
1030                         if (i >= 0)
1031                                 langModule->encodingCO->setCurrentIndex(i);
1032                         else
1033                                 // unknown encoding. Set to default.
1034                                 langModule->defaultencodingCB->setChecked(true);
1035                 }
1036         }
1037
1038         // numbering
1039         int const min_toclevel = form_->controller().textClass().min_toclevel();
1040         int const max_toclevel = form_->controller().textClass().max_toclevel();
1041         if (form_->controller().textClass().hasTocLevels()) {
1042                 numberingModule->setEnabled(true);
1043                 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1044                 numberingModule->depthSL->setMaximum(max_toclevel);
1045                 numberingModule->depthSL->setValue(params.secnumdepth);
1046                 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1047                 numberingModule->tocSL->setMaximum(max_toclevel);
1048                 numberingModule->tocSL->setValue(params.tocdepth);
1049                 updateNumbering();
1050         } else {
1051                 numberingModule->setEnabled(false);
1052                 numberingModule->tocTW->clear();
1053         }
1054
1055         // bullets
1056         bulletsModule->setBullet(0, params.user_defined_bullet(0));
1057         bulletsModule->setBullet(1, params.user_defined_bullet(1));
1058         bulletsModule->setBullet(2, params.user_defined_bullet(2));
1059         bulletsModule->setBullet(3, params.user_defined_bullet(3));
1060         bulletsModule->init();
1061
1062         // packages
1063         QString text = toqstr(params.graphicsDriver);
1064         int nitem = latexModule->psdriverCO->count();
1065         for (int n = 0; n < nitem ; ++n) {
1066                 QString enc = tex_graphics[n];
1067                 if (enc == text) {
1068                         latexModule->psdriverCO->setCurrentIndex(n);
1069                 }
1070         }
1071
1072
1073         mathsModule->amsCB->setChecked(
1074                 params.use_amsmath == BufferParams::package_on);
1075         mathsModule->amsautoCB->setChecked(
1076                 params.use_amsmath == BufferParams::package_auto);
1077
1078         mathsModule->esintCB->setChecked(
1079                 params.use_esint == BufferParams::package_on);
1080         mathsModule->esintautoCB->setChecked(
1081                 params.use_esint == BufferParams::package_auto);
1082
1083         switch (params.spacing().getSpace()) {
1084                 case Spacing::Other: nitem = 3; break;
1085                 case Spacing::Double: nitem = 2; break;
1086                 case Spacing::Onehalf: nitem = 1; break;
1087                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1088         }
1089
1090         // text layout
1091         latexModule->classCO->setCurrentIndex(params.textclass);
1092
1093         updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1094                                  params.pagestyle);
1095
1096         textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1097         if (params.spacing().getSpace() == Spacing::Other) {
1098                 textLayoutModule->lspacingLE->setText(
1099                         toqstr(params.spacing().getValueAsString()));
1100         }
1101         setLSpacing(nitem);
1102
1103         if (params.paragraph_separation
1104             == BufferParams::PARSEP_INDENT) {
1105                 textLayoutModule->indentRB->setChecked(true);
1106         } else {
1107                 textLayoutModule->skipRB->setChecked(true);
1108         }
1109
1110         int skip = 0;
1111         switch (params.getDefSkip().kind()) {
1112         case VSpace::SMALLSKIP:
1113                 skip = 0;
1114                 break;
1115         case VSpace::MEDSKIP:
1116                 skip = 1;
1117                 break;
1118         case VSpace::BIGSKIP:
1119                 skip = 2;
1120                 break;
1121         case VSpace::LENGTH:
1122         {
1123                 skip = 3;
1124                 string const length = params.getDefSkip().asLyXCommand();
1125                 lengthToWidgets(textLayoutModule->skipLE,
1126                         textLayoutModule->skipLengthCO,
1127                         length, defaultUnit);
1128                 break;
1129         }
1130         default:
1131                 skip = 0;
1132                 break;
1133         }
1134         textLayoutModule->skipCO->setCurrentIndex(skip);
1135         setSkip(skip);
1136
1137         textLayoutModule->twoColumnCB->setChecked(
1138                 params.columns == 2);
1139
1140         if (!params.options.empty()) {
1141                 latexModule->optionsLE->setText(
1142                         toqstr(params.options));
1143         } else {
1144                 latexModule->optionsLE->setText("");
1145         }
1146
1147         floatModule->set(params.float_placement);
1148
1149         //fonts
1150         updateFontsize(form_->controller().textClass().opt_fontsize(),
1151                         params.fontsize);
1152
1153         int n = findToken(tex_fonts_roman, params.fontsRoman);
1154         if (n >= 0) {
1155                 fontModule->fontsRomanCO->setCurrentIndex(n);
1156                 romanChanged(n);
1157         }
1158
1159         n = findToken(tex_fonts_sans, params.fontsSans);
1160         if (n >= 0)     {
1161                 fontModule->fontsSansCO->setCurrentIndex(n);
1162                 sansChanged(n);
1163         }
1164
1165         n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1166         if (n >= 0) {
1167                 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1168                 ttChanged(n);
1169         }
1170
1171         fontModule->fontScCB->setChecked(params.fontsSC);
1172         fontModule->fontOsfCB->setChecked(params.fontsOSF);
1173         fontModule->scaleSansSB->setValue(params.fontsSansScale);
1174         fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1175         n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
1176         if (n >= 0)
1177                 fontModule->fontsDefaultCO->setCurrentIndex(n);
1178
1179         // paper
1180         int const psize = params.papersize;
1181         pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1182         setCustomPapersize(psize);
1183
1184         bool const landscape =
1185                 params.orientation == ORIENTATION_LANDSCAPE;
1186         pageLayoutModule->landscapeRB->setChecked(landscape);
1187         pageLayoutModule->portraitRB->setChecked(!landscape);
1188
1189         pageLayoutModule->facingPagesCB->setChecked(
1190                 params.sides == LyXTextClass::TwoSides);
1191
1192
1193         lengthToWidgets(pageLayoutModule->paperwidthLE,
1194                 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1195
1196         lengthToWidgets(pageLayoutModule->paperheightLE,
1197                 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1198
1199         // margins
1200         Ui::MarginsUi * m = marginsModule;
1201
1202         setMargins(!params.use_geometry);
1203
1204         lengthToWidgets(m->topLE, m->topUnit,
1205                 params.topmargin, defaultUnit);
1206
1207         lengthToWidgets(m->bottomLE, m->bottomUnit,
1208                 params.bottommargin, defaultUnit);
1209
1210         lengthToWidgets(m->innerLE, m->innerUnit,
1211                 params.leftmargin, defaultUnit);
1212
1213         lengthToWidgets(m->outerLE, m->outerUnit,
1214                 params.rightmargin, defaultUnit);
1215
1216         lengthToWidgets(m->headheightLE, m->headheightUnit,
1217                 params.headheight, defaultUnit);
1218
1219         lengthToWidgets(m->headsepLE, m->headsepUnit,
1220                 params.headsep, defaultUnit);
1221
1222         lengthToWidgets(m->footskipLE, m->footskipUnit,
1223                 params.footskip, defaultUnit);
1224
1225         branchesModule->update(params);
1226 }
1227
1228
1229
1230 /////////////////////////////////////////////////////////////////////
1231 //
1232 // Document
1233 //
1234 /////////////////////////////////////////////////////////////////////
1235
1236 typedef QController<ControlDocument, QView<QDocumentDialog> >
1237         DocumentBase;
1238
1239
1240 QDocument::QDocument(Dialog & parent)
1241         : DocumentBase(parent, _("Document Settings"))
1242 {}
1243
1244
1245 void QDocument::build_dialog()
1246 {
1247         dialog_.reset(new QDocumentDialog(this));
1248 }
1249
1250
1251 void QDocument::showPreamble()
1252 {
1253         dialog_->showPreamble();
1254 }
1255
1256
1257 void QDocument::apply()
1258 {
1259         if (!dialog_.get())
1260                 return;
1261
1262         dialog_->apply(controller().params());
1263 }
1264
1265
1266 void QDocument::update_contents()
1267 {
1268         if (!dialog_.get())
1269                 return;
1270
1271         dialog_->updateParams(controller().params());
1272 }
1273
1274 void QDocument::saveDocDefault()
1275 {
1276         // we have to apply the params first
1277         apply();
1278         controller().saveAsDefault();
1279 }
1280
1281
1282 void QDocument::useClassDefaults()
1283 {
1284         BufferParams & params = controller().params();
1285
1286         ///\todo verify the use of below with lyx-devel:
1287         params.textclass = dialog_->latexModule->classCO->currentIndex();
1288
1289         params.useClassDefaults();
1290         update_contents();
1291 }
1292
1293 } // namespace frontend
1294 } // namespace lyx
1295
1296 #include "QDocument_moc.cpp"