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 Kimberly Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "BulletsModule.h"
17 #include "CategorizedCombo.h"
18 #include "FancyLineEdit.h"
19 #include "GuiApplication.h"
20 #include "GuiBranches.h"
21 #include "GuiIndices.h"
22 #include "GuiSelectionManager.h"
23 #include "LaTeXHighlighter.h"
24 #include "Validator.h"
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
30 #include "BufferView.h"
31 #include "CiteEnginesList.h"
33 #include "ColorCache.h"
34 #include "Converter.h"
37 #include "FloatPlacement.h"
39 #include "FuncRequest.h"
40 #include "IndicesList.h"
42 #include "LaTeXFeatures.h"
43 #include "LaTeXFonts.h"
45 #include "LayoutEnums.h"
46 #include "LayoutModuleList.h"
48 #include "ModuleList.h"
49 #include "PDFOptions.h"
50 #include "qt_helpers.h"
53 #include "TextClass.h"
57 #include "insets/InsetListingsParams.h"
58 #include "insets/InsetQuotes.h"
60 #include "support/debug.h"
61 #include "support/docstream.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"
67 #include "support/Package.h"
68 #include "support/TempFile.h"
70 #include "frontends/alert.h"
72 #include <QAbstractItemModel>
73 #include <QButtonGroup>
75 #include <QColorDialog>
76 #include <QCloseEvent>
77 #include <QDirIterator>
78 #include <QFontDatabase>
79 #include <QHeaderView>
82 #include <QTextBoundaryFinder>
83 #include <QTextCursor>
89 // a style sheet for buttons
90 // this is for example used for the background color setting button
91 static inline QString colorButtonStyleSheet(QColor const & bgColor)
93 if (bgColor.isValid()) {
94 QString rc = QLatin1String("background-color:");
103 using namespace lyx::support;
108 char const * const tex_graphics[] =
110 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
111 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
112 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
113 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
118 char const * const tex_graphics_gui[] =
120 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
121 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
122 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
123 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
124 "XeTeX", N_("None"), ""
128 char const * backref_opts[] =
130 "false", "section", "slide", "page", ""
134 char const * backref_opts_gui[] =
136 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
140 char const * lst_packages[] =
142 "Listings", "Minted", ""
146 vector<string> engine_types_;
147 vector<pair<string, QString> > pagestyles;
149 QMap<QString, QString> rmfonts_;
150 QMap<QString, QString> sffonts_;
151 QMap<QString, QString> ttfonts_;
152 QMap<QString, QString> mathfonts_;
160 lyx::RGBColor set_backgroundcolor;
161 bool is_backgroundcolor;
162 lyx::RGBColor set_fontcolor;
164 lyx::RGBColor set_notefontcolor;
165 bool is_notefontcolor;
166 lyx::RGBColor set_boxbgcolor;
168 bool forced_fontspec_activation;
170 } // anonymous namespace
175 // used when sorting the textclass list.
176 class less_textclass_avail_desc
179 bool operator()(string const & lhs, string const & rhs) const
181 // Ordering criteria:
182 // 1. Availability of text class
183 // 2. Description (lexicographic)
184 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
185 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
186 int const order = compare_no_case(
187 translateIfPossible(from_utf8(tc1.description())),
188 translateIfPossible(from_utf8(tc2.description())));
189 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
190 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
199 vector<string> getRequiredList(string const & modName)
201 LyXModule const * const mod = theModuleList[modName];
203 return vector<string>(); //empty such thing
204 return mod->getRequiredModules();
208 vector<string> getExcludedList(string const & modName)
210 LyXModule const * const mod = theModuleList[modName];
212 return vector<string>(); //empty such thing
213 return mod->getExcludedModules();
217 docstring getModuleCategory(string const & modName)
219 LyXModule const * const mod = theModuleList[modName];
222 return from_utf8(mod->category());
226 docstring getModuleDescription(string const & modName)
228 LyXModule const * const mod = theModuleList[modName];
230 return _("Module not found!");
232 return translateIfPossible(from_utf8(mod->getDescription()));
236 vector<string> getPackageList(string const & modName)
238 LyXModule const * const mod = theModuleList[modName];
240 return vector<string>(); //empty such thing
241 return mod->getPackageList();
245 bool isModuleAvailable(string const & modName)
247 LyXModule const * const mod = theModuleList[modName];
250 return mod->isAvailable();
253 } // anonymous namespace
256 /////////////////////////////////////////////////////////////////////
258 // ModuleSelectionManager
260 /////////////////////////////////////////////////////////////////////
262 /// SelectionManager for use with modules
263 class ModuleSelectionManager : public GuiSelectionManager
267 ModuleSelectionManager(QObject * parent,
268 QTreeView * availableLVarg,
269 QTreeView * selectedLVarg,
270 QPushButton * addPBarg,
271 QPushButton * delPBarg,
272 QPushButton * upPBarg,
273 QPushButton * downPBarg,
274 QStandardItemModel * availableModelarg,
275 GuiIdListModel * selectedModelarg,
276 GuiDocument const * container)
277 : GuiSelectionManager(parent, availableLVarg, selectedLVarg, addPBarg, delPBarg,
278 upPBarg, downPBarg, availableModelarg, selectedModelarg),
279 container_(container)
282 void updateProvidedModules(LayoutModuleList const & pm)
283 { provided_modules_ = pm.list(); }
285 void updateExcludedModules(LayoutModuleList const & em)
286 { excluded_modules_ = em.list(); }
289 void updateAddPB() override;
291 void updateUpPB() override;
293 void updateDownPB() override;
295 void updateDelPB() override;
296 /// returns availableModel as a GuiIdListModel
297 QStandardItemModel * getAvailableModel()
299 return dynamic_cast<QStandardItemModel *>(availableModel);
301 /// returns selectedModel as a GuiIdListModel
302 GuiIdListModel * getSelectedModel()
304 return dynamic_cast<GuiIdListModel *>(selectedModel);
306 /// keeps a list of the modules the text class provides
307 list<string> provided_modules_;
309 list<string> excluded_modules_;
311 GuiDocument const * container_;
314 void ModuleSelectionManager::updateAddPB()
316 int const arows = availableModel->rowCount();
317 QModelIndexList const avail_sels =
318 availableLV->selectionModel()->selectedRows(0);
320 // disable if there aren't any modules (?), if none of them is chosen
321 // in the dialog, or if the chosen one is already selected for use.
322 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
323 addPB->setEnabled(false);
327 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
329 if (getAvailableModel()->itemFromIndex(idx)->hasChildren()) {
330 // This is a category header
331 addPB->setEnabled(false);
335 string const modname = fromqstr(getAvailableModel()->data(idx, Qt::UserRole).toString());
338 container_->params().layoutModuleCanBeAdded(modname);
339 addPB->setEnabled(enable);
343 void ModuleSelectionManager::updateDownPB()
345 int const srows = selectedModel->rowCount();
347 downPB->setEnabled(false);
350 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
351 int const curRow = curidx.row();
352 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
353 downPB->setEnabled(false);
357 // determine whether immediately succeeding element requires this one
358 string const curmodname = getSelectedModel()->getIDString(curRow);
359 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
361 vector<string> reqs = getRequiredList(nextmodname);
363 // if it doesn't require anything....
365 downPB->setEnabled(true);
369 // Enable it if this module isn't required.
370 // FIXME This should perhaps be more flexible and check whether, even
371 // if the next one is required, there is also an earlier one that will do.
373 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
376 void ModuleSelectionManager::updateUpPB()
378 int const srows = selectedModel->rowCount();
380 upPB->setEnabled(false);
384 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
385 int curRow = curIdx.row();
386 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
387 upPB->setEnabled(false);
390 string const curmodname = getSelectedModel()->getIDString(curRow);
392 // determine whether immediately preceding element is required by this one
393 vector<string> reqs = getRequiredList(curmodname);
395 // if this one doesn't require anything....
397 upPB->setEnabled(true);
402 // Enable it if the preceding module isn't required.
403 // NOTE This is less flexible than it might be. We could check whether, even
404 // if the previous one is required, there is an earlier one that would do.
405 string const premod = getSelectedModel()->getIDString(curRow - 1);
406 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
409 void ModuleSelectionManager::updateDelPB()
411 int const srows = selectedModel->rowCount();
413 deletePB->setEnabled(false);
417 QModelIndex const & curidx =
418 selectedLV->selectionModel()->currentIndex();
419 int const curRow = curidx.row();
420 if (curRow < 0 || curRow >= srows) { // invalid index?
421 deletePB->setEnabled(false);
425 string const curmodname = getSelectedModel()->getIDString(curRow);
427 // We're looking here for a reason NOT to enable the button. If we
428 // find one, we disable it and return. If we don't, we'll end up at
429 // the end of the function, and then we enable it.
430 for (int i = curRow + 1; i < srows; ++i) {
431 string const thisMod = getSelectedModel()->getIDString(i);
432 vector<string> reqs = getRequiredList(thisMod);
433 //does this one require us?
434 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
438 // OK, so this module requires us
439 // is there an EARLIER module that also satisfies the require?
440 // NOTE We demand that it be earlier to keep the list of modules
441 // consistent with the rule that a module must be proceeded by a
442 // required module. There would be more flexible ways to proceed,
443 // but that would be a lot more complicated, and the logic here is
444 // already complicated. (That's why I've left the debugging code.)
445 // lyxerr << "Testing " << thisMod << endl;
446 bool foundone = false;
447 for (int j = 0; j < curRow; ++j) {
448 string const mod = getSelectedModel()->getIDString(j);
449 // lyxerr << "In loop: Testing " << mod << endl;
450 // do we satisfy the require?
451 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
452 // lyxerr << mod << " does the trick." << endl;
457 // did we find a module to satisfy the require?
459 // lyxerr << "No matching module found." << endl;
460 deletePB->setEnabled(false);
464 // lyxerr << "All's well that ends well." << endl;
465 deletePB->setEnabled(true);
469 /////////////////////////////////////////////////////////////////////
473 /////////////////////////////////////////////////////////////////////
475 PreambleModule::PreambleModule(QWidget * parent)
476 : UiWidget<Ui::PreambleUi>(parent), current_id_(nullptr)
478 // This is not a memory leak. The object will be destroyed
480 // @ is letter in the LyX user preamble
481 (void) new LaTeXHighlighter(preambleTE->document(), true);
482 preambleTE->setFont(guiApp->typewriterSystemFont());
483 preambleTE->setWordWrapMode(QTextOption::NoWrap);
484 setFocusProxy(preambleTE);
485 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
486 connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
487 connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
488 connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
489 connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
491 int const tabStop = 4;
492 QFontMetrics metrics(preambleTE->currentFont());
493 #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
494 // horizontalAdvance() is available starting in 5.11.0
495 // setTabStopDistance() is available starting in 5.10.0
496 preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
498 preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
503 void PreambleModule::checkFindButton()
505 findButtonPB->setEnabled(!findLE->text().isEmpty());
509 void PreambleModule::findText()
511 bool const found = preambleTE->find(findLE->text());
514 QTextCursor qtcur = preambleTE->textCursor();
515 qtcur.movePosition(QTextCursor::Start);
516 preambleTE->setTextCursor(qtcur);
517 preambleTE->find(findLE->text());
522 void PreambleModule::update(BufferParams const & params, BufferId id)
524 QString preamble = toqstr(params.preamble);
525 // Nothing to do if the params and preamble are unchanged.
526 if (id == current_id_
527 && preamble == preambleTE->document()->toPlainText())
530 QTextCursor cur = preambleTE->textCursor();
531 // Save the coords before switching to the new one.
532 preamble_coords_[current_id_] =
533 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
535 // Save the params address for further use.
537 preambleTE->document()->setPlainText(preamble);
538 Coords::const_iterator it = preamble_coords_.find(current_id_);
539 if (it == preamble_coords_.end())
540 // First time we open this one.
541 preamble_coords_[current_id_] = make_pair(0, 0);
543 // Restore saved coords.
544 cur = preambleTE->textCursor();
545 cur.setPosition(it->second.first);
546 preambleTE->setTextCursor(cur);
547 preambleTE->verticalScrollBar()->setValue(it->second.second);
552 void PreambleModule::apply(BufferParams & params)
554 params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
558 void PreambleModule::closeEvent(QCloseEvent * e)
560 // Save the coords before closing.
561 QTextCursor cur = preambleTE->textCursor();
562 preamble_coords_[current_id_] =
563 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
568 void PreambleModule::editExternal() {
573 preambleTE->setReadOnly(false);
574 FileName const tempfilename = tempfile_->name();
575 docstring const s = tempfilename.fileContents("UTF-8");
576 preambleTE->document()->setPlainText(toqstr(s));
578 editPB->setText(qt_("&Edit Externally"));
583 string const format =
584 current_id_->params().documentClass().outputFormat();
585 string const ext = theFormats().extension(format);
586 tempfile_.reset(new TempFile("preamble_editXXXXXX." + ext));
587 FileName const tempfilename = tempfile_->name();
588 string const name = tempfilename.toFilesystemEncoding();
589 ofdocstream os(name.c_str());
590 os << qstring_to_ucs4(preambleTE->document()->toPlainText());
592 preambleTE->setReadOnly(true);
593 theFormats().edit(*current_id_, tempfilename, format);
594 editPB->setText(qt_("&End Edit"));
598 /////////////////////////////////////////////////////////////////////
602 /////////////////////////////////////////////////////////////////////
605 LocalLayout::LocalLayout(QWidget * parent)
606 : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(nullptr), validated_(false)
608 locallayoutTE->setFont(guiApp->typewriterSystemFont());
609 locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
610 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
611 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
612 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
613 connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
614 int const tabStop = 4;
615 QFontMetrics metrics(locallayoutTE->currentFont());
616 #if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
617 // horizontalAdvance() is available starting in 5.11.0
618 // setTabStopDistance() is available starting in 5.10.0
619 locallayoutTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
621 locallayoutTE->setTabStopWidth(tabStop * metrics.width(' '));
626 void LocalLayout::update(BufferParams const & params, BufferId id)
628 QString layout = toqstr(params.getLocalLayout(false));
629 // Nothing to do if the params and preamble are unchanged.
630 if (id == current_id_
631 && layout == locallayoutTE->document()->toPlainText())
634 // Save the params address for further use.
636 locallayoutTE->document()->setPlainText(layout);
641 void LocalLayout::apply(BufferParams & params)
643 docstring const layout =
644 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
645 params.setLocalLayout(layout, false);
649 void LocalLayout::hideConvert()
651 convertPB->setEnabled(false);
652 convertLB->setText("");
658 void LocalLayout::textChanged()
660 validLB->setText("");
661 string const layout =
662 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
664 if (layout.empty()) {
666 validatePB->setEnabled(false);
669 } else if (!validatePB->isEnabled()) {
670 // if that's already enabled, we shouldn't need to do anything.
672 validatePB->setEnabled(true);
679 void LocalLayout::convert() {
680 string const layout =
681 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
682 string const newlayout = TextClass::convert(layout);
683 if (!newlayout.empty())
684 locallayoutTE->setPlainText(toqstr(newlayout));
689 void LocalLayout::convertPressed() {
696 void LocalLayout::validate() {
698 static const QString vpar("<p style=\"font-weight: bold; text-align:left\">%1</p>");
699 // Flashy red bold text
700 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; text-align:left\">"
702 string const layout =
703 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
704 if (!layout.empty()) {
705 TextClass::ReturnValues const ret = TextClass::validate(layout);
706 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
707 validatePB->setEnabled(false);
708 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
709 : ivpar.arg(qt_("Layout is invalid!")));
710 if (ret == TextClass::OK_OLDFORMAT) {
712 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
714 if (TextClass::convert(layout).empty()) {
715 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
716 // then maybe the layout is still valid, but its format is more
717 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
718 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
719 convertPB->setEnabled(false);
720 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
721 ? ivpar.arg(qt_("Conversion to current format impossible!"))
722 : vpar.arg(qt_("Conversion to current stable format "
724 convertLB->setText(text);
726 convertPB->setEnabled(true);
727 convertLB->setText(qt_("Convert to current format"));
738 void LocalLayout::validatePressed() {
744 void LocalLayout::editExternal() {
749 locallayoutTE->setReadOnly(false);
750 FileName const tempfilename = tempfile_->name();
751 docstring const s = tempfilename.fileContents("UTF-8");
752 locallayoutTE->document()->setPlainText(toqstr(s));
754 editPB->setText(qt_("&Edit Externally"));
759 string const format =
760 current_id_->params().documentClass().outputFormat();
761 string const ext = theFormats().extension(format);
762 tempfile_.reset(new TempFile("preamble_editXXXXXX." + ext));
763 FileName const tempfilename = tempfile_->name();
764 string const name = tempfilename.toFilesystemEncoding();
765 ofdocstream os(name.c_str());
766 os << qstring_to_ucs4(locallayoutTE->document()->toPlainText());
768 locallayoutTE->setReadOnly(true);
769 theFormats().edit(*current_id_, tempfilename, format);
770 editPB->setText(qt_("&End Edit"));
771 validatePB->setEnabled(false);
776 /////////////////////////////////////////////////////////////////////
780 /////////////////////////////////////////////////////////////////////
783 GuiDocument::GuiDocument(GuiView & lv)
784 : GuiDialog(lv, "document", qt_("Document Settings")),
785 biblioChanged_(false), nonModuleChanged_(false),
786 modulesChanged_(false), shellescapeChanged_(false),
787 switchback_(false), prompted_(false)
791 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
792 this, SLOT(slotButtonBox(QAbstractButton *)));
794 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
795 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
797 // Manage the restore, ok, apply, restore and cancel/close buttons
798 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
799 bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
800 bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
801 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
802 bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
806 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
807 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
808 this, SLOT(change_adaptor()));
809 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
810 this, SLOT(setLSpacing(int)));
811 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
812 this, SLOT(change_adaptor()));
814 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
815 this, SLOT(change_adaptor()));
816 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
817 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
818 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
819 this, SLOT(change_adaptor()));
820 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
821 this, SLOT(setIndent(int)));
822 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
823 this, SLOT(change_adaptor()));
824 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
825 this, SLOT(change_adaptor()));
827 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
828 this, SLOT(change_adaptor()));
829 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
830 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
831 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
832 this, SLOT(change_adaptor()));
833 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
834 this, SLOT(setSkip(int)));
835 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
836 this, SLOT(change_adaptor()));
837 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
838 this, SLOT(change_adaptor()));
840 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
841 this, SLOT(enableIndent(bool)));
842 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
843 this, SLOT(enableSkip(bool)));
845 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
846 this, SLOT(change_adaptor()));
847 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
848 this, SLOT(setColSep()));
849 connect(textLayoutModule->justCB, SIGNAL(clicked()),
850 this, SLOT(change_adaptor()));
852 connect(textLayoutModule->tableStyleCO, SIGNAL(activated(int)),
853 this, SLOT(change_adaptor()));
855 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
856 textLayoutModule->lspacingLE));
857 textLayoutModule->indentLE->setValidator(new LengthValidator(
858 textLayoutModule->indentLE));
859 textLayoutModule->skipLE->setValidator(new LengthValidator(
860 textLayoutModule->skipLE));
862 textLayoutModule->indentCO->addItem(qt_("Default"), toqstr("default"));
863 textLayoutModule->indentCO->addItem(qt_("Custom"), toqstr("custom"));
864 textLayoutModule->skipCO->addItem(qt_("Half line height"), VSpace::HALFLINE);
865 textLayoutModule->skipCO->addItem(qt_("Line height"), VSpace::FULLLINE);
866 textLayoutModule->skipCO->addItem(qt_("Small Skip"), VSpace::SMALLSKIP);
867 textLayoutModule->skipCO->addItem(qt_("Medium Skip"), VSpace::MEDSKIP);
868 textLayoutModule->skipCO->addItem(qt_("Big Skip"), VSpace::BIGSKIP);
869 textLayoutModule->skipCO->addItem(qt_("Custom"), VSpace::LENGTH);
870 textLayoutModule->lspacingCO->insertItem(
871 Spacing::Single, qt_("Single"));
872 textLayoutModule->lspacingCO->insertItem(
873 Spacing::Onehalf, qt_("OneHalf"));
874 textLayoutModule->lspacingCO->insertItem(
875 Spacing::Double, qt_("Double"));
876 textLayoutModule->lspacingCO->insertItem(
877 Spacing::Other, qt_("Custom"));
878 // initialize the length validator
879 bc().addCheckedLineEdit(textLayoutModule->indentLE, textLayoutModule->indentRB);
880 bc().addCheckedLineEdit(textLayoutModule->skipLE, textLayoutModule->skipRB);
882 textLayoutModule->tableStyleCO->addItem(qt_("Default"), toqstr("default"));
886 // master/child handling
887 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
889 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
890 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
891 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
892 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
893 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
894 masterChildModule->maintainGB, SLOT(setEnabled(bool)));
895 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
896 this, SLOT(change_adaptor()));
897 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
898 this, SLOT(change_adaptor()));
899 connect(masterChildModule->maintainCRNoneRB, SIGNAL(clicked()),
900 this, SLOT(change_adaptor()));
901 connect(masterChildModule->maintainCRMostlyRB, SIGNAL(clicked()),
902 this, SLOT(change_adaptor()));
903 connect(masterChildModule->maintainCRStrictRB, SIGNAL(clicked()),
904 this, SLOT(change_adaptor()));
905 masterChildModule->childrenTW->setColumnCount(2);
906 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
907 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
908 masterChildModule->childrenTW->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
909 masterChildModule->childrenTW->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
912 outputModule = new UiWidget<Ui::OutputUi>(this);
914 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
915 this, SLOT(change_adaptor()));
916 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
917 this, SLOT(change_adaptor()));
918 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
919 this, SLOT(change_adaptor()));
920 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
921 this, SLOT(change_adaptor()));
922 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
923 this, SLOT(change_adaptor()));
924 connect(outputModule->tableoutCB, SIGNAL(currentIndexChanged(int)),
925 this, SLOT(change_adaptor()));
926 connect(outputModule->mathmlprefixCB, SIGNAL(currentIndexChanged(int)),
927 this, SLOT(change_adaptor()));
929 connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
930 this, SLOT(shellescapeChanged()));
931 connect(outputModule->outputsyncCB, SIGNAL(toggled(bool)),
932 this, SLOT(setOutputSync(bool)));
933 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
934 this, SLOT(change_adaptor()));
935 outputModule->synccustomCB->addItem("");
936 outputModule->synccustomCB->addItem("\\synctex=1");
937 outputModule->synccustomCB->addItem("\\synctex=-1");
938 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
940 outputModule->synccustomCB->lineEdit()->setValidator(new NoNewLineValidator(
941 outputModule->synccustomCB));
943 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
944 this, SLOT(change_adaptor()));
945 connect(outputModule->postponeFragileCB, SIGNAL(clicked()),
946 this, SLOT(change_adaptor()));
950 // this must precede font, since fonts depend on this
951 langModule = new UiWidget<Ui::LanguageUi>(this);
952 connect(langModule->languageCO, SIGNAL(activated(int)),
953 this, SLOT(change_adaptor()));
954 connect(langModule->languageCO, SIGNAL(activated(int)),
955 this, SLOT(languageChanged(int)));
956 connect(langModule->encodingCO, SIGNAL(activated(int)),
957 this, SLOT(change_adaptor()));
958 connect(langModule->encodingCO, SIGNAL(activated(int)),
959 this, SLOT(encodingSwitched(int)));
960 connect(langModule->unicodeEncodingCO, SIGNAL(activated(int)),
961 this, SLOT(change_adaptor()));
962 connect(langModule->autoEncodingCO, SIGNAL(activated(int)),
963 this, SLOT(change_adaptor()));
964 connect(langModule->customEncodingCO, SIGNAL(activated(int)),
965 this, SLOT(change_adaptor()));
966 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
967 this, SLOT(change_adaptor()));
968 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
969 this, SLOT(change_adaptor()));
970 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
971 this, SLOT(change_adaptor()));
972 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
973 this, SLOT(languagePackageChanged(int)));
974 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
975 this, SLOT(change_adaptor()));
977 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
978 langModule->languagePackageLE));
980 QAbstractItemModel * language_model = guiApp->languageModel();
981 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
982 language_model->sort(0);
983 langModule->languageCO->setModel(language_model);
984 langModule->languageCO->setModelColumn(0);
986 langModule->encodingCO->addItem(qt_("Unicode (utf8)"));
987 langModule->encodingCO->addItem(qt_("Traditional (auto-selected)"));
988 langModule->encodingCO->addItem(qt_("Custom"));
989 langModule->encodingCO->setItemData(EncodingSets::unicode,
990 qt_("Select Unicode (utf8) encoding."), Qt::ToolTipRole);
991 langModule->encodingCO->setItemData(EncodingSets::legacy,
992 qt_("Use language-dependent traditional encodings."), Qt::ToolTipRole);
993 langModule->encodingCO->setItemData(EncodingSets::custom,
994 qt_("Select a custom, document-wide encoding."), Qt::ToolTipRole);
996 // basic Unicode encodings: keep order
997 const QStringList utf8_base_encodings = {"utf8", "utf8-plain", "utf8x"};
998 for (auto const & i : utf8_base_encodings) {
999 langModule->unicodeEncodingCO->addItem(
1000 qt_(encodings.fromLyXName(fromqstr(i))->guiName()), i);
1002 langModule->unicodeEncodingCO->setItemData(0,
1003 qt_("Standard Unicode support by the ``inputenc'' package."),
1005 langModule->unicodeEncodingCO->setItemData(1,
1006 qt_("Use UTF-8 'as-is': do not load any supporting packages, "
1007 "do not convert any characters to LaTeX macros. "
1008 "For use with non-TeX fonts (XeTeX/LuaTeX) or custom preamble code."),
1010 langModule->unicodeEncodingCO->setItemData(2,
1011 qt_("Load ``inputenc'' with option 'utf8x' "
1012 "for extended Unicode support by the ``ucs'' package."),
1014 langModule->autoEncodingCO->addItem(qt_("Language Default"), toqstr("auto-legacy"));
1015 langModule->autoEncodingCO->addItem(qt_("Language Default (no inputenc)"), toqstr("auto-legacy-plain"));
1016 langModule->autoEncodingCO->setItemData(0,
1017 qt_("Use the traditional default encoding of the text language. Switch encoding "
1018 "if a text part is set to a language with different default."),
1020 langModule->autoEncodingCO->setItemData(1,
1021 qt_("Do not load the 'inputenc' package. Switch encoding if required "
1022 "but do not write input encoding switch commands to the source."),
1025 QMap<QString,QString> encodingmap;
1026 QMap<QString,QString> encodingmap_utf8;
1027 for (auto const & encvar : encodings) {
1028 if (encvar.unsafe() ||encvar.guiName().empty()
1029 || utf8_base_encodings.contains(toqstr(encvar.name())))
1031 if (encvar.name().find("utf8") == 0)
1032 encodingmap_utf8.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
1034 encodingmap.insert(qt_(encvar.guiName()), toqstr(encvar.name()));
1036 for (auto const & i : encodingmap_utf8.keys()) {
1037 langModule->unicodeEncodingCO->addItem(i, encodingmap_utf8.value(i));
1039 for (auto const & i : encodingmap.keys()) {
1040 langModule->customEncodingCO->addItem(i, encodingmap.value(i));
1042 // equalise the width of encoding selectors
1043 langModule->autoEncodingCO->setMinimumSize(
1044 langModule->unicodeEncodingCO->minimumSizeHint());
1045 langModule->customEncodingCO->setMinimumSize(
1046 langModule->unicodeEncodingCO->minimumSizeHint());
1048 langModule->languagePackageCO->addItem(
1049 qt_("Default"), toqstr("default"));
1050 langModule->languagePackageCO->addItem(
1051 qt_("Automatic"), toqstr("auto"));
1052 langModule->languagePackageCO->addItem(
1053 qt_("Always Babel"), toqstr("babel"));
1054 langModule->languagePackageCO->addItem(
1055 qt_("Custom"), toqstr("custom"));
1056 langModule->languagePackageCO->addItem(
1057 qt_("None[[language package]]"), toqstr("none"));
1061 fontModule = new FontModule(this);
1062 connect(fontModule->osFontsCB, SIGNAL(clicked()),
1063 this, SLOT(change_adaptor()));
1064 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
1065 this, SLOT(osFontsChanged(bool)));
1066 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
1067 this, SLOT(change_adaptor()));
1068 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
1069 this, SLOT(romanChanged(int)));
1070 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
1071 this, SLOT(change_adaptor()));
1072 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
1073 this, SLOT(sansChanged(int)));
1074 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
1075 this, SLOT(change_adaptor()));
1076 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
1077 this, SLOT(ttChanged(int)));
1078 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
1079 this, SLOT(change_adaptor()));
1080 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
1081 this, SLOT(mathFontChanged(int)));
1082 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
1083 this, SLOT(change_adaptor()));
1084 connect(fontModule->fontencCO, SIGNAL(activated(int)),
1085 this, SLOT(change_adaptor()));
1086 connect(fontModule->fontencCO, SIGNAL(activated(int)),
1087 this, SLOT(fontencChanged(int)));
1088 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
1089 this, SLOT(change_adaptor()));
1090 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
1091 this, SLOT(change_adaptor()));
1092 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
1093 this, SLOT(change_adaptor()));
1094 connect(fontModule->microtypeCB, SIGNAL(clicked()),
1095 this, SLOT(change_adaptor()));
1096 connect(fontModule->dashesCB, SIGNAL(clicked()),
1097 this, SLOT(change_adaptor()));
1098 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
1099 this, SLOT(change_adaptor()));
1100 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
1101 this, SLOT(change_adaptor()));
1102 connect(fontModule->fontScCB, SIGNAL(clicked()),
1103 this, SLOT(change_adaptor()));
1104 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
1105 this, SLOT(fontScToggled(bool)));
1106 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
1107 this, SLOT(change_adaptor()));
1108 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
1109 this, SLOT(fontOsfToggled(bool)));
1110 connect(fontModule->fontSansOsfCB, SIGNAL(clicked()),
1111 this, SLOT(change_adaptor()));
1112 connect(fontModule->fontTypewriterOsfCB, SIGNAL(clicked()),
1113 this, SLOT(change_adaptor()));
1114 connect(fontModule->fontspecRomanLE, SIGNAL(textChanged(const QString &)),
1115 this, SLOT(change_adaptor()));
1116 connect(fontModule->fontspecSansLE, SIGNAL(textChanged(const QString &)),
1117 this, SLOT(change_adaptor()));
1118 connect(fontModule->fontspecTypewriterLE, SIGNAL(textChanged(const QString &)),
1119 this, SLOT(change_adaptor()));
1121 fontModule->fontencLE->setValidator(new NoNewLineValidator(
1122 fontModule->fontencLE));
1123 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
1124 fontModule->cjkFontLE));
1125 fontModule->fontspecRomanLE->setValidator(new NoNewLineValidator(
1126 fontModule->fontspecRomanLE));
1127 fontModule->fontspecSansLE->setValidator(new NoNewLineValidator(
1128 fontModule->fontspecSansLE));
1129 fontModule->fontspecTypewriterLE->setValidator(new NoNewLineValidator(
1130 fontModule->fontspecTypewriterLE));
1134 fontModule->fontsizeCO->addItem(qt_("Default"));
1135 fontModule->fontsizeCO->addItem(qt_("10"));
1136 fontModule->fontsizeCO->addItem(qt_("11"));
1137 fontModule->fontsizeCO->addItem(qt_("12"));
1139 fontModule->fontencCO->addItem(qt_("Automatic[[encoding]]"), QString("auto"));
1140 fontModule->fontencCO->addItem(qt_("Class Default"), QString("default"));
1141 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
1143 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
1144 fontModule->fontsDefaultCO->addItem(
1145 qt_(GuiDocument::fontfamilies_gui[n]));
1147 if (!LaTeXFeatures::isAvailable("fontspec"))
1148 fontModule->osFontsCB->setToolTip(
1149 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
1150 "You need to install the package \"fontspec\" to use this feature"));
1154 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
1155 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
1156 this, SLOT(papersizeChanged(int)));
1157 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
1158 this, SLOT(papersizeChanged(int)));
1159 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
1160 this, SLOT(change_adaptor()));
1161 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
1162 this, SLOT(change_adaptor()));
1163 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
1164 this, SLOT(change_adaptor()));
1165 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
1166 this, SLOT(change_adaptor()));
1167 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
1168 this, SLOT(change_adaptor()));
1169 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
1170 this, SLOT(change_adaptor()));
1171 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
1172 this, SLOT(change_adaptor()));
1173 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
1174 this, SLOT(change_adaptor()));
1175 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
1176 this, SLOT(change_adaptor()));
1177 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
1178 this, SLOT(change_adaptor()));
1180 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1181 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
1182 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
1183 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
1184 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
1185 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
1186 pageLayoutModule->paperheightL);
1187 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
1188 pageLayoutModule->paperwidthL);
1190 QComboBox * cb = pageLayoutModule->papersizeCO;
1191 cb->addItem(qt_("Default"));
1192 cb->addItem(qt_("Custom"));
1193 cb->addItem(qt_("US letter"));
1194 cb->addItem(qt_("US legal"));
1195 cb->addItem(qt_("US executive"));
1196 cb->addItem(qt_("A0"));
1197 cb->addItem(qt_("A1"));
1198 cb->addItem(qt_("A2"));
1199 cb->addItem(qt_("A3"));
1200 cb->addItem(qt_("A4"));
1201 cb->addItem(qt_("A5"));
1202 cb->addItem(qt_("A6"));
1203 cb->addItem(qt_("B0"));
1204 cb->addItem(qt_("B1"));
1205 cb->addItem(qt_("B2"));
1206 cb->addItem(qt_("B3"));
1207 cb->addItem(qt_("B4"));
1208 cb->addItem(qt_("B5"));
1209 cb->addItem(qt_("B6"));
1210 cb->addItem(qt_("C0"));
1211 cb->addItem(qt_("C1"));
1212 cb->addItem(qt_("C2"));
1213 cb->addItem(qt_("C3"));
1214 cb->addItem(qt_("C4"));
1215 cb->addItem(qt_("C5"));
1216 cb->addItem(qt_("C6"));
1217 cb->addItem(qt_("JIS B0"));
1218 cb->addItem(qt_("JIS B1"));
1219 cb->addItem(qt_("JIS B2"));
1220 cb->addItem(qt_("JIS B3"));
1221 cb->addItem(qt_("JIS B4"));
1222 cb->addItem(qt_("JIS B5"));
1223 cb->addItem(qt_("JIS B6"));
1224 // remove the %-items from the unit choice
1225 pageLayoutModule->paperwidthUnitCO->noPercents();
1226 pageLayoutModule->paperheightUnitCO->noPercents();
1227 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
1228 pageLayoutModule->paperheightLE));
1229 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
1230 pageLayoutModule->paperwidthLE));
1234 marginsModule = new UiWidget<Ui::MarginsUi>(this);
1235 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1236 this, SLOT(setCustomMargins(bool)));
1237 connect(marginsModule->marginCB, SIGNAL(clicked()),
1238 this, SLOT(change_adaptor()));
1239 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1240 this, SLOT(change_adaptor()));
1241 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1242 this, SLOT(change_adaptor()));
1243 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1244 this, SLOT(change_adaptor()));
1245 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1246 this, SLOT(change_adaptor()));
1247 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1248 this, SLOT(change_adaptor()));
1249 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1250 this, SLOT(change_adaptor()));
1251 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1252 this, SLOT(change_adaptor()));
1253 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1254 this, SLOT(change_adaptor()));
1255 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1256 this, SLOT(change_adaptor()));
1257 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1258 this, SLOT(change_adaptor()));
1259 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1260 this, SLOT(change_adaptor()));
1261 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1262 this, SLOT(change_adaptor()));
1263 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1264 this, SLOT(change_adaptor()));
1265 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1266 this, SLOT(change_adaptor()));
1267 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1268 this, SLOT(change_adaptor()));
1269 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1270 this, SLOT(change_adaptor()));
1271 marginsModule->topLE->setValidator(new LengthValidator(
1272 marginsModule->topLE));
1273 marginsModule->bottomLE->setValidator(new LengthValidator(
1274 marginsModule->bottomLE));
1275 marginsModule->innerLE->setValidator(new LengthValidator(
1276 marginsModule->innerLE));
1277 marginsModule->outerLE->setValidator(new LengthValidator(
1278 marginsModule->outerLE));
1279 marginsModule->headsepLE->setValidator(new LengthValidator(
1280 marginsModule->headsepLE));
1281 marginsModule->headheightLE->setValidator(new LengthValidator(
1282 marginsModule->headheightLE));
1283 marginsModule->footskipLE->setValidator(new LengthValidator(
1284 marginsModule->footskipLE));
1285 marginsModule->columnsepLE->setValidator(new LengthValidator(
1286 marginsModule->columnsepLE));
1288 bc().addCheckedLineEdit(marginsModule->topLE,
1289 marginsModule->topL);
1290 bc().addCheckedLineEdit(marginsModule->bottomLE,
1291 marginsModule->bottomL);
1292 bc().addCheckedLineEdit(marginsModule->innerLE,
1293 marginsModule->innerL);
1294 bc().addCheckedLineEdit(marginsModule->outerLE,
1295 marginsModule->outerL);
1296 bc().addCheckedLineEdit(marginsModule->headsepLE,
1297 marginsModule->headsepL);
1298 bc().addCheckedLineEdit(marginsModule->headheightLE,
1299 marginsModule->headheightL);
1300 bc().addCheckedLineEdit(marginsModule->footskipLE,
1301 marginsModule->footskipL);
1302 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1303 marginsModule->columnsepL);
1307 colorModule = new UiWidget<Ui::ColorUi>(this);
1308 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1309 this, SLOT(changeFontColor()));
1310 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1311 this, SLOT(deleteFontColor()));
1312 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1313 this, SLOT(changeNoteFontColor()));
1314 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1315 this, SLOT(deleteNoteFontColor()));
1316 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1317 this, SLOT(changeBackgroundColor()));
1318 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1319 this, SLOT(deleteBackgroundColor()));
1320 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1321 this, SLOT(changeBoxBackgroundColor()));
1322 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1323 this, SLOT(deleteBoxBackgroundColor()));
1327 changesModule = new UiWidget<Ui::ChangeTrackingUi>(this);
1328 connect(changesModule->trackChangesCB, SIGNAL(clicked()),
1329 this, SLOT(change_adaptor()));
1330 connect(changesModule->outputChangesCB, SIGNAL(toggled(bool)),
1331 this, SLOT(outputChangesToggled(bool)));
1332 connect(changesModule->changeBarsCB, SIGNAL(clicked()),
1333 this, SLOT(change_adaptor()));
1337 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1338 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1339 this, SLOT(change_adaptor()));
1340 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1341 this, SLOT(change_adaptor()));
1342 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1343 this, SLOT(updateNumbering()));
1344 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1345 this, SLOT(updateNumbering()));
1346 numberingModule->tocTW->setColumnCount(3);
1347 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1348 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1349 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1350 numberingModule->tocTW->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
1351 connect(numberingModule->linenoCB, SIGNAL(toggled(bool)),
1352 this, SLOT(linenoToggled(bool)));
1353 connect(numberingModule->linenoCB, SIGNAL(clicked()),
1354 this, SLOT(change_adaptor()));
1355 connect(numberingModule->linenoLE, SIGNAL(textChanged(QString)),
1356 this, SLOT(change_adaptor()));
1360 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1361 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1362 this, SLOT(citeEngineChanged(int)));
1363 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1364 this, SLOT(citeStyleChanged()));
1365 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1366 this, SLOT(biblioChanged()));
1367 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1368 this, SLOT(biblioChanged()));
1369 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1370 this, SLOT(bibtexChanged(int)));
1371 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1372 this, SLOT(biblioChanged()));
1373 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1374 this, SLOT(biblioChanged()));
1375 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1376 this, SLOT(biblioChanged()));
1377 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1378 this, SLOT(biblioChanged()));
1379 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1380 this, SLOT(updateResetDefaultBiblio()));
1381 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1382 this, SLOT(biblioChanged()));
1383 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1384 this, SLOT(biblioChanged()));
1385 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1386 this, SLOT(updateResetDefaultBiblio()));
1387 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1388 this, SLOT(biblioChanged()));
1389 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1390 this, SLOT(biblioChanged()));
1391 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1392 this, SLOT(updateResetDefaultBiblio()));
1393 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1394 this, SLOT(rescanBibFiles()));
1395 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1396 this, SLOT(resetDefaultBibfile()));
1397 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1398 this, SLOT(resetDefaultCbxBibfile()));
1399 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1400 this, SLOT(resetDefaultBbxBibfile()));
1401 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1402 this, SLOT(matchBiblatexStyles()));
1404 biblioModule->citeEngineCO->clear();
1405 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1406 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1407 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1408 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1412 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1413 biblioModule->bibtexOptionsLE));
1414 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1415 biblioModule->defaultBiblioCO->lineEdit()));
1416 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1417 biblioModule->citePackageOptionsLE));
1419 // NOTE: we do not provide "custom" here for security reasons!
1420 biblioModule->bibtexCO->clear();
1421 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1422 for (auto const & alts : lyxrc.bibtex_alternatives) {
1423 QString const command = toqstr(alts).left(toqstr(alts).indexOf(" "));
1424 biblioModule->bibtexCO->addItem(command, command);
1429 indicesModule = new GuiIndices;
1430 connect(indicesModule, SIGNAL(changed()),
1431 this, SLOT(change_adaptor()));
1435 mathsModule = new UiWidget<Ui::MathsUi>(this);
1436 QStringList headers;
1437 headers << qt_("Package") << qt_("Load automatically")
1438 << qt_("Load always") << qt_("Do not load");
1439 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1440 mathsModule->packagesTW->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
1441 map<string, string> const & packages = BufferParams::auto_packages();
1442 mathsModule->packagesTW->setRowCount(packages.size());
1444 for (auto const & pkgvar : packages) {
1445 docstring const package = from_ascii(pkgvar.first);
1446 QString autoTooltip = qt_(pkgvar.second);
1447 QString alwaysTooltip;
1448 if (package == "amsmath")
1450 qt_("The AMS LaTeX packages are always used");
1452 alwaysTooltip = toqstr(bformat(
1453 _("The LaTeX package %1$s is always used"),
1455 QString neverTooltip;
1456 if (package == "amsmath")
1458 qt_("The AMS LaTeX packages are never used");
1460 neverTooltip = toqstr(bformat(
1461 _("The LaTeX package %1$s is never used"),
1463 QRadioButton * autoRB = new QRadioButton(mathsModule);
1464 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1465 QRadioButton * neverRB = new QRadioButton(mathsModule);
1466 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1467 packageGroup->addButton(autoRB);
1468 packageGroup->addButton(alwaysRB);
1469 packageGroup->addButton(neverRB);
1470 autoRB->setToolTip(autoTooltip);
1471 alwaysRB->setToolTip(alwaysTooltip);
1472 neverRB->setToolTip(neverTooltip);
1474 // Pack the buttons in a layout in order to get proper alignment
1475 QWidget * autoRBWidget = new QWidget();
1476 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1477 autoRBLayout->addWidget(autoRB);
1478 autoRBLayout->setAlignment(Qt::AlignCenter);
1479 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1480 autoRBWidget->setLayout(autoRBLayout);
1482 QWidget * alwaysRBWidget = new QWidget();
1483 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1484 alwaysRBLayout->addWidget(alwaysRB);
1485 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1486 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1487 alwaysRBWidget->setLayout(alwaysRBLayout);
1489 QWidget * neverRBWidget = new QWidget();
1490 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1491 neverRBLayout->addWidget(neverRB);
1492 neverRBLayout->setAlignment(Qt::AlignCenter);
1493 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1494 neverRBWidget->setLayout(neverRBLayout);
1496 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1497 mathsModule->packagesTW->setItem(packnum, 0, pack);
1498 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1499 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1500 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1502 connect(autoRB, SIGNAL(clicked()),
1503 this, SLOT(change_adaptor()));
1504 connect(alwaysRB, SIGNAL(clicked()),
1505 this, SLOT(change_adaptor()));
1506 connect(neverRB, SIGNAL(clicked()),
1507 this, SLOT(change_adaptor()));
1510 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1511 this, SLOT(allPackagesAuto()));
1512 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1513 this, SLOT(allPackagesAlways()));
1514 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1515 this, SLOT(allPackagesNot()));
1516 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1517 this, SLOT(change_adaptor()));
1518 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1519 this, SLOT(change_adaptor()));
1520 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1521 this, SLOT(change_adaptor()));
1522 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1523 this, SLOT(change_adaptor()));
1525 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1526 this, SLOT(allowMathIndent()));
1527 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1528 this, SLOT(change_adaptor()));
1529 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1530 this, SLOT(enableMathIndent(int)));
1531 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1532 this, SLOT(change_adaptor()));
1533 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1534 this, SLOT(change_adaptor()));
1535 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1536 this, SLOT(change_adaptor()));
1539 mathsModule->MathIndentCO->addItem(qt_("Default"), toqstr("default"));
1540 mathsModule->MathIndentCO->addItem(qt_("Custom"), toqstr("custom"));
1541 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1542 mathsModule->MathIndentLE));
1543 // initialize the length validator
1544 bc().addCheckedLineEdit(mathsModule->MathIndentLE, mathsModule->MathIndentCB);
1545 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1546 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1547 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1548 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1552 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1553 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1554 this, SLOT(change_adaptor()));
1555 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1556 this, SLOT(change_adaptor()));
1557 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1558 this, SLOT(change_adaptor()));
1559 connect(latexModule->classCO, SIGNAL(activated(int)),
1560 this, SLOT(classChanged_adaptor()));
1561 connect(latexModule->classCO, SIGNAL(activated(int)),
1562 this, SLOT(change_adaptor()));
1563 connect(latexModule->layoutPB, SIGNAL(clicked()),
1564 this, SLOT(browseLayout()));
1565 connect(latexModule->layoutPB, SIGNAL(clicked()),
1566 this, SLOT(change_adaptor()));
1567 connect(latexModule->childDocGB, SIGNAL(clicked()),
1568 this, SLOT(change_adaptor()));
1569 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1570 this, SLOT(change_adaptor()));
1571 connect(latexModule->childDocPB, SIGNAL(clicked()),
1572 this, SLOT(browseMaster()));
1573 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1574 this, SLOT(change_adaptor()));
1575 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1576 this, SLOT(change_adaptor()));
1578 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1579 latexModule->optionsLE));
1580 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1581 latexModule->childDocLE));
1583 // postscript drivers
1584 for (int n = 0; tex_graphics[n][0]; ++n) {
1585 QString enc = qt_(tex_graphics_gui[n]);
1586 latexModule->psdriverCO->addItem(enc);
1589 LayoutFileList const & bcl = LayoutFileList::get();
1590 vector<LayoutFileIndex> classList = bcl.classList();
1591 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1593 for (auto const & cvar : classList) {
1594 LayoutFile const & tc = bcl[cvar];
1595 bool const available = tc.isTeXClassAvailable();
1596 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1597 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1598 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1600 docstring const output_type = _("LaTeX");
1601 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1602 "Please check if you have the matching %1$s class "
1603 "and all required packages (%2$s) installed."),
1604 output_type, from_utf8(tc.prerequisites(", "))));
1606 latexModule->classCO->addItemSort(toqstr(tc.name()),
1608 toqstr(translateIfPossible(from_utf8(tc.category()))),
1610 true, true, true, available);
1615 branchesModule = new GuiBranches(this);
1616 connect(branchesModule, SIGNAL(changed()),
1617 this, SLOT(change_adaptor()));
1618 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1619 this, SLOT(branchesRename(docstring const &, docstring const &)));
1620 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1621 updateUnknownBranches();
1625 preambleModule = new PreambleModule(this);
1626 connect(preambleModule, SIGNAL(changed()),
1627 this, SLOT(change_adaptor()));
1629 localLayout = new LocalLayout(this);
1630 connect(localLayout, SIGNAL(changed()),
1631 this, SLOT(change_adaptor()));
1635 bulletsModule = new BulletsModule(this);
1636 connect(bulletsModule, SIGNAL(changed()),
1637 this, SLOT(change_adaptor()));
1641 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1642 modulesModule->availableLV->header()->setVisible(false);
1643 modulesModule->availableLV->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
1644 modulesModule->availableLV->header()->setStretchLastSection(false);
1645 modulesModule->selectedLV->header()->setVisible(false);
1646 modulesModule->selectedLV->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
1647 modulesModule->selectedLV->header()->setStretchLastSection(false);
1649 new ModuleSelectionManager(this, modulesModule->availableLV,
1650 modulesModule->selectedLV,
1651 modulesModule->addPB,
1652 modulesModule->deletePB,
1653 modulesModule->upPB,
1654 modulesModule->downPB,
1655 availableModel(), selectedModel(), this);
1656 connect(selectionManager, SIGNAL(updateHook()),
1657 this, SLOT(updateModuleInfo()));
1658 connect(selectionManager, SIGNAL(selectionChanged()),
1659 this, SLOT(modulesChanged()));
1661 filter_ = new FancyLineEdit(this);
1662 filter_->setClearButton(true);
1663 filter_->setPlaceholderText(qt_("All avail. modules"));
1664 modulesModule->moduleFilterBarL->addWidget(filter_, 0);
1665 modulesModule->findModulesLA->setBuddy(filter_);
1667 connect(filter_, SIGNAL(rightButtonClicked()),
1668 this, SLOT(resetModuleFilter()));
1669 connect(filter_, SIGNAL(textEdited(QString)),
1670 this, SLOT(moduleFilterChanged(QString)));
1671 connect(filter_, SIGNAL(returnPressed()),
1672 this, SLOT(moduleFilterPressed()));
1673 connect(filter_, &FancyLineEdit::downPressed,
1674 modulesModule->availableLV, [this](){ focusAndHighlight(modulesModule->availableLV); });
1678 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1679 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1680 this, SLOT(change_adaptor()));
1681 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1682 this, SLOT(change_adaptor()));
1683 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1684 this, SLOT(change_adaptor()));
1685 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1686 this, SLOT(change_adaptor()));
1687 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1688 this, SLOT(change_adaptor()));
1689 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1690 this, SLOT(change_adaptor()));
1691 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1692 this, SLOT(change_adaptor()));
1693 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1694 this, SLOT(change_adaptor()));
1695 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1696 this, SLOT(bookmarksopenChanged(bool)));
1697 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1698 this, SLOT(change_adaptor()));
1699 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1700 this, SLOT(change_adaptor()));
1701 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1702 this, SLOT(change_adaptor()));
1703 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1704 this, SLOT(change_adaptor()));
1705 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1706 this, SLOT(change_adaptor()));
1707 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1708 this, SLOT(change_adaptor()));
1709 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1710 this, SLOT(change_adaptor()));
1711 connect(pdfSupportModule->optionsTE, SIGNAL(textChanged()),
1712 this, SLOT(change_adaptor()));
1713 connect(pdfSupportModule->metadataTE, SIGNAL(textChanged()),
1714 this, SLOT(change_adaptor()));
1716 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1717 pdfSupportModule->titleLE));
1718 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1719 pdfSupportModule->authorLE));
1720 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1721 pdfSupportModule->subjectLE));
1722 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1723 pdfSupportModule->keywordsLE));
1724 (void) new LaTeXHighlighter(pdfSupportModule->optionsTE->document(), true, true);
1725 (void) new LaTeXHighlighter(pdfSupportModule->metadataTE->document(), true, true);
1727 for (int i = 0; backref_opts[i][0]; ++i)
1728 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1732 floatModule = new FloatPlacement;
1733 connect(floatModule, SIGNAL(changed()),
1734 this, SLOT(change_adaptor()));
1738 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1739 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1740 this, SLOT(change_adaptor()));
1741 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1742 this, SLOT(change_adaptor()));
1743 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1744 this, SLOT(setListingsMessage()));
1745 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1746 this, SLOT(change_adaptor()));
1747 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1748 this, SLOT(listingsPackageChanged(int)));
1749 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1750 this, SLOT(setListingsMessage()));
1751 listingsModule->listingsTB->setPlainText(
1752 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1754 for (int i = 0; lst_packages[i][0]; ++i)
1755 listingsModule->packageCO->addItem(lst_packages[i]);
1759 docPS->addPanel(latexModule, N_("Document Class"));
1760 docPS->addPanel(masterChildModule, N_("Child Documents"));
1761 docPS->addPanel(modulesModule, N_("Modules"));
1762 docPS->addPanel(localLayout, N_("Local Layout"));
1763 docPS->addPanel(fontModule, N_("Fonts"));
1764 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1765 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1766 docPS->addPanel(marginsModule, N_("Page Margins"));
1767 docPS->addPanel(langModule, N_("Language"));
1768 docPS->addPanel(colorModule, N_("Colors"));
1769 docPS->addPanel(changesModule, N_("Change Tracking"));
1770 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1771 docPS->addPanel(biblioModule, N_("Bibliography"));
1772 docPS->addPanel(indicesModule, N_("Indexes"));
1773 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1774 docPS->addPanel(mathsModule, N_("Math Options"));
1775 docPS->addPanel(floatModule, N_("Float Settings"));
1776 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1777 docPS->addPanel(bulletsModule, N_("Bullets"));
1778 docPS->addPanel(branchesModule, N_("Branches"));
1779 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1780 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1781 docPS->setCurrentPanel("Document Class");
1785 void GuiDocument::onBufferViewChanged()
1788 // We are just switching back. Nothing to do.
1789 switchback_ = false;
1792 BufferView const * view = bufferview();
1793 string const new_filename = view ? view->buffer().absFileName() : string();
1794 // If we switched buffer really and the previous file name is different to
1795 // the current one, we ask on unapplied changes (#9369)
1796 // FIXME: This is more complicated than it should be. Why do we need these to cycles?
1797 // And ideally, we should propose to apply without having to switch back
1798 // (e.g., via a LFUN_BUFFER_PARAMS_APPLY_OTHER)
1799 if (!prev_buffer_filename_.empty() && prev_buffer_filename_ != new_filename
1800 && buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
1801 // Only ask if we haven't yet in this cycle
1802 int const ret = prompted_ ? 3 : Alert::prompt(_("Unapplied changes"),
1803 _("Some changes in the previous document were not yet applied.\n"
1804 "Do you want to switch back and apply them?"),
1805 1, 1, _("Yes, &Switch Back"), _("No, &Dismiss Changes"));
1807 // Switch to previous buffer view and apply
1809 // Record that we have asked.
1811 lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, prev_buffer_filename_));
1813 } else if (ret == 3) {
1814 // We are in the second cycle. Set back.
1820 if (isVisibleView())
1821 initialiseParams("");
1825 void GuiDocument::saveDefaultClicked()
1831 void GuiDocument::useDefaultsClicked()
1837 void GuiDocument::change_adaptor()
1839 nonModuleChanged_ = true;
1844 void GuiDocument::shellescapeChanged()
1846 shellescapeChanged_ = true;
1850 void GuiDocument::bookmarksopenChanged(bool state)
1852 pdfSupportModule->bookmarksopenlevelSB->setEnabled(state);
1853 pdfSupportModule->bookmarksopenlevelLA->setEnabled(state);
1857 void GuiDocument::slotApply()
1859 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1860 bool wasclean = buffer().isClean();
1861 GuiDialog::slotApply();
1862 if (wasclean && only_shellescape_changed)
1863 buffer().markClean();
1864 modulesChanged_ = false;
1868 void GuiDocument::slotOK()
1870 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1871 bool wasclean = buffer().isClean();
1872 GuiDialog::slotOK();
1873 if (wasclean && only_shellescape_changed)
1874 buffer().markClean();
1875 modulesChanged_ = false;
1879 void GuiDocument::slotButtonBox(QAbstractButton * button)
1881 switch (buttonBox->standardButton(button)) {
1882 case QDialogButtonBox::Ok:
1885 case QDialogButtonBox::Apply:
1888 case QDialogButtonBox::Cancel:
1891 case QDialogButtonBox::Reset:
1892 case QDialogButtonBox::RestoreDefaults:
1901 void GuiDocument::filterModules(QString const & str)
1903 updateAvailableModules();
1907 modules_av_model_.clear();
1908 list<modInfoStruct> modInfoList = getModuleInfo();
1909 // Sort names according to the locale
1910 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
1911 return 0 < b.name.localeAwareCompare(a.name);
1914 QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
1915 QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
1918 for (modInfoStruct const & m : modInfoList) {
1919 if (m.name.contains(str, Qt::CaseInsensitive) || contains(m.id, fromqstr(str))) {
1920 QStandardItem * item = new QStandardItem();
1921 item->setData(m.name, Qt::DisplayRole);
1922 item->setData(toqstr(m.id), Qt::UserRole);
1923 item->setData(m.description, Qt::ToolTipRole);
1924 item->setEditable(false);
1926 item->setIcon(user_icon);
1928 item->setIcon(system_icon);
1929 modules_av_model_.insertRow(i, item);
1936 void GuiDocument::moduleFilterChanged(const QString & text)
1938 if (!text.isEmpty()) {
1939 filterModules(filter_->text());
1942 filterModules(filter_->text());
1943 filter_->setFocus();
1947 void GuiDocument::moduleFilterPressed()
1949 filterModules(filter_->text());
1953 void GuiDocument::resetModuleFilter()
1955 filter_->setText(QString());
1956 filterModules(filter_->text());
1960 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1962 if (item == nullptr)
1965 string child = fromqstr(item->text(0));
1969 if (std::find(includeonlys_.begin(),
1970 includeonlys_.end(), child) != includeonlys_.end())
1971 includeonlys_.remove(child);
1973 includeonlys_.push_back(child);
1975 updateIncludeonlys();
1980 QString GuiDocument::validateListingsParameters()
1982 if (listingsModule->bypassCB->isChecked())
1984 string const package =
1985 lst_packages[listingsModule->packageCO->currentIndex()];
1986 string params = fromqstr(listingsModule->listingsED->toPlainText());
1987 InsetListingsParams lstparams(params);
1988 lstparams.setMinted(package == "Minted");
1989 return toqstr(lstparams.validate());
1993 void GuiDocument::setListingsMessage()
1996 static bool isOK = true;
1997 QString msg = validateListingsParameters();
1998 if (msg.isEmpty()) {
2002 // listingsModule->listingsTB->setTextColor("black");
2003 listingsModule->listingsTB->setPlainText(
2004 qt_("Input listings parameters below. "
2005 "Enter ? for a list of parameters."));
2008 // listingsModule->listingsTB->setTextColor("red");
2009 listingsModule->listingsTB->setPlainText(msg);
2014 void GuiDocument::listingsPackageChanged(int index)
2016 string const package = lst_packages[index];
2017 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
2018 Alert::warning(_("Pygments driver command not found!"),
2019 _("The driver command necessary to use the minted package\n"
2020 "(pygmentize) has not been found. Make sure you have\n"
2021 "the python-pygments module installed or, if the driver\n"
2022 "is named differently, to add the following line to the\n"
2023 "document preamble:\n\n"
2024 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
2025 "where 'driver' is name of the driver command."));
2030 void GuiDocument::setLSpacing(int item)
2032 textLayoutModule->lspacingLE->setEnabled(item == 3);
2036 void GuiDocument::setIndent(int item)
2038 bool const enable = (textLayoutModule->indentCO->itemData(item) == "custom");
2039 textLayoutModule->indentLE->setEnabled(enable);
2040 textLayoutModule->indentLengthCO->setEnabled(enable);
2041 textLayoutModule->skipLE->setEnabled(false);
2042 textLayoutModule->skipLengthCO->setEnabled(false);
2047 void GuiDocument::enableIndent(bool indent)
2049 textLayoutModule->skipLE->setEnabled(!indent);
2050 textLayoutModule->skipLengthCO->setEnabled(!indent);
2052 setIndent(textLayoutModule->indentCO->currentIndex());
2056 void GuiDocument::setSkip(int item)
2058 VSpace::VSpaceKind kind =
2059 VSpace::VSpaceKind(textLayoutModule->skipCO->itemData(item).toInt());
2060 bool const enable = (kind == VSpace::LENGTH);
2061 textLayoutModule->skipLE->setEnabled(enable);
2062 textLayoutModule->skipLengthCO->setEnabled(enable);
2067 void GuiDocument::enableSkip(bool skip)
2069 textLayoutModule->indentLE->setEnabled(!skip);
2070 textLayoutModule->indentLengthCO->setEnabled(!skip);
2072 setSkip(textLayoutModule->skipCO->currentIndex());
2075 void GuiDocument::allowMathIndent() {
2076 // only disable when not checked, checked does not always allow enabling
2077 if (!mathsModule->MathIndentCB->isChecked()) {
2078 mathsModule->MathIndentLE->setEnabled(false);
2079 mathsModule->MathIndentLengthCO->setEnabled(false);
2081 if (mathsModule->MathIndentCB->isChecked()
2082 && mathsModule->MathIndentCO->itemData(mathsModule->MathIndentCO->currentIndex()) == "custom") {
2083 mathsModule->MathIndentLE->setEnabled(true);
2084 mathsModule->MathIndentLengthCO->setEnabled(true);
2089 void GuiDocument::enableMathIndent(int item)
2091 bool const enable = (item == 1);
2092 mathsModule->MathIndentLE->setEnabled(enable);
2093 mathsModule->MathIndentLengthCO->setEnabled(enable);
2098 void GuiDocument::setMargins()
2100 bool const extern_geometry =
2101 documentClass().provides("geometry");
2102 marginsModule->marginCB->setEnabled(!extern_geometry);
2103 if (extern_geometry) {
2104 marginsModule->marginCB->setChecked(false);
2105 setCustomMargins(true);
2107 marginsModule->marginCB->setChecked(!bp_.use_geometry);
2108 setCustomMargins(!bp_.use_geometry);
2111 // set some placeholder text that hint on defaults
2112 QString const placeholder = marginsModule->marginCB->isChecked() ?
2113 qt_("Class defaults") : qt_("Package defaults");
2114 // set tooltip depending on gemoetry state
2115 QString const tooltip = marginsModule->marginCB->isChecked() ?
2116 qt_("If no value is given, the defaults as set by the class are used.")
2117 : qt_("If no value is given, the defaults as set by the geometry package or a package/class overriding geometry's defaults are used.");
2118 marginsModule->topLE->setPlaceholderText(placeholder);
2119 marginsModule->bottomLE->setPlaceholderText(placeholder);
2120 marginsModule->innerLE->setPlaceholderText(placeholder);
2121 marginsModule->outerLE->setPlaceholderText(placeholder);
2122 marginsModule->headheightLE->setPlaceholderText(placeholder);
2123 marginsModule->headsepLE->setPlaceholderText(placeholder);
2124 marginsModule->footskipLE->setPlaceholderText(placeholder);
2125 marginsModule->columnsepLE->setPlaceholderText(placeholder);
2126 marginsModule->topLE->setToolTip(tooltip);
2127 marginsModule->bottomLE->setToolTip(tooltip);
2128 marginsModule->innerLE->setToolTip(tooltip);
2129 marginsModule->outerLE->setToolTip(tooltip);
2130 marginsModule->headheightLE->setToolTip(tooltip);
2131 marginsModule->headsepLE->setToolTip(tooltip);
2132 marginsModule->footskipLE->setToolTip(tooltip);
2133 marginsModule->columnsepLE->setToolTip(tooltip);
2137 void GuiDocument::papersizeChanged(int paper_size)
2139 setCustomPapersize(paper_size == 1);
2143 void GuiDocument::setCustomPapersize(bool custom)
2145 pageLayoutModule->paperwidthL->setEnabled(custom);
2146 pageLayoutModule->paperwidthLE->setEnabled(custom);
2147 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
2148 pageLayoutModule->paperheightL->setEnabled(custom);
2149 pageLayoutModule->paperheightLE->setEnabled(custom);
2150 pageLayoutModule->paperheightLE->setFocus();
2151 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
2155 void GuiDocument::setColSep()
2157 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
2161 void GuiDocument::setCustomMargins(bool custom)
2163 marginsModule->topL->setEnabled(!custom);
2164 marginsModule->topLE->setEnabled(!custom);
2165 marginsModule->topUnit->setEnabled(!custom);
2167 marginsModule->bottomL->setEnabled(!custom);
2168 marginsModule->bottomLE->setEnabled(!custom);
2169 marginsModule->bottomUnit->setEnabled(!custom);
2171 marginsModule->innerL->setEnabled(!custom);
2172 marginsModule->innerLE->setEnabled(!custom);
2173 marginsModule->innerUnit->setEnabled(!custom);
2175 marginsModule->outerL->setEnabled(!custom);
2176 marginsModule->outerLE->setEnabled(!custom);
2177 marginsModule->outerUnit->setEnabled(!custom);
2179 marginsModule->headheightL->setEnabled(!custom);
2180 marginsModule->headheightLE->setEnabled(!custom);
2181 marginsModule->headheightUnit->setEnabled(!custom);
2183 marginsModule->headsepL->setEnabled(!custom);
2184 marginsModule->headsepLE->setEnabled(!custom);
2185 marginsModule->headsepUnit->setEnabled(!custom);
2187 marginsModule->footskipL->setEnabled(!custom);
2188 marginsModule->footskipLE->setEnabled(!custom);
2189 marginsModule->footskipUnit->setEnabled(!custom);
2191 bool const enableColSep = !custom &&
2192 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
2193 marginsModule->columnsepL->setEnabled(enableColSep);
2194 marginsModule->columnsepLE->setEnabled(enableColSep);
2195 marginsModule->columnsepUnit->setEnabled(enableColSep);
2197 // set some placeholder text that hint on defaults
2198 QString const placeholder = marginsModule->marginCB->isChecked() ?
2199 qt_("Class defaults") : qt_("Package defaults");
2200 // set tooltip depending on gemoetry state
2201 QString const tooltip = marginsModule->marginCB->isChecked() ?
2202 qt_("If no value is given, the defaults as set by the class are used.")
2203 : qt_("If no value is given, the defaults as set by the geometry package or a package/class overriding geometry's defaults are used.");
2204 marginsModule->topLE->setPlaceholderText(placeholder);
2205 marginsModule->bottomLE->setPlaceholderText(placeholder);
2206 marginsModule->innerLE->setPlaceholderText(placeholder);
2207 marginsModule->outerLE->setPlaceholderText(placeholder);
2208 marginsModule->headheightLE->setPlaceholderText(placeholder);
2209 marginsModule->headsepLE->setPlaceholderText(placeholder);
2210 marginsModule->footskipLE->setPlaceholderText(placeholder);
2211 marginsModule->columnsepLE->setPlaceholderText(placeholder);
2212 marginsModule->topLE->setToolTip(tooltip);
2213 marginsModule->bottomLE->setToolTip(tooltip);
2214 marginsModule->innerLE->setToolTip(tooltip);
2215 marginsModule->outerLE->setToolTip(tooltip);
2216 marginsModule->headheightLE->setToolTip(tooltip);
2217 marginsModule->headsepLE->setToolTip(tooltip);
2218 marginsModule->footskipLE->setToolTip(tooltip);
2219 marginsModule->columnsepLE->setToolTip(tooltip);
2224 void GuiDocument::changeBackgroundColor()
2226 QColor const & newColor = QColorDialog::getColor(
2227 rgb2qcolor(set_backgroundcolor), asQWidget());
2228 if (!newColor.isValid())
2230 // set the button color and text
2231 colorModule->backgroundPB->setStyleSheet(
2232 colorButtonStyleSheet(newColor));
2233 colorModule->backgroundPB->setText(qt_("&Change..."));
2235 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
2236 is_backgroundcolor = true;
2241 void GuiDocument::deleteBackgroundColor()
2243 // set the button color back to default by setting an empty StyleSheet
2244 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
2245 // change button text
2246 colorModule->backgroundPB->setText(qt_("&Default..."));
2247 // save default color (white)
2248 set_backgroundcolor = rgbFromHexName("#ffffff");
2249 is_backgroundcolor = false;
2254 void GuiDocument::changeFontColor()
2256 QColor const & newColor = QColorDialog::getColor(
2257 rgb2qcolor(set_fontcolor), asQWidget());
2258 if (!newColor.isValid())
2260 // set the button color and text
2261 colorModule->fontColorPB->setStyleSheet(
2262 colorButtonStyleSheet(newColor));
2263 colorModule->fontColorPB->setText(qt_("&Change..."));
2265 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
2266 is_fontcolor = true;
2271 void GuiDocument::deleteFontColor()
2273 // set the button color back to default by setting an empty StyleSheet
2274 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
2275 // change button text
2276 colorModule->fontColorPB->setText(qt_("&Default..."));
2277 // save default color (black)
2278 set_fontcolor = rgbFromHexName("#000000");
2279 is_fontcolor = false;
2284 void GuiDocument::changeNoteFontColor()
2286 QColor const & newColor = QColorDialog::getColor(
2287 rgb2qcolor(set_notefontcolor), asQWidget());
2288 if (!newColor.isValid())
2290 // set the button color
2291 colorModule->noteFontColorPB->setStyleSheet(
2292 colorButtonStyleSheet(newColor));
2294 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
2295 is_notefontcolor = true;
2300 void GuiDocument::deleteNoteFontColor()
2302 // set the button color back to pref
2303 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
2304 colorModule->noteFontColorPB->setStyleSheet(
2305 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
2306 is_notefontcolor = false;
2311 void GuiDocument::changeBoxBackgroundColor()
2313 QColor const & newColor = QColorDialog::getColor(
2314 rgb2qcolor(set_boxbgcolor), asQWidget());
2315 if (!newColor.isValid())
2317 // set the button color
2318 colorModule->boxBackgroundPB->setStyleSheet(
2319 colorButtonStyleSheet(newColor));
2321 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
2322 is_boxbgcolor = true;
2327 void GuiDocument::deleteBoxBackgroundColor()
2329 // set the button color back to pref
2330 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
2331 colorModule->boxBackgroundPB->setStyleSheet(
2332 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
2333 is_boxbgcolor = false;
2338 void GuiDocument::updateQuoteStyles(bool const set)
2340 Language const * lang = lyx::languages.getLanguage(
2341 fromqstr(langModule->languageCO->itemData(
2342 langModule->languageCO->currentIndex()).toString()));
2344 QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
2346 langModule->quoteStyleCO->clear();
2348 bool has_default = false;
2349 for (int i = 0; i < quoteparams.stylescount(); ++i) {
2350 QuoteStyle qs = QuoteStyle(i);
2351 if (qs == QuoteStyle::Dynamic)
2353 bool const langdef = (qs == def);
2355 // add the default style on top
2356 langModule->quoteStyleCO->insertItem(0,
2357 toqstr(quoteparams.getGuiLabel(qs, langdef)), static_cast<int>(qs));
2361 langModule->quoteStyleCO->addItem(
2362 toqstr(quoteparams.getGuiLabel(qs, langdef)), static_cast<int>(qs));
2364 if (set && has_default)
2365 // (re)set to the default style
2366 langModule->quoteStyleCO->setCurrentIndex(0);
2370 void GuiDocument::languageChanged(int i)
2372 // some languages only work with Polyglossia
2373 Language const * lang = lyx::languages.getLanguage(
2374 fromqstr(langModule->languageCO->itemData(i).toString()));
2375 if (lang->babel().empty() && !lang->polyglossia().empty()
2376 && lang->required() != "CJK" && lang->required() != "japanese") {
2377 // If we force to switch fontspec on, store
2378 // current state (#8717)
2379 if (fontModule->osFontsCB->isEnabled())
2380 forced_fontspec_activation =
2381 !fontModule->osFontsCB->isChecked();
2382 fontModule->osFontsCB->setChecked(true);
2383 fontModule->osFontsCB->setEnabled(false);
2386 fontModule->osFontsCB->setEnabled(true);
2387 // If we have forced to switch fontspec on,
2388 // restore previous state (#8717)
2389 if (forced_fontspec_activation)
2390 fontModule->osFontsCB->setChecked(false);
2391 forced_fontspec_activation = false;
2394 // set appropriate quotation mark style
2395 updateQuoteStyles(true);
2399 void GuiDocument::osFontsChanged(bool nontexfonts)
2401 bool const tex_fonts = !nontexfonts;
2402 // store current fonts
2403 QString const font_roman = fontModule->fontsRomanCO->itemData(
2404 fontModule->fontsRomanCO->currentIndex()).toString();
2405 QString const font_sans = fontModule->fontsSansCO->itemData(
2406 fontModule->fontsSansCO->currentIndex()).toString();
2407 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2408 fontModule->fontsTypewriterCO->currentIndex()).toString();
2409 QString const font_math = fontModule->fontsMathCO->itemData(
2410 fontModule->fontsMathCO->currentIndex()).toString();
2411 int const font_sf_scale = fontModule->scaleSansSB->value();
2412 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2415 // store default format
2416 QString const dformat = outputModule->defaultFormatCO->itemData(
2417 outputModule->defaultFormatCO->currentIndex()).toString();
2418 updateDefaultFormat();
2419 // try to restore default format
2420 int index = outputModule->defaultFormatCO->findData(dformat);
2421 // set to default if format is not found
2424 outputModule->defaultFormatCO->setCurrentIndex(index);
2426 // try to restore fonts which were selected two toggles ago
2427 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2429 fontModule->fontsRomanCO->setCurrentIndex(index);
2430 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2432 fontModule->fontsSansCO->setCurrentIndex(index);
2433 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2435 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2436 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2438 fontModule->fontsMathCO->setCurrentIndex(index);
2439 // save fonts for next next toggle
2440 fontModule->font_roman = font_roman;
2441 fontModule->font_sans = font_sans;
2442 fontModule->font_typewriter = font_typewriter;
2443 fontModule->font_math = font_math;
2444 fontModule->font_sf_scale = font_sf_scale;
2445 fontModule->font_tt_scale = font_tt_scale;
2447 // non-tex fonts override the "\inputencoding" option with "utf8-plain"
2448 langModule->encodingCO->setEnabled(tex_fonts);
2449 inputencodingToDialog();
2451 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2452 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2453 fontModule->cjkFontLE->setEnabled(tex_fonts);
2454 fontModule->cjkFontLA->setEnabled(tex_fonts);
2456 updateFontOptions();
2458 fontModule->fontencLA->setEnabled(tex_fonts);
2459 fontModule->fontencCO->setEnabled(tex_fonts);
2461 fontModule->fontencLE->setEnabled(false);
2463 fontencChanged(fontModule->fontencCO->currentIndex());
2467 void GuiDocument::encodingSwitched(int i)
2469 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2470 langModule->unicodeEncodingCO->setEnabled(tex_fonts);
2471 langModule->customEncodingCO->setEnabled(tex_fonts);
2472 langModule->autoEncodingCO->setEnabled(tex_fonts);
2473 langModule->unicodeEncodingCO->setVisible(i == EncodingSets::unicode);
2474 langModule->autoEncodingCO->setVisible(i == EncodingSets::legacy);
2475 langModule->customEncodingCO->setVisible(i == EncodingSets::custom);
2477 langModule->unicodeEncodingCO->setItemText(1, qt_("Direct (No inputenc)"));
2479 langModule->unicodeEncodingCO->setItemText(1, qt_("Direct (XeTeX/LuaTeX)"));
2482 void GuiDocument::inputencodingToDialog()
2484 QString inputenc = toqstr(bp_.inputenc);
2486 if (fontModule->osFontsCB->isChecked()) { // non-tex fonts require utf8-plain
2487 langModule->encodingCO->setCurrentIndex(EncodingSets::unicode);
2488 langModule->unicodeEncodingCO->setCurrentIndex(
2489 langModule->unicodeEncodingCO->findData("utf8-plain"));
2490 } else if (inputenc.startsWith("utf8")) {
2491 langModule->encodingCO->setCurrentIndex(EncodingSets::unicode);
2492 p = langModule->unicodeEncodingCO->findData(inputenc);
2495 langModule->unicodeEncodingCO->setCurrentIndex(p);
2496 langModule->autoEncodingCO->setCurrentIndex(0);
2497 langModule->customEncodingCO->setCurrentIndex(0);
2498 } else if (inputenc.startsWith("auto")) {
2499 langModule->encodingCO->setCurrentIndex(EncodingSets::legacy);
2500 p = langModule->autoEncodingCO->findData(inputenc);
2503 langModule->unicodeEncodingCO->setCurrentIndex(0);
2504 langModule->autoEncodingCO->setCurrentIndex(p);
2505 langModule->customEncodingCO->setCurrentIndex(0);
2507 langModule->encodingCO->setCurrentIndex(EncodingSets::custom);
2508 p = langModule->customEncodingCO->findData(inputenc);
2511 langModule->encodingCO->setCurrentIndex(EncodingSets::unicode);
2513 langModule->unicodeEncodingCO->setCurrentIndex(0);
2514 langModule->autoEncodingCO->setCurrentIndex(0);
2515 langModule->customEncodingCO->setCurrentIndex(p);
2517 encodingSwitched(langModule->encodingCO->currentIndex());
2521 void GuiDocument::mathFontChanged(int)
2523 updateFontOptions();
2526 void GuiDocument::fontOsfToggled(bool state)
2528 if (fontModule->osFontsCB->isChecked())
2530 QString font = fontModule->fontsRomanCO->itemData(
2531 fontModule->fontsRomanCO->currentIndex()).toString();
2532 if (hasMonolithicExpertSet(font))
2533 fontModule->fontScCB->setChecked(state);
2537 void GuiDocument::fontScToggled(bool state)
2539 if (fontModule->osFontsCB->isChecked())
2541 QString font = fontModule->fontsRomanCO->itemData(
2542 fontModule->fontsRomanCO->currentIndex()).toString();
2543 if (hasMonolithicExpertSet(font))
2544 fontModule->fontOsfCB->setChecked(state);
2548 void GuiDocument::updateExtraOpts()
2550 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2553 font = fontModule->fontsRomanCO->itemData(
2554 fontModule->fontsRomanCO->currentIndex()).toString();
2555 bool const rm_opts = providesExtraOpts(font);
2557 font = fontModule->fontsSansCO->itemData(
2558 fontModule->fontsSansCO->currentIndex()).toString();
2559 bool const sf_opts = providesExtraOpts(font);
2561 font = fontModule->fontsTypewriterCO->itemData(
2562 fontModule->fontsTypewriterCO->currentIndex()).toString();
2563 bool const tt_opts = providesExtraOpts(font);
2564 fontModule->fontspecRomanLA->setEnabled(!tex_fonts || rm_opts);
2565 fontModule->fontspecRomanLE->setEnabled(!tex_fonts || rm_opts);
2566 fontModule->fontspecSansLA->setEnabled(!tex_fonts || sf_opts);
2567 fontModule->fontspecSansLE->setEnabled(!tex_fonts || sf_opts);
2568 fontModule->fontspecTypewriterLA->setEnabled(!tex_fonts || tt_opts);
2569 fontModule->fontspecTypewriterLE->setEnabled(!tex_fonts || tt_opts);
2573 void GuiDocument::updateFontOptions()
2575 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2578 font = fontModule->fontsSansCO->itemData(
2579 fontModule->fontsSansCO->currentIndex()).toString();
2580 bool scalable = providesScale(font);
2581 fontModule->scaleSansSB->setEnabled(scalable);
2582 fontModule->scaleSansLA->setEnabled(scalable);
2583 fontModule->fontSansOsfCB->setEnabled(providesOSF(font));
2585 font = fontModule->fontsTypewriterCO->itemData(
2586 fontModule->fontsTypewriterCO->currentIndex()).toString();
2587 scalable = providesScale(font);
2588 fontModule->scaleTypewriterSB->setEnabled(scalable);
2589 fontModule->scaleTypewriterLA->setEnabled(scalable);
2590 fontModule->fontTypewriterOsfCB->setEnabled(providesOSF(font));
2592 font = fontModule->fontsRomanCO->itemData(
2593 fontModule->fontsRomanCO->currentIndex()).toString();
2594 fontModule->fontScCB->setEnabled(providesSC(font));
2595 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2597 updateMathFonts(font);
2601 void GuiDocument::updateFontsize(string const & items, string const & sel)
2603 fontModule->fontsizeCO->clear();
2604 fontModule->fontsizeCO->addItem(qt_("Default"));
2606 for (int n = 0; !token(items,'|',n).empty(); ++n)
2607 fontModule->fontsizeCO->
2608 addItem(toqstr(token(items,'|',n)));
2610 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2611 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2612 fontModule->fontsizeCO->setCurrentIndex(n);
2619 bool GuiDocument::ot1() const
2621 QString const fontenc =
2622 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2623 int const i = langModule->languageCO->currentIndex();
2626 QString const langname = langModule->languageCO->itemData(i).toString();
2627 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2628 return (fontenc == "default"
2629 || (fontenc == "auto" && newlang->fontenc(buffer().params()) == "OT1")
2630 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2634 bool GuiDocument::completeFontset() const
2636 return (fontModule->fontsSansCO->itemData(
2637 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2638 && fontModule->fontsSansCO->itemData(
2639 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2643 bool GuiDocument::noMathFont() const
2645 return (fontModule->fontsMathCO->itemData(
2646 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2650 void GuiDocument::updateTexFonts()
2652 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2654 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2655 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2656 for (; it != end; ++it) {
2657 LaTeXFont lf = it->second;
2658 if (lf.name().empty()) {
2659 LYXERR0("Error: Unnamed font: " << it->first);
2662 docstring const family = lf.family();
2663 docstring guiname = translateIfPossible(lf.guiname());
2664 if (!lf.available(ot1(), noMathFont()))
2665 guiname += _(" (not installed)");
2667 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2668 else if (family == "sf")
2669 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2670 else if (family == "tt")
2671 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2672 else if (family == "math")
2673 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2678 void GuiDocument::updateFontlist()
2680 // reset the filters of the CategorizedCombos
2681 fontModule->fontsRomanCO->resetFilter();
2682 fontModule->fontsSansCO->resetFilter();
2683 fontModule->fontsTypewriterCO->resetFilter();
2684 fontModule->fontsRomanCO->clear();
2685 fontModule->fontsSansCO->clear();
2686 fontModule->fontsTypewriterCO->clear();
2687 fontModule->fontsMathCO->clear();
2689 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2690 if (fontModule->osFontsCB->isChecked()) {
2691 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2692 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2693 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2694 QString unimath = qt_("Non-TeX Fonts Default");
2695 if (!LaTeXFeatures::isAvailable("unicode-math"))
2696 unimath += qt_(" (not available)");
2697 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2698 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2700 #if QT_VERSION >= 0x060000
2701 const QStringList families(QFontDatabase::families());
2703 QFontDatabase fontdb;
2704 const QStringList families(fontdb.families());
2706 for (auto const & family : families) {
2707 fontModule->fontsRomanCO->addItem(family, family);
2708 fontModule->fontsSansCO->addItem(family, family);
2709 fontModule->fontsTypewriterCO->addItem(family, family);
2714 if (rmfonts_.empty())
2717 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2718 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2719 while (rmi != rmfonts_.constEnd()) {
2720 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2724 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2725 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2726 while (sfi != sffonts_.constEnd()) {
2727 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2731 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2732 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2733 while (tti != ttfonts_.constEnd()) {
2734 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2738 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2739 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2740 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2741 while (mmi != mathfonts_.constEnd()) {
2742 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2748 void GuiDocument::fontencChanged(int item)
2750 fontModule->fontencLE->setEnabled(
2751 fontModule->fontencCO->itemData(item).toString() == "custom");
2752 // The availability of TeX fonts depends on the font encoding
2754 updateFontOptions();
2758 void GuiDocument::updateMathFonts(QString const & rm)
2760 if (fontModule->osFontsCB->isChecked())
2762 QString const math =
2763 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2764 int const i = fontModule->fontsMathCO->findData("default");
2765 if (providesNoMath(rm) && i == -1)
2766 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2767 else if (!providesNoMath(rm) && i != -1) {
2768 int const c = fontModule->fontsMathCO->currentIndex();
2769 fontModule->fontsMathCO->removeItem(i);
2771 fontModule->fontsMathCO->setCurrentIndex(0);
2776 void GuiDocument::romanChanged(int item)
2778 if (fontModule->osFontsCB->isChecked())
2780 QString const font =
2781 fontModule->fontsRomanCO->itemData(item).toString();
2782 fontModule->fontScCB->setEnabled(providesSC(font));
2783 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2785 updateMathFonts(font);
2789 void GuiDocument::sansChanged(int item)
2791 if (fontModule->osFontsCB->isChecked())
2793 QString const font =
2794 fontModule->fontsSansCO->itemData(item).toString();
2795 bool const scalable = providesScale(font);
2796 fontModule->scaleSansSB->setEnabled(scalable);
2797 fontModule->scaleSansLA->setEnabled(scalable);
2798 fontModule->fontSansOsfCB->setEnabled(providesOSF(font));
2803 void GuiDocument::ttChanged(int item)
2805 if (fontModule->osFontsCB->isChecked())
2807 QString const font =
2808 fontModule->fontsTypewriterCO->itemData(item).toString();
2809 bool scalable = providesScale(font);
2810 fontModule->scaleTypewriterSB->setEnabled(scalable);
2811 fontModule->scaleTypewriterLA->setEnabled(scalable);
2812 fontModule->fontTypewriterOsfCB->setEnabled(providesOSF(font));
2817 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2820 pageLayoutModule->pagestyleCO->clear();
2821 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2823 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2824 string style = token(items, '|', n);
2825 QString style_gui = qt_(style);
2826 pagestyles.push_back(pair<string, QString>(style, style_gui));
2827 pageLayoutModule->pagestyleCO->addItem(style_gui);
2830 if (sel == "default") {
2831 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2837 for (auto const & pagestyle : pagestyles)
2838 if (pagestyle.first == sel)
2839 nn = pageLayoutModule->pagestyleCO->findText(pagestyle.second);
2842 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2846 void GuiDocument::browseLayout()
2848 QString const label1 = qt_("Lay&outs");
2849 QString const dir1 = toqstr(lyxrc.document_path);
2850 QStringList const filter(qt_("LyX Layout (*.layout)"));
2851 QString file = browseRelToParent(QString(), bufferFilePath(),
2852 qt_("Local layout file"), filter, false,
2855 if (!file.endsWith(".layout"))
2858 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2859 fromqstr(bufferFilePath()));
2861 int const ret = Alert::prompt(_("Local layout file"),
2862 _("The layout file you have selected is a local layout\n"
2863 "file, not one in the system or user directory.\n"
2864 "Your document will not work with this layout if you\n"
2865 "move the layout file to a different directory."),
2866 1, 1, _("&Set Layout"), _("&Cancel"));
2870 // load the layout file
2871 LayoutFileList & bcl = LayoutFileList::get();
2872 string classname = layoutFile.onlyFileName();
2873 // this will update an existing layout if that layout has been loaded before.
2874 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2875 classname.substr(0, classname.size() - 7),
2876 layoutFile.onlyPath().absFileName()));
2879 Alert::error(_("Error"),
2880 _("Unable to read local layout file."));
2884 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2886 // do not trigger classChanged if there is no change.
2887 if (latexModule->classCO->currentText() == toqstr(name))
2891 bool const avail = latexModule->classCO->set(toqstr(name));
2893 LayoutFile const & tc = bcl[name];
2894 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2895 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2896 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2897 tooltip += '\n' + qt_("This is a local layout file.");
2898 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2899 toqstr(translateIfPossible(from_utf8(tc.category()))),
2901 true, true, true, true);
2902 latexModule->classCO->set(toqstr(name));
2909 void GuiDocument::browseMaster()
2911 QString const title = qt_("Select master document");
2912 QString const dir1 = toqstr(lyxrc.document_path);
2913 QString const old = latexModule->childDocLE->text();
2914 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2915 QStringList const filter(qt_("LyX Files (*.lyx)"));
2916 QString file = browseRelToSub(old, docpath, title, filter, false,
2917 qt_("D&ocuments"), toqstr(lyxrc.document_path));
2919 if (!file.isEmpty())
2920 latexModule->childDocLE->setText(file);
2924 void GuiDocument::classChanged_adaptor()
2926 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2931 void GuiDocument::classChanged()
2933 int idx = latexModule->classCO->currentIndex();
2936 string const classname = fromqstr(latexModule->classCO->getData(idx));
2938 if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
2939 int const ret = Alert::prompt(_("Unapplied changes"),
2940 _("Some changes in the dialog were not yet applied.\n"
2941 "If you do not apply now, they will be lost after this action."),
2942 1, 1, _("&Apply"), _("&Dismiss"));
2947 // We load the TextClass as soon as it is selected. This is
2948 // necessary so that other options in the dialog can be updated
2949 // according to the new class. Note, however, that, if you use
2950 // the scroll wheel when sitting on the combo box, we'll load a
2951 // lot of TextClass objects very quickly....
2952 if (!bp_.setBaseClass(classname, buffer().layoutPos())) {
2953 Alert::error(_("Error"), _("Unable to set document class."));
2956 if (lyxrc.auto_reset_options)
2957 bp_.useClassDefaults();
2959 // With the introduction of modules came a distinction between the base
2960 // class and the document class. The former corresponds to the main layout
2961 // file; the latter is that plus the modules (or the document-specific layout,
2962 // or whatever else there could be). Our parameters come from the document
2963 // class. So when we set the base class, we also need to recreate the document
2964 // class. Otherwise, we still have the old one.
2965 bp_.makeDocumentClass();
2970 void GuiDocument::languagePackageChanged(int i)
2972 langModule->languagePackageLE->setEnabled(
2973 langModule->languagePackageCO->itemData(i).toString() == "custom");
2977 void GuiDocument::biblioChanged()
2979 biblioChanged_ = true;
2984 void GuiDocument::checkPossibleCiteEngines()
2986 // Check if the class provides a specific engine,
2987 // and if so, enforce this.
2988 string force_engine;
2989 if (documentClass().provides("natbib")
2990 || documentClass().provides("natbib-internal"))
2991 force_engine = "natbib";
2992 else if (documentClass().provides("jurabib"))
2993 force_engine = "jurabib";
2994 else if (documentClass().provides("biblatex"))
2995 force_engine = "biblatex";
2996 else if (documentClass().provides("biblatex-natbib"))
2997 force_engine = "biblatex-natbib";
2999 if (!force_engine.empty())
3000 biblioModule->citeEngineCO->setCurrentIndex(
3001 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
3002 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
3006 void GuiDocument::rescanBibFiles()
3009 rescanTexStyles("bbx cbx");
3011 rescanTexStyles("bst");
3015 void GuiDocument::resetDefaultBibfile(string const & which)
3017 QString const engine =
3018 biblioModule->citeEngineCO->itemData(
3019 biblioModule->citeEngineCO->currentIndex()).toString();
3021 CiteEngineType const cet =
3022 CiteEngineType(biblioModule->citeStyleCO->itemData(
3023 biblioModule->citeStyleCO->currentIndex()).toInt());
3025 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
3029 void GuiDocument::resetDefaultBbxBibfile()
3031 resetDefaultBibfile("bbx");
3035 void GuiDocument::resetDefaultCbxBibfile()
3037 resetDefaultBibfile("cbx");
3041 void GuiDocument::citeEngineChanged(int n)
3043 QString const engine =
3044 biblioModule->citeEngineCO->itemData(n).toString();
3046 vector<string> const engs =
3047 theCiteEnginesList[fromqstr(engine)]->getEngineType();
3049 updateCiteStyles(engs);
3050 updateEngineDependends();
3051 resetDefaultBibfile();
3056 void GuiDocument::updateEngineDependends()
3058 bool const biblatex = isBiblatex();
3060 // These are only useful with BibTeX
3061 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
3062 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
3063 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
3064 biblioModule->bibtopicCB->setEnabled(!biblatex);
3066 // These are only useful with Biblatex
3067 biblioModule->biblatexBbxCO->setEnabled(biblatex);
3068 biblioModule->biblatexBbxLA->setEnabled(biblatex);
3069 biblioModule->biblatexCbxCO->setEnabled(biblatex);
3070 biblioModule->biblatexCbxLA->setEnabled(biblatex);
3071 biblioModule->resetBbxPB->setEnabled(biblatex);
3072 biblioModule->resetCbxPB->setEnabled(biblatex);
3073 biblioModule->matchBbxPB->setEnabled(biblatex);
3075 // These are useful with biblatex, jurabib and natbib
3076 QString const engine =
3077 biblioModule->citeEngineCO->itemData(
3078 biblioModule->citeEngineCO->currentIndex()).toString();
3079 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
3081 bool const citepack = ce->required("biblatex.sty") || ce->required("jurabib.sty")
3082 || ce->required("natbib.sty");
3083 biblioModule->citePackageOptionsLE->setEnabled(citepack);
3084 biblioModule->citePackageOptionsL->setEnabled(citepack);
3088 void GuiDocument::citeStyleChanged()
3090 QString const engine =
3091 biblioModule->citeEngineCO->itemData(
3092 biblioModule->citeEngineCO->currentIndex()).toString();
3093 QString const currentDef = isBiblatex() ?
3094 biblioModule->biblatexBbxCO->currentText()
3095 : biblioModule->defaultBiblioCO->currentText();
3096 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
3097 resetDefaultBibfile();
3103 void GuiDocument::bibtexChanged(int n)
3105 biblioModule->bibtexOptionsLE->setEnabled(
3106 biblioModule->bibtexCO->itemData(n).toString() != "default");
3111 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
3113 biblioModule->citeStyleCO->clear();
3115 vector<string>::const_iterator it = engs.begin();
3116 vector<string>::const_iterator end = engs.end();
3117 for (; it != end; ++it) {
3118 if (*it == "default")
3119 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
3120 ENGINE_TYPE_DEFAULT);
3121 else if (*it == "authoryear")
3122 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
3123 ENGINE_TYPE_AUTHORYEAR);
3124 else if (*it == "numerical")
3125 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
3126 ENGINE_TYPE_NUMERICAL);
3128 int i = biblioModule->citeStyleCO->findData(sel);
3129 if (biblioModule->citeStyleCO->findData(sel) == -1)
3131 biblioModule->citeStyleCO->setCurrentIndex(i);
3133 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
3134 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
3138 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
3140 engine_types_.clear();
3142 for (int n = 0; !token(items, '|', n).empty(); ++n) {
3143 string style = token(items, '|', n);
3144 engine_types_.push_back(style);
3147 updateCiteStyles(engine_types_, sel);
3153 // both of these should take a vector<docstring>
3155 // This is an insanely complicated attempt to make this sort of thing
3156 // work with RTL languages.
3157 docstring formatStrVec(vector<string> const & v, docstring const & s)
3159 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
3163 return translateIfPossible(from_utf8(v[0]));
3164 if (v.size() == 2) {
3165 docstring retval = _("%1$s and %2$s");
3166 retval = subst(retval, _("and"), s);
3167 return bformat(retval, translateIfPossible(from_utf8(v[0])),
3168 translateIfPossible(from_utf8(v[1])));
3170 // The idea here is to format all but the last two items...
3171 int const vSize = v.size();
3172 docstring t2 = _("%1$s, %2$s");
3173 docstring retval = translateIfPossible(from_utf8(v[0]));
3174 for (int i = 1; i < vSize - 2; ++i)
3175 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
3176 //...and then to plug them, and the last two, into this schema
3177 docstring t = _("%1$s, %2$s, and %3$s");
3178 t = subst(t, _("and"), s);
3179 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
3180 translateIfPossible(from_utf8(v[vSize - 1])));
3183 vector<string> idsToNames(vector<string> const & idList)
3185 vector<string> retval;
3186 vector<string>::const_iterator it = idList.begin();
3187 vector<string>::const_iterator end = idList.end();
3188 for (; it != end; ++it) {
3189 LyXModule const * const mod = theModuleList[*it];
3191 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
3192 translateIfPossible(from_utf8(*it)))));
3194 retval.push_back(mod->getName());
3198 } // end anonymous namespace
3201 void GuiDocument::modulesToParams(BufferParams & bp)
3203 // update list of loaded modules
3204 bp.clearLayoutModules();
3205 int const srows = modules_sel_model_.rowCount();
3206 for (int i = 0; i < srows; ++i)
3207 bp.addLayoutModule(modules_sel_model_.getIDString(i));
3208 updateSelectedModules();
3210 // update the list of removed modules
3211 bp.clearRemovedModules();
3212 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
3213 list<string>::const_iterator rit = reqmods.begin();
3214 list<string>::const_iterator ren = reqmods.end();
3216 // check each of the default modules
3217 for (; rit != ren; ++rit) {
3218 list<string>::const_iterator mit = bp.getModules().begin();
3219 list<string>::const_iterator men = bp.getModules().end();
3221 for (; mit != men; ++mit) {
3228 // the module isn't present so must have been removed by the user
3229 bp.addRemovedModule(*rit);
3234 void GuiDocument::modulesChanged()
3236 modulesToParams(bp_);
3238 if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()
3239 && (nonModuleChanged_ || shellescapeChanged_)) {
3240 int const ret = Alert::prompt(_("Unapplied changes"),
3241 _("Some changes in the dialog were not yet applied.\n"
3242 "If you do not apply now, they will be lost after this action."),
3243 1, 1, _("&Apply"), _("&Dismiss"));
3248 modulesChanged_ = true;
3249 bp_.makeDocumentClass();
3255 void GuiDocument::updateModuleInfo()
3257 selectionManager->update();
3259 //Module description
3260 bool const focus_on_selected = selectionManager->selectedFocused();
3261 QAbstractItemView * lv;
3262 bool category = false;
3263 if (focus_on_selected) {
3264 lv = modulesModule->selectedLV;
3267 lv = modulesModule->availableLV;
3268 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
3269 modulesModule->infoML->document()->clear();
3272 QModelIndex const & idx = lv->selectionModel()->currentIndex();
3274 if (!focus_on_selected
3275 && modules_av_model_.itemFromIndex(idx)->hasChildren()) {
3276 // This is a category header
3277 modulesModule->infoML->document()->clear();
3281 string const modName = focus_on_selected ?
3282 modules_sel_model_.getIDString(idx.row())
3283 : fromqstr(modules_av_model_.data(idx, Qt::UserRole).toString());
3284 docstring desc = getModuleDescription(modName);
3286 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
3287 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
3290 desc += _("Module provided by document class.");
3294 docstring cat = getModuleCategory(modName);
3298 desc += bformat(_("<p><b>Category:</b> %1$s.</p>"),
3299 translateIfPossible(cat));
3303 vector<string> pkglist = getPackageList(modName);
3304 docstring pkgdesc = formatStrVec(pkglist, _("and"));
3305 if (!pkgdesc.empty()) {
3308 desc += bformat(_("<p><b>Package(s) required:</b> %1$s.</p>"), pkgdesc);
3311 pkglist = getRequiredList(modName);
3312 if (!pkglist.empty()) {
3313 vector<string> const reqdescs = idsToNames(pkglist);
3314 pkgdesc = formatStrVec(reqdescs, _("or"));
3317 desc += bformat(_("<p><b>Modules required:</b> %1$s.</p>"), pkgdesc);
3320 pkglist = getExcludedList(modName);
3321 if (!pkglist.empty()) {
3322 vector<string> const reqdescs = idsToNames(pkglist);
3323 pkgdesc = formatStrVec(reqdescs, _( "and"));
3326 desc += bformat(_("<p><b>Modules excluded:</b> %1$s.</p>"), pkgdesc);
3331 desc += bformat(_("<p><b>Filename:</b> <tt>%1$s.module</tt>.</p>"), from_utf8(modName));
3333 if (!isModuleAvailable(modName)) {
3336 desc += _("<p><font color=red><b>WARNING: Some required packages are unavailable!</b></font></p>");
3339 modulesModule->infoML->document()->setHtml(toqstr(desc));
3343 void GuiDocument::updateNumbering()
3345 DocumentClass const & tclass = documentClass();
3347 numberingModule->tocTW->setUpdatesEnabled(false);
3348 numberingModule->tocTW->clear();
3350 int const depth = numberingModule->depthSL->value();
3351 int const toc = numberingModule->tocSL->value();
3352 QString const no = qt_("No");
3353 QString const yes = qt_("Yes");
3354 QTreeWidgetItem * item = nullptr;
3356 DocumentClass::const_iterator lit = tclass.begin();
3357 DocumentClass::const_iterator len = tclass.end();
3358 for (; lit != len; ++lit) {
3359 int const toclevel = lit->toclevel;
3360 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
3361 item = new QTreeWidgetItem(numberingModule->tocTW);
3362 item->setText(0, toqstr(translateIfPossible(lit->name())));
3363 item->setText(1, (toclevel <= depth) ? yes : no);
3364 item->setText(2, (toclevel <= toc) ? yes : no);
3368 numberingModule->tocTW->setUpdatesEnabled(true);
3369 numberingModule->tocTW->update();
3373 void GuiDocument::getTableStyles()
3375 // We look for lyx files in the subdirectory dir of
3377 // 2) build_lyxdir (if not empty)
3379 // in this order. Files with a given sub-hierarchy will
3380 // only be listed once.
3381 // We also consider i18n subdirectories and store them separately.
3384 // The three locations to look at.
3385 string const user = addPath(package().user_support().absFileName(), "tabletemplates");
3386 string const build = addPath(package().build_support().absFileName(), "tabletemplates");
3387 string const system = addPath(package().system_support().absFileName(), "tabletemplates");
3389 dirs << toqstr(user)
3393 for (int i = 0; i < dirs.size(); ++i) {
3394 QString const & dir = dirs.at(i);
3395 QDirIterator it(dir, QDir::Files, QDirIterator::Subdirectories);
3396 while (it.hasNext()) {
3397 QString fn = QFileInfo(it.next()).fileName();
3398 if (!fn.endsWith(".lyx") || fn.contains("_1x"))
3400 QString data = fn.left(fn.lastIndexOf(".lyx"));
3401 QString guiname = data;
3402 guiname = toqstr(translateIfPossible(qstring_to_ucs4(guiname.replace('_', ' '))));
3403 QString relpath = toqstr(makeRelPath(qstring_to_ucs4(fn),
3404 qstring_to_ucs4(dir)));
3405 if (textLayoutModule->tableStyleCO->findData(data) == -1)
3406 textLayoutModule->tableStyleCO->addItem(guiname, data);
3412 void GuiDocument::updateDefaultFormat()
3416 // make a copy in order to consider unapplied changes
3417 BufferParams param_copy = buffer().params();
3418 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
3419 int const idx = latexModule->classCO->currentIndex();
3421 string const classname = fromqstr(latexModule->classCO->getData(idx));
3422 param_copy.setBaseClass(classname, buffer().layoutPos());
3423 param_copy.makeDocumentClass(true);
3425 outputModule->defaultFormatCO->blockSignals(true);
3426 outputModule->defaultFormatCO->clear();
3427 outputModule->defaultFormatCO->addItem(qt_("Default"),
3428 QVariant(QString("default")));
3429 FormatList const & formats =
3430 param_copy.exportableFormats(true);
3431 for (Format const * f : formats)
3432 outputModule->defaultFormatCO->addItem
3433 (toqstr(translateIfPossible(f->prettyname())),
3434 QVariant(toqstr(f->name())));
3435 outputModule->defaultFormatCO->blockSignals(false);
3439 bool GuiDocument::isChildIncluded(string const & child)
3441 if (includeonlys_.empty())
3443 return (std::find(includeonlys_.begin(),
3444 includeonlys_.end(), child) != includeonlys_.end());
3448 void GuiDocument::applyView()
3450 // auto-validate local layout
3451 if (!localLayout->isValid()) {
3452 localLayout->validate();
3453 if (!localLayout->isValid()) {
3454 setApplyStopped(true);
3455 docPS->setCurrentPanel(N_("Local Layout"));
3461 preambleModule->apply(bp_);
3462 localLayout->apply(bp_);
3465 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
3466 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
3469 string const engine =
3470 fromqstr(biblioModule->citeEngineCO->itemData(
3471 biblioModule->citeEngineCO->currentIndex()).toString());
3472 bp_.setCiteEngine(engine);
3474 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
3475 biblioModule->citeStyleCO->currentIndex()).toInt());
3476 if (theCiteEnginesList[engine]->hasEngineType(style))
3477 bp_.setCiteEngineType(style);
3479 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
3481 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
3483 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
3484 biblioModule->bibunitsCO->currentIndex()).toString());
3486 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
3488 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
3489 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
3490 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
3492 string const bibtex_command =
3493 fromqstr(biblioModule->bibtexCO->itemData(
3494 biblioModule->bibtexCO->currentIndex()).toString());
3495 string const bibtex_options =
3496 fromqstr(biblioModule->bibtexOptionsLE->text());
3497 if (bibtex_command == "default" || bibtex_options.empty())
3498 bp_.bibtex_command = bibtex_command;
3500 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
3502 if (biblioChanged_) {
3503 buffer().invalidateBibinfoCache();
3504 buffer().removeBiblioTempFiles();
3508 indicesModule->apply(bp_);
3510 // language & quotes
3511 switch (langModule->encodingCO->currentIndex()) {
3512 case EncodingSets::unicode: {
3513 if (!fontModule->osFontsCB->isChecked())
3514 bp_.inputenc = fromqstr(langModule->unicodeEncodingCO->itemData(
3515 langModule->unicodeEncodingCO->currentIndex()).toString());
3518 case EncodingSets::legacy: {
3519 bp_.inputenc = "auto-legacy";
3520 bp_.inputenc = fromqstr(langModule->autoEncodingCO->itemData(
3521 langModule->autoEncodingCO->currentIndex()).toString());
3524 case EncodingSets::custom: {
3525 bp_.inputenc = fromqstr(langModule->customEncodingCO->itemData(
3526 langModule->customEncodingCO->currentIndex()).toString());
3530 // this should never happen
3531 bp_.inputenc = "utf8";
3533 bp_.quotes_style = QuoteStyle(langModule->quoteStyleCO->itemData(
3534 langModule->quoteStyleCO->currentIndex()).toInt());
3535 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
3537 QString const langname = langModule->languageCO->itemData(
3538 langModule->languageCO->currentIndex()).toString();
3539 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
3540 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
3541 // If current cursor language was the document language, then update it too.
3542 if (cur.current_font.language() == bp_.language) {
3543 cur.current_font.setLanguage(newlang);
3544 cur.real_current_font.setLanguage(newlang);
3546 bp_.language = newlang;
3548 QString const pack = langModule->languagePackageCO->itemData(
3549 langModule->languagePackageCO->currentIndex()).toString();
3550 if (pack == "custom")
3552 fromqstr(langModule->languagePackageLE->text());
3554 bp_.lang_package = fromqstr(pack);
3557 bp_.backgroundcolor = set_backgroundcolor;
3558 bp_.isbackgroundcolor = is_backgroundcolor;
3559 bp_.fontcolor = set_fontcolor;
3560 bp_.isfontcolor = is_fontcolor;
3561 bp_.notefontcolor = set_notefontcolor;
3562 bp_.isnotefontcolor = is_notefontcolor;
3563 if (is_notefontcolor) {
3564 // Set information used in statusbar (#12130)
3565 lcolor.setColor("notefontcolor", lyx::X11hexname(set_notefontcolor));
3566 lcolor.setGUIName("notefontcolor", N_("greyedout inset text"));
3568 bp_.boxbgcolor = set_boxbgcolor;
3569 bp_.isboxbgcolor = is_boxbgcolor;
3572 if (bp_.documentClass().hasTocLevels()) {
3573 bp_.tocdepth = numberingModule->tocSL->value();
3574 bp_.secnumdepth = numberingModule->depthSL->value();
3576 bp_.use_lineno = numberingModule->linenoCB->isChecked();
3577 bp_.lineno_opts = fromqstr(numberingModule->linenoLE->text());
3580 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3581 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3582 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3583 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3586 bp_.graphics_driver =
3587 tex_graphics[latexModule->psdriverCO->currentIndex()];
3590 int idx = latexModule->classCO->currentIndex();
3592 string const classname = fromqstr(latexModule->classCO->getData(idx));
3593 bp_.setBaseClass(classname, buffer().layoutPos());
3597 modulesToParams(bp_);
3600 map<string, string> const & packages = BufferParams::auto_packages();
3601 for (map<string, string>::const_iterator it = packages.begin();
3602 it != packages.end(); ++it) {
3603 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3606 int row = mathsModule->packagesTW->row(item);
3609 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3610 if (rb->isChecked()) {
3611 bp_.use_package(it->first, BufferParams::package_auto);
3614 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3615 if (rb->isChecked()) {
3616 bp_.use_package(it->first, BufferParams::package_on);
3619 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3620 if (rb->isChecked())
3621 bp_.use_package(it->first, BufferParams::package_off);
3623 // if math is indented
3624 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3625 if (bp_.is_math_indent) {
3626 // if formulas are indented
3627 if (mathsModule->MathIndentCO->itemData(mathsModule->MathIndentCO->currentIndex()) == "custom") {
3628 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3629 mathsModule->MathIndentLengthCO));
3630 bp_.setMathIndent(mathindent);
3633 bp_.setMathIndent(Length());
3635 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3637 bp_.math_numbering_side = BufferParams::LEFT;
3640 bp_.math_numbering_side = BufferParams::DEFAULT;
3643 bp_.math_numbering_side = BufferParams::RIGHT;
3646 // this should never happen
3647 bp_.math_numbering_side = BufferParams::DEFAULT;
3652 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3653 bp_.pagestyle = "default";
3655 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3656 for (size_t i = 0; i != pagestyles.size(); ++i)
3657 if (pagestyles[i].second == style_gui)
3658 bp_.pagestyle = pagestyles[i].first;
3662 switch (textLayoutModule->lspacingCO->currentIndex()) {
3664 bp_.spacing().set(Spacing::Single);
3667 bp_.spacing().set(Spacing::Onehalf);
3670 bp_.spacing().set(Spacing::Double);
3673 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3675 bp_.spacing().set(Spacing::Single);
3677 bp_.spacing().set(Spacing::Other, s);
3682 if (textLayoutModule->twoColumnCB->isChecked())
3687 bp_.justification = textLayoutModule->justCB->isChecked();
3689 if (textLayoutModule->indentRB->isChecked()) {
3690 // if paragraphs are separated by an indentation
3691 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3692 if (textLayoutModule->indentCO->itemData(textLayoutModule->indentCO->currentIndex()) == "custom") {
3693 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3694 textLayoutModule->indentLengthCO));
3695 bp_.setParIndent(parindent);
3698 bp_.setParIndent(Length());
3700 // if paragraphs are separated by a skip
3701 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3702 VSpace::VSpaceKind spacekind =
3703 VSpace::VSpaceKind(textLayoutModule->skipCO->itemData(textLayoutModule->skipCO->currentIndex()).toInt());
3704 switch (spacekind) {
3705 case VSpace::SMALLSKIP:
3706 case VSpace::MEDSKIP:
3707 case VSpace::BIGSKIP:
3708 case VSpace::HALFLINE:
3709 case VSpace::FULLLINE:
3710 bp_.setDefSkip(VSpace(spacekind));
3712 case VSpace::LENGTH: {
3714 widgetsToLength(textLayoutModule->skipLE,
3715 textLayoutModule->skipLengthCO)
3721 // this should never happen
3722 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3726 bp_.tablestyle = fromqstr(textLayoutModule->tableStyleCO->itemData(
3727 textLayoutModule->tableStyleCO->currentIndex()).toString());
3730 fromqstr(latexModule->optionsLE->text());
3732 bp_.use_default_options =
3733 latexModule->defaultOptionsCB->isChecked();
3735 if (latexModule->childDocGB->isChecked())
3737 fromqstr(latexModule->childDocLE->text());
3739 bp_.master = string();
3742 bp_.clearIncludedChildren();
3743 if (masterChildModule->includeonlyRB->isChecked()) {
3744 list<string>::const_iterator it = includeonlys_.begin();
3745 for (; it != includeonlys_.end() ; ++it) {
3746 bp_.addIncludedChildren(*it);
3749 if (masterChildModule->maintainCRNoneRB->isChecked())
3750 bp_.maintain_unincluded_children =
3751 BufferParams::CM_None;
3752 else if (masterChildModule->maintainCRMostlyRB->isChecked())
3753 bp_.maintain_unincluded_children =
3754 BufferParams::CM_Mostly;
3756 bp_.maintain_unincluded_children =
3757 BufferParams::CM_Strict;
3758 updateIncludeonlyDisplay();
3761 bp_.float_placement = floatModule->getPlacement();
3762 bp_.float_alignment = floatModule->getAlignment();
3765 // text should have passed validation
3766 idx = listingsModule->packageCO->currentIndex();
3767 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3768 bp_.listings_params =
3769 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3772 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3773 outputModule->defaultFormatCO->currentIndex()).toString());
3775 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3776 bp_.useNonTeXFonts = nontexfonts;
3778 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3779 if (!bp_.shell_escape)
3780 theSession().shellescapeFiles().remove(buffer().absFileName());
3781 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3782 theSession().shellescapeFiles().insert(buffer().absFileName());
3783 Buffer & buf = const_cast<Buffer &>(buffer());
3784 buf.params().shell_escape = bp_.shell_escape;
3786 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3788 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3790 int mathfmt = outputModule->mathoutCB->currentIndex();
3793 BufferParams::MathOutput const mo =
3794 static_cast<BufferParams::MathOutput>(mathfmt);
3795 bp_.html_math_output = mo;
3796 bp_.html_be_strict = outputModule->strictCB->isChecked();
3797 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3798 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3799 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3801 int tablefmt = outputModule->tableoutCB->currentIndex();
3804 auto const to = static_cast<BufferParams::TableOutput>(tablefmt);
3805 bp_.docbook_table_output = to;
3807 int mathmlprefix = outputModule->mathmlprefixCB->currentIndex();
3808 if (mathmlprefix == -1)
3810 auto const mp = static_cast<BufferParams::MathMLNameSpacePrefix>(mathmlprefix);
3811 bp_.docbook_mathml_prefix = mp;
3813 bp_.save_transient_properties =
3814 outputModule->saveTransientPropertiesCB->isChecked();
3815 bp_.postpone_fragile_content =
3816 outputModule->postponeFragileCB->isChecked();
3819 bp_.fonts_roman[nontexfonts] =
3820 fromqstr(fontModule->fontsRomanCO->
3821 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3822 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3823 bp_.font_roman_opts = fromqstr(fontModule->fontspecRomanLE->text());
3825 bp_.fonts_sans[nontexfonts] =
3826 fromqstr(fontModule->fontsSansCO->
3827 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3828 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3829 bp_.font_sans_opts = fromqstr(fontModule->fontspecSansLE->text());
3831 bp_.fonts_typewriter[nontexfonts] =
3832 fromqstr(fontModule->fontsTypewriterCO->
3833 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3834 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3835 bp_.font_typewriter_opts = fromqstr(fontModule->fontspecTypewriterLE->text());
3837 bp_.fonts_math[nontexfonts] =
3838 fromqstr(fontModule->fontsMathCO->
3839 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3840 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3842 QString const fontenc =
3843 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3844 if (fontenc == "custom")
3845 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3847 bp_.fontenc = fromqstr(fontenc);
3850 fromqstr(fontModule->cjkFontLE->text());
3852 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3853 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3855 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3856 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3858 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3859 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3861 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3863 bp_.fonts_roman_osf = fontModule->fontOsfCB->isChecked();
3864 bp_.fonts_sans_osf = fontModule->fontSansOsfCB->isChecked();
3865 bp_.fonts_typewriter_osf = fontModule->fontTypewriterOsfCB->isChecked();
3868 bp_.fonts_default_family = "default";
3870 bp_.fonts_default_family = GuiDocument::fontfamilies[
3871 fontModule->fontsDefaultCO->currentIndex()];
3873 if (fontModule->fontsizeCO->currentIndex() == 0)
3874 bp_.fontsize = "default";
3877 fromqstr(fontModule->fontsizeCO->currentText());
3880 bp_.papersize = PAPER_SIZE(
3881 pageLayoutModule->papersizeCO->currentIndex());
3883 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3884 pageLayoutModule->paperwidthUnitCO);
3886 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3887 pageLayoutModule->paperheightUnitCO);
3889 if (pageLayoutModule->facingPagesCB->isChecked())
3890 bp_.sides = TwoSides;
3892 bp_.sides = OneSide;
3894 if (pageLayoutModule->landscapeRB->isChecked())
3895 bp_.orientation = ORIENTATION_LANDSCAPE;
3897 bp_.orientation = ORIENTATION_PORTRAIT;
3900 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3902 Ui::MarginsUi const * m = marginsModule;
3904 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3905 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3906 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3907 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3908 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3909 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3910 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3911 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3914 branchesModule->apply(bp_);
3917 PDFOptions & pdf = bp_.pdfoptions();
3918 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3919 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3920 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3921 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3922 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3924 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3925 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3926 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3927 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3929 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3930 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3931 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3932 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3934 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3935 if (pdfSupportModule->fullscreenCB->isChecked())
3936 pdf.pagemode = pdf.pagemode_fullscreen;
3938 pdf.pagemode.clear();
3939 pdf.quoted_options = pdf.quoted_options_check(
3940 fromqstr(pdfSupportModule->optionsTE->toPlainText()));
3941 #if QT_VERSION < 0x060000
3942 bp_.document_metadata = qstring_to_ucs4(pdfSupportModule->metadataTE->toPlainText()
3943 .trimmed().replace(QRegExp("\n+"), "\n"));
3945 bp_.document_metadata = qstring_to_ucs4(pdfSupportModule->metadataTE->toPlainText()
3946 .trimmed().replace(QRegularExpression("\n+"), "\n"));
3950 bp_.track_changes = changesModule->trackChangesCB->isChecked();
3951 bp_.output_changes = changesModule->outputChangesCB->isChecked();
3952 bool const cb_switched_off = (bp_.change_bars
3953 && !changesModule->changeBarsCB->isChecked());
3954 bp_.change_bars = changesModule->changeBarsCB->isChecked();
3955 if (cb_switched_off)
3956 // if change bars have been switched off,
3957 // we need to ditch the aux file
3958 buffer().requireFreshStart(true);
3961 nonModuleChanged_ = false;
3962 shellescapeChanged_ = false;
3966 void GuiDocument::paramsToDialog()
3968 // set the default unit
3969 Length::UNIT const default_unit = Length::defaultUnit();
3972 preambleModule->update(bp_, id());
3973 localLayout->update(bp_, id());
3976 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3977 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3980 string const cite_engine = bp_.citeEngine();
3982 biblioModule->citeEngineCO->setCurrentIndex(
3983 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3985 updateEngineType(documentClass().opt_enginetype(),
3986 bp_.citeEngineType());
3988 checkPossibleCiteEngines();
3990 biblioModule->citeStyleCO->setCurrentIndex(
3991 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3993 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3995 biblioModule->bibunitsCO->clear();
3996 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3997 if (documentClass().hasLaTeXLayout("part"))
3998 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3999 if (documentClass().hasLaTeXLayout("chapter"))
4000 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
4001 if (documentClass().hasLaTeXLayout("section"))
4002 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
4003 if (documentClass().hasLaTeXLayout("subsection"))
4004 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
4005 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
4007 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
4009 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
4011 biblioModule->bibunitsCO->setCurrentIndex(0);
4013 updateEngineDependends();
4016 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
4017 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
4019 updateDefaultBiblio(bp_.defaultBiblioStyle());
4021 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
4025 split(bp_.bibtex_command, command, ' ');
4027 int bpos = biblioModule->bibtexCO->findData(toqstr(command));
4029 // We add and set the unknown compiler, indicating that it is unavailable
4030 // to assure document compilation and for security reasons, a fallback
4031 // will be used on document processing stage
4032 biblioModule->bibtexCO->addItem(toqstr(bformat(_("%1$s (not available)"),
4033 from_utf8(command))), toqstr(command));
4034 bpos = biblioModule->bibtexCO->findData(toqstr(command));
4036 biblioModule->bibtexCO->setCurrentIndex(bpos);
4037 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
4038 biblioModule->bibtexOptionsLE->setEnabled(
4039 biblioModule->bibtexCO->currentIndex() != 0);
4041 biblioChanged_ = false;
4044 // We may be called when there is no Buffer, e.g., when
4045 // the last view has just been closed.
4046 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
4047 indicesModule->update(bp_, isReadOnly);
4049 // language & quotes
4050 int const pos = langModule->languageCO->findData(toqstr(
4051 bp_.language->lang()));
4052 langModule->languageCO->setCurrentIndex(pos);
4054 updateQuoteStyles();
4056 langModule->quoteStyleCO->setCurrentIndex(
4057 langModule->quoteStyleCO->findData(static_cast<int>(bp_.quotes_style)));
4058 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
4060 // LaTeX input encoding: set after the fonts (see below)
4062 int p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
4064 langModule->languagePackageCO->setCurrentIndex(
4065 langModule->languagePackageCO->findData("custom"));
4066 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
4068 langModule->languagePackageCO->setCurrentIndex(p);
4069 langModule->languagePackageLE->clear();
4073 if (bp_.isfontcolor) {
4074 colorModule->fontColorPB->setStyleSheet(
4075 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
4077 set_fontcolor = bp_.fontcolor;
4078 is_fontcolor = bp_.isfontcolor;
4080 colorModule->noteFontColorPB->setStyleSheet(
4081 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
4082 set_notefontcolor = bp_.notefontcolor;
4083 is_notefontcolor = bp_.isnotefontcolor;
4085 if (bp_.isbackgroundcolor) {
4086 colorModule->backgroundPB->setStyleSheet(
4087 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
4089 set_backgroundcolor = bp_.backgroundcolor;
4090 is_backgroundcolor = bp_.isbackgroundcolor;
4092 colorModule->boxBackgroundPB->setStyleSheet(
4093 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
4094 set_boxbgcolor = bp_.boxbgcolor;
4095 is_boxbgcolor = bp_.isboxbgcolor;
4098 int const min_toclevel = documentClass().min_toclevel();
4099 int const max_toclevel = documentClass().max_toclevel();
4100 if (documentClass().hasTocLevels()) {
4101 numberingModule->setEnabled(true);
4102 numberingModule->depthSL->setMinimum(min_toclevel - 1);
4103 numberingModule->depthSL->setMaximum(max_toclevel);
4104 numberingModule->depthSL->setValue(bp_.secnumdepth);
4105 numberingModule->tocSL->setMaximum(min_toclevel - 1);
4106 numberingModule->tocSL->setMaximum(max_toclevel);
4107 numberingModule->tocSL->setValue(bp_.tocdepth);
4110 numberingModule->setEnabled(false);
4111 numberingModule->tocTW->clear();
4114 numberingModule->linenoCB->setChecked(bp_.use_lineno);
4115 numberingModule->linenoLE->setEnabled(bp_.use_lineno);
4116 numberingModule->linenoLA->setEnabled(bp_.use_lineno);
4117 numberingModule->linenoLE->setText(toqstr(bp_.lineno_opts));
4120 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
4121 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
4122 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
4123 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
4124 bulletsModule->init();
4127 int nitem = findToken(tex_graphics, bp_.graphics_driver);
4129 latexModule->psdriverCO->setCurrentIndex(nitem);
4133 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
4134 if (bp_.is_math_indent) {
4135 Length const mathindent = bp_.getMathIndent();
4137 if (!mathindent.empty()) {
4138 lengthToWidgets(mathsModule->MathIndentLE,
4139 mathsModule->MathIndentLengthCO,
4140 mathindent, default_unit);
4143 mathsModule->MathIndentCO->setCurrentIndex(indent);
4144 enableMathIndent(indent);
4146 switch(bp_.math_numbering_side) {
4147 case BufferParams::LEFT:
4148 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
4150 case BufferParams::DEFAULT:
4151 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
4153 case BufferParams::RIGHT:
4154 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
4157 map<string, string> const & packages = BufferParams::auto_packages();
4158 for (map<string, string>::const_iterator it = packages.begin();
4159 it != packages.end(); ++it) {
4160 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
4163 int row = mathsModule->packagesTW->row(item);
4164 switch (bp_.use_package(it->first)) {
4165 case BufferParams::package_off: {
4167 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
4168 rb->setChecked(true);
4171 case BufferParams::package_on: {
4173 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
4174 rb->setChecked(true);
4177 case BufferParams::package_auto: {
4179 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
4180 rb->setChecked(true);
4186 switch (bp_.spacing().getSpace()) {
4187 case Spacing::Other: nitem = 3; break;
4188 case Spacing::Double: nitem = 2; break;
4189 case Spacing::Onehalf: nitem = 1; break;
4190 case Spacing::Default: case Spacing::Single: nitem = 0; break;
4194 string const & layoutID = bp_.baseClassID();
4195 setLayoutComboByIDString(layoutID);
4197 updatePagestyle(documentClass().opt_pagestyle(),
4200 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
4201 if (bp_.spacing().getSpace() == Spacing::Other) {
4202 doubleToWidget(textLayoutModule->lspacingLE,
4203 bp_.spacing().getValueAsString());
4206 int ts = textLayoutModule->tableStyleCO->findData(toqstr(bp_.tablestyle));
4208 textLayoutModule->tableStyleCO->setCurrentIndex(ts);
4210 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
4211 textLayoutModule->indentRB->setChecked(true);
4212 string parindent = bp_.getParIndent().asString();
4213 QString indent = toqstr("default");
4214 if (!parindent.empty()) {
4215 lengthToWidgets(textLayoutModule->indentLE,
4216 textLayoutModule->indentLengthCO,
4217 parindent, default_unit);
4218 indent = toqstr("custom");
4220 textLayoutModule->indentCO->setCurrentIndex(textLayoutModule->indentCO->findData(indent));
4221 setIndent(textLayoutModule->indentCO->currentIndex());
4223 textLayoutModule->skipRB->setChecked(true);
4224 VSpace::VSpaceKind skip = bp_.getDefSkip().kind();
4225 textLayoutModule->skipCO->setCurrentIndex(textLayoutModule->skipCO->findData(skip));
4226 if (skip == VSpace::LENGTH) {
4227 string const length = bp_.getDefSkip().asLyXCommand();
4228 lengthToWidgets(textLayoutModule->skipLE,
4229 textLayoutModule->skipLengthCO,
4230 length, default_unit);
4232 setSkip(textLayoutModule->skipCO->currentIndex());
4235 textLayoutModule->twoColumnCB->setChecked(
4237 textLayoutModule->justCB->setChecked(bp_.justification);
4239 if (!bp_.options.empty()) {
4240 latexModule->optionsLE->setText(
4241 toqstr(bp_.options));
4243 latexModule->optionsLE->setText(QString());
4247 latexModule->defaultOptionsCB->setChecked(
4248 bp_.use_default_options);
4249 updateSelectedModules();
4250 selectionManager->updateProvidedModules(
4251 bp_.baseClass()->providedModules());
4252 selectionManager->updateExcludedModules(
4253 bp_.baseClass()->excludedModules());
4255 if (!documentClass().options().empty()) {
4256 latexModule->defaultOptionsLE->setText(
4257 toqstr(documentClass().options()));
4259 latexModule->defaultOptionsLE->setText(
4260 toqstr(_("[No options predefined]")));
4263 latexModule->defaultOptionsLE->setEnabled(
4264 bp_.use_default_options
4265 && !documentClass().options().empty());
4267 latexModule->defaultOptionsCB->setEnabled(
4268 !documentClass().options().empty());
4270 if (!bp_.master.empty()) {
4271 latexModule->childDocGB->setChecked(true);
4272 latexModule->childDocLE->setText(
4273 toqstr(bp_.master));
4275 latexModule->childDocLE->setText(QString());
4276 latexModule->childDocGB->setChecked(false);
4280 if (!bufferview() || !buffer().hasChildren()) {
4281 masterChildModule->childrenTW->clear();
4282 includeonlys_.clear();
4283 docPS->showPanel("Child Documents", false);
4284 if (docPS->isCurrentPanel("Child Documents"))
4285 docPS->setCurrentPanel("Document Class");
4287 docPS->showPanel("Child Documents", true);
4288 masterChildModule->setEnabled(true);
4289 includeonlys_ = bp_.getIncludedChildren();
4290 updateIncludeonlys();
4291 updateIncludeonlyDisplay();
4293 switch (bp_.maintain_unincluded_children) {
4294 case BufferParams::CM_None:
4295 masterChildModule->maintainCRNoneRB->setChecked(true);
4297 case BufferParams::CM_Mostly:
4298 masterChildModule->maintainCRMostlyRB->setChecked(true);
4300 case BufferParams::CM_Strict:
4302 masterChildModule->maintainCRStrictRB->setChecked(true);
4307 floatModule->setPlacement(bp_.float_placement);
4308 floatModule->setAlignment(bp_.float_alignment);
4311 // break listings_params to multiple lines
4313 InsetListingsParams(bp_.listings_params).separatedParams();
4314 listingsModule->listingsED->setPlainText(toqstr(lstparams));
4315 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
4317 listingsModule->packageCO->setCurrentIndex(nn);
4320 // some languages only work with Polyglossia (which requires non-TeX fonts)
4321 Language const * lang = lyx::languages.getLanguage(
4322 fromqstr(langModule->languageCO->itemData(
4323 langModule->languageCO->currentIndex()).toString()));
4324 bool const need_fontspec =
4325 lang->babel().empty() && !lang->polyglossia().empty()
4326 && lang->required() != "CJK" && lang->required() != "japanese";
4327 bool const os_fonts_available =
4328 bp_.baseClass()->outputType() == lyx::LATEX
4329 && LaTeXFeatures::isAvailable("fontspec");
4330 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
4331 fontModule->osFontsCB->setChecked(
4332 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
4333 updateFontsize(documentClass().opt_fontsize(),
4336 QString font = toqstr(bp_.fontsRoman());
4337 int rpos = fontModule->fontsRomanCO->findData(font);
4339 rpos = fontModule->fontsRomanCO->count();
4340 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
4342 fontModule->fontsRomanCO->setCurrentIndex(rpos);
4343 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
4345 font = toqstr(bp_.fontsSans());
4346 int spos = fontModule->fontsSansCO->findData(font);
4348 spos = fontModule->fontsSansCO->count();
4349 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
4351 fontModule->fontsSansCO->setCurrentIndex(spos);
4352 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
4354 font = toqstr(bp_.fontsTypewriter());
4355 int tpos = fontModule->fontsTypewriterCO->findData(font);
4357 tpos = fontModule->fontsTypewriterCO->count();
4358 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
4360 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
4361 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
4363 font = toqstr(bp_.fontsMath());
4364 int mpos = fontModule->fontsMathCO->findData(font);
4366 mpos = fontModule->fontsMathCO->count();
4367 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
4369 fontModule->fontsMathCO->setCurrentIndex(mpos);
4370 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
4372 if (bp_.useNonTeXFonts && os_fonts_available) {
4373 fontModule->fontencLA->setEnabled(false);
4374 fontModule->fontencCO->setEnabled(false);
4375 fontModule->fontencLE->setEnabled(false);
4377 fontModule->fontencLA->setEnabled(true);
4378 fontModule->fontencCO->setEnabled(true);
4379 fontModule->fontencLE->setEnabled(true);
4385 if (!bp_.fonts_cjk.empty())
4386 fontModule->cjkFontLE->setText(
4387 toqstr(bp_.fonts_cjk));
4389 fontModule->cjkFontLE->setText(QString());
4391 fontModule->microtypeCB->setChecked(bp_.use_microtype);
4392 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
4394 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
4395 fontModule->fontOsfCB->setChecked(bp_.fonts_roman_osf);
4396 fontModule->fontSansOsfCB->setChecked(bp_.fonts_sans_osf);
4397 fontModule->fontTypewriterOsfCB->setChecked(bp_.fonts_typewriter_osf);
4398 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
4399 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
4400 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
4401 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
4402 if (!bp_.font_roman_opts.empty())
4403 fontModule->fontspecRomanLE->setText(
4404 toqstr(bp_.font_roman_opts));
4406 fontModule->fontspecRomanLE->setText(QString());
4407 if (!bp_.font_sans_opts.empty())
4408 fontModule->fontspecSansLE->setText(
4409 toqstr(bp_.font_sans_opts));
4411 fontModule->fontspecSansLE->setText(QString());
4412 if (!bp_.font_typewriter_opts.empty())
4413 fontModule->fontspecTypewriterLE->setText(
4414 toqstr(bp_.font_typewriter_opts));
4416 fontModule->fontspecTypewriterLE->setText(QString());
4418 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
4420 fontModule->fontsDefaultCO->setCurrentIndex(nn);
4422 if (bp_.fontenc == "auto" || bp_.fontenc == "default") {
4423 fontModule->fontencCO->setCurrentIndex(
4424 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
4425 fontModule->fontencLE->setEnabled(false);
4427 fontModule->fontencCO->setCurrentIndex(
4428 fontModule->fontencCO->findData("custom"));
4429 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
4432 // LaTeX input encoding
4433 // Set after fonts because non-tex fonts override "\inputencoding".
4434 inputencodingToDialog();
4437 // This must be set _after_ fonts since updateDefaultFormat()
4438 // checks osFontsCB settings.
4439 // update combobox with formats
4440 updateDefaultFormat();
4441 int index = outputModule->defaultFormatCO->findData(toqstr(
4442 bp_.default_output_format));
4443 // set to default if format is not found
4446 outputModule->defaultFormatCO->setCurrentIndex(index);
4448 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
4449 outputModule->outputsyncCB->setChecked(bp_.output_sync);
4450 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
4451 outputModule->synccustomCB->setEnabled(bp_.output_sync);
4452 outputModule->synccustomLA->setEnabled(bp_.output_sync);
4454 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
4455 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
4456 outputModule->strictCB->setChecked(bp_.html_be_strict);
4457 outputModule->cssCB->setChecked(bp_.html_css_as_file);
4459 outputModule->tableoutCB->setCurrentIndex(bp_.docbook_table_output);
4460 outputModule->mathmlprefixCB->setCurrentIndex(bp_.docbook_mathml_prefix);
4462 outputModule->saveTransientPropertiesCB
4463 ->setChecked(bp_.save_transient_properties);
4464 outputModule->postponeFragileCB
4465 ->setChecked(bp_.postpone_fragile_content);
4468 bool const extern_geometry =
4469 documentClass().provides("geometry");
4470 int const psize = bp_.papersize;
4471 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
4472 setCustomPapersize(!extern_geometry && psize == 1);
4473 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
4475 bool const landscape =
4476 bp_.orientation == ORIENTATION_LANDSCAPE;
4477 pageLayoutModule->landscapeRB->setChecked(landscape);
4478 pageLayoutModule->portraitRB->setChecked(!landscape);
4479 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
4480 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
4482 pageLayoutModule->facingPagesCB->setChecked(
4483 bp_.sides == TwoSides);
4485 lengthToWidgets(pageLayoutModule->paperwidthLE,
4486 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
4487 lengthToWidgets(pageLayoutModule->paperheightLE,
4488 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
4491 Ui::MarginsUi * m = marginsModule;
4495 lengthToWidgets(m->topLE, m->topUnit,
4496 bp_.topmargin, default_unit);
4498 lengthToWidgets(m->bottomLE, m->bottomUnit,
4499 bp_.bottommargin, default_unit);
4501 lengthToWidgets(m->innerLE, m->innerUnit,
4502 bp_.leftmargin, default_unit);
4504 lengthToWidgets(m->outerLE, m->outerUnit,
4505 bp_.rightmargin, default_unit);
4507 lengthToWidgets(m->headheightLE, m->headheightUnit,
4508 bp_.headheight, default_unit);
4510 lengthToWidgets(m->headsepLE, m->headsepUnit,
4511 bp_.headsep, default_unit);
4513 lengthToWidgets(m->footskipLE, m->footskipUnit,
4514 bp_.footskip, default_unit);
4516 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
4517 bp_.columnsep, default_unit);
4520 updateUnknownBranches();
4521 branchesModule->update(bp_);
4524 PDFOptions const & pdf = bp_.pdfoptions();
4525 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
4526 if (bp_.documentClass().provides("hyperref"))
4527 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
4529 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
4530 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
4531 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
4532 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
4533 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
4535 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
4536 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
4537 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
4539 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
4540 pdfSupportModule->bookmarksopenlevelSB->setEnabled(pdf.bookmarksopen);
4541 pdfSupportModule->bookmarksopenlevelLA->setEnabled(pdf.bookmarksopen);
4543 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
4544 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
4545 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
4546 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
4548 nn = findToken(backref_opts, pdf.backref);
4550 pdfSupportModule->backrefCO->setCurrentIndex(nn);
4552 pdfSupportModule->fullscreenCB->setChecked
4553 (pdf.pagemode == pdf.pagemode_fullscreen);
4555 pdfSupportModule->optionsTE->setPlainText(
4556 toqstr(pdf.quoted_options));
4558 pdfSupportModule->metadataTE->setPlainText(
4559 toqstr(bp_.document_metadata));
4562 changesModule->trackChangesCB->setChecked(bp_.track_changes);
4563 changesModule->outputChangesCB->setChecked(bp_.output_changes);
4564 changesModule->changeBarsCB->setChecked(bp_.change_bars);
4565 changesModule->changeBarsCB->setEnabled(bp_.output_changes);
4567 // Make sure that the bc is in the INITIAL state
4568 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
4571 // clear changed branches cache
4572 changedBranches_.clear();
4574 // re-initiate module filter
4575 if (!filter_->text().isEmpty())
4576 moduleFilterPressed();
4579 nonModuleChanged_ = false;
4580 shellescapeChanged_ = false;
4584 void GuiDocument::saveDocDefault()
4586 // we have to apply the params first
4592 void GuiDocument::updateAvailableModules()
4594 modules_av_model_.clear();
4595 list<modInfoStruct> modInfoList = getModuleInfo();
4596 // Sort names according to the locale
4597 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
4598 return 0 < b.name.localeAwareCompare(a.name);
4600 QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png"));
4601 QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png"));
4604 catfont.setBold(true);
4606 unavbrush.setColor(Qt::gray);
4607 for (modInfoStruct const & m : modInfoList) {
4608 QStandardItem * item = new QStandardItem();
4609 QStandardItem * catItem;
4610 QString const catname = m.category;
4611 QList<QStandardItem *> fcats = modules_av_model_.findItems(catname, Qt::MatchExactly);
4613 catItem = fcats.first();
4615 catItem = new QStandardItem();
4616 catItem->setText(catname);
4617 catItem->setFont(catfont);
4618 modules_av_model_.insertRow(i, catItem);
4621 item->setEditable(false);
4622 catItem->setEditable(false);
4623 item->setData(m.name, Qt::DisplayRole);
4625 item->setForeground(unavbrush);
4626 item->setData(toqstr(m.id), Qt::UserRole);
4627 item->setData(m.description, Qt::ToolTipRole);
4629 item->setIcon(user_icon);
4631 item->setIcon(system_icon);
4632 catItem->appendRow(item);
4634 modules_av_model_.sort(0);
4638 void GuiDocument::updateSelectedModules()
4640 modules_sel_model_.clear();
4641 list<modInfoStruct> const selModList = getSelectedModules();
4643 for (modInfoStruct const & m : selModList) {
4644 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4650 void GuiDocument::updateIncludeonlyDisplay()
4652 if (includeonlys_.empty()) {
4653 masterChildModule->includeallRB->setChecked(true);
4654 masterChildModule->childrenTW->setEnabled(false);
4655 masterChildModule->maintainGB->setEnabled(false);
4657 masterChildModule->includeonlyRB->setChecked(true);
4658 masterChildModule->childrenTW->setEnabled(true);
4659 masterChildModule->maintainGB->setEnabled(true);
4664 void GuiDocument::updateIncludeonlys()
4666 masterChildModule->childrenTW->clear();
4667 QString const no = qt_("No");
4668 QString const yes = qt_("Yes");
4670 ListOfBuffers children = buffer().getChildren();
4671 ListOfBuffers::const_iterator it = children.begin();
4672 ListOfBuffers::const_iterator end = children.end();
4673 bool has_unincluded = false;
4674 bool all_unincluded = true;
4675 for (; it != end; ++it) {
4676 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4679 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4680 from_utf8(buffer().filePath())));
4681 item->setText(0, toqstr(name));
4682 item->setText(1, isChildIncluded(name) ? yes : no);
4683 if (!isChildIncluded(name))
4684 has_unincluded = true;
4686 all_unincluded = false;
4688 // Both if all children are included and if none is included
4689 // is equal to "include all" (i.e., omit \includeonly).
4690 if (!has_unincluded || all_unincluded)
4691 includeonlys_.clear();
4695 bool GuiDocument::isBiblatex() const
4697 QString const engine =
4698 biblioModule->citeEngineCO->itemData(
4699 biblioModule->citeEngineCO->currentIndex()).toString();
4701 // this can happen if the cite engine is unknown, which can happen
4702 // if one is using a file that came from someone else, etc. in that
4703 // case, we crash if we proceed.
4704 if (engine.isEmpty())
4707 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4711 void GuiDocument::updateDefaultBiblio(string const & style,
4712 string const & which)
4714 QString const bibstyle = toqstr(style);
4715 biblioModule->defaultBiblioCO->clear();
4720 if (which != "cbx") {
4721 // First the bbx styles
4722 biblioModule->biblatexBbxCO->clear();
4723 QStringList str = texFileList("bbxFiles.lst");
4724 // test whether we have a valid list, otherwise run rescan
4725 if (str.isEmpty()) {
4726 rescanTexStyles("bbx");
4727 str = texFileList("bbxFiles.lst");
4729 for (int i = 0; i != str.size(); ++i)
4730 str[i] = onlyFileName(str[i]);
4731 // sort on filename only (no path)
4734 for (int i = 0; i != str.count(); ++i) {
4735 QString item = changeExtension(str[i], "");
4736 if (item == bibstyle)
4738 biblioModule->biblatexBbxCO->addItem(item);
4741 if (item_nr == -1 && !bibstyle.isEmpty()) {
4742 biblioModule->biblatexBbxCO->addItem(bibstyle);
4743 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4747 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4749 biblioModule->biblatexBbxCO->clearEditText();
4752 if (which != "bbx") {
4753 // now the cbx styles
4754 biblioModule->biblatexCbxCO->clear();
4755 QStringList str = texFileList("cbxFiles.lst");
4756 // test whether we have a valid list, otherwise run rescan
4757 if (str.isEmpty()) {
4758 rescanTexStyles("cbx");
4759 str = texFileList("cbxFiles.lst");
4761 for (int i = 0; i != str.size(); ++i)
4762 str[i] = onlyFileName(str[i]);
4763 // sort on filename only (no path)
4766 for (int i = 0; i != str.count(); ++i) {
4767 QString item = changeExtension(str[i], "");
4768 if (item == bibstyle)
4770 biblioModule->biblatexCbxCO->addItem(item);
4773 if (item_nr == -1 && !bibstyle.isEmpty()) {
4774 biblioModule->biblatexCbxCO->addItem(bibstyle);
4775 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4779 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4781 biblioModule->biblatexCbxCO->clearEditText();
4784 biblioModule->biblatexBbxCO->clear();
4785 biblioModule->biblatexCbxCO->clear();
4786 QStringList str = texFileList("bstFiles.lst");
4787 // test whether we have a valid list, otherwise run rescan
4788 if (str.isEmpty()) {
4789 rescanTexStyles("bst");
4790 str = texFileList("bstFiles.lst");
4792 for (int i = 0; i != str.size(); ++i)
4793 str[i] = onlyFileName(str[i]);
4794 // sort on filename only (no path)
4797 for (int i = 0; i != str.count(); ++i) {
4798 QString item = changeExtension(str[i], "");
4799 if (item == bibstyle)
4801 biblioModule->defaultBiblioCO->addItem(item);
4804 if (item_nr == -1 && !bibstyle.isEmpty()) {
4805 biblioModule->defaultBiblioCO->addItem(bibstyle);
4806 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4810 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4812 biblioModule->defaultBiblioCO->clearEditText();
4815 updateResetDefaultBiblio();
4819 void GuiDocument::updateResetDefaultBiblio()
4821 QString const engine =
4822 biblioModule->citeEngineCO->itemData(
4823 biblioModule->citeEngineCO->currentIndex()).toString();
4824 CiteEngineType const cet =
4825 CiteEngineType(biblioModule->citeStyleCO->itemData(
4826 biblioModule->citeStyleCO->currentIndex()).toInt());
4828 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4830 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4831 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4832 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4833 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4834 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4835 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4837 biblioModule->resetDefaultBiblioPB->setEnabled(
4838 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4842 void GuiDocument::matchBiblatexStyles()
4844 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4849 void GuiDocument::updateContents()
4851 // Nothing to do here as the document settings is not cursor dependent.
4856 void GuiDocument::useClassDefaults()
4858 if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
4859 int const ret = Alert::prompt(_("Unapplied changes"),
4860 _("Some changes in the dialog were not yet applied.\n"
4861 "If you do not apply now, they will be lost after this action."),
4862 1, 1, _("&Apply"), _("&Dismiss"));
4867 int idx = latexModule->classCO->currentIndex();
4868 string const classname = fromqstr(latexModule->classCO->getData(idx));
4869 if (!bp_.setBaseClass(classname, buffer().layoutPos())) {
4870 Alert::error(_("Error"), _("Unable to set document class."));
4873 bp_.useClassDefaults();
4879 void GuiDocument::setLayoutComboByIDString(string const & idString)
4881 if (!latexModule->classCO->set(toqstr(idString)))
4882 Alert::warning(_("Can't set layout!"),
4883 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4887 bool GuiDocument::isValid()
4890 validateListingsParameters().isEmpty() &&
4891 !localLayout->editing() &&
4892 !preambleModule->editing() &&
4894 // if we're asking for skips between paragraphs
4895 !textLayoutModule->skipRB->isChecked() ||
4896 // then either we haven't chosen custom
4898 textLayoutModule->skipCO->itemData(
4899 textLayoutModule->skipCO->currentIndex()).toInt())
4900 != VSpace::LENGTH ||
4901 // or else a length has been given
4902 !textLayoutModule->skipLE->text().isEmpty()
4905 // if we're asking for indentation
4906 !textLayoutModule->indentRB->isChecked() ||
4907 // then either we haven't chosen custom
4908 (textLayoutModule->indentCO->itemData(
4909 textLayoutModule->indentCO->currentIndex()) != "custom") ||
4910 // or else a length has been given
4911 !textLayoutModule->indentLE->text().isEmpty()
4914 // if we're asking for math indentation
4915 !mathsModule->MathIndentCB->isChecked() ||
4916 // then either we haven't chosen custom
4917 (mathsModule->MathIndentCO->itemData(
4918 mathsModule->MathIndentCO->currentIndex()) != "custom") ||
4919 // or else a length has been given
4920 !mathsModule->MathIndentLE->text().isEmpty()
4925 char const * const GuiDocument::fontfamilies[5] = {
4926 "default", "rmdefault", "sfdefault", "ttdefault", ""
4930 char const * GuiDocument::fontfamilies_gui[5] = {
4931 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4935 bool GuiDocument::initialiseParams(string const &)
4937 BufferView const * view = bufferview();
4939 bp_ = BufferParams();
4943 prev_buffer_filename_ = view->buffer().absFileName();
4944 bp_ = view->buffer().params();
4946 updateAvailableModules();
4947 //FIXME It'd be nice to make sure here that the selected
4948 //modules are consistent: That required modules are actually
4949 //selected, and that we don't have conflicts. If so, we could
4950 //at least pop up a warning.
4956 void GuiDocument::clearParams()
4958 bp_ = BufferParams();
4962 BufferId GuiDocument::id() const
4964 BufferView const * const view = bufferview();
4965 return view? &view->buffer() : nullptr;
4969 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4971 return moduleNames_;
4975 list<GuiDocument::modInfoStruct> const
4976 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4978 list<modInfoStruct> mInfo;
4979 for (string const & name : mods) {
4981 LyXModule const * const mod = theModuleList[name];
4986 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4988 m.missingreqs = true;
4996 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4998 return makeModuleInfo(params().getModules());
5002 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
5004 return makeModuleInfo(params().baseClass()->providedModules());
5008 DocumentClass const & GuiDocument::documentClass() const
5010 return bp_.documentClass();
5014 static void dispatch_bufferparams(Dialog const & dialog,
5015 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
5018 ss << "\\begin_header\n";
5019 bp.writeFile(ss, buf);
5020 ss << "\\end_header\n";
5021 dialog.dispatch(FuncRequest(lfun, ss.str()));
5025 void GuiDocument::dispatchParams()
5027 // We need a non-const buffer object.
5028 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
5029 // There may be several undo records; group them (bug #8998)
5030 // This handles undo groups automagically
5031 UndoGroupHelper ugh(&buf);
5033 // This must come first so that a language change is correctly noticed
5036 // We need to load the master before we formally update the params,
5037 // since otherwise we run updateBuffer, etc, before the child's master
5039 if (!params().master.empty()) {
5040 FileName const master_file = support::makeAbsPath(params().master,
5041 support::onlyPath(buffer().absFileName()));
5042 if (isLyXFileName(master_file.absFileName())) {
5043 Buffer * master = checkAndLoadLyXFile(master_file, true);
5045 if (master->isChild(const_cast<Buffer *>(&buffer())))
5046 const_cast<Buffer &>(buffer()).setParent(master);
5048 Alert::warning(_("Assigned master does not include this file"),
5049 bformat(_("You must include this file in the document\n"
5050 "'%1$s' in order to use the master document\n"
5051 "feature."), from_utf8(params().master)));
5053 Alert::warning(_("Could not load master"),
5054 bformat(_("The master document '%1$s'\n"
5055 "could not be loaded."),
5056 from_utf8(params().master)));
5060 // Apply the BufferParams. Note that this will set the base class
5061 // and then update the buffer's layout.
5062 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
5064 // Generate the colours requested by each new branch.
5065 BranchList & branchlist = params().branchlist();
5066 if (!branchlist.empty()) {
5067 BranchList::const_iterator it = branchlist.begin();
5068 BranchList::const_iterator const end = branchlist.end();
5069 for (; it != end; ++it) {
5070 docstring const & current_branch = it->branch();
5071 Branch const * branch = branchlist.find(current_branch);
5072 string const bcolor = branch->color();
5074 if (bcolor.size() == 7 && bcolor[0] == '#')
5075 rgbcol = lyx::rgbFromHexName(bcolor);
5077 guiApp->getRgbColor(lcolor.getFromLyXName(bcolor), rgbcol);
5078 string const x11hexname = X11hexname(rgbcol);
5079 // display the new color
5080 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
5081 dispatch(FuncRequest(LFUN_SET_COLOR, str));
5084 // rename branches in the document
5085 executeBranchRenaming();
5086 // and clear changed branches cache
5087 changedBranches_.clear();
5089 // Generate the colours requested by indices.
5090 IndicesList & indiceslist = params().indiceslist();
5091 if (!indiceslist.empty()) {
5092 IndicesList::const_iterator it = indiceslist.begin();
5093 IndicesList::const_iterator const end = indiceslist.end();
5094 for (; it != end; ++it) {
5095 docstring const & current_index = it->shortcut();
5096 Index const * index = indiceslist.findShortcut(current_index);
5097 string const x11hexname = X11hexname(index->color());
5098 // display the new color
5099 docstring const str = current_index + ' ' + from_ascii(x11hexname);
5100 dispatch(FuncRequest(LFUN_SET_COLOR, str));
5104 // If we used an LFUN, we would not need these two lines:
5105 BufferView * bv = const_cast<BufferView *>(bufferview());
5106 bv->processUpdateFlags(Update::Force | Update::FitCursor);
5110 void GuiDocument::setLanguage() const
5112 Language const * const newL = bp_.language;
5113 if (buffer().params().language == newL)
5116 string const & lang_name = newL->lang();
5117 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
5121 void GuiDocument::saveAsDefault() const
5123 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
5127 bool GuiDocument::providesOSF(QString const & font) const
5129 if (fontModule->osFontsCB->isChecked())
5130 // FIXME: we should check if the fonts really
5131 // have OSF support. But how?
5133 return theLaTeXFonts().getLaTeXFont(
5134 qstring_to_ucs4(font)).providesOSF(ot1(),
5140 bool GuiDocument::providesSC(QString const & font) const
5142 if (fontModule->osFontsCB->isChecked())
5144 return theLaTeXFonts().getLaTeXFont(
5145 qstring_to_ucs4(font)).providesSC(ot1(),
5151 bool GuiDocument::providesScale(QString const & font) const
5153 if (fontModule->osFontsCB->isChecked())
5155 return theLaTeXFonts().getLaTeXFont(
5156 qstring_to_ucs4(font)).providesScale(ot1(),
5162 bool GuiDocument::providesExtraOpts(QString const & font) const
5164 if (fontModule->osFontsCB->isChecked())
5166 return theLaTeXFonts().getLaTeXFont(
5167 qstring_to_ucs4(font)).providesMoreOptions(ot1(),
5173 bool GuiDocument::providesNoMath(QString const & font) const
5175 if (fontModule->osFontsCB->isChecked())
5177 return theLaTeXFonts().getLaTeXFont(
5178 qstring_to_ucs4(font)).providesNoMath(ot1(),
5183 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
5185 if (fontModule->osFontsCB->isChecked())
5187 return theLaTeXFonts().getLaTeXFont(
5188 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
5195 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
5197 // FIXME Unicode: docstrings would be better for these parameters but this
5198 // change requires a lot of others
5201 QString const guiname = toqstr(translateIfPossible(from_utf8(mod.getName())));
5202 m.missingreqs = !isModuleAvailable(mod.getID());
5203 if (m.missingreqs) {
5204 m.name = qt_("%1 (missing req.)").arg(guiname);
5207 m.category = mod.category().empty() ? qt_("Miscellaneous")
5208 : toqstr(translateIfPossible(from_utf8(mod.category())));
5209 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
5210 // Find the first sentence of the description
5211 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
5212 int pos = bf.toNextBoundary();
5215 m.local = mod.isLocal();
5216 QString const mtype = m.local ? qt_("personal module") : qt_("distributed module");
5217 QString modulename = qt_("<b>Module name:</b> <i>%1</i> (%2)").arg(toqstr(m.id)).arg(mtype);
5218 // Tooltip is the desc followed by the module name and the type
5219 m.description = QString("%1%2")
5220 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
5223 m.description += QString("<p>%1</p>").arg(qt_("<b>Note:</b> Some requirements for this module are missing!"));
5228 void GuiDocument::loadModuleInfo()
5230 moduleNames_.clear();
5231 for (LyXModule const & mod : theModuleList)
5232 moduleNames_.push_back(modInfo(mod));
5236 void GuiDocument::updateUnknownBranches()
5240 list<docstring> used_branches;
5241 buffer().getUsedBranches(used_branches);
5242 list<docstring>::const_iterator it = used_branches.begin();
5243 QStringList unknown_branches;
5244 for (; it != used_branches.end() ; ++it) {
5245 if (!buffer().params().branchlist().find(*it))
5246 unknown_branches.append(toqstr(*it));
5248 branchesModule->setUnknownBranches(unknown_branches);
5252 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
5254 map<docstring, docstring>::iterator it = changedBranches_.begin();
5255 for (; it != changedBranches_.end() ; ++it) {
5256 if (it->second == oldname) {
5257 // branch has already been renamed
5258 it->second = newname;
5263 changedBranches_[oldname] = newname;
5267 void GuiDocument::executeBranchRenaming() const
5269 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
5270 for (; it != changedBranches_.end() ; ++it) {
5271 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
5272 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
5277 void GuiDocument::allPackagesAuto()
5283 void GuiDocument::allPackagesAlways()
5289 void GuiDocument::allPackagesNot()
5295 void GuiDocument::allPackages(int col)
5297 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
5299 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
5300 rb->setChecked(true);
5305 void GuiDocument::linenoToggled(bool on)
5307 numberingModule->linenoLE->setEnabled(on);
5308 numberingModule->linenoLA->setEnabled(on);
5312 void GuiDocument::outputChangesToggled(bool on)
5314 changesModule->changeBarsCB->setEnabled(on);
5318 void GuiDocument::setOutputSync(bool on)
5320 outputModule->synccustomCB->setEnabled(on);
5321 outputModule->synccustomLA->setEnabled(on);
5326 } // namespace frontend
5329 #include "moc_GuiDocument.cpp"