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>
38 #include <qlineedit.h>
39 #include "lengthcombo.h"
42 using lyx::support::bformat;
43 using lyx::support::getVectorFromString;
52 typedef QController<ControlDocument, QView<QDocumentDialog> > base_class;
57 char const * encodings[] = { "LaTeX default", "latin1", "latin2",
58 "latin3", "latin4", "latin5", "latin9",
59 "koi8-r", "koi8-u", "cp866", "cp1251",
60 "iso88595", "pt154", 0
66 QDocument::QDocument(Dialog & parent)
67 : base_class(parent, _("LyX: Document Settings")),
68 lang_(getSecond(getLanguageData(false)))
72 void QDocument::build_dialog()
74 dialog_.reset(new QDocumentDialog(this));
77 dialog_->biblioModule->citeStyleCO->insertItem(qt_("Author-year"));
78 dialog_->biblioModule->citeStyleCO->insertItem(qt_("Numerical"));
79 dialog_->biblioModule->citeStyleCO->setCurrentItem(0);
82 vector<LanguagePair> const langs = getLanguageData(false);
83 vector<LanguagePair>::const_iterator lit = langs.begin();
84 vector<LanguagePair>::const_iterator lend = langs.end();
85 for (; lit != lend; ++lit) {
86 dialog_->langModule->languageCO->insertItem(
91 while (encodings[i]) {
92 dialog_->langModule->encodingCO->insertItem(qt_(encodings[i++]));
95 dialog_->langModule->quoteStyleCO->insertItem(qt_("``text''"));
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<<"));
103 for (int n = 0; tex_graphics[n][0]; ++n) {
104 QString enc = tex_graphics[n];
105 dialog_->latexModule->psdriverCO->insertItem(enc);
109 QComboBox * cb = dialog_->pageLayoutModule->papersizeCO;
110 cb->insertItem(qt_("Default"));
111 cb->insertItem(qt_("Custom"));
112 cb->insertItem(qt_("US letter"));
113 cb->insertItem(qt_("US legal"));
114 cb->insertItem(qt_("US executive"));
115 cb->insertItem(qt_("A3"));
116 cb->insertItem(qt_("A4"));
117 cb->insertItem(qt_("A5"));
118 cb->insertItem(qt_("B3"));
119 cb->insertItem(qt_("B4"));
120 cb->insertItem(qt_("B5"));
121 // remove the %-items from the unit choice
122 dialog_->pageLayoutModule->paperwidthUnitCO->noPercents();
123 dialog_->pageLayoutModule->paperheightUnitCO->noPercents();
126 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
127 cit != textclasslist.end(); ++cit) {
128 if (cit->isTeXClassAvailable()) {
129 dialog_->latexModule->classCO->insertItem(toqstr(cit->description()));
132 bformat(_("Unavailable: %1$s"), cit->description());
133 dialog_->latexModule->classCO->insertItem(toqstr(item));
137 for (int n = 0; tex_fonts[n][0]; ++n) {
138 QString font = tex_fonts[n];
139 dialog_->textLayoutModule->fontsCO->insertItem(font);
142 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("default"));
143 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("10"));
144 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("11"));
145 dialog_->textLayoutModule->fontsizeCO->insertItem(qt_("12"));
147 dialog_->textLayoutModule->skipCO->insertItem(qt_("SmallSkip"));
148 dialog_->textLayoutModule->skipCO->insertItem(qt_("MedSkip"));
149 dialog_->textLayoutModule->skipCO->insertItem(qt_("BigSkip"));
150 dialog_->textLayoutModule->skipCO->insertItem(qt_("Length"));
151 // remove the %-items from the unit choice
152 dialog_->textLayoutModule->skipLengthCO->noPercents();
154 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("default"));
155 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("empty"));
156 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("plain"));
157 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("headings"));
158 dialog_->pageLayoutModule->pagestyleCO->insertItem(qt_("fancy"));
160 dialog_->textLayoutModule->lspacingCO->insertItem(
161 qt_("Single"), Spacing::Single);
162 dialog_->textLayoutModule->lspacingCO->insertItem(
163 qt_("OneHalf"), Spacing::Onehalf);
164 dialog_->textLayoutModule->lspacingCO->insertItem(
165 qt_("Double"), Spacing::Double);
166 dialog_->textLayoutModule->lspacingCO->insertItem(
167 qt_("Custom"), Spacing::Other);
170 dialog_->setMargins(0);
172 // Manage the restore, ok, apply, restore and cancel/close buttons
173 bcview().setOK(dialog_->okPB);
174 bcview().setApply(dialog_->applyPB);
175 bcview().setCancel(dialog_->closePB);
176 bcview().setRestore(dialog_->restorePB);
178 // initialize the length validator
179 addCheckedLineEdit(bcview(), dialog_->textLayoutModule->skipLE);
180 addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperheightLE,
181 dialog_->pageLayoutModule->paperheightL);
182 addCheckedLineEdit(bcview(), dialog_->pageLayoutModule->paperwidthLE,
183 dialog_->pageLayoutModule->paperwidthL);
184 addCheckedLineEdit(bcview(), dialog_->marginsModule->topLE,
185 dialog_->marginsModule->topL);
186 addCheckedLineEdit(bcview(), dialog_->marginsModule->bottomLE,
187 dialog_->marginsModule->bottomL);
188 addCheckedLineEdit(bcview(), dialog_->marginsModule->innerLE,
189 dialog_->marginsModule->innerL);
190 addCheckedLineEdit(bcview(), dialog_->marginsModule->outerLE,
191 dialog_->marginsModule->outerL);
192 addCheckedLineEdit(bcview(), dialog_->marginsModule->headsepLE,
193 dialog_->marginsModule->headsepL);
194 addCheckedLineEdit(bcview(), dialog_->marginsModule->headheightLE,
195 dialog_->marginsModule->headheightL);
196 addCheckedLineEdit(bcview(), dialog_->marginsModule->footskipLE,
197 dialog_->marginsModule->footskipL);
201 void QDocument::showPreamble()
203 dialog_->showPreamble();
207 void QDocument::apply()
209 BufferParams & params = controller().params();
213 fromqstr(dialog_->preambleModule->preambleMLE->text());
216 params.cite_engine = biblio::ENGINE_BASIC;
218 if (dialog_->biblioModule->citeNatbibRB->isChecked()) {
219 bool const use_numerical_citations =
220 dialog_->biblioModule->citeStyleCO->currentItem();
221 if (use_numerical_citations)
222 params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
224 params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
226 } else if (dialog_->biblioModule->citeJurabibRB->isChecked())
227 params.cite_engine = biblio::ENGINE_JURABIB;
229 params.use_bibtopic =
230 dialog_->biblioModule->bibtopicCB->isChecked();
233 if (dialog_->langModule->defaultencodingCB->isChecked()) {
234 params.inputenc = "auto";
236 int i = dialog_->langModule->encodingCO->currentItem();
238 params.inputenc = "default";
240 params.inputenc = encodings[i];
244 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
245 switch (dialog_->langModule->quoteStyleCO->currentItem()) {
247 lga = InsetQuotes::EnglishQ;
250 lga = InsetQuotes::SwedishQ;
253 lga = InsetQuotes::GermanQ;
256 lga = InsetQuotes::PolishQ;
259 lga = InsetQuotes::FrenchQ;
262 lga = InsetQuotes::DanishQ;
265 params.quotes_language = lga;
267 int const pos = dialog_->langModule->languageCO->currentItem();
268 params.language = languages.getLanguage(lang_[pos]);
271 params.tocdepth = dialog_->numberingModule->tocSL->value();
272 params.secnumdepth = dialog_->numberingModule->depthSL->value();
275 params.user_defined_bullet(0) = dialog_->bulletsModule->getBullet(0);
276 params.user_defined_bullet(1) = dialog_->bulletsModule->getBullet(1);
277 params.user_defined_bullet(2) = dialog_->bulletsModule->getBullet(2);
278 params.user_defined_bullet(3) = dialog_->bulletsModule->getBullet(3);
281 params.graphicsDriver =
282 fromqstr(dialog_->latexModule->psdriverCO->currentText());
284 if (dialog_->mathsModule->amsautoCB->isChecked()) {
285 params.use_amsmath = BufferParams::AMS_AUTO;
287 if (dialog_->mathsModule->amsCB->isChecked())
288 params.use_amsmath = BufferParams::AMS_ON;
290 params.use_amsmath = BufferParams::AMS_OFF;
295 dialog_->latexModule->classCO->currentItem();
298 fromqstr(dialog_->textLayoutModule->fontsCO->currentText());
301 fromqstr(dialog_->textLayoutModule->fontsizeCO->currentText());
304 fromqstr(dialog_->pageLayoutModule->pagestyleCO->currentText());
306 switch (dialog_->textLayoutModule->lspacingCO->currentItem()) {
308 params.spacing().set(Spacing::Single);
311 params.spacing().set(Spacing::Onehalf);
314 params.spacing().set(Spacing::Double);
317 params.spacing().set(Spacing::Other,
318 fromqstr(dialog_->textLayoutModule->lspacingLE->text()));
322 if (dialog_->textLayoutModule->twoColumnCB->isChecked())
327 if (dialog_->textLayoutModule->indentRB->isChecked())
328 params.paragraph_separation = BufferParams::PARSEP_INDENT;
330 params.paragraph_separation = BufferParams::PARSEP_SKIP;
332 switch (dialog_->textLayoutModule->skipCO->currentItem()) {
334 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
337 params.setDefSkip(VSpace(VSpace::MEDSKIP));
340 params.setDefSkip(VSpace(VSpace::BIGSKIP));
345 widgetsToLength(dialog_->textLayoutModule->skipLE,
346 dialog_->textLayoutModule->skipLengthCO)
348 params.setDefSkip(vs);
352 // DocumentDefskipCB assures that this never happens
353 // so Assert then !!! - jbl
354 params.setDefSkip(VSpace(VSpace::MEDSKIP));
359 fromqstr(dialog_->latexModule->optionsLE->text());
361 params.float_placement = dialog_->floatModule->get();
364 params.papersize2 = VMARGIN_PAPER_TYPE(
365 dialog_->pageLayoutModule->papersizeCO->currentItem());
367 // custom, A3, B3 and B4 paper sizes need geometry
368 int psize = dialog_->pageLayoutModule->papersizeCO->currentItem();
369 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
371 params.paperwidth = widgetsToLength(dialog_->pageLayoutModule->paperwidthLE,
372 dialog_->pageLayoutModule->paperwidthUnitCO);
374 params.paperheight = widgetsToLength(dialog_->pageLayoutModule->paperheightLE,
375 dialog_->pageLayoutModule->paperheightUnitCO);
377 if (dialog_->pageLayoutModule->facingPagesCB->isChecked())
378 params.sides = LyXTextClass::TwoSides;
380 params.sides = LyXTextClass::OneSide;
382 if (dialog_->pageLayoutModule->landscapeRB->isChecked())
383 params.orientation = ORIENTATION_LANDSCAPE;
385 params.orientation = ORIENTATION_PORTRAIT;
388 params.use_geometry =
389 (dialog_->marginsModule->marginCO->currentItem() == 1
392 int margin = dialog_->marginsModule->marginCO->currentItem();
396 params.paperpackage = PAPER_PACKAGES(margin);
398 // set params.papersize from params.papersize2
399 // and params.paperpackage
400 params.setPaperStuff();
402 MarginsModuleBase const * m(dialog_->marginsModule);
404 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
406 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
408 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
410 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
412 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
414 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
416 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
418 params.branchlist() = branchlist_;
424 /** Return the position of val in the vector if found.
425 If not found, return 0.
428 typename std::vector<A>::size_type
429 findPos(std::vector<A> const & vec, A const & val)
431 typename std::vector<A>::const_iterator it =
432 std::find(vec.begin(), vec.end(), val);
435 return distance(vec.begin(), it);
441 void QDocument::update_contents()
446 BufferParams const & params = controller().params();
448 // set the default unit
449 // FIXME: move to controller
450 LyXLength::UNIT defaultUnit = LyXLength::CM;
451 switch (lyxrc.default_papersize) {
452 case PAPER_DEFAULT: break;
455 case PAPER_LEGALPAPER:
456 case PAPER_EXECUTIVEPAPER:
457 defaultUnit = LyXLength::IN;
464 defaultUnit = LyXLength::CM;
469 QString preamble = toqstr(params.preamble);
470 dialog_->preambleModule->preambleMLE->setText(preamble);
473 dialog_->biblioModule->citeDefaultRB->setChecked(
474 params.cite_engine == biblio::ENGINE_BASIC);
476 dialog_->biblioModule->citeNatbibRB->setChecked(
477 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
478 params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
480 dialog_->biblioModule->citeStyleCO->setCurrentItem(
481 params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
483 dialog_->biblioModule->citeJurabibRB->setChecked(
484 params.cite_engine == biblio::ENGINE_JURABIB);
486 dialog_->biblioModule->bibtopicCB->setChecked(
487 params.use_bibtopic);
490 int const pos = int(findPos(lang_,
491 params.language->lang()));
492 dialog_->langModule->languageCO->setCurrentItem(pos);
494 dialog_->langModule->quoteStyleCO->setCurrentItem(
495 params.quotes_language);
497 dialog_->langModule->defaultencodingCB->setChecked(true);
499 if (params.inputenc != "auto") {
500 dialog_->langModule->defaultencodingCB->setChecked(false);
501 if (params.inputenc == "default") {
502 dialog_->langModule->encodingCO->setCurrentItem(0);
505 while (encodings[i]) {
506 if (encodings[i] == params.inputenc)
507 dialog_->langModule->encodingCO->setCurrentItem(i);
514 dialog_->numberingModule->tocSL->setValue(params.tocdepth);
515 dialog_->numberingModule->depthSL->setValue(params.secnumdepth);
516 dialog_->updateNumbering();
519 dialog_->bulletsModule->setBullet(0,params.user_defined_bullet(0));
520 dialog_->bulletsModule->setBullet(1,params.user_defined_bullet(1));
521 dialog_->bulletsModule->setBullet(2,params.user_defined_bullet(2));
522 dialog_->bulletsModule->setBullet(3,params.user_defined_bullet(3));
525 QString text = toqstr(params.graphicsDriver);
526 int nitem = dialog_->latexModule->psdriverCO->count();
527 for (int n = 0; n < nitem ; ++n) {
528 QString enc = tex_graphics[n];
530 dialog_->latexModule->psdriverCO->setCurrentItem(n);
535 dialog_->mathsModule->amsCB->setChecked(
536 params.use_amsmath == BufferParams::AMS_ON);
537 dialog_->mathsModule->amsautoCB->setChecked(
538 params.use_amsmath == BufferParams::AMS_AUTO);
540 switch (params.spacing().getSpace()) {
541 case Spacing::Other: nitem = 3; break;
542 case Spacing::Double: nitem = 2; break;
543 case Spacing::Onehalf: nitem = 1; break;
544 case Spacing::Default: case Spacing::Single: nitem = 0; break;
549 dialog_->latexModule->classCO->setCurrentItem(params.textclass);
551 dialog_->updateFontsize(controller().textClass().opt_fontsize(),
554 dialog_->updatePagestyle(controller().textClass().opt_pagestyle(),
557 for (int n = 0; tex_fonts[n][0]; ++n) {
558 if (tex_fonts[n] == params.fonts) {
559 dialog_->textLayoutModule->fontsCO->setCurrentItem(n);
564 dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
565 if (params.spacing().getSpace() == Spacing::Other) {
566 dialog_->textLayoutModule->lspacingLE->setText(
567 toqstr(params.spacing().getValueAsString()));
569 dialog_->setLSpacing(nitem);
571 if (params.paragraph_separation
572 == BufferParams::PARSEP_INDENT) {
573 dialog_->textLayoutModule->indentRB->setChecked(true);
575 dialog_->textLayoutModule->skipRB->setChecked(true);
579 switch (params.getDefSkip().kind()) {
580 case VSpace::SMALLSKIP:
583 case VSpace::MEDSKIP:
586 case VSpace::BIGSKIP:
592 string const length = params.getDefSkip().asLyXCommand();
593 lengthToWidgets(dialog_->textLayoutModule->skipLE,
594 dialog_->textLayoutModule->skipLengthCO,
595 length, defaultUnit);
602 dialog_->textLayoutModule->skipCO->setCurrentItem(skip);
603 dialog_->setSkip(skip);
605 dialog_->textLayoutModule->twoColumnCB->setChecked(
606 params.columns == 2);
608 if (!params.options.empty()) {
609 dialog_->latexModule->optionsLE->setText(
610 toqstr(params.options));
612 dialog_->latexModule->optionsLE->setText("");
615 dialog_->floatModule->set(params.float_placement);
618 int const psize = params.papersize2;
619 dialog_->pageLayoutModule->papersizeCO->setCurrentItem(psize);
620 dialog_->setMargins(psize);
621 dialog_->setCustomPapersize(psize);
623 bool const landscape =
624 params.orientation == ORIENTATION_LANDSCAPE;
625 dialog_->pageLayoutModule->landscapeRB->setChecked(landscape);
626 dialog_->pageLayoutModule->portraitRB->setChecked(!landscape);
628 dialog_->pageLayoutModule->facingPagesCB->setChecked(
629 params.sides == LyXTextClass::TwoSides);
633 lengthToWidgets(dialog_->pageLayoutModule->paperwidthLE,
634 dialog_->pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
636 lengthToWidgets(dialog_->pageLayoutModule->paperheightLE,
637 dialog_->pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
641 MarginsModuleBase * m = dialog_->marginsModule;
643 int item = params.paperpackage;
644 if (params.use_geometry) {
646 } else if (item > 0) {
649 m->marginCO->setCurrentItem(item);
650 dialog_->setCustomMargins(item);
652 lengthToWidgets(m->topLE, m->topUnit,
653 params.topmargin, defaultUnit);
655 lengthToWidgets(m->bottomLE, m->bottomUnit,
656 params.bottommargin, defaultUnit);
658 lengthToWidgets(m->innerLE, m->innerUnit,
659 params.leftmargin, defaultUnit);
661 lengthToWidgets(m->outerLE, m->outerUnit,
662 params.rightmargin, defaultUnit);
664 lengthToWidgets(m->headheightLE, m->headheightUnit,
665 params.headheight, defaultUnit);
667 lengthToWidgets(m->headsepLE, m->headsepUnit,
668 params.headsep, defaultUnit);
670 lengthToWidgets(m->footskipLE, m->footskipUnit,
671 params.footskip, defaultUnit);
674 branchlist_ = params.branchlist();
675 dialog_->updateBranchView();
679 void QDocument::saveDocDefault()
681 // we have to apply the params first
683 controller().saveAsDefault();
687 void QDocument::useClassDefaults()
689 BufferParams & params = controller().params();
691 params.textclass = dialog_->latexModule->classCO->currentItem();
692 params.useClassDefaults();
696 } // namespace frontend