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::getVectorFromString;
61 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
62 "latin3", "latin4", "latin5", "latin9",
63 "koi8-r", "koi8-u", "cp866", "cp1251",
64 "iso88595", "pt154", 0
69 QDocumentDialog::QDocumentDialog(QDocument * form)
71 lang_(getSecond(getLanguageData(false)))
75 connect(okPB, SIGNAL(clicked()),
76 form, SLOT(slotOK()));
77 connect(applyPB, SIGNAL(clicked()),
78 form, SLOT(slotApply()));
79 connect(closePB, SIGNAL(clicked()),
80 form, SLOT(slotClose()));
81 connect(restorePB, SIGNAL(clicked()),
82 form, SLOT(slotRestore()));
85 connect(savePB, SIGNAL( clicked() ),
86 this, SLOT( saveDefaultClicked() ) );
87 connect(defaultPB, SIGNAL( clicked() ),
88 this, SLOT( useDefaultsClicked() ) );
90 // Manage the restore, ok, apply, restore and cancel/close buttons
91 form_->bcview().setOK(okPB);
92 form_->bcview().setApply(applyPB);
93 form_->bcview().setCancel(closePB);
94 form_->bcview().setRestore(restorePB);
97 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
99 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
100 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
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 for (int n = 0; tex_fonts[n][0]; ++n) {
118 QString font = tex_fonts[n];
119 textLayoutModule->fontsCO->insertItem(font);
122 textLayoutModule->fontsizeCO->insertItem(qt_("default"));
123 textLayoutModule->fontsizeCO->insertItem(qt_("10"));
124 textLayoutModule->fontsizeCO->insertItem(qt_("11"));
125 textLayoutModule->fontsizeCO->insertItem(qt_("12"));
127 textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
128 textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
129 textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
130 textLayoutModule->skipCO->insertItem(qt_("Length"));
131 // remove the %-items from the unit choice
132 textLayoutModule->skipLengthCO->noPercents();
133 textLayoutModule->lspacingCO->insertItem(
134 qt_("Single"), Spacing::Single);
135 textLayoutModule->lspacingCO->insertItem(
136 qt_("OneHalf"), Spacing::Onehalf);
137 textLayoutModule->lspacingCO->insertItem(
138 qt_("Double"), Spacing::Double);
139 textLayoutModule->lspacingCO->insertItem(
140 qt_("Custom"), Spacing::Other);
142 // initialize the length validator
143 addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
148 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
150 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
151 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
152 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
153 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
154 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
155 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
156 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
157 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
158 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
159 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
160 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
161 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
162 pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
163 pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
164 pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
165 pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
166 pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
167 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
168 pageLayoutModule->paperheightL);
169 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
170 pageLayoutModule->paperwidthL);
173 QComboBox * cb = pageLayoutModule->papersizeCO;
174 cb->insertItem(qt_("Default"));
175 cb->insertItem(qt_("Custom"));
176 cb->insertItem(qt_("US letter"));
177 cb->insertItem(qt_("US legal"));
178 cb->insertItem(qt_("US executive"));
179 cb->insertItem(qt_("A3"));
180 cb->insertItem(qt_("A4"));
181 cb->insertItem(qt_("A5"));
182 cb->insertItem(qt_("B3"));
183 cb->insertItem(qt_("B4"));
184 cb->insertItem(qt_("B5"));
185 // remove the %-items from the unit choice
186 pageLayoutModule->paperwidthUnitCO->noPercents();
187 pageLayoutModule->paperheightUnitCO->noPercents();
188 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
189 pageLayoutModule->paperheightLE));
190 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
191 pageLayoutModule->paperwidthLE));
196 marginsModule = new UiWidget<Ui::MarginsUi>;
198 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
199 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
200 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
201 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
202 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
203 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
204 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
205 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
206 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
207 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
208 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
209 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
210 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
211 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
212 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
213 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
214 marginsModule->topLE->setValidator(unsignedLengthValidator(
215 marginsModule->topLE));
216 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
217 marginsModule->bottomLE));
218 marginsModule->innerLE->setValidator(unsignedLengthValidator(
219 marginsModule->innerLE));
220 marginsModule->outerLE->setValidator(unsignedLengthValidator(
221 marginsModule->outerLE));
222 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
223 marginsModule->headsepLE));
224 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
225 marginsModule->headheightLE));
226 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
227 marginsModule->footskipLE));
229 addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
230 marginsModule->topL);
231 addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
232 marginsModule->bottomL);
233 addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
234 marginsModule->innerL);
235 addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
236 marginsModule->outerL);
237 addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
238 marginsModule->headsepL);
239 addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
240 marginsModule->headheightL);
241 addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
242 marginsModule->footskipL);
248 langModule = new UiWidget<Ui::LanguageUi>;
249 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingL, SLOT( setDisabled(bool) ) );
250 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingCO, SLOT( setDisabled(bool) ) );
252 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
253 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
254 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
255 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
257 vector<LanguagePair> const langs = getLanguageData(false);
258 vector<LanguagePair>::const_iterator lit = langs.begin();
259 vector<LanguagePair>::const_iterator lend = langs.end();
260 for (; lit != lend; ++lit) {
261 langModule->languageCO->insertItem(
266 while (encodings[k]) {
267 langModule->encodingCO->insertItem(qt_(encodings[k++]));
270 langModule->quoteStyleCO->insertItem(qt_("``text''"));
271 langModule->quoteStyleCO->insertItem(qt_("''text''"));
272 langModule->quoteStyleCO->insertItem(qt_(",,text``"));
273 langModule->quoteStyleCO->insertItem(qt_(",,text''"));
274 langModule->quoteStyleCO->insertItem(qt_("<<text>>"));
275 langModule->quoteStyleCO->insertItem(qt_(">>text<<"));
279 numberingModule = new UiWidget<Ui::NumberingUi>;
281 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
282 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
283 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
284 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
285 numberingModule->tocTW->setColumnCount(3);
286 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
287 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
288 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
291 biblioModule = new UiWidget<Ui::BiblioUi>;
292 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citationStyleL, SLOT( setEnabled(bool) ) );
293 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citeStyleCO, SLOT( setEnabled(bool) ) );
295 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
296 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
297 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
298 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
299 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
301 biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
302 biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
303 biblioModule->citeStyleCO->setCurrentItem(0);
307 mathsModule = new UiWidget<Ui::MathsUi>;
308 connect( mathsModule->amsautoCB, SIGNAL( toggled(bool) ), mathsModule->amsCB, SLOT( setDisabled(bool) ) );
310 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
311 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
314 latexModule = new UiWidget<Ui::LaTeXUi>;
316 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
317 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
318 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
319 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
321 for (int n = 0; tex_graphics[n][0]; ++n) {
322 QString enc = tex_graphics[n];
323 latexModule->psdriverCO->insertItem(enc);
326 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
327 cit != textclasslist.end(); ++cit) {
328 if (cit->isTeXClassAvailable()) {
329 latexModule->classCO->insertItem(toqstr(cit->description()));
332 bformat(_("Unavailable: %1$s"), cit->description());
333 latexModule->classCO->insertItem(toqstr(item));
339 branchesModule = new QBranches;
340 connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
343 preambleModule = new UiWidget<Ui::PreambleUi>;
345 connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
348 bulletsModule = new BulletsModule;
349 // FIXME: disable until we fix browsebox in BulletsModule.[Ch]
350 bulletsModule->setEnabled(false);
352 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
355 floatModule = new FloatPlacement;
357 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
359 docPS->addPanel(latexModule, _("Document Class"));
360 docPS->addPanel(textLayoutModule, _("Text Layout"));
361 docPS->addPanel(pageLayoutModule, _("Page Layout"));
362 docPS->addPanel(marginsModule, _("Page Margins"));
363 docPS->addPanel(langModule, _("Language"));
364 docPS->addPanel(numberingModule, _("Numbering & TOC"));
365 docPS->addPanel(biblioModule, _("Bibliography"));
366 docPS->addPanel(mathsModule, _("Math Options"));
367 docPS->addPanel(floatModule, _("Float Placement"));
368 docPS->addPanel(bulletsModule, _("Bullets"));
369 docPS->addPanel(branchesModule, _("Branches"));
370 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
371 docPS->setCurrentPanel(_("Document Class"));
375 QDocumentDialog::~QDocumentDialog()
380 void QDocumentDialog::showPreamble()
382 docPS->setCurrentPanel(_("LaTeX Preamble"));
386 void QDocumentDialog::saveDefaultClicked()
388 form_->saveDocDefault();
392 void QDocumentDialog::useDefaultsClicked()
394 form_->useClassDefaults();
398 void QDocumentDialog::change_adaptor()
404 void QDocumentDialog::closeEvent(QCloseEvent * e)
411 void QDocumentDialog::setLSpacing(int item)
413 textLayoutModule->lspacingLE->setEnabled(item == 3);
417 void QDocumentDialog::setSkip(int item)
419 bool const enable = (item == 3);
420 textLayoutModule->skipLE->setEnabled(enable);
421 textLayoutModule->skipLengthCO->setEnabled(enable);
425 void QDocumentDialog::enableSkip(bool skip)
427 textLayoutModule->skipCO->setEnabled(skip);
428 textLayoutModule->skipLE->setEnabled(skip);
429 textLayoutModule->skipLengthCO->setEnabled(skip);
431 setSkip(textLayoutModule->skipCO->currentItem());
434 void QDocumentDialog::portraitChanged()
436 setMargins(pageLayoutModule->papersizeCO->currentItem());
439 void QDocumentDialog::setMargins(bool custom)
441 marginsModule->marginCB->setChecked(custom);
442 setCustomMargins(custom);
446 void QDocumentDialog::setCustomPapersize(int papersize)
448 bool const custom = (papersize == 1);
450 pageLayoutModule->paperwidthL->setEnabled(custom);
451 pageLayoutModule->paperwidthLE->setEnabled(custom);
452 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
453 pageLayoutModule->paperheightL->setEnabled(custom);
454 pageLayoutModule->paperheightLE->setEnabled(custom);
455 pageLayoutModule->paperheightLE->setFocus();
456 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
460 void QDocumentDialog::setCustomMargins(bool custom)
462 marginsModule->topL->setEnabled(!custom);
463 marginsModule->topLE->setEnabled(!custom);
464 marginsModule->topUnit->setEnabled(!custom);
466 marginsModule->bottomL->setEnabled(!custom);
467 marginsModule->bottomLE->setEnabled(!custom);
468 marginsModule->bottomUnit->setEnabled(!custom);
470 marginsModule->innerL->setEnabled(!custom);
471 marginsModule->innerLE->setEnabled(!custom);
472 marginsModule->innerUnit->setEnabled(!custom);
474 marginsModule->outerL->setEnabled(!custom);
475 marginsModule->outerLE->setEnabled(!custom);
476 marginsModule->outerUnit->setEnabled(!custom);
478 marginsModule->headheightL->setEnabled(!custom);
479 marginsModule->headheightLE->setEnabled(!custom);
480 marginsModule->headheightUnit->setEnabled(!custom);
482 marginsModule->headsepL->setEnabled(!custom);
483 marginsModule->headsepLE->setEnabled(!custom);
484 marginsModule->headsepUnit->setEnabled(!custom);
486 marginsModule->footskipL->setEnabled(!custom);
487 marginsModule->footskipLE->setEnabled(!custom);
488 marginsModule->footskipUnit->setEnabled(!custom);
492 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
494 textLayoutModule->fontsizeCO->clear();
495 textLayoutModule->fontsizeCO->insertItem("default");
497 for (int n = 0; !token(items,'|',n).empty(); ++n)
498 textLayoutModule->fontsizeCO->
499 insertItem(toqstr(token(items,'|',n)));
501 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
502 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
503 textLayoutModule->fontsizeCO->setCurrentItem(n);
510 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
512 pageLayoutModule->pagestyleCO->clear();
513 pageLayoutModule->pagestyleCO->insertItem("default");
515 for (int n=0; !token(items,'|',n).empty(); ++n)
516 pageLayoutModule->pagestyleCO->
517 insertItem(toqstr(token(items,'|',n)));
519 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
520 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
521 pageLayoutModule->pagestyleCO->setCurrentItem(n);
528 void QDocumentDialog::classChanged()
530 ControlDocument & cntrl = form_->controller();
531 BufferParams & params = cntrl.params();
533 lyx::textclass_type const tc = latexModule->classCO->currentItem();
535 if (form_->controller().loadTextclass(tc)) {
536 params.textclass = tc;
537 if (lyxrc.auto_reset_options)
538 params.useClassDefaults();
539 form_->update_contents();
541 latexModule->classCO->setCurrentItem(params.textclass);
546 void QDocumentDialog::updateNumbering()
548 LyXTextClass const & tclass =
549 form_->controller().params().getLyXTextClass();
551 numberingModule->tocTW->setUpdatesEnabled(false);
552 numberingModule->tocTW->clear();
554 int const depth = numberingModule->depthSL->value();
555 int const toc = numberingModule->tocSL->value();
556 QString const no = qt_("No");
557 QString const yes = qt_("Yes");
558 LyXTextClass::const_iterator end = tclass.end();
559 LyXTextClass::const_iterator cit = tclass.begin();
560 QTreeWidgetItem * item = 0;
561 for ( ; cit != end ; ++cit) {
562 int const toclevel = (*cit)->toclevel;
563 if (toclevel != LyXLayout::NOT_IN_TOC) {
564 item = new QTreeWidgetItem(numberingModule->tocTW);
565 item->setText(0, qt_((*cit)->name()));
566 item->setText(1, (toclevel <= depth) ? yes : no);
567 item->setText(2, (toclevel <= toc) ? yes : no);
571 numberingModule->tocTW->setUpdatesEnabled(true);
572 numberingModule->tocTW->update();
575 void QDocumentDialog::apply(BufferParams & params)
579 fromqstr(preambleModule->preambleTE->document()->toPlainText());
582 params.cite_engine = biblio::ENGINE_BASIC;
584 if (biblioModule->citeNatbibRB->isChecked()) {
585 bool const use_numerical_citations =
586 biblioModule->citeStyleCO->currentItem();
587 if (use_numerical_citations)
588 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
590 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
592 } else if (biblioModule->citeJurabibRB->isChecked())
593 params.cite_engine = biblio::ENGINE_JURABIB;
595 params.use_bibtopic =
596 biblioModule->bibtopicCB->isChecked();
599 if (langModule->defaultencodingCB->isChecked()) {
600 params.inputenc = "auto";
602 int i = langModule->encodingCO->currentItem();
604 params.inputenc = "default";
606 params.inputenc = encodings[i];
610 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
611 switch (langModule->quoteStyleCO->currentItem()) {
613 lga = InsetQuotes::EnglishQ;
616 lga = InsetQuotes::SwedishQ;
619 lga = InsetQuotes::GermanQ;
622 lga = InsetQuotes::PolishQ;
625 lga = InsetQuotes::FrenchQ;
628 lga = InsetQuotes::DanishQ;
631 params.quotes_language = lga;
633 int const pos = langModule->languageCO->currentItem();
634 params.language = languages.getLanguage(lang_[pos]);
637 if (params.getLyXTextClass().hasTocLevels()) {
638 params.tocdepth = numberingModule->tocSL->value();
639 params.secnumdepth = numberingModule->depthSL->value();
643 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
644 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
645 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
646 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
649 params.graphicsDriver =
650 fromqstr(latexModule->psdriverCO->currentText());
652 if (mathsModule->amsautoCB->isChecked()) {
653 params.use_amsmath = BufferParams::AMS_AUTO;
655 if (mathsModule->amsCB->isChecked())
656 params.use_amsmath = BufferParams::AMS_ON;
658 params.use_amsmath = BufferParams::AMS_OFF;
663 latexModule->classCO->currentItem();
666 fromqstr(textLayoutModule->fontsCO->currentText());
669 fromqstr(textLayoutModule->fontsizeCO->currentText());
672 fromqstr(pageLayoutModule->pagestyleCO->currentText());
674 switch (textLayoutModule->lspacingCO->currentItem()) {
676 params.spacing().set(Spacing::Single);
679 params.spacing().set(Spacing::Onehalf);
682 params.spacing().set(Spacing::Double);
685 params.spacing().set(Spacing::Other,
686 fromqstr(textLayoutModule->lspacingLE->text()));
690 if (textLayoutModule->twoColumnCB->isChecked())
695 if (textLayoutModule->indentRB->isChecked())
696 params.paragraph_separation = BufferParams::PARSEP_INDENT;
698 params.paragraph_separation = BufferParams::PARSEP_SKIP;
700 switch (textLayoutModule->skipCO->currentItem()) {
702 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
705 params.setDefSkip(VSpace(VSpace::MEDSKIP));
708 params.setDefSkip(VSpace(VSpace::BIGSKIP));
713 widgetsToLength(textLayoutModule->skipLE,
714 textLayoutModule->skipLengthCO)
716 params.setDefSkip(vs);
720 // DocumentDefskipCB assures that this never happens
721 // so Assert then !!! - jbl
722 params.setDefSkip(VSpace(VSpace::MEDSKIP));
727 fromqstr(latexModule->optionsLE->text());
729 params.float_placement = floatModule->get();
732 params.papersize = PAPER_SIZE(
733 pageLayoutModule->papersizeCO->currentItem());
735 // custom, A3, B3 and B4 paper sizes need geometry
736 int psize = pageLayoutModule->papersizeCO->currentItem();
737 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
739 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
740 pageLayoutModule->paperwidthUnitCO);
742 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
743 pageLayoutModule->paperheightUnitCO);
745 if (pageLayoutModule->facingPagesCB->isChecked())
746 params.sides = LyXTextClass::TwoSides;
748 params.sides = LyXTextClass::OneSide;
750 if (pageLayoutModule->landscapeRB->isChecked())
751 params.orientation = ORIENTATION_LANDSCAPE;
753 params.orientation = ORIENTATION_PORTRAIT;
756 params.use_geometry =
757 (!marginsModule->marginCB->isChecked()
760 Ui::MarginsUi const * m(marginsModule);
762 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
764 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
766 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
768 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
770 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
772 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
774 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
776 branchesModule->apply(params);
781 /** Return the position of val in the vector if found.
782 If not found, return 0.
785 typename std::vector<A>::size_type
786 findPos(std::vector<A> const & vec, A const & val)
788 typename std::vector<A>::const_iterator it =
789 std::find(vec.begin(), vec.end(), val);
792 return distance(vec.begin(), it);
798 void QDocumentDialog::update(BufferParams const & params)
800 // set the default unit
801 // FIXME: move to controller
802 LyXLength::UNIT defaultUnit = LyXLength::CM;
803 switch (lyxrc.default_papersize) {
804 case PAPER_DEFAULT: break;
808 case PAPER_USEXECUTIVE:
809 defaultUnit = LyXLength::IN;
818 defaultUnit = LyXLength::CM;
825 QString preamble = toqstr(params.preamble);
826 preambleModule->preambleTE->document()->setPlainText(preamble);
829 biblioModule->citeDefaultRB->setChecked(
830 params.cite_engine == biblio::ENGINE_BASIC);
832 biblioModule->citeNatbibRB->setChecked(
833 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
834 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
836 biblioModule->citeStyleCO->setCurrentItem(
837 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
839 biblioModule->citeJurabibRB->setChecked(
840 params.cite_engine == biblio::ENGINE_JURABIB);
842 biblioModule->bibtopicCB->setChecked(
843 params.use_bibtopic);
846 int const pos = int(findPos(lang_,
847 params.language->lang()));
848 langModule->languageCO->setCurrentItem(pos);
850 langModule->quoteStyleCO->setCurrentItem(
851 params.quotes_language);
853 langModule->defaultencodingCB->setChecked(true);
855 if (params.inputenc != "auto") {
856 langModule->defaultencodingCB->setChecked(false);
857 if (params.inputenc == "default") {
858 langModule->encodingCO->setCurrentItem(0);
861 while (encodings[i]) {
862 if (encodings[i] == params.inputenc)
863 langModule->encodingCO->setCurrentItem(i);
870 int const min_toclevel = form_->controller().textClass().min_toclevel();
871 int const max_toclevel = form_->controller().textClass().max_toclevel();
872 if (form_->controller().textClass().hasTocLevels()) {
873 numberingModule->setEnabled(true);
874 numberingModule->depthSL->setMinValue(min_toclevel - 1);
875 numberingModule->depthSL->setMaxValue(max_toclevel);
876 numberingModule->depthSL->setValue(params.secnumdepth);
877 numberingModule->tocSL->setMinValue(min_toclevel - 1);
878 numberingModule->tocSL->setMaxValue(max_toclevel);
879 numberingModule->tocSL->setValue(params.tocdepth);
882 numberingModule->setEnabled(false);
883 numberingModule->tocTW->clear();
887 bulletsModule->setBullet(0,params.user_defined_bullet(0));
888 bulletsModule->setBullet(1,params.user_defined_bullet(1));
889 bulletsModule->setBullet(2,params.user_defined_bullet(2));
890 bulletsModule->setBullet(3,params.user_defined_bullet(3));
893 QString text = toqstr(params.graphicsDriver);
894 int nitem = latexModule->psdriverCO->count();
895 for (int n = 0; n < nitem ; ++n) {
896 QString enc = tex_graphics[n];
898 latexModule->psdriverCO->setCurrentItem(n);
903 mathsModule->amsCB->setChecked(
904 params.use_amsmath == BufferParams::AMS_ON);
905 mathsModule->amsautoCB->setChecked(
906 params.use_amsmath == BufferParams::AMS_AUTO);
908 switch (params.spacing().getSpace()) {
909 case Spacing::Other: nitem = 3; break;
910 case Spacing::Double: nitem = 2; break;
911 case Spacing::Onehalf: nitem = 1; break;
912 case Spacing::Default: case Spacing::Single: nitem = 0; break;
916 latexModule->classCO->setCurrentItem(params.textclass);
918 updateFontsize(form_->controller().textClass().opt_fontsize(),
921 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
924 for (int n = 0; tex_fonts[n][0]; ++n) {
925 if (tex_fonts[n] == params.fonts) {
926 textLayoutModule->fontsCO->setCurrentItem(n);
931 textLayoutModule->lspacingCO->setCurrentItem(nitem);
932 if (params.spacing().getSpace() == Spacing::Other) {
933 textLayoutModule->lspacingLE->setText(
934 toqstr(params.spacing().getValueAsString()));
938 if (params.paragraph_separation
939 == BufferParams::PARSEP_INDENT) {
940 textLayoutModule->indentRB->setChecked(true);
942 textLayoutModule->skipRB->setChecked(true);
946 switch (params.getDefSkip().kind()) {
947 case VSpace::SMALLSKIP:
950 case VSpace::MEDSKIP:
953 case VSpace::BIGSKIP:
959 string const length = params.getDefSkip().asLyXCommand();
960 lengthToWidgets(textLayoutModule->skipLE,
961 textLayoutModule->skipLengthCO,
962 length, defaultUnit);
969 textLayoutModule->skipCO->setCurrentItem(skip);
972 textLayoutModule->twoColumnCB->setChecked(
973 params.columns == 2);
975 if (!params.options.empty()) {
976 latexModule->optionsLE->setText(
977 toqstr(params.options));
979 latexModule->optionsLE->setText("");
982 floatModule->set(params.float_placement);
985 int const psize = params.papersize;
986 pageLayoutModule->papersizeCO->setCurrentItem(psize);
987 setCustomPapersize(psize);
989 bool const landscape =
990 params.orientation == ORIENTATION_LANDSCAPE;
991 pageLayoutModule->landscapeRB->setChecked(landscape);
992 pageLayoutModule->portraitRB->setChecked(!landscape);
994 pageLayoutModule->facingPagesCB->setChecked(
995 params.sides == LyXTextClass::TwoSides);
998 lengthToWidgets(pageLayoutModule->paperwidthLE,
999 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1001 lengthToWidgets(pageLayoutModule->paperheightLE,
1002 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1005 Ui::MarginsUi * m = marginsModule;
1007 setMargins(!params.use_geometry);
1009 lengthToWidgets(m->topLE, m->topUnit,
1010 params.topmargin, defaultUnit);
1012 lengthToWidgets(m->bottomLE, m->bottomUnit,
1013 params.bottommargin, defaultUnit);
1015 lengthToWidgets(m->innerLE, m->innerUnit,
1016 params.leftmargin, defaultUnit);
1018 lengthToWidgets(m->outerLE, m->outerUnit,
1019 params.rightmargin, defaultUnit);
1021 lengthToWidgets(m->headheightLE, m->headheightUnit,
1022 params.headheight, defaultUnit);
1024 lengthToWidgets(m->headsepLE, m->headsepUnit,
1025 params.headsep, defaultUnit);
1027 lengthToWidgets(m->footskipLE, m->footskipUnit,
1028 params.footskip, defaultUnit);
1030 branchesModule->update(params);
1036 } // namespace frontend