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