]> git.lyx.org Git - features.git/blob - src/frontends/qt4/QDocumentDialog.C
remove faulty FIXMEs. I was confused.
[features.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 "gettext.h"
29 #include "helper_funcs.h" // getSecond()
30 #include "language.h"
31 #include "lyxrc.h" // defaultUnit
32 #include "lyxtextclasslist.h"
33 #include "tex-strings.h" // tex_graphics
34 #include "Spacing.h"
35
36 #include "controllers/ControlDocument.h"
37 #include "controllers/frnt_lang.h"
38
39 #include "support/lstrings.h"
40
41 #include "controllers/ControlDocument.h"
42 #include "controllers/frnt_lang.h"
43
44
45 using lyx::support::token;
46 using lyx::support::bformat;
47 using lyx::support::findToken;
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 // FIXME: This list is incomplete. It should not be hardcoded but come from
62 // the available encodings in src/encodings.C
63 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
64         "latin3", "latin4", "latin5", "latin9",
65         "koi8-r", "koi8-u", "cp866", "cp1251",
66         "iso88595", "pt154", "utf8", 0
67 };
68
69 }
70
71 QDocumentDialog::QDocumentDialog(QDocument * form)
72         : form_(form),
73         lang_(getSecond(getLanguageData(false)))
74 {
75         setupUi(this);
76
77         connect(okPB, SIGNAL(clicked()),
78                 form, SLOT(slotOK()));
79         connect(applyPB, SIGNAL(clicked()),
80                 form, SLOT(slotApply()));
81         connect(closePB, SIGNAL(clicked()),
82                 form, SLOT(slotClose()));
83         connect(restorePB, SIGNAL(clicked()),
84                 form, SLOT(slotRestore()));
85
86
87         connect(savePB, SIGNAL( clicked() ), 
88                 this, SLOT( saveDefaultClicked() ) );
89         connect(defaultPB, SIGNAL( clicked() ), 
90                 this, SLOT( useDefaultsClicked() ) );
91
92         // Manage the restore, ok, apply, restore and cancel/close buttons
93         form_->bcview().setOK(okPB);
94         form_->bcview().setApply(applyPB);
95         form_->bcview().setCancel(closePB);
96         form_->bcview().setRestore(restorePB);
97
98
99         textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
100         // text layout
101         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
102         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
103         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
104         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
105         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
106         connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
107         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
108         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
109         connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
110         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
111         connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
112         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
113                 textLayoutModule->lspacingLE));
114         textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
115                 textLayoutModule->skipLE));
116
117         textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
118         textLayoutModule->skipCO->addItem(qt_("MedSkip"));
119         textLayoutModule->skipCO->addItem(qt_("BigSkip"));
120         textLayoutModule->skipCO->addItem(qt_("Length"));
121         // remove the %-items from the unit choice
122         textLayoutModule->skipLengthCO->noPercents();
123         textLayoutModule->lspacingCO->insertItem(
124                 Spacing::Single, qt_("Single"));
125         textLayoutModule->lspacingCO->insertItem(
126                 Spacing::Onehalf, qt_("OneHalf"));
127         textLayoutModule->lspacingCO->insertItem(
128                 Spacing::Double, qt_("Double"));
129         textLayoutModule->lspacingCO->insertItem(
130                 Spacing::Other, qt_("Custom"));
131
132         // initialize the length validator
133         addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
134
135
136
137
138         fontModule = new UiWidget<Ui::FontUi>;
139         // fonts
140         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(romanChanged(int)));
142         connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143         connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(sansChanged(int)));
144         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
145         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int)));
146         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
147         connect(fontModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
148         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
149         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
150         connect(fontModule->fontScCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
151         connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
152
153         for (int n = 0; tex_fonts_roman[n][0]; ++n) {
154                 QString font = toqstr(tex_fonts_roman_gui[n]);
155                 if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
156                         font += qt_(" (not installed)");
157                 fontModule->fontsRomanCO->addItem(font);
158         }
159         for (int n = 0; tex_fonts_sans[n][0]; ++n) {
160                 QString font = toqstr(tex_fonts_sans_gui[n]);
161                 if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
162                         font += qt_(" (not installed)");
163                 fontModule->fontsSansCO->addItem(font);
164         }
165         for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
166                 QString font = toqstr(tex_fonts_monospaced_gui[n]);
167                 if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
168                         font += qt_(" (not installed)");
169                 fontModule->fontsTypewriterCO->addItem(font);
170         }
171
172         fontModule->fontsizeCO->addItem(qt_("default"));
173         fontModule->fontsizeCO->addItem(qt_("10"));
174         fontModule->fontsizeCO->addItem(qt_("11"));
175         fontModule->fontsizeCO->addItem(qt_("12"));
176
177         for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
178                 fontModule->fontsDefaultCO->addItem(
179                         qt_(ControlDocument::fontfamilies_gui[n]));
180
181
182
183
184         pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
185         // page layout
186         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
187         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
188         connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
189         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
190         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
191         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
192         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
193         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
194         connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
195         connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
196         connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
197         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
198         pageLayoutModule->pagestyleCO->addItem(qt_("default"));
199         pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
200         pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
201         pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
202         pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
203         addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
204                 pageLayoutModule->paperheightL);
205         addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
206                 pageLayoutModule->paperwidthL);
207
208         // paper
209         QComboBox * cb = pageLayoutModule->papersizeCO;
210         cb->addItem(qt_("Default"));
211         cb->addItem(qt_("Custom"));
212         cb->addItem(qt_("US letter"));
213         cb->addItem(qt_("US legal"));
214         cb->addItem(qt_("US executive"));
215         cb->addItem(qt_("A3"));
216         cb->addItem(qt_("A4"));
217         cb->addItem(qt_("A5"));
218         cb->addItem(qt_("B3"));
219         cb->addItem(qt_("B4"));
220         cb->addItem(qt_("B5"));
221         // remove the %-items from the unit choice
222         pageLayoutModule->paperwidthUnitCO->noPercents();
223         pageLayoutModule->paperheightUnitCO->noPercents();
224         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
225                 pageLayoutModule->paperheightLE));
226         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
227                 pageLayoutModule->paperwidthLE));
228
229
230
231
232         marginsModule = new UiWidget<Ui::MarginsUi>;
233         // margins
234         connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
235         connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
236         connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
237         connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
238         connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
239         connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
240         connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
241         connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
242         connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
243         connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
244         connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
245         connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
246         connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
247         connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
248         connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
249         connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
250         marginsModule->topLE->setValidator(unsignedLengthValidator(
251                 marginsModule->topLE));
252         marginsModule->bottomLE->setValidator(unsignedLengthValidator(
253                 marginsModule->bottomLE));
254         marginsModule->innerLE->setValidator(unsignedLengthValidator(
255                 marginsModule->innerLE));
256         marginsModule->outerLE->setValidator(unsignedLengthValidator(
257                 marginsModule->outerLE));
258         marginsModule->headsepLE->setValidator(unsignedLengthValidator(
259                 marginsModule->headsepLE));
260         marginsModule->headheightLE->setValidator(unsignedLengthValidator(
261                 marginsModule->headheightLE));
262         marginsModule->footskipLE->setValidator(unsignedLengthValidator(
263                 marginsModule->footskipLE));
264
265         addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
266                 marginsModule->topL);
267         addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
268                 marginsModule->bottomL);
269         addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
270                 marginsModule->innerL);
271         addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
272                 marginsModule->outerL);
273         addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
274                 marginsModule->headsepL);
275         addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
276                 marginsModule->headheightL);
277         addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
278                 marginsModule->footskipL);
279
280
281
282
283
284         langModule = new UiWidget<Ui::LanguageUi>;
285         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), langModule->encodingL, SLOT(setDisabled(bool)));
286         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), langModule->encodingCO, SLOT(setDisabled(bool)));
287         // language & quote
288         connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
289         connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
290         connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
291         connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
292         // language & quotes
293         vector<LanguagePair> const langs = getLanguageData(false);
294         vector<LanguagePair>::const_iterator lit  = langs.begin();
295         vector<LanguagePair>::const_iterator lend = langs.end();
296         for (; lit != lend; ++lit) {
297                 langModule->languageCO->addItem(
298                         toqstr(lit->first));
299         }
300
301         int k = 0;
302         while (encodings[k]) {
303                 langModule->encodingCO->addItem(qt_(encodings[k++]));
304         }
305
306         langModule->quoteStyleCO->addItem(qt_("``text''"));
307         langModule->quoteStyleCO->addItem(qt_("''text''"));
308         langModule->quoteStyleCO->addItem(qt_(",,text``"));
309         langModule->quoteStyleCO->addItem(qt_(",,text''"));
310         langModule->quoteStyleCO->addItem(qt_("<<text>>"));
311         langModule->quoteStyleCO->addItem(qt_(">>text<<"));
312
313
314
315         numberingModule = new UiWidget<Ui::NumberingUi>;
316         // numbering
317         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
318         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
319         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
320         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
321         numberingModule->tocTW->setColumnCount(3);
322         numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
323         numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
324         numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
325
326
327         biblioModule = new UiWidget<Ui::BiblioUi>;
328         connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citationStyleL, SLOT( setEnabled(bool) ) );
329         connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citeStyleCO, SLOT( setEnabled(bool) ) );
330         // biblio
331         connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
332         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
333         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
334         connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
335         connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
336         // biblio
337         biblioModule->citeStyleCO->addItem(qt_("Author-year"));
338         biblioModule->citeStyleCO->addItem(qt_("Numerical"));
339         biblioModule->citeStyleCO->setCurrentIndex(0);
340
341
342
343         mathsModule = new UiWidget<Ui::MathsUi>;
344     connect( mathsModule->amsautoCB, SIGNAL( toggled(bool) ), mathsModule->amsCB, SLOT( setDisabled(bool) ) );
345         // maths
346         connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
347         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
348
349
350         latexModule = new UiWidget<Ui::LaTeXUi>;
351         // latex class
352         connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
353         connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
354         connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
355         connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
356         // packages
357         for (int n = 0; tex_graphics[n][0]; ++n) {
358                 QString enc = tex_graphics[n];
359                 latexModule->psdriverCO->addItem(enc);
360         }
361         // latex
362         for (LyXTextClassList::const_iterator cit = textclasslist.begin();
363              cit != textclasslist.end(); ++cit) {
364                 if (cit->isTeXClassAvailable()) {
365                         latexModule->classCO->addItem(toqstr(cit->description()));
366                 } else {
367                         docstring item =
368                                 bformat(_("Unavailable: %1$s"), lyx::from_utf8(cit->description()));
369                         latexModule->classCO->addItem(toqstr(item));
370                 }
371         }
372
373         // branches
374         branchesModule = new QBranches;
375         connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
376
377         // preamble
378         preambleModule = new UiWidget<Ui::PreambleUi>;
379         connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
380
381
382         // bullets
383         bulletsModule = new BulletsModule;
384         connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
385
386
387         // float
388         floatModule = new FloatPlacement;
389         connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
390
391         docPS->addPanel(latexModule, _("Document Class"));
392         docPS->addPanel(fontModule, _("Fonts"));
393         docPS->addPanel(textLayoutModule, _("Text Layout"));
394         docPS->addPanel(pageLayoutModule, _("Page Layout"));
395         docPS->addPanel(marginsModule, _("Page Margins"));
396         docPS->addPanel(langModule, _("Language"));
397         docPS->addPanel(numberingModule, _("Numbering & TOC"));
398         docPS->addPanel(biblioModule, _("Bibliography"));
399         docPS->addPanel(mathsModule, _("Math Options"));
400         docPS->addPanel(floatModule, _("Float Placement"));
401         docPS->addPanel(bulletsModule, _("Bullets"));
402         docPS->addPanel(branchesModule, _("Branches"));
403         docPS->addPanel(preambleModule, _("LaTeX Preamble"));
404         docPS->setCurrentPanel(_("Document Class"));
405 }
406
407
408 QDocumentDialog::~QDocumentDialog()
409 {
410 }
411
412
413 void QDocumentDialog::showPreamble()
414 {
415         docPS->setCurrentPanel(_("LaTeX Preamble"));
416 }
417
418
419 void QDocumentDialog::saveDefaultClicked()
420 {
421         form_->saveDocDefault();
422 }
423
424
425 void QDocumentDialog::useDefaultsClicked()
426 {
427         form_->useClassDefaults();
428 }
429
430
431 void QDocumentDialog::change_adaptor()
432 {
433         form_->changed();
434 }
435
436
437 void QDocumentDialog::closeEvent(QCloseEvent * e)
438 {
439         form_->slotWMHide();
440         e->accept();
441 }
442
443
444 void QDocumentDialog::setLSpacing(int item)
445 {
446         textLayoutModule->lspacingLE->setEnabled(item == 3);
447 }
448
449
450 void QDocumentDialog::setSkip(int item)
451 {
452         bool const enable = (item == 3);
453         textLayoutModule->skipLE->setEnabled(enable);
454         textLayoutModule->skipLengthCO->setEnabled(enable);
455 }
456
457
458 void QDocumentDialog::enableSkip(bool skip)
459 {
460         textLayoutModule->skipCO->setEnabled(skip);
461         textLayoutModule->skipLE->setEnabled(skip);
462         textLayoutModule->skipLengthCO->setEnabled(skip);
463         if (skip)
464                 setSkip(textLayoutModule->skipCO->currentIndex());
465 }
466
467 void QDocumentDialog::portraitChanged()
468 {
469         setMargins(pageLayoutModule->papersizeCO->currentIndex());
470 }
471
472 void QDocumentDialog::setMargins(bool custom)
473 {
474         marginsModule->marginCB->setChecked(custom);
475         setCustomMargins(custom);
476 }
477
478
479 void QDocumentDialog::setCustomPapersize(int papersize)
480 {
481         bool const custom = (papersize == 1);
482
483         pageLayoutModule->paperwidthL->setEnabled(custom);
484         pageLayoutModule->paperwidthLE->setEnabled(custom);
485         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
486         pageLayoutModule->paperheightL->setEnabled(custom);
487         pageLayoutModule->paperheightLE->setEnabled(custom);
488         pageLayoutModule->paperheightLE->setFocus();
489         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
490 }
491
492
493 void QDocumentDialog::setCustomMargins(bool custom)
494 {
495         marginsModule->topL->setEnabled(!custom);
496         marginsModule->topLE->setEnabled(!custom);
497         marginsModule->topUnit->setEnabled(!custom);
498
499         marginsModule->bottomL->setEnabled(!custom);
500         marginsModule->bottomLE->setEnabled(!custom);
501         marginsModule->bottomUnit->setEnabled(!custom);
502
503         marginsModule->innerL->setEnabled(!custom);
504         marginsModule->innerLE->setEnabled(!custom);
505         marginsModule->innerUnit->setEnabled(!custom);
506
507         marginsModule->outerL->setEnabled(!custom);
508         marginsModule->outerLE->setEnabled(!custom);
509         marginsModule->outerUnit->setEnabled(!custom);
510
511         marginsModule->headheightL->setEnabled(!custom);
512         marginsModule->headheightLE->setEnabled(!custom);
513         marginsModule->headheightUnit->setEnabled(!custom);
514
515         marginsModule->headsepL->setEnabled(!custom);
516         marginsModule->headsepLE->setEnabled(!custom);
517         marginsModule->headsepUnit->setEnabled(!custom);
518
519         marginsModule->footskipL->setEnabled(!custom);
520         marginsModule->footskipLE->setEnabled(!custom);
521         marginsModule->footskipUnit->setEnabled(!custom);
522 }
523
524
525 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
526 {
527         fontModule->fontsizeCO->clear();
528         fontModule->fontsizeCO->addItem(qt_("default"));
529
530         for (int n = 0; !token(items,'|',n).empty(); ++n)
531                 fontModule->fontsizeCO->
532                         addItem(toqstr(token(items,'|',n)));
533
534         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
535                 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
536                         fontModule->fontsizeCO->setCurrentIndex(n);
537                         break;
538                 }
539         }
540 }
541
542
543 void QDocumentDialog::romanChanged(int item)
544 {
545         string const font = tex_fonts_roman[item];
546         
547         fontModule->fontScCB->setEnabled(
548                 form_->controller().providesSC(font));
549         fontModule->fontOsfCB->setEnabled(
550                 form_->controller().providesOSF(font));
551 }
552
553
554 void QDocumentDialog::sansChanged(int item)
555 {
556         string const font = tex_fonts_sans[item];
557         
558         fontModule->scaleSansSB->setEnabled(
559                 form_->controller().providesScale(font));
560 }
561
562
563 void QDocumentDialog::ttChanged(int item)
564 {
565         string const font = tex_fonts_monospaced[item];
566         
567         fontModule->scaleTypewriterSB->setEnabled(
568                 form_->controller().providesScale(font));
569 }
570
571
572 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
573 {
574         pageLayoutModule->pagestyleCO->clear();
575         pageLayoutModule->pagestyleCO->addItem("default");
576
577         for (int n=0; !token(items,'|',n).empty(); ++n)
578                 pageLayoutModule->pagestyleCO->
579                         addItem(toqstr(token(items,'|',n)));
580
581         for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
582                 if (fromqstr(pageLayoutModule->pagestyleCO->itemText(n))==sel) {
583                         pageLayoutModule->pagestyleCO->setCurrentIndex(n);
584                         break;
585                 }
586         }
587 }
588
589
590 void QDocumentDialog::classChanged()
591 {
592         ControlDocument & cntrl = form_->controller();
593         BufferParams & params = cntrl.params();
594
595         lyx::textclass_type const tc = latexModule->classCO->currentIndex();
596
597         if (form_->controller().loadTextclass(tc)) {
598                 params.textclass = tc;
599                 if (lyxrc.auto_reset_options)
600                         params.useClassDefaults();
601                 form_->update_contents();
602         } else {
603                 latexModule->classCO->setCurrentIndex(params.textclass);
604         }
605 }
606
607
608 void QDocumentDialog::updateNumbering()
609 {
610         LyXTextClass const & tclass =
611                 form_->controller().params().getLyXTextClass();
612
613         numberingModule->tocTW->setUpdatesEnabled(false);
614         numberingModule->tocTW->clear();
615
616         int const depth = numberingModule->depthSL->value();
617         int const toc = numberingModule->tocSL->value();
618         QString const no = qt_("No");
619         QString const yes = qt_("Yes");
620         LyXTextClass::const_iterator end = tclass.end();
621         LyXTextClass::const_iterator cit = tclass.begin();
622         QTreeWidgetItem * item = 0;
623         for ( ; cit != end ; ++cit) {
624                 int const toclevel = (*cit)->toclevel;
625                 if (toclevel != LyXLayout::NOT_IN_TOC 
626                     && (*cit)->labeltype == LABEL_COUNTER) {
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->currentIndex();
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->currentIndex();
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->currentIndex()) {
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->currentIndex();
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->currentIndex();
727
728         params.pagestyle =
729                 fromqstr(pageLayoutModule->pagestyleCO->currentText());
730
731         switch (textLayoutModule->lspacingCO->currentIndex()) {
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->currentIndex()) {
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->currentIndex()];
791
792         params.fontsSans =
793                 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
794
795         params.fontsTypewriter =
796                 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
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->currentIndex()];
808
809         if (fontModule->fontsizeCO->currentIndex() == 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->currentIndex());
818
819         // custom, A3, B3 and B4 paper sizes need geometry
820         int psize = pageLayoutModule->papersizeCO->currentIndex();
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->setCurrentIndex(
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->setCurrentIndex(pos);
933
934         langModule->quoteStyleCO->setCurrentIndex(
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->setCurrentIndex(0);
943                 } else {
944                         int i = 0;
945                         while (encodings[i]) {
946                                 if (encodings[i] == params.inputenc) {
947                                         langModule->encodingCO->setCurrentIndex(i);
948                                         break;
949                                 }
950                                 ++i;
951                         }
952                         // FIXME: possible data loss because of encodings is
953                         // incomplete
954                 }
955         }
956
957         // numbering
958         int const min_toclevel = form_->controller().textClass().min_toclevel();
959         int const max_toclevel = form_->controller().textClass().max_toclevel();
960         if (form_->controller().textClass().hasTocLevels()) {
961                 numberingModule->setEnabled(true);
962                 numberingModule->depthSL->setMinimum(min_toclevel - 1);
963                 numberingModule->depthSL->setMaximum(max_toclevel);
964                 numberingModule->depthSL->setValue(params.secnumdepth);
965                 numberingModule->tocSL->setMaximum(min_toclevel - 1);
966                 numberingModule->tocSL->setMaximum(max_toclevel);
967                 numberingModule->tocSL->setValue(params.tocdepth);
968                 updateNumbering();
969         } else {
970                 numberingModule->setEnabled(false);
971                 numberingModule->tocTW->clear();
972         }
973
974         // bullets
975         bulletsModule->setBullet(0, params.user_defined_bullet(0));
976         bulletsModule->setBullet(1, params.user_defined_bullet(1));
977         bulletsModule->setBullet(2, params.user_defined_bullet(2));
978         bulletsModule->setBullet(3, params.user_defined_bullet(3));
979         bulletsModule->init();
980
981         // packages
982         QString text = toqstr(params.graphicsDriver);
983         int nitem = latexModule->psdriverCO->count();
984         for (int n = 0; n < nitem ; ++n) {
985                 QString enc = tex_graphics[n];
986                 if (enc == text) {
987                         latexModule->psdriverCO->setCurrentIndex(n);
988                 }
989         }
990
991
992         mathsModule->amsCB->setChecked(
993                 params.use_amsmath == BufferParams::AMS_ON);
994         mathsModule->amsautoCB->setChecked(
995                 params.use_amsmath == BufferParams::AMS_AUTO);
996
997         switch (params.spacing().getSpace()) {
998                 case Spacing::Other: nitem = 3; break;
999                 case Spacing::Double: nitem = 2; break;
1000                 case Spacing::Onehalf: nitem = 1; break;
1001                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1002         }
1003
1004         // text layout
1005         latexModule->classCO->setCurrentIndex(params.textclass);
1006
1007         updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1008                                  params.pagestyle);
1009
1010         textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1011         if (params.spacing().getSpace() == Spacing::Other) {
1012                 textLayoutModule->lspacingLE->setText(
1013                         toqstr(params.spacing().getValueAsString()));
1014         }
1015         setLSpacing(nitem);
1016
1017         if (params.paragraph_separation
1018             == BufferParams::PARSEP_INDENT) {
1019                 textLayoutModule->indentRB->setChecked(true);
1020         } else {
1021                 textLayoutModule->skipRB->setChecked(true);
1022         }
1023
1024         int skip = 0;
1025         switch (params.getDefSkip().kind()) {
1026         case VSpace::SMALLSKIP:
1027                 skip = 0;
1028                 break;
1029         case VSpace::MEDSKIP:
1030                 skip = 1;
1031                 break;
1032         case VSpace::BIGSKIP:
1033                 skip = 2;
1034                 break;
1035         case VSpace::LENGTH:
1036         {
1037                 skip = 3;
1038                 string const length = params.getDefSkip().asLyXCommand();
1039                 lengthToWidgets(textLayoutModule->skipLE,
1040                         textLayoutModule->skipLengthCO,
1041                         length, defaultUnit);
1042                 break;
1043         }
1044         default:
1045                 skip = 0;
1046                 break;
1047         }
1048         textLayoutModule->skipCO->setCurrentIndex(skip);
1049         setSkip(skip);
1050
1051         textLayoutModule->twoColumnCB->setChecked(
1052                 params.columns == 2);
1053
1054         if (!params.options.empty()) {
1055                 latexModule->optionsLE->setText(
1056                         toqstr(params.options));
1057         } else {
1058                 latexModule->optionsLE->setText("");
1059         }
1060
1061         floatModule->set(params.float_placement);
1062
1063         //fonts
1064         updateFontsize(form_->controller().textClass().opt_fontsize(),
1065                         params.fontsize);
1066
1067         int n = findToken(tex_fonts_roman, params.fontsRoman);
1068         if (n >= 0)
1069                 fontModule->fontsRomanCO->setCurrentIndex(n);
1070
1071         n = findToken(tex_fonts_sans, params.fontsSans);
1072         if (n >= 0)
1073                 fontModule->fontsSansCO->setCurrentIndex(n);
1074
1075         n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1076         if (n >= 0)
1077                 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1078
1079         fontModule->fontScCB->setChecked(params.fontsSC);
1080         fontModule->fontOsfCB->setChecked(params.fontsOSF);
1081         fontModule->fontScCB->setEnabled(
1082                 form_->controller().providesSC(params.fontsRoman));
1083         fontModule->fontOsfCB->setEnabled(
1084                 form_->controller().providesOSF(params.fontsRoman));
1085         fontModule->scaleSansSB->setValue(params.fontsSansScale);
1086         fontModule->scaleTypewriterSB->setValue(
1087                 params.fontsTypewriterScale);
1088         fontModule->scaleSansSB->setEnabled(
1089                 form_->controller().providesScale(params.fontsSans));
1090         fontModule->scaleTypewriterSB->setEnabled(
1091                 form_->controller().providesScale(params.fontsTypewriter));
1092         n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
1093         if (n >= 0)
1094                 fontModule->fontsDefaultCO->setCurrentIndex(n);
1095
1096         // paper
1097         int const psize = params.papersize;
1098         pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1099         setCustomPapersize(psize);
1100
1101         bool const landscape =
1102                 params.orientation == ORIENTATION_LANDSCAPE;
1103         pageLayoutModule->landscapeRB->setChecked(landscape);
1104         pageLayoutModule->portraitRB->setChecked(!landscape);
1105
1106         pageLayoutModule->facingPagesCB->setChecked(
1107                 params.sides == LyXTextClass::TwoSides);
1108
1109
1110         lengthToWidgets(pageLayoutModule->paperwidthLE,
1111                 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1112
1113         lengthToWidgets(pageLayoutModule->paperheightLE,
1114                 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1115
1116         // margins
1117         Ui::MarginsUi * m = marginsModule;
1118
1119         setMargins(!params.use_geometry);
1120
1121         lengthToWidgets(m->topLE, m->topUnit,
1122                 params.topmargin, defaultUnit);
1123
1124         lengthToWidgets(m->bottomLE, m->bottomUnit,
1125                 params.bottommargin, defaultUnit);
1126
1127         lengthToWidgets(m->innerLE, m->innerUnit,
1128                 params.leftmargin, defaultUnit);
1129
1130         lengthToWidgets(m->outerLE, m->outerUnit,
1131                 params.rightmargin, defaultUnit);
1132
1133         lengthToWidgets(m->headheightLE, m->headheightUnit,
1134                 params.headheight, defaultUnit);
1135
1136         lengthToWidgets(m->headsepLE, m->headsepUnit,
1137                 params.headsep, defaultUnit);
1138
1139         lengthToWidgets(m->footskipLE, m->footskipUnit,
1140                 params.footskip, defaultUnit);
1141
1142         branchesModule->update(params);
1143 }
1144
1145
1146
1147
1148 } // namespace frontend
1149 } // namespace lyx
1150
1151 #include "QDocumentDialog_moc.cpp"