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