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 "GuiApplication.h"
17 #include "GuiBranches.h"
18 #include "GuiIndices.h"
19 #include "GuiSelectionManager.h"
20 #include "LaTeXHighlighter.h"
21 #include "LengthCombo.h"
22 #include "PanelStack.h"
23 #include "Validator.h"
25 #include "LayoutFile.h"
26 #include "BranchList.h"
27 #include "buffer_funcs.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
32 #include "ColorCache.h"
34 #include "FloatPlacement.h"
36 #include "FuncRequest.h"
38 #include "IndicesList.h"
40 #include "LaTeXFeatures.h"
42 #include "LayoutModuleList.h"
44 #include "ModuleList.h"
45 #include "OutputParams.h"
46 #include "PDFOptions.h"
47 #include "qt_helpers.h"
50 #include "insets/InsetListingsParams.h"
52 #include "support/debug.h"
53 #include "support/FileName.h"
54 #include "support/filetools.h"
55 #include "support/gettext.h"
56 #include "support/lstrings.h"
58 #include "frontends/alert.h"
60 #include <QAbstractItemModel>
62 #include <QColorDialog>
63 #include <QCloseEvent>
64 #include <QFontDatabase>
66 #include <QTextCursor>
76 // a style sheet for buttons
77 // this is for example used for the background color setting button
78 static inline QString colorButtonStyleSheet(QColor const & bgColor)
80 if (bgColor.isValid()) {
81 QString rc = QLatin1String("background:");
90 using namespace lyx::support;
95 char const * const tex_graphics[] =
97 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
98 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
99 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
100 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
105 char const * const tex_graphics_gui[] =
107 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
108 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
109 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
110 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
111 "XeTeX", N_("None"), ""
115 char const * const tex_fonts_roman[] =
117 "default", "cmr", "lmodern", "ae", "times", "palatino",
118 "charter", "newcent", "bookman", "utopia", "beraserif",
119 "ccfonts", "chancery", ""
123 char const * tex_fonts_roman_gui[] =
125 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
126 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
127 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
128 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
133 char const * const tex_fonts_sans[] =
135 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
139 char const * tex_fonts_sans_gui[] =
141 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
142 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
146 char const * const tex_fonts_monospaced[] =
148 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
152 char const * tex_fonts_monospaced_gui[] =
154 N_("Default"), N_("Computer Modern Typewriter"),
155 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
156 N_("LuxiMono"), N_("CM Typewriter Light"), ""
160 char const * backref_opts[] =
162 "false", "section", "slide", "page", ""
166 char const * backref_opts_gui[] =
168 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
172 vector<pair<string, QString> > pagestyles;
175 } // anonymous namespace
179 RGBColor set_backgroundcolor;
182 // used when sorting the textclass list.
183 class less_textclass_avail_desc
184 : public binary_function<string, string, int>
187 bool operator()(string const & lhs, string const & rhs) const
189 // Ordering criteria:
190 // 1. Availability of text class
191 // 2. Description (lexicographic)
192 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
193 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
194 int const rel = compare_no_case(
195 translateIfPossible(from_utf8(tc1.description())),
196 translateIfPossible(from_utf8(tc2.description())));
197 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
198 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && rel < 0);
207 vector<string> getRequiredList(string const & modName)
209 LyXModule const * const mod = moduleList[modName];
211 return vector<string>(); //empty such thing
212 return mod->getRequiredModules();
216 vector<string> getExcludedList(string const & modName)
218 LyXModule const * const mod = moduleList[modName];
220 return vector<string>(); //empty such thing
221 return mod->getExcludedModules();
225 docstring getModuleDescription(string const & modName)
227 LyXModule const * const mod = moduleList[modName];
229 return _("Module not found!");
231 return translateIfPossible(from_utf8(mod->getDescription()));
235 vector<string> getPackageList(string const & modName)
237 LyXModule const * const mod = moduleList[modName];
239 return vector<string>(); //empty such thing
240 return mod->getPackageList();
244 bool isModuleAvailable(string const & modName)
246 LyXModule * mod = moduleList[modName];
249 return mod->isAvailable();
252 } // anonymous namespace
255 /////////////////////////////////////////////////////////////////////
257 // ModuleSelectionManager
259 /////////////////////////////////////////////////////////////////////
261 /// SelectionManager for use with modules
262 class ModuleSelectionManager : public GuiSelectionManager
266 ModuleSelectionManager(
267 QListView * availableLV,
268 QListView * selectedLV,
272 QPushButton * downPB,
273 GuiIdListModel * availableModel,
274 GuiIdListModel * selectedModel,
275 GuiDocument const * container)
276 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
277 upPB, downPB, availableModel, selectedModel), container_(container)
280 void updateProvidedModules(LayoutModuleList const & pm)
281 { provided_modules_ = pm.list(); }
283 void updateExcludedModules(LayoutModuleList const & em)
284 { excluded_modules_ = em.list(); }
287 virtual void updateAddPB();
289 virtual void updateUpPB();
291 virtual void updateDownPB();
293 virtual void updateDelPB();
294 /// returns availableModel as a GuiIdListModel
295 GuiIdListModel * getAvailableModel()
297 return dynamic_cast<GuiIdListModel *>(availableModel);
299 /// returns selectedModel as a GuiIdListModel
300 GuiIdListModel * getSelectedModel()
302 return dynamic_cast<GuiIdListModel *>(selectedModel);
304 /// keeps a list of the modules the text class provides
305 std::list<std::string> provided_modules_;
307 std::list<std::string> excluded_modules_;
309 GuiDocument const * container_;
312 void ModuleSelectionManager::updateAddPB()
314 int const arows = availableModel->rowCount();
315 QModelIndexList const avail_sels =
316 availableLV->selectionModel()->selectedIndexes();
318 // disable if there aren't any modules (?), if none of them is chosen
319 // in the dialog, or if the chosen one is already selected for use.
320 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
321 addPB->setEnabled(false);
325 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
326 string const modname = getAvailableModel()->getIDString(idx.row());
329 container_->params().moduleCanBeAdded(modname);
330 addPB->setEnabled(enable);
334 void ModuleSelectionManager::updateDownPB()
336 int const srows = selectedModel->rowCount();
338 downPB->setEnabled(false);
341 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
342 int const curRow = curidx.row();
343 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
344 downPB->setEnabled(false);
348 // determine whether immediately succeding element requires this one
349 string const curmodname = getSelectedModel()->getIDString(curRow);
350 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
352 vector<string> reqs = getRequiredList(nextmodname);
354 // if it doesn't require anything....
356 downPB->setEnabled(true);
360 // Enable it if this module isn't required.
361 // FIXME This should perhaps be more flexible and check whether, even
362 // if the next one is required, there is also an earlier one that will do.
364 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
367 void ModuleSelectionManager::updateUpPB()
369 int const srows = selectedModel->rowCount();
371 upPB->setEnabled(false);
375 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
376 int curRow = curIdx.row();
377 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
378 upPB->setEnabled(false);
381 string const curmodname = getSelectedModel()->getIDString(curRow);
383 // determine whether immediately preceding element is required by this one
384 vector<string> reqs = getRequiredList(curmodname);
386 // if this one doesn't require anything....
388 upPB->setEnabled(true);
393 // Enable it if the preceding module isn't required.
394 // NOTE This is less flexible than it might be. We could check whether, even
395 // if the previous one is required, there is an earlier one that would do.
396 string const premod = getSelectedModel()->getIDString(curRow - 1);
397 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
400 void ModuleSelectionManager::updateDelPB()
402 int const srows = selectedModel->rowCount();
404 deletePB->setEnabled(false);
408 QModelIndex const & curidx =
409 selectedLV->selectionModel()->currentIndex();
410 int const curRow = curidx.row();
411 if (curRow < 0 || curRow >= srows) { // invalid index?
412 deletePB->setEnabled(false);
416 string const curmodname = getSelectedModel()->getIDString(curRow);
418 // We're looking here for a reason NOT to enable the button. If we
419 // find one, we disable it and return. If we don't, we'll end up at
420 // the end of the function, and then we enable it.
421 for (int i = curRow + 1; i < srows; ++i) {
422 string const thisMod = getSelectedModel()->getIDString(i);
423 vector<string> reqs = getRequiredList(thisMod);
424 //does this one require us?
425 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
429 // OK, so this module requires us
430 // is there an EARLIER module that also satisfies the require?
431 // NOTE We demand that it be earlier to keep the list of modules
432 // consistent with the rule that a module must be proceeded by a
433 // required module. There would be more flexible ways to proceed,
434 // but that would be a lot more complicated, and the logic here is
435 // already complicated. (That's why I've left the debugging code.)
436 // lyxerr << "Testing " << thisMod << std::endl;
437 bool foundone = false;
438 for (int j = 0; j < curRow; ++j) {
439 string const mod = getSelectedModel()->getIDString(j);
440 // lyxerr << "In loop: Testing " << mod << std::endl;
441 // do we satisfy the require?
442 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
443 // lyxerr << mod << " does the trick." << std::endl;
448 // did we find a module to satisfy the require?
450 // lyxerr << "No matching module found." << std::endl;
451 deletePB->setEnabled(false);
455 // lyxerr << "All's well that ends well." << std::endl;
456 deletePB->setEnabled(true);
460 /////////////////////////////////////////////////////////////////////
464 /////////////////////////////////////////////////////////////////////
466 PreambleModule::PreambleModule() : current_id_(0)
468 // This is not a memory leak. The object will be destroyed
470 (void) new LaTeXHighlighter(preambleTE->document());
471 setFocusProxy(preambleTE);
472 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
476 void PreambleModule::update(BufferParams const & params, BufferId id)
478 QString preamble = toqstr(params.preamble);
479 // Nothing to do if the params and preamble are unchanged.
480 if (id == current_id_
481 && preamble == preambleTE->document()->toPlainText())
484 QTextCursor cur = preambleTE->textCursor();
485 // Save the coords before switching to the new one.
486 preamble_coords_[current_id_] =
487 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
489 // Save the params address for further use.
491 preambleTE->document()->setPlainText(preamble);
492 Coords::const_iterator it = preamble_coords_.find(current_id_);
493 if (it == preamble_coords_.end())
494 // First time we open this one.
495 preamble_coords_[current_id_] = make_pair(0, 0);
497 // Restore saved coords.
498 QTextCursor cur = preambleTE->textCursor();
499 cur.setPosition(it->second.first);
500 preambleTE->setTextCursor(cur);
501 preambleTE->verticalScrollBar()->setValue(it->second.second);
506 void PreambleModule::apply(BufferParams & params)
508 params.preamble = fromqstr(preambleTE->document()->toPlainText());
512 void PreambleModule::closeEvent(QCloseEvent * e)
514 // Save the coords before closing.
515 QTextCursor cur = preambleTE->textCursor();
516 preamble_coords_[current_id_] =
517 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
522 /////////////////////////////////////////////////////////////////////
526 /////////////////////////////////////////////////////////////////////
529 GuiDocument::GuiDocument(GuiView & lv)
530 : GuiDialog(lv, "document", qt_("Document Settings"))
534 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
535 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
536 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
537 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
539 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
540 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
542 // Manage the restore, ok, apply, restore and cancel/close buttons
543 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
545 bc().setApply(applyPB);
546 bc().setCancel(closePB);
547 bc().setRestore(restorePB);
549 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
551 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
552 this, SLOT(change_adaptor()));
553 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
554 this, SLOT(setLSpacing(int)));
555 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
556 this, SLOT(change_adaptor()));
558 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
559 this, SLOT(change_adaptor()));
560 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
561 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
562 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
563 this, SLOT(change_adaptor()));
564 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
565 this, SLOT(setIndent(int)));
566 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
567 this, SLOT(change_adaptor()));
568 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
569 this, SLOT(change_adaptor()));
571 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
572 this, SLOT(change_adaptor()));
573 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
574 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
575 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
576 this, SLOT(change_adaptor()));
577 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
578 this, SLOT(setSkip(int)));
579 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
580 this, SLOT(change_adaptor()));
581 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
582 this, SLOT(change_adaptor()));
584 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
585 this, SLOT(enableIndent(bool)));
586 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
587 this, SLOT(enableSkip(bool)));
589 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
590 this, SLOT(change_adaptor()));
591 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
592 this, SLOT(setColSep()));
593 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
594 this, SLOT(change_adaptor()));
595 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
596 this, SLOT(change_adaptor()));
597 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
598 this, SLOT(setListingsMessage()));
599 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
600 this, SLOT(setListingsMessage()));
601 textLayoutModule->listingsTB->setPlainText(
602 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
603 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
604 textLayoutModule->lspacingLE));
605 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
606 textLayoutModule->indentLE));
607 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
608 textLayoutModule->skipLE));
610 textLayoutModule->indentCO->addItem(qt_("Default"));
611 textLayoutModule->indentCO->addItem(qt_("Custom"));
612 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
613 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
614 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
615 textLayoutModule->skipCO->addItem(qt_("Length"));
616 textLayoutModule->lspacingCO->insertItem(
617 Spacing::Single, qt_("Single"));
618 textLayoutModule->lspacingCO->insertItem(
619 Spacing::Onehalf, qt_("OneHalf"));
620 textLayoutModule->lspacingCO->insertItem(
621 Spacing::Double, qt_("Double"));
622 textLayoutModule->lspacingCO->insertItem(
623 Spacing::Other, qt_("Custom"));
624 // initialize the length validator
625 bc().addCheckedLineEdit(textLayoutModule->indentLE);
626 bc().addCheckedLineEdit(textLayoutModule->skipLE);
629 outputModule = new UiWidget<Ui::OutputUi>;
631 connect(outputModule->xetexCB, SIGNAL(clicked()),
632 this, SLOT(change_adaptor()));
633 connect(outputModule->xetexCB, SIGNAL(toggled(bool)),
634 this, SLOT(xetexChanged(bool)));
635 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
636 this, SLOT(change_adaptor()));
639 fontModule = new UiWidget<Ui::FontUi>;
640 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
641 this, SLOT(change_adaptor()));
642 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
643 this, SLOT(romanChanged(int)));
644 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
645 this, SLOT(change_adaptor()));
646 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
647 this, SLOT(sansChanged(int)));
648 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
649 this, SLOT(change_adaptor()));
650 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
651 this, SLOT(ttChanged(int)));
652 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
653 this, SLOT(change_adaptor()));
654 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
655 this, SLOT(change_adaptor()));
656 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
657 this, SLOT(change_adaptor()));
658 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
659 this, SLOT(change_adaptor()));
660 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
661 this, SLOT(change_adaptor()));
662 connect(fontModule->fontScCB, SIGNAL(clicked()),
663 this, SLOT(change_adaptor()));
664 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
665 this, SLOT(change_adaptor()));
669 fontModule->fontsizeCO->addItem(qt_("Default"));
670 fontModule->fontsizeCO->addItem(qt_("10"));
671 fontModule->fontsizeCO->addItem(qt_("11"));
672 fontModule->fontsizeCO->addItem(qt_("12"));
674 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
675 fontModule->fontsDefaultCO->addItem(
676 qt_(GuiDocument::fontfamilies_gui[n]));
679 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
681 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
682 this, SLOT(papersizeChanged(int)));
683 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
684 this, SLOT(papersizeChanged(int)));
685 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
686 this, SLOT(portraitChanged()));
687 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
688 this, SLOT(change_adaptor()));
689 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
690 this, SLOT(change_adaptor()));
691 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
692 this, SLOT(change_adaptor()));
693 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
694 this, SLOT(change_adaptor()));
695 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
696 this, SLOT(change_adaptor()));
697 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
698 this, SLOT(change_adaptor()));
699 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
700 this, SLOT(change_adaptor()));
701 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
702 this, SLOT(change_adaptor()));
703 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
704 this, SLOT(change_adaptor()));
705 connect(pageLayoutModule->backgroundPB, SIGNAL(clicked()),
706 this, SLOT(changeBackgroundColor()));
707 connect(pageLayoutModule->delbackgroundTB, SIGNAL(clicked()),
708 this, SLOT(deleteBackgroundColor()));
710 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
711 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
712 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
713 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
714 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
715 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
716 pageLayoutModule->paperheightL);
717 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
718 pageLayoutModule->paperwidthL);
721 QComboBox * cb = pageLayoutModule->papersizeCO;
722 cb->addItem(qt_("Default"));
723 cb->addItem(qt_("Custom"));
724 cb->addItem(qt_("US letter"));
725 cb->addItem(qt_("US legal"));
726 cb->addItem(qt_("US executive"));
727 cb->addItem(qt_("A3"));
728 cb->addItem(qt_("A4"));
729 cb->addItem(qt_("A5"));
730 cb->addItem(qt_("B3"));
731 cb->addItem(qt_("B4"));
732 cb->addItem(qt_("B5"));
733 // remove the %-items from the unit choice
734 pageLayoutModule->paperwidthUnitCO->noPercents();
735 pageLayoutModule->paperheightUnitCO->noPercents();
736 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
737 pageLayoutModule->paperheightLE));
738 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
739 pageLayoutModule->paperwidthLE));
742 marginsModule = new UiWidget<Ui::MarginsUi>;
744 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
745 this, SLOT(setCustomMargins(bool)));
746 connect(marginsModule->marginCB, SIGNAL(clicked()),
747 this, SLOT(change_adaptor()));
748 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
749 this, SLOT(change_adaptor()));
750 connect(marginsModule->topUnit, SIGNAL(activated(int)),
751 this, SLOT(change_adaptor()));
752 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
753 this, SLOT(change_adaptor()));
754 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
755 this, SLOT(change_adaptor()));
756 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
757 this, SLOT(change_adaptor()));
758 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
759 this, SLOT(change_adaptor()));
760 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
761 this, SLOT(change_adaptor()));
762 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
763 this, SLOT(change_adaptor()));
764 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
765 this, SLOT(change_adaptor()));
766 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
767 this, SLOT(change_adaptor()));
768 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
769 this, SLOT(change_adaptor()));
770 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
771 this, SLOT(change_adaptor()));
772 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
773 this, SLOT(change_adaptor()));
774 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
775 this, SLOT(change_adaptor()));
776 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
777 this, SLOT(change_adaptor()));
778 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
779 this, SLOT(change_adaptor()));
780 marginsModule->topLE->setValidator(unsignedLengthValidator(
781 marginsModule->topLE));
782 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
783 marginsModule->bottomLE));
784 marginsModule->innerLE->setValidator(unsignedLengthValidator(
785 marginsModule->innerLE));
786 marginsModule->outerLE->setValidator(unsignedLengthValidator(
787 marginsModule->outerLE));
788 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
789 marginsModule->headsepLE));
790 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
791 marginsModule->headheightLE));
792 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
793 marginsModule->footskipLE));
794 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
795 marginsModule->columnsepLE));
797 bc().addCheckedLineEdit(marginsModule->topLE,
798 marginsModule->topL);
799 bc().addCheckedLineEdit(marginsModule->bottomLE,
800 marginsModule->bottomL);
801 bc().addCheckedLineEdit(marginsModule->innerLE,
802 marginsModule->innerL);
803 bc().addCheckedLineEdit(marginsModule->outerLE,
804 marginsModule->outerL);
805 bc().addCheckedLineEdit(marginsModule->headsepLE,
806 marginsModule->headsepL);
807 bc().addCheckedLineEdit(marginsModule->headheightLE,
808 marginsModule->headheightL);
809 bc().addCheckedLineEdit(marginsModule->footskipLE,
810 marginsModule->footskipL);
811 bc().addCheckedLineEdit(marginsModule->columnsepLE,
812 marginsModule->columnsepL);
815 langModule = new UiWidget<Ui::LanguageUi>;
817 connect(langModule->languageCO, SIGNAL(activated(int)),
818 this, SLOT(change_adaptor()));
819 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
820 this, SLOT(change_adaptor()));
821 connect(langModule->otherencodingRB, SIGNAL(clicked()),
822 this, SLOT(change_adaptor()));
823 connect(langModule->encodingCO, SIGNAL(activated(int)),
824 this, SLOT(change_adaptor()));
825 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
826 this, SLOT(change_adaptor()));
828 QAbstractItemModel * language_model = guiApp->languageModel();
829 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
830 language_model->sort(0);
831 langModule->languageCO->setModel(language_model);
833 // Always put the default encoding in the first position.
834 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
835 QStringList encodinglist;
836 Encodings::const_iterator it = encodings.begin();
837 Encodings::const_iterator const end = encodings.end();
838 for (; it != end; ++it)
839 encodinglist.append(qt_(it->guiName()));
841 langModule->encodingCO->addItems(encodinglist);
843 langModule->quoteStyleCO->addItem(qt_("``text''"));
844 langModule->quoteStyleCO->addItem(qt_("''text''"));
845 langModule->quoteStyleCO->addItem(qt_(",,text``"));
846 langModule->quoteStyleCO->addItem(qt_(",,text''"));
847 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
848 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
851 numberingModule = new UiWidget<Ui::NumberingUi>;
853 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
854 this, SLOT(change_adaptor()));
855 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
856 this, SLOT(change_adaptor()));
857 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
858 this, SLOT(updateNumbering()));
859 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
860 this, SLOT(updateNumbering()));
861 numberingModule->tocTW->setColumnCount(3);
862 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
863 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
864 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
867 biblioModule = new UiWidget<Ui::BiblioUi>;
868 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
869 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
870 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
871 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
873 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
874 this, SLOT(change_adaptor()));
875 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
876 this, SLOT(change_adaptor()));
877 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
878 this, SLOT(change_adaptor()));
879 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
880 this, SLOT(change_adaptor()));
881 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
882 this, SLOT(change_adaptor()));
883 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
884 this, SLOT(bibtexChanged(int)));
885 connect(biblioModule->bibtexOptionsED, SIGNAL(textChanged(QString)),
886 this, SLOT(change_adaptor()));
888 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
889 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
890 biblioModule->citeStyleCO->setCurrentIndex(0);
892 biblioModule->bibtexCO->clear();
894 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
895 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
896 it != lyxrc.bibtex_alternatives.end(); ++it) {
897 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
898 biblioModule->bibtexCO->addItem(command, command);
902 indicesModule = new GuiIndices;
903 connect(indicesModule, SIGNAL(changed()),
904 this, SLOT(change_adaptor()));
907 mathsModule = new UiWidget<Ui::MathsUi>;
908 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
909 mathsModule->amsCB, SLOT(setDisabled(bool)));
910 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
911 mathsModule->esintCB, SLOT(setDisabled(bool)));
913 connect(mathsModule->amsCB, SIGNAL(clicked()),
914 this, SLOT(change_adaptor()));
915 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
916 this, SLOT(change_adaptor()));
917 connect(mathsModule->esintCB, SIGNAL(clicked()),
918 this, SLOT(change_adaptor()));
919 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
920 this, SLOT(change_adaptor()));
922 latexModule = new UiWidget<Ui::LaTeXUi>;
924 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
925 this, SLOT(change_adaptor()));
926 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
927 this, SLOT(change_adaptor()));
928 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
929 this, SLOT(change_adaptor()));
930 connect(latexModule->classCO, SIGNAL(activated(int)),
931 this, SLOT(classChanged()));
932 connect(latexModule->classCO, SIGNAL(activated(int)),
933 this, SLOT(change_adaptor()));
934 connect(latexModule->layoutPB, SIGNAL(clicked()),
935 this, SLOT(browseLayout()));
936 connect(latexModule->layoutPB, SIGNAL(clicked()),
937 this, SLOT(change_adaptor()));
938 connect(latexModule->childDocGB, SIGNAL(clicked()),
939 this, SLOT(change_adaptor()));
940 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
941 this, SLOT(change_adaptor()));
942 connect(latexModule->childDocPB, SIGNAL(clicked()),
943 this, SLOT(browseMaster()));
945 // postscript drivers
946 for (int n = 0; tex_graphics[n][0]; ++n) {
947 QString enc = qt_(tex_graphics_gui[n]);
948 latexModule->psdriverCO->addItem(enc);
951 latexModule->classCO->setModel(&classes_model_);
952 LayoutFileList const & bcl = LayoutFileList::get();
953 vector<LayoutFileIndex> classList = bcl.classList();
954 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
956 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
957 vector<LayoutFileIndex>::const_iterator cen = classList.end();
958 for (int i = 0; cit != cen; ++cit, ++i) {
959 LayoutFile const & tc = bcl[*cit];
960 docstring item = (tc.isTeXClassAvailable()) ?
961 from_utf8(tc.description()) :
962 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
963 classes_model_.insertRow(i, toqstr(item), *cit);
967 branchesModule = new GuiBranches;
968 connect(branchesModule, SIGNAL(changed()),
969 this, SLOT(change_adaptor()));
970 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
971 this, SLOT(branchesRename(docstring const &, docstring const &)));
972 updateUnknownBranches();
975 preambleModule = new PreambleModule;
976 connect(preambleModule, SIGNAL(changed()),
977 this, SLOT(change_adaptor()));
980 bulletsModule = new BulletsModule;
981 connect(bulletsModule, SIGNAL(changed()),
982 this, SLOT(change_adaptor()));
985 modulesModule = new UiWidget<Ui::ModulesUi>;
988 new ModuleSelectionManager(modulesModule->availableLV,
989 modulesModule->selectedLV,
990 modulesModule->addPB, modulesModule->deletePB,
991 modulesModule->upPB, modulesModule->downPB,
992 availableModel(), selectedModel(), this);
993 connect(selectionManager, SIGNAL(updateHook()),
994 this, SLOT(updateModuleInfo()));
995 connect(selectionManager, SIGNAL(updateHook()),
996 this, SLOT(change_adaptor()));
997 connect(selectionManager, SIGNAL(selectionChanged()),
998 this, SLOT(modulesChanged()));
1001 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1003 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1004 this, SLOT(change_adaptor()));
1005 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1006 this, SLOT(change_adaptor()));
1007 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1008 this, SLOT(change_adaptor()));
1009 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1010 this, SLOT(change_adaptor()));
1011 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1012 this, SLOT(change_adaptor()));
1013 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1014 this, SLOT(change_adaptor()));
1015 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1016 this, SLOT(change_adaptor()));
1017 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1018 this, SLOT(change_adaptor()));
1019 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1020 this, SLOT(change_adaptor()));
1021 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1022 this, SLOT(change_adaptor()));
1023 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1024 this, SLOT(change_adaptor()));
1025 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1026 this, SLOT(change_adaptor()));
1027 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1028 this, SLOT(change_adaptor()));
1029 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1030 this, SLOT(change_adaptor()));
1031 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1032 this, SLOT(change_adaptor()));
1033 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1034 this, SLOT(change_adaptor()));
1036 for (int i = 0; backref_opts[i][0]; ++i)
1037 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1040 floatModule = new FloatPlacement;
1041 connect(floatModule, SIGNAL(changed()),
1042 this, SLOT(change_adaptor()));
1044 docPS->addPanel(latexModule, qt_("Document Class"));
1045 docPS->addPanel(modulesModule, qt_("Modules"));
1046 docPS->addPanel(fontModule, qt_("Fonts"));
1047 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1048 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1049 docPS->addPanel(marginsModule, qt_("Page Margins"));
1050 docPS->addPanel(langModule, qt_("Language"));
1051 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1052 docPS->addPanel(biblioModule, qt_("Bibliography"));
1053 docPS->addPanel(indicesModule, qt_("Indexes"));
1054 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1055 docPS->addPanel(mathsModule, qt_("Math Options"));
1056 docPS->addPanel(floatModule, qt_("Float Placement"));
1057 docPS->addPanel(bulletsModule, qt_("Bullets"));
1058 docPS->addPanel(branchesModule, qt_("Branches"));
1059 docPS->addPanel(outputModule, qt_("Output"));
1060 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1061 docPS->setCurrentPanel(qt_("Document Class"));
1062 // FIXME: hack to work around resizing bug in Qt >= 4.2
1063 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1064 #if QT_VERSION >= 0x040200
1065 docPS->updateGeometry();
1070 void GuiDocument::showPreamble()
1072 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
1076 void GuiDocument::saveDefaultClicked()
1082 void GuiDocument::useDefaultsClicked()
1088 void GuiDocument::change_adaptor()
1094 QString GuiDocument::validateListingsParameters()
1096 // use a cache here to avoid repeated validation
1097 // of the same parameters
1098 static string param_cache;
1099 static QString msg_cache;
1101 if (textLayoutModule->bypassCB->isChecked())
1104 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1105 if (params != param_cache) {
1106 param_cache = params;
1107 msg_cache = toqstr(InsetListingsParams(params).validate());
1113 void GuiDocument::setListingsMessage()
1115 static bool isOK = true;
1116 QString msg = validateListingsParameters();
1117 if (msg.isEmpty()) {
1121 // listingsTB->setTextColor("black");
1122 textLayoutModule->listingsTB->setPlainText(
1123 qt_("Input listings parameters on the right. "
1124 "Enter ? for a list of parameters."));
1127 // listingsTB->setTextColor("red");
1128 textLayoutModule->listingsTB->setPlainText(msg);
1133 void GuiDocument::setLSpacing(int item)
1135 textLayoutModule->lspacingLE->setEnabled(item == 3);
1139 void GuiDocument::setIndent(int item)
1141 bool const enable = (item == 1);
1142 textLayoutModule->indentLE->setEnabled(enable);
1143 textLayoutModule->indentLengthCO->setEnabled(enable);
1144 textLayoutModule->skipLE->setEnabled(false);
1145 textLayoutModule->skipLengthCO->setEnabled(false);
1150 void GuiDocument::enableIndent(bool indent)
1152 textLayoutModule->skipLE->setEnabled(!indent);
1153 textLayoutModule->skipLengthCO->setEnabled(!indent);
1155 setIndent(textLayoutModule->indentCO->currentIndex());
1159 void GuiDocument::setSkip(int item)
1161 bool const enable = (item == 3);
1162 textLayoutModule->skipLE->setEnabled(enable);
1163 textLayoutModule->skipLengthCO->setEnabled(enable);
1168 void GuiDocument::enableSkip(bool skip)
1170 textLayoutModule->indentLE->setEnabled(!skip);
1171 textLayoutModule->indentLengthCO->setEnabled(!skip);
1173 setSkip(textLayoutModule->skipCO->currentIndex());
1177 void GuiDocument::portraitChanged()
1179 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1183 void GuiDocument::setMargins(bool custom)
1185 bool const extern_geometry =
1186 documentClass().provides("geometry");
1187 marginsModule->marginCB->setEnabled(!extern_geometry);
1188 if (extern_geometry) {
1189 marginsModule->marginCB->setChecked(false);
1190 setCustomMargins(true);
1193 marginsModule->marginCB->setChecked(custom);
1194 setCustomMargins(custom);
1198 void GuiDocument::papersizeChanged(int paper_size)
1200 setCustomPapersize(paper_size == 1);
1204 void GuiDocument::setCustomPapersize(bool custom)
1206 pageLayoutModule->paperwidthL->setEnabled(custom);
1207 pageLayoutModule->paperwidthLE->setEnabled(custom);
1208 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1209 pageLayoutModule->paperheightL->setEnabled(custom);
1210 pageLayoutModule->paperheightLE->setEnabled(custom);
1211 pageLayoutModule->paperheightLE->setFocus();
1212 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1216 void GuiDocument::setColSep()
1218 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1222 void GuiDocument::setCustomMargins(bool custom)
1224 marginsModule->topL->setEnabled(!custom);
1225 marginsModule->topLE->setEnabled(!custom);
1226 marginsModule->topUnit->setEnabled(!custom);
1228 marginsModule->bottomL->setEnabled(!custom);
1229 marginsModule->bottomLE->setEnabled(!custom);
1230 marginsModule->bottomUnit->setEnabled(!custom);
1232 marginsModule->innerL->setEnabled(!custom);
1233 marginsModule->innerLE->setEnabled(!custom);
1234 marginsModule->innerUnit->setEnabled(!custom);
1236 marginsModule->outerL->setEnabled(!custom);
1237 marginsModule->outerLE->setEnabled(!custom);
1238 marginsModule->outerUnit->setEnabled(!custom);
1240 marginsModule->headheightL->setEnabled(!custom);
1241 marginsModule->headheightLE->setEnabled(!custom);
1242 marginsModule->headheightUnit->setEnabled(!custom);
1244 marginsModule->headsepL->setEnabled(!custom);
1245 marginsModule->headsepLE->setEnabled(!custom);
1246 marginsModule->headsepUnit->setEnabled(!custom);
1248 marginsModule->footskipL->setEnabled(!custom);
1249 marginsModule->footskipLE->setEnabled(!custom);
1250 marginsModule->footskipUnit->setEnabled(!custom);
1252 bool const enableColSep = !custom &&
1253 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1254 marginsModule->columnsepL->setEnabled(enableColSep);
1255 marginsModule->columnsepLE->setEnabled(enableColSep);
1256 marginsModule->columnsepUnit->setEnabled(enableColSep);
1259 void GuiDocument::changeBackgroundColor()
1261 QColor const & newColor = QColorDialog::getColor(
1262 rgb2qcolor(set_backgroundcolor), asQWidget());
1263 if (!newColor.isValid())
1265 // set the button color
1266 pageLayoutModule->backgroundPB->setStyleSheet(
1267 colorButtonStyleSheet(newColor));
1269 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1274 void GuiDocument::deleteBackgroundColor()
1276 // set the button color back to white
1277 pageLayoutModule->backgroundPB->setStyleSheet(
1278 colorButtonStyleSheet(QColor(Qt::white)));
1279 // save white as the set color
1280 set_backgroundcolor = rgbFromHexName("#ffffff");
1285 void GuiDocument::xetexChanged(bool xetex)
1288 updateDefaultFormat();
1289 langModule->encodingCO->setEnabled(!xetex &&
1290 !langModule->defaultencodingRB->isChecked());
1291 langModule->defaultencodingRB->setEnabled(!xetex);
1292 langModule->otherencodingRB->setEnabled(!xetex);
1294 fontModule->fontsDefaultCO->setEnabled(!xetex);
1295 fontModule->fontsDefaultLA->setEnabled(!xetex);
1296 fontModule->cjkFontLE->setEnabled(!xetex);
1297 fontModule->cjkFontLA->setEnabled(!xetex);
1300 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1301 bool scaleable = providesScale(font);
1302 fontModule->scaleSansSB->setEnabled(scaleable);
1303 fontModule->scaleSansLA->setEnabled(scaleable);
1305 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1306 scaleable = providesScale(font);
1307 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1308 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1310 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1311 fontModule->fontScCB->setEnabled(providesSC(font));
1312 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1316 void GuiDocument::updateFontsize(string const & items, string const & sel)
1318 fontModule->fontsizeCO->clear();
1319 fontModule->fontsizeCO->addItem(qt_("Default"));
1321 for (int n = 0; !token(items,'|',n).empty(); ++n)
1322 fontModule->fontsizeCO->
1323 addItem(toqstr(token(items,'|',n)));
1325 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1326 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1327 fontModule->fontsizeCO->setCurrentIndex(n);
1334 void GuiDocument::updateFontlist()
1336 fontModule->fontsRomanCO->clear();
1337 fontModule->fontsSansCO->clear();
1338 fontModule->fontsTypewriterCO->clear();
1340 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1341 if (outputModule->xetexCB->isChecked()) {
1342 fontModule->fontsRomanCO->addItem(qt_("Default"));
1343 fontModule->fontsSansCO->addItem(qt_("Default"));
1344 fontModule->fontsTypewriterCO->addItem(qt_("Default"));
1346 QFontDatabase fontdb;
1347 QStringList families(fontdb.families());
1348 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1349 fontModule->fontsRomanCO->addItem(*it);
1350 fontModule->fontsSansCO->addItem(*it);
1351 fontModule->fontsTypewriterCO->addItem(*it);
1356 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1357 QString font = qt_(tex_fonts_roman_gui[n]);
1358 if (!isFontAvailable(tex_fonts_roman[n]))
1359 font += qt_(" (not installed)");
1360 fontModule->fontsRomanCO->addItem(font);
1362 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1363 QString font = qt_(tex_fonts_sans_gui[n]);
1364 if (!isFontAvailable(tex_fonts_sans[n]))
1365 font += qt_(" (not installed)");
1366 fontModule->fontsSansCO->addItem(font);
1368 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1369 QString font = qt_(tex_fonts_monospaced_gui[n]);
1370 if (!isFontAvailable(tex_fonts_monospaced[n]))
1371 font += qt_(" (not installed)");
1372 fontModule->fontsTypewriterCO->addItem(font);
1377 void GuiDocument::romanChanged(int item)
1379 if (outputModule->xetexCB->isChecked())
1381 string const font = tex_fonts_roman[item];
1382 fontModule->fontScCB->setEnabled(providesSC(font));
1383 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1387 void GuiDocument::sansChanged(int item)
1389 if (outputModule->xetexCB->isChecked())
1391 string const font = tex_fonts_sans[item];
1392 bool scaleable = providesScale(font);
1393 fontModule->scaleSansSB->setEnabled(scaleable);
1394 fontModule->scaleSansLA->setEnabled(scaleable);
1398 void GuiDocument::ttChanged(int item)
1400 if (outputModule->xetexCB->isChecked())
1402 string const font = tex_fonts_monospaced[item];
1403 bool scaleable = providesScale(font);
1404 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1405 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1409 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1412 pageLayoutModule->pagestyleCO->clear();
1413 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1415 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1416 string style = token(items, '|', n);
1417 QString style_gui = qt_(style);
1418 pagestyles.push_back(pair<string, QString>(style, style_gui));
1419 pageLayoutModule->pagestyleCO->addItem(style_gui);
1422 if (sel == "default") {
1423 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1429 for (size_t i = 0; i < pagestyles.size(); ++i)
1430 if (pagestyles[i].first == sel)
1431 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1434 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1438 void GuiDocument::browseLayout()
1440 QString const label1 = qt_("Layouts|#o#O");
1441 QString const dir1 = toqstr(lyxrc.document_path);
1442 QStringList const filter(qt_("LyX Layout (*.layout)"));
1443 QString file = browseRelFile(QString(), bufferFilepath(),
1444 qt_("Local layout file"), filter, false,
1447 if (!file.endsWith(".layout"))
1450 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1451 fromqstr(bufferFilepath()));
1453 int const ret = Alert::prompt(_("Local layout file"),
1454 _("The layout file you have selected is a local layout\n"
1455 "file, not one in the system or user directory. Your\n"
1456 "document may not work with this layout if you do not\n"
1457 "keep the layout file in the document directory."),
1458 1, 1, _("&Set Layout"), _("&Cancel"));
1462 // load the layout file
1463 LayoutFileList & bcl = LayoutFileList::get();
1464 string classname = layoutFile.onlyFileName();
1465 // this will update an existing layout if that layout has been loaded before.
1466 LayoutFileIndex name = bcl.addLocalLayout(
1467 classname.substr(0, classname.size() - 7),
1468 layoutFile.onlyPath().absFilename());
1471 Alert::error(_("Error"),
1472 _("Unable to read local layout file."));
1476 // do not trigger classChanged if there is no change.
1477 if (latexModule->classCO->currentText() == toqstr(name))
1481 int idx = latexModule->classCO->findText(toqstr(name));
1483 classes_model_.insertRow(0, toqstr(name), name);
1484 latexModule->classCO->setCurrentIndex(0);
1486 latexModule->classCO->setCurrentIndex(idx);
1492 void GuiDocument::browseMaster()
1494 QString const title = qt_("Select master document");
1495 QString const dir1 = toqstr(lyxrc.document_path);
1496 QString const old = latexModule->childDocLE->text();
1497 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1498 QStringList const filter(qt_("LyX Files (*.lyx)"));
1499 QString file = browseRelFile(old, docpath, title, filter, false,
1500 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1502 latexModule->childDocLE->setText(file);
1506 void GuiDocument::classChanged()
1508 int idx = latexModule->classCO->currentIndex();
1511 string const classname = classes_model_.getIDString(idx);
1513 // check whether the selected modules have changed.
1514 bool modules_changed = false;
1515 unsigned int const srows = selectedModel()->rowCount();
1516 if (srows != bp_.getModules().size())
1517 modules_changed = true;
1519 list<string>::const_iterator mit = bp_.getModules().begin();
1520 list<string>::const_iterator men = bp_.getModules().end();
1521 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1522 if (selectedModel()->getIDString(i) != *mit) {
1523 modules_changed = true;
1528 if (modules_changed || lyxrc.auto_reset_options) {
1529 if (applyPB->isEnabled()) {
1530 int const ret = Alert::prompt(_("Unapplied changes"),
1531 _("Some changes in the dialog were not yet applied.\n"
1532 "If you do not apply now, they will be lost after this action."),
1533 1, 1, _("&Apply"), _("&Dismiss"));
1539 // We load the TextClass as soon as it is selected. This is
1540 // necessary so that other options in the dialog can be updated
1541 // according to the new class. Note, however, that, if you use
1542 // the scroll wheel when sitting on the combo box, we'll load a
1543 // lot of TextClass objects very quickly....
1544 if (!bp_.setBaseClass(classname)) {
1545 Alert::error(_("Error"), _("Unable to set document class."));
1548 if (lyxrc.auto_reset_options)
1549 bp_.useClassDefaults();
1551 // With the introduction of modules came a distinction between the base
1552 // class and the document class. The former corresponds to the main layout
1553 // file; the latter is that plus the modules (or the document-specific layout,
1554 // or whatever else there could be). Our parameters come from the document
1555 // class. So when we set the base class, we also need to recreate the document
1556 // class. Otherwise, we still have the old one.
1557 bp_.makeDocumentClass();
1562 void GuiDocument::bibtexChanged(int n)
1564 biblioModule->bibtexOptionsED->setEnabled(n != 0);
1570 // This is an insanely complicated attempt to make this sort of thing
1571 // work with RTL languages.
1572 docstring formatStrVec(vector<string> const & v, docstring const & s)
1574 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1578 return from_utf8(v[0]);
1579 if (v.size() == 2) {
1580 docstring retval = _("%1$s and %2$s");
1581 retval = subst(retval, _("and"), s);
1582 return bformat(retval, from_utf8(v[0]), from_utf8(v[1]));
1584 // The idea here is to format all but the last two items...
1585 int const vSize = v.size();
1586 docstring t2 = _("%1$s, %2$s");
1587 docstring retval = from_utf8(v[0]);
1588 for (int i = 1; i < vSize - 2; ++i)
1589 retval = bformat(t2, retval, from_utf8(v[i]));
1590 //...and then to plug them, and the last two, into this schema
1591 docstring t = _("%1$s, %2$s, and %3$s");
1592 t = subst(t, _("and"), s);
1593 return bformat(t, retval, from_utf8(v[vSize - 2]), from_utf8(v[vSize - 1]));
1596 vector<string> idsToNames(vector<string> const & idList)
1598 vector<string> retval;
1599 vector<string>::const_iterator it = idList.begin();
1600 vector<string>::const_iterator end = idList.end();
1601 for (; it != end; ++it) {
1602 LyXModule const * const mod = moduleList[*it];
1604 retval.push_back(*it + " (Unavailable)");
1606 retval.push_back(mod->getName());
1613 void GuiDocument::modulesToParams(BufferParams & bp)
1615 // update list of loaded modules
1616 bp.clearLayoutModules();
1617 int const srows = modules_sel_model_.rowCount();
1618 for (int i = 0; i < srows; ++i)
1619 bp.addLayoutModule(modules_sel_model_.getIDString(i));
1621 // update the list of removed modules
1622 bp.clearRemovedModules();
1623 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
1624 list<string>::const_iterator rit = reqmods.begin();
1625 list<string>::const_iterator ren = reqmods.end();
1627 // check each of the default modules
1628 for (; rit != ren; rit++) {
1629 list<string>::const_iterator mit = bp.getModules().begin();
1630 list<string>::const_iterator men = bp.getModules().end();
1632 for (; mit != men; mit++) {
1639 // the module isn't present so must have been removed by the user
1640 bp.addRemovedModule(*rit);
1645 void GuiDocument::modulesChanged()
1647 modulesToParams(bp_);
1648 bp_.makeDocumentClass();
1653 void GuiDocument::updateModuleInfo()
1655 selectionManager->update();
1657 //Module description
1658 bool const focus_on_selected = selectionManager->selectedFocused();
1659 QListView const * const lv =
1660 focus_on_selected ? modulesModule->selectedLV : modulesModule->availableLV;
1661 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1662 modulesModule->infoML->document()->clear();
1665 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1666 GuiIdListModel const & id_model =
1667 focus_on_selected ? modules_sel_model_ : modules_av_model_;
1668 string const modName = id_model.getIDString(idx.row());
1669 docstring desc = getModuleDescription(modName);
1671 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
1672 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
1675 desc += _("Module provided by document class.");
1678 vector<string> pkglist = getPackageList(modName);
1679 docstring pkgdesc = formatStrVec(pkglist, _("and"));
1680 if (!pkgdesc.empty()) {
1683 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1686 pkglist = getRequiredList(modName);
1687 if (!pkglist.empty()) {
1688 vector<string> const reqdescs = idsToNames(pkglist);
1689 pkgdesc = formatStrVec(reqdescs, _("or"));
1692 desc += bformat(_("Module required: %1$s."), pkgdesc);
1695 pkglist = getExcludedList(modName);
1696 if (!pkglist.empty()) {
1697 vector<string> const reqdescs = idsToNames(pkglist);
1698 pkgdesc = formatStrVec(reqdescs, _( "and"));
1701 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1704 if (!isModuleAvailable(modName)) {
1707 desc += _("WARNING: Some required packages are unavailable!");
1710 modulesModule->infoML->document()->setPlainText(toqstr(desc));
1714 void GuiDocument::updateNumbering()
1716 DocumentClass const & tclass = documentClass();
1718 numberingModule->tocTW->setUpdatesEnabled(false);
1719 numberingModule->tocTW->clear();
1721 int const depth = numberingModule->depthSL->value();
1722 int const toc = numberingModule->tocSL->value();
1723 QString const no = qt_("No");
1724 QString const yes = qt_("Yes");
1725 QTreeWidgetItem * item = 0;
1727 DocumentClass::const_iterator lit = tclass.begin();
1728 DocumentClass::const_iterator len = tclass.end();
1729 for (; lit != len; ++lit) {
1730 int const toclevel = lit->toclevel;
1731 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1732 item = new QTreeWidgetItem(numberingModule->tocTW);
1733 item->setText(0, toqstr(translateIfPossible(lit->name())));
1734 item->setText(1, (toclevel <= depth) ? yes : no);
1735 item->setText(2, (toclevel <= toc) ? yes : no);
1739 numberingModule->tocTW->setUpdatesEnabled(true);
1740 numberingModule->tocTW->update();
1744 void GuiDocument::updateDefaultFormat()
1746 // make a copy in order to consider unapplied changes
1747 Buffer * tmpbuf = const_cast<Buffer *>(&buffer());
1748 tmpbuf->params().useXetex = outputModule->xetexCB->isChecked();
1749 int idx = latexModule->classCO->currentIndex();
1751 string const classname = classes_model_.getIDString(idx);
1752 tmpbuf->params().setBaseClass(classname);
1753 tmpbuf->params().makeDocumentClass();
1755 outputModule->defaultFormatCO->blockSignals(true);
1756 outputModule->defaultFormatCO->clear();
1757 outputModule->defaultFormatCO->addItem(qt_("Default"),
1758 QVariant(QString("default")));
1759 typedef vector<Format const *> Formats;
1760 Formats formats = tmpbuf->exportableFormats(true);
1761 Formats::const_iterator cit = formats.begin();
1762 Formats::const_iterator end = formats.end();
1763 for (; cit != end; ++cit)
1764 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
1765 QVariant(toqstr((*cit)->name())));
1766 outputModule->defaultFormatCO->blockSignals(false);
1770 void GuiDocument::applyView()
1773 preambleModule->apply(bp_);
1776 bp_.setCiteEngine(ENGINE_BASIC);
1778 if (biblioModule->citeNatbibRB->isChecked()) {
1779 bool const use_numerical_citations =
1780 biblioModule->citeStyleCO->currentIndex();
1781 if (use_numerical_citations)
1782 bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
1784 bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
1786 } else if (biblioModule->citeJurabibRB->isChecked())
1787 bp_.setCiteEngine(ENGINE_JURABIB);
1790 biblioModule->bibtopicCB->isChecked();
1792 string const bibtex_command =
1793 fromqstr(biblioModule->bibtexCO->itemData(
1794 biblioModule->bibtexCO->currentIndex()).toString());
1795 string const bibtex_options =
1796 fromqstr(biblioModule->bibtexOptionsED->text());
1797 if (bibtex_command == "default" || bibtex_options.empty())
1798 bp_.bibtex_command = bibtex_command;
1800 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
1803 indicesModule->apply(bp_);
1805 // language & quotes
1806 if (langModule->defaultencodingRB->isChecked()) {
1807 bp_.inputenc = "auto";
1809 int i = langModule->encodingCO->currentIndex();
1811 bp_.inputenc = "default";
1813 QString const enc_gui =
1814 langModule->encodingCO->currentText();
1815 Encodings::const_iterator it = encodings.begin();
1816 Encodings::const_iterator const end = encodings.end();
1818 for (; it != end; ++it) {
1819 if (qt_(it->guiName()) == enc_gui) {
1820 bp_.inputenc = it->latexName();
1826 // should not happen
1827 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
1828 bp_.inputenc = "default";
1833 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
1834 switch (langModule->quoteStyleCO->currentIndex()) {
1836 lga = InsetQuotes::EnglishQuotes;
1839 lga = InsetQuotes::SwedishQuotes;
1842 lga = InsetQuotes::GermanQuotes;
1845 lga = InsetQuotes::PolishQuotes;
1848 lga = InsetQuotes::FrenchQuotes;
1851 lga = InsetQuotes::DanishQuotes;
1854 bp_.quotes_language = lga;
1856 QString const lang = langModule->languageCO->itemData(
1857 langModule->languageCO->currentIndex()).toString();
1858 bp_.language = languages.getLanguage(fromqstr(lang));
1861 if (bp_.documentClass().hasTocLevels()) {
1862 bp_.tocdepth = numberingModule->tocSL->value();
1863 bp_.secnumdepth = numberingModule->depthSL->value();
1867 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
1868 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
1869 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
1870 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
1873 bp_.graphicsDriver =
1874 tex_graphics[latexModule->psdriverCO->currentIndex()];
1877 int idx = latexModule->classCO->currentIndex();
1879 string const classname = classes_model_.getIDString(idx);
1880 bp_.setBaseClass(classname);
1884 modulesToParams(bp_);
1886 if (mathsModule->amsautoCB->isChecked()) {
1887 bp_.use_amsmath = BufferParams::package_auto;
1889 if (mathsModule->amsCB->isChecked())
1890 bp_.use_amsmath = BufferParams::package_on;
1892 bp_.use_amsmath = BufferParams::package_off;
1895 if (mathsModule->esintautoCB->isChecked())
1896 bp_.use_esint = BufferParams::package_auto;
1898 if (mathsModule->esintCB->isChecked())
1899 bp_.use_esint = BufferParams::package_on;
1901 bp_.use_esint = BufferParams::package_off;
1904 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1905 bp_.pagestyle = "default";
1907 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
1908 for (size_t i = 0; i != pagestyles.size(); ++i)
1909 if (pagestyles[i].second == style_gui)
1910 bp_.pagestyle = pagestyles[i].first;
1913 switch (textLayoutModule->lspacingCO->currentIndex()) {
1915 bp_.spacing().set(Spacing::Single);
1918 bp_.spacing().set(Spacing::Onehalf);
1921 bp_.spacing().set(Spacing::Double);
1924 bp_.spacing().set(Spacing::Other,
1925 widgetToDoubleStr(textLayoutModule->lspacingLE));
1929 if (textLayoutModule->twoColumnCB->isChecked())
1934 // text should have passed validation
1935 bp_.listings_params =
1936 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1938 if (textLayoutModule->indentRB->isChecked()) {
1939 // if paragraphs are separated by an indentation
1940 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
1941 switch (textLayoutModule->indentCO->currentIndex()) {
1943 bp_.setIndentation(HSpace(HSpace::DEFAULT));
1946 HSpace indent = HSpace(
1947 widgetsToLength(textLayoutModule->indentLE,
1948 textLayoutModule->indentLengthCO)
1950 bp_.setIndentation(indent);
1954 // this should never happen
1955 bp_.setIndentation(HSpace(HSpace::DEFAULT));
1959 // if paragraphs are separated by a skip
1960 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
1961 switch (textLayoutModule->skipCO->currentIndex()) {
1963 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
1966 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
1969 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
1974 widgetsToLength(textLayoutModule->skipLE,
1975 textLayoutModule->skipLengthCO)
1981 // this should never happen
1982 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
1988 fromqstr(latexModule->optionsLE->text());
1990 bp_.use_default_options =
1991 latexModule->defaultOptionsCB->isChecked();
1993 if (latexModule->childDocGB->isChecked())
1995 fromqstr(latexModule->childDocLE->text());
1997 bp_.master = string();
1999 bp_.float_placement = floatModule->get();
2002 bp_.defaultOutputFormat = fromqstr(outputModule->defaultFormatCO->itemData(
2003 outputModule->defaultFormatCO->currentIndex()).toString());
2005 bool const xetex = outputModule->xetexCB->isChecked();
2006 bp_.useXetex = xetex;
2010 if (fontModule->fontsRomanCO->currentIndex() == 0)
2011 bp_.fontsRoman = "default";
2014 fromqstr(fontModule->fontsRomanCO->currentText());
2016 if (fontModule->fontsSansCO->currentIndex() == 0)
2017 bp_.fontsSans = "default";
2020 fromqstr(fontModule->fontsSansCO->currentText());
2022 if (fontModule->fontsTypewriterCO->currentIndex() == 0)
2023 bp_.fontsTypewriter = "default";
2025 bp_.fontsTypewriter =
2026 fromqstr(fontModule->fontsTypewriterCO->currentText());
2029 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
2032 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
2034 bp_.fontsTypewriter =
2035 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
2039 fromqstr(fontModule->cjkFontLE->text());
2041 bp_.fontsSansScale = fontModule->scaleSansSB->value();
2043 bp_.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
2045 bp_.fontsSC = fontModule->fontScCB->isChecked();
2047 bp_.fontsOSF = fontModule->fontOsfCB->isChecked();
2050 bp_.fontsDefaultFamily = "default";
2052 bp_.fontsDefaultFamily = GuiDocument::fontfamilies[
2053 fontModule->fontsDefaultCO->currentIndex()];
2055 if (fontModule->fontsizeCO->currentIndex() == 0)
2056 bp_.fontsize = "default";
2059 fromqstr(fontModule->fontsizeCO->currentText());
2062 bp_.papersize = PAPER_SIZE(
2063 pageLayoutModule->papersizeCO->currentIndex());
2065 // custom, A3, B3 and B4 paper sizes need geometry
2066 int psize = pageLayoutModule->papersizeCO->currentIndex();
2067 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
2069 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2070 pageLayoutModule->paperwidthUnitCO);
2072 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2073 pageLayoutModule->paperheightUnitCO);
2075 if (pageLayoutModule->facingPagesCB->isChecked())
2076 bp_.sides = TwoSides;
2078 bp_.sides = OneSide;
2080 if (pageLayoutModule->landscapeRB->isChecked())
2081 bp_.orientation = ORIENTATION_LANDSCAPE;
2083 bp_.orientation = ORIENTATION_PORTRAIT;
2085 bp_.backgroundcolor = set_backgroundcolor;
2088 bp_.use_geometry = !marginsModule->marginCB->isChecked()
2091 Ui::MarginsUi const * m = marginsModule;
2093 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2094 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2095 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2096 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2097 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2098 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2099 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2100 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2103 branchesModule->apply(bp_);
2106 PDFOptions & pdf = bp_.pdfoptions();
2107 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2108 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2109 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2110 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2111 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2113 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2114 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2115 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2116 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2118 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2119 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2120 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2121 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2123 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2124 if (pdfSupportModule->fullscreenCB->isChecked())
2125 pdf.pagemode = pdf.pagemode_fullscreen;
2127 pdf.pagemode.clear();
2128 pdf.quoted_options = pdf.quoted_options_check(
2129 fromqstr(pdfSupportModule->optionsLE->text()));
2133 void GuiDocument::paramsToDialog()
2135 // set the default unit
2136 Length::UNIT const defaultUnit = Length::defaultUnit();
2139 preambleModule->update(bp_, id());
2142 biblioModule->citeDefaultRB->setChecked(
2143 bp_.citeEngine() == ENGINE_BASIC);
2145 biblioModule->citeNatbibRB->setChecked(
2146 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
2147 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
2149 biblioModule->citeStyleCO->setCurrentIndex(
2150 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
2152 biblioModule->citeJurabibRB->setChecked(
2153 bp_.citeEngine() == ENGINE_JURABIB);
2155 biblioModule->bibtopicCB->setChecked(
2160 split(bp_.bibtex_command, command, ' ');
2162 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2164 biblioModule->bibtexCO->setCurrentIndex(bpos);
2165 biblioModule->bibtexOptionsED->setText(toqstr(options).trimmed());
2167 biblioModule->bibtexCO->setCurrentIndex(0);
2168 biblioModule->bibtexOptionsED->clear();
2170 biblioModule->bibtexOptionsED->setEnabled(
2171 biblioModule->bibtexCO->currentIndex() != 0);
2174 indicesModule->update(bp_);
2176 // language & quotes
2177 int const pos = langModule->languageCO->findData(toqstr(
2178 bp_.language->lang()));
2179 langModule->languageCO->setCurrentIndex(pos);
2181 langModule->quoteStyleCO->setCurrentIndex(
2182 bp_.quotes_language);
2184 bool default_enc = true;
2185 if (bp_.inputenc != "auto") {
2186 default_enc = false;
2187 if (bp_.inputenc == "default") {
2188 langModule->encodingCO->setCurrentIndex(0);
2191 Encodings::const_iterator it = encodings.begin();
2192 Encodings::const_iterator const end = encodings.end();
2193 for (; it != end; ++it) {
2194 if (it->latexName() == bp_.inputenc) {
2195 enc_gui = it->guiName();
2199 int const i = langModule->encodingCO->findText(
2202 langModule->encodingCO->setCurrentIndex(i);
2204 // unknown encoding. Set to default.
2208 langModule->defaultencodingRB->setChecked(default_enc);
2209 langModule->otherencodingRB->setChecked(!default_enc);
2212 int const min_toclevel = documentClass().min_toclevel();
2213 int const max_toclevel = documentClass().max_toclevel();
2214 if (documentClass().hasTocLevels()) {
2215 numberingModule->setEnabled(true);
2216 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2217 numberingModule->depthSL->setMaximum(max_toclevel);
2218 numberingModule->depthSL->setValue(bp_.secnumdepth);
2219 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2220 numberingModule->tocSL->setMaximum(max_toclevel);
2221 numberingModule->tocSL->setValue(bp_.tocdepth);
2224 numberingModule->setEnabled(false);
2225 numberingModule->tocTW->clear();
2229 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2230 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2231 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2232 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2233 bulletsModule->init();
2236 int nitem = findToken(tex_graphics, bp_.graphicsDriver);
2238 latexModule->psdriverCO->setCurrentIndex(nitem);
2241 mathsModule->amsCB->setChecked(
2242 bp_.use_amsmath == BufferParams::package_on);
2243 mathsModule->amsautoCB->setChecked(
2244 bp_.use_amsmath == BufferParams::package_auto);
2246 mathsModule->esintCB->setChecked(
2247 bp_.use_esint == BufferParams::package_on);
2248 mathsModule->esintautoCB->setChecked(
2249 bp_.use_esint == BufferParams::package_auto);
2251 switch (bp_.spacing().getSpace()) {
2252 case Spacing::Other: nitem = 3; break;
2253 case Spacing::Double: nitem = 2; break;
2254 case Spacing::Onehalf: nitem = 1; break;
2255 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2259 string const & layoutID = bp_.baseClassID();
2260 setLayoutComboByIDString(layoutID);
2262 updatePagestyle(documentClass().opt_pagestyle(),
2265 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2266 if (bp_.spacing().getSpace() == Spacing::Other) {
2267 doubleToWidget(textLayoutModule->lspacingLE,
2268 bp_.spacing().getValueAsString());
2272 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2273 textLayoutModule->indentRB->setChecked(true);
2274 string indentation = bp_.getIndentation().asLyXCommand();
2276 if (indentation != "default") {
2277 lengthToWidgets(textLayoutModule->indentLE,
2278 textLayoutModule->indentLengthCO,
2279 indentation, defaultUnit);
2282 textLayoutModule->indentCO->setCurrentIndex(indent);
2285 textLayoutModule->skipRB->setChecked(true);
2287 switch (bp_.getDefSkip().kind()) {
2288 case VSpace::SMALLSKIP:
2291 case VSpace::MEDSKIP:
2294 case VSpace::BIGSKIP:
2297 case VSpace::LENGTH:
2300 string const length = bp_.getDefSkip().asLyXCommand();
2301 lengthToWidgets(textLayoutModule->skipLE,
2302 textLayoutModule->skipLengthCO,
2303 length, defaultUnit);
2310 textLayoutModule->skipCO->setCurrentIndex(skip);
2314 textLayoutModule->twoColumnCB->setChecked(
2317 // break listings_params to multiple lines
2319 InsetListingsParams(bp_.listings_params).separatedParams();
2320 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
2322 if (!bp_.options.empty()) {
2323 latexModule->optionsLE->setText(
2324 toqstr(bp_.options));
2326 latexModule->optionsLE->setText(QString());
2330 latexModule->defaultOptionsCB->setChecked(
2331 bp_.use_default_options);
2332 updateSelectedModules();
2333 selectionManager->updateProvidedModules(
2334 bp_.baseClass()->providedModules());
2335 selectionManager->updateExcludedModules(
2336 bp_.baseClass()->excludedModules());
2338 if (!documentClass().options().empty()) {
2339 latexModule->defaultOptionsLE->setText(
2340 toqstr(documentClass().options()));
2342 latexModule->defaultOptionsLE->setText(
2343 toqstr(_("[No options predefined]")));
2346 latexModule->defaultOptionsLE->setEnabled(
2347 bp_.use_default_options
2348 && !documentClass().options().empty());
2350 latexModule->defaultOptionsCB->setEnabled(
2351 !documentClass().options().empty());
2353 if (!bp_.master.empty()) {
2354 latexModule->childDocGB->setChecked(true);
2355 latexModule->childDocLE->setText(
2356 toqstr(bp_.master));
2358 latexModule->childDocLE->setText(QString());
2359 latexModule->childDocGB->setChecked(false);
2362 floatModule->set(bp_.float_placement);
2365 // update combobox with formats
2366 updateDefaultFormat();
2367 int index = outputModule->defaultFormatCO->findData(toqstr(
2368 bp_.defaultOutputFormat));
2369 // set to default if format is not found
2372 outputModule->defaultFormatCO->setCurrentIndex(index);
2373 outputModule->xetexCB->setEnabled(bp_.baseClass()->outputType() == lyx::LATEX);
2374 outputModule->xetexCB->setChecked(
2375 bp_.baseClass()->outputType() == lyx::LATEX && bp_.useXetex);
2378 updateFontsize(documentClass().opt_fontsize(),
2382 for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
2383 if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fontsRoman)) {
2384 fontModule->fontsRomanCO->setCurrentIndex(i);
2389 for (int i = 0; i < fontModule->fontsSansCO->count(); ++i) {
2390 if (fontModule->fontsSansCO->itemText(i) == toqstr(bp_.fontsSans)) {
2391 fontModule->fontsSansCO->setCurrentIndex(i);
2395 for (int i = 0; i < fontModule->fontsTypewriterCO->count(); ++i) {
2396 if (fontModule->fontsTypewriterCO->itemText(i) ==
2397 toqstr(bp_.fontsTypewriter)) {
2398 fontModule->fontsTypewriterCO->setCurrentIndex(i);
2403 int n = findToken(tex_fonts_roman, bp_.fontsRoman);
2405 fontModule->fontsRomanCO->setCurrentIndex(n);
2409 n = findToken(tex_fonts_sans, bp_.fontsSans);
2411 fontModule->fontsSansCO->setCurrentIndex(n);
2415 n = findToken(tex_fonts_monospaced, bp_.fontsTypewriter);
2417 fontModule->fontsTypewriterCO->setCurrentIndex(n);
2422 if (!bp_.fontsCJK.empty())
2423 fontModule->cjkFontLE->setText(
2424 toqstr(bp_.fontsCJK));
2426 fontModule->cjkFontLE->setText(QString());
2428 fontModule->fontScCB->setChecked(bp_.fontsSC);
2429 fontModule->fontOsfCB->setChecked(bp_.fontsOSF);
2430 fontModule->scaleSansSB->setValue(bp_.fontsSansScale);
2431 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale);
2433 int nn = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily);
2435 fontModule->fontsDefaultCO->setCurrentIndex(nn);
2438 bool const extern_geometry =
2439 documentClass().provides("geometry");
2440 int const psize = bp_.papersize;
2441 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
2442 setCustomPapersize(!extern_geometry && psize == 1);
2443 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
2445 bool const landscape =
2446 bp_.orientation == ORIENTATION_LANDSCAPE;
2447 pageLayoutModule->landscapeRB->setChecked(landscape);
2448 pageLayoutModule->portraitRB->setChecked(!landscape);
2449 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
2450 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
2452 pageLayoutModule->facingPagesCB->setChecked(
2453 bp_.sides == TwoSides);
2455 pageLayoutModule->backgroundPB->setStyleSheet(
2456 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2457 set_backgroundcolor = bp_.backgroundcolor;
2459 lengthToWidgets(pageLayoutModule->paperwidthLE,
2460 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, defaultUnit);
2461 lengthToWidgets(pageLayoutModule->paperheightLE,
2462 pageLayoutModule->paperheightUnitCO, bp_.paperheight, defaultUnit);
2465 Ui::MarginsUi * m = marginsModule;
2467 setMargins(!bp_.use_geometry);
2469 lengthToWidgets(m->topLE, m->topUnit,
2470 bp_.topmargin, defaultUnit);
2472 lengthToWidgets(m->bottomLE, m->bottomUnit,
2473 bp_.bottommargin, defaultUnit);
2475 lengthToWidgets(m->innerLE, m->innerUnit,
2476 bp_.leftmargin, defaultUnit);
2478 lengthToWidgets(m->outerLE, m->outerUnit,
2479 bp_.rightmargin, defaultUnit);
2481 lengthToWidgets(m->headheightLE, m->headheightUnit,
2482 bp_.headheight, defaultUnit);
2484 lengthToWidgets(m->headsepLE, m->headsepUnit,
2485 bp_.headsep, defaultUnit);
2487 lengthToWidgets(m->footskipLE, m->footskipUnit,
2488 bp_.footskip, defaultUnit);
2490 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2491 bp_.columnsep, defaultUnit);
2494 updateUnknownBranches();
2495 branchesModule->update(bp_);
2498 PDFOptions const & pdf = bp_.pdfoptions();
2499 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2500 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2501 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2502 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2503 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2505 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2506 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2507 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2509 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2511 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2512 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2513 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2514 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2516 nn = findToken(backref_opts, pdf.backref);
2518 pdfSupportModule->backrefCO->setCurrentIndex(nn);
2520 pdfSupportModule->fullscreenCB->setChecked
2521 (pdf.pagemode == pdf.pagemode_fullscreen);
2523 pdfSupportModule->optionsLE->setText(
2524 toqstr(pdf.quoted_options));
2526 // Make sure that the bc is in the INITIAL state
2527 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2530 // clear changed branches cache
2531 changedBranches_.clear();
2535 void GuiDocument::saveDocDefault()
2537 // we have to apply the params first
2543 void GuiDocument::updateAvailableModules()
2545 modules_av_model_.clear();
2546 list<modInfoStruct> const & modInfoList = getModuleInfo();
2547 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
2548 list<modInfoStruct>::const_iterator men = modInfoList.end();
2549 for (int i = 0; mit != men; ++mit, ++i)
2550 modules_av_model_.insertRow(i, mit->name, mit->id,
2555 void GuiDocument::updateSelectedModules()
2557 modules_sel_model_.clear();
2558 list<modInfoStruct> const selModList = getSelectedModules();
2559 list<modInfoStruct>::const_iterator mit = selModList.begin();
2560 list<modInfoStruct>::const_iterator men = selModList.end();
2561 for (int i = 0; mit != men; ++mit, ++i)
2562 modules_sel_model_.insertRow(i, mit->name, mit->id,
2567 void GuiDocument::updateContents()
2569 // Nothing to do here as the document settings is not cursor dependant.
2574 void GuiDocument::useClassDefaults()
2576 if (applyPB->isEnabled()) {
2577 int const ret = Alert::prompt(_("Unapplied changes"),
2578 _("Some changes in the dialog were not yet applied.\n"
2579 "If you do not apply now, they will be lost after this action."),
2580 1, 1, _("&Apply"), _("&Dismiss"));
2585 int idx = latexModule->classCO->currentIndex();
2586 string const classname = classes_model_.getIDString(idx);
2587 if (!bp_.setBaseClass(classname)) {
2588 Alert::error(_("Error"), _("Unable to set document class."));
2591 bp_.useClassDefaults();
2596 void GuiDocument::setLayoutComboByIDString(string const & idString)
2598 int idx = classes_model_.findIDString(idString);
2600 Alert::warning(_("Can't set layout!"),
2601 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2603 latexModule->classCO->setCurrentIndex(idx);
2607 bool GuiDocument::isValid()
2609 return validateListingsParameters().isEmpty()
2610 && (textLayoutModule->skipCO->currentIndex() != 3
2611 || !textLayoutModule->skipLE->text().isEmpty()
2612 || textLayoutModule->indentRB->isChecked())
2613 && (textLayoutModule->indentCO->currentIndex() != 1
2614 || !textLayoutModule->indentLE->text().isEmpty()
2615 || textLayoutModule->skipRB->isChecked());
2619 char const * const GuiDocument::fontfamilies[5] = {
2620 "default", "rmdefault", "sfdefault", "ttdefault", ""
2624 char const * GuiDocument::fontfamilies_gui[5] = {
2625 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2629 bool GuiDocument::initialiseParams(string const &)
2631 BufferView const * view = bufferview();
2633 bp_ = BufferParams();
2637 bp_ = view->buffer().params();
2639 updateAvailableModules();
2640 //FIXME It'd be nice to make sure here that the selected
2641 //modules are consistent: That required modules are actually
2642 //selected, and that we don't have conflicts. If so, we could
2643 //at least pop up a warning.
2649 void GuiDocument::clearParams()
2651 bp_ = BufferParams();
2655 BufferId GuiDocument::id() const
2657 BufferView const * const view = bufferview();
2658 return view? &view->buffer() : 0;
2662 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2664 return moduleNames_;
2668 list<GuiDocument::modInfoStruct> const
2669 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
2671 LayoutModuleList::const_iterator it = mods.begin();
2672 LayoutModuleList::const_iterator end = mods.end();
2673 list<modInfoStruct> mInfo;
2674 for (; it != end; ++it) {
2677 LyXModule * mod = moduleList[*it];
2680 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
2682 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
2689 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2691 return makeModuleInfo(params().getModules());
2695 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
2697 return makeModuleInfo(params().baseClass()->providedModules());
2701 DocumentClass const & GuiDocument::documentClass() const
2703 return bp_.documentClass();
2707 static void dispatch_bufferparams(Dialog const & dialog,
2708 BufferParams const & bp, FuncCode lfun)
2711 ss << "\\begin_header\n";
2713 ss << "\\end_header\n";
2714 dialog.dispatch(FuncRequest(lfun, ss.str()));
2718 void GuiDocument::dispatchParams()
2720 // This must come first so that a language change is correctly noticed
2723 // Apply the BufferParams. Note that this will set the base class
2724 // and then update the buffer's layout.
2725 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2727 if (!params().master.empty()) {
2728 FileName const master_file = support::makeAbsPath(params().master,
2729 support::onlyPath(buffer().absFileName()));
2730 if (isLyXFilename(master_file.absFilename())) {
2731 Buffer * master = checkAndLoadLyXFile(master_file);
2733 if (master->isChild(const_cast<Buffer *>(&buffer())))
2734 const_cast<Buffer &>(buffer()).setParent(master);
2736 Alert::warning(_("Assigned master does not include this file"),
2737 bformat(_("You must include this file in the document\n"
2738 "'%1$s' in order to use the master document\n"
2739 "feature."), from_utf8(params().master)));
2741 Alert::warning(_("Could not load master"),
2742 bformat(_("The master document '%1$s'\n"
2743 "could not be loaded."),
2744 from_utf8(params().master)));
2748 // Generate the colours requested by each new branch.
2749 BranchList & branchlist = params().branchlist();
2750 if (!branchlist.empty()) {
2751 BranchList::const_iterator it = branchlist.begin();
2752 BranchList::const_iterator const end = branchlist.end();
2753 for (; it != end; ++it) {
2754 docstring const & current_branch = it->branch();
2755 Branch const * branch = branchlist.find(current_branch);
2756 string const x11hexname = X11hexname(branch->color());
2757 // display the new color
2758 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2759 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2762 // Open insets of selected branches, close deselected ones
2763 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2766 // rename branches in the document
2767 executeBranchRenaming();
2768 // and clear changed branches cache
2769 changedBranches_.clear();
2771 // Generate the colours requested by indices.
2772 IndicesList & indiceslist = params().indiceslist();
2773 if (!indiceslist.empty()) {
2774 IndicesList::const_iterator it = indiceslist.begin();
2775 IndicesList::const_iterator const end = indiceslist.end();
2776 for (; it != end; ++it) {
2777 docstring const & current_index = it->shortcut();
2778 Index const * index = indiceslist.findShortcut(current_index);
2779 string const x11hexname = X11hexname(index->color());
2780 // display the new color
2781 docstring const str = current_index + ' ' + from_ascii(x11hexname);
2782 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2785 // FIXME: If we used an LFUN, we would not need those two lines:
2786 BufferView * bv = const_cast<BufferView *>(bufferview());
2787 bv->processUpdateFlags(Update::Force | Update::FitCursor);
2791 void GuiDocument::setLanguage() const
2793 Language const * const newL = bp_.language;
2794 if (buffer().params().language == newL)
2797 string const & lang_name = newL->lang();
2798 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2802 void GuiDocument::saveAsDefault() const
2804 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2808 bool GuiDocument::isFontAvailable(string const & font) const
2810 if (font == "default" || font == "cmr"
2811 || font == "cmss" || font == "cmtt")
2812 // these are standard
2814 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2815 return LaTeXFeatures::isAvailable("lmodern");
2816 if (font == "times" || font == "palatino"
2817 || font == "helvet" || font == "courier")
2818 return LaTeXFeatures::isAvailable("psnfss");
2819 if (font == "cmbr" || font == "cmtl")
2820 return LaTeXFeatures::isAvailable("cmbright");
2821 if (font == "utopia")
2822 return LaTeXFeatures::isAvailable("utopia")
2823 || LaTeXFeatures::isAvailable("fourier");
2824 if (font == "beraserif" || font == "berasans"
2825 || font == "beramono")
2826 return LaTeXFeatures::isAvailable("bera");
2827 return LaTeXFeatures::isAvailable(font);
2831 bool GuiDocument::providesOSF(string const & font) const
2833 if (outputModule->xetexCB->isChecked())
2834 // FIXME: we should check if the fonts really
2835 // have OSF support. But how?
2838 return isFontAvailable("eco");
2839 if (font == "palatino")
2840 return isFontAvailable("mathpazo");
2845 bool GuiDocument::providesSC(string const & font) const
2847 if (outputModule->xetexCB->isChecked())
2849 if (font == "palatino")
2850 return isFontAvailable("mathpazo");
2851 if (font == "utopia")
2852 return isFontAvailable("fourier");
2857 bool GuiDocument::providesScale(string const & font) const
2859 if (outputModule->xetexCB->isChecked())
2861 return font == "helvet" || font == "luximono"
2862 || font == "berasans" || font == "beramono";
2866 void GuiDocument::loadModuleInfo()
2868 moduleNames_.clear();
2869 LyXModuleList::const_iterator it = moduleList.begin();
2870 LyXModuleList::const_iterator end = moduleList.end();
2871 for (; it != end; ++it) {
2875 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
2876 // this is supposed to give us the first sentence of the description
2879 toqstr(translateIfPossible(from_utf8(it->getDescription())));
2880 int const pos = desc.indexOf(".");
2882 desc.truncate(pos + 1);
2883 m.description = desc;
2884 moduleNames_.push_back(m);
2889 void GuiDocument::updateUnknownBranches()
2891 list<docstring> used_branches;
2892 buffer().getUsedBranches(used_branches);
2893 list<docstring>::const_iterator it = used_branches.begin();
2894 QStringList unknown_branches;
2895 for (; it != used_branches.end() ; ++it) {
2896 if (!buffer().params().branchlist().find(*it))
2897 unknown_branches.append(toqstr(*it));
2899 branchesModule->setUnknownBranches(unknown_branches);
2903 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
2905 map<docstring, docstring>::iterator it = changedBranches_.begin();
2906 for (; it != changedBranches_.end() ; ++it) {
2907 if (it->second == oldname) {
2908 // branch has already been renamed
2909 it->second = newname;
2914 changedBranches_[oldname] = newname;
2918 void GuiDocument::executeBranchRenaming() const
2920 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
2921 for (; it != changedBranches_.end() ; ++it) {
2922 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
2923 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
2928 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2931 } // namespace frontend
2934 #include "moc_GuiDocument.cpp"