]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QDocument.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / qt2 / 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 "checkedwidgets.h"
14 #include "QDocument.h"
15 #include "QDocumentDialog.h"
16 #include "Qt2BC.h"
17 #include "qt_helpers.h"
18
19 #include "bufferparams.h"
20 #include "floatplacement.h"
21 #include "gettext.h"
22 #include "helper_funcs.h" // getSecond()
23 #include "language.h"
24 #include "lyxrc.h" // defaultUnit
25 #include "lyxtextclasslist.h"
26 #include "tex-strings.h" // tex_graphics
27
28 #include "support/lstrings.h"
29
30 #include "controllers/ControlDocument.h"
31 #include "controllers/frnt_lang.h"
32
33 #include <qpushbutton.h>
34 #include <qmultilineedit.h>
35 #include <qradiobutton.h>
36 #include <qcheckbox.h>
37 #include <qslider.h>
38 #include <qlineedit.h>
39 #include "lengthcombo.h"
40
41
42 using lyx::support::bformat;
43 using lyx::support::getVectorFromString;
44
45 using std::distance;
46 using std::vector;
47 using std::string;
48
49 namespace lyx {
50 namespace frontend {
51
52 typedef QController<ControlDocument, QView<QDocumentDialog> > base_class;
53
54
55 namespace {
56
57 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
58         "latin3", "latin4", "latin5", "latin9",
59         "koi8-r", "koi8-u", "cp866", "cp1251",
60         "iso88595", "pt154", 0
61 };
62
63 }
64
65
66 QDocument::QDocument(Dialog & parent)
67         : base_class(parent, _("LyX: Document Settings")),
68                 lang_(getSecond(getLanguageData(false)))
69 {}
70
71
72 void QDocument::build_dialog()
73 {
74         dialog_.reset(new QDocumentDialog(this));
75
76         // biblio
77         dialog_->biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
78         dialog_->biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
79         dialog_->biblioModule->citeStyleCO->setCurrentItem(0);
80
81         // language & quotes
82         vector<LanguagePair> const langs = getLanguageData(false);
83         vector<LanguagePair>::const_iterator lit  = langs.begin();
84         vector<LanguagePair>::const_iterator lend = langs.end();
85         for (; lit != lend; ++lit) {
86                 dialog_->langModule->languageCO->insertItem(
87                         toqstr(lit->first));
88         }
89
90         int i = 0;
91         while (encodings[i]) {
92                 dialog_->langModule->encodingCO->insertItem(qt_(encodings[i++]));
93         }
94
95         dialog_->langModule->quoteStyleCO->insertItem(qt_("``text''"));
96         dialog_->langModule->quoteStyleCO->insertItem(qt_("''text''"));
97         dialog_->langModule->quoteStyleCO->insertItem(qt_(",,text``"));
98         dialog_->langModule->quoteStyleCO->insertItem(qt_(",,text''"));
99         dialog_->langModule->quoteStyleCO->insertItem(qt_("<<text>>"));
100         dialog_->langModule->quoteStyleCO->insertItem(qt_(">>text<<"));
101
102         // packages
103         for (int n = 0; tex_graphics[n][0]; ++n) {
104                 QString enc = tex_graphics[n];
105                 dialog_->latexModule->psdriverCO->insertItem(enc);
106         }
107
108         // paper
109         QComboBox * cb = dialog_->pageLayoutModule->papersizeCO;
110         cb->insertItem(qt_("Default"));
111         cb->insertItem(qt_("Custom"));
112         cb->insertItem(qt_("US letter"));
113         cb->insertItem(qt_("US legal"));
114         cb->insertItem(qt_("US executive"));
115         cb->insertItem(qt_("A3"));
116         cb->insertItem(qt_("A4"));
117         cb->insertItem(qt_("A5"));
118         cb->insertItem(qt_("B3"));
119         cb->insertItem(qt_("B4"));
120         cb->insertItem(qt_("B5"));
121         // remove the %-items from the unit choice
122         dialog_->pageLayoutModule->paperwidthUnitCO->noPercents();
123         dialog_->pageLayoutModule->paperheightUnitCO->noPercents();
124
125         // layout
126         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
127              cit != textclasslist.end(); ++cit) {
128                 if (cit->isTeXClassAvailable()) {
129                         dialog_->latexModule->classCO->insertItem(toqstr(cit->description()));
130                 } else {
131                         string item =
132                                 bformat(_("Unavailable: %1$s"), cit->description());
133                         dialog_->latexModule->classCO->insertItem(toqstr(item));
134                 }
135         }
136
137         for (int n = 0; tex_fonts[n][0]; ++n) {
138                 QString font = tex_fonts[n];
139                 dialog_->textLayoutModule->fontsCO->insertItem(font);
140         }
141
142         dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("default"));
143         dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("10"));
144         dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("11"));
145         dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("12"));
146
147         dialog_->textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
148         dialog_->textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
149         dialog_->textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
150         dialog_->textLayoutModule->skipCO->insertItem(qt_("Length"));
151         // remove the %-items from the unit choice
152         dialog_->textLayoutModule->skipLengthCO->noPercents();
153
154         dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
155         dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
156         dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
157         dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
158         dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
159
160         dialog_->textLayoutModule->lspacingCO->insertItem(
161                 qt_("Single"), Spacing::Single);
162         dialog_->textLayoutModule->lspacingCO->insertItem(
163                 qt_("OneHalf"), Spacing::Onehalf);
164         dialog_->textLayoutModule->lspacingCO->insertItem(
165                 qt_("Double"), Spacing::Double);
166         dialog_->textLayoutModule->lspacingCO->insertItem(
167                 qt_("Custom"), Spacing::Other);
168
169         // margins
170         dialog_->setMargins(0);
171
172         // Manage the restore, ok, apply, restore and cancel/close buttons
173         bcview().setOK(dialog_->okPB);
174         bcview().setApply(dialog_->applyPB);
175         bcview().setCancel(dialog_->closePB);
176         bcview().setRestore(dialog_->restorePB);
177
178         // initialize the length validator
179         addCheckedLineEdit(bcview(), dialog_->textLayoutModule->skipLE);
180         addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperheightLE,
181                 dialog_->pageLayoutModule->paperheightL);
182         addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperwidthLE,
183                 dialog_->pageLayoutModule->paperwidthL);
184         addCheckedLineEdit(bcview(), dialog_->marginsModule->topLE,
185                 dialog_->marginsModule->topL);
186         addCheckedLineEdit(bcview(), dialog_->marginsModule->bottomLE,
187                 dialog_->marginsModule->bottomL);
188         addCheckedLineEdit(bcview(), dialog_->marginsModule->innerLE,
189                 dialog_->marginsModule->innerL);
190         addCheckedLineEdit(bcview(), dialog_->marginsModule->outerLE,
191                 dialog_->marginsModule->outerL);
192         addCheckedLineEdit(bcview(), dialog_->marginsModule->headsepLE,
193                 dialog_->marginsModule->headsepL);
194         addCheckedLineEdit(bcview(), dialog_->marginsModule->headheightLE,
195                 dialog_->marginsModule->headheightL);
196         addCheckedLineEdit(bcview(), dialog_->marginsModule->footskipLE,
197                 dialog_->marginsModule->footskipL);
198 }
199
200
201 void QDocument::showPreamble()
202 {
203         dialog_->showPreamble();
204 }
205
206
207 void QDocument::apply()
208 {
209         BufferParams & params = controller().params();
210
211         // preamble
212         params.preamble =
213                 fromqstr(dialog_->preambleModule->preambleMLE->text());
214
215         // biblio
216         params.cite_engine = biblio::ENGINE_BASIC;
217
218         if (dialog_->biblioModule->citeNatbibRB->isChecked()) {
219                 bool const use_numerical_citations =
220                         dialog_->biblioModule->citeStyleCO->currentItem();
221                 if (use_numerical_citations)
222                         params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
223                 else
224                         params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
225
226         } else if (dialog_->biblioModule->citeJurabibRB->isChecked())
227                 params.cite_engine = biblio::ENGINE_JURABIB;
228
229         params.use_bibtopic =
230                 dialog_->biblioModule->bibtopicCB->isChecked();
231
232         // language & quotes
233         if (dialog_->langModule->defaultencodingCB->isChecked()) {
234                 params.inputenc = "auto";
235         } else {
236                 int i = dialog_->langModule->encodingCO->currentItem();
237                 if (i == 0) {
238                         params.inputenc = "default";
239                 } else {
240                         params.inputenc = encodings[i];
241                 }
242         }
243
244         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
245         switch (dialog_->langModule->quoteStyleCO->currentItem()) {
246         case 0:
247                 lga = InsetQuotes::EnglishQ;
248                 break;
249         case 1:
250                 lga = InsetQuotes::SwedishQ;
251                 break;
252         case 2:
253                 lga = InsetQuotes::GermanQ;
254                 break;
255         case 3:
256                 lga = InsetQuotes::PolishQ;
257                 break;
258         case 4:
259                 lga = InsetQuotes::FrenchQ;
260                 break;
261         case 5:
262                 lga = InsetQuotes::DanishQ;
263                 break;
264         }
265         params.quotes_language = lga;
266
267         int const pos = dialog_->langModule->languageCO->currentItem();
268         params.language = languages.getLanguage(lang_[pos]);
269
270         // numbering
271         params.tocdepth = dialog_->numberingModule->tocSL->value();
272         params.secnumdepth = dialog_->numberingModule->depthSL->value();
273
274         // bullets
275         params.user_defined_bullet(0) = dialog_->bulletsModule->getBullet(0);
276         params.user_defined_bullet(1) = dialog_->bulletsModule->getBullet(1);
277         params.user_defined_bullet(2) = dialog_->bulletsModule->getBullet(2);
278         params.user_defined_bullet(3) = dialog_->bulletsModule->getBullet(3);
279
280         // packages
281         params.graphicsDriver =
282                 fromqstr(dialog_->latexModule->psdriverCO->currentText());
283
284         if (dialog_->mathsModule->amsautoCB->isChecked()) {
285                 params.use_amsmath = BufferParams::AMS_AUTO;
286         } else {
287                 if (dialog_->mathsModule->amsCB->isChecked())
288                         params.use_amsmath = BufferParams::AMS_ON;
289                 else
290                         params.use_amsmath = BufferParams::AMS_OFF;
291         }
292
293         // layout
294         params.textclass =
295                 dialog_->latexModule->classCO->currentItem();
296
297         params.fonts =
298                 fromqstr(dialog_->textLayoutModule->fontsCO->currentText());
299
300         params.fontsize =
301                 fromqstr(dialog_->textLayoutModule->fontsizeCO->currentText());
302
303         params.pagestyle =
304                 fromqstr(dialog_->pageLayoutModule->pagestyleCO->currentText());
305
306         switch (dialog_->textLayoutModule->lspacingCO->currentItem()) {
307         case 0:
308                 params.spacing().set(Spacing::Single);
309                 break;
310         case 1:
311                 params.spacing().set(Spacing::Onehalf);
312                 break;
313         case 2:
314                 params.spacing().set(Spacing::Double);
315                 break;
316         case 3:
317                 params.spacing().set(Spacing::Other,
318                         fromqstr(dialog_->textLayoutModule->lspacingLE->text()));
319                 break;
320         }
321
322         if (dialog_->textLayoutModule->twoColumnCB->isChecked())
323                 params.columns = 2;
324         else
325                 params.columns = 1;
326
327         if (dialog_->textLayoutModule->indentRB->isChecked())
328                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
329         else
330                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
331
332         switch (dialog_->textLayoutModule->skipCO->currentItem()) {
333         case 0:
334                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
335                 break;
336         case 1:
337                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
338                 break;
339         case 2:
340                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
341                 break;
342         case 3:
343         {
344                 VSpace vs = VSpace(
345                         widgetsToLength(dialog_->textLayoutModule->skipLE,
346                                 dialog_->textLayoutModule->skipLengthCO)
347                         );
348                 params.setDefSkip(vs);
349                 break;
350         }
351         default:
352                 // DocumentDefskipCB assures that this never happens
353                 // so Assert then !!!  - jbl
354                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
355                 break;
356         }
357
358         params.options =
359                 fromqstr(dialog_->latexModule->optionsLE->text());
360
361         params.float_placement = dialog_->floatModule->get();
362
363         // paper
364         params.papersize2 = VMARGIN_PAPER_TYPE(
365                 dialog_->pageLayoutModule->papersizeCO->currentItem());
366
367         // custom, A3, B3 and B4 paper sizes need geometry
368         int psize = dialog_->pageLayoutModule->papersizeCO->currentItem();
369         bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
370
371         params.paperwidth = widgetsToLength(dialog_->pageLayoutModule->paperwidthLE,
372                 dialog_->pageLayoutModule->paperwidthUnitCO);
373
374         params.paperheight = widgetsToLength(dialog_->pageLayoutModule->paperheightLE,
375                 dialog_->pageLayoutModule->paperheightUnitCO);
376
377         if (dialog_->pageLayoutModule->facingPagesCB->isChecked())
378                 params.sides = LyXTextClass::TwoSides;
379         else
380                 params.sides = LyXTextClass::OneSide;
381
382         if (dialog_->pageLayoutModule->landscapeRB->isChecked())
383                 params.orientation = ORIENTATION_LANDSCAPE;
384         else
385                 params.orientation = ORIENTATION_PORTRAIT;
386
387         // margins
388         params.use_geometry =
389                 (dialog_->marginsModule->marginCO->currentItem() == 1
390                 || geom_papersize);
391
392         int margin = dialog_->marginsModule->marginCO->currentItem();
393         if (margin > 0) {
394                 margin = margin - 1;
395         }
396         params.paperpackage = PAPER_PACKAGES(margin);
397
398         // set params.papersize from params.papersize2
399         // and params.paperpackage
400         params.setPaperStuff();
401
402         MarginsModuleBase const * m(dialog_->marginsModule);
403
404         params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
405
406         params.topmargin = widgetsToLength(m->topLE, m->topUnit);
407
408         params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
409
410         params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
411
412         params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
413
414         params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
415
416         params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
417
418         params.branchlist() = branchlist_;
419 }
420
421
422 namespace {
423
424 /** Return the position of val in the vector if found.
425     If not found, return 0.
426  */
427 template<class A>
428 typename std::vector<A>::size_type
429 findPos(std::vector<A> const & vec, A const & val)
430 {
431         typename std::vector<A>::const_iterator it =
432                 std::find(vec.begin(), vec.end(), val);
433         if (it == vec.end())
434                 return 0;
435         return distance(vec.begin(), it);
436 }
437
438 } // namespace anom
439
440
441 void QDocument::update_contents()
442 {
443         if (!dialog_.get())
444                 return;
445
446         BufferParams const & params = controller().params();
447
448         // set the default unit
449         // FIXME: move to controller
450         LyXLength::UNIT defaultUnit = LyXLength::CM;
451         switch (lyxrc.default_papersize) {
452                 case PAPER_DEFAULT: break;
453
454                 case PAPER_USLETTER:
455                 case PAPER_LEGALPAPER:
456                 case PAPER_EXECUTIVEPAPER:
457                         defaultUnit = LyXLength::IN;
458                         break;
459
460                 case PAPER_A3PAPER:
461                 case PAPER_A4PAPER:
462                 case PAPER_A5PAPER:
463                 case PAPER_B5PAPER:
464                         defaultUnit = LyXLength::CM;
465                         break;
466         }
467
468         // preamble
469         QString preamble = toqstr(params.preamble);
470         dialog_->preambleModule->preambleMLE->setText(preamble);
471
472         // biblio
473         dialog_->biblioModule->citeDefaultRB->setChecked(
474                 params.cite_engine == biblio::ENGINE_BASIC);
475
476         dialog_->biblioModule->citeNatbibRB->setChecked(
477                 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
478                 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
479
480         dialog_->biblioModule->citeStyleCO->setCurrentItem(
481                 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
482
483         dialog_->biblioModule->citeJurabibRB->setChecked(
484                 params.cite_engine == biblio::ENGINE_JURABIB);
485
486         dialog_->biblioModule->bibtopicCB->setChecked(
487                 params.use_bibtopic);
488
489         // language & quotes
490         int const pos = int(findPos(lang_,
491                                     params.language->lang()));
492         dialog_->langModule->languageCO->setCurrentItem(pos);
493
494         dialog_->langModule->quoteStyleCO->setCurrentItem(
495                 params.quotes_language);
496
497         dialog_->langModule->defaultencodingCB->setChecked(true);
498
499         if (params.inputenc != "auto") {
500                 dialog_->langModule->defaultencodingCB->setChecked(false);
501                 if (params.inputenc == "default") {
502                         dialog_->langModule->encodingCO->setCurrentItem(0);
503                 } else {
504                         int i = 0;
505                         while (encodings[i]) {
506                                 if (encodings[i] == params.inputenc)
507                                         dialog_->langModule->encodingCO->setCurrentItem(i);
508                                 ++i;
509                         }
510                 }
511         }
512
513         // numbering
514         dialog_->numberingModule->tocSL->setValue(params.tocdepth);
515         dialog_->numberingModule->depthSL->setValue(params.secnumdepth);
516         dialog_->updateNumbering();
517
518         // bullets
519         dialog_->bulletsModule->setBullet(0,params.user_defined_bullet(0));
520         dialog_->bulletsModule->setBullet(1,params.user_defined_bullet(1));
521         dialog_->bulletsModule->setBullet(2,params.user_defined_bullet(2));
522         dialog_->bulletsModule->setBullet(3,params.user_defined_bullet(3));
523
524         // packages
525         QString text = toqstr(params.graphicsDriver);
526         int nitem = dialog_->latexModule->psdriverCO->count();
527         for (int n = 0; n < nitem ; ++n) {
528                 QString enc = tex_graphics[n];
529                 if (enc == text) {
530                         dialog_->latexModule->psdriverCO->setCurrentItem(n);
531                 }
532         }
533
534
535         dialog_->mathsModule->amsCB->setChecked(
536                 params.use_amsmath == BufferParams::AMS_ON);
537         dialog_->mathsModule->amsautoCB->setChecked(
538                 params.use_amsmath == BufferParams::AMS_AUTO);
539
540         switch (params.spacing().getSpace()) {
541                 case Spacing::Other: nitem = 3; break;
542                 case Spacing::Double: nitem = 2; break;
543                 case Spacing::Onehalf: nitem = 1; break;
544                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
545         }
546
547
548         // layout
549         dialog_->latexModule->classCO->setCurrentItem(params.textclass);
550
551         dialog_->updateFontsize(controller().textClass().opt_fontsize(),
552                                 params.fontsize);
553
554         dialog_->updatePagestyle(controller().textClass().opt_pagestyle(),
555                                  params.pagestyle);
556
557         for (int n = 0; tex_fonts[n][0]; ++n) {
558                 if (tex_fonts[n] == params.fonts) {
559                         dialog_->textLayoutModule->fontsCO->setCurrentItem(n);
560                         break;
561                 }
562         }
563
564         dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
565         if (params.spacing().getSpace() == Spacing::Other) {
566                 dialog_->textLayoutModule->lspacingLE->setText(
567                         toqstr(params.spacing().getValueAsString()));
568         }
569         dialog_->setLSpacing(nitem);
570
571         if (params.paragraph_separation
572             == BufferParams::PARSEP_INDENT) {
573                 dialog_->textLayoutModule->indentRB->setChecked(true);
574         } else {
575                 dialog_->textLayoutModule->skipRB->setChecked(true);
576         }
577
578         int skip = 0;
579         switch (params.getDefSkip().kind()) {
580         case VSpace::SMALLSKIP:
581                 skip = 0;
582                 break;
583         case VSpace::MEDSKIP:
584                 skip = 1;
585                 break;
586         case VSpace::BIGSKIP:
587                 skip = 2;
588                 break;
589         case VSpace::LENGTH:
590         {
591                 skip = 3;
592                 string const length = params.getDefSkip().asLyXCommand();
593                 lengthToWidgets(dialog_->textLayoutModule->skipLE,
594                         dialog_->textLayoutModule->skipLengthCO,
595                         length, defaultUnit);
596                 break;
597         }
598         default:
599                 skip = 0;
600                 break;
601         }
602         dialog_->textLayoutModule->skipCO->setCurrentItem(skip);
603         dialog_->setSkip(skip);
604
605         dialog_->textLayoutModule->twoColumnCB->setChecked(
606                 params.columns == 2);
607
608         if (!params.options.empty()) {
609                 dialog_->latexModule->optionsLE->setText(
610                         toqstr(params.options));
611         } else {
612                 dialog_->latexModule->optionsLE->setText("");
613         }
614
615         dialog_->floatModule->set(params.float_placement);
616
617         // paper
618         int const psize = params.papersize2;
619         dialog_->pageLayoutModule->papersizeCO->setCurrentItem(psize);
620         dialog_->setMargins(psize);
621         dialog_->setCustomPapersize(psize);
622
623         bool const landscape =
624                 params.orientation == ORIENTATION_LANDSCAPE;
625         dialog_->pageLayoutModule->landscapeRB->setChecked(landscape);
626         dialog_->pageLayoutModule->portraitRB->setChecked(!landscape);
627
628         dialog_->pageLayoutModule->facingPagesCB->setChecked(
629                 params.sides == LyXTextClass::TwoSides);
630
631
632
633         lengthToWidgets(dialog_->pageLayoutModule->paperwidthLE,
634                 dialog_->pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
635
636         lengthToWidgets(dialog_->pageLayoutModule->paperheightLE,
637                 dialog_->pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
638
639         // margins
640
641         MarginsModuleBase * m = dialog_->marginsModule;
642
643         int item = params.paperpackage;
644         if (params.use_geometry) {
645                 item = 1;
646         } else if (item > 0) {
647                 item = item + 1;
648         }
649         m->marginCO->setCurrentItem(item);
650         dialog_->setCustomMargins(item);
651
652         lengthToWidgets(m->topLE, m->topUnit,
653                 params.topmargin, defaultUnit);
654
655         lengthToWidgets(m->bottomLE, m->bottomUnit,
656                 params.bottommargin, defaultUnit);
657
658         lengthToWidgets(m->innerLE, m->innerUnit,
659                 params.leftmargin, defaultUnit);
660
661         lengthToWidgets(m->outerLE, m->outerUnit,
662                 params.rightmargin, defaultUnit);
663
664         lengthToWidgets(m->headheightLE, m->headheightUnit,
665                 params.headheight, defaultUnit);
666
667         lengthToWidgets(m->headsepLE, m->headsepUnit,
668                 params.headsep, defaultUnit);
669
670         lengthToWidgets(m->footskipLE, m->footskipUnit,
671                 params.footskip, defaultUnit);
672
673         // branches
674         branchlist_ = params.branchlist();
675         dialog_->updateBranchView();
676 }
677
678
679 void QDocument::saveDocDefault()
680 {
681         // we have to apply the params first
682         apply();
683         controller().saveAsDefault();
684 }
685
686
687 void QDocument::useClassDefaults()
688 {
689         BufferParams & params = controller().params();
690
691         params.textclass = dialog_->latexModule->classCO->currentItem();
692         params.useClassDefaults();
693         update_contents();
694 }
695
696 } // namespace frontend
697 } // namespace lyx