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