3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "checkedwidgets.h"
14 #include "QDocument.h"
15 #include "QDocumentDialog.h"
17 #include "qt_helpers.h"
19 #include "bufferparams.h"
20 #include "floatplacement.h"
22 #include "helper_funcs.h" // getSecond()
24 #include "lyxrc.h" // defaultUnit
25 #include "lyxtextclasslist.h"
26 #include "tex-strings.h" // tex_graphics
28 #include "support/tostr.h"
29 #include "support/lstrings.h"
31 #include "controllers/ControlDocument.h"
32 #include "controllers/frnt_lang.h"
34 #include <qpushbutton.h>
35 #include <qmultilineedit.h>
36 #include <qradiobutton.h>
37 #include <qcheckbox.h>
39 #include <qlineedit.h>
40 #include "lengthcombo.h"
43 using lyx::support::bformat;
44 using lyx::support::getVectorFromString;
53 typedef QController<ControlDocument, QView<QDocumentDialog> > base_class;
58 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
59 "latin3", "latin4", "latin5", "latin9",
60 "koi8-r", "koi8-u", "cp866", "cp1251",
61 "iso88595", "pt154", 0
67 QDocument::QDocument(Dialog & parent)
68 : base_class(parent, _("LyX: Document Settings")),
69 lang_(getSecond(getLanguageData(false)))
73 void QDocument::build_dialog()
75 dialog_.reset(new QDocumentDialog(this));
78 dialog_->biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
79 dialog_->biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
80 dialog_->biblioModule->citeStyleCO->setCurrentItem(0);
83 vector<LanguagePair> const langs = getLanguageData(false);
84 vector<LanguagePair>::const_iterator lit = langs.begin();
85 vector<LanguagePair>::const_iterator lend = langs.end();
86 for (; lit != lend; ++lit) {
87 dialog_->langModule->languageCO->insertItem(
92 while (encodings[i]) {
93 dialog_->langModule->encodingCO->insertItem(qt_(encodings[i++]));
96 dialog_->langModule->quoteStyleCO->insertItem(qt_("``text''"));
97 dialog_->langModule->quoteStyleCO->insertItem(qt_("''text''"));
98 dialog_->langModule->quoteStyleCO->insertItem(qt_(",,text``"));
99 dialog_->langModule->quoteStyleCO->insertItem(qt_(",,text''"));
100 dialog_->langModule->quoteStyleCO->insertItem(qt_("<<text>>"));
101 dialog_->langModule->quoteStyleCO->insertItem(qt_(">>text<<"));
104 for (int n = 0; tex_graphics[n][0]; ++n) {
105 QString enc = tex_graphics[n];
106 dialog_->latexModule->psdriverCO->insertItem(enc);
110 QComboBox * cb = dialog_->pageLayoutModule->papersizeCO;
111 cb->insertItem(qt_("Default"));
112 cb->insertItem(qt_("Custom"));
113 cb->insertItem(qt_("US letter"));
114 cb->insertItem(qt_("US legal"));
115 cb->insertItem(qt_("US executive"));
116 cb->insertItem(qt_("A3"));
117 cb->insertItem(qt_("A4"));
118 cb->insertItem(qt_("A5"));
119 cb->insertItem(qt_("B3"));
120 cb->insertItem(qt_("B4"));
121 cb->insertItem(qt_("B5"));
122 // remove the %-items from the unit choice
123 dialog_->pageLayoutModule->paperwidthUnitCO->noPercents();
124 dialog_->pageLayoutModule->paperheightUnitCO->noPercents();
127 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
128 cit != textclasslist.end(); ++cit) {
129 if (cit->isTeXClassAvailable()) {
130 dialog_->latexModule->classCO->insertItem(toqstr(cit->description()));
133 bformat(_("Unavailable: %1$s"), cit->description());
134 dialog_->latexModule->classCO->insertItem(toqstr(item));
138 for (int n = 0; tex_fonts[n][0]; ++n) {
139 QString font = tex_fonts[n];
140 dialog_->textLayoutModule->fontsCO->insertItem(font);
143 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("default"));
144 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("10"));
145 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("11"));
146 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("12"));
148 dialog_->textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
149 dialog_->textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
150 dialog_->textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
151 dialog_->textLayoutModule->skipCO->insertItem(qt_("Length"));
152 // remove the %-items from the unit choice
153 dialog_->textLayoutModule->skipLengthCO->noPercents();
155 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
156 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
157 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
158 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
159 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
161 dialog_->textLayoutModule->lspacingCO->insertItem(
162 qt_("Single"), Spacing::Single);
163 dialog_->textLayoutModule->lspacingCO->insertItem(
164 qt_("OneHalf"), Spacing::Onehalf);
165 dialog_->textLayoutModule->lspacingCO->insertItem(
166 qt_("Double"), Spacing::Double);
167 dialog_->textLayoutModule->lspacingCO->insertItem(
168 qt_("Custom"), Spacing::Other);
171 dialog_->setMargins(0);
173 // Manage the restore, ok, apply, restore and cancel/close buttons
174 bcview().setOK(dialog_->okPB);
175 bcview().setApply(dialog_->applyPB);
176 bcview().setCancel(dialog_->closePB);
177 bcview().setRestore(dialog_->restorePB);
179 // initialize the length validator
180 addCheckedLineEdit(bcview(), dialog_->textLayoutModule->skipLE);
181 addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperheightLE,
182 dialog_->pageLayoutModule->paperheightL);
183 addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperwidthLE,
184 dialog_->pageLayoutModule->paperwidthL);
185 addCheckedLineEdit(bcview(), dialog_->marginsModule->topLE,
186 dialog_->marginsModule->topL);
187 addCheckedLineEdit(bcview(), dialog_->marginsModule->bottomLE,
188 dialog_->marginsModule->bottomL);
189 addCheckedLineEdit(bcview(), dialog_->marginsModule->innerLE,
190 dialog_->marginsModule->innerL);
191 addCheckedLineEdit(bcview(), dialog_->marginsModule->outerLE,
192 dialog_->marginsModule->outerL);
193 addCheckedLineEdit(bcview(), dialog_->marginsModule->headsepLE,
194 dialog_->marginsModule->headsepL);
195 addCheckedLineEdit(bcview(), dialog_->marginsModule->headheightLE,
196 dialog_->marginsModule->headheightL);
197 addCheckedLineEdit(bcview(), dialog_->marginsModule->footskipLE,
198 dialog_->marginsModule->footskipL);
202 void QDocument::showPreamble()
204 dialog_->showPreamble();
208 void QDocument::apply()
210 BufferParams & params = controller().params();
214 fromqstr(dialog_->preambleModule->preambleMLE->text());
217 params.cite_engine = biblio::ENGINE_BASIC;
219 if (dialog_->biblioModule->citeNatbibRB->isChecked()) {
220 bool const use_numerical_citations =
221 dialog_->biblioModule->citeStyleCO->currentItem();
222 if (use_numerical_citations)
223 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
225 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
227 } else if (dialog_->biblioModule->citeJurabibRB->isChecked())
228 params.cite_engine = biblio::ENGINE_JURABIB;
230 params.use_bibtopic =
231 dialog_->biblioModule->bibtopicCB->isChecked();
234 if (dialog_->langModule->defaultencodingCB->isChecked()) {
235 params.inputenc = "auto";
237 int i = dialog_->langModule->encodingCO->currentItem();
239 params.inputenc = "default";
241 params.inputenc = encodings[i];
245 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
246 switch (dialog_->langModule->quoteStyleCO->currentItem()) {
248 lga = InsetQuotes::EnglishQ;
251 lga = InsetQuotes::SwedishQ;
254 lga = InsetQuotes::GermanQ;
257 lga = InsetQuotes::PolishQ;
260 lga = InsetQuotes::FrenchQ;
263 lga = InsetQuotes::DanishQ;
266 params.quotes_language = lga;
268 int const pos = dialog_->langModule->languageCO->currentItem();
269 params.language = languages.getLanguage(lang_[pos]);
272 params.tocdepth = dialog_->numberingModule->tocSL->value();
273 params.secnumdepth = dialog_->numberingModule->depthSL->value();
276 params.user_defined_bullet(0) = dialog_->bulletsModule->getBullet(0);
277 params.user_defined_bullet(1) = dialog_->bulletsModule->getBullet(1);
278 params.user_defined_bullet(2) = dialog_->bulletsModule->getBullet(2);
279 params.user_defined_bullet(3) = dialog_->bulletsModule->getBullet(3);
282 params.graphicsDriver =
283 fromqstr(dialog_->latexModule->psdriverCO->currentText());
285 if (dialog_->mathsModule->amsautoCB->isChecked()) {
286 params.use_amsmath = BufferParams::AMS_AUTO;
288 if (dialog_->mathsModule->amsCB->isChecked())
289 params.use_amsmath = BufferParams::AMS_ON;
291 params.use_amsmath = BufferParams::AMS_OFF;
296 dialog_->latexModule->classCO->currentItem();
299 fromqstr(dialog_->textLayoutModule->fontsCO->currentText());
302 fromqstr(dialog_->textLayoutModule->fontsizeCO->currentText());
305 fromqstr(dialog_->pageLayoutModule->pagestyleCO->currentText());
307 switch (dialog_->textLayoutModule->lspacingCO->currentItem()) {
309 params.spacing().set(Spacing::Single);
312 params.spacing().set(Spacing::Onehalf);
315 params.spacing().set(Spacing::Double);
318 params.spacing().set(Spacing::Other,
319 fromqstr(dialog_->textLayoutModule->lspacingLE->text()));
323 if (dialog_->textLayoutModule->twoColumnCB->isChecked())
328 if (dialog_->textLayoutModule->indentRB->isChecked())
329 params.paragraph_separation = BufferParams::PARSEP_INDENT;
331 params.paragraph_separation = BufferParams::PARSEP_SKIP;
333 switch (dialog_->textLayoutModule->skipCO->currentItem()) {
335 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
338 params.setDefSkip(VSpace(VSpace::MEDSKIP));
341 params.setDefSkip(VSpace(VSpace::BIGSKIP));
346 widgetsToLength(dialog_->textLayoutModule->skipLE,
347 dialog_->textLayoutModule->skipLengthCO)
349 params.setDefSkip(vs);
353 // DocumentDefskipCB assures that this never happens
354 // so Assert then !!! - jbl
355 params.setDefSkip(VSpace(VSpace::MEDSKIP));
360 fromqstr(dialog_->latexModule->optionsLE->text());
362 params.float_placement = dialog_->floatModule->get();
365 params.papersize2 = VMARGIN_PAPER_TYPE(
366 dialog_->pageLayoutModule->papersizeCO->currentItem());
368 // custom, A3, B3 and B4 paper sizes need geometry
369 int psize = dialog_->pageLayoutModule->papersizeCO->currentItem();
370 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
372 params.paperwidth = widgetsToLength(dialog_->pageLayoutModule->paperwidthLE,
373 dialog_->pageLayoutModule->paperwidthUnitCO);
375 params.paperheight = widgetsToLength(dialog_->pageLayoutModule->paperheightLE,
376 dialog_->pageLayoutModule->paperheightUnitCO);
378 if (dialog_->pageLayoutModule->facingPagesCB->isChecked())
379 params.sides = LyXTextClass::TwoSides;
381 params.sides = LyXTextClass::OneSide;
383 if (dialog_->pageLayoutModule->landscapeRB->isChecked())
384 params.orientation = ORIENTATION_LANDSCAPE;
386 params.orientation = ORIENTATION_PORTRAIT;
389 params.use_geometry =
390 (dialog_->marginsModule->marginCO->currentItem() == 1
393 int margin = dialog_->marginsModule->marginCO->currentItem();
397 params.paperpackage = PAPER_PACKAGES(margin);
399 // set params.papersize from params.papersize2
400 // and params.paperpackage
401 params.setPaperStuff();
403 MarginsModuleBase const * m(dialog_->marginsModule);
405 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
407 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
409 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
411 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
413 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
415 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
417 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
419 params.branchlist() = branchlist_;
425 /** Return the position of val in the vector if found.
426 If not found, return 0.
429 typename std::vector<A>::size_type
430 findPos(std::vector<A> const & vec, A const & val)
432 typename std::vector<A>::const_iterator it =
433 std::find(vec.begin(), vec.end(), val);
436 return distance(vec.begin(), it);
442 void QDocument::update_contents()
447 BufferParams const & params = controller().params();
449 // set the default unit
450 // FIXME: move to controller
451 LyXLength::UNIT defaultUnit = LyXLength::CM;
452 switch (lyxrc.default_papersize) {
453 case PAPER_DEFAULT: break;
456 case PAPER_LEGALPAPER:
457 case PAPER_EXECUTIVEPAPER:
458 defaultUnit = LyXLength::IN;
465 defaultUnit = LyXLength::CM;
470 QString preamble = toqstr(params.preamble);
471 dialog_->preambleModule->preambleMLE->setText(preamble);
474 dialog_->biblioModule->citeDefaultRB->setChecked(
475 params.cite_engine == biblio::ENGINE_BASIC);
477 dialog_->biblioModule->citeNatbibRB->setChecked(
478 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
479 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
481 dialog_->biblioModule->citeStyleCO->setCurrentItem(
482 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
484 dialog_->biblioModule->citeJurabibRB->setChecked(
485 params.cite_engine == biblio::ENGINE_JURABIB);
487 dialog_->biblioModule->bibtopicCB->setChecked(
488 params.use_bibtopic);
491 int const pos = int(findPos(lang_,
492 params.language->lang()));
493 dialog_->langModule->languageCO->setCurrentItem(pos);
495 dialog_->langModule->quoteStyleCO->setCurrentItem(
496 params.quotes_language);
498 dialog_->langModule->defaultencodingCB->setChecked(true);
500 if (params.inputenc != "auto") {
501 dialog_->langModule->defaultencodingCB->setChecked(false);
502 if (params.inputenc == "default") {
503 dialog_->langModule->encodingCO->setCurrentItem(0);
506 while (encodings[i]) {
507 if (encodings[i] == params.inputenc)
508 dialog_->langModule->encodingCO->setCurrentItem(i);
515 dialog_->numberingModule->tocSL->setValue(params.tocdepth);
516 dialog_->numberingModule->depthSL->setValue(params.secnumdepth);
517 dialog_->updateNumbering();
520 dialog_->bulletsModule->setBullet(0,params.user_defined_bullet(0));
521 dialog_->bulletsModule->setBullet(1,params.user_defined_bullet(1));
522 dialog_->bulletsModule->setBullet(2,params.user_defined_bullet(2));
523 dialog_->bulletsModule->setBullet(3,params.user_defined_bullet(3));
526 QString text = toqstr(params.graphicsDriver);
527 int nitem = dialog_->latexModule->psdriverCO->count();
528 for (int n = 0; n < nitem ; ++n) {
529 QString enc = tex_graphics[n];
531 dialog_->latexModule->psdriverCO->setCurrentItem(n);
536 dialog_->mathsModule->amsCB->setChecked(
537 params.use_amsmath == BufferParams::AMS_ON);
538 dialog_->mathsModule->amsautoCB->setChecked(
539 params.use_amsmath == BufferParams::AMS_AUTO);
541 switch (params.spacing().getSpace()) {
542 case Spacing::Other: nitem = 3; break;
543 case Spacing::Double: nitem = 2; break;
544 case Spacing::Onehalf: nitem = 1; break;
545 case Spacing::Default: case Spacing::Single: nitem = 0; break;
550 dialog_->latexModule->classCO->setCurrentItem(params.textclass);
552 dialog_->updateFontsize(controller().textClass().opt_fontsize(),
555 dialog_->updatePagestyle(controller().textClass().opt_pagestyle(),
558 for (int n = 0; tex_fonts[n][0]; ++n) {
559 if (tex_fonts[n] == params.fonts) {
560 dialog_->textLayoutModule->fontsCO->setCurrentItem(n);
565 dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
566 if (params.spacing().getSpace() == Spacing::Other) {
567 dialog_->textLayoutModule->lspacingLE->setText(
568 toqstr(params.spacing().getValueAsString()));
570 dialog_->setLSpacing(nitem);
572 if (params.paragraph_separation
573 == BufferParams::PARSEP_INDENT) {
574 dialog_->textLayoutModule->indentRB->setChecked(true);
576 dialog_->textLayoutModule->skipRB->setChecked(true);
580 switch (params.getDefSkip().kind()) {
581 case VSpace::SMALLSKIP:
584 case VSpace::MEDSKIP:
587 case VSpace::BIGSKIP:
593 string const length = params.getDefSkip().asLyXCommand();
594 lengthToWidgets(dialog_->textLayoutModule->skipLE,
595 dialog_->textLayoutModule->skipLengthCO,
596 length, defaultUnit);
603 dialog_->textLayoutModule->skipCO->setCurrentItem(skip);
604 dialog_->setSkip(skip);
606 dialog_->textLayoutModule->twoColumnCB->setChecked(
607 params.columns == 2);
609 if (!params.options.empty()) {
610 dialog_->latexModule->optionsLE->setText(
611 toqstr(params.options));
613 dialog_->latexModule->optionsLE->setText("");
616 dialog_->floatModule->set(params.float_placement);
619 int const psize = params.papersize2;
620 dialog_->pageLayoutModule->papersizeCO->setCurrentItem(psize);
621 dialog_->setMargins(psize);
622 dialog_->setCustomPapersize(psize);
624 bool const landscape =
625 params.orientation == ORIENTATION_LANDSCAPE;
626 dialog_->pageLayoutModule->landscapeRB->setChecked(landscape);
627 dialog_->pageLayoutModule->portraitRB->setChecked(!landscape);
629 dialog_->pageLayoutModule->facingPagesCB->setChecked(
630 params.sides == LyXTextClass::TwoSides);
634 lengthToWidgets(dialog_->pageLayoutModule->paperwidthLE,
635 dialog_->pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
637 lengthToWidgets(dialog_->pageLayoutModule->paperheightLE,
638 dialog_->pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
642 MarginsModuleBase * m = dialog_->marginsModule;
644 int item = params.paperpackage;
645 if (params.use_geometry) {
647 } else if (item > 0) {
650 m->marginCO->setCurrentItem(item);
651 dialog_->setCustomMargins(item);
653 lengthToWidgets(m->topLE, m->topUnit,
654 params.topmargin, defaultUnit);
656 lengthToWidgets(m->bottomLE, m->bottomUnit,
657 params.bottommargin, defaultUnit);
659 lengthToWidgets(m->innerLE, m->innerUnit,
660 params.leftmargin, defaultUnit);
662 lengthToWidgets(m->outerLE, m->outerUnit,
663 params.rightmargin, defaultUnit);
665 lengthToWidgets(m->headheightLE, m->headheightUnit,
666 params.headheight, defaultUnit);
668 lengthToWidgets(m->headsepLE, m->headsepUnit,
669 params.headsep, defaultUnit);
671 lengthToWidgets(m->footskipLE, m->footskipUnit,
672 params.footskip, defaultUnit);
675 branchlist_ = params.branchlist();
676 dialog_->updateBranchView();
680 void QDocument::saveDocDefault()
682 // we have to apply the params first
684 controller().saveAsDefault();
688 void QDocument::useClassDefaults()
690 BufferParams & params = controller().params();
692 params.textclass = dialog_->latexModule->classCO->currentItem();
693 params.useClassDefaults();
697 } // namespace frontend