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
14 #pragma implementation
19 #include "ControlDocument.h"
20 #include "QDocument.h"
21 #include "QDocumentDialog.h"
25 #include "helper_funcs.h" // getSecond()
26 #include "insets/insetquotes.h"
27 #include "frnt_lang.h"
28 #include "tex-strings.h" // tex_graphics
29 #include "support/lstrings.h" // tostr()
30 #include "support/filetools.h" // LibFileSearch()
31 #include "lyxtextclasslist.h"
33 #include "bufferparams.h"
35 #include <qpushbutton.h>
36 #include <qmultilineedit.h>
37 #include <qradiobutton.h>
38 #include <qcombobox.h>
39 #include <qcheckbox.h>
41 #include <qlineedit.h>
42 #include <qstringlist.h>
43 #include "lengthcombo.h"
45 #include "QBrowseBox.h"
51 typedef Qt2CB<ControlDocument, Qt2DB<QDocumentDialog> > base_class;
54 QDocument::QDocument()
55 : base_class(_("Document Settings"))
57 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
58 lang_ = getSecond(langs);
62 void QDocument::build_dialog()
64 dialog_.reset(new QDocumentDialog(this));
67 dialog_->biblioModule->citeStyleCO->insertItem(_("Author-year"));
68 dialog_->biblioModule->citeStyleCO->insertItem(_("Numerical"));
69 dialog_->biblioModule->citeStyleCO->setCurrentItem(0);
72 vector<frnt::LanguagePair> const langs = frnt::getLanguageData(false);
73 vector<frnt::LanguagePair>::const_iterator lit = langs.begin();
74 vector<frnt::LanguagePair>::const_iterator lend = langs.end();
75 for (; lit != lend; ++lit) {
76 dialog_->langModule->languageCO->insertItem(
80 dialog_->langModule->quoteStyleCO->insertItem(_("``text''"));
81 dialog_->langModule->quoteStyleCO->insertItem(_("''text''"));
82 dialog_->langModule->quoteStyleCO->insertItem(_(",,text``"));
83 dialog_->langModule->quoteStyleCO->insertItem(_(",,text''"));
84 dialog_->langModule->quoteStyleCO->insertItem(_("«text»"));
85 dialog_->langModule->quoteStyleCO->insertItem(_("»text«"));
88 char const * items[] = {"default","auto","latin1","latin2",
89 "latin3","latin4","latin5","latin9",
90 "koi8-r","koi8-u","cp866","cp1251",
91 "iso88595","pt154",0};
92 dialog_->packagesModule->encodingCO->insertStrList(items);
94 dialog_->packagesModule->lspacingCO->insertItem(
95 _("Single"), Spacing::Single);
96 dialog_->packagesModule->lspacingCO->insertItem(
97 _("OneHalf"), Spacing::Onehalf);
98 dialog_->packagesModule->lspacingCO->insertItem(
99 _("Double"), Spacing::Double);
100 dialog_->packagesModule->lspacingCO->insertItem(
101 _("Custom"), Spacing::Other);
103 for (int n = 0; tex_graphics[n][0]; ++n) {
104 QString enc = tex_graphics[n];
105 dialog_->packagesModule->psdriverCO->insertItem(enc);
109 QStringList papersize_;
110 papersize_ << _("Default") << _("Custom") << _("US letter") << _("US legal")
111 << _("US executive") << _("A3") << _("A4") << _("A5")
112 << _("B3") << _("B4") << _("B5");
113 dialog_->paperModule->papersizeCO->insertStringList(papersize_);
116 for (LyXTextClassList::const_iterator cit = textclasslist.begin();
117 cit != textclasslist.end(); ++cit) {
118 dialog_->layoutModule->classCO->insertItem(cit->description().c_str());
121 for (int n = 0; tex_fonts[n][0]; ++n) {
122 QString font = tex_fonts[n];
123 dialog_->layoutModule->fontsCO->insertItem(font);
126 dialog_->layoutModule->fontsizeCO->insertItem(_("default"));
127 dialog_->layoutModule->fontsizeCO->insertItem(_("10"));
128 dialog_->layoutModule->fontsizeCO->insertItem(_("11"));
129 dialog_->layoutModule->fontsizeCO->insertItem(_("12"));
131 dialog_->layoutModule->skipCO->insertItem(_("Smallskip"));
132 dialog_->layoutModule->skipCO->insertItem(_("Medskip"));
133 dialog_->layoutModule->skipCO->insertItem(_("Bigskip"));
134 dialog_->layoutModule->skipCO->insertItem(_("Length"));
136 dialog_->layoutModule->pagestyleCO->insertItem(_("default"));
137 dialog_->layoutModule->pagestyleCO->insertItem(_("empty"));
138 dialog_->layoutModule->pagestyleCO->insertItem(_("plain"));
139 dialog_->layoutModule->pagestyleCO->insertItem(_("headings"));
140 dialog_->layoutModule->pagestyleCO->insertItem(_("fancy"));
143 dialog_->setMargins(0);
145 // Manage the restore, ok, apply, restore and cancel/close buttons
146 bc().setOK(dialog_->okPB);
147 bc().setApply(dialog_->applyPB);
148 bc().setCancel(dialog_->cancelPB);
149 bc().setRestore(dialog_->restorePB);
153 void QDocument::apply()
155 BufferParams & params = controller().params();
159 dialog_->preambleModule->preambleMLE->text().latin1();
163 dialog_->biblioModule->natbibCB->isChecked();
164 params.use_numerical_citations =
165 dialog_->biblioModule->citeStyleCO->currentItem();
168 if (dialog_->langModule->singleQuoteRB->isChecked())
169 params.quotes_times = InsetQuotes::SingleQ;
171 params.quotes_times = InsetQuotes::DoubleQ;
174 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
175 switch (dialog_->langModule->quoteStyleCO->currentItem()) {
177 lga = InsetQuotes::EnglishQ;
180 lga = InsetQuotes::SwedishQ;
183 lga = InsetQuotes::GermanQ;
186 lga = InsetQuotes::PolishQ;
189 lga = InsetQuotes::FrenchQ;
192 lga = InsetQuotes::DanishQ;
195 params.quotes_language = lga;
197 int const pos = dialog_->langModule->languageCO->currentItem();
198 params.language = languages.getLanguage(lang_[pos]);
202 dialog_->numberingModule->tocDepthSB->value();
204 dialog_->numberingModule->sectionnrDepthSB->value();
207 params.user_defined_bullets[0].setText(dialog_->bulletsModule->bullet1LE->text().latin1());
208 params.user_defined_bullets[1].setText(dialog_->bulletsModule->bullet2LE->text().latin1());
209 params.user_defined_bullets[2].setText(dialog_->bulletsModule->bullet3LE->text().latin1());
210 params.user_defined_bullets[3].setText(dialog_->bulletsModule->bullet4LE->text().latin1());
212 params.user_defined_bullets[0].setSize(dialog_->bulletsModule->bulletsize1CO->currentItem()-1);
213 params.user_defined_bullets[1].setSize(dialog_->bulletsModule->bulletsize2CO->currentItem()-1);
214 params.user_defined_bullets[2].setSize(dialog_->bulletsModule->bulletsize3CO->currentItem()-1);
215 params.user_defined_bullets[3].setSize(dialog_->bulletsModule->bulletsize4CO->currentItem()-1);
218 switch (dialog_->packagesModule->lspacingCO->currentItem()) {
220 params.spacing.set(Spacing::Single);
223 params.spacing.set(Spacing::Onehalf);
226 params.spacing.set(Spacing::Double);
229 params.spacing.set(Spacing::Other,
230 dialog_->packagesModule->
231 lspacingLE->text().toFloat()
236 params.graphicsDriver =
237 dialog_->packagesModule->psdriverCO->currentText().latin1();
240 dialog_->packagesModule->amsCB->isChecked();
243 dialog_->packagesModule->encodingCO->currentText().latin1();
247 dialog_->layoutModule->classCO->currentItem();
249 //bool succes = controller().classApply();
252 dialog_->layoutModule->fontsCO->currentText().latin1();
255 dialog_->layoutModule->fontsizeCO->currentText().latin1();
258 dialog_->layoutModule->pagestyleCO->currentText().latin1();
260 if (dialog_->layoutModule->indentRB->isChecked())
261 params.paragraph_separation = BufferParams::PARSEP_INDENT;
263 params.paragraph_separation = BufferParams::PARSEP_SKIP;
265 switch (dialog_->layoutModule->skipCO->currentItem()) {
267 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
270 params.setDefSkip(VSpace(VSpace::MEDSKIP));
273 params.setDefSkip(VSpace(VSpace::BIGSKIP));
277 LyXLength::UNIT unit =
278 dialog_->layoutModule->skipLengthCO->
281 dialog_->layoutModule->skipLE->text().toDouble();
282 VSpace vs = VSpace(LyXGlueLength(LyXLength(length,unit)));
283 params.setDefSkip(vs);
287 // DocumentDefskipCB assures that this never happens
288 // so Assert then !!! - jbl
289 params.setDefSkip(VSpace(VSpace::MEDSKIP));
294 dialog_->layoutModule->optionsLE->text().latin1();
296 params.float_placement =
297 dialog_->layoutModule->floatPlacementLE->text().latin1();
301 dialog_->paperModule->papersizeCO->currentItem();
304 LyXLength(dialog_->paperModule->paperwidthLE->text().toDouble(),
305 dialog_->paperModule->paperwidthUnitCO->currentLengthItem()
309 LyXLength(dialog_->paperModule->paperheightLE->text().toDouble(),
310 dialog_->paperModule->paperheightUnitCO->currentLengthItem()
313 if (dialog_->paperModule->twoColumnCB->isChecked())
318 if (dialog_->paperModule->facingPagesCB->isChecked())
319 params.sides = LyXTextClass::TwoSides;
321 params.sides = LyXTextClass::OneSide;
323 if (dialog_->paperModule->landscapeRB->isChecked())
324 params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
326 params.orientation = BufferParams::ORIENTATION_PORTRAIT;
329 params.use_geometry =
330 (dialog_->marginsModule->marginCO->currentItem() == 1);
332 int margin = dialog_->marginsModule->marginCO->currentItem();
336 params.paperpackage = char(margin);
338 MarginsModuleBase const * m(dialog_->marginsModule);
341 LyXLength(m->innerLE->text().toDouble(),
342 m->innerUnit->currentLengthItem()
346 LyXLength(m->topLE->text().toDouble(),
347 m->topUnit->currentLengthItem()
351 LyXLength(m->outerLE->text().toDouble(),
352 m->outerUnit->currentLengthItem()
355 params.bottommargin =
356 LyXLength(m->bottomLE->text().toDouble(),
357 m->bottomUnit->currentLengthItem()
361 LyXLength(m->headheightLE->text().toDouble(),
362 m->headheightUnit->currentLengthItem()
366 LyXLength(m->headsepLE->text().toDouble(),
367 m->headsepUnit->currentLengthItem()
371 LyXLength(m->footskipLE->text().toDouble(),
372 m->footskipUnit->currentLengthItem()
379 /** Return the position of val in the vector if found.
380 If not found, return 0.
383 typename std::vector<A>::size_type
384 findPos(std::vector<A> const & vec, A const & val)
386 typename std::vector<A>::const_iterator it =
387 std::find(vec.begin(), vec.end(), val);
390 return std::distance(vec.begin(), it);
396 void QDocument::update_contents()
401 BufferParams const & params = controller().params();
404 QString preamble = params.preamble.c_str();
405 dialog_->preambleModule->preambleMLE->setText(preamble);
408 dialog_->biblioModule->natbibCB->setChecked(
410 dialog_->biblioModule->citeStyleCO->setCurrentItem(
411 params.use_numerical_citations ? 1 : 0);
414 dialog_->langModule->singleQuoteRB->setChecked(
415 params.quotes_times == InsetQuotes::SingleQ);
416 dialog_->langModule->doubleQuoteRB->setChecked(
417 params.quotes_times == InsetQuotes::DoubleQ);
419 int const pos = int(findPos(lang_,
420 params.language->lang()));
421 dialog_->langModule->languageCO->setCurrentItem(pos);
423 dialog_->langModule->quoteStyleCO->setCurrentItem(
424 params.quotes_language);
427 dialog_->numberingModule->tocDepthSB->setValue(
429 dialog_->numberingModule->sectionnrDepthSB->setValue(
434 s = params.user_defined_bullets[0].getText().c_str();
435 dialog_->bulletsModule->bullet1LE->setText(s);
436 s = params.user_defined_bullets[1].getText().c_str();
437 dialog_->bulletsModule->bullet2LE->setText(s);
438 s = params.user_defined_bullets[2].getText().c_str();
439 dialog_->bulletsModule->bullet3LE->setText(s);
440 s = params.user_defined_bullets[3].getText().c_str();
441 dialog_->bulletsModule->bullet4LE->setText(s);
443 dialog_->bulletsModule->bulletsize1CO->setCurrentItem(
444 params.user_defined_bullets[0].getSize() + 1);
445 dialog_->bulletsModule->bulletsize2CO->setCurrentItem(
446 params.user_defined_bullets[1].getSize() + 1);
447 dialog_->bulletsModule->bulletsize3CO->setCurrentItem(
448 params.user_defined_bullets[2].getSize() + 1);
449 dialog_->bulletsModule->bulletsize4CO->setCurrentItem(
450 params.user_defined_bullets[3].getSize() + 1);
454 enc << "default" << "auto" << "latin1" << "latin2" << "latin3" <<
455 "latin4" << "latin5" << "latin9" << "koi8-r" << "koi8-u" <<
456 "cp866" << "cp1251" << "iso88595" << "pt154";
458 for (QStringList::Iterator it = enc.begin();
459 it!=enc.end(); ++it) {
460 if (*it == params.inputenc.c_str()) {
461 dialog_->packagesModule->encodingCO->setCurrentItem(pos2);
467 QString text = params.graphicsDriver.c_str();
468 int nitem = dialog_->packagesModule->psdriverCO->count();
469 for (int n = 0; n < nitem ; ++n) {
470 QString enc = tex_graphics[n];
472 dialog_->packagesModule->psdriverCO->setCurrentItem(n);
477 dialog_->packagesModule->amsCB->setChecked(
480 // FIXME: this is wrong
481 // QComboBox::setCurrentItem: (lspacingCO) Index 4 out of range
483 dialog_->packagesModule->lspacingCO->
484 setCurrentItem(params.spacing.getSpace());
485 if (params.spacing.getSpace() == Spacing::Other) {
486 dialog_->packagesModule->lspacingLE->setText(
487 tostr(params.spacing.getValue()).c_str());
488 dialog_->setLSpacing(3);
492 for (int n = 0; n<dialog_->layoutModule->classCO->count(); ++n) {
493 if (dialog_->layoutModule->classCO->text(n) ==
494 controller().textClass().description().c_str()) {
495 dialog_->layoutModule->classCO->setCurrentItem(n);
500 dialog_->updateFontsize(controller().textClass().opt_fontsize(),
503 dialog_->updatePagestyle(controller().textClass().opt_pagestyle(),
506 for (int n = 0; tex_fonts[n][0]; ++n) {
507 if (tex_fonts[n] == params.fonts) {
508 dialog_->layoutModule->fontsCO->setCurrentItem(n);
513 if (params.paragraph_separation
514 == BufferParams::PARSEP_INDENT) {
515 dialog_->layoutModule->indentRB->setChecked(true);
517 dialog_->layoutModule->skipRB->setChecked(true);
521 switch (params.getDefSkip().kind()) {
522 case VSpace::SMALLSKIP:
525 case VSpace::MEDSKIP:
528 case VSpace::BIGSKIP:
534 string const length = params.getDefSkip().asLyXCommand();
535 dialog_->layoutModule->skipLengthCO->setCurrentItem(LyXLength(length).unit());
536 dialog_->layoutModule->skipLE->setText(tostr(LyXLength(length).value()).c_str());
543 dialog_->layoutModule->skipCO->setCurrentItem(skip);
544 dialog_->setSkip(skip);
546 if (!params.options.empty()) {
547 dialog_->layoutModule->optionsLE->setText(
548 params.options.c_str());
550 dialog_->layoutModule->optionsLE->setText("");
554 int const psize = params.papersize2;
555 dialog_->paperModule->papersizeCO->setCurrentItem(psize);
556 dialog_->setMargins(psize);
557 dialog_->setCustomPapersize(psize);
559 bool const landscape =
560 params.orientation == BufferParams::ORIENTATION_LANDSCAPE;
561 dialog_->paperModule->landscapeRB->setChecked(landscape);
562 dialog_->paperModule->portraitRB->setChecked(!landscape);
564 dialog_->paperModule->facingPagesCB->setChecked(
565 params.sides == LyXTextClass::TwoSides);
567 dialog_->paperModule->twoColumnCB->setChecked(
568 params.columns == 2);
570 dialog_->paperModule->paperwidthUnitCO->setCurrentItem(
571 LyXLength(params.paperwidth).unit());
573 dialog_->paperModule->paperwidthLE->setText(
574 tostr(LyXLength(params.paperwidth).value()).c_str());
576 dialog_->paperModule->paperheightUnitCO->setCurrentItem(
577 LyXLength(params.paperheight).unit());
579 dialog_->paperModule->paperheightLE->setText(
580 tostr(LyXLength(params.paperheight).value()).c_str());
584 MarginsModuleBase * m(dialog_->marginsModule);
586 int item = params.paperpackage;
587 if (params.use_geometry) {
589 } else if (item > 0) {
592 m->marginCO->setCurrentItem(item);
593 dialog_->setCustomMargins(item);
595 m->topUnit->setCurrentItem(LyXLength(params.topmargin).unit());
596 m->topLE->setText(tostr(LyXLength(params.topmargin).value()).c_str());
598 m->bottomUnit->setCurrentItem(LyXLength(params.bottommargin).unit());
599 m->bottomLE->setText(tostr(LyXLength(params.bottommargin).value()).c_str());
601 m->innerUnit->setCurrentItem(LyXLength(params.leftmargin).unit());
602 m->innerLE->setText(tostr(LyXLength(params.leftmargin).value()).c_str());
604 m->outerUnit->setCurrentItem(LyXLength(params.rightmargin).unit());
605 m->outerLE->setText(tostr(LyXLength(params.rightmargin).value()).c_str());
607 m->headheightUnit->setCurrentItem(LyXLength(params.headheight).unit());
608 m->headheightLE->setText(tostr(LyXLength(params.headheight).value()).c_str());
610 m->headsepUnit->setCurrentItem(LyXLength(params.headsep).unit());
611 m->headsepLE->setText(tostr(LyXLength(params.headsep).value()).c_str());
613 m->footskipUnit->setCurrentItem(LyXLength(params.footskip).unit());
614 m->footskipLE->setText(tostr(LyXLength(params.footskip).value()).c_str());
618 void QDocument::saveDocDefault()
620 // we have to apply the params first
622 controller().saveAsDefault();
626 void QDocument::useClassDefaults()
628 BufferParams & params = controller().params();
630 params.textclass = dialog_->layoutModule->classCO->currentItem();
631 params.useClassDefaults();