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/lstrings.h"
30 #include "controllers/ControlDocument.h"
31 #include "controllers/frnt_lang.h"
33 #include <qpushbutton.h>
34 #include <qmultilineedit.h>
35 #include <qradiobutton.h>
36 #include <qcheckbox.h>
39 #include <qlineedit.h>
40 #include <qlistview.h>
41 #include "lengthcombo.h"
44 using lyx::support::bformat;
45 using lyx::support::findToken;
46 using lyx::support::getVectorFromString;
55 typedef QController<ControlDocument, QView<QDocumentDialog> > base_class;
60 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
61 "latin3", "latin4", "latin5", "latin9",
62 "koi8-r", "koi8-u", "cp866", "cp1251",
63 "iso88595", "pt154", 0
69 QDocument::QDocument(Dialog & parent)
70 : base_class(parent, _("Document Settings")),
71 lang_(getSecond(getLanguageData(false)))
75 void QDocument::build_dialog()
77 dialog_.reset(new QDocumentDialog(this));
80 dialog_->biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
81 dialog_->biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
82 dialog_->biblioModule->citeStyleCO->setCurrentItem(0);
85 vector<LanguagePair> const langs = getLanguageData(false);
86 vector<LanguagePair>::const_iterator lit = langs.begin();
87 vector<LanguagePair>::const_iterator lend = langs.end();
88 for (; lit != lend; ++lit) {
89 dialog_->langModule->languageCO->insertItem(
94 while (encodings[i]) {
95 dialog_->langModule->encodingCO->insertItem(qt_(encodings[i++]));
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''"));
102 dialog_->langModule->quoteStyleCO->insertItem(qt_("<<text>>"));
103 dialog_->langModule->quoteStyleCO->insertItem(qt_(">>text<<"));
106 for (int n = 0; tex_graphics[n][0]; ++n) {
107 QString enc = tex_graphics[n];
108 dialog_->latexModule->psdriverCO->insertItem(enc);
112 QComboBox * cb = dialog_->pageLayoutModule->papersizeCO;
113 cb->insertItem(qt_("Default"));
114 cb->insertItem(qt_("Custom"));
115 cb->insertItem(qt_("US letter"));
116 cb->insertItem(qt_("US legal"));
117 cb->insertItem(qt_("US executive"));
118 cb->insertItem(qt_("A3"));
119 cb->insertItem(qt_("A4"));
120 cb->insertItem(qt_("A5"));
121 cb->insertItem(qt_("B3"));
122 cb->insertItem(qt_("B4"));
123 cb->insertItem(qt_("B5"));
124 // remove the %-items from the unit choice
125 dialog_->pageLayoutModule->paperwidthUnitCO->noPercents();
126 dialog_->pageLayoutModule->paperheightUnitCO->noPercents();
129 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
130 cit != textclasslist.end(); ++cit) {
131 if (cit->isTeXClassAvailable()) {
132 dialog_->latexModule->classCO->insertItem(toqstr(cit->description()));
135 bformat(_("Unavailable: %1$s"), lyx::from_utf8(cit->description()));
136 dialog_->latexModule->classCO->insertItem(toqstr(item));
140 dialog_->textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
141 dialog_->textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
142 dialog_->textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
143 dialog_->textLayoutModule->skipCO->insertItem(qt_("Length"));
144 // remove the %-items from the unit choice
145 dialog_->textLayoutModule->skipLengthCO->noPercents();
148 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
149 QString font = toqstr(tex_fonts_roman_gui[n]);
150 if (!controller().isFontAvailable(tex_fonts_roman[n]))
151 font += qt_(" (not installed)");
152 dialog_->fontModule->fontsRomanCO->insertItem(font);
154 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
155 QString font = toqstr(tex_fonts_sans_gui[n]);
156 if (!controller().isFontAvailable(tex_fonts_sans[n]))
157 font += qt_(" (not installed)");
158 dialog_->fontModule->fontsSansCO->insertItem(font);
160 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
161 QString font = toqstr(tex_fonts_monospaced_gui[n]);
162 if (!controller().isFontAvailable(tex_fonts_monospaced[n]))
163 font += qt_(" (not installed)");
164 dialog_->fontModule->fontsTypewriterCO->insertItem(font);
167 for (int n = 0; ControlDocument::fontfamilies_gui[n][0]; ++n)
168 dialog_->fontModule->fontsDefaultCO->insertItem(
169 qt_(ControlDocument::fontfamilies_gui[n]));
171 dialog_->fontModule->fontsizeCO->insertItem(qt_("default"));
172 dialog_->fontModule->fontsizeCO->insertItem(qt_("10"));
173 dialog_->fontModule->fontsizeCO->insertItem(qt_("11"));
174 dialog_->fontModule->fontsizeCO->insertItem(qt_("12"));
177 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
178 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
179 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
180 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
181 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
183 dialog_->textLayoutModule->lspacingCO->insertItem(
184 qt_("Single"), Spacing::Single);
185 dialog_->textLayoutModule->lspacingCO->insertItem(
186 qt_("OneHalf"), Spacing::Onehalf);
187 dialog_->textLayoutModule->lspacingCO->insertItem(
188 qt_("Double"), Spacing::Double);
189 dialog_->textLayoutModule->lspacingCO->insertItem(
190 qt_("Custom"), Spacing::Other);
193 // Manage the restore, ok, apply, restore and cancel/close buttons
194 bcview().setOK(dialog_->okPB);
195 bcview().setApply(dialog_->applyPB);
196 bcview().setCancel(dialog_->closePB);
197 bcview().setRestore(dialog_->restorePB);
199 // initialize the length validator
200 addCheckedLineEdit(bcview(), dialog_->textLayoutModule->skipLE);
201 addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperheightLE,
202 dialog_->pageLayoutModule->paperheightL);
203 addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperwidthLE,
204 dialog_->pageLayoutModule->paperwidthL);
205 addCheckedLineEdit(bcview(), dialog_->marginsModule->topLE,
206 dialog_->marginsModule->topL);
207 addCheckedLineEdit(bcview(), dialog_->marginsModule->bottomLE,
208 dialog_->marginsModule->bottomL);
209 addCheckedLineEdit(bcview(), dialog_->marginsModule->innerLE,
210 dialog_->marginsModule->innerL);
211 addCheckedLineEdit(bcview(), dialog_->marginsModule->outerLE,
212 dialog_->marginsModule->outerL);
213 addCheckedLineEdit(bcview(), dialog_->marginsModule->headsepLE,
214 dialog_->marginsModule->headsepL);
215 addCheckedLineEdit(bcview(), dialog_->marginsModule->headheightLE,
216 dialog_->marginsModule->headheightL);
217 addCheckedLineEdit(bcview(), dialog_->marginsModule->footskipLE,
218 dialog_->marginsModule->footskipL);
222 void QDocument::showPreamble()
224 dialog_->showPreamble();
228 void QDocument::apply()
230 BufferParams & params = controller().params();
234 fromqstr(dialog_->preambleModule->preambleMLE->text());
237 params.cite_engine = biblio::ENGINE_BASIC;
239 if (dialog_->biblioModule->citeNatbibRB->isChecked()) {
240 bool const use_numerical_citations =
241 dialog_->biblioModule->citeStyleCO->currentItem();
242 if (use_numerical_citations)
243 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
245 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
247 } else if (dialog_->biblioModule->citeJurabibRB->isChecked())
248 params.cite_engine = biblio::ENGINE_JURABIB;
250 params.use_bibtopic =
251 dialog_->biblioModule->bibtopicCB->isChecked();
254 if (dialog_->langModule->defaultencodingCB->isChecked()) {
255 params.inputenc = "auto";
257 int i = dialog_->langModule->encodingCO->currentItem();
259 params.inputenc = "default";
261 params.inputenc = encodings[i];
265 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
266 switch (dialog_->langModule->quoteStyleCO->currentItem()) {
268 lga = InsetQuotes::EnglishQ;
271 lga = InsetQuotes::SwedishQ;
274 lga = InsetQuotes::GermanQ;
277 lga = InsetQuotes::PolishQ;
280 lga = InsetQuotes::FrenchQ;
283 lga = InsetQuotes::DanishQ;
286 params.quotes_language = lga;
288 int const pos = dialog_->langModule->languageCO->currentItem();
289 params.language = languages.getLanguage(lang_[pos]);
292 if (params.getLyXTextClass().hasTocLevels()) {
293 params.tocdepth = dialog_->numberingModule->tocSL->value();
294 params.secnumdepth = dialog_->numberingModule->depthSL->value();
298 params.user_defined_bullet(0) = dialog_->bulletsModule->getBullet(0);
299 params.user_defined_bullet(1) = dialog_->bulletsModule->getBullet(1);
300 params.user_defined_bullet(2) = dialog_->bulletsModule->getBullet(2);
301 params.user_defined_bullet(3) = dialog_->bulletsModule->getBullet(3);
304 params.graphicsDriver =
305 fromqstr(dialog_->latexModule->psdriverCO->currentText());
307 if (dialog_->mathsModule->amsautoCB->isChecked()) {
308 params.use_amsmath = BufferParams::AMS_AUTO;
310 if (dialog_->mathsModule->amsCB->isChecked())
311 params.use_amsmath = BufferParams::AMS_ON;
313 params.use_amsmath = BufferParams::AMS_OFF;
318 dialog_->latexModule->classCO->currentItem();
321 fromqstr(dialog_->pageLayoutModule->pagestyleCO->currentText());
323 switch (dialog_->textLayoutModule->lspacingCO->currentItem()) {
325 params.spacing().set(Spacing::Single);
328 params.spacing().set(Spacing::Onehalf);
331 params.spacing().set(Spacing::Double);
334 params.spacing().set(Spacing::Other,
335 fromqstr(dialog_->textLayoutModule->lspacingLE->text()));
339 if (dialog_->textLayoutModule->twoColumnCB->isChecked())
344 if (dialog_->textLayoutModule->indentRB->isChecked())
345 params.paragraph_separation = BufferParams::PARSEP_INDENT;
347 params.paragraph_separation = BufferParams::PARSEP_SKIP;
349 switch (dialog_->textLayoutModule->skipCO->currentItem()) {
351 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
354 params.setDefSkip(VSpace(VSpace::MEDSKIP));
357 params.setDefSkip(VSpace(VSpace::BIGSKIP));
362 widgetsToLength(dialog_->textLayoutModule->skipLE,
363 dialog_->textLayoutModule->skipLengthCO)
365 params.setDefSkip(vs);
369 // DocumentDefskipCB assures that this never happens
370 // so Assert then !!! - jbl
371 params.setDefSkip(VSpace(VSpace::MEDSKIP));
376 fromqstr(dialog_->latexModule->optionsLE->text());
378 params.float_placement = dialog_->floatModule->get();
382 tex_fonts_roman[dialog_->fontModule->fontsRomanCO->currentItem()];
385 tex_fonts_sans[dialog_->fontModule->fontsSansCO->currentItem()];
387 params.fontsTypewriter =
388 tex_fonts_monospaced[dialog_->fontModule->fontsTypewriterCO->currentItem()];
390 params.fontsSansScale = dialog_->fontModule->scaleSansSB->value();
392 params.fontsTypewriterScale = dialog_->fontModule->scaleTypewriterSB->value();
394 params.fontsSC = dialog_->fontModule->fontScCB->isChecked();
396 params.fontsOSF = dialog_->fontModule->fontOsfCB->isChecked();
398 params.fontsDefaultFamily =
399 ControlDocument::fontfamilies[
400 dialog_->fontModule->fontsDefaultCO->currentItem()];
402 if (dialog_->fontModule->fontsizeCO->currentItem() == 0)
403 params.fontsize = "default";
406 fromqstr(dialog_->fontModule->fontsizeCO->currentText());
409 params.papersize = PAPER_SIZE(
410 dialog_->pageLayoutModule->papersizeCO->currentItem());
412 // custom, A3, B3 and B4 paper sizes need geometry
413 int psize = dialog_->pageLayoutModule->papersizeCO->currentItem();
414 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
416 params.paperwidth = widgetsToLength(dialog_->pageLayoutModule->paperwidthLE,
417 dialog_->pageLayoutModule->paperwidthUnitCO);
419 params.paperheight = widgetsToLength(dialog_->pageLayoutModule->paperheightLE,
420 dialog_->pageLayoutModule->paperheightUnitCO);
422 if (dialog_->pageLayoutModule->facingPagesCB->isChecked())
423 params.sides = LyXTextClass::TwoSides;
425 params.sides = LyXTextClass::OneSide;
427 if (dialog_->pageLayoutModule->landscapeRB->isChecked())
428 params.orientation = ORIENTATION_LANDSCAPE;
430 params.orientation = ORIENTATION_PORTRAIT;
433 params.use_geometry =
434 (!dialog_->marginsModule->marginCB->isChecked()
437 MarginsModuleBase const * m(dialog_->marginsModule);
439 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
441 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
443 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
445 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
447 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
449 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
451 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
453 params.branchlist() = branchlist_;
459 /** Return the position of val in the vector if found.
460 If not found, return 0.
463 typename std::vector<A>::size_type
464 findPos(std::vector<A> const & vec, A const & val)
466 typename std::vector<A>::const_iterator it =
467 std::find(vec.begin(), vec.end(), val);
470 return distance(vec.begin(), it);
476 void QDocument::update_contents()
481 BufferParams const & params = controller().params();
483 // set the default unit
484 // FIXME: move to controller
485 LyXLength::UNIT defaultUnit = LyXLength::CM;
486 switch (lyxrc.default_papersize) {
487 case PAPER_DEFAULT: break;
491 case PAPER_USEXECUTIVE:
492 defaultUnit = LyXLength::IN;
501 defaultUnit = LyXLength::CM;
508 QString preamble = toqstr(params.preamble);
509 dialog_->preambleModule->preambleMLE->setText(preamble);
512 dialog_->biblioModule->citeDefaultRB->setChecked(
513 params.cite_engine == biblio::ENGINE_BASIC);
515 dialog_->biblioModule->citeNatbibRB->setChecked(
516 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
517 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
519 dialog_->biblioModule->citeStyleCO->setCurrentItem(
520 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
522 dialog_->biblioModule->citeJurabibRB->setChecked(
523 params.cite_engine == biblio::ENGINE_JURABIB);
525 dialog_->biblioModule->bibtopicCB->setChecked(
526 params.use_bibtopic);
529 int const pos = int(findPos(lang_,
530 params.language->lang()));
531 dialog_->langModule->languageCO->setCurrentItem(pos);
533 dialog_->langModule->quoteStyleCO->setCurrentItem(
534 params.quotes_language);
536 dialog_->langModule->defaultencodingCB->setChecked(true);
538 if (params.inputenc != "auto") {
539 dialog_->langModule->defaultencodingCB->setChecked(false);
540 if (params.inputenc == "default") {
541 dialog_->langModule->encodingCO->setCurrentItem(0);
544 while (encodings[i]) {
545 if (encodings[i] == params.inputenc)
546 dialog_->langModule->encodingCO->setCurrentItem(i);
553 int const min_toclevel = controller().textClass().min_toclevel();
554 int const max_toclevel = controller().textClass().max_toclevel();
555 if (controller().textClass().hasTocLevels()) {
556 dialog_->numberingModule->setEnabled(true);
557 dialog_->numberingModule->depthSL->setMinValue(min_toclevel - 1);
558 dialog_->numberingModule->depthSL->setMaxValue(max_toclevel);
559 dialog_->numberingModule->depthSL->setValue(params.secnumdepth);
560 dialog_->numberingModule->tocSL->setMinValue(min_toclevel - 1);
561 dialog_->numberingModule->tocSL->setMaxValue(max_toclevel);
562 dialog_->numberingModule->tocSL->setValue(params.tocdepth);
563 dialog_->updateNumbering();
565 dialog_->numberingModule->setEnabled(false);
566 dialog_->numberingModule->tocLV->clear();
570 dialog_->bulletsModule->setBullet(0,params.user_defined_bullet(0));
571 dialog_->bulletsModule->setBullet(1,params.user_defined_bullet(1));
572 dialog_->bulletsModule->setBullet(2,params.user_defined_bullet(2));
573 dialog_->bulletsModule->setBullet(3,params.user_defined_bullet(3));
576 QString text = toqstr(params.graphicsDriver);
577 int nitem = dialog_->latexModule->psdriverCO->count();
578 for (int n = 0; n < nitem ; ++n) {
579 QString enc = tex_graphics[n];
581 dialog_->latexModule->psdriverCO->setCurrentItem(n);
586 dialog_->mathsModule->amsCB->setChecked(
587 params.use_amsmath == BufferParams::AMS_ON);
588 dialog_->mathsModule->amsautoCB->setChecked(
589 params.use_amsmath == BufferParams::AMS_AUTO);
591 switch (params.spacing().getSpace()) {
592 case Spacing::Other: nitem = 3; break;
593 case Spacing::Double: nitem = 2; break;
594 case Spacing::Onehalf: nitem = 1; break;
595 case Spacing::Default: case Spacing::Single: nitem = 0; break;
599 dialog_->latexModule->classCO->setCurrentItem(params.textclass);
601 dialog_->updatePagestyle(controller().textClass().opt_pagestyle(),
604 dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
605 if (params.spacing().getSpace() == Spacing::Other) {
606 dialog_->textLayoutModule->lspacingLE->setText(
607 toqstr(params.spacing().getValueAsString()));
609 dialog_->setLSpacing(nitem);
611 if (params.paragraph_separation
612 == BufferParams::PARSEP_INDENT) {
613 dialog_->textLayoutModule->indentRB->setChecked(true);
615 dialog_->textLayoutModule->skipRB->setChecked(true);
619 switch (params.getDefSkip().kind()) {
620 case VSpace::SMALLSKIP:
623 case VSpace::MEDSKIP:
626 case VSpace::BIGSKIP:
632 string const length = params.getDefSkip().asLyXCommand();
633 lengthToWidgets(dialog_->textLayoutModule->skipLE,
634 dialog_->textLayoutModule->skipLengthCO,
635 length, defaultUnit);
642 dialog_->textLayoutModule->skipCO->setCurrentItem(skip);
643 dialog_->setSkip(skip);
645 dialog_->textLayoutModule->twoColumnCB->setChecked(
646 params.columns == 2);
648 if (!params.options.empty()) {
649 dialog_->latexModule->optionsLE->setText(
650 toqstr(params.options));
652 dialog_->latexModule->optionsLE->setText("");
655 dialog_->floatModule->set(params.float_placement);
658 dialog_->updateFontsize(controller().textClass().opt_fontsize(),
661 int n = findToken(tex_fonts_roman, params.fontsRoman);
663 dialog_->fontModule->fontsRomanCO->setCurrentItem(n);
665 n = findToken(tex_fonts_sans, params.fontsSans);
667 dialog_->fontModule->fontsSansCO->setCurrentItem(n);
669 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
671 dialog_->fontModule->fontsTypewriterCO->setCurrentItem(n);
673 dialog_->fontModule->fontScCB->setChecked(params.fontsSC);
674 dialog_->fontModule->fontOsfCB->setChecked(params.fontsOSF);
675 dialog_->fontModule->fontScCB->setEnabled(
676 controller().providesSC(params.fontsRoman));
677 dialog_->fontModule->fontOsfCB->setEnabled(
678 controller().providesOSF(params.fontsRoman));
679 dialog_->fontModule->scaleSansSB->setValue(params.fontsSansScale);
680 dialog_->fontModule->scaleTypewriterSB->setValue(
681 params.fontsTypewriterScale);
682 dialog_->fontModule->scaleSansSB->setEnabled(
683 controller().providesScale(params.fontsSans));
684 dialog_->fontModule->scaleTypewriterSB->setEnabled(
685 controller().providesScale(params.fontsTypewriter));
687 n = findToken(ControlDocument::fontfamilies, params.fontsDefaultFamily);
689 dialog_->fontModule->fontsDefaultCO->setCurrentItem(n);
692 int const psize = params.papersize;
693 dialog_->pageLayoutModule->papersizeCO->setCurrentItem(psize);
694 dialog_->setCustomPapersize(psize);
697 MarginsModuleBase * m = dialog_->marginsModule;
699 dialog_->setMargins(!params.use_geometry);
701 lengthToWidgets(m->topLE, m->topUnit,
702 params.topmargin, defaultUnit);
704 lengthToWidgets(m->bottomLE, m->bottomUnit,
705 params.bottommargin, defaultUnit);
707 lengthToWidgets(m->innerLE, m->innerUnit,
708 params.leftmargin, defaultUnit);
710 lengthToWidgets(m->outerLE, m->outerUnit,
711 params.rightmargin, defaultUnit);
713 lengthToWidgets(m->headheightLE, m->headheightUnit,
714 params.headheight, defaultUnit);
716 lengthToWidgets(m->headsepLE, m->headsepUnit,
717 params.headsep, defaultUnit);
719 lengthToWidgets(m->footskipLE, m->footskipUnit,
720 params.footskip, defaultUnit);
723 branchlist_ = params.branchlist();
724 dialog_->updateBranchView();
728 void QDocument::saveDocDefault()
730 // we have to apply the params first
732 controller().saveAsDefault();
736 void QDocument::useClassDefaults()
738 BufferParams & params = controller().params();
740 params.textclass = dialog_->latexModule->classCO->currentItem();
741 params.useClassDefaults();
745 } // namespace frontend