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