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"
28 #include "floatplacement.h"
30 #include "helper_funcs.h" // getSecond()
32 #include "lyxrc.h" // defaultUnit
33 #include "lyxtextclasslist.h"
34 #include "tex-strings.h" // tex_graphics
37 #include "controllers/ControlDocument.h"
38 #include "controllers/frnt_lang.h"
40 #include "support/lstrings.h"
42 #include "controllers/ControlDocument.h"
43 #include "controllers/frnt_lang.h"
46 using lyx::support::token;
47 using lyx::support::bformat;
48 using lyx::support::findToken;
49 using lyx::support::getVectorFromString;
62 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
63 "latin3", "latin4", "latin5", "latin9",
64 "koi8-r", "koi8-u", "cp866", "cp1251",
65 "iso88595", "pt154", 0
70 QDocumentDialog::QDocumentDialog(QDocument * form)
72 lang_(getSecond(getLanguageData(false)))
76 connect(okPB, SIGNAL(clicked()),
77 form, SLOT(slotOK()));
78 connect(applyPB, SIGNAL(clicked()),
79 form, SLOT(slotApply()));
80 connect(closePB, SIGNAL(clicked()),
81 form, SLOT(slotClose()));
82 connect(restorePB, SIGNAL(clicked()),
83 form, SLOT(slotRestore()));
86 connect(savePB, SIGNAL( clicked() ),
87 this, SLOT( saveDefaultClicked() ) );
88 connect(defaultPB, SIGNAL( clicked() ),
89 this, SLOT( useDefaultsClicked() ) );
91 // Manage the restore, ok, apply, restore and cancel/close buttons
92 form_->bcview().setOK(okPB);
93 form_->bcview().setApply(applyPB);
94 form_->bcview().setCancel(closePB);
95 form_->bcview().setRestore(restorePB);
98 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
100 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
101 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
102 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
103 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
104 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
105 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
106 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
107 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
108 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
109 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
110 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
111 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
112 textLayoutModule->lspacingLE));
113 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
114 textLayoutModule->skipLE));
116 textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
117 textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
118 textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
119 textLayoutModule->skipCO->insertItem(qt_("Length"));
120 // remove the %-items from the unit choice
121 textLayoutModule->skipLengthCO->noPercents();
122 textLayoutModule->lspacingCO->insertItem(
123 qt_("Single"), Spacing::Single);
124 textLayoutModule->lspacingCO->insertItem(
125 qt_("OneHalf"), Spacing::Onehalf);
126 textLayoutModule->lspacingCO->insertItem(
127 qt_("Double"), Spacing::Double);
128 textLayoutModule->lspacingCO->insertItem(
129 qt_("Custom"), Spacing::Other);
131 // initialize the length validator
132 addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
137 fontModule = new UiWidget<Ui::FontUi>;
139 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
140 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)), this, SLOT(romanChanged(int)));
141 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
142 connect(fontModule->fontsSansCO, SIGNAL(activated(int)), this, SLOT(sansChanged(int)));
143 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
144 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)), this, SLOT(ttChanged(int)));
145 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
146 connect(fontModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
147 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
148 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
149 connect(fontModule->fontScCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
150 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
152 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
153 QString font = toqstr(tex_fonts_roman_gui[n]);
154 if (!form_->controller().isFontAvailable(tex_fonts_roman[n]))
155 font += qt_(" (not installed)");
156 fontModule->fontsRomanCO->insertItem(font);
158 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
159 QString font = toqstr(tex_fonts_sans_gui[n]);
160 if (!form_->controller().isFontAvailable(tex_fonts_sans[n]))
161 font += qt_(" (not installed)");
162 fontModule->fontsSansCO->insertItem(font);
164 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
165 QString font = toqstr(tex_fonts_monospaced_gui[n]);
166 if (!form_->controller().isFontAvailable(tex_fonts_monospaced[n]))
167 font += qt_(" (not installed)");
168 fontModule->fontsTypewriterCO->insertItem(font);
171 fontModule->fontsizeCO->insertItem(qt_("default"));
172 fontModule->fontsizeCO->insertItem(qt_("10"));
173 fontModule->fontsizeCO->insertItem(qt_("11"));
174 fontModule->fontsizeCO->insertItem(qt_("12"));
176 for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
177 fontModule->fontsDefaultCO->insertItem(
178 qt_(ControlDocument::fontfamilies_gui[n]));
183 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
185 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
186 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
187 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
188 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
189 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
190 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
191 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
192 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
193 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
194 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
195 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
196 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
197 pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
198 pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
199 pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
200 pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
201 pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
202 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
203 pageLayoutModule->paperheightL);
204 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
205 pageLayoutModule->paperwidthL);
208 QComboBox * cb = pageLayoutModule->papersizeCO;
209 cb->insertItem(qt_("Default"));
210 cb->insertItem(qt_("Custom"));
211 cb->insertItem(qt_("US letter"));
212 cb->insertItem(qt_("US legal"));
213 cb->insertItem(qt_("US executive"));
214 cb->insertItem(qt_("A3"));
215 cb->insertItem(qt_("A4"));
216 cb->insertItem(qt_("A5"));
217 cb->insertItem(qt_("B3"));
218 cb->insertItem(qt_("B4"));
219 cb->insertItem(qt_("B5"));
220 // remove the %-items from the unit choice
221 pageLayoutModule->paperwidthUnitCO->noPercents();
222 pageLayoutModule->paperheightUnitCO->noPercents();
223 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
224 pageLayoutModule->paperheightLE));
225 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
226 pageLayoutModule->paperwidthLE));
231 marginsModule = new UiWidget<Ui::MarginsUi>;
233 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
234 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
235 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
236 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
237 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
238 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
239 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
240 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
241 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
242 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
243 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
244 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
245 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
246 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
247 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
248 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
249 marginsModule->topLE->setValidator(unsignedLengthValidator(
250 marginsModule->topLE));
251 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
252 marginsModule->bottomLE));
253 marginsModule->innerLE->setValidator(unsignedLengthValidator(
254 marginsModule->innerLE));
255 marginsModule->outerLE->setValidator(unsignedLengthValidator(
256 marginsModule->outerLE));
257 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
258 marginsModule->headsepLE));
259 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
260 marginsModule->headheightLE));
261 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
262 marginsModule->footskipLE));
264 addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
265 marginsModule->topL);
266 addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
267 marginsModule->bottomL);
268 addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
269 marginsModule->innerL);
270 addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
271 marginsModule->outerL);
272 addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
273 marginsModule->headsepL);
274 addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
275 marginsModule->headheightL);
276 addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
277 marginsModule->footskipL);
283 langModule = new UiWidget<Ui::LanguageUi>;
284 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingL, SLOT( setDisabled(bool) ) );
285 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingCO, SLOT( setDisabled(bool) ) );
287 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
288 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
289 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
290 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
292 vector<LanguagePair> const langs = getLanguageData(false);
293 vector<LanguagePair>::const_iterator lit = langs.begin();
294 vector<LanguagePair>::const_iterator lend = langs.end();
295 for (; lit != lend; ++lit) {
296 langModule->languageCO->insertItem(
301 while (encodings[k]) {
302 langModule->encodingCO->insertItem(qt_(encodings[k++]));
305 langModule->quoteStyleCO->insertItem(qt_("``text''"));
306 langModule->quoteStyleCO->insertItem(qt_("''text''"));
307 langModule->quoteStyleCO->insertItem(qt_(",,text``"));
308 langModule->quoteStyleCO->insertItem(qt_(",,text''"));
309 langModule->quoteStyleCO->insertItem(qt_("<<text>>"));
310 langModule->quoteStyleCO->insertItem(qt_(">>text<<"));
314 numberingModule = new UiWidget<Ui::NumberingUi>;
316 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
317 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
318 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
319 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
320 numberingModule->tocTW->setColumnCount(3);
321 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
322 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
323 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
326 biblioModule = new UiWidget<Ui::BiblioUi>;
327 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citationStyleL, SLOT( setEnabled(bool) ) );
328 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citeStyleCO, SLOT( setEnabled(bool) ) );
330 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
331 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
332 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
333 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
334 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
336 biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
337 biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
338 biblioModule->citeStyleCO->setCurrentItem(0);
342 mathsModule = new UiWidget<Ui::MathsUi>;
343 connect( mathsModule->amsautoCB, SIGNAL( toggled(bool) ), mathsModule->amsCB, SLOT( setDisabled(bool) ) );
345 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
346 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
349 latexModule = new UiWidget<Ui::LaTeXUi>;
351 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
352 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
353 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
354 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
356 for (int n = 0; tex_graphics[n][0]; ++n) {
357 QString enc = tex_graphics[n];
358 latexModule->psdriverCO->insertItem(enc);
361 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
362 cit != textclasslist.end(); ++cit) {
363 if (cit->isTeXClassAvailable()) {
364 latexModule->classCO->insertItem(toqstr(cit->description()));
367 bformat(_("Unavailable: %1$s"), cit->description());
368 latexModule->classCO->insertItem(toqstr(item));
374 branchesModule = new QBranches;
375 connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
378 preambleModule = new UiWidget<Ui::PreambleUi>;
380 connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
383 bulletsModule = new BulletsModule;
384 // FIXME: disable until we fix browsebox in BulletsModule.[Ch]
385 bulletsModule->setEnabled(false);
387 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
390 floatModule = new FloatPlacement;
392 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
394 docPS->addPanel(latexModule, _("Document Class"));
395 docPS->addPanel(fontModule, _("Fonts"));
396 docPS->addPanel(textLayoutModule, _("Text Layout"));
397 docPS->addPanel(pageLayoutModule, _("Page Layout"));
398 docPS->addPanel(marginsModule, _("Page Margins"));
399 docPS->addPanel(langModule, _("Language"));
400 docPS->addPanel(numberingModule, _("Numbering & TOC"));
401 docPS->addPanel(biblioModule, _("Bibliography"));
402 docPS->addPanel(mathsModule, _("Math Options"));
403 docPS->addPanel(floatModule, _("Float Placement"));
404 docPS->addPanel(bulletsModule, _("Bullets"));
405 docPS->addPanel(branchesModule, _("Branches"));
406 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
407 docPS->setCurrentPanel(_("Document Class"));
411 QDocumentDialog::~QDocumentDialog()
416 void QDocumentDialog::showPreamble()
418 docPS->setCurrentPanel(_("LaTeX Preamble"));
422 void QDocumentDialog::saveDefaultClicked()
424 form_->saveDocDefault();
428 void QDocumentDialog::useDefaultsClicked()
430 form_->useClassDefaults();
434 void QDocumentDialog::change_adaptor()
440 void QDocumentDialog::closeEvent(QCloseEvent * e)
447 void QDocumentDialog::setLSpacing(int item)
449 textLayoutModule->lspacingLE->setEnabled(item == 3);
453 void QDocumentDialog::setSkip(int item)
455 bool const enable = (item == 3);
456 textLayoutModule->skipLE->setEnabled(enable);
457 textLayoutModule->skipLengthCO->setEnabled(enable);
461 void QDocumentDialog::enableSkip(bool skip)
463 textLayoutModule->skipCO->setEnabled(skip);
464 textLayoutModule->skipLE->setEnabled(skip);
465 textLayoutModule->skipLengthCO->setEnabled(skip);
467 setSkip(textLayoutModule->skipCO->currentItem());
470 void QDocumentDialog::portraitChanged()
472 setMargins(pageLayoutModule->papersizeCO->currentItem());
475 void QDocumentDialog::setMargins(bool custom)
477 marginsModule->marginCB->setChecked(custom);
478 setCustomMargins(custom);
482 void QDocumentDialog::setCustomPapersize(int papersize)
484 bool const custom = (papersize == 1);
486 pageLayoutModule->paperwidthL->setEnabled(custom);
487 pageLayoutModule->paperwidthLE->setEnabled(custom);
488 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
489 pageLayoutModule->paperheightL->setEnabled(custom);
490 pageLayoutModule->paperheightLE->setEnabled(custom);
491 pageLayoutModule->paperheightLE->setFocus();
492 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
496 void QDocumentDialog::setCustomMargins(bool custom)
498 marginsModule->topL->setEnabled(!custom);
499 marginsModule->topLE->setEnabled(!custom);
500 marginsModule->topUnit->setEnabled(!custom);
502 marginsModule->bottomL->setEnabled(!custom);
503 marginsModule->bottomLE->setEnabled(!custom);
504 marginsModule->bottomUnit->setEnabled(!custom);
506 marginsModule->innerL->setEnabled(!custom);
507 marginsModule->innerLE->setEnabled(!custom);
508 marginsModule->innerUnit->setEnabled(!custom);
510 marginsModule->outerL->setEnabled(!custom);
511 marginsModule->outerLE->setEnabled(!custom);
512 marginsModule->outerUnit->setEnabled(!custom);
514 marginsModule->headheightL->setEnabled(!custom);
515 marginsModule->headheightLE->setEnabled(!custom);
516 marginsModule->headheightUnit->setEnabled(!custom);
518 marginsModule->headsepL->setEnabled(!custom);
519 marginsModule->headsepLE->setEnabled(!custom);
520 marginsModule->headsepUnit->setEnabled(!custom);
522 marginsModule->footskipL->setEnabled(!custom);
523 marginsModule->footskipLE->setEnabled(!custom);
524 marginsModule->footskipUnit->setEnabled(!custom);
528 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
530 fontModule->fontsizeCO->clear();
531 fontModule->fontsizeCO->insertItem(qt_("default"));
533 for (int n = 0; !token(items,'|',n).empty(); ++n)
534 fontModule->fontsizeCO->
535 insertItem(toqstr(token(items,'|',n)));
537 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
538 if (fromqstr(fontModule->fontsizeCO->text(n)) == sel) {
539 fontModule->fontsizeCO->setCurrentItem(n);
546 void QDocumentDialog::romanChanged(int item)
548 string const font = tex_fonts_roman[item];
550 fontModule->fontScCB->setEnabled(
551 form_->controller().providesSC(font));
552 fontModule->fontOsfCB->setEnabled(
553 form_->controller().providesOSF(font));
557 void QDocumentDialog::sansChanged(int item)
559 string const font = tex_fonts_sans[item];
561 fontModule->scaleSansSB->setEnabled(
562 form_->controller().providesScale(font));
566 void QDocumentDialog::ttChanged(int item)
568 string const font = tex_fonts_monospaced[item];
570 fontModule->scaleTypewriterSB->setEnabled(
571 form_->controller().providesScale(font));
575 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
577 pageLayoutModule->pagestyleCO->clear();
578 pageLayoutModule->pagestyleCO->insertItem("default");
580 for (int n=0; !token(items,'|',n).empty(); ++n)
581 pageLayoutModule->pagestyleCO->
582 insertItem(toqstr(token(items,'|',n)));
584 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
585 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
586 pageLayoutModule->pagestyleCO->setCurrentItem(n);
593 void QDocumentDialog::classChanged()
595 ControlDocument & cntrl = form_->controller();
596 BufferParams & params = cntrl.params();
598 lyx::textclass_type const tc = latexModule->classCO->currentItem();
600 if (form_->controller().loadTextclass(tc)) {
601 params.textclass = tc;
602 if (lyxrc.auto_reset_options)
603 params.useClassDefaults();
604 form_->update_contents();
606 latexModule->classCO->setCurrentItem(params.textclass);
611 void QDocumentDialog::updateNumbering()
613 LyXTextClass const & tclass =
614 form_->controller().params().getLyXTextClass();
616 numberingModule->tocTW->setUpdatesEnabled(false);
617 numberingModule->tocTW->clear();
619 int const depth = numberingModule->depthSL->value();
620 int const toc = numberingModule->tocSL->value();
621 QString const no = qt_("No");
622 QString const yes = qt_("Yes");
623 LyXTextClass::const_iterator end = tclass.end();
624 LyXTextClass::const_iterator cit = tclass.begin();
625 QTreeWidgetItem * item = 0;
626 for ( ; cit != end ; ++cit) {
627 int const toclevel = (*cit)->toclevel;
628 if (toclevel != LyXLayout::NOT_IN_TOC) {
629 item = new QTreeWidgetItem(numberingModule->tocTW);
630 item->setText(0, qt_((*cit)->name()));
631 item->setText(1, (toclevel <= depth) ? yes : no);
632 item->setText(2, (toclevel <= toc) ? yes : no);
636 numberingModule->tocTW->setUpdatesEnabled(true);
637 numberingModule->tocTW->update();
640 void QDocumentDialog::apply(BufferParams & params)
644 fromqstr(preambleModule->preambleTE->document()->toPlainText());
647 params.cite_engine = biblio::ENGINE_BASIC;
649 if (biblioModule->citeNatbibRB->isChecked()) {
650 bool const use_numerical_citations =
651 biblioModule->citeStyleCO->currentItem();
652 if (use_numerical_citations)
653 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
655 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
657 } else if (biblioModule->citeJurabibRB->isChecked())
658 params.cite_engine = biblio::ENGINE_JURABIB;
660 params.use_bibtopic =
661 biblioModule->bibtopicCB->isChecked();
664 if (langModule->defaultencodingCB->isChecked()) {
665 params.inputenc = "auto";
667 int i = langModule->encodingCO->currentItem();
669 params.inputenc = "default";
671 params.inputenc = encodings[i];
675 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
676 switch (langModule->quoteStyleCO->currentItem()) {
678 lga = InsetQuotes::EnglishQ;
681 lga = InsetQuotes::SwedishQ;
684 lga = InsetQuotes::GermanQ;
687 lga = InsetQuotes::PolishQ;
690 lga = InsetQuotes::FrenchQ;
693 lga = InsetQuotes::DanishQ;
696 params.quotes_language = lga;
698 int const pos = langModule->languageCO->currentItem();
699 params.language = languages.getLanguage(lang_[pos]);
702 if (params.getLyXTextClass().hasTocLevels()) {
703 params.tocdepth = numberingModule->tocSL->value();
704 params.secnumdepth = numberingModule->depthSL->value();
708 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
709 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
710 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
711 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
714 params.graphicsDriver =
715 fromqstr(latexModule->psdriverCO->currentText());
717 if (mathsModule->amsautoCB->isChecked()) {
718 params.use_amsmath = BufferParams::AMS_AUTO;
720 if (mathsModule->amsCB->isChecked())
721 params.use_amsmath = BufferParams::AMS_ON;
723 params.use_amsmath = BufferParams::AMS_OFF;
728 latexModule->classCO->currentItem();
731 fromqstr(pageLayoutModule->pagestyleCO->currentText());
733 switch (textLayoutModule->lspacingCO->currentItem()) {
735 params.spacing().set(Spacing::Single);
738 params.spacing().set(Spacing::Onehalf);
741 params.spacing().set(Spacing::Double);
744 params.spacing().set(Spacing::Other,
745 fromqstr(textLayoutModule->lspacingLE->text()));
749 if (textLayoutModule->twoColumnCB->isChecked())
754 if (textLayoutModule->indentRB->isChecked())
755 params.paragraph_separation = BufferParams::PARSEP_INDENT;
757 params.paragraph_separation = BufferParams::PARSEP_SKIP;
759 switch (textLayoutModule->skipCO->currentItem()) {
761 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
764 params.setDefSkip(VSpace(VSpace::MEDSKIP));
767 params.setDefSkip(VSpace(VSpace::BIGSKIP));
772 widgetsToLength(textLayoutModule->skipLE,
773 textLayoutModule->skipLengthCO)
775 params.setDefSkip(vs);
779 // DocumentDefskipCB assures that this never happens
780 // so Assert then !!! - jbl
781 params.setDefSkip(VSpace(VSpace::MEDSKIP));
786 fromqstr(latexModule->optionsLE->text());
788 params.float_placement = floatModule->get();
792 tex_fonts_roman[fontModule->fontsRomanCO->currentItem()];
795 tex_fonts_sans[fontModule->fontsSansCO->currentItem()];
797 params.fontsTypewriter =
798 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentItem()];
800 params.fontsSansScale = fontModule->scaleSansSB->value();
802 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
804 params.fontsSC = fontModule->fontScCB->isChecked();
806 params.fontsOSF = fontModule->fontOsfCB->isChecked();
808 params.fontsDefaultFamily = ControlDocument::fontfamilies[
809 fontModule->fontsDefaultCO->currentItem()];
811 if (fontModule->fontsizeCO->currentItem() == 0)
812 params.fontsize = "default";
815 fromqstr(fontModule->fontsizeCO->currentText());
818 params.papersize = PAPER_SIZE(
819 pageLayoutModule->papersizeCO->currentItem());
821 // custom, A3, B3 and B4 paper sizes need geometry
822 int psize = pageLayoutModule->papersizeCO->currentItem();
823 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
825 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
826 pageLayoutModule->paperwidthUnitCO);
828 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
829 pageLayoutModule->paperheightUnitCO);
831 if (pageLayoutModule->facingPagesCB->isChecked())
832 params.sides = LyXTextClass::TwoSides;
834 params.sides = LyXTextClass::OneSide;
836 if (pageLayoutModule->landscapeRB->isChecked())
837 params.orientation = ORIENTATION_LANDSCAPE;
839 params.orientation = ORIENTATION_PORTRAIT;
842 params.use_geometry =
843 (!marginsModule->marginCB->isChecked()
846 Ui::MarginsUi const * m(marginsModule);
848 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
850 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
852 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
854 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
856 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
858 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
860 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
862 branchesModule->apply(params);
867 /** Return the position of val in the vector if found.
868 If not found, return 0.
871 typename std::vector<A>::size_type
872 findPos(std::vector<A> const & vec, A const & val)
874 typename std::vector<A>::const_iterator it =
875 std::find(vec.begin(), vec.end(), val);
878 return distance(vec.begin(), it);
884 void QDocumentDialog::update(BufferParams const & params)
886 // set the default unit
887 // FIXME: move to controller
888 LyXLength::UNIT defaultUnit = LyXLength::CM;
889 switch (lyxrc.default_papersize) {
890 case PAPER_DEFAULT: break;
894 case PAPER_USEXECUTIVE:
895 defaultUnit = LyXLength::IN;
904 defaultUnit = LyXLength::CM;
911 QString preamble = toqstr(params.preamble);
912 preambleModule->preambleTE->document()->setPlainText(preamble);
915 biblioModule->citeDefaultRB->setChecked(
916 params.cite_engine == biblio::ENGINE_BASIC);
918 biblioModule->citeNatbibRB->setChecked(
919 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
920 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
922 biblioModule->citeStyleCO->setCurrentItem(
923 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
925 biblioModule->citeJurabibRB->setChecked(
926 params.cite_engine == biblio::ENGINE_JURABIB);
928 biblioModule->bibtopicCB->setChecked(
929 params.use_bibtopic);
932 int const pos = int(findPos(lang_,
933 params.language->lang()));
934 langModule->languageCO->setCurrentItem(pos);
936 langModule->quoteStyleCO->setCurrentItem(
937 params.quotes_language);
939 langModule->defaultencodingCB->setChecked(true);
941 if (params.inputenc != "auto") {
942 langModule->defaultencodingCB->setChecked(false);
943 if (params.inputenc == "default") {
944 langModule->encodingCO->setCurrentItem(0);
947 while (encodings[i]) {
948 if (encodings[i] == params.inputenc)
949 langModule->encodingCO->setCurrentItem(i);
956 int const min_toclevel = form_->controller().textClass().min_toclevel();
957 int const max_toclevel = form_->controller().textClass().max_toclevel();
958 if (form_->controller().textClass().hasTocLevels()) {
959 numberingModule->setEnabled(true);
960 numberingModule->depthSL->setMinValue(min_toclevel - 1);
961 numberingModule->depthSL->setMaxValue(max_toclevel);
962 numberingModule->depthSL->setValue(params.secnumdepth);
963 numberingModule->tocSL->setMinValue(min_toclevel - 1);
964 numberingModule->tocSL->setMaxValue(max_toclevel);
965 numberingModule->tocSL->setValue(params.tocdepth);
968 numberingModule->setEnabled(false);
969 numberingModule->tocTW->clear();
973 bulletsModule->setBullet(0,params.user_defined_bullet(0));
974 bulletsModule->setBullet(1,params.user_defined_bullet(1));
975 bulletsModule->setBullet(2,params.user_defined_bullet(2));
976 bulletsModule->setBullet(3,params.user_defined_bullet(3));
979 QString text = toqstr(params.graphicsDriver);
980 int nitem = latexModule->psdriverCO->count();
981 for (int n = 0; n < nitem ; ++n) {
982 QString enc = tex_graphics[n];
984 latexModule->psdriverCO->setCurrentItem(n);
989 mathsModule->amsCB->setChecked(
990 params.use_amsmath == BufferParams::AMS_ON);
991 mathsModule->amsautoCB->setChecked(
992 params.use_amsmath == BufferParams::AMS_AUTO);
994 switch (params.spacing().getSpace()) {
995 case Spacing::Other: nitem = 3; break;
996 case Spacing::Double: nitem = 2; break;
997 case Spacing::Onehalf: nitem = 1; break;
998 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1002 latexModule->classCO->setCurrentItem(params.textclass);
1004 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1007 textLayoutModule->lspacingCO->setCurrentItem(nitem);
1008 if (params.spacing().getSpace() == Spacing::Other) {
1009 textLayoutModule->lspacingLE->setText(
1010 toqstr(params.spacing().getValueAsString()));
1014 if (params.paragraph_separation
1015 == BufferParams::PARSEP_INDENT) {
1016 textLayoutModule->indentRB->setChecked(true);
1018 textLayoutModule->skipRB->setChecked(true);
1022 switch (params.getDefSkip().kind()) {
1023 case VSpace::SMALLSKIP:
1026 case VSpace::MEDSKIP:
1029 case VSpace::BIGSKIP:
1032 case VSpace::LENGTH:
1035 string const length = params.getDefSkip().asLyXCommand();
1036 lengthToWidgets(textLayoutModule->skipLE,
1037 textLayoutModule->skipLengthCO,
1038 length, defaultUnit);
1045 textLayoutModule->skipCO->setCurrentItem(skip);
1048 textLayoutModule->twoColumnCB->setChecked(
1049 params.columns == 2);
1051 if (!params.options.empty()) {
1052 latexModule->optionsLE->setText(
1053 toqstr(params.options));
1055 latexModule->optionsLE->setText("");
1058 floatModule->set(params.float_placement);
1061 updateFontsize(form_->controller().textClass().opt_fontsize(),
1064 int n = findToken(tex_fonts_roman, params.fontsRoman);
1066 fontModule->fontsRomanCO->setCurrentItem(n);
1068 n = findToken(tex_fonts_sans, params.fontsSans);
1070 fontModule->fontsSansCO->setCurrentItem(n);
1072 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1074 fontModule->fontsTypewriterCO->setCurrentItem(n);
1076 fontModule->fontScCB->setChecked(params.fontsSC);
1077 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1078 fontModule->fontScCB->setEnabled(
1079 form_->controller().providesSC(params.fontsRoman));
1080 fontModule->fontOsfCB->setEnabled(
1081 form_->controller().providesOSF(params.fontsRoman));
1082 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1083 fontModule->scaleTypewriterSB->setValue(
1084 params.fontsTypewriterScale);
1085 fontModule->scaleSansSB->setEnabled(
1086 form_->controller().providesScale(params.fontsSans));
1087 fontModule->scaleTypewriterSB->setEnabled(
1088 form_->controller().providesScale(params.fontsTypewriter));
1089 n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
1091 fontModule->fontsDefaultCO->setCurrentItem(n);
1094 int const psize = params.papersize;
1095 pageLayoutModule->papersizeCO->setCurrentItem(psize);
1096 setCustomPapersize(psize);
1098 bool const landscape =
1099 params.orientation == ORIENTATION_LANDSCAPE;
1100 pageLayoutModule->landscapeRB->setChecked(landscape);
1101 pageLayoutModule->portraitRB->setChecked(!landscape);
1103 pageLayoutModule->facingPagesCB->setChecked(
1104 params.sides == LyXTextClass::TwoSides);
1107 lengthToWidgets(pageLayoutModule->paperwidthLE,
1108 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1110 lengthToWidgets(pageLayoutModule->paperheightLE,
1111 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1114 Ui::MarginsUi * m = marginsModule;
1116 setMargins(!params.use_geometry);
1118 lengthToWidgets(m->topLE, m->topUnit,
1119 params.topmargin, defaultUnit);
1121 lengthToWidgets(m->bottomLE, m->bottomUnit,
1122 params.bottommargin, defaultUnit);
1124 lengthToWidgets(m->innerLE, m->innerUnit,
1125 params.leftmargin, defaultUnit);
1127 lengthToWidgets(m->outerLE, m->outerUnit,
1128 params.rightmargin, defaultUnit);
1130 lengthToWidgets(m->headheightLE, m->headheightUnit,
1131 params.headheight, defaultUnit);
1133 lengthToWidgets(m->headsepLE, m->headsepUnit,
1134 params.headsep, defaultUnit);
1136 lengthToWidgets(m->footskipLE, m->footskipUnit,
1137 params.footskip, defaultUnit);
1139 branchesModule->update(params);
1145 } // namespace frontend
1148 #include "QDocumentDialog_moc.cpp"