2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "BranchList.h"
17 #include "buffer_funcs.h"
19 #include "BufferParams.h"
20 #include "BufferView.h"
22 #include "EmbeddedFiles.h"
24 #include "FloatPlacement.h"
25 #include "FuncRequest.h"
26 #include "support/gettext.h"
27 #include "GuiBranches.h"
29 #include "LaTeXFeatures.h"
30 #include "LaTeXHighlighter.h"
32 #include "LengthCombo.h"
33 #include "LyXRC.h" // defaultUnit
34 #include "ModuleList.h"
35 #include "OutputParams.h"
36 #include "PanelStack.h"
37 #include "PDFOptions.h"
38 #include "qt_helpers.h"
40 #include "TextClassList.h"
41 #include "Validator.h"
43 #include "insets/InsetListingsParams.h"
45 #include "support/FileName.h"
46 #include "support/filetools.h"
47 #include "support/lstrings.h"
49 #include <boost/bind.hpp>
51 #include <QCloseEvent>
53 #include <QTextCursor>
59 using namespace lyx::support;
63 vector<typename Pair::second_type> const
64 getSecond(vector<Pair> const & pr)
66 vector<typename Pair::second_type> tmp(pr.size());
67 transform(pr.begin(), pr.end(), tmp.begin(),
68 boost::bind(&Pair::second, _1));
72 char const * const tex_graphics[] =
74 "default", "dvips", "dvitops", "emtex",
75 "ln", "oztex", "textures", "none", ""
79 char const * const tex_graphics_gui[] =
81 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
82 "LN", "OzTeX", "Textures", N_("None"), ""
86 char const * const tex_fonts_roman[] =
88 "default", "cmr", "lmodern", "ae", "times", "palatino",
89 "charter", "newcent", "bookman", "utopia", "beraserif",
90 "ccfonts", "chancery", ""
94 char const * tex_fonts_roman_gui[] =
96 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
97 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
98 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
99 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
104 char const * const tex_fonts_sans[] =
106 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
110 char const * tex_fonts_sans_gui[] =
112 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
113 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
117 char const * const tex_fonts_monospaced[] =
119 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
123 char const * tex_fonts_monospaced_gui[] =
125 N_("Default"), N_("Computer Modern Typewriter"),
126 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
127 N_("LuxiMono"), N_("CM Typewriter Light"), ""
131 vector<pair<string, lyx::docstring> > pagestyles;
138 vector<string> getRequiredList(string const & modName)
140 LyXModule const * const mod = moduleList[modName];
142 return vector<string>(); //empty such thing
143 return mod->getRequiredModules();
147 vector<string> getExcludedList(string const & modName)
149 LyXModule const * const mod = moduleList[modName];
151 return vector<string>(); //empty such thing
152 return mod->getExcludedModules();
156 docstring getModuleDescription(string const & modName)
158 LyXModule const * const mod = moduleList[modName];
160 return _("Module not found!");
161 return from_ascii(mod->getDescription());
165 vector<string> getPackageList(string const & modName)
167 LyXModule const * const mod = moduleList[modName];
169 return vector<string>(); //empty such thing
170 return mod->getPackageList();
174 bool isModuleAvailable(string const & modName)
176 LyXModule * mod = moduleList[modName];
179 return mod->isAvailable();
181 } //anonymous namespace
184 ModuleSelMan::ModuleSelMan(
185 QListView * availableLV,
186 QListView * selectedLV,
190 QPushButton * downPB,
191 QStringListModel * availableModel,
192 QStringListModel * selectedModel) :
193 GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
194 upPB, downPB, availableModel, selectedModel)
198 void ModuleSelMan::updateAddPB()
200 int const arows = availableLV->model()->rowCount();
201 QModelIndexList const availSels =
202 availableLV->selectionModel()->selectedIndexes();
203 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
204 addPB->setEnabled(false);
208 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
209 string const modName = fromqstr(idx.data().toString());
210 vector<string> reqs = getRequiredList(modName);
211 vector<string> excl = getExcludedList(modName);
213 if (reqs.empty() && excl.empty()) {
214 addPB->setEnabled(true);
218 QStringList const & qsl = selectedModel->stringList();
220 //Check whether some required module is available
222 bool foundOne = false;
223 vector<string>::const_iterator it = reqs.begin();
224 vector<string>::const_iterator end = reqs.end();
225 for (; it != end; ++it) {
226 if (qsl.contains(toqstr(*it))) {
232 addPB->setEnabled(false);
237 //Check whether any excluded module is being used
239 vector<string>::const_iterator it = excl.begin();
240 vector<string>::const_iterator end = excl.end();
241 for (; it != end; ++it) {
242 if (qsl.contains(toqstr(*it))) {
243 addPB->setEnabled(false);
249 addPB->setEnabled(true);
253 /////////////////////////////////////////////////////////////////////
257 /////////////////////////////////////////////////////////////////////
259 PreambleModule::PreambleModule(): current_id_(0)
261 // This is not a memory leak. The object will be destroyed
263 (void) new LaTeXHighlighter(preambleTE->document());
264 setFocusProxy(preambleTE);
265 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
269 void PreambleModule::update(BufferParams const & params, BufferId id)
271 QString preamble = toqstr(params.preamble);
272 // Nothing to do if the params and preamble are unchanged.
273 if (id == current_id_
274 && preamble == preambleTE->document()->toPlainText())
277 QTextCursor cur = preambleTE->textCursor();
278 // Save the coords before switching to the new one.
279 preamble_coords_[current_id_] =
280 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
282 // Save the params address for further use.
284 preambleTE->document()->setPlainText(preamble);
285 Coords::const_iterator it = preamble_coords_.find(current_id_);
286 if (it == preamble_coords_.end())
287 // First time we open this one.
288 preamble_coords_[current_id_] = make_pair(0,0);
290 // Restore saved coords.
291 QTextCursor cur = preambleTE->textCursor();
292 cur.setPosition(it->second.first);
293 preambleTE->setTextCursor(cur);
294 preambleTE->verticalScrollBar()->setValue(it->second.second);
299 void PreambleModule::apply(BufferParams & params)
301 params.preamble = fromqstr(preambleTE->document()->toPlainText());
305 void PreambleModule::closeEvent(QCloseEvent * e)
307 // Save the coords before closing.
308 QTextCursor cur = preambleTE->textCursor();
309 preamble_coords_[current_id_] =
310 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
315 /////////////////////////////////////////////////////////////////////
319 /////////////////////////////////////////////////////////////////////
323 GuiDocument::GuiDocument(GuiView & lv)
324 : GuiDialog(lv, "document")
327 setViewTitle(_("Document Settings"));
329 lang_ = getSecond(getLanguageData(false));
331 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
332 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
333 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
334 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
336 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
337 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
339 // Manage the restore, ok, apply, restore and cancel/close buttons
340 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
342 bc().setApply(applyPB);
343 bc().setCancel(closePB);
344 bc().setRestore(restorePB);
346 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
348 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
349 this, SLOT(change_adaptor()));
350 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
351 this, SLOT(setLSpacing(int)));
352 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString&)),
353 this, SLOT(change_adaptor()));
354 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
355 this, SLOT(change_adaptor()));
356 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
357 this, SLOT(change_adaptor()));
358 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
359 this, SLOT(change_adaptor()));
360 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
361 this, SLOT(change_adaptor()));
362 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
363 this, SLOT(change_adaptor()));
364 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
365 this, SLOT(setSkip(int)));
366 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
367 this, SLOT(enableSkip(bool)));
368 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
369 this, SLOT(change_adaptor()));
370 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
371 this, SLOT(change_adaptor()));
372 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
373 this, SLOT(change_adaptor()));
374 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
375 this, SLOT(set_listings_msg()));
376 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
377 this, SLOT(set_listings_msg()));
378 textLayoutModule->listingsTB->setPlainText(
379 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
380 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
381 textLayoutModule->lspacingLE));
382 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
383 textLayoutModule->skipLE));
385 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
386 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
387 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
388 textLayoutModule->skipCO->addItem(qt_("Length"));
389 // remove the %-items from the unit choice
390 textLayoutModule->skipLengthCO->noPercents();
391 textLayoutModule->lspacingCO->insertItem(
392 Spacing::Single, qt_("Single"));
393 textLayoutModule->lspacingCO->insertItem(
394 Spacing::Onehalf, qt_("OneHalf"));
395 textLayoutModule->lspacingCO->insertItem(
396 Spacing::Double, qt_("Double"));
397 textLayoutModule->lspacingCO->insertItem(
398 Spacing::Other, qt_("Custom"));
400 // initialize the length validator
401 bc().addCheckedLineEdit(textLayoutModule->skipLE);
403 fontModule = new UiWidget<Ui::FontUi>;
405 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
406 this, SLOT(change_adaptor()));
407 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
408 this, SLOT(romanChanged(int)));
409 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
410 this, SLOT(change_adaptor()));
411 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
412 this, SLOT(sansChanged(int)));
413 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
414 this, SLOT(change_adaptor()));
415 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
416 this, SLOT(ttChanged(int)));
417 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
418 this, SLOT(change_adaptor()));
419 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
420 this, SLOT(change_adaptor()));
421 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
422 this, SLOT(change_adaptor()));
423 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
424 this, SLOT(change_adaptor()));
425 connect(fontModule->fontScCB, SIGNAL(clicked()),
426 this, SLOT(change_adaptor()));
427 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
428 this, SLOT(change_adaptor()));
430 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
431 QString font = qt_(tex_fonts_roman_gui[n]);
432 if (!isFontAvailable(tex_fonts_roman[n]))
433 font += qt_(" (not installed)");
434 fontModule->fontsRomanCO->addItem(font);
436 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
437 QString font = qt_(tex_fonts_sans_gui[n]);
438 if (!isFontAvailable(tex_fonts_sans[n]))
439 font += qt_(" (not installed)");
440 fontModule->fontsSansCO->addItem(font);
442 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
443 QString font = qt_(tex_fonts_monospaced_gui[n]);
444 if (!isFontAvailable(tex_fonts_monospaced[n]))
445 font += qt_(" (not installed)");
446 fontModule->fontsTypewriterCO->addItem(font);
449 fontModule->fontsizeCO->addItem(qt_("Default"));
450 fontModule->fontsizeCO->addItem(qt_("10"));
451 fontModule->fontsizeCO->addItem(qt_("11"));
452 fontModule->fontsizeCO->addItem(qt_("12"));
454 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
455 fontModule->fontsDefaultCO->addItem(
456 qt_(GuiDocument::fontfamilies_gui[n]));
459 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
461 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
462 this, SLOT(setCustomPapersize(int)));
463 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
464 this, SLOT(setCustomPapersize(int)));
465 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
466 this, SLOT(portraitChanged()));
467 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
468 this, SLOT(change_adaptor()));
469 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
470 this, SLOT(change_adaptor()));
471 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
472 this, SLOT(change_adaptor()));
473 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
474 this, SLOT(change_adaptor()));
475 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
476 this, SLOT(change_adaptor()));
477 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
478 this, SLOT(change_adaptor()));
479 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
480 this, SLOT(change_adaptor()));
481 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
482 this, SLOT(change_adaptor()));
483 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
484 this, SLOT(change_adaptor()));
486 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
487 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
488 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
489 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
490 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
491 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
492 pageLayoutModule->paperheightL);
493 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
494 pageLayoutModule->paperwidthL);
497 QComboBox * cb = pageLayoutModule->papersizeCO;
498 cb->addItem(qt_("Default"));
499 cb->addItem(qt_("Custom"));
500 cb->addItem(qt_("US letter"));
501 cb->addItem(qt_("US legal"));
502 cb->addItem(qt_("US executive"));
503 cb->addItem(qt_("A3"));
504 cb->addItem(qt_("A4"));
505 cb->addItem(qt_("A5"));
506 cb->addItem(qt_("B3"));
507 cb->addItem(qt_("B4"));
508 cb->addItem(qt_("B5"));
509 // remove the %-items from the unit choice
510 pageLayoutModule->paperwidthUnitCO->noPercents();
511 pageLayoutModule->paperheightUnitCO->noPercents();
512 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
513 pageLayoutModule->paperheightLE));
514 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
515 pageLayoutModule->paperwidthLE));
518 marginsModule = new UiWidget<Ui::MarginsUi>;
520 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
521 this, SLOT(setCustomMargins(bool)));
522 connect(marginsModule->marginCB, SIGNAL(clicked()),
523 this, SLOT(change_adaptor()));
524 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
525 this, SLOT(change_adaptor()));
526 connect(marginsModule->topUnit, SIGNAL(activated(int)),
527 this, SLOT(change_adaptor()));
528 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
529 this, SLOT(change_adaptor()));
530 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
531 this, SLOT(change_adaptor()));
532 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
533 this, SLOT(change_adaptor()));
534 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
535 this, SLOT(change_adaptor()));
536 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
537 this, SLOT(change_adaptor()));
538 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
539 this, SLOT(change_adaptor()));
540 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
541 this, SLOT(change_adaptor()));
542 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
543 this, SLOT(change_adaptor()));
544 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
545 this, SLOT(change_adaptor()));
546 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
547 this, SLOT(change_adaptor()));
548 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
549 this, SLOT(change_adaptor()));
550 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
551 this, SLOT(change_adaptor()));
552 marginsModule->topLE->setValidator(unsignedLengthValidator(
553 marginsModule->topLE));
554 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
555 marginsModule->bottomLE));
556 marginsModule->innerLE->setValidator(unsignedLengthValidator(
557 marginsModule->innerLE));
558 marginsModule->outerLE->setValidator(unsignedLengthValidator(
559 marginsModule->outerLE));
560 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
561 marginsModule->headsepLE));
562 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
563 marginsModule->headheightLE));
564 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
565 marginsModule->footskipLE));
567 bc().addCheckedLineEdit(marginsModule->topLE,
568 marginsModule->topL);
569 bc().addCheckedLineEdit(marginsModule->bottomLE,
570 marginsModule->bottomL);
571 bc().addCheckedLineEdit(marginsModule->innerLE,
572 marginsModule->innerL);
573 bc().addCheckedLineEdit(marginsModule->outerLE,
574 marginsModule->outerL);
575 bc().addCheckedLineEdit(marginsModule->headsepLE,
576 marginsModule->headsepL);
577 bc().addCheckedLineEdit(marginsModule->headheightLE,
578 marginsModule->headheightL);
579 bc().addCheckedLineEdit(marginsModule->footskipLE,
580 marginsModule->footskipL);
583 langModule = new UiWidget<Ui::LanguageUi>;
585 connect(langModule->languageCO, SIGNAL(activated(int)),
586 this, SLOT(change_adaptor()));
587 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
588 this, SLOT(change_adaptor()));
589 connect(langModule->otherencodingRB, SIGNAL(clicked()),
590 this, SLOT(change_adaptor()));
591 connect(langModule->encodingCO, SIGNAL(activated(int)),
592 this, SLOT(change_adaptor()));
593 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
594 this, SLOT(change_adaptor()));
596 vector<LanguagePair> const langs = getLanguageData(false);
597 vector<LanguagePair>::const_iterator lit = langs.begin();
598 vector<LanguagePair>::const_iterator lend = langs.end();
599 for (; lit != lend; ++lit) {
600 langModule->languageCO->addItem(toqstr(lit->first));
603 // Always put the default encoding in the first position.
604 // It is special because the displayed text is translated.
605 langModule->encodingCO->addItem(qt_("LaTeX default"));
606 Encodings::const_iterator it = encodings.begin();
607 Encodings::const_iterator const end = encodings.end();
608 for (; it != end; ++it)
609 langModule->encodingCO->addItem(toqstr(it->latexName()));
611 langModule->quoteStyleCO->addItem(qt_("``text''"));
612 langModule->quoteStyleCO->addItem(qt_("''text''"));
613 langModule->quoteStyleCO->addItem(qt_(",,text``"));
614 langModule->quoteStyleCO->addItem(qt_(",,text''"));
615 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
616 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
620 numberingModule = new UiWidget<Ui::NumberingUi>;
622 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
623 this, SLOT(change_adaptor()));
624 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
625 this, SLOT(change_adaptor()));
626 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
627 this, SLOT(updateNumbering()));
628 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
629 this, SLOT(updateNumbering()));
630 numberingModule->tocTW->setColumnCount(3);
631 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
632 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
633 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
636 biblioModule = new UiWidget<Ui::BiblioUi>;
637 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
638 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
639 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
640 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
642 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
643 this, SLOT(change_adaptor()));
644 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
645 this, SLOT(change_adaptor()));
646 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
647 this, SLOT(change_adaptor()));
648 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
649 this, SLOT(change_adaptor()));
650 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
651 this, SLOT(change_adaptor()));
653 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
654 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
655 biblioModule->citeStyleCO->setCurrentIndex(0);
658 mathsModule = new UiWidget<Ui::MathsUi>;
659 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
660 mathsModule->amsCB, SLOT(setDisabled(bool)));
661 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
662 mathsModule->esintCB, SLOT(setDisabled(bool)));
664 connect(mathsModule->amsCB, SIGNAL(clicked()),
665 this, SLOT(change_adaptor()));
666 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
667 this, SLOT(change_adaptor()));
668 connect(mathsModule->esintCB, SIGNAL(clicked()),
669 this, SLOT(change_adaptor()));
670 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
671 this, SLOT(change_adaptor()));
673 latexModule = new UiWidget<Ui::LaTeXUi>;
675 connect(latexModule->classCO, SIGNAL(activated(int)),
676 this, SLOT(change_adaptor()));
677 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
678 this, SLOT(change_adaptor()));
679 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
680 this, SLOT(change_adaptor()));
681 connect(latexModule->classCO, SIGNAL(activated(int)),
682 this, SLOT(classChanged()));
685 new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
686 latexModule->addPB, latexModule->deletePB,
687 latexModule->upPB, latexModule->downPB,
688 availableModel(), selectedModel());
689 connect(selectionManager, SIGNAL(updateHook()),
690 this, SLOT(updateModuleInfo()));
691 connect(selectionManager, SIGNAL(updateHook()),
692 this, SLOT(change_adaptor()));
694 // postscript drivers
695 for (int n = 0; tex_graphics[n][0]; ++n) {
696 QString enc = qt_(tex_graphics_gui[n]);
697 latexModule->psdriverCO->addItem(enc);
700 //FIXME This seems too involved with the kernel. Some of this
701 //should be moved to the kernel---which should perhaps just
702 //give us a list of entries or something of the sort.
703 for (TextClassList::const_iterator cit = textclasslist.begin();
704 cit != textclasslist.end(); ++cit) {
705 if (cit->isTeXClassAvailable()) {
706 latexModule->classCO->addItem(toqstr(cit->description()));
709 bformat(_("Unavailable: %1$s"), from_utf8(cit->description()));
710 latexModule->classCO->addItem(toqstr(item));
715 branchesModule = new GuiBranches;
716 connect(branchesModule, SIGNAL(changed()),
717 this, SLOT(change_adaptor()));
720 preambleModule = new PreambleModule;
721 connect(preambleModule, SIGNAL(changed()),
722 this, SLOT(change_adaptor()));
725 bulletsModule = new BulletsModule;
726 connect(bulletsModule, SIGNAL(changed()),
727 this, SLOT(change_adaptor()));
730 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
731 connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
732 this, SLOT(change_adaptor()));
733 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
734 this, SLOT(change_adaptor()));
735 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
736 this, SLOT(change_adaptor()));
739 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
741 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
742 this, SLOT(change_adaptor()));
743 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
744 this, SLOT(change_adaptor()));
745 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
746 this, SLOT(change_adaptor()));
747 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
748 this, SLOT(change_adaptor()));
749 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
750 this, SLOT(change_adaptor()));
751 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
752 this, SLOT(change_adaptor()));
753 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
754 this, SLOT(change_adaptor()));
755 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
756 this, SLOT(change_adaptor()));
757 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
758 this, SLOT(change_adaptor()));
759 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
760 this, SLOT(change_adaptor()));
761 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
762 this, SLOT(change_adaptor()));
763 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
764 this, SLOT(change_adaptor()));
765 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
766 this, SLOT(change_adaptor()));
767 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
768 this, SLOT(change_adaptor()));
769 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
770 this, SLOT(change_adaptor()));
771 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
772 this, SLOT(change_adaptor()));
773 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
774 this, SLOT(change_adaptor()));
777 floatModule = new FloatPlacement;
778 connect(floatModule, SIGNAL(changed()),
779 this, SLOT(change_adaptor()));
781 docPS->addPanel(latexModule, _("Document Class"));
782 docPS->addPanel(fontModule, _("Fonts"));
783 docPS->addPanel(textLayoutModule, _("Text Layout"));
784 docPS->addPanel(pageLayoutModule, _("Page Layout"));
785 docPS->addPanel(marginsModule, _("Page Margins"));
786 docPS->addPanel(langModule, _("Language"));
787 docPS->addPanel(numberingModule, _("Numbering & TOC"));
788 docPS->addPanel(biblioModule, _("Bibliography"));
789 docPS->addPanel(pdfSupportModule, _("PDF Properties"));
790 docPS->addPanel(mathsModule, _("Math Options"));
791 docPS->addPanel(floatModule, _("Float Placement"));
792 docPS->addPanel(bulletsModule, _("Bullets"));
793 docPS->addPanel(branchesModule, _("Branches"));
794 docPS->addPanel(embeddedFilesModule, _("Embedded Files"));
795 docPS->addPanel(preambleModule, _("LaTeX Preamble"));
796 docPS->setCurrentPanel(_("Document Class"));
797 // FIXME: hack to work around resizing bug in Qt >= 4.2
798 // bug verified with Qt 4.2.{0-3} (JSpitzm)
799 #if QT_VERSION >= 0x040200
800 docPS->updateGeometry();
805 void GuiDocument::showPreamble()
807 docPS->setCurrentPanel(_("LaTeX Preamble"));
811 void GuiDocument::saveDefaultClicked()
817 void GuiDocument::useDefaultsClicked()
823 void GuiDocument::change_adaptor()
829 docstring GuiDocument::validate_listings_params()
831 // use a cache here to avoid repeated validation
832 // of the same parameters
833 static string param_cache = string();
834 static docstring msg_cache = docstring();
836 if (textLayoutModule->bypassCB->isChecked())
839 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
840 if (params != param_cache) {
841 param_cache = params;
842 msg_cache = InsetListingsParams(params).validate();
848 void GuiDocument::set_listings_msg()
850 static bool isOK = true;
851 docstring msg = validate_listings_params();
856 // listingsTB->setTextColor("black");
857 textLayoutModule->listingsTB->setPlainText(
858 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
861 // listingsTB->setTextColor("red");
862 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
867 void GuiDocument::closeEvent(QCloseEvent * e)
874 void GuiDocument::setLSpacing(int item)
876 textLayoutModule->lspacingLE->setEnabled(item == 3);
880 void GuiDocument::setSkip(int item)
882 bool const enable = (item == 3);
883 textLayoutModule->skipLE->setEnabled(enable);
884 textLayoutModule->skipLengthCO->setEnabled(enable);
888 void GuiDocument::enableSkip(bool skip)
890 textLayoutModule->skipCO->setEnabled(skip);
891 textLayoutModule->skipLE->setEnabled(skip);
892 textLayoutModule->skipLengthCO->setEnabled(skip);
894 setSkip(textLayoutModule->skipCO->currentIndex());
897 void GuiDocument::portraitChanged()
899 setMargins(pageLayoutModule->papersizeCO->currentIndex());
902 void GuiDocument::setMargins(bool custom)
904 marginsModule->marginCB->setChecked(custom);
905 setCustomMargins(custom);
909 void GuiDocument::setCustomPapersize(int papersize)
911 bool const custom = (papersize == 1);
913 pageLayoutModule->paperwidthL->setEnabled(custom);
914 pageLayoutModule->paperwidthLE->setEnabled(custom);
915 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
916 pageLayoutModule->paperheightL->setEnabled(custom);
917 pageLayoutModule->paperheightLE->setEnabled(custom);
918 pageLayoutModule->paperheightLE->setFocus();
919 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
923 void GuiDocument::setCustomMargins(bool custom)
925 marginsModule->topL->setEnabled(!custom);
926 marginsModule->topLE->setEnabled(!custom);
927 marginsModule->topUnit->setEnabled(!custom);
929 marginsModule->bottomL->setEnabled(!custom);
930 marginsModule->bottomLE->setEnabled(!custom);
931 marginsModule->bottomUnit->setEnabled(!custom);
933 marginsModule->innerL->setEnabled(!custom);
934 marginsModule->innerLE->setEnabled(!custom);
935 marginsModule->innerUnit->setEnabled(!custom);
937 marginsModule->outerL->setEnabled(!custom);
938 marginsModule->outerLE->setEnabled(!custom);
939 marginsModule->outerUnit->setEnabled(!custom);
941 marginsModule->headheightL->setEnabled(!custom);
942 marginsModule->headheightLE->setEnabled(!custom);
943 marginsModule->headheightUnit->setEnabled(!custom);
945 marginsModule->headsepL->setEnabled(!custom);
946 marginsModule->headsepLE->setEnabled(!custom);
947 marginsModule->headsepUnit->setEnabled(!custom);
949 marginsModule->footskipL->setEnabled(!custom);
950 marginsModule->footskipLE->setEnabled(!custom);
951 marginsModule->footskipUnit->setEnabled(!custom);
955 void GuiDocument::updateFontsize(string const & items, string const & sel)
957 fontModule->fontsizeCO->clear();
958 fontModule->fontsizeCO->addItem(qt_("Default"));
960 for (int n = 0; !token(items,'|',n).empty(); ++n)
961 fontModule->fontsizeCO->
962 addItem(toqstr(token(items,'|',n)));
964 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
965 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
966 fontModule->fontsizeCO->setCurrentIndex(n);
973 void GuiDocument::romanChanged(int item)
975 string const font = tex_fonts_roman[item];
976 fontModule->fontScCB->setEnabled(providesSC(font));
977 fontModule->fontOsfCB->setEnabled(providesOSF(font));
981 void GuiDocument::sansChanged(int item)
983 string const font = tex_fonts_sans[item];
984 bool scaleable = providesScale(font);
985 fontModule->scaleSansSB->setEnabled(scaleable);
986 fontModule->scaleSansLA->setEnabled(scaleable);
990 void GuiDocument::ttChanged(int item)
992 string const font = tex_fonts_monospaced[item];
993 bool scaleable = providesScale(font);
994 fontModule->scaleTypewriterSB->setEnabled(scaleable);
995 fontModule->scaleTypewriterLA->setEnabled(scaleable);
999 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1002 pageLayoutModule->pagestyleCO->clear();
1003 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1005 for (int n = 0; !token(items,'|',n).empty(); ++n) {
1006 string style = token(items, '|', n);
1007 docstring style_gui = _(style);
1008 pagestyles.push_back(pair<string, docstring>(style, style_gui));
1009 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
1012 if (sel == "default") {
1013 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1019 for (size_t i = 0; i < pagestyles.size(); ++i)
1020 if (pagestyles[i].first == sel)
1021 nn = pageLayoutModule->pagestyleCO->findText(
1022 toqstr(pagestyles[i].second));
1025 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1029 void GuiDocument::classChanged()
1031 textclass_type const tc = latexModule->classCO->currentIndex();
1032 bp_.setBaseClass(tc);
1033 if (lyxrc.auto_reset_options)
1034 bp_.useClassDefaults();
1040 //This is an insanely complicated attempt to make this sort of thing
1041 //work with RTL languages.
1042 docstring formatStrVec(vector<string> const & v, docstring const & s)
1044 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1045 int const vSize = v.size();
1048 else if (v.size() == 1)
1049 return from_ascii(v[0]);
1050 else if (v.size() == 2) {
1051 docstring retval = _("%1$s and %2$s");
1052 retval = subst(retval, _("and"), s);
1053 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1055 //The idea here is to format all but the last two items...
1056 docstring t2 = _("%1$s, %2$s");
1057 docstring retval = from_ascii(v[0]);
1058 for (int i = 1; i < vSize - 2; ++i)
1059 retval = bformat(t2, retval, from_ascii(v[i]));
1060 //...and then to plug them, and the last two, into this schema
1061 docstring t = _("%1$s, %2$s, and %3$s");
1062 t = subst(t, _("and"), s);
1063 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1068 void GuiDocument::updateModuleInfo()
1070 selectionManager->update();
1071 //Module description
1072 QListView const * const lv = selectionManager->selectedFocused() ?
1073 latexModule->selectedLV :
1074 latexModule->availableLV;
1075 if (lv->selectionModel()->selectedIndexes().isEmpty())
1076 latexModule->infoML->document()->clear();
1078 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1079 string const modName = fromqstr(idx.data().toString());
1080 docstring desc = getModuleDescription(modName);
1082 vector<string> pkgList = getPackageList(modName);
1083 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1084 if (!pkgdesc.empty()) {
1087 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1090 pkgList = getRequiredList(modName);
1091 pkgdesc = formatStrVec(pkgList, _("or"));
1092 if (!pkgdesc.empty()) {
1095 desc += bformat(_("Module required: %1$s."), pkgdesc);
1098 pkgList = getExcludedList(modName);
1099 pkgdesc = formatStrVec(pkgList, _( "and"));
1100 if (!pkgdesc.empty()) {
1103 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1106 if (!isModuleAvailable(modName)) {
1109 desc += _("WARNING: Some packages are unavailable!");
1111 latexModule->infoML->document()->setPlainText(toqstr(desc));
1116 void GuiDocument::updateEmbeddedFileList()
1118 embeddedFilesModule->filesLW->clear();
1119 // add current embedded files
1120 EmbeddedFileList & files = buffer().embeddedFiles();
1121 files.update(buffer());
1122 EmbeddedFileList::iterator fit = files.begin();
1123 EmbeddedFileList::iterator fit_end = files.end();
1124 for (; fit != fit_end; ++fit) {
1125 QString label = toqstr(fit->relFilename(buffer().filePath()));
1126 if (fit->refCount() > 1)
1127 label += " (" + QString::number(fit->refCount()) + ")";
1128 QListWidgetItem * item = new QListWidgetItem(label);
1129 item->setFlags(item->flags() | Qt::ItemIsSelectable
1130 | Qt::ItemIsUserCheckable);
1132 item->setCheckState(Qt::Checked);
1134 item->setCheckState(Qt::Unchecked);
1135 // index of the currently used ParConstIterator
1136 embeddedFilesModule->filesLW->addItem(item);
1141 void GuiDocument::updateNumbering()
1143 TextClass const & tclass = bp_.getTextClass();
1145 numberingModule->tocTW->setUpdatesEnabled(false);
1146 numberingModule->tocTW->clear();
1148 int const depth = numberingModule->depthSL->value();
1149 int const toc = numberingModule->tocSL->value();
1150 QString const no = qt_("No");
1151 QString const yes = qt_("Yes");
1152 TextClass::const_iterator end = tclass.end();
1153 TextClass::const_iterator cit = tclass.begin();
1154 QTreeWidgetItem * item = 0;
1155 for ( ; cit != end ; ++cit) {
1156 int const toclevel = (*cit)->toclevel;
1157 if (toclevel != Layout::NOT_IN_TOC
1158 && (*cit)->labeltype == LABEL_COUNTER) {
1159 item = new QTreeWidgetItem(numberingModule->tocTW);
1160 item->setText(0, toqstr(translateIfPossible((*cit)->name())));
1161 item->setText(1, (toclevel <= depth) ? yes : no);
1162 item->setText(2, (toclevel <= toc) ? yes : no);
1166 numberingModule->tocTW->setUpdatesEnabled(true);
1167 numberingModule->tocTW->update();
1171 void GuiDocument::apply(BufferParams & params)
1174 preambleModule->apply(params);
1177 params.setCiteEngine(biblio::ENGINE_BASIC);
1179 if (biblioModule->citeNatbibRB->isChecked()) {
1180 bool const use_numerical_citations =
1181 biblioModule->citeStyleCO->currentIndex();
1182 if (use_numerical_citations)
1183 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1185 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1187 } else if (biblioModule->citeJurabibRB->isChecked())
1188 params.setCiteEngine(biblio::ENGINE_JURABIB);
1190 params.use_bibtopic =
1191 biblioModule->bibtopicCB->isChecked();
1193 // language & quotes
1194 if (langModule->defaultencodingRB->isChecked()) {
1195 params.inputenc = "auto";
1197 int i = langModule->encodingCO->currentIndex();
1199 params.inputenc = "default";
1202 fromqstr(langModule->encodingCO->currentText());
1205 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1206 switch (langModule->quoteStyleCO->currentIndex()) {
1208 lga = InsetQuotes::EnglishQ;
1211 lga = InsetQuotes::SwedishQ;
1214 lga = InsetQuotes::GermanQ;
1217 lga = InsetQuotes::PolishQ;
1220 lga = InsetQuotes::FrenchQ;
1223 lga = InsetQuotes::DanishQ;
1226 params.quotes_language = lga;
1228 int const pos = langModule->languageCO->currentIndex();
1229 params.language = lyx::languages.getLanguage(lang_[pos]);
1232 if (params.getTextClass().hasTocLevels()) {
1233 params.tocdepth = numberingModule->tocSL->value();
1234 params.secnumdepth = numberingModule->depthSL->value();
1238 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1239 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1240 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1241 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1244 params.graphicsDriver =
1245 tex_graphics[latexModule->psdriverCO->currentIndex()];
1248 params.setBaseClass(latexModule->classCO->currentIndex());
1251 params.clearLayoutModules();
1252 QStringList const selMods = selectedModel()->stringList();
1253 for (int i = 0; i != selMods.size(); ++i)
1254 params.addLayoutModule(lyx::fromqstr(selMods[i]));
1256 if (mathsModule->amsautoCB->isChecked()) {
1257 params.use_amsmath = BufferParams::package_auto;
1259 if (mathsModule->amsCB->isChecked())
1260 params.use_amsmath = BufferParams::package_on;
1262 params.use_amsmath = BufferParams::package_off;
1265 if (mathsModule->esintautoCB->isChecked())
1266 params.use_esint = BufferParams::package_auto;
1268 if (mathsModule->esintCB->isChecked())
1269 params.use_esint = BufferParams::package_on;
1271 params.use_esint = BufferParams::package_off;
1274 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1275 params.pagestyle = "default";
1277 docstring style_gui =
1278 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1279 for (size_t i = 0; i < pagestyles.size(); ++i)
1280 if (pagestyles[i].second == style_gui)
1281 params.pagestyle = pagestyles[i].first;
1284 switch (textLayoutModule->lspacingCO->currentIndex()) {
1286 params.spacing().set(Spacing::Single);
1289 params.spacing().set(Spacing::Onehalf);
1292 params.spacing().set(Spacing::Double);
1295 params.spacing().set(Spacing::Other,
1296 fromqstr(textLayoutModule->lspacingLE->text()));
1300 if (textLayoutModule->twoColumnCB->isChecked())
1305 // text should have passed validation
1306 params.listings_params =
1307 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1309 if (textLayoutModule->indentRB->isChecked())
1310 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1312 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1314 switch (textLayoutModule->skipCO->currentIndex()) {
1316 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1319 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1322 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1327 widgetsToLength(textLayoutModule->skipLE,
1328 textLayoutModule->skipLengthCO)
1330 params.setDefSkip(vs);
1334 // DocumentDefskipCB assures that this never happens
1335 // so Assert then !!! - jbl
1336 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1341 fromqstr(latexModule->optionsLE->text());
1343 params.float_placement = floatModule->get();
1347 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1350 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1352 params.fontsTypewriter =
1353 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1355 params.fontsSansScale = fontModule->scaleSansSB->value();
1357 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1359 params.fontsSC = fontModule->fontScCB->isChecked();
1361 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1363 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1364 fontModule->fontsDefaultCO->currentIndex()];
1366 if (fontModule->fontsizeCO->currentIndex() == 0)
1367 params.fontsize = "default";
1370 fromqstr(fontModule->fontsizeCO->currentText());
1373 params.papersize = PAPER_SIZE(
1374 pageLayoutModule->papersizeCO->currentIndex());
1376 // custom, A3, B3 and B4 paper sizes need geometry
1377 int psize = pageLayoutModule->papersizeCO->currentIndex();
1378 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1380 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1381 pageLayoutModule->paperwidthUnitCO);
1383 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1384 pageLayoutModule->paperheightUnitCO);
1386 if (pageLayoutModule->facingPagesCB->isChecked())
1387 params.sides = TwoSides;
1389 params.sides = OneSide;
1391 if (pageLayoutModule->landscapeRB->isChecked())
1392 params.orientation = ORIENTATION_LANDSCAPE;
1394 params.orientation = ORIENTATION_PORTRAIT;
1397 params.use_geometry =
1398 (!marginsModule->marginCB->isChecked()
1401 Ui::MarginsUi const * m(marginsModule);
1403 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1404 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1405 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1406 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1407 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1408 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1409 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1411 branchesModule->apply(params);
1414 PDFOptions & pdf = params.pdfoptions();
1415 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1416 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1417 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1418 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1419 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1421 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1422 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1423 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1424 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1426 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1427 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1428 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1429 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1430 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1431 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1432 if (pdfSupportModule->fullscreenCB->isChecked())
1433 pdf.pagemode = pdf.pagemode_fullscreen;
1435 pdf.pagemode.clear();
1436 pdf.quoted_options = fromqstr(pdfSupportModule->optionsLE->text());
1443 /** Return the position of val in the vector if found.
1444 If not found, return 0.
1447 static size_t findPos(vector<A> const & vec, A const & val)
1449 typename vector<A>::const_iterator it =
1450 find(vec.begin(), vec.end(), val);
1451 if (it == vec.end())
1453 return distance(vec.begin(), it);
1457 void GuiDocument::updateParams()
1463 void GuiDocument::updateParams(BufferParams const & params)
1465 // set the default unit
1466 Length::UNIT defaultUnit = Length::CM;
1467 switch (lyxrc.default_papersize) {
1468 case PAPER_DEFAULT: break;
1470 case PAPER_USLETTER:
1472 case PAPER_USEXECUTIVE:
1473 defaultUnit = Length::IN;
1482 defaultUnit = Length::CM;
1489 preambleModule->update(params, id());
1492 biblioModule->citeDefaultRB->setChecked(
1493 params.getEngine() == biblio::ENGINE_BASIC);
1495 biblioModule->citeNatbibRB->setChecked(
1496 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1497 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1499 biblioModule->citeStyleCO->setCurrentIndex(
1500 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1502 biblioModule->citeJurabibRB->setChecked(
1503 params.getEngine() == biblio::ENGINE_JURABIB);
1505 biblioModule->bibtopicCB->setChecked(
1506 params.use_bibtopic);
1508 // language & quotes
1509 int const pos = int(findPos(lang_,
1510 params.language->lang()));
1511 langModule->languageCO->setCurrentIndex(pos);
1513 langModule->quoteStyleCO->setCurrentIndex(
1514 params.quotes_language);
1516 bool default_enc = true;
1517 if (params.inputenc != "auto") {
1518 default_enc = false;
1519 if (params.inputenc == "default") {
1520 langModule->encodingCO->setCurrentIndex(0);
1522 int const i = langModule->encodingCO->findText(
1523 toqstr(params.inputenc));
1525 langModule->encodingCO->setCurrentIndex(i);
1527 // unknown encoding. Set to default.
1531 langModule->defaultencodingRB->setChecked(default_enc);
1532 langModule->otherencodingRB->setChecked(!default_enc);
1535 int const min_toclevel = textClass().min_toclevel();
1536 int const max_toclevel = textClass().max_toclevel();
1537 if (textClass().hasTocLevels()) {
1538 numberingModule->setEnabled(true);
1539 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1540 numberingModule->depthSL->setMaximum(max_toclevel);
1541 numberingModule->depthSL->setValue(params.secnumdepth);
1542 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1543 numberingModule->tocSL->setMaximum(max_toclevel);
1544 numberingModule->tocSL->setValue(params.tocdepth);
1547 numberingModule->setEnabled(false);
1548 numberingModule->tocTW->clear();
1552 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1553 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1554 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1555 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1556 bulletsModule->init();
1559 int nitem = findToken(tex_graphics, params.graphicsDriver);
1561 latexModule->psdriverCO->setCurrentIndex(nitem);
1564 mathsModule->amsCB->setChecked(
1565 params.use_amsmath == BufferParams::package_on);
1566 mathsModule->amsautoCB->setChecked(
1567 params.use_amsmath == BufferParams::package_auto);
1569 mathsModule->esintCB->setChecked(
1570 params.use_esint == BufferParams::package_on);
1571 mathsModule->esintautoCB->setChecked(
1572 params.use_esint == BufferParams::package_auto);
1574 switch (params.spacing().getSpace()) {
1575 case Spacing::Other: nitem = 3; break;
1576 case Spacing::Double: nitem = 2; break;
1577 case Spacing::Onehalf: nitem = 1; break;
1578 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1582 latexModule->classCO->setCurrentIndex(params.getBaseClass());
1584 updatePagestyle(textClass().opt_pagestyle(),
1587 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1588 if (params.spacing().getSpace() == Spacing::Other) {
1589 textLayoutModule->lspacingLE->setText(
1590 toqstr(params.spacing().getValueAsString()));
1594 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1595 textLayoutModule->indentRB->setChecked(true);
1597 textLayoutModule->skipRB->setChecked(true);
1600 switch (params.getDefSkip().kind()) {
1601 case VSpace::SMALLSKIP:
1604 case VSpace::MEDSKIP:
1607 case VSpace::BIGSKIP:
1610 case VSpace::LENGTH:
1613 string const length = params.getDefSkip().asLyXCommand();
1614 lengthToWidgets(textLayoutModule->skipLE,
1615 textLayoutModule->skipLengthCO,
1616 length, defaultUnit);
1623 textLayoutModule->skipCO->setCurrentIndex(skip);
1626 textLayoutModule->twoColumnCB->setChecked(
1627 params.columns == 2);
1629 // break listings_params to multiple lines
1631 InsetListingsParams(params.listings_params).separatedParams();
1632 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1634 if (!params.options.empty()) {
1635 latexModule->optionsLE->setText(
1636 toqstr(params.options));
1638 latexModule->optionsLE->setText(QString());
1641 floatModule->set(params.float_placement);
1644 updateFontsize(textClass().opt_fontsize(),
1647 int n = findToken(tex_fonts_roman, params.fontsRoman);
1649 fontModule->fontsRomanCO->setCurrentIndex(n);
1653 n = findToken(tex_fonts_sans, params.fontsSans);
1655 fontModule->fontsSansCO->setCurrentIndex(n);
1659 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1661 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1665 fontModule->fontScCB->setChecked(params.fontsSC);
1666 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1667 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1668 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1669 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1671 fontModule->fontsDefaultCO->setCurrentIndex(n);
1674 int const psize = params.papersize;
1675 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1676 setCustomPapersize(psize);
1678 bool const landscape =
1679 params.orientation == ORIENTATION_LANDSCAPE;
1680 pageLayoutModule->landscapeRB->setChecked(landscape);
1681 pageLayoutModule->portraitRB->setChecked(!landscape);
1683 pageLayoutModule->facingPagesCB->setChecked(
1684 params.sides == TwoSides);
1687 lengthToWidgets(pageLayoutModule->paperwidthLE,
1688 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1690 lengthToWidgets(pageLayoutModule->paperheightLE,
1691 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1694 Ui::MarginsUi * m = marginsModule;
1696 setMargins(!params.use_geometry);
1698 lengthToWidgets(m->topLE, m->topUnit,
1699 params.topmargin, defaultUnit);
1701 lengthToWidgets(m->bottomLE, m->bottomUnit,
1702 params.bottommargin, defaultUnit);
1704 lengthToWidgets(m->innerLE, m->innerUnit,
1705 params.leftmargin, defaultUnit);
1707 lengthToWidgets(m->outerLE, m->outerUnit,
1708 params.rightmargin, defaultUnit);
1710 lengthToWidgets(m->headheightLE, m->headheightUnit,
1711 params.headheight, defaultUnit);
1713 lengthToWidgets(m->headsepLE, m->headsepUnit,
1714 params.headsep, defaultUnit);
1716 lengthToWidgets(m->footskipLE, m->footskipUnit,
1717 params.footskip, defaultUnit);
1719 branchesModule->update(params);
1722 PDFOptions const & pdf = params.pdfoptions();
1723 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
1724 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
1725 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
1726 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
1727 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
1729 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
1730 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
1731 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
1733 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
1735 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
1736 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
1737 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
1738 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
1739 pdfSupportModule->backrefCB->setChecked(pdf.backref);
1740 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
1741 pdfSupportModule->fullscreenCB->setChecked
1742 (pdf.pagemode == pdf.pagemode_fullscreen);
1744 pdfSupportModule->optionsLE->setText(
1745 toqstr(pdf.quoted_options));
1748 updateEmbeddedFileList();
1752 void GuiDocument::applyView()
1758 void GuiDocument::saveDocDefault()
1760 // we have to apply the params first
1766 void GuiDocument::updateContents()
1768 //update list of available modules
1769 QStringList strlist;
1770 vector<string> const modNames = getModuleNames();
1771 vector<string>::const_iterator it = modNames.begin();
1772 for (; it != modNames.end(); ++it)
1773 strlist.push_back(toqstr(*it));
1774 available_model_.setStringList(strlist);
1775 //and selected ones, too
1776 QStringList strlist2;
1777 vector<string> const & selMods = getSelectedModules();
1778 it = selMods.begin();
1779 for (; it != selMods.end(); ++it)
1780 strlist2.push_back(toqstr(*it));
1781 //FIXME It'd be nice to make sure here that the selected
1782 //modules are consistent: That required modules are actually
1783 //selected, and that we don't have conflicts. If so, we could
1784 //at least pop up a warning.
1785 selected_model_.setStringList(strlist2);
1790 void GuiDocument::useClassDefaults()
1792 bp_.setBaseClass(latexModule->classCO->currentIndex());
1793 bp_.useClassDefaults();
1798 bool GuiDocument::isValid()
1800 return validate_listings_params().empty();
1804 char const * const GuiDocument::fontfamilies[5] = {
1805 "default", "rmdefault", "sfdefault", "ttdefault", ""
1809 char const * GuiDocument::fontfamilies_gui[5] = {
1810 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
1814 bool GuiDocument::initialiseParams(string const &)
1816 bp_ = buffer().params();
1822 void GuiDocument::clearParams()
1824 bp_ = BufferParams();
1828 BufferId GuiDocument::id() const
1834 vector<string> const & GuiDocument::getModuleNames()
1836 return moduleNames_;
1840 vector<string> const & GuiDocument::getSelectedModules()
1842 return params().getModules();
1846 TextClass const & GuiDocument::textClass() const
1848 return textclasslist[bp_.getBaseClass()];
1852 static void dispatch_bufferparams(Dialog const & dialog,
1853 BufferParams const & bp, kb_action lfun)
1856 ss << "\\begin_header\n";
1858 ss << "\\end_header\n";
1859 dialog.dispatch(FuncRequest(lfun, ss.str()));
1863 void GuiDocument::dispatchParams()
1865 // This must come first so that a language change is correctly noticed
1868 // Apply the BufferParams. Note that this will set the base class
1869 // and then update the buffer's layout.
1870 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
1872 // Generate the colours requested by each new branch.
1873 BranchList & branchlist = params().branchlist();
1874 if (!branchlist.empty()) {
1875 BranchList::const_iterator it = branchlist.begin();
1876 BranchList::const_iterator const end = branchlist.end();
1877 for (; it != end; ++it) {
1878 docstring const & current_branch = it->getBranch();
1879 Branch const * branch = branchlist.find(current_branch);
1880 string const x11hexname = X11hexname(branch->getColor());
1881 // display the new color
1882 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
1883 dispatch(FuncRequest(LFUN_SET_COLOR, str));
1886 // Open insets of selected branches, close deselected ones
1887 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
1890 // FIXME: If we used an LFUN, we would not need those two lines:
1891 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
1895 void GuiDocument::setLanguage() const
1897 Language const * const newL = bp_.language;
1898 if (buffer().params().language == newL)
1901 string const & lang_name = newL->lang();
1902 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
1906 void GuiDocument::saveAsDefault() const
1908 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
1912 bool GuiDocument::isFontAvailable(string const & font) const
1914 if (font == "default" || font == "cmr"
1915 || font == "cmss" || font == "cmtt")
1916 // these are standard
1918 if (font == "lmodern" || font == "lmss" || font == "lmtt")
1919 return LaTeXFeatures::isAvailable("lmodern");
1920 if (font == "times" || font == "palatino"
1921 || font == "helvet" || font == "courier")
1922 return LaTeXFeatures::isAvailable("psnfss");
1923 if (font == "cmbr" || font == "cmtl")
1924 return LaTeXFeatures::isAvailable("cmbright");
1925 if (font == "utopia")
1926 return LaTeXFeatures::isAvailable("utopia")
1927 || LaTeXFeatures::isAvailable("fourier");
1928 if (font == "beraserif" || font == "berasans"
1929 || font == "beramono")
1930 return LaTeXFeatures::isAvailable("bera");
1931 return LaTeXFeatures::isAvailable(font);
1935 bool GuiDocument::providesOSF(string const & font) const
1938 return isFontAvailable("eco");
1939 if (font == "palatino")
1940 return isFontAvailable("mathpazo");
1945 bool GuiDocument::providesSC(string const & font) const
1947 if (font == "palatino")
1948 return isFontAvailable("mathpazo");
1949 if (font == "utopia")
1950 return isFontAvailable("fourier");
1955 bool GuiDocument::providesScale(string const & font) const
1957 return font == "helvet" || font == "luximono"
1958 || font == "berasans" || font == "beramono";
1962 void GuiDocument::loadModuleNames ()
1964 moduleNames_.clear();
1965 LyXModuleList::const_iterator it = moduleList.begin();
1966 for (; it != moduleList.end(); ++it)
1967 moduleNames_.push_back(it->getName());
1968 if (!moduleNames_.empty())
1969 sort(moduleNames_.begin(), moduleNames_.end());
1973 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
1976 } // namespace frontend
1979 #include "GuiDocument_moc.cpp"