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 "CategorizedCombo.h"
17 #include "GuiApplication.h"
18 #include "GuiBranches.h"
19 #include "GuiIndices.h"
20 #include "GuiSelectionManager.h"
21 #include "LaTeXHighlighter.h"
22 #include "LengthCombo.h"
23 #include "PanelStack.h"
24 #include "Validator.h"
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "CiteEnginesList.h"
34 #include "ColorCache.h"
35 #include "Converter.h"
38 #include "FloatPlacement.h"
40 #include "FuncRequest.h"
41 #include "IndicesList.h"
43 #include "LaTeXFeatures.h"
44 #include "LaTeXFonts.h"
46 #include "LayoutEnums.h"
47 #include "LayoutModuleList.h"
49 #include "ModuleList.h"
50 #include "OutputParams.h"
51 #include "PDFOptions.h"
52 #include "qt_helpers.h"
55 #include "TextClass.h"
59 #include "insets/InsetListingsParams.h"
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
68 #include "frontends/alert.h"
70 #include <QAbstractItemModel>
71 #include <QHeaderView>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
77 #include <QTextBoundaryFinder>
78 #include <QTextCursor>
88 // a style sheet for buttons
89 // this is for example used for the background color setting button
90 static inline QString colorButtonStyleSheet(QColor const & bgColor)
92 if (bgColor.isValid()) {
93 QString rc = QLatin1String("background-color:");
102 using namespace lyx::support;
107 char const * const tex_graphics[] =
109 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
110 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
111 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
112 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
117 char const * const tex_graphics_gui[] =
119 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
120 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
121 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
122 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
123 "XeTeX", N_("None"), ""
127 char const * backref_opts[] =
129 "false", "section", "slide", "page", ""
133 char const * backref_opts_gui[] =
135 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
139 char const * lst_packages[] =
141 "Listings", "Minted", ""
145 vector<string> engine_types_;
146 vector<pair<string, QString> > pagestyles;
148 QMap<QString, QString> rmfonts_;
149 QMap<QString, QString> sffonts_;
150 QMap<QString, QString> ttfonts_;
151 QMap<QString, QString> mathfonts_;
154 } // anonymous namespace
158 RGBColor set_backgroundcolor;
159 bool is_backgroundcolor;
160 RGBColor set_fontcolor;
162 RGBColor set_notefontcolor;
163 RGBColor set_boxbgcolor;
164 bool forced_fontspec_activation;
167 // used when sorting the textclass list.
168 class less_textclass_avail_desc
169 : public binary_function<string, string, int>
172 bool operator()(string const & lhs, string const & rhs) const
174 // Ordering criteria:
175 // 1. Availability of text class
176 // 2. Description (lexicographic)
177 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
178 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
179 int const order = compare_no_case(
180 translateIfPossible(from_utf8(tc1.description())),
181 translateIfPossible(from_utf8(tc2.description())));
182 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
183 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
192 vector<string> getRequiredList(string const & modName)
194 LyXModule const * const mod = theModuleList[modName];
196 return vector<string>(); //empty such thing
197 return mod->getRequiredModules();
201 vector<string> getExcludedList(string const & modName)
203 LyXModule const * const mod = theModuleList[modName];
205 return vector<string>(); //empty such thing
206 return mod->getExcludedModules();
210 docstring getModuleCategory(string const & modName)
212 LyXModule const * const mod = theModuleList[modName];
215 return from_utf8(mod->category());
219 docstring getModuleDescription(string const & modName)
221 LyXModule const * const mod = theModuleList[modName];
223 return _("Module not found!");
225 return translateIfPossible(from_utf8(mod->getDescription()));
229 vector<string> getPackageList(string const & modName)
231 LyXModule const * const mod = theModuleList[modName];
233 return vector<string>(); //empty such thing
234 return mod->getPackageList();
238 bool isModuleAvailable(string const & modName)
240 LyXModule const * const mod = theModuleList[modName];
243 return mod->isAvailable();
246 } // anonymous namespace
249 /////////////////////////////////////////////////////////////////////
251 // ModuleSelectionManager
253 /////////////////////////////////////////////////////////////////////
255 /// SelectionManager for use with modules
256 class ModuleSelectionManager : public GuiSelectionManager
260 ModuleSelectionManager(QObject * parent,
261 QTreeView * availableLV,
262 QListView * selectedLV,
266 QPushButton * downPB,
267 GuiIdListModel * availableModel,
268 GuiIdListModel * selectedModel,
269 GuiDocument const * container)
270 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
271 upPB, downPB, availableModel, selectedModel),
272 container_(container)
275 void updateProvidedModules(LayoutModuleList const & pm)
276 { provided_modules_ = pm.list(); }
278 void updateExcludedModules(LayoutModuleList const & em)
279 { excluded_modules_ = em.list(); }
282 virtual void updateAddPB();
284 virtual void updateUpPB();
286 virtual void updateDownPB();
288 virtual void updateDelPB();
289 /// returns availableModel as a GuiIdListModel
290 GuiIdListModel * getAvailableModel()
292 return dynamic_cast<GuiIdListModel *>(availableModel);
294 /// returns selectedModel as a GuiIdListModel
295 GuiIdListModel * getSelectedModel()
297 return dynamic_cast<GuiIdListModel *>(selectedModel);
299 /// keeps a list of the modules the text class provides
300 list<string> provided_modules_;
302 list<string> excluded_modules_;
304 GuiDocument const * container_;
307 void ModuleSelectionManager::updateAddPB()
309 int const arows = availableModel->rowCount();
310 QModelIndexList const avail_sels =
311 availableLV->selectionModel()->selectedIndexes();
313 // disable if there aren't any modules (?), if none of them is chosen
314 // in the dialog, or if the chosen one is already selected for use.
315 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
316 addPB->setEnabled(false);
320 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
321 string const modname = getAvailableModel()->getIDString(idx.row());
324 container_->params().layoutModuleCanBeAdded(modname);
325 addPB->setEnabled(enable);
329 void ModuleSelectionManager::updateDownPB()
331 int const srows = selectedModel->rowCount();
333 downPB->setEnabled(false);
336 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
337 int const curRow = curidx.row();
338 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
339 downPB->setEnabled(false);
343 // determine whether immediately succeding element requires this one
344 string const curmodname = getSelectedModel()->getIDString(curRow);
345 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
347 vector<string> reqs = getRequiredList(nextmodname);
349 // if it doesn't require anything....
351 downPB->setEnabled(true);
355 // Enable it if this module isn't required.
356 // FIXME This should perhaps be more flexible and check whether, even
357 // if the next one is required, there is also an earlier one that will do.
359 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
362 void ModuleSelectionManager::updateUpPB()
364 int const srows = selectedModel->rowCount();
366 upPB->setEnabled(false);
370 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
371 int curRow = curIdx.row();
372 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
373 upPB->setEnabled(false);
376 string const curmodname = getSelectedModel()->getIDString(curRow);
378 // determine whether immediately preceding element is required by this one
379 vector<string> reqs = getRequiredList(curmodname);
381 // if this one doesn't require anything....
383 upPB->setEnabled(true);
388 // Enable it if the preceding module isn't required.
389 // NOTE This is less flexible than it might be. We could check whether, even
390 // if the previous one is required, there is an earlier one that would do.
391 string const premod = getSelectedModel()->getIDString(curRow - 1);
392 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
395 void ModuleSelectionManager::updateDelPB()
397 int const srows = selectedModel->rowCount();
399 deletePB->setEnabled(false);
403 QModelIndex const & curidx =
404 selectedLV->selectionModel()->currentIndex();
405 int const curRow = curidx.row();
406 if (curRow < 0 || curRow >= srows) { // invalid index?
407 deletePB->setEnabled(false);
411 string const curmodname = getSelectedModel()->getIDString(curRow);
413 // We're looking here for a reason NOT to enable the button. If we
414 // find one, we disable it and return. If we don't, we'll end up at
415 // the end of the function, and then we enable it.
416 for (int i = curRow + 1; i < srows; ++i) {
417 string const thisMod = getSelectedModel()->getIDString(i);
418 vector<string> reqs = getRequiredList(thisMod);
419 //does this one require us?
420 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
424 // OK, so this module requires us
425 // is there an EARLIER module that also satisfies the require?
426 // NOTE We demand that it be earlier to keep the list of modules
427 // consistent with the rule that a module must be proceeded by a
428 // required module. There would be more flexible ways to proceed,
429 // but that would be a lot more complicated, and the logic here is
430 // already complicated. (That's why I've left the debugging code.)
431 // lyxerr << "Testing " << thisMod << endl;
432 bool foundone = false;
433 for (int j = 0; j < curRow; ++j) {
434 string const mod = getSelectedModel()->getIDString(j);
435 // lyxerr << "In loop: Testing " << mod << endl;
436 // do we satisfy the require?
437 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
438 // lyxerr << mod << " does the trick." << endl;
443 // did we find a module to satisfy the require?
445 // lyxerr << "No matching module found." << endl;
446 deletePB->setEnabled(false);
450 // lyxerr << "All's well that ends well." << endl;
451 deletePB->setEnabled(true);
455 /////////////////////////////////////////////////////////////////////
459 /////////////////////////////////////////////////////////////////////
461 PreambleModule::PreambleModule(QWidget * parent)
462 : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
464 // This is not a memory leak. The object will be destroyed
466 // @ is letter in the LyX user preamble
467 (void) new LaTeXHighlighter(preambleTE->document(), true);
468 preambleTE->setFont(guiApp->typewriterSystemFont());
469 preambleTE->setWordWrapMode(QTextOption::NoWrap);
470 setFocusProxy(preambleTE);
471 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
472 connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
473 connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
474 connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
476 // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
477 const int tabStop = 4;
478 QFontMetrics metrics(preambleTE->currentFont());
479 preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
483 void PreambleModule::checkFindButton()
485 findButtonPB->setEnabled(!findLE->text().isEmpty());
489 void PreambleModule::findText()
491 bool const found = preambleTE->find(findLE->text());
494 QTextCursor qtcur = preambleTE->textCursor();
495 qtcur.movePosition(QTextCursor::Start);
496 preambleTE->setTextCursor(qtcur);
497 preambleTE->find(findLE->text());
502 void PreambleModule::update(BufferParams const & params, BufferId id)
504 QString preamble = toqstr(params.preamble);
505 // Nothing to do if the params and preamble are unchanged.
506 if (id == current_id_
507 && preamble == preambleTE->document()->toPlainText())
510 QTextCursor cur = preambleTE->textCursor();
511 // Save the coords before switching to the new one.
512 preamble_coords_[current_id_] =
513 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
515 // Save the params address for further use.
517 preambleTE->document()->setPlainText(preamble);
518 Coords::const_iterator it = preamble_coords_.find(current_id_);
519 if (it == preamble_coords_.end())
520 // First time we open this one.
521 preamble_coords_[current_id_] = make_pair(0, 0);
523 // Restore saved coords.
524 cur = preambleTE->textCursor();
525 cur.setPosition(it->second.first);
526 preambleTE->setTextCursor(cur);
527 preambleTE->verticalScrollBar()->setValue(it->second.second);
532 void PreambleModule::apply(BufferParams & params)
534 params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
538 void PreambleModule::closeEvent(QCloseEvent * e)
540 // Save the coords before closing.
541 QTextCursor cur = preambleTE->textCursor();
542 preamble_coords_[current_id_] =
543 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
548 /////////////////////////////////////////////////////////////////////
552 /////////////////////////////////////////////////////////////////////
555 LocalLayout::LocalLayout(QWidget * parent)
556 : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
558 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
559 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
560 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
564 void LocalLayout::update(BufferParams const & params, BufferId id)
566 QString layout = toqstr(params.getLocalLayout(false));
567 // Nothing to do if the params and preamble are unchanged.
568 if (id == current_id_
569 && layout == locallayoutTE->document()->toPlainText())
572 // Save the params address for further use.
574 locallayoutTE->document()->setPlainText(layout);
579 void LocalLayout::apply(BufferParams & params)
581 docstring const layout =
582 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
583 params.setLocalLayout(layout, false);
587 void LocalLayout::hideConvert()
589 convertPB->setEnabled(false);
590 convertLB->setText("");
596 void LocalLayout::textChanged()
598 static const QString message =
599 qt_("Press button to check validity...");
600 string const layout =
601 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
603 if (layout.empty()) {
605 validatePB->setEnabled(false);
606 validLB->setText("");
609 } else if (!validatePB->isEnabled()) {
610 // if that's already enabled, we shouldn't need to do anything.
612 validLB->setText(message);
613 validatePB->setEnabled(true);
620 void LocalLayout::convert() {
621 string const layout =
622 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
623 string const newlayout = TextClass::convert(layout);
624 if (!newlayout.empty())
625 locallayoutTE->setPlainText(toqstr(newlayout));
630 void LocalLayout::convertPressed() {
637 void LocalLayout::validate() {
639 static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
640 // Flashy red bold text
641 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
643 string const layout =
644 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
645 if (!layout.empty()) {
646 TextClass::ReturnValues const ret = TextClass::validate(layout);
647 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
648 validatePB->setEnabled(false);
649 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
650 : ivpar.arg(qt_("Layout is invalid!")));
651 if (ret == TextClass::OK_OLDFORMAT) {
653 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
655 if (TextClass::convert(layout).empty()) {
656 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
657 // then maybe the layout is still valid, but its format is more
658 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
659 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
660 convertPB->setEnabled(false);
661 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
662 ? ivpar.arg(qt_("Conversion to current format impossible!"))
663 : vpar.arg(qt_("Conversion to current stable format "
665 convertLB->setText(text);
667 convertPB->setEnabled(true);
668 convertLB->setText(qt_("Convert to current format"));
679 void LocalLayout::validatePressed() {
685 /////////////////////////////////////////////////////////////////////
689 /////////////////////////////////////////////////////////////////////
692 GuiDocument::GuiDocument(GuiView & lv)
693 : GuiDialog(lv, "document", qt_("Document Settings")),
694 biblioChanged_(false), nonModuleChanged_(false),
695 modulesChanged_(false), shellescapeChanged_(false)
699 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
700 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
701 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
702 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
704 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
705 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
707 // Manage the restore, ok, apply, restore and cancel/close buttons
708 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
710 bc().setApply(applyPB);
711 bc().setCancel(closePB);
712 bc().setRestore(restorePB);
716 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
717 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
718 this, SLOT(change_adaptor()));
719 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
720 this, SLOT(setLSpacing(int)));
721 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
722 this, SLOT(change_adaptor()));
724 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
725 this, SLOT(change_adaptor()));
726 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
727 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
728 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
729 this, SLOT(change_adaptor()));
730 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
731 this, SLOT(setIndent(int)));
732 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
733 this, SLOT(change_adaptor()));
734 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
735 this, SLOT(change_adaptor()));
737 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
738 this, SLOT(change_adaptor()));
739 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
740 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
741 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
742 this, SLOT(change_adaptor()));
743 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
744 this, SLOT(setSkip(int)));
745 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
746 this, SLOT(change_adaptor()));
747 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
748 this, SLOT(change_adaptor()));
750 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
751 this, SLOT(enableIndent(bool)));
752 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
753 this, SLOT(enableSkip(bool)));
755 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
756 this, SLOT(change_adaptor()));
757 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
758 this, SLOT(setColSep()));
759 connect(textLayoutModule->justCB, SIGNAL(clicked()),
760 this, SLOT(change_adaptor()));
762 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
763 textLayoutModule->lspacingLE));
764 textLayoutModule->indentLE->setValidator(new LengthValidator(
765 textLayoutModule->indentLE));
766 textLayoutModule->skipLE->setValidator(new LengthValidator(
767 textLayoutModule->skipLE));
769 textLayoutModule->indentCO->addItem(qt_("Default"));
770 textLayoutModule->indentCO->addItem(qt_("Custom"));
771 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
772 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
773 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
774 textLayoutModule->skipCO->addItem(qt_("Custom"));
775 textLayoutModule->lspacingCO->insertItem(
776 Spacing::Single, qt_("Single"));
777 textLayoutModule->lspacingCO->insertItem(
778 Spacing::Onehalf, qt_("OneHalf"));
779 textLayoutModule->lspacingCO->insertItem(
780 Spacing::Double, qt_("Double"));
781 textLayoutModule->lspacingCO->insertItem(
782 Spacing::Other, qt_("Custom"));
783 // initialize the length validator
784 bc().addCheckedLineEdit(textLayoutModule->indentLE);
785 bc().addCheckedLineEdit(textLayoutModule->skipLE);
788 // master/child handling
789 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
791 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
792 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
793 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
794 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
795 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
796 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
797 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
798 this, SLOT(change_adaptor()));
799 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
800 this, SLOT(change_adaptor()));
801 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
802 this, SLOT(change_adaptor()));
803 masterChildModule->childrenTW->setColumnCount(2);
804 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
805 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
806 masterChildModule->childrenTW->resizeColumnToContents(1);
807 masterChildModule->childrenTW->resizeColumnToContents(2);
811 outputModule = new UiWidget<Ui::OutputUi>(this);
813 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
814 this, SLOT(change_adaptor()));
815 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
816 this, SLOT(change_adaptor()));
817 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
818 this, SLOT(change_adaptor()));
819 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
820 this, SLOT(change_adaptor()));
821 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
822 this, SLOT(change_adaptor()));
824 connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
825 this, SLOT(shellescapeChanged()));
826 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
827 this, SLOT(change_adaptor()));
828 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
829 this, SLOT(change_adaptor()));
830 outputModule->synccustomCB->addItem("");
831 outputModule->synccustomCB->addItem("\\synctex=1");
832 outputModule->synccustomCB->addItem("\\synctex=-1");
833 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
835 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
836 outputModule->synccustomCB));
838 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
839 this, SLOT(change_adaptor()));
842 fontModule = new FontModule(this);
843 connect(fontModule->osFontsCB, SIGNAL(clicked()),
844 this, SLOT(change_adaptor()));
845 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
846 this, SLOT(osFontsChanged(bool)));
847 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
848 this, SLOT(change_adaptor()));
849 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
850 this, SLOT(romanChanged(int)));
851 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
852 this, SLOT(change_adaptor()));
853 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
854 this, SLOT(sansChanged(int)));
855 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
856 this, SLOT(change_adaptor()));
857 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
858 this, SLOT(ttChanged(int)));
859 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
860 this, SLOT(change_adaptor()));
861 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
862 this, SLOT(mathFontChanged(int)));
863 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
864 this, SLOT(change_adaptor()));
865 connect(fontModule->fontencCO, SIGNAL(activated(int)),
866 this, SLOT(change_adaptor()));
867 connect(fontModule->fontencCO, SIGNAL(activated(int)),
868 this, SLOT(fontencChanged(int)));
869 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
870 this, SLOT(change_adaptor()));
871 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
872 this, SLOT(change_adaptor()));
873 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
874 this, SLOT(change_adaptor()));
875 connect(fontModule->microtypeCB, SIGNAL(clicked()),
876 this, SLOT(change_adaptor()));
877 connect(fontModule->dashesCB, SIGNAL(clicked()),
878 this, SLOT(change_adaptor()));
879 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
880 this, SLOT(change_adaptor()));
881 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
882 this, SLOT(change_adaptor()));
883 connect(fontModule->fontScCB, SIGNAL(clicked()),
884 this, SLOT(change_adaptor()));
885 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
886 this, SLOT(fontScToggled(bool)));
887 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
888 this, SLOT(change_adaptor()));
889 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
890 this, SLOT(fontOsfToggled(bool)));
892 fontModule->fontencLE->setValidator(new NoNewLineValidator(
893 fontModule->fontencLE));
894 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
895 fontModule->cjkFontLE));
899 fontModule->fontsizeCO->addItem(qt_("Default"));
900 fontModule->fontsizeCO->addItem(qt_("10"));
901 fontModule->fontsizeCO->addItem(qt_("11"));
902 fontModule->fontsizeCO->addItem(qt_("12"));
904 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
905 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
906 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
908 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
909 fontModule->fontsDefaultCO->addItem(
910 qt_(GuiDocument::fontfamilies_gui[n]));
912 if (!LaTeXFeatures::isAvailable("fontspec"))
913 fontModule->osFontsCB->setToolTip(
914 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
915 "You need to install the package \"fontspec\" to use this feature"));
919 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
920 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
921 this, SLOT(papersizeChanged(int)));
922 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
923 this, SLOT(papersizeChanged(int)));
924 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
925 this, SLOT(change_adaptor()));
926 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
927 this, SLOT(change_adaptor()));
928 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
929 this, SLOT(change_adaptor()));
930 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
931 this, SLOT(change_adaptor()));
932 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
933 this, SLOT(change_adaptor()));
934 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
935 this, SLOT(change_adaptor()));
936 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
937 this, SLOT(change_adaptor()));
938 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
939 this, SLOT(change_adaptor()));
940 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
941 this, SLOT(change_adaptor()));
942 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
943 this, SLOT(change_adaptor()));
945 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
946 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
947 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
948 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
949 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
950 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
951 pageLayoutModule->paperheightL);
952 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
953 pageLayoutModule->paperwidthL);
955 QComboBox * cb = pageLayoutModule->papersizeCO;
956 cb->addItem(qt_("Default"));
957 cb->addItem(qt_("Custom"));
958 cb->addItem(qt_("US letter"));
959 cb->addItem(qt_("US legal"));
960 cb->addItem(qt_("US executive"));
961 cb->addItem(qt_("A0"));
962 cb->addItem(qt_("A1"));
963 cb->addItem(qt_("A2"));
964 cb->addItem(qt_("A3"));
965 cb->addItem(qt_("A4"));
966 cb->addItem(qt_("A5"));
967 cb->addItem(qt_("A6"));
968 cb->addItem(qt_("B0"));
969 cb->addItem(qt_("B1"));
970 cb->addItem(qt_("B2"));
971 cb->addItem(qt_("B3"));
972 cb->addItem(qt_("B4"));
973 cb->addItem(qt_("B5"));
974 cb->addItem(qt_("B6"));
975 cb->addItem(qt_("C0"));
976 cb->addItem(qt_("C1"));
977 cb->addItem(qt_("C2"));
978 cb->addItem(qt_("C3"));
979 cb->addItem(qt_("C4"));
980 cb->addItem(qt_("C5"));
981 cb->addItem(qt_("C6"));
982 cb->addItem(qt_("JIS B0"));
983 cb->addItem(qt_("JIS B1"));
984 cb->addItem(qt_("JIS B2"));
985 cb->addItem(qt_("JIS B3"));
986 cb->addItem(qt_("JIS B4"));
987 cb->addItem(qt_("JIS B5"));
988 cb->addItem(qt_("JIS B6"));
989 // remove the %-items from the unit choice
990 pageLayoutModule->paperwidthUnitCO->noPercents();
991 pageLayoutModule->paperheightUnitCO->noPercents();
992 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
993 pageLayoutModule->paperheightLE));
994 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
995 pageLayoutModule->paperwidthLE));
999 marginsModule = new UiWidget<Ui::MarginsUi>(this);
1000 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1001 this, SLOT(setCustomMargins(bool)));
1002 connect(marginsModule->marginCB, SIGNAL(clicked()),
1003 this, SLOT(change_adaptor()));
1004 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1005 this, SLOT(change_adaptor()));
1006 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1007 this, SLOT(change_adaptor()));
1008 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1009 this, SLOT(change_adaptor()));
1010 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1011 this, SLOT(change_adaptor()));
1012 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1013 this, SLOT(change_adaptor()));
1014 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1015 this, SLOT(change_adaptor()));
1016 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1017 this, SLOT(change_adaptor()));
1018 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1019 this, SLOT(change_adaptor()));
1020 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1021 this, SLOT(change_adaptor()));
1022 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1023 this, SLOT(change_adaptor()));
1024 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1025 this, SLOT(change_adaptor()));
1026 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1027 this, SLOT(change_adaptor()));
1028 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1029 this, SLOT(change_adaptor()));
1030 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1031 this, SLOT(change_adaptor()));
1032 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1033 this, SLOT(change_adaptor()));
1034 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1035 this, SLOT(change_adaptor()));
1036 marginsModule->topLE->setValidator(new LengthValidator(
1037 marginsModule->topLE));
1038 marginsModule->bottomLE->setValidator(new LengthValidator(
1039 marginsModule->bottomLE));
1040 marginsModule->innerLE->setValidator(new LengthValidator(
1041 marginsModule->innerLE));
1042 marginsModule->outerLE->setValidator(new LengthValidator(
1043 marginsModule->outerLE));
1044 marginsModule->headsepLE->setValidator(new LengthValidator(
1045 marginsModule->headsepLE));
1046 marginsModule->headheightLE->setValidator(new LengthValidator(
1047 marginsModule->headheightLE));
1048 marginsModule->footskipLE->setValidator(new LengthValidator(
1049 marginsModule->footskipLE));
1050 marginsModule->columnsepLE->setValidator(new LengthValidator(
1051 marginsModule->columnsepLE));
1053 bc().addCheckedLineEdit(marginsModule->topLE,
1054 marginsModule->topL);
1055 bc().addCheckedLineEdit(marginsModule->bottomLE,
1056 marginsModule->bottomL);
1057 bc().addCheckedLineEdit(marginsModule->innerLE,
1058 marginsModule->innerL);
1059 bc().addCheckedLineEdit(marginsModule->outerLE,
1060 marginsModule->outerL);
1061 bc().addCheckedLineEdit(marginsModule->headsepLE,
1062 marginsModule->headsepL);
1063 bc().addCheckedLineEdit(marginsModule->headheightLE,
1064 marginsModule->headheightL);
1065 bc().addCheckedLineEdit(marginsModule->footskipLE,
1066 marginsModule->footskipL);
1067 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1068 marginsModule->columnsepL);
1072 langModule = new UiWidget<Ui::LanguageUi>(this);
1073 connect(langModule->languageCO, SIGNAL(activated(int)),
1074 this, SLOT(change_adaptor()));
1075 connect(langModule->languageCO, SIGNAL(activated(int)),
1076 this, SLOT(languageChanged(int)));
1077 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1078 this, SLOT(change_adaptor()));
1079 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1080 this, SLOT(change_adaptor()));
1081 connect(langModule->encodingCO, SIGNAL(activated(int)),
1082 this, SLOT(change_adaptor()));
1083 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1084 this, SLOT(change_adaptor()));
1085 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1086 this, SLOT(change_adaptor()));
1087 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1088 this, SLOT(change_adaptor()));
1089 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1090 this, SLOT(languagePackageChanged(int)));
1091 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1092 this, SLOT(change_adaptor()));
1094 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1095 langModule->languagePackageLE));
1097 QAbstractItemModel * language_model = guiApp->languageModel();
1098 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1099 language_model->sort(0);
1100 langModule->languageCO->setModel(language_model);
1101 langModule->languageCO->setModelColumn(0);
1103 // Always put the default encoding in the first position.
1104 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1105 QStringList encodinglist;
1106 for (auto const & encvar : encodings) {
1107 if (!encvar.unsafe() && !encvar.guiName().empty())
1108 encodinglist.append(qt_(encvar.guiName()));
1110 encodinglist.sort();
1111 langModule->encodingCO->addItems(encodinglist);
1113 langModule->languagePackageCO->addItem(
1114 qt_("Default"), toqstr("default"));
1115 langModule->languagePackageCO->addItem(
1116 qt_("Automatic"), toqstr("auto"));
1117 langModule->languagePackageCO->addItem(
1118 qt_("Always Babel"), toqstr("babel"));
1119 langModule->languagePackageCO->addItem(
1120 qt_("Custom"), toqstr("custom"));
1121 langModule->languagePackageCO->addItem(
1122 qt_("None[[language package]]"), toqstr("none"));
1126 colorModule = new UiWidget<Ui::ColorUi>(this);
1127 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1128 this, SLOT(changeFontColor()));
1129 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1130 this, SLOT(deleteFontColor()));
1131 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1132 this, SLOT(changeNoteFontColor()));
1133 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1134 this, SLOT(deleteNoteFontColor()));
1135 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1136 this, SLOT(changeBackgroundColor()));
1137 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1138 this, SLOT(deleteBackgroundColor()));
1139 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1140 this, SLOT(changeBoxBackgroundColor()));
1141 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1142 this, SLOT(deleteBoxBackgroundColor()));
1146 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1147 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1148 this, SLOT(change_adaptor()));
1149 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1150 this, SLOT(change_adaptor()));
1151 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1152 this, SLOT(updateNumbering()));
1153 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1154 this, SLOT(updateNumbering()));
1155 numberingModule->tocTW->setColumnCount(3);
1156 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1157 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1158 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1159 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1162 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1163 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1164 this, SLOT(citeEngineChanged(int)));
1165 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1166 this, SLOT(citeStyleChanged()));
1167 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1168 this, SLOT(biblioChanged()));
1169 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1170 this, SLOT(biblioChanged()));
1171 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1172 this, SLOT(bibtexChanged(int)));
1173 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1174 this, SLOT(biblioChanged()));
1175 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1176 this, SLOT(biblioChanged()));
1177 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1178 this, SLOT(biblioChanged()));
1179 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1180 this, SLOT(biblioChanged()));
1181 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1182 this, SLOT(updateResetDefaultBiblio()));
1183 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1184 this, SLOT(biblioChanged()));
1185 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1186 this, SLOT(biblioChanged()));
1187 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1188 this, SLOT(updateResetDefaultBiblio()));
1189 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1190 this, SLOT(biblioChanged()));
1191 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1192 this, SLOT(biblioChanged()));
1193 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1194 this, SLOT(updateResetDefaultBiblio()));
1195 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1196 this, SLOT(rescanBibFiles()));
1197 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1198 this, SLOT(resetDefaultBibfile()));
1199 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1200 this, SLOT(resetDefaultCbxBibfile()));
1201 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1202 this, SLOT(resetDefaultBbxBibfile()));
1203 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1204 this, SLOT(matchBiblatexStyles()));
1206 biblioModule->citeEngineCO->clear();
1207 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1208 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1209 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1210 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1214 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1215 biblioModule->bibtexOptionsLE));
1216 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1217 biblioModule->defaultBiblioCO->lineEdit()));
1218 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1219 biblioModule->citePackageOptionsLE));
1221 // NOTE: we do not provide "custom" here for security reasons!
1222 biblioModule->bibtexCO->clear();
1223 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1224 for (auto const & alts : lyxrc.bibtex_alternatives) {
1225 QString const command = toqstr(alts).left(toqstr(alts).indexOf(" "));
1226 biblioModule->bibtexCO->addItem(command, command);
1231 indicesModule = new GuiIndices;
1232 connect(indicesModule, SIGNAL(changed()),
1233 this, SLOT(change_adaptor()));
1237 mathsModule = new UiWidget<Ui::MathsUi>(this);
1238 QStringList headers;
1239 headers << qt_("Package") << qt_("Load automatically")
1240 << qt_("Load always") << qt_("Do not load");
1241 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1242 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1243 map<string, string> const & packages = BufferParams::auto_packages();
1244 mathsModule->packagesTW->setRowCount(packages.size());
1246 for (auto const & pkgvar : packages) {
1247 docstring const package = from_ascii(pkgvar.first);
1248 QString autoTooltip = qt_(pkgvar.second);
1249 QString alwaysTooltip;
1250 if (package == "amsmath")
1252 qt_("The AMS LaTeX packages are always used");
1254 alwaysTooltip = toqstr(bformat(
1255 _("The LaTeX package %1$s is always used"),
1257 QString neverTooltip;
1258 if (package == "amsmath")
1260 qt_("The AMS LaTeX packages are never used");
1262 neverTooltip = toqstr(bformat(
1263 _("The LaTeX package %1$s is never used"),
1265 QRadioButton * autoRB = new QRadioButton(mathsModule);
1266 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1267 QRadioButton * neverRB = new QRadioButton(mathsModule);
1268 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1269 packageGroup->addButton(autoRB);
1270 packageGroup->addButton(alwaysRB);
1271 packageGroup->addButton(neverRB);
1272 autoRB->setToolTip(autoTooltip);
1273 alwaysRB->setToolTip(alwaysTooltip);
1274 neverRB->setToolTip(neverTooltip);
1276 // Pack the buttons in a layout in order to get proper alignment
1277 QWidget * autoRBWidget = new QWidget();
1278 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1279 autoRBLayout->addWidget(autoRB);
1280 autoRBLayout->setAlignment(Qt::AlignCenter);
1281 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1282 autoRBWidget->setLayout(autoRBLayout);
1284 QWidget * alwaysRBWidget = new QWidget();
1285 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1286 alwaysRBLayout->addWidget(alwaysRB);
1287 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1288 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1289 alwaysRBWidget->setLayout(alwaysRBLayout);
1291 QWidget * neverRBWidget = new QWidget();
1292 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1293 neverRBLayout->addWidget(neverRB);
1294 neverRBLayout->setAlignment(Qt::AlignCenter);
1295 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1296 neverRBWidget->setLayout(neverRBLayout);
1298 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1299 mathsModule->packagesTW->setItem(packnum, 0, pack);
1300 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1301 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1302 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1304 connect(autoRB, SIGNAL(clicked()),
1305 this, SLOT(change_adaptor()));
1306 connect(alwaysRB, SIGNAL(clicked()),
1307 this, SLOT(change_adaptor()));
1308 connect(neverRB, SIGNAL(clicked()),
1309 this, SLOT(change_adaptor()));
1312 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1313 this, SLOT(allPackagesAuto()));
1314 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1315 this, SLOT(allPackagesAlways()));
1316 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1317 this, SLOT(allPackagesNot()));
1318 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1319 this, SLOT(change_adaptor()));
1320 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1321 this, SLOT(change_adaptor()));
1322 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1323 this, SLOT(change_adaptor()));
1324 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1325 this, SLOT(change_adaptor()));
1327 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1328 this, SLOT(change_adaptor()));
1329 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1330 this, SLOT(allowMathIndent()));
1331 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1332 this, SLOT(change_adaptor()));
1333 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1334 this, SLOT(enableMathIndent(int)));
1335 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1336 this, SLOT(change_adaptor()));
1337 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1338 this, SLOT(change_adaptor()));
1341 mathsModule->MathIndentCO->addItem(qt_("Default"));
1342 mathsModule->MathIndentCO->addItem(qt_("Custom"));
1343 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1344 mathsModule->MathIndentLE));
1345 // initialize the length validator
1346 bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1347 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1348 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1349 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1350 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1354 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1355 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1356 this, SLOT(change_adaptor()));
1357 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1358 this, SLOT(change_adaptor()));
1359 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1360 this, SLOT(change_adaptor()));
1361 connect(latexModule->classCO, SIGNAL(activated(int)),
1362 this, SLOT(classChanged_adaptor()));
1363 connect(latexModule->classCO, SIGNAL(activated(int)),
1364 this, SLOT(change_adaptor()));
1365 connect(latexModule->layoutPB, SIGNAL(clicked()),
1366 this, SLOT(browseLayout()));
1367 connect(latexModule->layoutPB, SIGNAL(clicked()),
1368 this, SLOT(change_adaptor()));
1369 connect(latexModule->childDocGB, SIGNAL(clicked()),
1370 this, SLOT(change_adaptor()));
1371 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1372 this, SLOT(change_adaptor()));
1373 connect(latexModule->childDocPB, SIGNAL(clicked()),
1374 this, SLOT(browseMaster()));
1375 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1376 this, SLOT(change_adaptor()));
1377 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1378 this, SLOT(change_adaptor()));
1380 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1381 latexModule->optionsLE));
1382 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1383 latexModule->childDocLE));
1385 // postscript drivers
1386 for (int n = 0; tex_graphics[n][0]; ++n) {
1387 QString enc = qt_(tex_graphics_gui[n]);
1388 latexModule->psdriverCO->addItem(enc);
1391 LayoutFileList const & bcl = LayoutFileList::get();
1392 vector<LayoutFileIndex> classList = bcl.classList();
1393 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1395 for (auto const & cvar : classList) {
1396 LayoutFile const & tc = bcl[cvar];
1397 bool const available = tc.isTeXClassAvailable();
1398 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1399 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1400 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1402 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1403 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1404 "Please check if you have the matching %1$s class "
1405 "and all required packages (%2$s) installed."),
1406 output_type, from_utf8(tc.prerequisites(", "))));
1408 latexModule->classCO->addItemSort(toqstr(tc.name()),
1410 toqstr(translateIfPossible(from_utf8(tc.category()))),
1412 true, true, true, available);
1417 branchesModule = new GuiBranches(this);
1418 connect(branchesModule, SIGNAL(changed()),
1419 this, SLOT(change_adaptor()));
1420 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1421 this, SLOT(branchesRename(docstring const &, docstring const &)));
1422 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1423 updateUnknownBranches();
1427 preambleModule = new PreambleModule(this);
1428 connect(preambleModule, SIGNAL(changed()),
1429 this, SLOT(change_adaptor()));
1431 localLayout = new LocalLayout(this);
1432 connect(localLayout, SIGNAL(changed()),
1433 this, SLOT(change_adaptor()));
1437 bulletsModule = new BulletsModule(this);
1438 connect(bulletsModule, SIGNAL(changed()),
1439 this, SLOT(change_adaptor()));
1443 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1444 modulesModule->availableLV->header()->setVisible(false);
1445 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1446 modulesModule->availableLV->header()->setStretchLastSection(false);
1448 new ModuleSelectionManager(this, modulesModule->availableLV,
1449 modulesModule->selectedLV,
1450 modulesModule->addPB,
1451 modulesModule->deletePB,
1452 modulesModule->upPB,
1453 modulesModule->downPB,
1454 availableModel(), selectedModel(), this);
1455 connect(selectionManager, SIGNAL(updateHook()),
1456 this, SLOT(updateModuleInfo()));
1457 connect(selectionManager, SIGNAL(selectionChanged()),
1458 this, SLOT(modulesChanged()));
1462 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1463 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1464 this, SLOT(change_adaptor()));
1465 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1466 this, SLOT(change_adaptor()));
1467 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1468 this, SLOT(change_adaptor()));
1469 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1470 this, SLOT(change_adaptor()));
1471 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1472 this, SLOT(change_adaptor()));
1473 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1474 this, SLOT(change_adaptor()));
1475 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1476 this, SLOT(change_adaptor()));
1477 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1478 this, SLOT(change_adaptor()));
1479 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1480 this, SLOT(change_adaptor()));
1481 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1482 this, SLOT(change_adaptor()));
1483 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1484 this, SLOT(change_adaptor()));
1485 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1486 this, SLOT(change_adaptor()));
1487 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1488 this, SLOT(change_adaptor()));
1489 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1490 this, SLOT(change_adaptor()));
1491 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1492 this, SLOT(change_adaptor()));
1493 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1494 this, SLOT(change_adaptor()));
1496 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1497 pdfSupportModule->titleLE));
1498 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1499 pdfSupportModule->authorLE));
1500 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1501 pdfSupportModule->subjectLE));
1502 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1503 pdfSupportModule->keywordsLE));
1504 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1505 pdfSupportModule->optionsLE));
1507 for (int i = 0; backref_opts[i][0]; ++i)
1508 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1512 floatModule = new FloatPlacement;
1513 connect(floatModule, SIGNAL(changed()),
1514 this, SLOT(change_adaptor()));
1518 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1519 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1520 this, SLOT(change_adaptor()));
1521 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1522 this, SLOT(change_adaptor()));
1523 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1524 this, SLOT(setListingsMessage()));
1525 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1526 this, SLOT(change_adaptor()));
1527 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1528 this, SLOT(listingsPackageChanged(int)));
1529 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1530 this, SLOT(setListingsMessage()));
1531 listingsModule->listingsTB->setPlainText(
1532 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1534 for (int i = 0; lst_packages[i][0]; ++i)
1535 listingsModule->packageCO->addItem(lst_packages[i]);
1539 docPS->addPanel(latexModule, N_("Document Class"));
1540 docPS->addPanel(masterChildModule, N_("Child Documents"));
1541 docPS->addPanel(modulesModule, N_("Modules"));
1542 docPS->addPanel(localLayout, N_("Local Layout"));
1543 docPS->addPanel(fontModule, N_("Fonts"));
1544 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1545 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1546 docPS->addPanel(marginsModule, N_("Page Margins"));
1547 docPS->addPanel(langModule, N_("Language"));
1548 docPS->addPanel(colorModule, N_("Colors"));
1549 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1550 docPS->addPanel(biblioModule, N_("Bibliography"));
1551 docPS->addPanel(indicesModule, N_("Indexes"));
1552 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1553 docPS->addPanel(mathsModule, N_("Math Options"));
1554 docPS->addPanel(floatModule, N_("Float Placement"));
1555 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1556 docPS->addPanel(bulletsModule, N_("Bullets"));
1557 docPS->addPanel(branchesModule, N_("Branches"));
1558 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1559 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1560 docPS->setCurrentPanel("Document Class");
1561 // FIXME: hack to work around resizing bug in Qt >= 4.2
1562 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1563 #if QT_VERSION >= 0x040200
1564 docPS->updateGeometry();
1569 void GuiDocument::onBufferViewChanged()
1571 if (isVisibleView())
1572 initialiseParams("");
1576 void GuiDocument::saveDefaultClicked()
1582 void GuiDocument::useDefaultsClicked()
1588 void GuiDocument::change_adaptor()
1590 nonModuleChanged_ = true;
1595 void GuiDocument::shellescapeChanged()
1597 shellescapeChanged_ = true;
1602 void GuiDocument::slotApply()
1604 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1605 bool wasclean = buffer().isClean();
1606 GuiDialog::slotApply();
1607 if (wasclean && only_shellescape_changed)
1608 buffer().markClean();
1609 modulesChanged_ = false;
1613 void GuiDocument::slotOK()
1615 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1616 bool wasclean = buffer().isClean();
1617 GuiDialog::slotOK();
1618 if (wasclean && only_shellescape_changed)
1619 buffer().markClean();
1620 modulesChanged_ = false;
1624 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1629 string child = fromqstr(item->text(0));
1633 if (std::find(includeonlys_.begin(),
1634 includeonlys_.end(), child) != includeonlys_.end())
1635 includeonlys_.remove(child);
1637 includeonlys_.push_back(child);
1639 updateIncludeonlys();
1644 QString GuiDocument::validateListingsParameters()
1646 if (listingsModule->bypassCB->isChecked())
1648 string const package =
1649 lst_packages[listingsModule->packageCO->currentIndex()];
1650 string params = fromqstr(listingsModule->listingsED->toPlainText());
1651 InsetListingsParams lstparams(params);
1652 lstparams.setMinted(package == "Minted");
1653 return toqstr(lstparams.validate());
1657 void GuiDocument::setListingsMessage()
1660 static bool isOK = true;
1661 QString msg = validateListingsParameters();
1662 if (msg.isEmpty()) {
1666 // listingsTB->setTextColor("black");
1667 listingsModule->listingsTB->setPlainText(
1668 qt_("Input listings parameters below. "
1669 "Enter ? for a list of parameters."));
1672 // listingsTB->setTextColor("red");
1673 listingsModule->listingsTB->setPlainText(msg);
1678 void GuiDocument::listingsPackageChanged(int index)
1680 string const package = lst_packages[index];
1681 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1682 Alert::warning(_("Pygments driver command not found!"),
1683 _("The driver command necessary to use the minted package\n"
1684 "(pygmentize) has not been found. Make sure you have\n"
1685 "the python-pygments module installed or, if the driver\n"
1686 "is named differently, to add the following line to the\n"
1687 "document preamble:\n\n"
1688 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1689 "where 'driver' is name of the driver command."));
1694 void GuiDocument::setLSpacing(int item)
1696 textLayoutModule->lspacingLE->setEnabled(item == 3);
1700 void GuiDocument::setIndent(int item)
1702 bool const enable = (item == 1);
1703 textLayoutModule->indentLE->setEnabled(enable);
1704 textLayoutModule->indentLengthCO->setEnabled(enable);
1705 textLayoutModule->skipLE->setEnabled(false);
1706 textLayoutModule->skipLengthCO->setEnabled(false);
1711 void GuiDocument::enableIndent(bool indent)
1713 textLayoutModule->skipLE->setEnabled(!indent);
1714 textLayoutModule->skipLengthCO->setEnabled(!indent);
1716 setIndent(textLayoutModule->indentCO->currentIndex());
1720 void GuiDocument::setSkip(int item)
1722 bool const enable = (item == 3);
1723 textLayoutModule->skipLE->setEnabled(enable);
1724 textLayoutModule->skipLengthCO->setEnabled(enable);
1729 void GuiDocument::enableSkip(bool skip)
1731 textLayoutModule->indentLE->setEnabled(!skip);
1732 textLayoutModule->indentLengthCO->setEnabled(!skip);
1734 setSkip(textLayoutModule->skipCO->currentIndex());
1737 void GuiDocument::allowMathIndent() {
1738 // only disable when not checked, checked does not always allow enabling
1739 if (!mathsModule->MathIndentCB->isChecked()) {
1740 mathsModule->MathIndentLE->setEnabled(false);
1741 mathsModule->MathIndentLengthCO->setEnabled(false);
1743 if (mathsModule->MathIndentCB->isChecked()
1744 && mathsModule->MathIndentCO->currentIndex() == 1) {
1745 mathsModule->MathIndentLE->setEnabled(true);
1746 mathsModule->MathIndentLengthCO->setEnabled(true);
1751 void GuiDocument::enableMathIndent(int item)
1753 bool const enable = (item == 1);
1754 mathsModule->MathIndentLE->setEnabled(enable);
1755 mathsModule->MathIndentLengthCO->setEnabled(enable);
1760 void GuiDocument::setMargins()
1762 bool const extern_geometry =
1763 documentClass().provides("geometry");
1764 marginsModule->marginCB->setEnabled(!extern_geometry);
1765 if (extern_geometry) {
1766 marginsModule->marginCB->setChecked(false);
1767 setCustomMargins(true);
1769 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1770 setCustomMargins(!bp_.use_geometry);
1775 void GuiDocument::papersizeChanged(int paper_size)
1777 setCustomPapersize(paper_size == 1);
1781 void GuiDocument::setCustomPapersize(bool custom)
1783 pageLayoutModule->paperwidthL->setEnabled(custom);
1784 pageLayoutModule->paperwidthLE->setEnabled(custom);
1785 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1786 pageLayoutModule->paperheightL->setEnabled(custom);
1787 pageLayoutModule->paperheightLE->setEnabled(custom);
1788 pageLayoutModule->paperheightLE->setFocus();
1789 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1793 void GuiDocument::setColSep()
1795 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1799 void GuiDocument::setCustomMargins(bool custom)
1801 marginsModule->topL->setEnabled(!custom);
1802 marginsModule->topLE->setEnabled(!custom);
1803 marginsModule->topUnit->setEnabled(!custom);
1805 marginsModule->bottomL->setEnabled(!custom);
1806 marginsModule->bottomLE->setEnabled(!custom);
1807 marginsModule->bottomUnit->setEnabled(!custom);
1809 marginsModule->innerL->setEnabled(!custom);
1810 marginsModule->innerLE->setEnabled(!custom);
1811 marginsModule->innerUnit->setEnabled(!custom);
1813 marginsModule->outerL->setEnabled(!custom);
1814 marginsModule->outerLE->setEnabled(!custom);
1815 marginsModule->outerUnit->setEnabled(!custom);
1817 marginsModule->headheightL->setEnabled(!custom);
1818 marginsModule->headheightLE->setEnabled(!custom);
1819 marginsModule->headheightUnit->setEnabled(!custom);
1821 marginsModule->headsepL->setEnabled(!custom);
1822 marginsModule->headsepLE->setEnabled(!custom);
1823 marginsModule->headsepUnit->setEnabled(!custom);
1825 marginsModule->footskipL->setEnabled(!custom);
1826 marginsModule->footskipLE->setEnabled(!custom);
1827 marginsModule->footskipUnit->setEnabled(!custom);
1829 bool const enableColSep = !custom &&
1830 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1831 marginsModule->columnsepL->setEnabled(enableColSep);
1832 marginsModule->columnsepLE->setEnabled(enableColSep);
1833 marginsModule->columnsepUnit->setEnabled(enableColSep);
1837 void GuiDocument::changeBackgroundColor()
1839 QColor const & newColor = QColorDialog::getColor(
1840 rgb2qcolor(set_backgroundcolor), asQWidget());
1841 if (!newColor.isValid())
1843 // set the button color and text
1844 colorModule->backgroundPB->setStyleSheet(
1845 colorButtonStyleSheet(newColor));
1846 colorModule->backgroundPB->setText(qt_("&Change..."));
1848 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1849 is_backgroundcolor = true;
1854 void GuiDocument::deleteBackgroundColor()
1856 // set the button color back to default by setting an empty StyleSheet
1857 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1858 // change button text
1859 colorModule->backgroundPB->setText(qt_("&Default..."));
1860 // save default color (white)
1861 set_backgroundcolor = rgbFromHexName("#ffffff");
1862 is_backgroundcolor = false;
1867 void GuiDocument::changeFontColor()
1869 QColor const & newColor = QColorDialog::getColor(
1870 rgb2qcolor(set_fontcolor), asQWidget());
1871 if (!newColor.isValid())
1873 // set the button color and text
1874 colorModule->fontColorPB->setStyleSheet(
1875 colorButtonStyleSheet(newColor));
1876 colorModule->fontColorPB->setText(qt_("&Change..."));
1878 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1879 is_fontcolor = true;
1884 void GuiDocument::deleteFontColor()
1886 // set the button color back to default by setting an empty StyleSheet
1887 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1888 // change button text
1889 colorModule->fontColorPB->setText(qt_("&Default..."));
1890 // save default color (black)
1891 set_fontcolor = rgbFromHexName("#000000");
1892 is_fontcolor = false;
1897 void GuiDocument::changeNoteFontColor()
1899 QColor const & newColor = QColorDialog::getColor(
1900 rgb2qcolor(set_notefontcolor), asQWidget());
1901 if (!newColor.isValid())
1903 // set the button color
1904 colorModule->noteFontColorPB->setStyleSheet(
1905 colorButtonStyleSheet(newColor));
1907 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1912 void GuiDocument::deleteNoteFontColor()
1914 // set the button color back to pref
1915 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1916 colorModule->noteFontColorPB->setStyleSheet(
1917 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1922 void GuiDocument::changeBoxBackgroundColor()
1924 QColor const & newColor = QColorDialog::getColor(
1925 rgb2qcolor(set_boxbgcolor), asQWidget());
1926 if (!newColor.isValid())
1928 // set the button color
1929 colorModule->boxBackgroundPB->setStyleSheet(
1930 colorButtonStyleSheet(newColor));
1932 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1937 void GuiDocument::deleteBoxBackgroundColor()
1939 // set the button color back to pref
1940 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1941 colorModule->boxBackgroundPB->setStyleSheet(
1942 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1947 void GuiDocument::updateQuoteStyles(bool const set)
1949 Language const * lang = lyx::languages.getLanguage(
1950 fromqstr(langModule->languageCO->itemData(
1951 langModule->languageCO->currentIndex()).toString()));
1953 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1955 langModule->quoteStyleCO->clear();
1957 bool has_default = false;
1958 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1959 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1960 if (qs == InsetQuotesParams::DynamicQuotes)
1962 bool const langdef = (qs == def);
1964 // add the default style on top
1965 langModule->quoteStyleCO->insertItem(0,
1966 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1970 langModule->quoteStyleCO->addItem(
1971 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1973 if (set && has_default)
1974 // (re)set to the default style
1975 langModule->quoteStyleCO->setCurrentIndex(0);
1979 void GuiDocument::languageChanged(int i)
1981 // some languages only work with polyglossia
1982 Language const * lang = lyx::languages.getLanguage(
1983 fromqstr(langModule->languageCO->itemData(i).toString()));
1984 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1985 // If we force to switch fontspec on, store
1986 // current state (#8717)
1987 if (fontModule->osFontsCB->isEnabled())
1988 forced_fontspec_activation =
1989 !fontModule->osFontsCB->isChecked();
1990 fontModule->osFontsCB->setChecked(true);
1991 fontModule->osFontsCB->setEnabled(false);
1994 fontModule->osFontsCB->setEnabled(true);
1995 // If we have forced to switch fontspec on,
1996 // restore previous state (#8717)
1997 if (forced_fontspec_activation)
1998 fontModule->osFontsCB->setChecked(false);
1999 forced_fontspec_activation = false;
2002 // set appropriate quotation mark style
2003 updateQuoteStyles(true);
2007 void GuiDocument::osFontsChanged(bool nontexfonts)
2009 bool const tex_fonts = !nontexfonts;
2010 // store current fonts
2011 QString const font_roman = fontModule->fontsRomanCO->itemData(
2012 fontModule->fontsRomanCO->currentIndex()).toString();
2013 QString const font_sans = fontModule->fontsSansCO->itemData(
2014 fontModule->fontsSansCO->currentIndex()).toString();
2015 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2016 fontModule->fontsTypewriterCO->currentIndex()).toString();
2017 QString const font_math = fontModule->fontsMathCO->itemData(
2018 fontModule->fontsMathCO->currentIndex()).toString();
2019 int const font_sf_scale = fontModule->scaleSansSB->value();
2020 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2023 // store default format
2024 QString const dformat = outputModule->defaultFormatCO->itemData(
2025 outputModule->defaultFormatCO->currentIndex()).toString();
2026 updateDefaultFormat();
2027 // try to restore default format
2028 int index = outputModule->defaultFormatCO->findData(dformat);
2029 // set to default if format is not found
2032 outputModule->defaultFormatCO->setCurrentIndex(index);
2034 // try to restore fonts which were selected two toggles ago
2035 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2037 fontModule->fontsRomanCO->setCurrentIndex(index);
2038 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2040 fontModule->fontsSansCO->setCurrentIndex(index);
2041 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2043 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2044 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2046 fontModule->fontsMathCO->setCurrentIndex(index);
2047 // save fonts for next next toggle
2048 fontModule->font_roman = font_roman;
2049 fontModule->font_sans = font_sans;
2050 fontModule->font_typewriter = font_typewriter;
2051 fontModule->font_math = font_math;
2052 fontModule->font_sf_scale = font_sf_scale;
2053 fontModule->font_tt_scale = font_tt_scale;
2055 langModule->encodingCO->setEnabled(tex_fonts &&
2056 !langModule->defaultencodingRB->isChecked());
2057 langModule->defaultencodingRB->setEnabled(tex_fonts);
2058 langModule->otherencodingRB->setEnabled(tex_fonts);
2060 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2061 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2062 fontModule->cjkFontLE->setEnabled(tex_fonts);
2063 fontModule->cjkFontLA->setEnabled(tex_fonts);
2065 updateFontOptions();
2067 fontModule->fontencLA->setEnabled(tex_fonts);
2068 fontModule->fontencCO->setEnabled(tex_fonts);
2070 fontModule->fontencLE->setEnabled(false);
2072 fontencChanged(fontModule->fontencCO->currentIndex());
2076 void GuiDocument::mathFontChanged(int)
2078 updateFontOptions();
2082 void GuiDocument::fontOsfToggled(bool state)
2084 if (fontModule->osFontsCB->isChecked())
2086 QString font = fontModule->fontsRomanCO->itemData(
2087 fontModule->fontsRomanCO->currentIndex()).toString();
2088 if (hasMonolithicExpertSet(font))
2089 fontModule->fontScCB->setChecked(state);
2093 void GuiDocument::fontScToggled(bool state)
2095 if (fontModule->osFontsCB->isChecked())
2097 QString font = fontModule->fontsRomanCO->itemData(
2098 fontModule->fontsRomanCO->currentIndex()).toString();
2099 if (hasMonolithicExpertSet(font))
2100 fontModule->fontOsfCB->setChecked(state);
2104 void GuiDocument::updateFontOptions()
2106 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2109 font = fontModule->fontsSansCO->itemData(
2110 fontModule->fontsSansCO->currentIndex()).toString();
2111 bool scaleable = providesScale(font);
2112 fontModule->scaleSansSB->setEnabled(scaleable);
2113 fontModule->scaleSansLA->setEnabled(scaleable);
2115 font = fontModule->fontsTypewriterCO->itemData(
2116 fontModule->fontsTypewriterCO->currentIndex()).toString();
2117 scaleable = providesScale(font);
2118 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2119 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2121 font = fontModule->fontsRomanCO->itemData(
2122 fontModule->fontsRomanCO->currentIndex()).toString();
2123 fontModule->fontScCB->setEnabled(providesSC(font));
2124 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2125 updateMathFonts(font);
2129 void GuiDocument::updateFontsize(string const & items, string const & sel)
2131 fontModule->fontsizeCO->clear();
2132 fontModule->fontsizeCO->addItem(qt_("Default"));
2134 for (int n = 0; !token(items,'|',n).empty(); ++n)
2135 fontModule->fontsizeCO->
2136 addItem(toqstr(token(items,'|',n)));
2138 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2139 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2140 fontModule->fontsizeCO->setCurrentIndex(n);
2147 bool GuiDocument::ot1() const
2149 QString const fontenc =
2150 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2151 return (fontenc == "default"
2152 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2153 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2157 bool GuiDocument::completeFontset() const
2159 return (fontModule->fontsSansCO->itemData(
2160 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2161 && fontModule->fontsSansCO->itemData(
2162 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2166 bool GuiDocument::noMathFont() const
2168 return (fontModule->fontsMathCO->itemData(
2169 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2173 void GuiDocument::updateTexFonts()
2175 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2177 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2178 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2179 for (; it != end; ++it) {
2180 LaTeXFont lf = it->second;
2181 if (lf.name().empty()) {
2182 LYXERR0("Error: Unnamed font: " << it->first);
2185 docstring const family = lf.family();
2186 docstring guiname = translateIfPossible(lf.guiname());
2187 if (!lf.available(ot1(), noMathFont()))
2188 guiname += _(" (not installed)");
2190 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2191 else if (family == "sf")
2192 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2193 else if (family == "tt")
2194 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2195 else if (family == "math")
2196 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2201 void GuiDocument::updateFontlist()
2203 fontModule->fontsRomanCO->clear();
2204 fontModule->fontsSansCO->clear();
2205 fontModule->fontsTypewriterCO->clear();
2206 fontModule->fontsMathCO->clear();
2208 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2209 if (fontModule->osFontsCB->isChecked()) {
2210 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2211 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2212 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2213 QString unimath = qt_("Non-TeX Fonts Default");
2214 if (!LaTeXFeatures::isAvailable("unicode-math"))
2215 unimath += qt_(" (not available)");
2216 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2217 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2219 QFontDatabase fontdb;
2220 QStringList families(fontdb.families());
2221 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2222 fontModule->fontsRomanCO->addItem(*it, *it);
2223 fontModule->fontsSansCO->addItem(*it, *it);
2224 fontModule->fontsTypewriterCO->addItem(*it, *it);
2229 if (rmfonts_.empty())
2232 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2233 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2234 while (rmi != rmfonts_.constEnd()) {
2235 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2239 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2240 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2241 while (sfi != sffonts_.constEnd()) {
2242 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2246 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2247 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2248 while (tti != ttfonts_.constEnd()) {
2249 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2253 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2254 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2255 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2256 while (mmi != mathfonts_.constEnd()) {
2257 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2263 void GuiDocument::fontencChanged(int item)
2265 fontModule->fontencLE->setEnabled(
2266 fontModule->fontencCO->itemData(item).toString() == "custom");
2267 // The availability of TeX fonts depends on the font encoding
2269 updateFontOptions();
2273 void GuiDocument::updateMathFonts(QString const & rm)
2275 if (fontModule->osFontsCB->isChecked())
2277 QString const math =
2278 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2279 int const i = fontModule->fontsMathCO->findData("default");
2280 if (providesNoMath(rm) && i == -1)
2281 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2282 else if (!providesNoMath(rm) && i != -1) {
2283 int const c = fontModule->fontsMathCO->currentIndex();
2284 fontModule->fontsMathCO->removeItem(i);
2286 fontModule->fontsMathCO->setCurrentIndex(0);
2291 void GuiDocument::romanChanged(int item)
2293 if (fontModule->osFontsCB->isChecked())
2295 QString const font =
2296 fontModule->fontsRomanCO->itemData(item).toString();
2297 fontModule->fontScCB->setEnabled(providesSC(font));
2298 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2299 updateMathFonts(font);
2303 void GuiDocument::sansChanged(int item)
2305 if (fontModule->osFontsCB->isChecked())
2307 QString const font =
2308 fontModule->fontsSansCO->itemData(item).toString();
2309 bool scaleable = providesScale(font);
2310 fontModule->scaleSansSB->setEnabled(scaleable);
2311 fontModule->scaleSansLA->setEnabled(scaleable);
2315 void GuiDocument::ttChanged(int item)
2317 if (fontModule->osFontsCB->isChecked())
2319 QString const font =
2320 fontModule->fontsTypewriterCO->itemData(item).toString();
2321 bool scaleable = providesScale(font);
2322 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2323 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2327 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2330 pageLayoutModule->pagestyleCO->clear();
2331 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2333 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2334 string style = token(items, '|', n);
2335 QString style_gui = qt_(style);
2336 pagestyles.push_back(pair<string, QString>(style, style_gui));
2337 pageLayoutModule->pagestyleCO->addItem(style_gui);
2340 if (sel == "default") {
2341 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2347 for (size_t i = 0; i < pagestyles.size(); ++i)
2348 if (pagestyles[i].first == sel)
2349 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2352 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2356 void GuiDocument::browseLayout()
2358 QString const label1 = qt_("Lay&outs");
2359 QString const dir1 = toqstr(lyxrc.document_path);
2360 QStringList const filter(qt_("LyX Layout (*.layout)"));
2361 QString file = browseRelToParent(QString(), bufferFilePath(),
2362 qt_("Local layout file"), filter, false,
2365 if (!file.endsWith(".layout"))
2368 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2369 fromqstr(bufferFilePath()));
2371 int const ret = Alert::prompt(_("Local layout file"),
2372 _("The layout file you have selected is a local layout\n"
2373 "file, not one in the system or user directory.\n"
2374 "Your document will not work with this layout if you\n"
2375 "move the layout file to a different directory."),
2376 1, 1, _("&Set Layout"), _("&Cancel"));
2380 // load the layout file
2381 LayoutFileList & bcl = LayoutFileList::get();
2382 string classname = layoutFile.onlyFileName();
2383 // this will update an existing layout if that layout has been loaded before.
2384 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2385 classname.substr(0, classname.size() - 7),
2386 layoutFile.onlyPath().absFileName()));
2389 Alert::error(_("Error"),
2390 _("Unable to read local layout file."));
2394 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2396 // do not trigger classChanged if there is no change.
2397 if (latexModule->classCO->currentText() == toqstr(name))
2401 bool const avail = latexModule->classCO->set(toqstr(name));
2403 LayoutFile const & tc = bcl[name];
2404 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2405 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2406 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2407 tooltip += '\n' + qt_("This is a local layout file.");
2408 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2409 toqstr(translateIfPossible(from_utf8(tc.category()))),
2411 true, true, true, true);
2412 latexModule->classCO->set(toqstr(name));
2419 void GuiDocument::browseMaster()
2421 QString const title = qt_("Select master document");
2422 QString const dir1 = toqstr(lyxrc.document_path);
2423 QString const old = latexModule->childDocLE->text();
2424 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2425 QStringList const filter(qt_("LyX Files (*.lyx)"));
2426 QString file = browseRelToSub(old, docpath, title, filter, false,
2427 qt_("D&ocuments"), toqstr(lyxrc.document_path));
2429 if (!file.isEmpty())
2430 latexModule->childDocLE->setText(file);
2434 void GuiDocument::classChanged_adaptor()
2436 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2441 void GuiDocument::classChanged()
2443 int idx = latexModule->classCO->currentIndex();
2446 string const classname = fromqstr(latexModule->classCO->getData(idx));
2448 if (applyPB->isEnabled()) {
2449 int const ret = Alert::prompt(_("Unapplied changes"),
2450 _("Some changes in the dialog were not yet applied.\n"
2451 "If you do not apply now, they will be lost after this action."),
2452 1, 1, _("&Apply"), _("&Dismiss"));
2457 // We load the TextClass as soon as it is selected. This is
2458 // necessary so that other options in the dialog can be updated
2459 // according to the new class. Note, however, that, if you use
2460 // the scroll wheel when sitting on the combo box, we'll load a
2461 // lot of TextClass objects very quickly....
2462 if (!bp_.setBaseClass(classname)) {
2463 Alert::error(_("Error"), _("Unable to set document class."));
2466 if (lyxrc.auto_reset_options)
2467 bp_.useClassDefaults();
2469 // With the introduction of modules came a distinction between the base
2470 // class and the document class. The former corresponds to the main layout
2471 // file; the latter is that plus the modules (or the document-specific layout,
2472 // or whatever else there could be). Our parameters come from the document
2473 // class. So when we set the base class, we also need to recreate the document
2474 // class. Otherwise, we still have the old one.
2475 bp_.makeDocumentClass();
2480 void GuiDocument::languagePackageChanged(int i)
2482 langModule->languagePackageLE->setEnabled(
2483 langModule->languagePackageCO->itemData(i).toString() == "custom");
2487 void GuiDocument::biblioChanged()
2489 biblioChanged_ = true;
2494 void GuiDocument::checkPossibleCiteEngines()
2496 // Check if the class provides a specific engine,
2497 // and if so, enforce this.
2498 string force_engine;
2499 if (documentClass().provides("natbib")
2500 || documentClass().provides("natbib-internal"))
2501 force_engine = "natbib";
2502 else if (documentClass().provides("jurabib"))
2503 force_engine = "jurabib";
2504 else if (documentClass().provides("biblatex"))
2505 force_engine = "biblatex";
2506 else if (documentClass().provides("biblatex-natbib"))
2507 force_engine = "biblatex-natbib";
2509 if (!force_engine.empty())
2510 biblioModule->citeEngineCO->setCurrentIndex(
2511 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2512 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2516 void GuiDocument::rescanBibFiles()
2519 rescanTexStyles("bbx cbx");
2521 rescanTexStyles("bst");
2525 void GuiDocument::resetDefaultBibfile(string const & which)
2527 QString const engine =
2528 biblioModule->citeEngineCO->itemData(
2529 biblioModule->citeEngineCO->currentIndex()).toString();
2531 CiteEngineType const cet =
2532 CiteEngineType(biblioModule->citeStyleCO->itemData(
2533 biblioModule->citeStyleCO->currentIndex()).toInt());
2535 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2539 void GuiDocument::resetDefaultBbxBibfile()
2541 resetDefaultBibfile("bbx");
2545 void GuiDocument::resetDefaultCbxBibfile()
2547 resetDefaultBibfile("cbx");
2551 void GuiDocument::citeEngineChanged(int n)
2553 QString const engine =
2554 biblioModule->citeEngineCO->itemData(n).toString();
2556 vector<string> const engs =
2557 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2559 updateCiteStyles(engs);
2560 updateEngineDependends();
2561 resetDefaultBibfile();
2566 void GuiDocument::updateEngineDependends()
2568 bool const biblatex = isBiblatex();
2570 // These are only useful with BibTeX
2571 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2572 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2573 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2574 biblioModule->bibtopicCB->setEnabled(!biblatex);
2576 // These are only useful with Biblatex
2577 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2578 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2579 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2580 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2581 biblioModule->resetBbxPB->setEnabled(biblatex);
2582 biblioModule->resetCbxPB->setEnabled(biblatex);
2583 biblioModule->matchBbxPB->setEnabled(biblatex);
2585 // These are useful with biblatex, jurabib and natbib
2586 QString const engine =
2587 biblioModule->citeEngineCO->itemData(
2588 biblioModule->citeEngineCO->currentIndex()).toString();
2589 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2591 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2592 || ce->requires("natbib.sty");
2593 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2594 biblioModule->citePackageOptionsL->setEnabled(citepack);
2598 void GuiDocument::citeStyleChanged()
2600 QString const engine =
2601 biblioModule->citeEngineCO->itemData(
2602 biblioModule->citeEngineCO->currentIndex()).toString();
2603 QString const currentDef = isBiblatex() ?
2604 biblioModule->biblatexBbxCO->currentText()
2605 : biblioModule->defaultBiblioCO->currentText();
2606 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2607 resetDefaultBibfile();
2613 void GuiDocument::bibtexChanged(int n)
2615 biblioModule->bibtexOptionsLE->setEnabled(
2616 biblioModule->bibtexCO->itemData(n).toString() != "default");
2621 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2623 biblioModule->citeStyleCO->clear();
2625 vector<string>::const_iterator it = engs.begin();
2626 vector<string>::const_iterator end = engs.end();
2627 for (; it != end; ++it) {
2628 if (*it == "default")
2629 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2630 ENGINE_TYPE_DEFAULT);
2631 else if (*it == "authoryear")
2632 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2633 ENGINE_TYPE_AUTHORYEAR);
2634 else if (*it == "numerical")
2635 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2636 ENGINE_TYPE_NUMERICAL);
2638 int i = biblioModule->citeStyleCO->findData(sel);
2639 if (biblioModule->citeStyleCO->findData(sel) == -1)
2641 biblioModule->citeStyleCO->setCurrentIndex(i);
2643 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2644 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2648 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2650 engine_types_.clear();
2654 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2656 string style = token(items, '|', n);
2657 engine_types_.push_back(style);
2660 updateCiteStyles(engine_types_, sel);
2666 // both of these should take a vector<docstring>
2668 // This is an insanely complicated attempt to make this sort of thing
2669 // work with RTL languages.
2670 docstring formatStrVec(vector<string> const & v, docstring const & s)
2672 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2676 return translateIfPossible(from_utf8(v[0]));
2677 if (v.size() == 2) {
2678 docstring retval = _("%1$s and %2$s");
2679 retval = subst(retval, _("and"), s);
2680 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2681 translateIfPossible(from_utf8(v[1])));
2683 // The idea here is to format all but the last two items...
2684 int const vSize = v.size();
2685 docstring t2 = _("%1$s, %2$s");
2686 docstring retval = translateIfPossible(from_utf8(v[0]));
2687 for (int i = 1; i < vSize - 2; ++i)
2688 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2689 //...and then to plug them, and the last two, into this schema
2690 docstring t = _("%1$s, %2$s, and %3$s");
2691 t = subst(t, _("and"), s);
2692 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2693 translateIfPossible(from_utf8(v[vSize - 1])));
2696 vector<string> idsToNames(vector<string> const & idList)
2698 vector<string> retval;
2699 vector<string>::const_iterator it = idList.begin();
2700 vector<string>::const_iterator end = idList.end();
2701 for (; it != end; ++it) {
2702 LyXModule const * const mod = theModuleList[*it];
2704 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2705 translateIfPossible(from_utf8(*it)))));
2707 retval.push_back(mod->getName());
2711 } // end anonymous namespace
2714 void GuiDocument::modulesToParams(BufferParams & bp)
2716 // update list of loaded modules
2717 bp.clearLayoutModules();
2718 int const srows = modules_sel_model_.rowCount();
2719 for (int i = 0; i < srows; ++i)
2720 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2722 // update the list of removed modules
2723 bp.clearRemovedModules();
2724 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2725 list<string>::const_iterator rit = reqmods.begin();
2726 list<string>::const_iterator ren = reqmods.end();
2728 // check each of the default modules
2729 for (; rit != ren; ++rit) {
2730 list<string>::const_iterator mit = bp.getModules().begin();
2731 list<string>::const_iterator men = bp.getModules().end();
2733 for (; mit != men; ++mit) {
2740 // the module isn't present so must have been removed by the user
2741 bp.addRemovedModule(*rit);
2746 void GuiDocument::modulesChanged()
2748 modulesToParams(bp_);
2750 if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2751 int const ret = Alert::prompt(_("Unapplied changes"),
2752 _("Some changes in the dialog were not yet applied.\n"
2753 "If you do not apply now, they will be lost after this action."),
2754 1, 1, _("&Apply"), _("&Dismiss"));
2759 modulesChanged_ = true;
2760 bp_.makeDocumentClass();
2766 void GuiDocument::updateModuleInfo()
2768 selectionManager->update();
2770 //Module description
2771 bool const focus_on_selected = selectionManager->selectedFocused();
2772 QAbstractItemView * lv;
2773 if (focus_on_selected)
2774 lv = modulesModule->selectedLV;
2776 lv = modulesModule->availableLV;
2777 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2778 modulesModule->infoML->document()->clear();
2781 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2782 GuiIdListModel const & id_model =
2783 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2784 string const modName = id_model.getIDString(idx.row());
2785 docstring desc = getModuleDescription(modName);
2787 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2788 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2791 desc += _("Module provided by document class.");
2794 docstring cat = getModuleCategory(modName);
2798 desc += bformat(_("Category: %1$s."), cat);
2801 vector<string> pkglist = getPackageList(modName);
2802 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2803 if (!pkgdesc.empty()) {
2806 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2809 pkglist = getRequiredList(modName);
2810 if (!pkglist.empty()) {
2811 vector<string> const reqdescs = idsToNames(pkglist);
2812 pkgdesc = formatStrVec(reqdescs, _("or"));
2815 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2818 pkglist = getExcludedList(modName);
2819 if (!pkglist.empty()) {
2820 vector<string> const reqdescs = idsToNames(pkglist);
2821 pkgdesc = formatStrVec(reqdescs, _( "and"));
2824 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2827 if (!isModuleAvailable(modName)) {
2830 desc += _("WARNING: Some required packages are unavailable!");
2833 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2837 void GuiDocument::updateNumbering()
2839 DocumentClass const & tclass = documentClass();
2841 numberingModule->tocTW->setUpdatesEnabled(false);
2842 numberingModule->tocTW->clear();
2844 int const depth = numberingModule->depthSL->value();
2845 int const toc = numberingModule->tocSL->value();
2846 QString const no = qt_("No");
2847 QString const yes = qt_("Yes");
2848 QTreeWidgetItem * item = 0;
2850 DocumentClass::const_iterator lit = tclass.begin();
2851 DocumentClass::const_iterator len = tclass.end();
2852 for (; lit != len; ++lit) {
2853 int const toclevel = lit->toclevel;
2854 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2855 item = new QTreeWidgetItem(numberingModule->tocTW);
2856 item->setText(0, toqstr(translateIfPossible(lit->name())));
2857 item->setText(1, (toclevel <= depth) ? yes : no);
2858 item->setText(2, (toclevel <= toc) ? yes : no);
2862 numberingModule->tocTW->setUpdatesEnabled(true);
2863 numberingModule->tocTW->update();
2867 void GuiDocument::updateDefaultFormat()
2871 // make a copy in order to consider unapplied changes
2872 BufferParams param_copy = buffer().params();
2873 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2874 int const idx = latexModule->classCO->currentIndex();
2876 string const classname = fromqstr(latexModule->classCO->getData(idx));
2877 param_copy.setBaseClass(classname);
2878 param_copy.makeDocumentClass(true);
2880 outputModule->defaultFormatCO->blockSignals(true);
2881 outputModule->defaultFormatCO->clear();
2882 outputModule->defaultFormatCO->addItem(qt_("Default"),
2883 QVariant(QString("default")));
2884 FormatList const & formats =
2885 param_copy.exportableFormats(true);
2886 for (Format const * f : formats)
2887 outputModule->defaultFormatCO->addItem
2888 (toqstr(translateIfPossible(f->prettyname())),
2889 QVariant(toqstr(f->name())));
2890 outputModule->defaultFormatCO->blockSignals(false);
2894 bool GuiDocument::isChildIncluded(string const & child)
2896 if (includeonlys_.empty())
2898 return (std::find(includeonlys_.begin(),
2899 includeonlys_.end(), child) != includeonlys_.end());
2903 void GuiDocument::applyView()
2906 preambleModule->apply(bp_);
2907 localLayout->apply(bp_);
2910 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2911 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2914 string const engine =
2915 fromqstr(biblioModule->citeEngineCO->itemData(
2916 biblioModule->citeEngineCO->currentIndex()).toString());
2917 bp_.setCiteEngine(engine);
2919 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2920 biblioModule->citeStyleCO->currentIndex()).toInt());
2921 if (theCiteEnginesList[engine]->hasEngineType(style))
2922 bp_.setCiteEngineType(style);
2924 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2926 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2928 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2929 biblioModule->bibunitsCO->currentIndex()).toString());
2931 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2933 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2934 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2935 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2937 string const bibtex_command =
2938 fromqstr(biblioModule->bibtexCO->itemData(
2939 biblioModule->bibtexCO->currentIndex()).toString());
2940 string const bibtex_options =
2941 fromqstr(biblioModule->bibtexOptionsLE->text());
2942 if (bibtex_command == "default" || bibtex_options.empty())
2943 bp_.bibtex_command = bibtex_command;
2945 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2947 if (biblioChanged_) {
2948 buffer().invalidateBibinfoCache();
2949 buffer().removeBiblioTempFiles();
2953 indicesModule->apply(bp_);
2955 // language & quotes
2956 if (langModule->defaultencodingRB->isChecked()) {
2957 bp_.inputenc = "auto";
2959 int i = langModule->encodingCO->currentIndex();
2961 bp_.inputenc = "default";
2963 QString const enc_gui =
2964 langModule->encodingCO->currentText();
2965 Encodings::const_iterator it = encodings.begin();
2966 Encodings::const_iterator const end = encodings.end();
2968 for (; it != end; ++it) {
2969 if (qt_(it->guiName()) == enc_gui &&
2971 bp_.inputenc = it->name();
2977 // should not happen
2978 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2979 bp_.inputenc = "default";
2984 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2985 langModule->quoteStyleCO->currentIndex()).toInt();
2986 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2988 QString const langname = langModule->languageCO->itemData(
2989 langModule->languageCO->currentIndex()).toString();
2990 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2991 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2992 // If current cursor language was the document language, then update it too.
2993 if (cur.current_font.language() == bp_.language) {
2994 cur.current_font.setLanguage(newlang);
2995 cur.real_current_font.setLanguage(newlang);
2997 bp_.language = newlang;
2999 QString const pack = langModule->languagePackageCO->itemData(
3000 langModule->languagePackageCO->currentIndex()).toString();
3001 if (pack == "custom")
3003 fromqstr(langModule->languagePackageLE->text());
3005 bp_.lang_package = fromqstr(pack);
3008 bp_.backgroundcolor = set_backgroundcolor;
3009 bp_.isbackgroundcolor = is_backgroundcolor;
3010 bp_.fontcolor = set_fontcolor;
3011 bp_.isfontcolor = is_fontcolor;
3012 bp_.notefontcolor = set_notefontcolor;
3013 bp_.boxbgcolor = set_boxbgcolor;
3016 if (bp_.documentClass().hasTocLevels()) {
3017 bp_.tocdepth = numberingModule->tocSL->value();
3018 bp_.secnumdepth = numberingModule->depthSL->value();
3022 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3023 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3024 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3025 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3028 bp_.graphics_driver =
3029 tex_graphics[latexModule->psdriverCO->currentIndex()];
3032 int idx = latexModule->classCO->currentIndex();
3034 string const classname = fromqstr(latexModule->classCO->getData(idx));
3035 bp_.setBaseClass(classname);
3039 modulesToParams(bp_);
3042 map<string, string> const & packages = BufferParams::auto_packages();
3043 for (map<string, string>::const_iterator it = packages.begin();
3044 it != packages.end(); ++it) {
3045 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3048 int row = mathsModule->packagesTW->row(item);
3051 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3052 if (rb->isChecked()) {
3053 bp_.use_package(it->first, BufferParams::package_auto);
3056 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3057 if (rb->isChecked()) {
3058 bp_.use_package(it->first, BufferParams::package_on);
3061 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3062 if (rb->isChecked())
3063 bp_.use_package(it->first, BufferParams::package_off);
3065 // if math is indented
3066 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3067 if (bp_.is_math_indent) {
3068 // if formulas are indented
3069 switch (mathsModule->MathIndentCO->currentIndex()) {
3071 bp_.setMathIndent(Length());
3074 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3075 mathsModule->MathIndentLengthCO));
3076 bp_.setMathIndent(mathindent);
3080 // this should never happen
3081 bp_.setMathIndent(Length());
3085 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3087 bp_.math_numbering_side = BufferParams::LEFT;
3090 bp_.math_numbering_side = BufferParams::DEFAULT;
3093 bp_.math_numbering_side = BufferParams::RIGHT;
3096 // this should never happen
3097 bp_.math_numbering_side = BufferParams::DEFAULT;
3102 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3103 bp_.pagestyle = "default";
3105 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3106 for (size_t i = 0; i != pagestyles.size(); ++i)
3107 if (pagestyles[i].second == style_gui)
3108 bp_.pagestyle = pagestyles[i].first;
3112 switch (textLayoutModule->lspacingCO->currentIndex()) {
3114 bp_.spacing().set(Spacing::Single);
3117 bp_.spacing().set(Spacing::Onehalf);
3120 bp_.spacing().set(Spacing::Double);
3123 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3125 bp_.spacing().set(Spacing::Single);
3127 bp_.spacing().set(Spacing::Other, s);
3132 if (textLayoutModule->twoColumnCB->isChecked())
3137 bp_.justification = textLayoutModule->justCB->isChecked();
3139 if (textLayoutModule->indentRB->isChecked()) {
3140 // if paragraphs are separated by an indentation
3141 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3142 switch (textLayoutModule->indentCO->currentIndex()) {
3144 bp_.setParIndent(Length());
3147 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3148 textLayoutModule->indentLengthCO));
3149 bp_.setParIndent(parindent);
3153 // this should never happen
3154 bp_.setParIndent(Length());
3158 // if paragraphs are separated by a skip
3159 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3160 switch (textLayoutModule->skipCO->currentIndex()) {
3162 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3165 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3168 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3173 widgetsToLength(textLayoutModule->skipLE,
3174 textLayoutModule->skipLengthCO)
3180 // this should never happen
3181 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3187 fromqstr(latexModule->optionsLE->text());
3189 bp_.use_default_options =
3190 latexModule->defaultOptionsCB->isChecked();
3192 if (latexModule->childDocGB->isChecked())
3194 fromqstr(latexModule->childDocLE->text());
3196 bp_.master = string();
3199 bp_.clearIncludedChildren();
3200 if (masterChildModule->includeonlyRB->isChecked()) {
3201 list<string>::const_iterator it = includeonlys_.begin();
3202 for (; it != includeonlys_.end() ; ++it) {
3203 bp_.addIncludedChildren(*it);
3206 bp_.maintain_unincluded_children =
3207 masterChildModule->maintainAuxCB->isChecked();
3210 bp_.float_placement = floatModule->get();
3213 // text should have passed validation
3214 idx = listingsModule->packageCO->currentIndex();
3215 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3216 bp_.listings_params =
3217 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3220 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3221 outputModule->defaultFormatCO->currentIndex()).toString());
3223 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3224 bp_.useNonTeXFonts = nontexfonts;
3226 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3227 if (!bp_.shell_escape)
3228 theSession().shellescapeFiles().remove(buffer().absFileName());
3229 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3230 theSession().shellescapeFiles().insert(buffer().absFileName());
3231 Buffer & buf = const_cast<Buffer &>(buffer());
3232 buf.params().shell_escape = bp_.shell_escape;
3234 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3236 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3238 int mathfmt = outputModule->mathoutCB->currentIndex();
3241 BufferParams::MathOutput const mo =
3242 static_cast<BufferParams::MathOutput>(mathfmt);
3243 bp_.html_math_output = mo;
3244 bp_.html_be_strict = outputModule->strictCB->isChecked();
3245 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3246 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3247 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3249 bp_.save_transient_properties =
3250 outputModule->saveTransientPropertiesCB->isChecked();
3253 bp_.fonts_roman[nontexfonts] =
3254 fromqstr(fontModule->fontsRomanCO->
3255 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3256 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3258 bp_.fonts_sans[nontexfonts] =
3259 fromqstr(fontModule->fontsSansCO->
3260 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3261 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3263 bp_.fonts_typewriter[nontexfonts] =
3264 fromqstr(fontModule->fontsTypewriterCO->
3265 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3266 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3268 bp_.fonts_math[nontexfonts] =
3269 fromqstr(fontModule->fontsMathCO->
3270 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3271 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3273 QString const fontenc =
3274 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3275 if (fontenc == "custom")
3276 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3278 bp_.fontenc = fromqstr(fontenc);
3281 fromqstr(fontModule->cjkFontLE->text());
3283 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3284 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3286 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3287 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3289 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3290 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3292 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3294 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3297 bp_.fonts_default_family = "default";
3299 bp_.fonts_default_family = GuiDocument::fontfamilies[
3300 fontModule->fontsDefaultCO->currentIndex()];
3302 if (fontModule->fontsizeCO->currentIndex() == 0)
3303 bp_.fontsize = "default";
3306 fromqstr(fontModule->fontsizeCO->currentText());
3309 bp_.papersize = PAPER_SIZE(
3310 pageLayoutModule->papersizeCO->currentIndex());
3312 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3313 pageLayoutModule->paperwidthUnitCO);
3315 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3316 pageLayoutModule->paperheightUnitCO);
3318 if (pageLayoutModule->facingPagesCB->isChecked())
3319 bp_.sides = TwoSides;
3321 bp_.sides = OneSide;
3323 if (pageLayoutModule->landscapeRB->isChecked())
3324 bp_.orientation = ORIENTATION_LANDSCAPE;
3326 bp_.orientation = ORIENTATION_PORTRAIT;
3329 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3331 Ui::MarginsUi const * m = marginsModule;
3333 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3334 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3335 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3336 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3337 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3338 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3339 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3340 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3343 branchesModule->apply(bp_);
3346 PDFOptions & pdf = bp_.pdfoptions();
3347 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3348 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3349 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3350 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3351 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3353 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3354 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3355 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3356 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3358 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3359 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3360 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3361 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3363 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3364 if (pdfSupportModule->fullscreenCB->isChecked())
3365 pdf.pagemode = pdf.pagemode_fullscreen;
3367 pdf.pagemode.clear();
3368 pdf.quoted_options = pdf.quoted_options_check(
3369 fromqstr(pdfSupportModule->optionsLE->text()));
3372 nonModuleChanged_ = false;
3373 shellescapeChanged_ = false;
3377 void GuiDocument::paramsToDialog()
3379 // set the default unit
3380 Length::UNIT const default_unit = Length::defaultUnit();
3383 preambleModule->update(bp_, id());
3384 localLayout->update(bp_, id());
3387 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3388 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3391 string const cite_engine = bp_.citeEngine().list().front();
3393 biblioModule->citeEngineCO->setCurrentIndex(
3394 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3396 updateEngineType(documentClass().opt_enginetype(),
3397 bp_.citeEngineType());
3399 checkPossibleCiteEngines();
3401 biblioModule->citeStyleCO->setCurrentIndex(
3402 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3404 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3406 biblioModule->bibunitsCO->clear();
3407 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3408 if (documentClass().hasLaTeXLayout("part"))
3409 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3410 if (documentClass().hasLaTeXLayout("chapter"))
3411 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3412 if (documentClass().hasLaTeXLayout("section"))
3413 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3414 if (documentClass().hasLaTeXLayout("subsection"))
3415 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3416 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3418 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3420 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3422 biblioModule->bibunitsCO->setCurrentIndex(0);
3424 updateEngineDependends();
3427 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3428 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3430 updateDefaultBiblio(bp_.defaultBiblioStyle());
3432 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3436 split(bp_.bibtex_command, command, ' ');
3438 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3440 biblioModule->bibtexCO->setCurrentIndex(bpos);
3441 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3443 // We reset to default if we do not know the specified compiler
3444 // This is for security reasons
3445 biblioModule->bibtexCO->setCurrentIndex(
3446 biblioModule->bibtexCO->findData(toqstr("default")));
3447 biblioModule->bibtexOptionsLE->clear();
3449 biblioModule->bibtexOptionsLE->setEnabled(
3450 biblioModule->bibtexCO->currentIndex() != 0);
3452 biblioChanged_ = false;
3455 // We may be called when there is no Buffer, e.g., when
3456 // the last view has just been closed.
3457 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3458 indicesModule->update(bp_, isReadOnly);
3460 // language & quotes
3461 int const pos = langModule->languageCO->findData(toqstr(
3462 bp_.language->lang()));
3463 langModule->languageCO->setCurrentIndex(pos);
3465 updateQuoteStyles();
3467 langModule->quoteStyleCO->setCurrentIndex(
3468 langModule->quoteStyleCO->findData(bp_.quotes_style));
3469 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3471 bool default_enc = true;
3472 if (bp_.inputenc != "auto") {
3473 default_enc = false;
3474 if (bp_.inputenc == "default") {
3475 langModule->encodingCO->setCurrentIndex(0);
3478 Encodings::const_iterator it = encodings.begin();
3479 Encodings::const_iterator const end = encodings.end();
3480 for (; it != end; ++it) {
3481 if (it->name() == bp_.inputenc &&
3483 enc_gui = it->guiName();
3487 int const i = langModule->encodingCO->findText(
3490 langModule->encodingCO->setCurrentIndex(i);
3492 // unknown encoding. Set to default.
3496 langModule->defaultencodingRB->setChecked(default_enc);
3497 langModule->otherencodingRB->setChecked(!default_enc);
3499 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3501 langModule->languagePackageCO->setCurrentIndex(
3502 langModule->languagePackageCO->findData("custom"));
3503 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3505 langModule->languagePackageCO->setCurrentIndex(p);
3506 langModule->languagePackageLE->clear();
3510 if (bp_.isfontcolor) {
3511 colorModule->fontColorPB->setStyleSheet(
3512 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3514 set_fontcolor = bp_.fontcolor;
3515 is_fontcolor = bp_.isfontcolor;
3517 colorModule->noteFontColorPB->setStyleSheet(
3518 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3519 set_notefontcolor = bp_.notefontcolor;
3521 if (bp_.isbackgroundcolor) {
3522 colorModule->backgroundPB->setStyleSheet(
3523 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3525 set_backgroundcolor = bp_.backgroundcolor;
3526 is_backgroundcolor = bp_.isbackgroundcolor;
3528 colorModule->boxBackgroundPB->setStyleSheet(
3529 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3530 set_boxbgcolor = bp_.boxbgcolor;
3533 int const min_toclevel = documentClass().min_toclevel();
3534 int const max_toclevel = documentClass().max_toclevel();
3535 if (documentClass().hasTocLevels()) {
3536 numberingModule->setEnabled(true);
3537 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3538 numberingModule->depthSL->setMaximum(max_toclevel);
3539 numberingModule->depthSL->setValue(bp_.secnumdepth);
3540 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3541 numberingModule->tocSL->setMaximum(max_toclevel);
3542 numberingModule->tocSL->setValue(bp_.tocdepth);
3545 numberingModule->setEnabled(false);
3546 numberingModule->tocTW->clear();
3550 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3551 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3552 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3553 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3554 bulletsModule->init();
3557 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3559 latexModule->psdriverCO->setCurrentIndex(nitem);
3563 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3564 if (bp_.is_math_indent) {
3565 Length const mathindent = bp_.getMathIndent();
3567 if (!mathindent.empty()) {
3568 lengthToWidgets(mathsModule->MathIndentLE,
3569 mathsModule->MathIndentLengthCO,
3570 mathindent, default_unit);
3573 mathsModule->MathIndentCO->setCurrentIndex(indent);
3574 enableMathIndent(indent);
3576 switch(bp_.math_numbering_side) {
3577 case BufferParams::LEFT:
3578 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3580 case BufferParams::DEFAULT:
3581 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3583 case BufferParams::RIGHT:
3584 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3587 map<string, string> const & packages = BufferParams::auto_packages();
3588 for (map<string, string>::const_iterator it = packages.begin();
3589 it != packages.end(); ++it) {
3590 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3593 int row = mathsModule->packagesTW->row(item);
3594 switch (bp_.use_package(it->first)) {
3595 case BufferParams::package_off: {
3597 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3598 rb->setChecked(true);
3601 case BufferParams::package_on: {
3603 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3604 rb->setChecked(true);
3607 case BufferParams::package_auto: {
3609 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3610 rb->setChecked(true);
3616 switch (bp_.spacing().getSpace()) {
3617 case Spacing::Other: nitem = 3; break;
3618 case Spacing::Double: nitem = 2; break;
3619 case Spacing::Onehalf: nitem = 1; break;
3620 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3624 string const & layoutID = bp_.baseClassID();
3625 setLayoutComboByIDString(layoutID);
3627 updatePagestyle(documentClass().opt_pagestyle(),
3630 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3631 if (bp_.spacing().getSpace() == Spacing::Other) {
3632 doubleToWidget(textLayoutModule->lspacingLE,
3633 bp_.spacing().getValueAsString());
3637 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3638 textLayoutModule->indentRB->setChecked(true);
3639 string parindent = bp_.getParIndent().asString();
3641 if (!parindent.empty()) {
3642 lengthToWidgets(textLayoutModule->indentLE,
3643 textLayoutModule->indentLengthCO,
3644 parindent, default_unit);
3647 textLayoutModule->indentCO->setCurrentIndex(indent);
3650 textLayoutModule->skipRB->setChecked(true);
3652 switch (bp_.getDefSkip().kind()) {
3653 case VSpace::SMALLSKIP:
3656 case VSpace::MEDSKIP:
3659 case VSpace::BIGSKIP:
3662 case VSpace::LENGTH:
3665 string const length = bp_.getDefSkip().asLyXCommand();
3666 lengthToWidgets(textLayoutModule->skipLE,
3667 textLayoutModule->skipLengthCO,
3668 length, default_unit);
3675 textLayoutModule->skipCO->setCurrentIndex(skip);
3679 textLayoutModule->twoColumnCB->setChecked(
3681 textLayoutModule->justCB->setChecked(bp_.justification);
3683 if (!bp_.options.empty()) {
3684 latexModule->optionsLE->setText(
3685 toqstr(bp_.options));
3687 latexModule->optionsLE->setText(QString());
3691 latexModule->defaultOptionsCB->setChecked(
3692 bp_.use_default_options);
3693 updateSelectedModules();
3694 selectionManager->updateProvidedModules(
3695 bp_.baseClass()->providedModules());
3696 selectionManager->updateExcludedModules(
3697 bp_.baseClass()->excludedModules());
3699 if (!documentClass().options().empty()) {
3700 latexModule->defaultOptionsLE->setText(
3701 toqstr(documentClass().options()));
3703 latexModule->defaultOptionsLE->setText(
3704 toqstr(_("[No options predefined]")));
3707 latexModule->defaultOptionsLE->setEnabled(
3708 bp_.use_default_options
3709 && !documentClass().options().empty());
3711 latexModule->defaultOptionsCB->setEnabled(
3712 !documentClass().options().empty());
3714 if (!bp_.master.empty()) {
3715 latexModule->childDocGB->setChecked(true);
3716 latexModule->childDocLE->setText(
3717 toqstr(bp_.master));
3719 latexModule->childDocLE->setText(QString());
3720 latexModule->childDocGB->setChecked(false);
3724 if (!bufferview() || !buffer().hasChildren()) {
3725 masterChildModule->childrenTW->clear();
3726 includeonlys_.clear();
3727 docPS->showPanel("Child Documents", false);
3728 if (docPS->isCurrentPanel("Child Documents"))
3729 docPS->setCurrentPanel("Document Class");
3731 docPS->showPanel("Child Documents", true);
3732 masterChildModule->setEnabled(true);
3733 includeonlys_ = bp_.getIncludedChildren();
3734 updateIncludeonlys();
3736 masterChildModule->maintainAuxCB->setChecked(
3737 bp_.maintain_unincluded_children);
3740 floatModule->set(bp_.float_placement);
3743 // break listings_params to multiple lines
3745 InsetListingsParams(bp_.listings_params).separatedParams();
3746 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3747 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3749 listingsModule->packageCO->setCurrentIndex(nn);
3753 // some languages only work with polyglossia/XeTeX
3754 Language const * lang = lyx::languages.getLanguage(
3755 fromqstr(langModule->languageCO->itemData(
3756 langModule->languageCO->currentIndex()).toString()));
3757 bool const need_fontspec =
3758 lang->babel().empty() && !lang->polyglossia().empty();
3759 bool const os_fonts_available =
3760 bp_.baseClass()->outputType() == lyx::LATEX
3761 && LaTeXFeatures::isAvailable("fontspec");
3762 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3763 fontModule->osFontsCB->setChecked(
3764 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3765 updateFontsize(documentClass().opt_fontsize(),
3768 QString font = toqstr(bp_.fontsRoman());
3769 int rpos = fontModule->fontsRomanCO->findData(font);
3771 rpos = fontModule->fontsRomanCO->count();
3772 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3774 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3775 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3777 font = toqstr(bp_.fontsSans());
3778 int spos = fontModule->fontsSansCO->findData(font);
3780 spos = fontModule->fontsSansCO->count();
3781 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3783 fontModule->fontsSansCO->setCurrentIndex(spos);
3784 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3786 font = toqstr(bp_.fontsTypewriter());
3787 int tpos = fontModule->fontsTypewriterCO->findData(font);
3789 tpos = fontModule->fontsTypewriterCO->count();
3790 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3792 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3793 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3795 font = toqstr(bp_.fontsMath());
3796 int mpos = fontModule->fontsMathCO->findData(font);
3798 mpos = fontModule->fontsMathCO->count();
3799 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3801 fontModule->fontsMathCO->setCurrentIndex(mpos);
3802 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3804 if (bp_.useNonTeXFonts && os_fonts_available) {
3805 fontModule->fontencLA->setEnabled(false);
3806 fontModule->fontencCO->setEnabled(false);
3807 fontModule->fontencLE->setEnabled(false);
3809 fontModule->fontencLA->setEnabled(true);
3810 fontModule->fontencCO->setEnabled(true);
3811 fontModule->fontencLE->setEnabled(true);
3817 if (!bp_.fonts_cjk.empty())
3818 fontModule->cjkFontLE->setText(
3819 toqstr(bp_.fonts_cjk));
3821 fontModule->cjkFontLE->setText(QString());
3823 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3824 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3826 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3827 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3828 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3829 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3830 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3831 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3833 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3835 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3837 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3838 fontModule->fontencCO->setCurrentIndex(
3839 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3840 fontModule->fontencLE->setEnabled(false);
3842 fontModule->fontencCO->setCurrentIndex(1);
3843 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3847 // This must be set _after_ fonts since updateDefaultFormat()
3848 // checks osFontsCB settings.
3849 // update combobox with formats
3850 updateDefaultFormat();
3851 int index = outputModule->defaultFormatCO->findData(toqstr(
3852 bp_.default_output_format));
3853 // set to default if format is not found
3856 outputModule->defaultFormatCO->setCurrentIndex(index);
3858 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3859 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3860 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3862 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3863 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3864 outputModule->strictCB->setChecked(bp_.html_be_strict);
3865 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3867 outputModule->saveTransientPropertiesCB
3868 ->setChecked(bp_.save_transient_properties);
3871 bool const extern_geometry =
3872 documentClass().provides("geometry");
3873 int const psize = bp_.papersize;
3874 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3875 setCustomPapersize(!extern_geometry && psize == 1);
3876 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3878 bool const landscape =
3879 bp_.orientation == ORIENTATION_LANDSCAPE;
3880 pageLayoutModule->landscapeRB->setChecked(landscape);
3881 pageLayoutModule->portraitRB->setChecked(!landscape);
3882 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3883 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3885 pageLayoutModule->facingPagesCB->setChecked(
3886 bp_.sides == TwoSides);
3888 lengthToWidgets(pageLayoutModule->paperwidthLE,
3889 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3890 lengthToWidgets(pageLayoutModule->paperheightLE,
3891 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3894 Ui::MarginsUi * m = marginsModule;
3898 lengthToWidgets(m->topLE, m->topUnit,
3899 bp_.topmargin, default_unit);
3901 lengthToWidgets(m->bottomLE, m->bottomUnit,
3902 bp_.bottommargin, default_unit);
3904 lengthToWidgets(m->innerLE, m->innerUnit,
3905 bp_.leftmargin, default_unit);
3907 lengthToWidgets(m->outerLE, m->outerUnit,
3908 bp_.rightmargin, default_unit);
3910 lengthToWidgets(m->headheightLE, m->headheightUnit,
3911 bp_.headheight, default_unit);
3913 lengthToWidgets(m->headsepLE, m->headsepUnit,
3914 bp_.headsep, default_unit);
3916 lengthToWidgets(m->footskipLE, m->footskipUnit,
3917 bp_.footskip, default_unit);
3919 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3920 bp_.columnsep, default_unit);
3923 updateUnknownBranches();
3924 branchesModule->update(bp_);
3927 PDFOptions const & pdf = bp_.pdfoptions();
3928 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3929 if (bp_.documentClass().provides("hyperref"))
3930 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3932 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3933 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3934 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3935 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3936 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3938 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3939 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3940 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3942 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3944 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3945 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3946 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3947 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3949 nn = findToken(backref_opts, pdf.backref);
3951 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3953 pdfSupportModule->fullscreenCB->setChecked
3954 (pdf.pagemode == pdf.pagemode_fullscreen);
3956 pdfSupportModule->optionsLE->setText(
3957 toqstr(pdf.quoted_options));
3959 // Make sure that the bc is in the INITIAL state
3960 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3963 // clear changed branches cache
3964 changedBranches_.clear();
3967 nonModuleChanged_ = false;
3968 shellescapeChanged_ = false;
3972 void GuiDocument::saveDocDefault()
3974 // we have to apply the params first
3980 void GuiDocument::updateAvailableModules()
3982 modules_av_model_.clear();
3983 list<modInfoStruct> modInfoList = getModuleInfo();
3984 // Sort names according to the locale
3985 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3986 return 0 < b.name.localeAwareCompare(a.name);
3989 for (modInfoStruct const & m : modInfoList) {
3990 modules_av_model_.insertRow(i, m.name, m.id, m.description);
3996 void GuiDocument::updateSelectedModules()
3998 modules_sel_model_.clear();
3999 list<modInfoStruct> const selModList = getSelectedModules();
4001 for (modInfoStruct const & m : selModList) {
4002 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4008 void GuiDocument::updateIncludeonlys()
4010 masterChildModule->childrenTW->clear();
4011 QString const no = qt_("No");
4012 QString const yes = qt_("Yes");
4014 if (includeonlys_.empty()) {
4015 masterChildModule->includeallRB->setChecked(true);
4016 masterChildModule->childrenTW->setEnabled(false);
4017 masterChildModule->maintainAuxCB->setEnabled(false);
4019 masterChildModule->includeonlyRB->setChecked(true);
4020 masterChildModule->childrenTW->setEnabled(true);
4021 masterChildModule->maintainAuxCB->setEnabled(true);
4023 ListOfBuffers children = buffer().getChildren();
4024 ListOfBuffers::const_iterator it = children.begin();
4025 ListOfBuffers::const_iterator end = children.end();
4026 bool has_unincluded = false;
4027 bool all_unincluded = true;
4028 for (; it != end; ++it) {
4029 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4032 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4033 from_utf8(buffer().filePath())));
4034 item->setText(0, toqstr(name));
4035 item->setText(1, isChildIncluded(name) ? yes : no);
4036 if (!isChildIncluded(name))
4037 has_unincluded = true;
4039 all_unincluded = false;
4041 // Both if all childs are included and if none is included
4042 // is equal to "include all" (i.e., omit \includeonly).
4043 // Thus, reset the GUI.
4044 if (!has_unincluded || all_unincluded) {
4045 masterChildModule->includeallRB->setChecked(true);
4046 masterChildModule->childrenTW->setEnabled(false);
4047 includeonlys_.clear();
4049 // If all are included, we need to update again.
4050 if (!has_unincluded)
4051 updateIncludeonlys();
4055 bool GuiDocument::isBiblatex() const
4057 QString const engine =
4058 biblioModule->citeEngineCO->itemData(
4059 biblioModule->citeEngineCO->currentIndex()).toString();
4061 // this can happen if the cite engine is unknown, which can happen
4062 // if one is using a file that came from someone else, etc. in that
4063 // case, we crash if we proceed.
4064 if (engine.isEmpty())
4067 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4071 void GuiDocument::updateDefaultBiblio(string const & style,
4072 string const & which)
4074 QString const bibstyle = toqstr(style);
4075 biblioModule->defaultBiblioCO->clear();
4080 if (which != "cbx") {
4081 // First the bbx styles
4082 biblioModule->biblatexBbxCO->clear();
4083 QStringList str = texFileList("bbxFiles.lst");
4084 // test whether we have a valid list, otherwise run rescan
4085 if (str.isEmpty()) {
4086 rescanTexStyles("bbx");
4087 str = texFileList("bbxFiles.lst");
4089 for (int i = 0; i != str.size(); ++i)
4090 str[i] = onlyFileName(str[i]);
4091 // sort on filename only (no path)
4094 for (int i = 0; i != str.count(); ++i) {
4095 QString item = changeExtension(str[i], "");
4096 if (item == bibstyle)
4098 biblioModule->biblatexBbxCO->addItem(item);
4101 if (item_nr == -1 && !bibstyle.isEmpty()) {
4102 biblioModule->biblatexBbxCO->addItem(bibstyle);
4103 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4107 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4109 biblioModule->biblatexBbxCO->clearEditText();
4112 if (which != "bbx") {
4113 // now the cbx styles
4114 biblioModule->biblatexCbxCO->clear();
4115 QStringList str = texFileList("cbxFiles.lst");
4116 // test whether we have a valid list, otherwise run rescan
4117 if (str.isEmpty()) {
4118 rescanTexStyles("cbx");
4119 str = texFileList("cbxFiles.lst");
4121 for (int i = 0; i != str.size(); ++i)
4122 str[i] = onlyFileName(str[i]);
4123 // sort on filename only (no path)
4126 for (int i = 0; i != str.count(); ++i) {
4127 QString item = changeExtension(str[i], "");
4128 if (item == bibstyle)
4130 biblioModule->biblatexCbxCO->addItem(item);
4133 if (item_nr == -1 && !bibstyle.isEmpty()) {
4134 biblioModule->biblatexCbxCO->addItem(bibstyle);
4135 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4139 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4141 biblioModule->biblatexCbxCO->clearEditText();
4144 biblioModule->biblatexBbxCO->clear();
4145 biblioModule->biblatexCbxCO->clear();
4146 QStringList str = texFileList("bstFiles.lst");
4147 // test whether we have a valid list, otherwise run rescan
4148 if (str.isEmpty()) {
4149 rescanTexStyles("bst");
4150 str = texFileList("bstFiles.lst");
4152 for (int i = 0; i != str.size(); ++i)
4153 str[i] = onlyFileName(str[i]);
4154 // sort on filename only (no path)
4157 for (int i = 0; i != str.count(); ++i) {
4158 QString item = changeExtension(str[i], "");
4159 if (item == bibstyle)
4161 biblioModule->defaultBiblioCO->addItem(item);
4164 if (item_nr == -1 && !bibstyle.isEmpty()) {
4165 biblioModule->defaultBiblioCO->addItem(bibstyle);
4166 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4170 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4172 biblioModule->defaultBiblioCO->clearEditText();
4175 updateResetDefaultBiblio();
4179 void GuiDocument::updateResetDefaultBiblio()
4181 QString const engine =
4182 biblioModule->citeEngineCO->itemData(
4183 biblioModule->citeEngineCO->currentIndex()).toString();
4184 CiteEngineType const cet =
4185 CiteEngineType(biblioModule->citeStyleCO->itemData(
4186 biblioModule->citeStyleCO->currentIndex()).toInt());
4188 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4190 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4191 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4192 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4193 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4194 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4195 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4197 biblioModule->resetDefaultBiblioPB->setEnabled(
4198 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4202 void GuiDocument::matchBiblatexStyles()
4204 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4209 void GuiDocument::updateContents()
4211 // Nothing to do here as the document settings is not cursor dependant.
4216 void GuiDocument::useClassDefaults()
4218 if (applyPB->isEnabled()) {
4219 int const ret = Alert::prompt(_("Unapplied changes"),
4220 _("Some changes in the dialog were not yet applied.\n"
4221 "If you do not apply now, they will be lost after this action."),
4222 1, 1, _("&Apply"), _("&Dismiss"));
4227 int idx = latexModule->classCO->currentIndex();
4228 string const classname = fromqstr(latexModule->classCO->getData(idx));
4229 if (!bp_.setBaseClass(classname)) {
4230 Alert::error(_("Error"), _("Unable to set document class."));
4233 bp_.useClassDefaults();
4239 void GuiDocument::setLayoutComboByIDString(string const & idString)
4241 if (!latexModule->classCO->set(toqstr(idString)))
4242 Alert::warning(_("Can't set layout!"),
4243 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4247 bool GuiDocument::isValid()
4250 validateListingsParameters().isEmpty() &&
4251 localLayout->isValid() &&
4253 // if we're asking for skips between paragraphs
4254 !textLayoutModule->skipRB->isChecked() ||
4255 // then either we haven't chosen custom
4256 textLayoutModule->skipCO->currentIndex() != 3 ||
4257 // or else a length has been given
4258 !textLayoutModule->skipLE->text().isEmpty()
4261 // if we're asking for indentation
4262 !textLayoutModule->indentRB->isChecked() ||
4263 // then either we haven't chosen custom
4264 textLayoutModule->indentCO->currentIndex() != 1 ||
4265 // or else a length has been given
4266 !textLayoutModule->indentLE->text().isEmpty()
4269 // if we're asking for math indentation
4270 !mathsModule->MathIndentCB->isChecked() ||
4271 // then either we haven't chosen custom
4272 mathsModule->MathIndentCO->currentIndex() != 1 ||
4273 // or else a length has been given
4274 !mathsModule->MathIndentLE->text().isEmpty()
4279 char const * const GuiDocument::fontfamilies[5] = {
4280 "default", "rmdefault", "sfdefault", "ttdefault", ""
4284 char const * GuiDocument::fontfamilies_gui[5] = {
4285 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4289 bool GuiDocument::initialiseParams(string const &)
4291 BufferView const * view = bufferview();
4293 bp_ = BufferParams();
4297 bp_ = view->buffer().params();
4299 updateAvailableModules();
4300 //FIXME It'd be nice to make sure here that the selected
4301 //modules are consistent: That required modules are actually
4302 //selected, and that we don't have conflicts. If so, we could
4303 //at least pop up a warning.
4309 void GuiDocument::clearParams()
4311 bp_ = BufferParams();
4315 BufferId GuiDocument::id() const
4317 BufferView const * const view = bufferview();
4318 return view? &view->buffer() : 0;
4322 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4324 return moduleNames_;
4328 list<GuiDocument::modInfoStruct> const
4329 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4331 list<modInfoStruct> mInfo;
4332 for (string const & name : mods) {
4334 LyXModule const * const mod = theModuleList[name];
4339 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4347 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4349 return makeModuleInfo(params().getModules());
4353 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4355 return makeModuleInfo(params().baseClass()->providedModules());
4359 DocumentClass const & GuiDocument::documentClass() const
4361 return bp_.documentClass();
4365 static void dispatch_bufferparams(Dialog const & dialog,
4366 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4369 ss << "\\begin_header\n";
4370 bp.writeFile(ss, buf);
4371 ss << "\\end_header\n";
4372 dialog.dispatch(FuncRequest(lfun, ss.str()));
4376 void GuiDocument::dispatchParams()
4378 // We need a non-const buffer object.
4379 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4380 // There may be several undo records; group them (bug #8998)
4381 // This handles undo groups automagically
4382 UndoGroupHelper ugh(&buf);
4384 // This must come first so that a language change is correctly noticed
4387 // Apply the BufferParams. Note that this will set the base class
4388 // and then update the buffer's layout.
4389 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4391 if (!params().master.empty()) {
4392 FileName const master_file = support::makeAbsPath(params().master,
4393 support::onlyPath(buffer().absFileName()));
4394 if (isLyXFileName(master_file.absFileName())) {
4395 Buffer * master = checkAndLoadLyXFile(master_file);
4397 if (master->isChild(const_cast<Buffer *>(&buffer())))
4398 const_cast<Buffer &>(buffer()).setParent(master);
4400 Alert::warning(_("Assigned master does not include this file"),
4401 bformat(_("You must include this file in the document\n"
4402 "'%1$s' in order to use the master document\n"
4403 "feature."), from_utf8(params().master)));
4405 Alert::warning(_("Could not load master"),
4406 bformat(_("The master document '%1$s'\n"
4407 "could not be loaded."),
4408 from_utf8(params().master)));
4412 // Generate the colours requested by each new branch.
4413 BranchList & branchlist = params().branchlist();
4414 if (!branchlist.empty()) {
4415 BranchList::const_iterator it = branchlist.begin();
4416 BranchList::const_iterator const end = branchlist.end();
4417 for (; it != end; ++it) {
4418 docstring const & current_branch = it->branch();
4419 Branch const * branch = branchlist.find(current_branch);
4420 string const x11hexname = X11hexname(branch->color());
4421 // display the new color
4422 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4423 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4426 // rename branches in the document
4427 executeBranchRenaming();
4428 // and clear changed branches cache
4429 changedBranches_.clear();
4431 // Generate the colours requested by indices.
4432 IndicesList & indiceslist = params().indiceslist();
4433 if (!indiceslist.empty()) {
4434 IndicesList::const_iterator it = indiceslist.begin();
4435 IndicesList::const_iterator const end = indiceslist.end();
4436 for (; it != end; ++it) {
4437 docstring const & current_index = it->shortcut();
4438 Index const * index = indiceslist.findShortcut(current_index);
4439 string const x11hexname = X11hexname(index->color());
4440 // display the new color
4441 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4442 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4446 // If we used an LFUN, we would not need these two lines:
4447 BufferView * bv = const_cast<BufferView *>(bufferview());
4448 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4452 void GuiDocument::setLanguage() const
4454 Language const * const newL = bp_.language;
4455 if (buffer().params().language == newL)
4458 string const & lang_name = newL->lang();
4459 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4463 void GuiDocument::saveAsDefault() const
4465 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4469 bool GuiDocument::providesOSF(QString const & font) const
4471 if (fontModule->osFontsCB->isChecked())
4472 // FIXME: we should check if the fonts really
4473 // have OSF support. But how?
4475 return theLaTeXFonts().getLaTeXFont(
4476 qstring_to_ucs4(font)).providesOSF(ot1(),
4482 bool GuiDocument::providesSC(QString const & font) const
4484 if (fontModule->osFontsCB->isChecked())
4486 return theLaTeXFonts().getLaTeXFont(
4487 qstring_to_ucs4(font)).providesSC(ot1(),
4493 bool GuiDocument::providesScale(QString const & font) const
4495 if (fontModule->osFontsCB->isChecked())
4497 return theLaTeXFonts().getLaTeXFont(
4498 qstring_to_ucs4(font)).providesScale(ot1(),
4504 bool GuiDocument::providesNoMath(QString const & font) const
4506 if (fontModule->osFontsCB->isChecked())
4508 return theLaTeXFonts().getLaTeXFont(
4509 qstring_to_ucs4(font)).providesNoMath(ot1(),
4514 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4516 if (fontModule->osFontsCB->isChecked())
4518 return theLaTeXFonts().getLaTeXFont(
4519 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4526 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4528 // FIXME Unicode: docstrings would be better for these parameters but this
4529 // change requires a lot of others
4532 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4533 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4534 // Find the first sentence of the description
4535 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4536 int pos = bf.toNextBoundary();
4539 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4540 // Tooltip is the desc followed by the module name
4541 m.description = QString("%1<i>%2</i>")
4542 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4548 void GuiDocument::loadModuleInfo()
4550 moduleNames_.clear();
4551 for (LyXModule const & mod : theModuleList)
4552 if (mod.category().substr(0, 8) != "Citation")
4553 moduleNames_.push_back(modInfo(mod));
4557 void GuiDocument::updateUnknownBranches()
4561 list<docstring> used_branches;
4562 buffer().getUsedBranches(used_branches);
4563 list<docstring>::const_iterator it = used_branches.begin();
4564 QStringList unknown_branches;
4565 for (; it != used_branches.end() ; ++it) {
4566 if (!buffer().params().branchlist().find(*it))
4567 unknown_branches.append(toqstr(*it));
4569 branchesModule->setUnknownBranches(unknown_branches);
4573 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4575 map<docstring, docstring>::iterator it = changedBranches_.begin();
4576 for (; it != changedBranches_.end() ; ++it) {
4577 if (it->second == oldname) {
4578 // branch has already been renamed
4579 it->second = newname;
4584 changedBranches_[oldname] = newname;
4588 void GuiDocument::executeBranchRenaming() const
4590 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4591 for (; it != changedBranches_.end() ; ++it) {
4592 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4593 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4598 void GuiDocument::allPackagesAuto()
4604 void GuiDocument::allPackagesAlways()
4610 void GuiDocument::allPackagesNot()
4616 void GuiDocument::allPackages(int col)
4618 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4620 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4621 rb->setChecked(true);
4626 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4629 } // namespace frontend
4632 #include "moc_GuiDocument.cpp"