2 * \file QDocumentDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
14 #include "QDocument.h"
15 #include "QDocumentDialog.h"
17 #include <QCloseEvent>
19 #include "FloatPlacement.h"
20 #include "lengthcombo.h"
21 #include "validators.h"
22 #include "panelstack.h"
24 #include "checkedwidgets.h"
25 #include "qt_helpers.h"
27 #include "bufferparams.h"
29 #include "helper_funcs.h" // getSecond()
31 #include "lyxrc.h" // defaultUnit
32 #include "lyxtextclasslist.h"
33 #include "tex-strings.h" // tex_graphics
36 #include "controllers/ControlDocument.h"
37 #include "controllers/frnt_lang.h"
39 #include "support/lstrings.h"
41 #include "controllers/ControlDocument.h"
42 #include "controllers/frnt_lang.h"
45 using lyx::support::token;
46 using lyx::support::bformat;
47 using lyx::support::findToken;
48 using lyx::support::getVectorFromString;
61 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
62 "latin3", "latin4", "latin5", "latin9",
63 "koi8-r", "koi8-u", "cp866", "cp1251",
64 "iso88595", "pt154", 0
69 QDocumentDialog::QDocumentDialog(QDocument * form)
71 lang_(getSecond(getLanguageData(false)))
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()));
85 connect(savePB, SIGNAL( clicked() ),
86 this, SLOT( saveDefaultClicked() ) );
87 connect(defaultPB, SIGNAL( clicked() ),
88 this, SLOT( useDefaultsClicked() ) );
90 // Manage the restore, ok, apply, restore and cancel/close buttons
91 form_->bcview().setOK(okPB);
92 form_->bcview().setApply(applyPB);
93 form_->bcview().setCancel(closePB);
94 form_->bcview().setRestore(restorePB);
97 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
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));
115 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
116 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
117 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
118 textLayoutModule->skipCO->addItem(qt_("Length"));
119 // remove the %-items from the unit choice
120 textLayoutModule->skipLengthCO->noPercents();
121 textLayoutModule->lspacingCO->insertItem(
122 Spacing::Single, qt_("Single"));
123 textLayoutModule->lspacingCO->insertItem(
124 Spacing::Onehalf, qt_("OneHalf"));
125 textLayoutModule->lspacingCO->insertItem(
126 Spacing::Double, qt_("Double"));
127 textLayoutModule->lspacingCO->insertItem(
128 Spacing::Other, qt_("Custom"));
130 // initialize the length validator
131 addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
136 fontModule = new UiWidget<Ui::FontUi>;
138 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
139 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(romanChanged(int)));
140 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
141 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(sansChanged(int)));
142 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
143 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int)));
144 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
145 connect(fontModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
146 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
147 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
148 connect(fontModule->fontScCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
149 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
151 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
152 QString font = toqstr(tex_fonts_roman_gui[n]);
153 if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
154 font += qt_(" (not installed)");
155 fontModule->fontsRomanCO->addItem(font);
157 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
158 QString font = toqstr(tex_fonts_sans_gui[n]);
159 if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
160 font += qt_(" (not installed)");
161 fontModule->fontsSansCO->addItem(font);
163 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
164 QString font = toqstr(tex_fonts_monospaced_gui[n]);
165 if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
166 font += qt_(" (not installed)");
167 fontModule->fontsTypewriterCO->addItem(font);
170 fontModule->fontsizeCO->addItem(qt_("default"));
171 fontModule->fontsizeCO->addItem(qt_("10"));
172 fontModule->fontsizeCO->addItem(qt_("11"));
173 fontModule->fontsizeCO->addItem(qt_("12"));
175 for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
176 fontModule->fontsDefaultCO->addItem(
177 qt_(ControlDocument::fontfamilies_gui[n]));
182 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
184 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
185 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
186 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
187 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
188 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
189 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
190 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
191 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
192 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
193 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
194 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
195 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
196 pageLayoutModule->pagestyleCO->addItem(qt_("default"));
197 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
198 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
199 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
200 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
201 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
202 pageLayoutModule->paperheightL);
203 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
204 pageLayoutModule->paperwidthL);
207 QComboBox * cb = pageLayoutModule->papersizeCO;
208 cb->addItem(qt_("Default"));
209 cb->addItem(qt_("Custom"));
210 cb->addItem(qt_("US letter"));
211 cb->addItem(qt_("US legal"));
212 cb->addItem(qt_("US executive"));
213 cb->addItem(qt_("A3"));
214 cb->addItem(qt_("A4"));
215 cb->addItem(qt_("A5"));
216 cb->addItem(qt_("B3"));
217 cb->addItem(qt_("B4"));
218 cb->addItem(qt_("B5"));
219 // remove the %-items from the unit choice
220 pageLayoutModule->paperwidthUnitCO->noPercents();
221 pageLayoutModule->paperheightUnitCO->noPercents();
222 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
223 pageLayoutModule->paperheightLE));
224 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
225 pageLayoutModule->paperwidthLE));
230 marginsModule = new UiWidget<Ui::MarginsUi>;
232 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
233 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
234 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
235 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
236 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
237 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
238 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
239 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
240 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
241 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
242 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
243 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
244 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
245 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
246 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
247 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
248 marginsModule->topLE->setValidator(unsignedLengthValidator(
249 marginsModule->topLE));
250 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
251 marginsModule->bottomLE));
252 marginsModule->innerLE->setValidator(unsignedLengthValidator(
253 marginsModule->innerLE));
254 marginsModule->outerLE->setValidator(unsignedLengthValidator(
255 marginsModule->outerLE));
256 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
257 marginsModule->headsepLE));
258 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
259 marginsModule->headheightLE));
260 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
261 marginsModule->footskipLE));
263 addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
264 marginsModule->topL);
265 addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
266 marginsModule->bottomL);
267 addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
268 marginsModule->innerL);
269 addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
270 marginsModule->outerL);
271 addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
272 marginsModule->headsepL);
273 addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
274 marginsModule->headheightL);
275 addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
276 marginsModule->footskipL);
282 langModule = new UiWidget<Ui::LanguageUi>;
283 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingL, SLOT( setDisabled(bool) ) );
284 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingCO, SLOT( setDisabled(bool) ) );
286 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
287 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
288 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
289 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
291 vector<LanguagePair> const langs = getLanguageData(false);
292 vector<LanguagePair>::const_iterator lit = langs.begin();
293 vector<LanguagePair>::const_iterator lend = langs.end();
294 for (; lit != lend; ++lit) {
295 langModule->languageCO->addItem(
300 while (encodings[k]) {
301 langModule->encodingCO->addItem(qt_(encodings[k++]));
304 langModule->quoteStyleCO->addItem(qt_("``text''"));
305 langModule->quoteStyleCO->addItem(qt_("''text''"));
306 langModule->quoteStyleCO->addItem(qt_(",,text``"));
307 langModule->quoteStyleCO->addItem(qt_(",,text''"));
308 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
309 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
313 numberingModule = new UiWidget<Ui::NumberingUi>;
315 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
316 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
317 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
318 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
319 numberingModule->tocTW->setColumnCount(3);
320 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
321 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
322 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
325 biblioModule = new UiWidget<Ui::BiblioUi>;
326 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citationStyleL, SLOT( setEnabled(bool) ) );
327 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citeStyleCO, SLOT( setEnabled(bool) ) );
329 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
330 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
331 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
332 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
333 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
335 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
336 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
337 biblioModule->citeStyleCO->setCurrentIndex(0);
341 mathsModule = new UiWidget<Ui::MathsUi>;
342 connect( mathsModule->amsautoCB, SIGNAL( toggled(bool) ), mathsModule->amsCB, SLOT( setDisabled(bool) ) );
344 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
345 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
348 latexModule = new UiWidget<Ui::LaTeXUi>;
350 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
351 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
352 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
353 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
355 for (int n = 0; tex_graphics[n][0]; ++n) {
356 QString enc = tex_graphics[n];
357 latexModule->psdriverCO->addItem(enc);
360 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
361 cit != textclasslist.end(); ++cit) {
362 if (cit->isTeXClassAvailable()) {
363 latexModule->classCO->addItem(toqstr(cit->description()));
366 bformat(_("Unavailable: %1$s"), lyx::from_utf8(cit->description()));
367 latexModule->classCO->addItem(toqstr(item));
373 branchesModule = new QBranches;
374 connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
378 preambleModule = new UiWidget<Ui::PreambleUi>;
379 connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
383 bulletsModule = new BulletsModule;
384 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
388 floatModule = new FloatPlacement;
389 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
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"));
408 QDocumentDialog::~QDocumentDialog()
413 void QDocumentDialog::showPreamble()
415 docPS->setCurrentPanel(_("LaTeX Preamble"));
419 void QDocumentDialog::saveDefaultClicked()
421 form_->saveDocDefault();
425 void QDocumentDialog::useDefaultsClicked()
427 form_->useClassDefaults();
431 void QDocumentDialog::change_adaptor()
437 void QDocumentDialog::closeEvent(QCloseEvent * e)
444 void QDocumentDialog::setLSpacing(int item)
446 textLayoutModule->lspacingLE->setEnabled(item == 3);
450 void QDocumentDialog::setSkip(int item)
452 bool const enable = (item == 3);
453 textLayoutModule->skipLE->setEnabled(enable);
454 textLayoutModule->skipLengthCO->setEnabled(enable);
458 void QDocumentDialog::enableSkip(bool skip)
460 textLayoutModule->skipCO->setEnabled(skip);
461 textLayoutModule->skipLE->setEnabled(skip);
462 textLayoutModule->skipLengthCO->setEnabled(skip);
464 setSkip(textLayoutModule->skipCO->currentIndex());
467 void QDocumentDialog::portraitChanged()
469 setMargins(pageLayoutModule->papersizeCO->currentIndex());
472 void QDocumentDialog::setMargins(bool custom)
474 marginsModule->marginCB->setChecked(custom);
475 setCustomMargins(custom);
479 void QDocumentDialog::setCustomPapersize(int papersize)
481 bool const custom = (papersize == 1);
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);
493 void QDocumentDialog::setCustomMargins(bool custom)
495 marginsModule->topL->setEnabled(!custom);
496 marginsModule->topLE->setEnabled(!custom);
497 marginsModule->topUnit->setEnabled(!custom);
499 marginsModule->bottomL->setEnabled(!custom);
500 marginsModule->bottomLE->setEnabled(!custom);
501 marginsModule->bottomUnit->setEnabled(!custom);
503 marginsModule->innerL->setEnabled(!custom);
504 marginsModule->innerLE->setEnabled(!custom);
505 marginsModule->innerUnit->setEnabled(!custom);
507 marginsModule->outerL->setEnabled(!custom);
508 marginsModule->outerLE->setEnabled(!custom);
509 marginsModule->outerUnit->setEnabled(!custom);
511 marginsModule->headheightL->setEnabled(!custom);
512 marginsModule->headheightLE->setEnabled(!custom);
513 marginsModule->headheightUnit->setEnabled(!custom);
515 marginsModule->headsepL->setEnabled(!custom);
516 marginsModule->headsepLE->setEnabled(!custom);
517 marginsModule->headsepUnit->setEnabled(!custom);
519 marginsModule->footskipL->setEnabled(!custom);
520 marginsModule->footskipLE->setEnabled(!custom);
521 marginsModule->footskipUnit->setEnabled(!custom);
525 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
527 fontModule->fontsizeCO->clear();
528 fontModule->fontsizeCO->addItem(qt_("default"));
530 for (int n = 0; !token(items,'|',n).empty(); ++n)
531 fontModule->fontsizeCO->
532 addItem(toqstr(token(items,'|',n)));
534 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
535 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
536 fontModule->fontsizeCO->setCurrentIndex(n);
543 void QDocumentDialog::romanChanged(int item)
545 string const font = tex_fonts_roman[item];
547 fontModule->fontScCB->setEnabled(
548 form_->controller().providesSC(font));
549 fontModule->fontOsfCB->setEnabled(
550 form_->controller().providesOSF(font));
554 void QDocumentDialog::sansChanged(int item)
556 string const font = tex_fonts_sans[item];
558 fontModule->scaleSansSB->setEnabled(
559 form_->controller().providesScale(font));
563 void QDocumentDialog::ttChanged(int item)
565 string const font = tex_fonts_monospaced[item];
567 fontModule->scaleTypewriterSB->setEnabled(
568 form_->controller().providesScale(font));
572 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
574 pageLayoutModule->pagestyleCO->clear();
575 pageLayoutModule->pagestyleCO->addItem("default");
577 for (int n=0; !token(items,'|',n).empty(); ++n)
578 pageLayoutModule->pagestyleCO->
579 addItem(toqstr(token(items,'|',n)));
581 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
582 if (fromqstr(pageLayoutModule->pagestyleCO->itemText(n))==sel) {
583 pageLayoutModule->pagestyleCO->setCurrentIndex(n);
590 void QDocumentDialog::classChanged()
592 ControlDocument & cntrl = form_->controller();
593 BufferParams & params = cntrl.params();
595 lyx::textclass_type const tc = latexModule->classCO->currentIndex();
597 if (form_->controller().loadTextclass(tc)) {
598 params.textclass = tc;
599 if (lyxrc.auto_reset_options)
600 params.useClassDefaults();
601 form_->update_contents();
603 latexModule->classCO->setCurrentIndex(params.textclass);
608 void QDocumentDialog::updateNumbering()
610 LyXTextClass const & tclass =
611 form_->controller().params().getLyXTextClass();
613 numberingModule->tocTW->setUpdatesEnabled(false);
614 numberingModule->tocTW->clear();
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);
634 numberingModule->tocTW->setUpdatesEnabled(true);
635 numberingModule->tocTW->update();
638 void QDocumentDialog::apply(BufferParams & params)
642 fromqstr(preambleModule->preambleTE->document()->toPlainText());
645 params.cite_engine = biblio::ENGINE_BASIC;
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;
653 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
655 } else if (biblioModule->citeJurabibRB->isChecked())
656 params.cite_engine = biblio::ENGINE_JURABIB;
658 params.use_bibtopic =
659 biblioModule->bibtopicCB->isChecked();
662 if (langModule->defaultencodingCB->isChecked()) {
663 params.inputenc = "auto";
665 int i = langModule->encodingCO->currentIndex();
667 params.inputenc = "default";
669 params.inputenc = encodings[i];
673 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
674 switch (langModule->quoteStyleCO->currentIndex()) {
676 lga = InsetQuotes::EnglishQ;
679 lga = InsetQuotes::SwedishQ;
682 lga = InsetQuotes::GermanQ;
685 lga = InsetQuotes::PolishQ;
688 lga = InsetQuotes::FrenchQ;
691 lga = InsetQuotes::DanishQ;
694 params.quotes_language = lga;
696 int const pos = langModule->languageCO->currentIndex();
697 params.language = languages.getLanguage(lang_[pos]);
700 if (params.getLyXTextClass().hasTocLevels()) {
701 params.tocdepth = numberingModule->tocSL->value();
702 params.secnumdepth = numberingModule->depthSL->value();
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);
712 params.graphicsDriver =
713 fromqstr(latexModule->psdriverCO->currentText());
715 if (mathsModule->amsautoCB->isChecked()) {
716 params.use_amsmath = BufferParams::AMS_AUTO;
718 if (mathsModule->amsCB->isChecked())
719 params.use_amsmath = BufferParams::AMS_ON;
721 params.use_amsmath = BufferParams::AMS_OFF;
726 latexModule->classCO->currentIndex();
729 fromqstr(pageLayoutModule->pagestyleCO->currentText());
731 switch (textLayoutModule->lspacingCO->currentIndex()) {
733 params.spacing().set(Spacing::Single);
736 params.spacing().set(Spacing::Onehalf);
739 params.spacing().set(Spacing::Double);
742 params.spacing().set(Spacing::Other,
743 fromqstr(textLayoutModule->lspacingLE->text()));
747 if (textLayoutModule->twoColumnCB->isChecked())
752 if (textLayoutModule->indentRB->isChecked())
753 params.paragraph_separation = BufferParams::PARSEP_INDENT;
755 params.paragraph_separation = BufferParams::PARSEP_SKIP;
757 switch (textLayoutModule->skipCO->currentIndex()) {
759 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
762 params.setDefSkip(VSpace(VSpace::MEDSKIP));
765 params.setDefSkip(VSpace(VSpace::BIGSKIP));
770 widgetsToLength(textLayoutModule->skipLE,
771 textLayoutModule->skipLengthCO)
773 params.setDefSkip(vs);
777 // DocumentDefskipCB assures that this never happens
778 // so Assert then !!! - jbl
779 params.setDefSkip(VSpace(VSpace::MEDSKIP));
784 fromqstr(latexModule->optionsLE->text());
786 params.float_placement = floatModule->get();
790 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
793 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
795 params.fontsTypewriter =
796 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
798 params.fontsSansScale = fontModule->scaleSansSB->value();
800 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
802 params.fontsSC = fontModule->fontScCB->isChecked();
804 params.fontsOSF = fontModule->fontOsfCB->isChecked();
806 params.fontsDefaultFamily = ControlDocument::fontfamilies[
807 fontModule->fontsDefaultCO->currentIndex()];
809 if (fontModule->fontsizeCO->currentIndex() == 0)
810 params.fontsize = "default";
813 fromqstr(fontModule->fontsizeCO->currentText());
816 params.papersize = PAPER_SIZE(
817 pageLayoutModule->papersizeCO->currentIndex());
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);
823 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
824 pageLayoutModule->paperwidthUnitCO);
826 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
827 pageLayoutModule->paperheightUnitCO);
829 if (pageLayoutModule->facingPagesCB->isChecked())
830 params.sides = LyXTextClass::TwoSides;
832 params.sides = LyXTextClass::OneSide;
834 if (pageLayoutModule->landscapeRB->isChecked())
835 params.orientation = ORIENTATION_LANDSCAPE;
837 params.orientation = ORIENTATION_PORTRAIT;
840 params.use_geometry =
841 (!marginsModule->marginCB->isChecked()
844 Ui::MarginsUi const * m(marginsModule);
846 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
848 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
850 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
852 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
854 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
856 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
858 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
860 branchesModule->apply(params);
865 /** Return the position of val in the vector if found.
866 If not found, return 0.
869 typename std::vector<A>::size_type
870 findPos(std::vector<A> const & vec, A const & val)
872 typename std::vector<A>::const_iterator it =
873 std::find(vec.begin(), vec.end(), val);
876 return distance(vec.begin(), it);
882 void QDocumentDialog::update(BufferParams const & params)
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;
892 case PAPER_USEXECUTIVE:
893 defaultUnit = LyXLength::IN;
902 defaultUnit = LyXLength::CM;
909 QString preamble = toqstr(params.preamble);
910 preambleModule->preambleTE->document()->setPlainText(preamble);
913 biblioModule->citeDefaultRB->setChecked(
914 params.cite_engine == biblio::ENGINE_BASIC);
916 biblioModule->citeNatbibRB->setChecked(
917 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
918 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
920 biblioModule->citeStyleCO->setCurrentIndex(
921 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
923 biblioModule->citeJurabibRB->setChecked(
924 params.cite_engine == biblio::ENGINE_JURABIB);
926 biblioModule->bibtopicCB->setChecked(
927 params.use_bibtopic);
930 int const pos = int(findPos(lang_,
931 params.language->lang()));
932 langModule->languageCO->setCurrentIndex(pos);
934 langModule->quoteStyleCO->setCurrentIndex(
935 params.quotes_language);
937 langModule->defaultencodingCB->setChecked(true);
939 if (params.inputenc != "auto") {
940 langModule->defaultencodingCB->setChecked(false);
941 if (params.inputenc == "default") {
942 langModule->encodingCO->setCurrentIndex(0);
945 while (encodings[i]) {
946 if (encodings[i] == params.inputenc)
947 langModule->encodingCO->setCurrentIndex(i);
954 int const min_toclevel = form_->controller().textClass().min_toclevel();
955 int const max_toclevel = form_->controller().textClass().max_toclevel();
956 if (form_->controller().textClass().hasTocLevels()) {
957 numberingModule->setEnabled(true);
958 numberingModule->depthSL->setMinimum(min_toclevel - 1);
959 numberingModule->depthSL->setMaximum(max_toclevel);
960 numberingModule->depthSL->setValue(params.secnumdepth);
961 numberingModule->tocSL->setMaximum(min_toclevel - 1);
962 numberingModule->tocSL->setMaximum(max_toclevel);
963 numberingModule->tocSL->setValue(params.tocdepth);
966 numberingModule->setEnabled(false);
967 numberingModule->tocTW->clear();
971 bulletsModule->setBullet(0, params.user_defined_bullet(0));
972 bulletsModule->setBullet(1, params.user_defined_bullet(1));
973 bulletsModule->setBullet(2, params.user_defined_bullet(2));
974 bulletsModule->setBullet(3, params.user_defined_bullet(3));
975 bulletsModule->init();
978 QString text = toqstr(params.graphicsDriver);
979 int nitem = latexModule->psdriverCO->count();
980 for (int n = 0; n < nitem ; ++n) {
981 QString enc = tex_graphics[n];
983 latexModule->psdriverCO->setCurrentIndex(n);
988 mathsModule->amsCB->setChecked(
989 params.use_amsmath == BufferParams::AMS_ON);
990 mathsModule->amsautoCB->setChecked(
991 params.use_amsmath == BufferParams::AMS_AUTO);
993 switch (params.spacing().getSpace()) {
994 case Spacing::Other: nitem = 3; break;
995 case Spacing::Double: nitem = 2; break;
996 case Spacing::Onehalf: nitem = 1; break;
997 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1001 latexModule->classCO->setCurrentIndex(params.textclass);
1003 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1006 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1007 if (params.spacing().getSpace() == Spacing::Other) {
1008 textLayoutModule->lspacingLE->setText(
1009 toqstr(params.spacing().getValueAsString()));
1013 if (params.paragraph_separation
1014 == BufferParams::PARSEP_INDENT) {
1015 textLayoutModule->indentRB->setChecked(true);
1017 textLayoutModule->skipRB->setChecked(true);
1021 switch (params.getDefSkip().kind()) {
1022 case VSpace::SMALLSKIP:
1025 case VSpace::MEDSKIP:
1028 case VSpace::BIGSKIP:
1031 case VSpace::LENGTH:
1034 string const length = params.getDefSkip().asLyXCommand();
1035 lengthToWidgets(textLayoutModule->skipLE,
1036 textLayoutModule->skipLengthCO,
1037 length, defaultUnit);
1044 textLayoutModule->skipCO->setCurrentIndex(skip);
1047 textLayoutModule->twoColumnCB->setChecked(
1048 params.columns == 2);
1050 if (!params.options.empty()) {
1051 latexModule->optionsLE->setText(
1052 toqstr(params.options));
1054 latexModule->optionsLE->setText("");
1057 floatModule->set(params.float_placement);
1060 updateFontsize(form_->controller().textClass().opt_fontsize(),
1063 int n = findToken(tex_fonts_roman, params.fontsRoman);
1065 fontModule->fontsRomanCO->setCurrentIndex(n);
1067 n = findToken(tex_fonts_sans, params.fontsSans);
1069 fontModule->fontsSansCO->setCurrentIndex(n);
1071 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1073 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1075 fontModule->fontScCB->setChecked(params.fontsSC);
1076 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1077 fontModule->fontScCB->setEnabled(
1078 form_->controller().providesSC(params.fontsRoman));
1079 fontModule->fontOsfCB->setEnabled(
1080 form_->controller().providesOSF(params.fontsRoman));
1081 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1082 fontModule->scaleTypewriterSB->setValue(
1083 params.fontsTypewriterScale);
1084 fontModule->scaleSansSB->setEnabled(
1085 form_->controller().providesScale(params.fontsSans));
1086 fontModule->scaleTypewriterSB->setEnabled(
1087 form_->controller().providesScale(params.fontsTypewriter));
1088 n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
1090 fontModule->fontsDefaultCO->setCurrentIndex(n);
1093 int const psize = params.papersize;
1094 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1095 setCustomPapersize(psize);
1097 bool const landscape =
1098 params.orientation == ORIENTATION_LANDSCAPE;
1099 pageLayoutModule->landscapeRB->setChecked(landscape);
1100 pageLayoutModule->portraitRB->setChecked(!landscape);
1102 pageLayoutModule->facingPagesCB->setChecked(
1103 params.sides == LyXTextClass::TwoSides);
1106 lengthToWidgets(pageLayoutModule->paperwidthLE,
1107 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1109 lengthToWidgets(pageLayoutModule->paperheightLE,
1110 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1113 Ui::MarginsUi * m = marginsModule;
1115 setMargins(!params.use_geometry);
1117 lengthToWidgets(m->topLE, m->topUnit,
1118 params.topmargin, defaultUnit);
1120 lengthToWidgets(m->bottomLE, m->bottomUnit,
1121 params.bottommargin, defaultUnit);
1123 lengthToWidgets(m->innerLE, m->innerUnit,
1124 params.leftmargin, defaultUnit);
1126 lengthToWidgets(m->outerLE, m->outerUnit,
1127 params.rightmargin, defaultUnit);
1129 lengthToWidgets(m->headheightLE, m->headheightUnit,
1130 params.headheight, defaultUnit);
1132 lengthToWidgets(m->headsepLE, m->headsepUnit,
1133 params.headsep, defaultUnit);
1135 lengthToWidgets(m->footskipLE, m->footskipUnit,
1136 params.footskip, defaultUnit);
1138 branchesModule->update(params);
1144 } // namespace frontend
1147 #include "QDocumentDialog_moc.cpp"