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