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()));
379 preambleModule = new UiWidget<Ui::PreambleUi>;
380 connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
384 bulletsModule = new BulletsModule;
385 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
389 floatModule = new FloatPlacement;
390 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
392 docPS->addPanel(latexModule, _("Document Class"));
393 docPS->addPanel(fontModule, _("Fonts"));
394 docPS->addPanel(textLayoutModule, _("Text Layout"));
395 docPS->addPanel(pageLayoutModule, _("Page Layout"));
396 docPS->addPanel(marginsModule, _("Page Margins"));
397 docPS->addPanel(langModule, _("Language"));
398 docPS->addPanel(numberingModule, _("Numbering & TOC"));
399 docPS->addPanel(biblioModule, _("Bibliography"));
400 docPS->addPanel(mathsModule, _("Math Options"));
401 docPS->addPanel(floatModule, _("Float Placement"));
402 docPS->addPanel(bulletsModule, _("Bullets"));
403 docPS->addPanel(branchesModule, _("Branches"));
404 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
405 docPS->setCurrentPanel(_("Document Class"));
409 QDocumentDialog::~QDocumentDialog()
414 void QDocumentDialog::showPreamble()
416 docPS->setCurrentPanel(_("LaTeX Preamble"));
420 void QDocumentDialog::saveDefaultClicked()
422 form_->saveDocDefault();
426 void QDocumentDialog::useDefaultsClicked()
428 form_->useClassDefaults();
432 void QDocumentDialog::change_adaptor()
438 void QDocumentDialog::closeEvent(QCloseEvent * e)
445 void QDocumentDialog::setLSpacing(int item)
447 textLayoutModule->lspacingLE->setEnabled(item == 3);
451 void QDocumentDialog::setSkip(int item)
453 bool const enable = (item == 3);
454 textLayoutModule->skipLE->setEnabled(enable);
455 textLayoutModule->skipLengthCO->setEnabled(enable);
459 void QDocumentDialog::enableSkip(bool skip)
461 textLayoutModule->skipCO->setEnabled(skip);
462 textLayoutModule->skipLE->setEnabled(skip);
463 textLayoutModule->skipLengthCO->setEnabled(skip);
465 setSkip(textLayoutModule->skipCO->currentItem());
468 void QDocumentDialog::portraitChanged()
470 setMargins(pageLayoutModule->papersizeCO->currentItem());
473 void QDocumentDialog::setMargins(bool custom)
475 marginsModule->marginCB->setChecked(custom);
476 setCustomMargins(custom);
480 void QDocumentDialog::setCustomPapersize(int papersize)
482 bool const custom = (papersize == 1);
484 pageLayoutModule->paperwidthL->setEnabled(custom);
485 pageLayoutModule->paperwidthLE->setEnabled(custom);
486 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
487 pageLayoutModule->paperheightL->setEnabled(custom);
488 pageLayoutModule->paperheightLE->setEnabled(custom);
489 pageLayoutModule->paperheightLE->setFocus();
490 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
494 void QDocumentDialog::setCustomMargins(bool custom)
496 marginsModule->topL->setEnabled(!custom);
497 marginsModule->topLE->setEnabled(!custom);
498 marginsModule->topUnit->setEnabled(!custom);
500 marginsModule->bottomL->setEnabled(!custom);
501 marginsModule->bottomLE->setEnabled(!custom);
502 marginsModule->bottomUnit->setEnabled(!custom);
504 marginsModule->innerL->setEnabled(!custom);
505 marginsModule->innerLE->setEnabled(!custom);
506 marginsModule->innerUnit->setEnabled(!custom);
508 marginsModule->outerL->setEnabled(!custom);
509 marginsModule->outerLE->setEnabled(!custom);
510 marginsModule->outerUnit->setEnabled(!custom);
512 marginsModule->headheightL->setEnabled(!custom);
513 marginsModule->headheightLE->setEnabled(!custom);
514 marginsModule->headheightUnit->setEnabled(!custom);
516 marginsModule->headsepL->setEnabled(!custom);
517 marginsModule->headsepLE->setEnabled(!custom);
518 marginsModule->headsepUnit->setEnabled(!custom);
520 marginsModule->footskipL->setEnabled(!custom);
521 marginsModule->footskipLE->setEnabled(!custom);
522 marginsModule->footskipUnit->setEnabled(!custom);
526 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
528 fontModule->fontsizeCO->clear();
529 fontModule->fontsizeCO->insertItem(qt_("default"));
531 for (int n = 0; !token(items,'|',n).empty(); ++n)
532 fontModule->fontsizeCO->
533 insertItem(toqstr(token(items,'|',n)));
535 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
536 if (fromqstr(fontModule->fontsizeCO->text(n)) == sel) {
537 fontModule->fontsizeCO->setCurrentItem(n);
544 void QDocumentDialog::romanChanged(int item)
546 string const font = tex_fonts_roman[item];
548 fontModule->fontScCB->setEnabled(
549 form_->controller().providesSC(font));
550 fontModule->fontOsfCB->setEnabled(
551 form_->controller().providesOSF(font));
555 void QDocumentDialog::sansChanged(int item)
557 string const font = tex_fonts_sans[item];
559 fontModule->scaleSansSB->setEnabled(
560 form_->controller().providesScale(font));
564 void QDocumentDialog::ttChanged(int item)
566 string const font = tex_fonts_monospaced[item];
568 fontModule->scaleTypewriterSB->setEnabled(
569 form_->controller().providesScale(font));
573 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
575 pageLayoutModule->pagestyleCO->clear();
576 pageLayoutModule->pagestyleCO->insertItem("default");
578 for (int n=0; !token(items,'|',n).empty(); ++n)
579 pageLayoutModule->pagestyleCO->
580 insertItem(toqstr(token(items,'|',n)));
582 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
583 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
584 pageLayoutModule->pagestyleCO->setCurrentItem(n);
591 void QDocumentDialog::classChanged()
593 ControlDocument & cntrl = form_->controller();
594 BufferParams & params = cntrl.params();
596 lyx::textclass_type const tc = latexModule->classCO->currentItem();
598 if (form_->controller().loadTextclass(tc)) {
599 params.textclass = tc;
600 if (lyxrc.auto_reset_options)
601 params.useClassDefaults();
602 form_->update_contents();
604 latexModule->classCO->setCurrentItem(params.textclass);
609 void QDocumentDialog::updateNumbering()
611 LyXTextClass const & tclass =
612 form_->controller().params().getLyXTextClass();
614 numberingModule->tocTW->setUpdatesEnabled(false);
615 numberingModule->tocTW->clear();
617 int const depth = numberingModule->depthSL->value();
618 int const toc = numberingModule->tocSL->value();
619 QString const no = qt_("No");
620 QString const yes = qt_("Yes");
621 LyXTextClass::const_iterator end = tclass.end();
622 LyXTextClass::const_iterator cit = tclass.begin();
623 QTreeWidgetItem * item = 0;
624 for ( ; cit != end ; ++cit) {
625 int const toclevel = (*cit)->toclevel;
626 if (toclevel != LyXLayout::NOT_IN_TOC) {
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->currentItem();
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->currentItem();
667 params.inputenc = "default";
669 params.inputenc = encodings[i];
673 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
674 switch (langModule->quoteStyleCO->currentItem()) {
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->currentItem();
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->currentItem();
729 fromqstr(pageLayoutModule->pagestyleCO->currentText());
731 switch (textLayoutModule->lspacingCO->currentItem()) {
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->currentItem()) {
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->currentItem()];
793 tex_fonts_sans[fontModule->fontsSansCO->currentItem()];
795 params.fontsTypewriter =
796 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentItem()];
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->currentItem()];
809 if (fontModule->fontsizeCO->currentItem() == 0)
810 params.fontsize = "default";
813 fromqstr(fontModule->fontsizeCO->currentText());
816 params.papersize = PAPER_SIZE(
817 pageLayoutModule->papersizeCO->currentItem());
819 // custom, A3, B3 and B4 paper sizes need geometry
820 int psize = pageLayoutModule->papersizeCO->currentItem();
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->setCurrentItem(
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->setCurrentItem(pos);
934 langModule->quoteStyleCO->setCurrentItem(
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->setCurrentItem(0);
945 while (encodings[i]) {
946 if (encodings[i] == params.inputenc)
947 langModule->encodingCO->setCurrentItem(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->setMinValue(min_toclevel - 1);
959 numberingModule->depthSL->setMaxValue(max_toclevel);
960 numberingModule->depthSL->setValue(params.secnumdepth);
961 numberingModule->tocSL->setMinValue(min_toclevel - 1);
962 numberingModule->tocSL->setMaxValue(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->setCurrentItem(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->setCurrentItem(params.textclass);
1003 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
1006 textLayoutModule->lspacingCO->setCurrentItem(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->setCurrentItem(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->setCurrentItem(n);
1067 n = findToken(tex_fonts_sans, params.fontsSans);
1069 fontModule->fontsSansCO->setCurrentItem(n);
1071 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1073 fontModule->fontsTypewriterCO->setCurrentItem(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->setCurrentItem(n);
1093 int const psize = params.papersize;
1094 pageLayoutModule->papersizeCO->setCurrentItem(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"