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() ), this, SLOT( saveDefaultClicked() ) );
86 connect( defaultPB, SIGNAL( clicked() ), this, SLOT( useDefaultsClicked() ) );
88 // Manage the restore, ok, apply, restore and cancel/close buttons
89 form_->bcview().setOK(okPB);
90 form_->bcview().setApply(applyPB);
91 form_->bcview().setCancel(closePB);
92 form_->bcview().setRestore(restorePB);
95 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
97 connect(textLayoutModule->fontsCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
98 connect(textLayoutModule->fontsizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
99 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
100 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)), this, SLOT(setLSpacing(int)));
101 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
102 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
103 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
104 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
105 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
106 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
107 connect(textLayoutModule->skipCO, SIGNAL(activated(int)), this, SLOT(setSkip(int)));
108 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)), this, SLOT(enableSkip(bool)));
109 connect(textLayoutModule->twoColumnCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
110 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
111 textLayoutModule->lspacingLE));
112 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
113 textLayoutModule->skipLE));
115 for (int n = 0; tex_fonts[n][0]; ++n) {
116 QString font = tex_fonts[n];
117 textLayoutModule->fontsCO->insertItem(font);
120 textLayoutModule->fontsizeCO->insertItem(qt_("default"));
121 textLayoutModule->fontsizeCO->insertItem(qt_("10"));
122 textLayoutModule->fontsizeCO->insertItem(qt_("11"));
123 textLayoutModule->fontsizeCO->insertItem(qt_("12"));
125 textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
126 textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
127 textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
128 textLayoutModule->skipCO->insertItem(qt_("Length"));
129 // remove the %-items from the unit choice
130 textLayoutModule->skipLengthCO->noPercents();
131 textLayoutModule->lspacingCO->insertItem(
132 qt_("Single"), Spacing::Single);
133 textLayoutModule->lspacingCO->insertItem(
134 qt_("OneHalf"), Spacing::Onehalf);
135 textLayoutModule->lspacingCO->insertItem(
136 qt_("Double"), Spacing::Double);
137 textLayoutModule->lspacingCO->insertItem(
138 qt_("Custom"), Spacing::Other);
140 // initialize the length validator
141 addCheckedLineEdit(form_->bcview(), textLayoutModule->skipLE);
146 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
148 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
149 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(setCustomPapersize(int)));
150 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(portraitChanged()));
151 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
152 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
153 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
154 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
155 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
156 connect(pageLayoutModule->portraitRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
157 connect(pageLayoutModule->landscapeRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
158 connect(pageLayoutModule->facingPagesCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
159 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
160 pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
161 pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
162 pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
163 pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
164 pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
165 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperheightLE,
166 pageLayoutModule->paperheightL);
167 addCheckedLineEdit(form_->bcview(), pageLayoutModule->paperwidthLE,
168 pageLayoutModule->paperwidthL);
171 QComboBox * cb = pageLayoutModule->papersizeCO;
172 cb->insertItem(qt_("Default"));
173 cb->insertItem(qt_("Custom"));
174 cb->insertItem(qt_("US letter"));
175 cb->insertItem(qt_("US legal"));
176 cb->insertItem(qt_("US executive"));
177 cb->insertItem(qt_("A3"));
178 cb->insertItem(qt_("A4"));
179 cb->insertItem(qt_("A5"));
180 cb->insertItem(qt_("B3"));
181 cb->insertItem(qt_("B4"));
182 cb->insertItem(qt_("B5"));
183 // remove the %-items from the unit choice
184 pageLayoutModule->paperwidthUnitCO->noPercents();
185 pageLayoutModule->paperheightUnitCO->noPercents();
186 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
187 pageLayoutModule->paperheightLE));
188 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
189 pageLayoutModule->paperwidthLE));
194 marginsModule = new UiWidget<Ui::MarginsUi>;
196 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(setCustomMargins(bool)));
197 connect(marginsModule->marginCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
198 connect(marginsModule->topLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
199 connect(marginsModule->topUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
200 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
201 connect(marginsModule->bottomUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
202 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
203 connect(marginsModule->innerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
204 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
205 connect(marginsModule->outerUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
206 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
207 connect(marginsModule->headheightUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
208 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
209 connect(marginsModule->headsepUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
210 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
211 connect(marginsModule->footskipUnit, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
212 marginsModule->topLE->setValidator(unsignedLengthValidator(
213 marginsModule->topLE));
214 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
215 marginsModule->bottomLE));
216 marginsModule->innerLE->setValidator(unsignedLengthValidator(
217 marginsModule->innerLE));
218 marginsModule->outerLE->setValidator(unsignedLengthValidator(
219 marginsModule->outerLE));
220 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
221 marginsModule->headsepLE));
222 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
223 marginsModule->headheightLE));
224 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
225 marginsModule->footskipLE));
227 addCheckedLineEdit(form_->bcview(), marginsModule->topLE,
228 marginsModule->topL);
229 addCheckedLineEdit(form_->bcview(), marginsModule->bottomLE,
230 marginsModule->bottomL);
231 addCheckedLineEdit(form_->bcview(), marginsModule->innerLE,
232 marginsModule->innerL);
233 addCheckedLineEdit(form_->bcview(), marginsModule->outerLE,
234 marginsModule->outerL);
235 addCheckedLineEdit(form_->bcview(), marginsModule->headsepLE,
236 marginsModule->headsepL);
237 addCheckedLineEdit(form_->bcview(), marginsModule->headheightLE,
238 marginsModule->headheightL);
239 addCheckedLineEdit(form_->bcview(), marginsModule->footskipLE,
240 marginsModule->footskipL);
246 langModule = new UiWidget<Ui::LanguageUi>;
247 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingL, SLOT( setDisabled(bool) ) );
248 connect( langModule->defaultencodingCB, SIGNAL( toggled(bool) ), langModule->encodingCO, SLOT( setDisabled(bool) ) );
250 connect(langModule->languageCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
251 connect(langModule->defaultencodingCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
252 connect(langModule->encodingCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
253 connect(langModule->quoteStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
255 vector<LanguagePair> const langs = getLanguageData(false);
256 vector<LanguagePair>::const_iterator lit = langs.begin();
257 vector<LanguagePair>::const_iterator lend = langs.end();
258 for (; lit != lend; ++lit) {
259 langModule->languageCO->insertItem(
264 while (encodings[k]) {
265 langModule->encodingCO->insertItem(qt_(encodings[k++]));
268 langModule->quoteStyleCO->insertItem(qt_("``text''"));
269 langModule->quoteStyleCO->insertItem(qt_("''text''"));
270 langModule->quoteStyleCO->insertItem(qt_(",,text``"));
271 langModule->quoteStyleCO->insertItem(qt_(",,text''"));
272 langModule->quoteStyleCO->insertItem(qt_("<<text>>"));
273 langModule->quoteStyleCO->insertItem(qt_(">>text<<"));
277 numberingModule = new UiWidget<Ui::NumberingUi>;
279 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
280 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(change_adaptor()));
281 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
282 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)), this, SLOT(updateNumbering()));
283 numberingModule->tocLV->setSorting(-1);
287 biblioModule = new UiWidget<Ui::BiblioUi>;
288 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citationStyleL, SLOT( setEnabled(bool) ) );
289 connect( biblioModule->citeNatbibRB, SIGNAL( toggled(bool) ), biblioModule->citeStyleCO, SLOT( setEnabled(bool) ) );
291 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
292 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
293 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
294 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
295 connect(biblioModule->bibtopicCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
297 biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
298 biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
299 biblioModule->citeStyleCO->setCurrentItem(0);
303 mathsModule = new UiWidget<Ui::MathsUi>;
304 connect( mathsModule->amsautoCB, SIGNAL( toggled(bool) ), mathsModule->amsCB, SLOT( setDisabled(bool) ) );
306 connect(mathsModule->amsCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
307 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
310 latexModule = new UiWidget<Ui::LaTeXUi>;
312 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
313 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor()));
314 connect(latexModule->psdriverCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
315 connect(latexModule->classCO, SIGNAL(activated(int)), this, SLOT(classChanged()));
317 for (int n = 0; tex_graphics[n][0]; ++n) {
318 QString enc = tex_graphics[n];
319 latexModule->psdriverCO->insertItem(enc);
322 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
323 cit != textclasslist.end(); ++cit) {
324 if (cit->isTeXClassAvailable()) {
325 latexModule->classCO->insertItem(toqstr(cit->description()));
328 bformat(_("Unavailable: %1$s"), cit->description());
329 latexModule->classCO->insertItem(toqstr(item));
335 branchesModule = new QBranches;
336 connect(branchesModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
339 preambleModule = new UiWidget<Ui::PreambleUi>;
341 connect(preambleModule->preambleTE, SIGNAL(textChanged()), this, SLOT(change_adaptor()));
344 bulletsModule = new BulletsModule;
346 connect(bulletsModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
349 floatModule = new FloatPlacement(this);
351 connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor()));
353 docPS->addPanel(latexModule, _("Document Class"));
354 docPS->addPanel(textLayoutModule, _("Text Layout"));
355 docPS->addPanel(pageLayoutModule, _("Page Layout"));
356 docPS->addPanel(marginsModule, _("Page Margins"));
357 docPS->addPanel(langModule, _("Language"));
358 docPS->addPanel(numberingModule, _("Numbering & TOC"));
359 docPS->addPanel(biblioModule, _("Bibliography"));
360 docPS->addPanel(mathsModule, _("Math Options"));
361 docPS->addPanel(floatModule, _("Float Placement"));
362 docPS->addPanel(bulletsModule, _("Bullets"));
363 docPS->addPanel(branchesModule, _("Branches"));
364 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
365 docPS->setCurrentPanel(_("Document Class"));
369 QDocumentDialog::~QDocumentDialog()
374 void QDocumentDialog::showPreamble()
376 docPS->setCurrentPanel(_("LaTeX Preamble"));
380 void QDocumentDialog::saveDefaultClicked()
382 form_->saveDocDefault();
386 void QDocumentDialog::useDefaultsClicked()
388 form_->useClassDefaults();
392 void QDocumentDialog::change_adaptor()
398 void QDocumentDialog::closeEvent(QCloseEvent * e)
405 void QDocumentDialog::setLSpacing(int item)
407 textLayoutModule->lspacingLE->setEnabled(item == 3);
411 void QDocumentDialog::setSkip(int item)
413 bool const enable = (item == 3);
414 textLayoutModule->skipLE->setEnabled(enable);
415 textLayoutModule->skipLengthCO->setEnabled(enable);
419 void QDocumentDialog::enableSkip(bool skip)
421 textLayoutModule->skipCO->setEnabled(skip);
422 textLayoutModule->skipLE->setEnabled(skip);
423 textLayoutModule->skipLengthCO->setEnabled(skip);
425 setSkip(textLayoutModule->skipCO->currentItem());
428 void QDocumentDialog::portraitChanged()
430 setMargins(pageLayoutModule->papersizeCO->currentItem());
433 void QDocumentDialog::setMargins(bool custom)
435 marginsModule->marginCB->setChecked(custom);
436 setCustomMargins(custom);
440 void QDocumentDialog::setCustomPapersize(int papersize)
442 bool const custom = (papersize == 1);
444 pageLayoutModule->paperwidthL->setEnabled(custom);
445 pageLayoutModule->paperwidthLE->setEnabled(custom);
446 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
447 pageLayoutModule->paperheightL->setEnabled(custom);
448 pageLayoutModule->paperheightLE->setEnabled(custom);
449 pageLayoutModule->paperheightLE->setFocus();
450 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
454 void QDocumentDialog::setCustomMargins(bool custom)
456 marginsModule->topL->setEnabled(!custom);
457 marginsModule->topLE->setEnabled(!custom);
458 marginsModule->topUnit->setEnabled(!custom);
460 marginsModule->bottomL->setEnabled(!custom);
461 marginsModule->bottomLE->setEnabled(!custom);
462 marginsModule->bottomUnit->setEnabled(!custom);
464 marginsModule->innerL->setEnabled(!custom);
465 marginsModule->innerLE->setEnabled(!custom);
466 marginsModule->innerUnit->setEnabled(!custom);
468 marginsModule->outerL->setEnabled(!custom);
469 marginsModule->outerLE->setEnabled(!custom);
470 marginsModule->outerUnit->setEnabled(!custom);
472 marginsModule->headheightL->setEnabled(!custom);
473 marginsModule->headheightLE->setEnabled(!custom);
474 marginsModule->headheightUnit->setEnabled(!custom);
476 marginsModule->headsepL->setEnabled(!custom);
477 marginsModule->headsepLE->setEnabled(!custom);
478 marginsModule->headsepUnit->setEnabled(!custom);
480 marginsModule->footskipL->setEnabled(!custom);
481 marginsModule->footskipLE->setEnabled(!custom);
482 marginsModule->footskipUnit->setEnabled(!custom);
486 void QDocumentDialog::updateFontsize(string const & items, string const & sel)
488 textLayoutModule->fontsizeCO->clear();
489 textLayoutModule->fontsizeCO->insertItem("default");
491 for (int n = 0; !token(items,'|',n).empty(); ++n)
492 textLayoutModule->fontsizeCO->
493 insertItem(toqstr(token(items,'|',n)));
495 for (int n = 0; n<textLayoutModule->fontsizeCO->count(); ++n) {
496 if (fromqstr(textLayoutModule->fontsizeCO->text(n)) == sel) {
497 textLayoutModule->fontsizeCO->setCurrentItem(n);
504 void QDocumentDialog::updatePagestyle(string const & items, string const & sel)
506 pageLayoutModule->pagestyleCO->clear();
507 pageLayoutModule->pagestyleCO->insertItem("default");
509 for (int n=0; !token(items,'|',n).empty(); ++n)
510 pageLayoutModule->pagestyleCO->
511 insertItem(toqstr(token(items,'|',n)));
513 for (int n = 0; n<pageLayoutModule->pagestyleCO->count(); ++n) {
514 if (fromqstr(pageLayoutModule->pagestyleCO->text(n))==sel) {
515 pageLayoutModule->pagestyleCO->setCurrentItem(n);
522 void QDocumentDialog::classChanged()
524 ControlDocument & cntrl = form_->controller();
525 BufferParams & params = cntrl.params();
527 lyx::textclass_type const tc = latexModule->classCO->currentItem();
529 if (form_->controller().loadTextclass(tc)) {
530 params.textclass = tc;
531 if (lyxrc.auto_reset_options)
532 params.useClassDefaults();
533 form_->update_contents();
535 latexModule->classCO->setCurrentItem(params.textclass);
540 void QDocumentDialog::updateNumbering()
542 LyXTextClass const & tclass =
543 form_->controller().params().getLyXTextClass();
545 //numberingModule->tocLV->setUpdatesEnabled(false);
547 // Update the example QListView
548 int const depth = numberingModule->depthSL->value();
549 int const toc = numberingModule->tocSL->value();
550 QString const no = qt_("No");
551 QString const yes = qt_("Yes");
552 LyXTextClass::const_iterator end = tclass.end();
553 LyXTextClass::const_iterator cit = tclass.begin();
554 numberingModule->tocLV->clear();
555 Q3ListViewItem * item = 0;
556 for ( ; cit != end ; ++cit) {
557 int const toclevel = (*cit)->toclevel;
558 if (toclevel != LyXLayout::NOT_IN_TOC) {
559 item = new Q3ListViewItem(numberingModule->tocLV,
560 item, qt_((*cit)->name()));
561 item->setText(1, (toclevel <= depth) ? yes : no);
562 item->setText(2, (toclevel <= toc) ? yes : no);
566 //numberingModule->tocLV->setUpdatesEnabled(true);
567 //numberingModule->tocLV->update();
570 void QDocumentDialog::apply(BufferParams & params)
574 fromqstr(preambleModule->preambleTE->document()->toPlainText());
577 params.cite_engine = biblio::ENGINE_BASIC;
579 if (biblioModule->citeNatbibRB->isChecked()) {
580 bool const use_numerical_citations =
581 biblioModule->citeStyleCO->currentItem();
582 if (use_numerical_citations)
583 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
585 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
587 } else if (biblioModule->citeJurabibRB->isChecked())
588 params.cite_engine = biblio::ENGINE_JURABIB;
590 params.use_bibtopic =
591 biblioModule->bibtopicCB->isChecked();
594 if (langModule->defaultencodingCB->isChecked()) {
595 params.inputenc = "auto";
597 int i = langModule->encodingCO->currentItem();
599 params.inputenc = "default";
601 params.inputenc = encodings[i];
605 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
606 switch (langModule->quoteStyleCO->currentItem()) {
608 lga = InsetQuotes::EnglishQ;
611 lga = InsetQuotes::SwedishQ;
614 lga = InsetQuotes::GermanQ;
617 lga = InsetQuotes::PolishQ;
620 lga = InsetQuotes::FrenchQ;
623 lga = InsetQuotes::DanishQ;
626 params.quotes_language = lga;
628 int const pos = langModule->languageCO->currentItem();
629 params.language = languages.getLanguage(lang_[pos]);
632 if (params.getLyXTextClass().hasTocLevels()) {
633 params.tocdepth = numberingModule->tocSL->value();
634 params.secnumdepth = numberingModule->depthSL->value();
638 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
639 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
640 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
641 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
644 params.graphicsDriver =
645 fromqstr(latexModule->psdriverCO->currentText());
647 if (mathsModule->amsautoCB->isChecked()) {
648 params.use_amsmath = BufferParams::AMS_AUTO;
650 if (mathsModule->amsCB->isChecked())
651 params.use_amsmath = BufferParams::AMS_ON;
653 params.use_amsmath = BufferParams::AMS_OFF;
658 latexModule->classCO->currentItem();
661 fromqstr(textLayoutModule->fontsCO->currentText());
664 fromqstr(textLayoutModule->fontsizeCO->currentText());
667 fromqstr(pageLayoutModule->pagestyleCO->currentText());
669 switch (textLayoutModule->lspacingCO->currentItem()) {
671 params.spacing().set(Spacing::Single);
674 params.spacing().set(Spacing::Onehalf);
677 params.spacing().set(Spacing::Double);
680 params.spacing().set(Spacing::Other,
681 fromqstr(textLayoutModule->lspacingLE->text()));
685 if (textLayoutModule->twoColumnCB->isChecked())
690 if (textLayoutModule->indentRB->isChecked())
691 params.paragraph_separation = BufferParams::PARSEP_INDENT;
693 params.paragraph_separation = BufferParams::PARSEP_SKIP;
695 switch (textLayoutModule->skipCO->currentItem()) {
697 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
700 params.setDefSkip(VSpace(VSpace::MEDSKIP));
703 params.setDefSkip(VSpace(VSpace::BIGSKIP));
708 widgetsToLength(textLayoutModule->skipLE,
709 textLayoutModule->skipLengthCO)
711 params.setDefSkip(vs);
715 // DocumentDefskipCB assures that this never happens
716 // so Assert then !!! - jbl
717 params.setDefSkip(VSpace(VSpace::MEDSKIP));
722 fromqstr(latexModule->optionsLE->text());
724 params.float_placement = floatModule->get();
727 params.papersize = PAPER_SIZE(
728 pageLayoutModule->papersizeCO->currentItem());
730 // custom, A3, B3 and B4 paper sizes need geometry
731 int psize = pageLayoutModule->papersizeCO->currentItem();
732 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
734 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
735 pageLayoutModule->paperwidthUnitCO);
737 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
738 pageLayoutModule->paperheightUnitCO);
740 if (pageLayoutModule->facingPagesCB->isChecked())
741 params.sides = LyXTextClass::TwoSides;
743 params.sides = LyXTextClass::OneSide;
745 if (pageLayoutModule->landscapeRB->isChecked())
746 params.orientation = ORIENTATION_LANDSCAPE;
748 params.orientation = ORIENTATION_PORTRAIT;
751 params.use_geometry =
752 (!marginsModule->marginCB->isChecked()
755 Ui::MarginsUi const * m(marginsModule);
757 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
759 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
761 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
763 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
765 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
767 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
769 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
771 branchesModule->apply(params);
776 /** Return the position of val in the vector if found.
777 If not found, return 0.
780 typename std::vector<A>::size_type
781 findPos(std::vector<A> const & vec, A const & val)
783 typename std::vector<A>::const_iterator it =
784 std::find(vec.begin(), vec.end(), val);
787 return distance(vec.begin(), it);
793 void QDocumentDialog::update(BufferParams const & params)
795 // set the default unit
796 // FIXME: move to controller
797 LyXLength::UNIT defaultUnit = LyXLength::CM;
798 switch (lyxrc.default_papersize) {
799 case PAPER_DEFAULT: break;
803 case PAPER_USEXECUTIVE:
804 defaultUnit = LyXLength::IN;
813 defaultUnit = LyXLength::CM;
820 QString preamble = toqstr(params.preamble);
821 preambleModule->preambleTE->document()->setPlainText(preamble);
824 biblioModule->citeDefaultRB->setChecked(
825 params.cite_engine == biblio::ENGINE_BASIC);
827 biblioModule->citeNatbibRB->setChecked(
828 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
829 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
831 biblioModule->citeStyleCO->setCurrentItem(
832 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
834 biblioModule->citeJurabibRB->setChecked(
835 params.cite_engine == biblio::ENGINE_JURABIB);
837 biblioModule->bibtopicCB->setChecked(
838 params.use_bibtopic);
841 int const pos = int(findPos(lang_,
842 params.language->lang()));
843 langModule->languageCO->setCurrentItem(pos);
845 langModule->quoteStyleCO->setCurrentItem(
846 params.quotes_language);
848 langModule->defaultencodingCB->setChecked(true);
850 if (params.inputenc != "auto") {
851 langModule->defaultencodingCB->setChecked(false);
852 if (params.inputenc == "default") {
853 langModule->encodingCO->setCurrentItem(0);
856 while (encodings[i]) {
857 if (encodings[i] == params.inputenc)
858 langModule->encodingCO->setCurrentItem(i);
865 int const min_toclevel = form_->controller().textClass().min_toclevel();
866 int const max_toclevel = form_->controller().textClass().max_toclevel();
867 if (form_->controller().textClass().hasTocLevels())
868 numberingModule->setEnabled(true);
869 numberingModule->depthSL->setMinValue(min_toclevel - 1);
870 numberingModule->depthSL->setMaxValue(max_toclevel);
871 numberingModule->depthSL->setValue(params.secnumdepth);
872 numberingModule->tocSL->setMinValue(min_toclevel - 1);
873 numberingModule->tocSL->setMaxValue(max_toclevel);
874 numberingModule->tocSL->setValue(params.tocdepth);
877 numberingModule->setEnabled(false);
878 numberingModule->tocLV->clear();
882 bulletsModule->setBullet(0,params.user_defined_bullet(0));
883 bulletsModule->setBullet(1,params.user_defined_bullet(1));
884 bulletsModule->setBullet(2,params.user_defined_bullet(2));
885 bulletsModule->setBullet(3,params.user_defined_bullet(3));
888 QString text = toqstr(params.graphicsDriver);
889 int nitem = latexModule->psdriverCO->count();
890 for (int n = 0; n < nitem ; ++n) {
891 QString enc = tex_graphics[n];
893 latexModule->psdriverCO->setCurrentItem(n);
898 mathsModule->amsCB->setChecked(
899 params.use_amsmath == BufferParams::AMS_ON);
900 mathsModule->amsautoCB->setChecked(
901 params.use_amsmath == BufferParams::AMS_AUTO);
903 switch (params.spacing().getSpace()) {
904 case Spacing::Other: nitem = 3; break;
905 case Spacing::Double: nitem = 2; break;
906 case Spacing::Onehalf: nitem = 1; break;
907 case Spacing::Default: case Spacing::Single: nitem = 0; break;
911 latexModule->classCO->setCurrentItem(params.textclass);
913 updateFontsize(form_->controller().textClass().opt_fontsize(),
916 updatePagestyle(form_->controller().textClass().opt_pagestyle(),
919 for (int n = 0; tex_fonts[n][0]; ++n) {
920 if (tex_fonts[n] == params.fonts) {
921 textLayoutModule->fontsCO->setCurrentItem(n);
926 textLayoutModule->lspacingCO->setCurrentItem(nitem);
927 if (params.spacing().getSpace() == Spacing::Other) {
928 textLayoutModule->lspacingLE->setText(
929 toqstr(params.spacing().getValueAsString()));
933 if (params.paragraph_separation
934 == BufferParams::PARSEP_INDENT) {
935 textLayoutModule->indentRB->setChecked(true);
937 textLayoutModule->skipRB->setChecked(true);
941 switch (params.getDefSkip().kind()) {
942 case VSpace::SMALLSKIP:
945 case VSpace::MEDSKIP:
948 case VSpace::BIGSKIP:
954 string const length = params.getDefSkip().asLyXCommand();
955 lengthToWidgets(textLayoutModule->skipLE,
956 textLayoutModule->skipLengthCO,
957 length, defaultUnit);
964 textLayoutModule->skipCO->setCurrentItem(skip);
967 textLayoutModule->twoColumnCB->setChecked(
968 params.columns == 2);
970 if (!params.options.empty()) {
971 latexModule->optionsLE->setText(
972 toqstr(params.options));
974 latexModule->optionsLE->setText("");
977 floatModule->set(params.float_placement);
980 int const psize = params.papersize;
981 pageLayoutModule->papersizeCO->setCurrentItem(psize);
982 setCustomPapersize(psize);
984 bool const landscape =
985 params.orientation == ORIENTATION_LANDSCAPE;
986 pageLayoutModule->landscapeRB->setChecked(landscape);
987 pageLayoutModule->portraitRB->setChecked(!landscape);
989 pageLayoutModule->facingPagesCB->setChecked(
990 params.sides == LyXTextClass::TwoSides);
993 lengthToWidgets(pageLayoutModule->paperwidthLE,
994 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
996 lengthToWidgets(pageLayoutModule->paperheightLE,
997 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1000 Ui::MarginsUi * m = marginsModule;
1002 setMargins(!params.use_geometry);
1004 lengthToWidgets(m->topLE, m->topUnit,
1005 params.topmargin, defaultUnit);
1007 lengthToWidgets(m->bottomLE, m->bottomUnit,
1008 params.bottommargin, defaultUnit);
1010 lengthToWidgets(m->innerLE, m->innerUnit,
1011 params.leftmargin, defaultUnit);
1013 lengthToWidgets(m->outerLE, m->outerUnit,
1014 params.rightmargin, defaultUnit);
1016 lengthToWidgets(m->headheightLE, m->headheightUnit,
1017 params.headheight, defaultUnit);
1019 lengthToWidgets(m->headsepLE, m->headsepUnit,
1020 params.headsep, defaultUnit);
1022 lengthToWidgets(m->footskipLE, m->footskipUnit,
1023 params.footskip, defaultUnit);
1025 branchesModule->update(params);
1031 } // namespace frontend