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 // 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
71 QDocumentDialog::QDocumentDialog(QDocument * form)
73 lang_(getSecond(getLanguageData(false)))
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()));
87 connect(savePB, SIGNAL( clicked() ),
88 this, SLOT( saveDefaultClicked() ) );
89 connect(defaultPB, SIGNAL( clicked() ),
90 this, SLOT( useDefaultsClicked() ) );
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);
99 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
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));
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"));
132 // initialize the length validator
133 addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
138 fontModule = new UiWidget<Ui::FontUi>;
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()));
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);
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);
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);
172 fontModule->fontsizeCO->addItem(qt_("default"));
173 fontModule->fontsizeCO->addItem(qt_("10"));
174 fontModule->fontsizeCO->addItem(qt_("11"));
175 fontModule->fontsizeCO->addItem(qt_("12"));
177 for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
178 fontModule->fontsDefaultCO->addItem(
179 qt_(ControlDocument::fontfamilies_gui[n]));
184 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
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);
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));
232 marginsModule = new UiWidget<Ui::MarginsUi>;
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));
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);
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)));
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()));
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(
302 while (encodings[k]) {
303 langModule->encodingCO->addItem(qt_(encodings[k++]));
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<<"));
315 numberingModule = new UiWidget<Ui::NumberingUi>;
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"));
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) ) );
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()));
337 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
338 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
339 biblioModule->citeStyleCO->setCurrentIndex(0);
343 mathsModule = new UiWidget<Ui::MathsUi>;
344 connect( mathsModule->amsautoCB, SIGNAL( toggled(bool) ), mathsModule->amsCB, SLOT( setDisabled(bool) ) );
346 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
347 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
350 latexModule = new UiWidget<Ui::LaTeXUi>;
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()));
357 for (int n = 0; tex_graphics[n][0]; ++n) {
358 QString enc = tex_graphics[n];
359 latexModule->psdriverCO->addItem(enc);
362 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
363 cit != textclasslist.end(); ++cit) {
364 if (cit->isTeXClassAvailable()) {
365 latexModule->classCO->addItem(toqstr(cit->description()));
368 bformat(_("Unavailable: %1$s"), lyx::from_utf8(cit->description()));
369 latexModule->classCO->addItem(toqstr(item));
374 branchesModule = new QBranches;
375 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);
952 // FIXME: possible data loss because of encodings is
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);
970 numberingModule->setEnabled(false);
971 numberingModule->tocTW->clear();
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();
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];
987 latexModule->psdriverCO->setCurrentIndex(n);
992 mathsModule->amsCB->setChecked(
993 params.use_amsmath == BufferParams::AMS_ON);
994 mathsModule->amsautoCB->setChecked(
995 params.use_amsmath == BufferParams::AMS_AUTO);
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;
1005 latexModule->classCO->setCurrentIndex(params.textclass);
1007 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1010 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1011 if (params.spacing().getSpace() == Spacing::Other) {
1012 textLayoutModule->lspacingLE->setText(
1013 toqstr(params.spacing().getValueAsString()));
1017 if (params.paragraph_separation
1018 == BufferParams::PARSEP_INDENT) {
1019 textLayoutModule->indentRB->setChecked(true);
1021 textLayoutModule->skipRB->setChecked(true);
1025 switch (params.getDefSkip().kind()) {
1026 case VSpace::SMALLSKIP:
1029 case VSpace::MEDSKIP:
1032 case VSpace::BIGSKIP:
1035 case VSpace::LENGTH:
1038 string const length = params.getDefSkip().asLyXCommand();
1039 lengthToWidgets(textLayoutModule->skipLE,
1040 textLayoutModule->skipLengthCO,
1041 length, defaultUnit);
1048 textLayoutModule->skipCO->setCurrentIndex(skip);
1051 textLayoutModule->twoColumnCB->setChecked(
1052 params.columns == 2);
1054 if (!params.options.empty()) {
1055 latexModule->optionsLE->setText(
1056 toqstr(params.options));
1058 latexModule->optionsLE->setText("");
1061 floatModule->set(params.float_placement);
1064 updateFontsize(form_->controller().textClass().opt_fontsize(),
1067 int n = findToken(tex_fonts_roman, params.fontsRoman);
1069 fontModule->fontsRomanCO->setCurrentIndex(n);
1071 n = findToken(tex_fonts_sans, params.fontsSans);
1073 fontModule->fontsSansCO->setCurrentIndex(n);
1075 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1077 fontModule->fontsTypewriterCO->setCurrentIndex(n);
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);
1094 fontModule->fontsDefaultCO->setCurrentIndex(n);
1097 int const psize = params.papersize;
1098 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1099 setCustomPapersize(psize);
1101 bool const landscape =
1102 params.orientation == ORIENTATION_LANDSCAPE;
1103 pageLayoutModule->landscapeRB->setChecked(landscape);
1104 pageLayoutModule->portraitRB->setChecked(!landscape);
1106 pageLayoutModule->facingPagesCB->setChecked(
1107 params.sides == LyXTextClass::TwoSides);
1110 lengthToWidgets(pageLayoutModule->paperwidthLE,
1111 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1113 lengthToWidgets(pageLayoutModule->paperheightLE,
1114 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1117 Ui::MarginsUi * m = marginsModule;
1119 setMargins(!params.use_geometry);
1121 lengthToWidgets(m->topLE, m->topUnit,
1122 params.topmargin, defaultUnit);
1124 lengthToWidgets(m->bottomLE, m->bottomUnit,
1125 params.bottommargin, defaultUnit);
1127 lengthToWidgets(m->innerLE, m->innerUnit,
1128 params.leftmargin, defaultUnit);
1130 lengthToWidgets(m->outerLE, m->outerUnit,
1131 params.rightmargin, defaultUnit);
1133 lengthToWidgets(m->headheightLE, m->headheightUnit,
1134 params.headheight, defaultUnit);
1136 lengthToWidgets(m->headsepLE, m->headsepUnit,
1137 params.headsep, defaultUnit);
1139 lengthToWidgets(m->footskipLE, m->footskipUnit,
1140 params.footskip, defaultUnit);
1142 branchesModule->update(params);
1148 } // namespace frontend
1151 #include "QDocumentDialog_moc.cpp"