]> git.lyx.org Git - features.git/blob - src/frontends/qt2/QDocument.C
493ed0e1dd9a17ad077e13f1531b1d42e4b49951
[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                                    dialog_->textLayoutModule->
320                                    lspacingLE->text().toFloat()
321                                    );
322                 break;
323         }
324
325         if (dialog_->textLayoutModule->twoColumnCB->isChecked())
326                 params.columns = 2;
327         else
328                 params.columns = 1;
329
330         if (dialog_->textLayoutModule->indentRB->isChecked())
331                 params.paragraph_separation = BufferParams::PARSEP_INDENT;
332         else
333                 params.paragraph_separation = BufferParams::PARSEP_SKIP;
334
335         switch (dialog_->textLayoutModule->skipCO->currentItem()) {
336         case 0:
337                 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
338                 break;
339         case 1:
340                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
341                 break;
342         case 2:
343                 params.setDefSkip(VSpace(VSpace::BIGSKIP));
344                 break;
345         case 3:
346         {
347                 VSpace vs = VSpace(
348                         widgetsToLength(dialog_->textLayoutModule->skipLE, 
349                                 dialog_->textLayoutModule->skipLengthCO)
350                         );
351                 params.setDefSkip(vs);
352                 break;
353         }
354         default:
355                 // DocumentDefskipCB assures that this never happens
356                 // so Assert then !!!  - jbl
357                 params.setDefSkip(VSpace(VSpace::MEDSKIP));
358                 break;
359         }
360
361         params.options =
362                 fromqstr(dialog_->latexModule->optionsLE->text());
363
364         params.float_placement = dialog_->floatModule->get();
365
366         // paper
367         params.papersize2 = VMARGIN_PAPER_TYPE(
368                 dialog_->pageLayoutModule->papersizeCO->currentItem());
369
370         // custom, A3, B3 and B4 paper sizes need geometry
371         int psize = dialog_->pageLayoutModule->papersizeCO->currentItem();
372         bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
373
374         params.paperwidth = widgetsToLength(dialog_->pageLayoutModule->paperwidthLE,
375                 dialog_->pageLayoutModule->paperwidthUnitCO);
376
377         params.paperheight = widgetsToLength(dialog_->pageLayoutModule->paperheightLE,
378                 dialog_->pageLayoutModule->paperheightUnitCO);
379
380         if (dialog_->pageLayoutModule->facingPagesCB->isChecked())
381                 params.sides = LyXTextClass::TwoSides;
382         else
383                 params.sides = LyXTextClass::OneSide;
384
385         if (dialog_->pageLayoutModule->landscapeRB->isChecked())
386                 params.orientation = ORIENTATION_LANDSCAPE;
387         else
388                 params.orientation = ORIENTATION_PORTRAIT;
389
390         // margins
391         params.use_geometry =
392                 (dialog_->marginsModule->marginCO->currentItem() == 1
393                 || geom_papersize);
394
395         int margin = dialog_->marginsModule->marginCO->currentItem();
396         if (margin > 0) {
397                 margin = margin - 1;
398         }
399         params.paperpackage = PAPER_PACKAGES(margin);
400
401         // set params.papersize from params.papersize2
402         // and params.paperpackage
403         params.setPaperStuff();
404
405         MarginsModuleBase const * m(dialog_->marginsModule);
406
407         params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
408
409         params.topmargin = widgetsToLength(m->topLE, m->topUnit);
410
411         params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
412
413         params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
414
415         params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
416
417         params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
418
419         params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
420
421         params.branchlist() = branchlist_;
422 }
423
424
425 namespace {
426
427 /** Return the position of val in the vector if found.
428     If not found, return 0.
429  */
430 template<class A>
431 typename std::vector<A>::size_type
432 findPos(std::vector<A> const & vec, A const & val)
433 {
434         typename std::vector<A>::const_iterator it =
435                 std::find(vec.begin(), vec.end(), val);
436         if (it == vec.end())
437                 return 0;
438         return distance(vec.begin(), it);
439 }
440
441 } // namespace anom
442
443
444 void QDocument::update_contents()
445 {
446         if (!dialog_.get())
447                 return;
448
449         BufferParams const & params = controller().params();
450
451         // set the default unit
452         // FIXME: move to controller
453         LyXLength::UNIT defaultUnit = LyXLength::CM;
454         switch (lyxrc.default_papersize) {
455                 case PAPER_DEFAULT: break;
456
457                 case PAPER_USLETTER:
458                 case PAPER_LEGALPAPER:
459                 case PAPER_EXECUTIVEPAPER:
460                         defaultUnit = LyXLength::IN;
461                         break;
462
463                 case PAPER_A3PAPER:
464                 case PAPER_A4PAPER:
465                 case PAPER_A5PAPER:
466                 case PAPER_B5PAPER:
467                         defaultUnit = LyXLength::CM;
468                         break;
469         }
470
471         // preamble
472         QString preamble = toqstr(params.preamble);
473         dialog_->preambleModule->preambleMLE->setText(preamble);
474
475         // biblio
476         dialog_->biblioModule->citeDefaultRB->setChecked(
477                 params.cite_engine == biblio::ENGINE_BASIC);
478
479         dialog_->biblioModule->citeNatbibRB->setChecked(
480                 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
481                 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
482
483         dialog_->biblioModule->citeStyleCO->setCurrentItem(
484                 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
485
486         dialog_->biblioModule->citeJurabibRB->setChecked(
487                 params.cite_engine == biblio::ENGINE_JURABIB);
488
489         dialog_->biblioModule->bibtopicCB->setChecked(
490                 params.use_bibtopic);
491
492         // language & quotes
493         int const pos = int(findPos(lang_,
494                                     params.language->lang()));
495         dialog_->langModule->languageCO->setCurrentItem(pos);
496
497         dialog_->langModule->quoteStyleCO->setCurrentItem(
498                 params.quotes_language);
499
500         dialog_->langModule->defaultencodingCB->setChecked(true);
501
502         if (params.inputenc != "auto") {
503                 dialog_->langModule->defaultencodingCB->setChecked(false);
504                 if (params.inputenc == "default") {
505                         dialog_->langModule->encodingCO->setCurrentItem(0);
506                 } else {
507                         int i = 0;
508                         while (encodings[i]) {
509                                 if (encodings[i] == params.inputenc)
510                                         dialog_->langModule->encodingCO->setCurrentItem(i);
511                                 ++i;
512                         }
513                 }
514         }
515
516         // numbering
517         dialog_->numberingModule->tocSL->setValue(params.tocdepth);
518         dialog_->numberingModule->depthSL->setValue(params.secnumdepth);
519         dialog_->updateNumbering();
520
521         // bullets
522         dialog_->bulletsModule->setBullet(0,params.user_defined_bullet(0));
523         dialog_->bulletsModule->setBullet(1,params.user_defined_bullet(1));
524         dialog_->bulletsModule->setBullet(2,params.user_defined_bullet(2));
525         dialog_->bulletsModule->setBullet(3,params.user_defined_bullet(3));
526
527         // packages
528         QString text = toqstr(params.graphicsDriver);
529         int nitem = dialog_->latexModule->psdriverCO->count();
530         for (int n = 0; n < nitem ; ++n) {
531                 QString enc = tex_graphics[n];
532                 if (enc == text) {
533                         dialog_->latexModule->psdriverCO->setCurrentItem(n);
534                 }
535         }
536
537
538         dialog_->mathsModule->amsCB->setChecked(
539                 params.use_amsmath == BufferParams::AMS_ON);
540         dialog_->mathsModule->amsautoCB->setChecked(
541                 params.use_amsmath == BufferParams::AMS_AUTO);
542
543         switch (params.spacing().getSpace()) {
544                 case Spacing::Other: nitem = 3; break;
545                 case Spacing::Double: nitem = 2; break;
546                 case Spacing::Onehalf: nitem = 1; break;
547                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
548         }
549
550
551         // layout
552         dialog_->latexModule->classCO->setCurrentItem(params.textclass);
553
554         dialog_->updateFontsize(controller().textClass().opt_fontsize(),
555                                 params.fontsize);
556
557         dialog_->updatePagestyle(controller().textClass().opt_pagestyle(),
558                                  params.pagestyle);
559
560         for (int n = 0; tex_fonts[n][0]; ++n) {
561                 if (tex_fonts[n] == params.fonts) {
562                         dialog_->textLayoutModule->fontsCO->setCurrentItem(n);
563                         break;
564                 }
565         }
566
567         dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
568         if (params.spacing().getSpace() == Spacing::Other) {
569                 dialog_->textLayoutModule->lspacingLE->setText(
570                         toqstr(tostr(params.spacing().getValue())));
571                 dialog_->setLSpacing(3);
572         }
573
574         if (params.paragraph_separation
575             == BufferParams::PARSEP_INDENT) {
576                 dialog_->textLayoutModule->indentRB->setChecked(true);
577         } else {
578                 dialog_->textLayoutModule->skipRB->setChecked(true);
579         }
580
581         int skip = 0;
582         switch (params.getDefSkip().kind()) {
583         case VSpace::SMALLSKIP:
584                 skip = 0;
585                 break;
586         case VSpace::MEDSKIP:
587                 skip = 1;
588                 break;
589         case VSpace::BIGSKIP:
590                 skip = 2;
591                 break;
592         case VSpace::LENGTH:
593         {
594                 skip = 3;
595                 string const length = params.getDefSkip().asLyXCommand();
596                 lengthToWidgets(dialog_->textLayoutModule->skipLE, 
597                         dialog_->textLayoutModule->skipLengthCO, 
598                         length, defaultUnit);
599                 break;
600         }
601         default:
602                 skip = 0;
603                 break;
604         }
605         dialog_->textLayoutModule->skipCO->setCurrentItem(skip);
606         dialog_->setSkip(skip);
607
608         dialog_->textLayoutModule->twoColumnCB->setChecked(
609                 params.columns == 2);
610
611         if (!params.options.empty()) {
612                 dialog_->latexModule->optionsLE->setText(
613                         toqstr(params.options));
614         } else {
615                 dialog_->latexModule->optionsLE->setText("");
616         }
617
618         dialog_->floatModule->set(params.float_placement);
619
620         // paper
621         int const psize = params.papersize2;
622         dialog_->pageLayoutModule->papersizeCO->setCurrentItem(psize);
623         dialog_->setMargins(psize);
624         dialog_->setCustomPapersize(psize);
625
626         bool const landscape =
627                 params.orientation == ORIENTATION_LANDSCAPE;
628         dialog_->pageLayoutModule->landscapeRB->setChecked(landscape);
629         dialog_->pageLayoutModule->portraitRB->setChecked(!landscape);
630
631         dialog_->pageLayoutModule->facingPagesCB->setChecked(
632                 params.sides == LyXTextClass::TwoSides);
633
634
635
636         lengthToWidgets(dialog_->pageLayoutModule->paperwidthLE,
637                 dialog_->pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
638
639         lengthToWidgets(dialog_->pageLayoutModule->paperheightLE,
640                 dialog_->pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
641
642         // margins
643
644         MarginsModuleBase * m = dialog_->marginsModule;
645
646         int item = params.paperpackage;
647         if (params.use_geometry) {
648                 item = 1;
649         } else if (item > 0) {
650                 item = item + 1;
651         }
652         m->marginCO->setCurrentItem(item);
653         dialog_->setCustomMargins(item);
654
655         lengthToWidgets(m->topLE, m->topUnit,
656                 params.topmargin, defaultUnit);
657
658         lengthToWidgets(m->bottomLE, m->bottomUnit,
659                 params.bottommargin, defaultUnit);
660
661         lengthToWidgets(m->innerLE, m->innerUnit,
662                 params.leftmargin, defaultUnit);
663
664         lengthToWidgets(m->outerLE, m->outerUnit,
665                 params.rightmargin, defaultUnit);
666
667         lengthToWidgets(m->headheightLE, m->headheightUnit,
668                 params.headheight, defaultUnit);
669
670         lengthToWidgets(m->headsepLE, m->headsepUnit,
671                 params.headsep, defaultUnit);
672
673         lengthToWidgets(m->footskipLE, m->footskipUnit,
674                 params.footskip, defaultUnit);
675
676         // branches
677         branchlist_ = params.branchlist();
678         dialog_->updateBranchView();
679 }
680
681
682 void QDocument::saveDocDefault()
683 {
684         // we have to apply the params first
685         apply();
686         controller().saveAsDefault();
687 }
688
689
690 void QDocument::useClassDefaults()
691 {
692         BufferParams & params = controller().params();
693
694         params.textclass = dialog_->latexModule->classCO->currentItem();
695         params.useClassDefaults();
696         update_contents();
697 }
698
699 } // namespace frontend
700 } // namespace lyx