2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "CategorizedCombo.h"
17 #include "GuiApplication.h"
18 #include "GuiBranches.h"
19 #include "GuiIndices.h"
20 #include "GuiSelectionManager.h"
21 #include "LaTeXHighlighter.h"
22 #include "LengthCombo.h"
23 #include "PanelStack.h"
24 #include "Validator.h"
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "CiteEnginesList.h"
34 #include "ColorCache.h"
35 #include "Converter.h"
38 #include "FloatPlacement.h"
40 #include "FuncRequest.h"
41 #include "IndicesList.h"
43 #include "LaTeXFeatures.h"
44 #include "LaTeXFonts.h"
46 #include "LayoutEnums.h"
47 #include "LayoutModuleList.h"
49 #include "ModuleList.h"
50 #include "OutputParams.h"
51 #include "PDFOptions.h"
52 #include "qt_helpers.h"
55 #include "TextClass.h"
59 #include "insets/InsetListingsParams.h"
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
68 #include "frontends/alert.h"
70 #include <QAbstractItemModel>
71 #include <QButtonGroup>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
76 #include <QHeaderView>
78 #include <QTextBoundaryFinder>
79 #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_;
155 } // anonymous namespace
159 RGBColor set_backgroundcolor;
160 bool is_backgroundcolor;
161 RGBColor set_fontcolor;
163 RGBColor set_notefontcolor;
164 RGBColor set_boxbgcolor;
165 bool forced_fontspec_activation;
168 // used when sorting the textclass list.
169 class less_textclass_avail_desc
170 : public binary_function<string, string, int>
173 bool operator()(string const & lhs, string const & rhs) const
175 // Ordering criteria:
176 // 1. Availability of text class
177 // 2. Description (lexicographic)
178 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
179 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
180 int const order = compare_no_case(
181 translateIfPossible(from_utf8(tc1.description())),
182 translateIfPossible(from_utf8(tc2.description())));
183 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
184 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
193 vector<string> getRequiredList(string const & modName)
195 LyXModule const * const mod = theModuleList[modName];
197 return vector<string>(); //empty such thing
198 return mod->getRequiredModules();
202 vector<string> getExcludedList(string const & modName)
204 LyXModule const * const mod = theModuleList[modName];
206 return vector<string>(); //empty such thing
207 return mod->getExcludedModules();
211 docstring getModuleCategory(string const & modName)
213 LyXModule const * const mod = theModuleList[modName];
216 return from_utf8(mod->category());
220 docstring getModuleDescription(string const & modName)
222 LyXModule const * const mod = theModuleList[modName];
224 return _("Module not found!");
226 return translateIfPossible(from_utf8(mod->getDescription()));
230 vector<string> getPackageList(string const & modName)
232 LyXModule const * const mod = theModuleList[modName];
234 return vector<string>(); //empty such thing
235 return mod->getPackageList();
239 bool isModuleAvailable(string const & modName)
241 LyXModule const * const mod = theModuleList[modName];
244 return mod->isAvailable();
247 } // anonymous namespace
250 /////////////////////////////////////////////////////////////////////
252 // ModuleSelectionManager
254 /////////////////////////////////////////////////////////////////////
256 /// SelectionManager for use with modules
257 class ModuleSelectionManager : public GuiSelectionManager
261 ModuleSelectionManager(QObject * parent,
262 QTreeView * availableLV,
263 QListView * selectedLV,
267 QPushButton * downPB,
268 GuiIdListModel * availableModel,
269 GuiIdListModel * selectedModel,
270 GuiDocument const * container)
271 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
272 upPB, downPB, availableModel, selectedModel),
273 container_(container)
276 void updateProvidedModules(LayoutModuleList const & pm)
277 { provided_modules_ = pm.list(); }
279 void updateExcludedModules(LayoutModuleList const & em)
280 { excluded_modules_ = em.list(); }
283 virtual void updateAddPB();
285 virtual void updateUpPB();
287 virtual void updateDownPB();
289 virtual void updateDelPB();
290 /// returns availableModel as a GuiIdListModel
291 GuiIdListModel * getAvailableModel()
293 return dynamic_cast<GuiIdListModel *>(availableModel);
295 /// returns selectedModel as a GuiIdListModel
296 GuiIdListModel * getSelectedModel()
298 return dynamic_cast<GuiIdListModel *>(selectedModel);
300 /// keeps a list of the modules the text class provides
301 list<string> provided_modules_;
303 list<string> excluded_modules_;
305 GuiDocument const * container_;
308 void ModuleSelectionManager::updateAddPB()
310 int const arows = availableModel->rowCount();
311 QModelIndexList const avail_sels =
312 availableLV->selectionModel()->selectedIndexes();
314 // disable if there aren't any modules (?), if none of them is chosen
315 // in the dialog, or if the chosen one is already selected for use.
316 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
317 addPB->setEnabled(false);
321 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
322 string const modname = getAvailableModel()->getIDString(idx.row());
325 container_->params().layoutModuleCanBeAdded(modname);
326 addPB->setEnabled(enable);
330 void ModuleSelectionManager::updateDownPB()
332 int const srows = selectedModel->rowCount();
334 downPB->setEnabled(false);
337 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
338 int const curRow = curidx.row();
339 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
340 downPB->setEnabled(false);
344 // determine whether immediately succeding element requires this one
345 string const curmodname = getSelectedModel()->getIDString(curRow);
346 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
348 vector<string> reqs = getRequiredList(nextmodname);
350 // if it doesn't require anything....
352 downPB->setEnabled(true);
356 // Enable it if this module isn't required.
357 // FIXME This should perhaps be more flexible and check whether, even
358 // if the next one is required, there is also an earlier one that will do.
360 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
363 void ModuleSelectionManager::updateUpPB()
365 int const srows = selectedModel->rowCount();
367 upPB->setEnabled(false);
371 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
372 int curRow = curIdx.row();
373 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
374 upPB->setEnabled(false);
377 string const curmodname = getSelectedModel()->getIDString(curRow);
379 // determine whether immediately preceding element is required by this one
380 vector<string> reqs = getRequiredList(curmodname);
382 // if this one doesn't require anything....
384 upPB->setEnabled(true);
389 // Enable it if the preceding module isn't required.
390 // NOTE This is less flexible than it might be. We could check whether, even
391 // if the previous one is required, there is an earlier one that would do.
392 string const premod = getSelectedModel()->getIDString(curRow - 1);
393 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
396 void ModuleSelectionManager::updateDelPB()
398 int const srows = selectedModel->rowCount();
400 deletePB->setEnabled(false);
404 QModelIndex const & curidx =
405 selectedLV->selectionModel()->currentIndex();
406 int const curRow = curidx.row();
407 if (curRow < 0 || curRow >= srows) { // invalid index?
408 deletePB->setEnabled(false);
412 string const curmodname = getSelectedModel()->getIDString(curRow);
414 // We're looking here for a reason NOT to enable the button. If we
415 // find one, we disable it and return. If we don't, we'll end up at
416 // the end of the function, and then we enable it.
417 for (int i = curRow + 1; i < srows; ++i) {
418 string const thisMod = getSelectedModel()->getIDString(i);
419 vector<string> reqs = getRequiredList(thisMod);
420 //does this one require us?
421 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
425 // OK, so this module requires us
426 // is there an EARLIER module that also satisfies the require?
427 // NOTE We demand that it be earlier to keep the list of modules
428 // consistent with the rule that a module must be proceeded by a
429 // required module. There would be more flexible ways to proceed,
430 // but that would be a lot more complicated, and the logic here is
431 // already complicated. (That's why I've left the debugging code.)
432 // lyxerr << "Testing " << thisMod << endl;
433 bool foundone = false;
434 for (int j = 0; j < curRow; ++j) {
435 string const mod = getSelectedModel()->getIDString(j);
436 // lyxerr << "In loop: Testing " << mod << endl;
437 // do we satisfy the require?
438 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
439 // lyxerr << mod << " does the trick." << endl;
444 // did we find a module to satisfy the require?
446 // lyxerr << "No matching module found." << endl;
447 deletePB->setEnabled(false);
451 // lyxerr << "All's well that ends well." << endl;
452 deletePB->setEnabled(true);
456 /////////////////////////////////////////////////////////////////////
460 /////////////////////////////////////////////////////////////////////
462 PreambleModule::PreambleModule(QWidget * parent)
463 : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
465 // This is not a memory leak. The object will be destroyed
467 // @ is letter in the LyX user preamble
468 (void) new LaTeXHighlighter(preambleTE->document(), true);
469 preambleTE->setFont(guiApp->typewriterSystemFont());
470 preambleTE->setWordWrapMode(QTextOption::NoWrap);
471 setFocusProxy(preambleTE);
472 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
473 connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
474 connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
475 connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
477 // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
478 const int tabStop = 4;
479 QFontMetrics metrics(preambleTE->currentFont());
480 preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
484 void PreambleModule::checkFindButton()
486 findButtonPB->setEnabled(!findLE->text().isEmpty());
490 void PreambleModule::findText()
492 bool const found = preambleTE->find(findLE->text());
495 QTextCursor qtcur = preambleTE->textCursor();
496 qtcur.movePosition(QTextCursor::Start);
497 preambleTE->setTextCursor(qtcur);
498 preambleTE->find(findLE->text());
503 void PreambleModule::update(BufferParams const & params, BufferId id)
505 QString preamble = toqstr(params.preamble);
506 // Nothing to do if the params and preamble are unchanged.
507 if (id == current_id_
508 && preamble == preambleTE->document()->toPlainText())
511 QTextCursor cur = preambleTE->textCursor();
512 // Save the coords before switching to the new one.
513 preamble_coords_[current_id_] =
514 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
516 // Save the params address for further use.
518 preambleTE->document()->setPlainText(preamble);
519 Coords::const_iterator it = preamble_coords_.find(current_id_);
520 if (it == preamble_coords_.end())
521 // First time we open this one.
522 preamble_coords_[current_id_] = make_pair(0, 0);
524 // Restore saved coords.
525 cur = preambleTE->textCursor();
526 cur.setPosition(it->second.first);
527 preambleTE->setTextCursor(cur);
528 preambleTE->verticalScrollBar()->setValue(it->second.second);
533 void PreambleModule::apply(BufferParams & params)
535 params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
539 void PreambleModule::closeEvent(QCloseEvent * e)
541 // Save the coords before closing.
542 QTextCursor cur = preambleTE->textCursor();
543 preamble_coords_[current_id_] =
544 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
549 /////////////////////////////////////////////////////////////////////
553 /////////////////////////////////////////////////////////////////////
556 LocalLayout::LocalLayout(QWidget * parent)
557 : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
559 locallayoutTE->setFont(guiApp->typewriterSystemFont());
560 locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
561 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
562 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
563 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
567 void LocalLayout::update(BufferParams const & params, BufferId id)
569 QString layout = toqstr(params.getLocalLayout(false));
570 // Nothing to do if the params and preamble are unchanged.
571 if (id == current_id_
572 && layout == locallayoutTE->document()->toPlainText())
575 // Save the params address for further use.
577 locallayoutTE->document()->setPlainText(layout);
582 void LocalLayout::apply(BufferParams & params)
584 docstring const layout =
585 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
586 params.setLocalLayout(layout, false);
590 void LocalLayout::hideConvert()
592 convertPB->setEnabled(false);
593 convertLB->setText("");
599 void LocalLayout::textChanged()
601 static const QString message =
602 qt_("Press button to check validity...");
603 string const layout =
604 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
606 if (layout.empty()) {
608 validatePB->setEnabled(false);
609 validLB->setText("");
612 } else if (!validatePB->isEnabled()) {
613 // if that's already enabled, we shouldn't need to do anything.
615 validLB->setText(message);
616 validatePB->setEnabled(true);
623 void LocalLayout::convert() {
624 string const layout =
625 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
626 string const newlayout = TextClass::convert(layout);
627 if (!newlayout.empty())
628 locallayoutTE->setPlainText(toqstr(newlayout));
633 void LocalLayout::convertPressed() {
640 void LocalLayout::validate() {
642 static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
643 // Flashy red bold text
644 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
646 string const layout =
647 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
648 if (!layout.empty()) {
649 TextClass::ReturnValues const ret = TextClass::validate(layout);
650 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
651 validatePB->setEnabled(false);
652 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
653 : ivpar.arg(qt_("Layout is invalid!")));
654 if (ret == TextClass::OK_OLDFORMAT) {
656 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
658 if (TextClass::convert(layout).empty()) {
659 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
660 // then maybe the layout is still valid, but its format is more
661 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
662 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
663 convertPB->setEnabled(false);
664 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
665 ? ivpar.arg(qt_("Conversion to current format impossible!"))
666 : vpar.arg(qt_("Conversion to current stable format "
668 convertLB->setText(text);
670 convertPB->setEnabled(true);
671 convertLB->setText(qt_("Convert to current format"));
682 void LocalLayout::validatePressed() {
688 /////////////////////////////////////////////////////////////////////
692 /////////////////////////////////////////////////////////////////////
695 GuiDocument::GuiDocument(GuiView & lv)
696 : GuiDialog(lv, "document", qt_("Document Settings")),
697 biblioChanged_(false), nonModuleChanged_(false),
698 modulesChanged_(false), shellescapeChanged_(false)
702 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
703 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
704 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
705 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
707 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
708 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
710 // Manage the restore, ok, apply, restore and cancel/close buttons
711 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
713 bc().setApply(applyPB);
714 bc().setCancel(closePB);
715 bc().setRestore(restorePB);
719 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
720 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
721 this, SLOT(change_adaptor()));
722 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
723 this, SLOT(setLSpacing(int)));
724 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
725 this, SLOT(change_adaptor()));
727 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
728 this, SLOT(change_adaptor()));
729 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
730 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
731 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
732 this, SLOT(change_adaptor()));
733 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
734 this, SLOT(setIndent(int)));
735 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
736 this, SLOT(change_adaptor()));
737 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
738 this, SLOT(change_adaptor()));
740 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
741 this, SLOT(change_adaptor()));
742 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
743 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
744 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
745 this, SLOT(change_adaptor()));
746 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
747 this, SLOT(setSkip(int)));
748 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
749 this, SLOT(change_adaptor()));
750 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
751 this, SLOT(change_adaptor()));
753 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
754 this, SLOT(enableIndent(bool)));
755 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
756 this, SLOT(enableSkip(bool)));
758 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
759 this, SLOT(change_adaptor()));
760 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
761 this, SLOT(setColSep()));
762 connect(textLayoutModule->justCB, SIGNAL(clicked()),
763 this, SLOT(change_adaptor()));
765 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
766 textLayoutModule->lspacingLE));
767 textLayoutModule->indentLE->setValidator(new LengthValidator(
768 textLayoutModule->indentLE));
769 textLayoutModule->skipLE->setValidator(new LengthValidator(
770 textLayoutModule->skipLE));
772 textLayoutModule->indentCO->addItem(qt_("Default"));
773 textLayoutModule->indentCO->addItem(qt_("Custom"));
774 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
775 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
776 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
777 textLayoutModule->skipCO->addItem(qt_("Custom"));
778 textLayoutModule->lspacingCO->insertItem(
779 Spacing::Single, qt_("Single"));
780 textLayoutModule->lspacingCO->insertItem(
781 Spacing::Onehalf, qt_("OneHalf"));
782 textLayoutModule->lspacingCO->insertItem(
783 Spacing::Double, qt_("Double"));
784 textLayoutModule->lspacingCO->insertItem(
785 Spacing::Other, qt_("Custom"));
786 // initialize the length validator
787 bc().addCheckedLineEdit(textLayoutModule->indentLE);
788 bc().addCheckedLineEdit(textLayoutModule->skipLE);
791 // master/child handling
792 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
794 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
795 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
796 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
797 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
798 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
799 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
800 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
801 this, SLOT(change_adaptor()));
802 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
803 this, SLOT(change_adaptor()));
804 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
805 this, SLOT(change_adaptor()));
806 masterChildModule->childrenTW->setColumnCount(2);
807 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
808 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
809 masterChildModule->childrenTW->resizeColumnToContents(1);
810 masterChildModule->childrenTW->resizeColumnToContents(2);
814 outputModule = new UiWidget<Ui::OutputUi>(this);
816 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
817 this, SLOT(change_adaptor()));
818 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
819 this, SLOT(change_adaptor()));
820 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
821 this, SLOT(change_adaptor()));
822 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
823 this, SLOT(change_adaptor()));
824 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
825 this, SLOT(change_adaptor()));
827 connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
828 this, SLOT(shellescapeChanged()));
829 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
830 this, SLOT(change_adaptor()));
831 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
832 this, SLOT(change_adaptor()));
833 outputModule->synccustomCB->addItem("");
834 outputModule->synccustomCB->addItem("\\synctex=1");
835 outputModule->synccustomCB->addItem("\\synctex=-1");
836 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
838 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
839 outputModule->synccustomCB));
841 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
842 this, SLOT(change_adaptor()));
846 // this must preceed font, since fonts depend on this
847 langModule = new UiWidget<Ui::LanguageUi>(this);
848 connect(langModule->languageCO, SIGNAL(activated(int)),
849 this, SLOT(change_adaptor()));
850 connect(langModule->languageCO, SIGNAL(activated(int)),
851 this, SLOT(languageChanged(int)));
852 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
853 this, SLOT(change_adaptor()));
854 connect(langModule->otherencodingRB, SIGNAL(clicked()),
855 this, SLOT(change_adaptor()));
856 connect(langModule->encodingCO, SIGNAL(activated(int)),
857 this, SLOT(change_adaptor()));
858 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
859 this, SLOT(change_adaptor()));
860 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
861 this, SLOT(change_adaptor()));
862 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
863 this, SLOT(change_adaptor()));
864 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
865 this, SLOT(languagePackageChanged(int)));
866 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
867 this, SLOT(change_adaptor()));
869 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
870 langModule->languagePackageLE));
872 QAbstractItemModel * language_model = guiApp->languageModel();
873 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
874 language_model->sort(0);
875 langModule->languageCO->setModel(language_model);
876 langModule->languageCO->setModelColumn(0);
878 // Always put the default encoding in the first position.
879 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
880 QStringList encodinglist;
881 for (auto const & encvar : encodings) {
882 if (!encvar.unsafe() && !encvar.guiName().empty())
883 encodinglist.append(qt_(encvar.guiName()));
886 langModule->encodingCO->addItems(encodinglist);
888 langModule->languagePackageCO->addItem(
889 qt_("Default"), toqstr("default"));
890 langModule->languagePackageCO->addItem(
891 qt_("Automatic"), toqstr("auto"));
892 langModule->languagePackageCO->addItem(
893 qt_("Always Babel"), toqstr("babel"));
894 langModule->languagePackageCO->addItem(
895 qt_("Custom"), toqstr("custom"));
896 langModule->languagePackageCO->addItem(
897 qt_("None[[language package]]"), toqstr("none"));
901 fontModule = new FontModule(this);
902 connect(fontModule->osFontsCB, SIGNAL(clicked()),
903 this, SLOT(change_adaptor()));
904 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
905 this, SLOT(osFontsChanged(bool)));
906 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
907 this, SLOT(change_adaptor()));
908 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
909 this, SLOT(romanChanged(int)));
910 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
911 this, SLOT(change_adaptor()));
912 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
913 this, SLOT(sansChanged(int)));
914 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
915 this, SLOT(change_adaptor()));
916 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
917 this, SLOT(ttChanged(int)));
918 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
919 this, SLOT(change_adaptor()));
920 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
921 this, SLOT(mathFontChanged(int)));
922 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
923 this, SLOT(change_adaptor()));
924 connect(fontModule->fontencCO, SIGNAL(activated(int)),
925 this, SLOT(change_adaptor()));
926 connect(fontModule->fontencCO, SIGNAL(activated(int)),
927 this, SLOT(fontencChanged(int)));
928 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
929 this, SLOT(change_adaptor()));
930 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
931 this, SLOT(change_adaptor()));
932 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
933 this, SLOT(change_adaptor()));
934 connect(fontModule->microtypeCB, SIGNAL(clicked()),
935 this, SLOT(change_adaptor()));
936 connect(fontModule->dashesCB, SIGNAL(clicked()),
937 this, SLOT(change_adaptor()));
938 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
939 this, SLOT(change_adaptor()));
940 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
941 this, SLOT(change_adaptor()));
942 connect(fontModule->fontScCB, SIGNAL(clicked()),
943 this, SLOT(change_adaptor()));
944 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
945 this, SLOT(fontScToggled(bool)));
946 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
947 this, SLOT(change_adaptor()));
948 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
949 this, SLOT(fontOsfToggled(bool)));
951 fontModule->fontencLE->setValidator(new NoNewLineValidator(
952 fontModule->fontencLE));
953 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
954 fontModule->cjkFontLE));
958 fontModule->fontsizeCO->addItem(qt_("Default"));
959 fontModule->fontsizeCO->addItem(qt_("10"));
960 fontModule->fontsizeCO->addItem(qt_("11"));
961 fontModule->fontsizeCO->addItem(qt_("12"));
963 fontModule->fontencCO->addItem(qt_("Automatic"), QString("auto"));
964 fontModule->fontencCO->addItem(qt_("Class Default"), QString("default"));
965 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
967 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
968 fontModule->fontsDefaultCO->addItem(
969 qt_(GuiDocument::fontfamilies_gui[n]));
971 if (!LaTeXFeatures::isAvailable("fontspec"))
972 fontModule->osFontsCB->setToolTip(
973 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
974 "You need to install the package \"fontspec\" to use this feature"));
978 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
979 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
980 this, SLOT(papersizeChanged(int)));
981 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
982 this, SLOT(papersizeChanged(int)));
983 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
984 this, SLOT(change_adaptor()));
985 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
986 this, SLOT(change_adaptor()));
987 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
988 this, SLOT(change_adaptor()));
989 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
990 this, SLOT(change_adaptor()));
991 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
992 this, SLOT(change_adaptor()));
993 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
994 this, SLOT(change_adaptor()));
995 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
996 this, SLOT(change_adaptor()));
997 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
998 this, SLOT(change_adaptor()));
999 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
1000 this, SLOT(change_adaptor()));
1001 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
1002 this, SLOT(change_adaptor()));
1004 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1005 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
1006 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
1007 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
1008 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
1009 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
1010 pageLayoutModule->paperheightL);
1011 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
1012 pageLayoutModule->paperwidthL);
1014 QComboBox * cb = pageLayoutModule->papersizeCO;
1015 cb->addItem(qt_("Default"));
1016 cb->addItem(qt_("Custom"));
1017 cb->addItem(qt_("US letter"));
1018 cb->addItem(qt_("US legal"));
1019 cb->addItem(qt_("US executive"));
1020 cb->addItem(qt_("A0"));
1021 cb->addItem(qt_("A1"));
1022 cb->addItem(qt_("A2"));
1023 cb->addItem(qt_("A3"));
1024 cb->addItem(qt_("A4"));
1025 cb->addItem(qt_("A5"));
1026 cb->addItem(qt_("A6"));
1027 cb->addItem(qt_("B0"));
1028 cb->addItem(qt_("B1"));
1029 cb->addItem(qt_("B2"));
1030 cb->addItem(qt_("B3"));
1031 cb->addItem(qt_("B4"));
1032 cb->addItem(qt_("B5"));
1033 cb->addItem(qt_("B6"));
1034 cb->addItem(qt_("C0"));
1035 cb->addItem(qt_("C1"));
1036 cb->addItem(qt_("C2"));
1037 cb->addItem(qt_("C3"));
1038 cb->addItem(qt_("C4"));
1039 cb->addItem(qt_("C5"));
1040 cb->addItem(qt_("C6"));
1041 cb->addItem(qt_("JIS B0"));
1042 cb->addItem(qt_("JIS B1"));
1043 cb->addItem(qt_("JIS B2"));
1044 cb->addItem(qt_("JIS B3"));
1045 cb->addItem(qt_("JIS B4"));
1046 cb->addItem(qt_("JIS B5"));
1047 cb->addItem(qt_("JIS B6"));
1048 // remove the %-items from the unit choice
1049 pageLayoutModule->paperwidthUnitCO->noPercents();
1050 pageLayoutModule->paperheightUnitCO->noPercents();
1051 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
1052 pageLayoutModule->paperheightLE));
1053 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
1054 pageLayoutModule->paperwidthLE));
1058 marginsModule = new UiWidget<Ui::MarginsUi>(this);
1059 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1060 this, SLOT(setCustomMargins(bool)));
1061 connect(marginsModule->marginCB, SIGNAL(clicked()),
1062 this, SLOT(change_adaptor()));
1063 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1064 this, SLOT(change_adaptor()));
1065 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1066 this, SLOT(change_adaptor()));
1067 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1068 this, SLOT(change_adaptor()));
1069 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1070 this, SLOT(change_adaptor()));
1071 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1072 this, SLOT(change_adaptor()));
1073 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1074 this, SLOT(change_adaptor()));
1075 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1076 this, SLOT(change_adaptor()));
1077 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1078 this, SLOT(change_adaptor()));
1079 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1080 this, SLOT(change_adaptor()));
1081 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1082 this, SLOT(change_adaptor()));
1083 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1084 this, SLOT(change_adaptor()));
1085 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1086 this, SLOT(change_adaptor()));
1087 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1088 this, SLOT(change_adaptor()));
1089 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1090 this, SLOT(change_adaptor()));
1091 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1092 this, SLOT(change_adaptor()));
1093 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1094 this, SLOT(change_adaptor()));
1095 marginsModule->topLE->setValidator(new LengthValidator(
1096 marginsModule->topLE));
1097 marginsModule->bottomLE->setValidator(new LengthValidator(
1098 marginsModule->bottomLE));
1099 marginsModule->innerLE->setValidator(new LengthValidator(
1100 marginsModule->innerLE));
1101 marginsModule->outerLE->setValidator(new LengthValidator(
1102 marginsModule->outerLE));
1103 marginsModule->headsepLE->setValidator(new LengthValidator(
1104 marginsModule->headsepLE));
1105 marginsModule->headheightLE->setValidator(new LengthValidator(
1106 marginsModule->headheightLE));
1107 marginsModule->footskipLE->setValidator(new LengthValidator(
1108 marginsModule->footskipLE));
1109 marginsModule->columnsepLE->setValidator(new LengthValidator(
1110 marginsModule->columnsepLE));
1112 bc().addCheckedLineEdit(marginsModule->topLE,
1113 marginsModule->topL);
1114 bc().addCheckedLineEdit(marginsModule->bottomLE,
1115 marginsModule->bottomL);
1116 bc().addCheckedLineEdit(marginsModule->innerLE,
1117 marginsModule->innerL);
1118 bc().addCheckedLineEdit(marginsModule->outerLE,
1119 marginsModule->outerL);
1120 bc().addCheckedLineEdit(marginsModule->headsepLE,
1121 marginsModule->headsepL);
1122 bc().addCheckedLineEdit(marginsModule->headheightLE,
1123 marginsModule->headheightL);
1124 bc().addCheckedLineEdit(marginsModule->footskipLE,
1125 marginsModule->footskipL);
1126 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1127 marginsModule->columnsepL);
1131 colorModule = new UiWidget<Ui::ColorUi>(this);
1132 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1133 this, SLOT(changeFontColor()));
1134 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1135 this, SLOT(deleteFontColor()));
1136 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1137 this, SLOT(changeNoteFontColor()));
1138 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1139 this, SLOT(deleteNoteFontColor()));
1140 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1141 this, SLOT(changeBackgroundColor()));
1142 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1143 this, SLOT(deleteBackgroundColor()));
1144 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1145 this, SLOT(changeBoxBackgroundColor()));
1146 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1147 this, SLOT(deleteBoxBackgroundColor()));
1151 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1152 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1153 this, SLOT(change_adaptor()));
1154 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1155 this, SLOT(change_adaptor()));
1156 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1157 this, SLOT(updateNumbering()));
1158 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1159 this, SLOT(updateNumbering()));
1160 numberingModule->tocTW->setColumnCount(3);
1161 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1162 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1163 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1164 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1167 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1168 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1169 this, SLOT(citeEngineChanged(int)));
1170 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1171 this, SLOT(citeStyleChanged()));
1172 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1173 this, SLOT(biblioChanged()));
1174 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1175 this, SLOT(biblioChanged()));
1176 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1177 this, SLOT(bibtexChanged(int)));
1178 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1179 this, SLOT(biblioChanged()));
1180 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1181 this, SLOT(biblioChanged()));
1182 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1183 this, SLOT(biblioChanged()));
1184 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1185 this, SLOT(biblioChanged()));
1186 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1187 this, SLOT(updateResetDefaultBiblio()));
1188 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1189 this, SLOT(biblioChanged()));
1190 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1191 this, SLOT(biblioChanged()));
1192 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1193 this, SLOT(updateResetDefaultBiblio()));
1194 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1195 this, SLOT(biblioChanged()));
1196 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1197 this, SLOT(biblioChanged()));
1198 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1199 this, SLOT(updateResetDefaultBiblio()));
1200 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1201 this, SLOT(rescanBibFiles()));
1202 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1203 this, SLOT(resetDefaultBibfile()));
1204 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1205 this, SLOT(resetDefaultCbxBibfile()));
1206 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1207 this, SLOT(resetDefaultBbxBibfile()));
1208 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1209 this, SLOT(matchBiblatexStyles()));
1211 biblioModule->citeEngineCO->clear();
1212 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1213 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1214 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1215 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1219 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1220 biblioModule->bibtexOptionsLE));
1221 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1222 biblioModule->defaultBiblioCO->lineEdit()));
1223 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1224 biblioModule->citePackageOptionsLE));
1226 // NOTE: we do not provide "custom" here for security reasons!
1227 biblioModule->bibtexCO->clear();
1228 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1229 for (auto const & alts : lyxrc.bibtex_alternatives) {
1230 QString const command = toqstr(alts).left(toqstr(alts).indexOf(" "));
1231 biblioModule->bibtexCO->addItem(command, command);
1236 indicesModule = new GuiIndices;
1237 connect(indicesModule, SIGNAL(changed()),
1238 this, SLOT(change_adaptor()));
1242 mathsModule = new UiWidget<Ui::MathsUi>(this);
1243 QStringList headers;
1244 headers << qt_("Package") << qt_("Load automatically")
1245 << qt_("Load always") << qt_("Do not load");
1246 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1247 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1248 map<string, string> const & packages = BufferParams::auto_packages();
1249 mathsModule->packagesTW->setRowCount(packages.size());
1251 for (auto const & pkgvar : packages) {
1252 docstring const package = from_ascii(pkgvar.first);
1253 QString autoTooltip = qt_(pkgvar.second);
1254 QString alwaysTooltip;
1255 if (package == "amsmath")
1257 qt_("The AMS LaTeX packages are always used");
1259 alwaysTooltip = toqstr(bformat(
1260 _("The LaTeX package %1$s is always used"),
1262 QString neverTooltip;
1263 if (package == "amsmath")
1265 qt_("The AMS LaTeX packages are never used");
1267 neverTooltip = toqstr(bformat(
1268 _("The LaTeX package %1$s is never used"),
1270 QRadioButton * autoRB = new QRadioButton(mathsModule);
1271 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1272 QRadioButton * neverRB = new QRadioButton(mathsModule);
1273 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1274 packageGroup->addButton(autoRB);
1275 packageGroup->addButton(alwaysRB);
1276 packageGroup->addButton(neverRB);
1277 autoRB->setToolTip(autoTooltip);
1278 alwaysRB->setToolTip(alwaysTooltip);
1279 neverRB->setToolTip(neverTooltip);
1281 // Pack the buttons in a layout in order to get proper alignment
1282 QWidget * autoRBWidget = new QWidget();
1283 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1284 autoRBLayout->addWidget(autoRB);
1285 autoRBLayout->setAlignment(Qt::AlignCenter);
1286 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1287 autoRBWidget->setLayout(autoRBLayout);
1289 QWidget * alwaysRBWidget = new QWidget();
1290 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1291 alwaysRBLayout->addWidget(alwaysRB);
1292 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1293 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1294 alwaysRBWidget->setLayout(alwaysRBLayout);
1296 QWidget * neverRBWidget = new QWidget();
1297 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1298 neverRBLayout->addWidget(neverRB);
1299 neverRBLayout->setAlignment(Qt::AlignCenter);
1300 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1301 neverRBWidget->setLayout(neverRBLayout);
1303 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1304 mathsModule->packagesTW->setItem(packnum, 0, pack);
1305 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1306 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1307 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1309 connect(autoRB, SIGNAL(clicked()),
1310 this, SLOT(change_adaptor()));
1311 connect(alwaysRB, SIGNAL(clicked()),
1312 this, SLOT(change_adaptor()));
1313 connect(neverRB, SIGNAL(clicked()),
1314 this, SLOT(change_adaptor()));
1317 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1318 this, SLOT(allPackagesAuto()));
1319 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1320 this, SLOT(allPackagesAlways()));
1321 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1322 this, SLOT(allPackagesNot()));
1323 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1324 this, SLOT(change_adaptor()));
1325 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1326 this, SLOT(change_adaptor()));
1327 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1328 this, SLOT(change_adaptor()));
1329 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1330 this, SLOT(change_adaptor()));
1332 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1333 this, SLOT(change_adaptor()));
1334 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1335 this, SLOT(allowMathIndent()));
1336 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1337 this, SLOT(change_adaptor()));
1338 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1339 this, SLOT(enableMathIndent(int)));
1340 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1341 this, SLOT(change_adaptor()));
1342 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1343 this, SLOT(change_adaptor()));
1346 mathsModule->MathIndentCO->addItem(qt_("Default"));
1347 mathsModule->MathIndentCO->addItem(qt_("Custom"));
1348 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1349 mathsModule->MathIndentLE));
1350 // initialize the length validator
1351 bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1352 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1353 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1354 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1355 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1359 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1360 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1361 this, SLOT(change_adaptor()));
1362 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1363 this, SLOT(change_adaptor()));
1364 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1365 this, SLOT(change_adaptor()));
1366 connect(latexModule->classCO, SIGNAL(activated(int)),
1367 this, SLOT(classChanged_adaptor()));
1368 connect(latexModule->classCO, SIGNAL(activated(int)),
1369 this, SLOT(change_adaptor()));
1370 connect(latexModule->layoutPB, SIGNAL(clicked()),
1371 this, SLOT(browseLayout()));
1372 connect(latexModule->layoutPB, SIGNAL(clicked()),
1373 this, SLOT(change_adaptor()));
1374 connect(latexModule->childDocGB, SIGNAL(clicked()),
1375 this, SLOT(change_adaptor()));
1376 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1377 this, SLOT(change_adaptor()));
1378 connect(latexModule->childDocPB, SIGNAL(clicked()),
1379 this, SLOT(browseMaster()));
1380 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1381 this, SLOT(change_adaptor()));
1382 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1383 this, SLOT(change_adaptor()));
1385 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1386 latexModule->optionsLE));
1387 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1388 latexModule->childDocLE));
1390 // postscript drivers
1391 for (int n = 0; tex_graphics[n][0]; ++n) {
1392 QString enc = qt_(tex_graphics_gui[n]);
1393 latexModule->psdriverCO->addItem(enc);
1396 LayoutFileList const & bcl = LayoutFileList::get();
1397 vector<LayoutFileIndex> classList = bcl.classList();
1398 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1400 for (auto const & cvar : classList) {
1401 LayoutFile const & tc = bcl[cvar];
1402 bool const available = tc.isTeXClassAvailable();
1403 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1404 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1405 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1407 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1408 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1409 "Please check if you have the matching %1$s class "
1410 "and all required packages (%2$s) installed."),
1411 output_type, from_utf8(tc.prerequisites(", "))));
1413 latexModule->classCO->addItemSort(toqstr(tc.name()),
1415 toqstr(translateIfPossible(from_utf8(tc.category()))),
1417 true, true, true, available);
1422 branchesModule = new GuiBranches(this);
1423 connect(branchesModule, SIGNAL(changed()),
1424 this, SLOT(change_adaptor()));
1425 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1426 this, SLOT(branchesRename(docstring const &, docstring const &)));
1427 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1428 updateUnknownBranches();
1432 preambleModule = new PreambleModule(this);
1433 connect(preambleModule, SIGNAL(changed()),
1434 this, SLOT(change_adaptor()));
1436 localLayout = new LocalLayout(this);
1437 connect(localLayout, SIGNAL(changed()),
1438 this, SLOT(change_adaptor()));
1442 bulletsModule = new BulletsModule(this);
1443 connect(bulletsModule, SIGNAL(changed()),
1444 this, SLOT(change_adaptor()));
1448 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1449 modulesModule->availableLV->header()->setVisible(false);
1450 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1451 modulesModule->availableLV->header()->setStretchLastSection(false);
1453 new ModuleSelectionManager(this, modulesModule->availableLV,
1454 modulesModule->selectedLV,
1455 modulesModule->addPB,
1456 modulesModule->deletePB,
1457 modulesModule->upPB,
1458 modulesModule->downPB,
1459 availableModel(), selectedModel(), this);
1460 connect(selectionManager, SIGNAL(updateHook()),
1461 this, SLOT(updateModuleInfo()));
1462 connect(selectionManager, SIGNAL(selectionChanged()),
1463 this, SLOT(modulesChanged()));
1467 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1468 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1469 this, SLOT(change_adaptor()));
1470 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1471 this, SLOT(change_adaptor()));
1472 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1473 this, SLOT(change_adaptor()));
1474 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1475 this, SLOT(change_adaptor()));
1476 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1477 this, SLOT(change_adaptor()));
1478 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1479 this, SLOT(change_adaptor()));
1480 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1481 this, SLOT(change_adaptor()));
1482 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1483 this, SLOT(change_adaptor()));
1484 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1485 this, SLOT(change_adaptor()));
1486 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1487 this, SLOT(change_adaptor()));
1488 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1489 this, SLOT(change_adaptor()));
1490 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1491 this, SLOT(change_adaptor()));
1492 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1493 this, SLOT(change_adaptor()));
1494 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1495 this, SLOT(change_adaptor()));
1496 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1497 this, SLOT(change_adaptor()));
1498 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1499 this, SLOT(change_adaptor()));
1501 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1502 pdfSupportModule->titleLE));
1503 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1504 pdfSupportModule->authorLE));
1505 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1506 pdfSupportModule->subjectLE));
1507 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1508 pdfSupportModule->keywordsLE));
1509 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1510 pdfSupportModule->optionsLE));
1512 for (int i = 0; backref_opts[i][0]; ++i)
1513 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1517 floatModule = new FloatPlacement;
1518 connect(floatModule, SIGNAL(changed()),
1519 this, SLOT(change_adaptor()));
1523 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1524 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1525 this, SLOT(change_adaptor()));
1526 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1527 this, SLOT(change_adaptor()));
1528 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1529 this, SLOT(setListingsMessage()));
1530 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1531 this, SLOT(change_adaptor()));
1532 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1533 this, SLOT(listingsPackageChanged(int)));
1534 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1535 this, SLOT(setListingsMessage()));
1536 listingsModule->listingsTB->setPlainText(
1537 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1539 for (int i = 0; lst_packages[i][0]; ++i)
1540 listingsModule->packageCO->addItem(lst_packages[i]);
1544 docPS->addPanel(latexModule, N_("Document Class"));
1545 docPS->addPanel(masterChildModule, N_("Child Documents"));
1546 docPS->addPanel(modulesModule, N_("Modules"));
1547 docPS->addPanel(localLayout, N_("Local Layout"));
1548 docPS->addPanel(fontModule, N_("Fonts"));
1549 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1550 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1551 docPS->addPanel(marginsModule, N_("Page Margins"));
1552 docPS->addPanel(langModule, N_("Language"));
1553 docPS->addPanel(colorModule, N_("Colors"));
1554 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1555 docPS->addPanel(biblioModule, N_("Bibliography"));
1556 docPS->addPanel(indicesModule, N_("Indexes"));
1557 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1558 docPS->addPanel(mathsModule, N_("Math Options"));
1559 docPS->addPanel(floatModule, N_("Float Settings"));
1560 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1561 docPS->addPanel(bulletsModule, N_("Bullets"));
1562 docPS->addPanel(branchesModule, N_("Branches"));
1563 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1564 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1565 docPS->setCurrentPanel("Document Class");
1566 // FIXME: hack to work around resizing bug in Qt >= 4.2
1567 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1568 #if QT_VERSION >= 0x040200
1569 docPS->updateGeometry();
1574 void GuiDocument::onBufferViewChanged()
1576 if (isVisibleView())
1577 initialiseParams("");
1581 void GuiDocument::saveDefaultClicked()
1587 void GuiDocument::useDefaultsClicked()
1593 void GuiDocument::change_adaptor()
1595 nonModuleChanged_ = true;
1600 void GuiDocument::shellescapeChanged()
1602 shellescapeChanged_ = true;
1607 void GuiDocument::slotApply()
1609 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1610 bool wasclean = buffer().isClean();
1611 GuiDialog::slotApply();
1612 if (wasclean && only_shellescape_changed)
1613 buffer().markClean();
1614 modulesChanged_ = false;
1618 void GuiDocument::slotOK()
1620 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1621 bool wasclean = buffer().isClean();
1622 GuiDialog::slotOK();
1623 if (wasclean && only_shellescape_changed)
1624 buffer().markClean();
1625 modulesChanged_ = false;
1629 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1634 string child = fromqstr(item->text(0));
1638 if (std::find(includeonlys_.begin(),
1639 includeonlys_.end(), child) != includeonlys_.end())
1640 includeonlys_.remove(child);
1642 includeonlys_.push_back(child);
1644 updateIncludeonlys();
1649 QString GuiDocument::validateListingsParameters()
1651 if (listingsModule->bypassCB->isChecked())
1653 string const package =
1654 lst_packages[listingsModule->packageCO->currentIndex()];
1655 string params = fromqstr(listingsModule->listingsED->toPlainText());
1656 InsetListingsParams lstparams(params);
1657 lstparams.setMinted(package == "Minted");
1658 return toqstr(lstparams.validate());
1662 void GuiDocument::setListingsMessage()
1665 static bool isOK = true;
1666 QString msg = validateListingsParameters();
1667 if (msg.isEmpty()) {
1671 // listingsTB->setTextColor("black");
1672 listingsModule->listingsTB->setPlainText(
1673 qt_("Input listings parameters below. "
1674 "Enter ? for a list of parameters."));
1677 // listingsTB->setTextColor("red");
1678 listingsModule->listingsTB->setPlainText(msg);
1683 void GuiDocument::listingsPackageChanged(int index)
1685 string const package = lst_packages[index];
1686 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1687 Alert::warning(_("Pygments driver command not found!"),
1688 _("The driver command necessary to use the minted package\n"
1689 "(pygmentize) has not been found. Make sure you have\n"
1690 "the python-pygments module installed or, if the driver\n"
1691 "is named differently, to add the following line to the\n"
1692 "document preamble:\n\n"
1693 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1694 "where 'driver' is name of the driver command."));
1699 void GuiDocument::setLSpacing(int item)
1701 textLayoutModule->lspacingLE->setEnabled(item == 3);
1705 void GuiDocument::setIndent(int item)
1707 bool const enable = (item == 1);
1708 textLayoutModule->indentLE->setEnabled(enable);
1709 textLayoutModule->indentLengthCO->setEnabled(enable);
1710 textLayoutModule->skipLE->setEnabled(false);
1711 textLayoutModule->skipLengthCO->setEnabled(false);
1716 void GuiDocument::enableIndent(bool indent)
1718 textLayoutModule->skipLE->setEnabled(!indent);
1719 textLayoutModule->skipLengthCO->setEnabled(!indent);
1721 setIndent(textLayoutModule->indentCO->currentIndex());
1725 void GuiDocument::setSkip(int item)
1727 bool const enable = (item == 3);
1728 textLayoutModule->skipLE->setEnabled(enable);
1729 textLayoutModule->skipLengthCO->setEnabled(enable);
1734 void GuiDocument::enableSkip(bool skip)
1736 textLayoutModule->indentLE->setEnabled(!skip);
1737 textLayoutModule->indentLengthCO->setEnabled(!skip);
1739 setSkip(textLayoutModule->skipCO->currentIndex());
1742 void GuiDocument::allowMathIndent() {
1743 // only disable when not checked, checked does not always allow enabling
1744 if (!mathsModule->MathIndentCB->isChecked()) {
1745 mathsModule->MathIndentLE->setEnabled(false);
1746 mathsModule->MathIndentLengthCO->setEnabled(false);
1748 if (mathsModule->MathIndentCB->isChecked()
1749 && mathsModule->MathIndentCO->currentIndex() == 1) {
1750 mathsModule->MathIndentLE->setEnabled(true);
1751 mathsModule->MathIndentLengthCO->setEnabled(true);
1756 void GuiDocument::enableMathIndent(int item)
1758 bool const enable = (item == 1);
1759 mathsModule->MathIndentLE->setEnabled(enable);
1760 mathsModule->MathIndentLengthCO->setEnabled(enable);
1765 void GuiDocument::setMargins()
1767 bool const extern_geometry =
1768 documentClass().provides("geometry");
1769 marginsModule->marginCB->setEnabled(!extern_geometry);
1770 if (extern_geometry) {
1771 marginsModule->marginCB->setChecked(false);
1772 setCustomMargins(true);
1774 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1775 setCustomMargins(!bp_.use_geometry);
1780 void GuiDocument::papersizeChanged(int paper_size)
1782 setCustomPapersize(paper_size == 1);
1786 void GuiDocument::setCustomPapersize(bool custom)
1788 pageLayoutModule->paperwidthL->setEnabled(custom);
1789 pageLayoutModule->paperwidthLE->setEnabled(custom);
1790 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1791 pageLayoutModule->paperheightL->setEnabled(custom);
1792 pageLayoutModule->paperheightLE->setEnabled(custom);
1793 pageLayoutModule->paperheightLE->setFocus();
1794 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1798 void GuiDocument::setColSep()
1800 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1804 void GuiDocument::setCustomMargins(bool custom)
1806 marginsModule->topL->setEnabled(!custom);
1807 marginsModule->topLE->setEnabled(!custom);
1808 marginsModule->topUnit->setEnabled(!custom);
1810 marginsModule->bottomL->setEnabled(!custom);
1811 marginsModule->bottomLE->setEnabled(!custom);
1812 marginsModule->bottomUnit->setEnabled(!custom);
1814 marginsModule->innerL->setEnabled(!custom);
1815 marginsModule->innerLE->setEnabled(!custom);
1816 marginsModule->innerUnit->setEnabled(!custom);
1818 marginsModule->outerL->setEnabled(!custom);
1819 marginsModule->outerLE->setEnabled(!custom);
1820 marginsModule->outerUnit->setEnabled(!custom);
1822 marginsModule->headheightL->setEnabled(!custom);
1823 marginsModule->headheightLE->setEnabled(!custom);
1824 marginsModule->headheightUnit->setEnabled(!custom);
1826 marginsModule->headsepL->setEnabled(!custom);
1827 marginsModule->headsepLE->setEnabled(!custom);
1828 marginsModule->headsepUnit->setEnabled(!custom);
1830 marginsModule->footskipL->setEnabled(!custom);
1831 marginsModule->footskipLE->setEnabled(!custom);
1832 marginsModule->footskipUnit->setEnabled(!custom);
1834 bool const enableColSep = !custom &&
1835 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1836 marginsModule->columnsepL->setEnabled(enableColSep);
1837 marginsModule->columnsepLE->setEnabled(enableColSep);
1838 marginsModule->columnsepUnit->setEnabled(enableColSep);
1842 void GuiDocument::changeBackgroundColor()
1844 QColor const & newColor = QColorDialog::getColor(
1845 rgb2qcolor(set_backgroundcolor), asQWidget());
1846 if (!newColor.isValid())
1848 // set the button color and text
1849 colorModule->backgroundPB->setStyleSheet(
1850 colorButtonStyleSheet(newColor));
1851 colorModule->backgroundPB->setText(qt_("&Change..."));
1853 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1854 is_backgroundcolor = true;
1859 void GuiDocument::deleteBackgroundColor()
1861 // set the button color back to default by setting an empty StyleSheet
1862 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1863 // change button text
1864 colorModule->backgroundPB->setText(qt_("&Default..."));
1865 // save default color (white)
1866 set_backgroundcolor = rgbFromHexName("#ffffff");
1867 is_backgroundcolor = false;
1872 void GuiDocument::changeFontColor()
1874 QColor const & newColor = QColorDialog::getColor(
1875 rgb2qcolor(set_fontcolor), asQWidget());
1876 if (!newColor.isValid())
1878 // set the button color and text
1879 colorModule->fontColorPB->setStyleSheet(
1880 colorButtonStyleSheet(newColor));
1881 colorModule->fontColorPB->setText(qt_("&Change..."));
1883 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1884 is_fontcolor = true;
1889 void GuiDocument::deleteFontColor()
1891 // set the button color back to default by setting an empty StyleSheet
1892 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1893 // change button text
1894 colorModule->fontColorPB->setText(qt_("&Default..."));
1895 // save default color (black)
1896 set_fontcolor = rgbFromHexName("#000000");
1897 is_fontcolor = false;
1902 void GuiDocument::changeNoteFontColor()
1904 QColor const & newColor = QColorDialog::getColor(
1905 rgb2qcolor(set_notefontcolor), asQWidget());
1906 if (!newColor.isValid())
1908 // set the button color
1909 colorModule->noteFontColorPB->setStyleSheet(
1910 colorButtonStyleSheet(newColor));
1912 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1917 void GuiDocument::deleteNoteFontColor()
1919 // set the button color back to pref
1920 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1921 colorModule->noteFontColorPB->setStyleSheet(
1922 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1927 void GuiDocument::changeBoxBackgroundColor()
1929 QColor const & newColor = QColorDialog::getColor(
1930 rgb2qcolor(set_boxbgcolor), asQWidget());
1931 if (!newColor.isValid())
1933 // set the button color
1934 colorModule->boxBackgroundPB->setStyleSheet(
1935 colorButtonStyleSheet(newColor));
1937 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1942 void GuiDocument::deleteBoxBackgroundColor()
1944 // set the button color back to pref
1945 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1946 colorModule->boxBackgroundPB->setStyleSheet(
1947 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1952 void GuiDocument::updateQuoteStyles(bool const set)
1954 Language const * lang = lyx::languages.getLanguage(
1955 fromqstr(langModule->languageCO->itemData(
1956 langModule->languageCO->currentIndex()).toString()));
1958 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1960 langModule->quoteStyleCO->clear();
1962 bool has_default = false;
1963 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1964 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1965 if (qs == InsetQuotesParams::DynamicQuotes)
1967 bool const langdef = (qs == def);
1969 // add the default style on top
1970 langModule->quoteStyleCO->insertItem(0,
1971 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1975 langModule->quoteStyleCO->addItem(
1976 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1978 if (set && has_default)
1979 // (re)set to the default style
1980 langModule->quoteStyleCO->setCurrentIndex(0);
1984 void GuiDocument::languageChanged(int i)
1986 // some languages only work with polyglossia
1987 Language const * lang = lyx::languages.getLanguage(
1988 fromqstr(langModule->languageCO->itemData(i).toString()));
1989 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1990 // If we force to switch fontspec on, store
1991 // current state (#8717)
1992 if (fontModule->osFontsCB->isEnabled())
1993 forced_fontspec_activation =
1994 !fontModule->osFontsCB->isChecked();
1995 fontModule->osFontsCB->setChecked(true);
1996 fontModule->osFontsCB->setEnabled(false);
1999 fontModule->osFontsCB->setEnabled(true);
2000 // If we have forced to switch fontspec on,
2001 // restore previous state (#8717)
2002 if (forced_fontspec_activation)
2003 fontModule->osFontsCB->setChecked(false);
2004 forced_fontspec_activation = false;
2007 // set appropriate quotation mark style
2008 updateQuoteStyles(true);
2012 void GuiDocument::osFontsChanged(bool nontexfonts)
2014 bool const tex_fonts = !nontexfonts;
2015 // store current fonts
2016 QString const font_roman = fontModule->fontsRomanCO->itemData(
2017 fontModule->fontsRomanCO->currentIndex()).toString();
2018 QString const font_sans = fontModule->fontsSansCO->itemData(
2019 fontModule->fontsSansCO->currentIndex()).toString();
2020 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2021 fontModule->fontsTypewriterCO->currentIndex()).toString();
2022 QString const font_math = fontModule->fontsMathCO->itemData(
2023 fontModule->fontsMathCO->currentIndex()).toString();
2024 int const font_sf_scale = fontModule->scaleSansSB->value();
2025 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2028 // store default format
2029 QString const dformat = outputModule->defaultFormatCO->itemData(
2030 outputModule->defaultFormatCO->currentIndex()).toString();
2031 updateDefaultFormat();
2032 // try to restore default format
2033 int index = outputModule->defaultFormatCO->findData(dformat);
2034 // set to default if format is not found
2037 outputModule->defaultFormatCO->setCurrentIndex(index);
2039 // try to restore fonts which were selected two toggles ago
2040 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2042 fontModule->fontsRomanCO->setCurrentIndex(index);
2043 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2045 fontModule->fontsSansCO->setCurrentIndex(index);
2046 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2048 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2049 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2051 fontModule->fontsMathCO->setCurrentIndex(index);
2052 // save fonts for next next toggle
2053 fontModule->font_roman = font_roman;
2054 fontModule->font_sans = font_sans;
2055 fontModule->font_typewriter = font_typewriter;
2056 fontModule->font_math = font_math;
2057 fontModule->font_sf_scale = font_sf_scale;
2058 fontModule->font_tt_scale = font_tt_scale;
2060 langModule->encodingCO->setEnabled(tex_fonts &&
2061 !langModule->defaultencodingRB->isChecked());
2062 langModule->defaultencodingRB->setEnabled(tex_fonts);
2063 langModule->otherencodingRB->setEnabled(tex_fonts);
2065 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2066 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2067 fontModule->cjkFontLE->setEnabled(tex_fonts);
2068 fontModule->cjkFontLA->setEnabled(tex_fonts);
2070 updateFontOptions();
2072 fontModule->fontencLA->setEnabled(tex_fonts);
2073 fontModule->fontencCO->setEnabled(tex_fonts);
2075 fontModule->fontencLE->setEnabled(false);
2077 fontencChanged(fontModule->fontencCO->currentIndex());
2081 void GuiDocument::mathFontChanged(int)
2083 updateFontOptions();
2087 void GuiDocument::fontOsfToggled(bool state)
2089 if (fontModule->osFontsCB->isChecked())
2091 QString font = fontModule->fontsRomanCO->itemData(
2092 fontModule->fontsRomanCO->currentIndex()).toString();
2093 if (hasMonolithicExpertSet(font))
2094 fontModule->fontScCB->setChecked(state);
2098 void GuiDocument::fontScToggled(bool state)
2100 if (fontModule->osFontsCB->isChecked())
2102 QString font = fontModule->fontsRomanCO->itemData(
2103 fontModule->fontsRomanCO->currentIndex()).toString();
2104 if (hasMonolithicExpertSet(font))
2105 fontModule->fontOsfCB->setChecked(state);
2109 void GuiDocument::updateFontOptions()
2111 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2114 font = fontModule->fontsSansCO->itemData(
2115 fontModule->fontsSansCO->currentIndex()).toString();
2116 bool scaleable = providesScale(font);
2117 fontModule->scaleSansSB->setEnabled(scaleable);
2118 fontModule->scaleSansLA->setEnabled(scaleable);
2120 font = fontModule->fontsTypewriterCO->itemData(
2121 fontModule->fontsTypewriterCO->currentIndex()).toString();
2122 scaleable = providesScale(font);
2123 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2124 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2126 font = fontModule->fontsRomanCO->itemData(
2127 fontModule->fontsRomanCO->currentIndex()).toString();
2128 fontModule->fontScCB->setEnabled(providesSC(font));
2129 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2130 updateMathFonts(font);
2134 void GuiDocument::updateFontsize(string const & items, string const & sel)
2136 fontModule->fontsizeCO->clear();
2137 fontModule->fontsizeCO->addItem(qt_("Default"));
2139 for (int n = 0; !token(items,'|',n).empty(); ++n)
2140 fontModule->fontsizeCO->
2141 addItem(toqstr(token(items,'|',n)));
2143 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2144 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2145 fontModule->fontsizeCO->setCurrentIndex(n);
2152 bool GuiDocument::ot1() const
2154 QString const fontenc =
2155 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2156 int const i = langModule->languageCO->currentIndex();
2159 QString const langname = langModule->languageCO->itemData(i).toString();
2160 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2161 return (fontenc == "default"
2162 || (fontenc == "auto" && newlang->fontenc(buffer().params()) == "OT1")
2163 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2167 bool GuiDocument::completeFontset() const
2169 return (fontModule->fontsSansCO->itemData(
2170 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2171 && fontModule->fontsSansCO->itemData(
2172 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2176 bool GuiDocument::noMathFont() const
2178 return (fontModule->fontsMathCO->itemData(
2179 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2183 void GuiDocument::updateTexFonts()
2185 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2187 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2188 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2189 for (; it != end; ++it) {
2190 LaTeXFont lf = it->second;
2191 if (lf.name().empty()) {
2192 LYXERR0("Error: Unnamed font: " << it->first);
2195 docstring const family = lf.family();
2196 docstring guiname = translateIfPossible(lf.guiname());
2197 if (!lf.available(ot1(), noMathFont()))
2198 guiname += _(" (not installed)");
2200 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2201 else if (family == "sf")
2202 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2203 else if (family == "tt")
2204 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2205 else if (family == "math")
2206 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2211 void GuiDocument::updateFontlist()
2213 fontModule->fontsRomanCO->clear();
2214 fontModule->fontsSansCO->clear();
2215 fontModule->fontsTypewriterCO->clear();
2216 fontModule->fontsMathCO->clear();
2218 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2219 if (fontModule->osFontsCB->isChecked()) {
2220 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2221 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2222 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2223 QString unimath = qt_("Non-TeX Fonts Default");
2224 if (!LaTeXFeatures::isAvailable("unicode-math"))
2225 unimath += qt_(" (not available)");
2226 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2227 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2229 QFontDatabase fontdb;
2230 QStringList families(fontdb.families());
2231 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2232 fontModule->fontsRomanCO->addItem(*it, *it);
2233 fontModule->fontsSansCO->addItem(*it, *it);
2234 fontModule->fontsTypewriterCO->addItem(*it, *it);
2239 if (rmfonts_.empty())
2242 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2243 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2244 while (rmi != rmfonts_.constEnd()) {
2245 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2249 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2250 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2251 while (sfi != sffonts_.constEnd()) {
2252 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2256 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2257 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2258 while (tti != ttfonts_.constEnd()) {
2259 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2263 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2264 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2265 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2266 while (mmi != mathfonts_.constEnd()) {
2267 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2273 void GuiDocument::fontencChanged(int item)
2275 fontModule->fontencLE->setEnabled(
2276 fontModule->fontencCO->itemData(item).toString() == "custom");
2277 // The availability of TeX fonts depends on the font encoding
2279 updateFontOptions();
2283 void GuiDocument::updateMathFonts(QString const & rm)
2285 if (fontModule->osFontsCB->isChecked())
2287 QString const math =
2288 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2289 int const i = fontModule->fontsMathCO->findData("default");
2290 if (providesNoMath(rm) && i == -1)
2291 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2292 else if (!providesNoMath(rm) && i != -1) {
2293 int const c = fontModule->fontsMathCO->currentIndex();
2294 fontModule->fontsMathCO->removeItem(i);
2296 fontModule->fontsMathCO->setCurrentIndex(0);
2301 void GuiDocument::romanChanged(int item)
2303 if (fontModule->osFontsCB->isChecked())
2305 QString const font =
2306 fontModule->fontsRomanCO->itemData(item).toString();
2307 fontModule->fontScCB->setEnabled(providesSC(font));
2308 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2309 updateMathFonts(font);
2313 void GuiDocument::sansChanged(int item)
2315 if (fontModule->osFontsCB->isChecked())
2317 QString const font =
2318 fontModule->fontsSansCO->itemData(item).toString();
2319 bool scaleable = providesScale(font);
2320 fontModule->scaleSansSB->setEnabled(scaleable);
2321 fontModule->scaleSansLA->setEnabled(scaleable);
2325 void GuiDocument::ttChanged(int item)
2327 if (fontModule->osFontsCB->isChecked())
2329 QString const font =
2330 fontModule->fontsTypewriterCO->itemData(item).toString();
2331 bool scaleable = providesScale(font);
2332 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2333 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2337 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2340 pageLayoutModule->pagestyleCO->clear();
2341 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2343 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2344 string style = token(items, '|', n);
2345 QString style_gui = qt_(style);
2346 pagestyles.push_back(pair<string, QString>(style, style_gui));
2347 pageLayoutModule->pagestyleCO->addItem(style_gui);
2350 if (sel == "default") {
2351 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2357 for (size_t i = 0; i < pagestyles.size(); ++i)
2358 if (pagestyles[i].first == sel)
2359 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2362 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2366 void GuiDocument::browseLayout()
2368 QString const label1 = qt_("Lay&outs");
2369 QString const dir1 = toqstr(lyxrc.document_path);
2370 QStringList const filter(qt_("LyX Layout (*.layout)"));
2371 QString file = browseRelToParent(QString(), bufferFilePath(),
2372 qt_("Local layout file"), filter, false,
2375 if (!file.endsWith(".layout"))
2378 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2379 fromqstr(bufferFilePath()));
2381 int const ret = Alert::prompt(_("Local layout file"),
2382 _("The layout file you have selected is a local layout\n"
2383 "file, not one in the system or user directory.\n"
2384 "Your document will not work with this layout if you\n"
2385 "move the layout file to a different directory."),
2386 1, 1, _("&Set Layout"), _("&Cancel"));
2390 // load the layout file
2391 LayoutFileList & bcl = LayoutFileList::get();
2392 string classname = layoutFile.onlyFileName();
2393 // this will update an existing layout if that layout has been loaded before.
2394 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2395 classname.substr(0, classname.size() - 7),
2396 layoutFile.onlyPath().absFileName()));
2399 Alert::error(_("Error"),
2400 _("Unable to read local layout file."));
2404 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2406 // do not trigger classChanged if there is no change.
2407 if (latexModule->classCO->currentText() == toqstr(name))
2411 bool const avail = latexModule->classCO->set(toqstr(name));
2413 LayoutFile const & tc = bcl[name];
2414 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2415 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2416 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2417 tooltip += '\n' + qt_("This is a local layout file.");
2418 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2419 toqstr(translateIfPossible(from_utf8(tc.category()))),
2421 true, true, true, true);
2422 latexModule->classCO->set(toqstr(name));
2429 void GuiDocument::browseMaster()
2431 QString const title = qt_("Select master document");
2432 QString const dir1 = toqstr(lyxrc.document_path);
2433 QString const old = latexModule->childDocLE->text();
2434 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2435 QStringList const filter(qt_("LyX Files (*.lyx)"));
2436 QString file = browseRelToSub(old, docpath, title, filter, false,
2437 qt_("D&ocuments"), toqstr(lyxrc.document_path));
2439 if (!file.isEmpty())
2440 latexModule->childDocLE->setText(file);
2444 void GuiDocument::classChanged_adaptor()
2446 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2451 void GuiDocument::classChanged()
2453 int idx = latexModule->classCO->currentIndex();
2456 string const classname = fromqstr(latexModule->classCO->getData(idx));
2458 if (applyPB->isEnabled()) {
2459 int const ret = Alert::prompt(_("Unapplied changes"),
2460 _("Some changes in the dialog were not yet applied.\n"
2461 "If you do not apply now, they will be lost after this action."),
2462 1, 1, _("&Apply"), _("&Dismiss"));
2467 // We load the TextClass as soon as it is selected. This is
2468 // necessary so that other options in the dialog can be updated
2469 // according to the new class. Note, however, that, if you use
2470 // the scroll wheel when sitting on the combo box, we'll load a
2471 // lot of TextClass objects very quickly....
2472 if (!bp_.setBaseClass(classname)) {
2473 Alert::error(_("Error"), _("Unable to set document class."));
2476 if (lyxrc.auto_reset_options)
2477 bp_.useClassDefaults();
2479 // With the introduction of modules came a distinction between the base
2480 // class and the document class. The former corresponds to the main layout
2481 // file; the latter is that plus the modules (or the document-specific layout,
2482 // or whatever else there could be). Our parameters come from the document
2483 // class. So when we set the base class, we also need to recreate the document
2484 // class. Otherwise, we still have the old one.
2485 bp_.makeDocumentClass();
2490 void GuiDocument::languagePackageChanged(int i)
2492 langModule->languagePackageLE->setEnabled(
2493 langModule->languagePackageCO->itemData(i).toString() == "custom");
2497 void GuiDocument::biblioChanged()
2499 biblioChanged_ = true;
2504 void GuiDocument::checkPossibleCiteEngines()
2506 // Check if the class provides a specific engine,
2507 // and if so, enforce this.
2508 string force_engine;
2509 if (documentClass().provides("natbib")
2510 || documentClass().provides("natbib-internal"))
2511 force_engine = "natbib";
2512 else if (documentClass().provides("jurabib"))
2513 force_engine = "jurabib";
2514 else if (documentClass().provides("biblatex"))
2515 force_engine = "biblatex";
2516 else if (documentClass().provides("biblatex-natbib"))
2517 force_engine = "biblatex-natbib";
2519 if (!force_engine.empty())
2520 biblioModule->citeEngineCO->setCurrentIndex(
2521 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2522 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2526 void GuiDocument::rescanBibFiles()
2529 rescanTexStyles("bbx cbx");
2531 rescanTexStyles("bst");
2535 void GuiDocument::resetDefaultBibfile(string const & which)
2537 QString const engine =
2538 biblioModule->citeEngineCO->itemData(
2539 biblioModule->citeEngineCO->currentIndex()).toString();
2541 CiteEngineType const cet =
2542 CiteEngineType(biblioModule->citeStyleCO->itemData(
2543 biblioModule->citeStyleCO->currentIndex()).toInt());
2545 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2549 void GuiDocument::resetDefaultBbxBibfile()
2551 resetDefaultBibfile("bbx");
2555 void GuiDocument::resetDefaultCbxBibfile()
2557 resetDefaultBibfile("cbx");
2561 void GuiDocument::citeEngineChanged(int n)
2563 QString const engine =
2564 biblioModule->citeEngineCO->itemData(n).toString();
2566 vector<string> const engs =
2567 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2569 updateCiteStyles(engs);
2570 updateEngineDependends();
2571 resetDefaultBibfile();
2576 void GuiDocument::updateEngineDependends()
2578 bool const biblatex = isBiblatex();
2580 // These are only useful with BibTeX
2581 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2582 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2583 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2584 biblioModule->bibtopicCB->setEnabled(!biblatex);
2586 // These are only useful with Biblatex
2587 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2588 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2589 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2590 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2591 biblioModule->resetBbxPB->setEnabled(biblatex);
2592 biblioModule->resetCbxPB->setEnabled(biblatex);
2593 biblioModule->matchBbxPB->setEnabled(biblatex);
2595 // These are useful with biblatex, jurabib and natbib
2596 QString const engine =
2597 biblioModule->citeEngineCO->itemData(
2598 biblioModule->citeEngineCO->currentIndex()).toString();
2599 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2601 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2602 || ce->requires("natbib.sty");
2603 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2604 biblioModule->citePackageOptionsL->setEnabled(citepack);
2608 void GuiDocument::citeStyleChanged()
2610 QString const engine =
2611 biblioModule->citeEngineCO->itemData(
2612 biblioModule->citeEngineCO->currentIndex()).toString();
2613 QString const currentDef = isBiblatex() ?
2614 biblioModule->biblatexBbxCO->currentText()
2615 : biblioModule->defaultBiblioCO->currentText();
2616 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2617 resetDefaultBibfile();
2623 void GuiDocument::bibtexChanged(int n)
2625 biblioModule->bibtexOptionsLE->setEnabled(
2626 biblioModule->bibtexCO->itemData(n).toString() != "default");
2631 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2633 biblioModule->citeStyleCO->clear();
2635 vector<string>::const_iterator it = engs.begin();
2636 vector<string>::const_iterator end = engs.end();
2637 for (; it != end; ++it) {
2638 if (*it == "default")
2639 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2640 ENGINE_TYPE_DEFAULT);
2641 else if (*it == "authoryear")
2642 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2643 ENGINE_TYPE_AUTHORYEAR);
2644 else if (*it == "numerical")
2645 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2646 ENGINE_TYPE_NUMERICAL);
2648 int i = biblioModule->citeStyleCO->findData(sel);
2649 if (biblioModule->citeStyleCO->findData(sel) == -1)
2651 biblioModule->citeStyleCO->setCurrentIndex(i);
2653 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2654 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2658 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2660 engine_types_.clear();
2664 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2666 string style = token(items, '|', n);
2667 engine_types_.push_back(style);
2670 updateCiteStyles(engine_types_, sel);
2676 // both of these should take a vector<docstring>
2678 // This is an insanely complicated attempt to make this sort of thing
2679 // work with RTL languages.
2680 docstring formatStrVec(vector<string> const & v, docstring const & s)
2682 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2686 return translateIfPossible(from_utf8(v[0]));
2687 if (v.size() == 2) {
2688 docstring retval = _("%1$s and %2$s");
2689 retval = subst(retval, _("and"), s);
2690 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2691 translateIfPossible(from_utf8(v[1])));
2693 // The idea here is to format all but the last two items...
2694 int const vSize = v.size();
2695 docstring t2 = _("%1$s, %2$s");
2696 docstring retval = translateIfPossible(from_utf8(v[0]));
2697 for (int i = 1; i < vSize - 2; ++i)
2698 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2699 //...and then to plug them, and the last two, into this schema
2700 docstring t = _("%1$s, %2$s, and %3$s");
2701 t = subst(t, _("and"), s);
2702 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2703 translateIfPossible(from_utf8(v[vSize - 1])));
2706 vector<string> idsToNames(vector<string> const & idList)
2708 vector<string> retval;
2709 vector<string>::const_iterator it = idList.begin();
2710 vector<string>::const_iterator end = idList.end();
2711 for (; it != end; ++it) {
2712 LyXModule const * const mod = theModuleList[*it];
2714 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2715 translateIfPossible(from_utf8(*it)))));
2717 retval.push_back(mod->getName());
2721 } // end anonymous namespace
2724 void GuiDocument::modulesToParams(BufferParams & bp)
2726 // update list of loaded modules
2727 bp.clearLayoutModules();
2728 int const srows = modules_sel_model_.rowCount();
2729 for (int i = 0; i < srows; ++i)
2730 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2732 // update the list of removed modules
2733 bp.clearRemovedModules();
2734 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2735 list<string>::const_iterator rit = reqmods.begin();
2736 list<string>::const_iterator ren = reqmods.end();
2738 // check each of the default modules
2739 for (; rit != ren; ++rit) {
2740 list<string>::const_iterator mit = bp.getModules().begin();
2741 list<string>::const_iterator men = bp.getModules().end();
2743 for (; mit != men; ++mit) {
2750 // the module isn't present so must have been removed by the user
2751 bp.addRemovedModule(*rit);
2756 void GuiDocument::modulesChanged()
2758 modulesToParams(bp_);
2760 if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2761 int const ret = Alert::prompt(_("Unapplied changes"),
2762 _("Some changes in the dialog were not yet applied.\n"
2763 "If you do not apply now, they will be lost after this action."),
2764 1, 1, _("&Apply"), _("&Dismiss"));
2769 modulesChanged_ = true;
2770 bp_.makeDocumentClass();
2776 void GuiDocument::updateModuleInfo()
2778 selectionManager->update();
2780 //Module description
2781 bool const focus_on_selected = selectionManager->selectedFocused();
2782 QAbstractItemView * lv;
2783 if (focus_on_selected)
2784 lv = modulesModule->selectedLV;
2786 lv = modulesModule->availableLV;
2787 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2788 modulesModule->infoML->document()->clear();
2791 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2792 GuiIdListModel const & id_model =
2793 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2794 string const modName = id_model.getIDString(idx.row());
2795 docstring desc = getModuleDescription(modName);
2797 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2798 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2801 desc += _("Module provided by document class.");
2804 docstring cat = getModuleCategory(modName);
2808 desc += bformat(_("Category: %1$s."), cat);
2811 vector<string> pkglist = getPackageList(modName);
2812 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2813 if (!pkgdesc.empty()) {
2816 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2819 pkglist = getRequiredList(modName);
2820 if (!pkglist.empty()) {
2821 vector<string> const reqdescs = idsToNames(pkglist);
2822 pkgdesc = formatStrVec(reqdescs, _("or"));
2825 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2828 pkglist = getExcludedList(modName);
2829 if (!pkglist.empty()) {
2830 vector<string> const reqdescs = idsToNames(pkglist);
2831 pkgdesc = formatStrVec(reqdescs, _( "and"));
2834 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2837 if (!isModuleAvailable(modName)) {
2840 desc += _("WARNING: Some required packages are unavailable!");
2843 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2847 void GuiDocument::updateNumbering()
2849 DocumentClass const & tclass = documentClass();
2851 numberingModule->tocTW->setUpdatesEnabled(false);
2852 numberingModule->tocTW->clear();
2854 int const depth = numberingModule->depthSL->value();
2855 int const toc = numberingModule->tocSL->value();
2856 QString const no = qt_("No");
2857 QString const yes = qt_("Yes");
2858 QTreeWidgetItem * item = 0;
2860 DocumentClass::const_iterator lit = tclass.begin();
2861 DocumentClass::const_iterator len = tclass.end();
2862 for (; lit != len; ++lit) {
2863 int const toclevel = lit->toclevel;
2864 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2865 item = new QTreeWidgetItem(numberingModule->tocTW);
2866 item->setText(0, toqstr(translateIfPossible(lit->name())));
2867 item->setText(1, (toclevel <= depth) ? yes : no);
2868 item->setText(2, (toclevel <= toc) ? yes : no);
2872 numberingModule->tocTW->setUpdatesEnabled(true);
2873 numberingModule->tocTW->update();
2877 void GuiDocument::updateDefaultFormat()
2881 // make a copy in order to consider unapplied changes
2882 BufferParams param_copy = buffer().params();
2883 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2884 int const idx = latexModule->classCO->currentIndex();
2886 string const classname = fromqstr(latexModule->classCO->getData(idx));
2887 param_copy.setBaseClass(classname);
2888 param_copy.makeDocumentClass(true);
2890 outputModule->defaultFormatCO->blockSignals(true);
2891 outputModule->defaultFormatCO->clear();
2892 outputModule->defaultFormatCO->addItem(qt_("Default"),
2893 QVariant(QString("default")));
2894 FormatList const & formats =
2895 param_copy.exportableFormats(true);
2896 for (Format const * f : formats)
2897 outputModule->defaultFormatCO->addItem
2898 (toqstr(translateIfPossible(f->prettyname())),
2899 QVariant(toqstr(f->name())));
2900 outputModule->defaultFormatCO->blockSignals(false);
2904 bool GuiDocument::isChildIncluded(string const & child)
2906 if (includeonlys_.empty())
2908 return (std::find(includeonlys_.begin(),
2909 includeonlys_.end(), child) != includeonlys_.end());
2913 void GuiDocument::applyView()
2916 preambleModule->apply(bp_);
2917 localLayout->apply(bp_);
2920 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2921 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2924 string const engine =
2925 fromqstr(biblioModule->citeEngineCO->itemData(
2926 biblioModule->citeEngineCO->currentIndex()).toString());
2927 bp_.setCiteEngine(engine);
2929 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2930 biblioModule->citeStyleCO->currentIndex()).toInt());
2931 if (theCiteEnginesList[engine]->hasEngineType(style))
2932 bp_.setCiteEngineType(style);
2934 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2936 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2938 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2939 biblioModule->bibunitsCO->currentIndex()).toString());
2941 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2943 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2944 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2945 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2947 string const bibtex_command =
2948 fromqstr(biblioModule->bibtexCO->itemData(
2949 biblioModule->bibtexCO->currentIndex()).toString());
2950 string const bibtex_options =
2951 fromqstr(biblioModule->bibtexOptionsLE->text());
2952 if (bibtex_command == "default" || bibtex_options.empty())
2953 bp_.bibtex_command = bibtex_command;
2955 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2957 if (biblioChanged_) {
2958 buffer().invalidateBibinfoCache();
2959 buffer().removeBiblioTempFiles();
2963 indicesModule->apply(bp_);
2965 // language & quotes
2966 if (langModule->defaultencodingRB->isChecked()) {
2967 bp_.inputenc = "auto";
2969 int i = langModule->encodingCO->currentIndex();
2971 bp_.inputenc = "default";
2973 QString const enc_gui =
2974 langModule->encodingCO->currentText();
2975 Encodings::const_iterator it = encodings.begin();
2976 Encodings::const_iterator const end = encodings.end();
2978 for (; it != end; ++it) {
2979 if (qt_(it->guiName()) == enc_gui &&
2981 bp_.inputenc = it->name();
2987 // should not happen
2988 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2989 bp_.inputenc = "default";
2994 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2995 langModule->quoteStyleCO->currentIndex()).toInt();
2996 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2998 QString const langname = langModule->languageCO->itemData(
2999 langModule->languageCO->currentIndex()).toString();
3000 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
3001 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
3002 // If current cursor language was the document language, then update it too.
3003 if (cur.current_font.language() == bp_.language) {
3004 cur.current_font.setLanguage(newlang);
3005 cur.real_current_font.setLanguage(newlang);
3007 bp_.language = newlang;
3009 QString const pack = langModule->languagePackageCO->itemData(
3010 langModule->languagePackageCO->currentIndex()).toString();
3011 if (pack == "custom")
3013 fromqstr(langModule->languagePackageLE->text());
3015 bp_.lang_package = fromqstr(pack);
3018 bp_.backgroundcolor = set_backgroundcolor;
3019 bp_.isbackgroundcolor = is_backgroundcolor;
3020 bp_.fontcolor = set_fontcolor;
3021 bp_.isfontcolor = is_fontcolor;
3022 bp_.notefontcolor = set_notefontcolor;
3023 bp_.boxbgcolor = set_boxbgcolor;
3026 if (bp_.documentClass().hasTocLevels()) {
3027 bp_.tocdepth = numberingModule->tocSL->value();
3028 bp_.secnumdepth = numberingModule->depthSL->value();
3032 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3033 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3034 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3035 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3038 bp_.graphics_driver =
3039 tex_graphics[latexModule->psdriverCO->currentIndex()];
3042 int idx = latexModule->classCO->currentIndex();
3044 string const classname = fromqstr(latexModule->classCO->getData(idx));
3045 bp_.setBaseClass(classname);
3049 modulesToParams(bp_);
3052 map<string, string> const & packages = BufferParams::auto_packages();
3053 for (map<string, string>::const_iterator it = packages.begin();
3054 it != packages.end(); ++it) {
3055 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3058 int row = mathsModule->packagesTW->row(item);
3061 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3062 if (rb->isChecked()) {
3063 bp_.use_package(it->first, BufferParams::package_auto);
3066 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3067 if (rb->isChecked()) {
3068 bp_.use_package(it->first, BufferParams::package_on);
3071 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3072 if (rb->isChecked())
3073 bp_.use_package(it->first, BufferParams::package_off);
3075 // if math is indented
3076 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3077 if (bp_.is_math_indent) {
3078 // if formulas are indented
3079 switch (mathsModule->MathIndentCO->currentIndex()) {
3081 bp_.setMathIndent(Length());
3084 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3085 mathsModule->MathIndentLengthCO));
3086 bp_.setMathIndent(mathindent);
3090 // this should never happen
3091 bp_.setMathIndent(Length());
3095 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3097 bp_.math_numbering_side = BufferParams::LEFT;
3100 bp_.math_numbering_side = BufferParams::DEFAULT;
3103 bp_.math_numbering_side = BufferParams::RIGHT;
3106 // this should never happen
3107 bp_.math_numbering_side = BufferParams::DEFAULT;
3112 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3113 bp_.pagestyle = "default";
3115 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3116 for (size_t i = 0; i != pagestyles.size(); ++i)
3117 if (pagestyles[i].second == style_gui)
3118 bp_.pagestyle = pagestyles[i].first;
3122 switch (textLayoutModule->lspacingCO->currentIndex()) {
3124 bp_.spacing().set(Spacing::Single);
3127 bp_.spacing().set(Spacing::Onehalf);
3130 bp_.spacing().set(Spacing::Double);
3133 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3135 bp_.spacing().set(Spacing::Single);
3137 bp_.spacing().set(Spacing::Other, s);
3142 if (textLayoutModule->twoColumnCB->isChecked())
3147 bp_.justification = textLayoutModule->justCB->isChecked();
3149 if (textLayoutModule->indentRB->isChecked()) {
3150 // if paragraphs are separated by an indentation
3151 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3152 switch (textLayoutModule->indentCO->currentIndex()) {
3154 bp_.setParIndent(Length());
3157 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3158 textLayoutModule->indentLengthCO));
3159 bp_.setParIndent(parindent);
3163 // this should never happen
3164 bp_.setParIndent(Length());
3168 // if paragraphs are separated by a skip
3169 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3170 switch (textLayoutModule->skipCO->currentIndex()) {
3172 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3175 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3178 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3183 widgetsToLength(textLayoutModule->skipLE,
3184 textLayoutModule->skipLengthCO)
3190 // this should never happen
3191 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3197 fromqstr(latexModule->optionsLE->text());
3199 bp_.use_default_options =
3200 latexModule->defaultOptionsCB->isChecked();
3202 if (latexModule->childDocGB->isChecked())
3204 fromqstr(latexModule->childDocLE->text());
3206 bp_.master = string();
3209 bp_.clearIncludedChildren();
3210 if (masterChildModule->includeonlyRB->isChecked()) {
3211 list<string>::const_iterator it = includeonlys_.begin();
3212 for (; it != includeonlys_.end() ; ++it) {
3213 bp_.addIncludedChildren(*it);
3216 bp_.maintain_unincluded_children =
3217 masterChildModule->maintainAuxCB->isChecked();
3220 bp_.float_placement = floatModule->getPlacement();
3221 bp_.float_alignment = floatModule->getAlignment();
3224 // text should have passed validation
3225 idx = listingsModule->packageCO->currentIndex();
3226 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3227 bp_.listings_params =
3228 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3231 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3232 outputModule->defaultFormatCO->currentIndex()).toString());
3234 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3235 bp_.useNonTeXFonts = nontexfonts;
3237 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3238 if (!bp_.shell_escape)
3239 theSession().shellescapeFiles().remove(buffer().absFileName());
3240 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3241 theSession().shellescapeFiles().insert(buffer().absFileName());
3242 Buffer & buf = const_cast<Buffer &>(buffer());
3243 buf.params().shell_escape = bp_.shell_escape;
3245 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3247 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3249 int mathfmt = outputModule->mathoutCB->currentIndex();
3252 BufferParams::MathOutput const mo =
3253 static_cast<BufferParams::MathOutput>(mathfmt);
3254 bp_.html_math_output = mo;
3255 bp_.html_be_strict = outputModule->strictCB->isChecked();
3256 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3257 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3258 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3260 bp_.save_transient_properties =
3261 outputModule->saveTransientPropertiesCB->isChecked();
3264 bp_.fonts_roman[nontexfonts] =
3265 fromqstr(fontModule->fontsRomanCO->
3266 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3267 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3269 bp_.fonts_sans[nontexfonts] =
3270 fromqstr(fontModule->fontsSansCO->
3271 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3272 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3274 bp_.fonts_typewriter[nontexfonts] =
3275 fromqstr(fontModule->fontsTypewriterCO->
3276 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3277 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3279 bp_.fonts_math[nontexfonts] =
3280 fromqstr(fontModule->fontsMathCO->
3281 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3282 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3284 QString const fontenc =
3285 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3286 if (fontenc == "custom")
3287 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3289 bp_.fontenc = fromqstr(fontenc);
3292 fromqstr(fontModule->cjkFontLE->text());
3294 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3295 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3297 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3298 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3300 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3301 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3303 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3305 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3308 bp_.fonts_default_family = "default";
3310 bp_.fonts_default_family = GuiDocument::fontfamilies[
3311 fontModule->fontsDefaultCO->currentIndex()];
3313 if (fontModule->fontsizeCO->currentIndex() == 0)
3314 bp_.fontsize = "default";
3317 fromqstr(fontModule->fontsizeCO->currentText());
3320 bp_.papersize = PAPER_SIZE(
3321 pageLayoutModule->papersizeCO->currentIndex());
3323 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3324 pageLayoutModule->paperwidthUnitCO);
3326 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3327 pageLayoutModule->paperheightUnitCO);
3329 if (pageLayoutModule->facingPagesCB->isChecked())
3330 bp_.sides = TwoSides;
3332 bp_.sides = OneSide;
3334 if (pageLayoutModule->landscapeRB->isChecked())
3335 bp_.orientation = ORIENTATION_LANDSCAPE;
3337 bp_.orientation = ORIENTATION_PORTRAIT;
3340 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3342 Ui::MarginsUi const * m = marginsModule;
3344 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3345 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3346 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3347 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3348 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3349 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3350 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3351 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3354 branchesModule->apply(bp_);
3357 PDFOptions & pdf = bp_.pdfoptions();
3358 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3359 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3360 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3361 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3362 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3364 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3365 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3366 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3367 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3369 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3370 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3371 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3372 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3374 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3375 if (pdfSupportModule->fullscreenCB->isChecked())
3376 pdf.pagemode = pdf.pagemode_fullscreen;
3378 pdf.pagemode.clear();
3379 pdf.quoted_options = pdf.quoted_options_check(
3380 fromqstr(pdfSupportModule->optionsLE->text()));
3383 nonModuleChanged_ = false;
3384 shellescapeChanged_ = false;
3388 void GuiDocument::paramsToDialog()
3390 // set the default unit
3391 Length::UNIT const default_unit = Length::defaultUnit();
3394 preambleModule->update(bp_, id());
3395 localLayout->update(bp_, id());
3398 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3399 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3402 string const cite_engine = bp_.citeEngine().list().front();
3404 biblioModule->citeEngineCO->setCurrentIndex(
3405 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3407 updateEngineType(documentClass().opt_enginetype(),
3408 bp_.citeEngineType());
3410 checkPossibleCiteEngines();
3412 biblioModule->citeStyleCO->setCurrentIndex(
3413 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3415 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3417 biblioModule->bibunitsCO->clear();
3418 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3419 if (documentClass().hasLaTeXLayout("part"))
3420 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3421 if (documentClass().hasLaTeXLayout("chapter"))
3422 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3423 if (documentClass().hasLaTeXLayout("section"))
3424 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3425 if (documentClass().hasLaTeXLayout("subsection"))
3426 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3427 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3429 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3431 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3433 biblioModule->bibunitsCO->setCurrentIndex(0);
3435 updateEngineDependends();
3438 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3439 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3441 updateDefaultBiblio(bp_.defaultBiblioStyle());
3443 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3447 split(bp_.bibtex_command, command, ' ');
3449 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3451 biblioModule->bibtexCO->setCurrentIndex(bpos);
3452 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3454 // We reset to default if we do not know the specified compiler
3455 // This is for security reasons
3456 biblioModule->bibtexCO->setCurrentIndex(
3457 biblioModule->bibtexCO->findData(toqstr("default")));
3458 biblioModule->bibtexOptionsLE->clear();
3460 biblioModule->bibtexOptionsLE->setEnabled(
3461 biblioModule->bibtexCO->currentIndex() != 0);
3463 biblioChanged_ = false;
3466 // We may be called when there is no Buffer, e.g., when
3467 // the last view has just been closed.
3468 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3469 indicesModule->update(bp_, isReadOnly);
3471 // language & quotes
3472 int const pos = langModule->languageCO->findData(toqstr(
3473 bp_.language->lang()));
3474 langModule->languageCO->setCurrentIndex(pos);
3476 updateQuoteStyles();
3478 langModule->quoteStyleCO->setCurrentIndex(
3479 langModule->quoteStyleCO->findData(bp_.quotes_style));
3480 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3482 bool default_enc = true;
3483 if (bp_.inputenc != "auto") {
3484 default_enc = false;
3485 if (bp_.inputenc == "default") {
3486 langModule->encodingCO->setCurrentIndex(0);
3489 Encodings::const_iterator it = encodings.begin();
3490 Encodings::const_iterator const end = encodings.end();
3491 for (; it != end; ++it) {
3492 if (it->name() == bp_.inputenc &&
3494 enc_gui = it->guiName();
3498 int const i = langModule->encodingCO->findText(
3501 langModule->encodingCO->setCurrentIndex(i);
3503 // unknown encoding. Set to default.
3507 langModule->defaultencodingRB->setChecked(default_enc);
3508 langModule->otherencodingRB->setChecked(!default_enc);
3510 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3512 langModule->languagePackageCO->setCurrentIndex(
3513 langModule->languagePackageCO->findData("custom"));
3514 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3516 langModule->languagePackageCO->setCurrentIndex(p);
3517 langModule->languagePackageLE->clear();
3521 if (bp_.isfontcolor) {
3522 colorModule->fontColorPB->setStyleSheet(
3523 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3525 set_fontcolor = bp_.fontcolor;
3526 is_fontcolor = bp_.isfontcolor;
3528 colorModule->noteFontColorPB->setStyleSheet(
3529 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3530 set_notefontcolor = bp_.notefontcolor;
3532 if (bp_.isbackgroundcolor) {
3533 colorModule->backgroundPB->setStyleSheet(
3534 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3536 set_backgroundcolor = bp_.backgroundcolor;
3537 is_backgroundcolor = bp_.isbackgroundcolor;
3539 colorModule->boxBackgroundPB->setStyleSheet(
3540 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3541 set_boxbgcolor = bp_.boxbgcolor;
3544 int const min_toclevel = documentClass().min_toclevel();
3545 int const max_toclevel = documentClass().max_toclevel();
3546 if (documentClass().hasTocLevels()) {
3547 numberingModule->setEnabled(true);
3548 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3549 numberingModule->depthSL->setMaximum(max_toclevel);
3550 numberingModule->depthSL->setValue(bp_.secnumdepth);
3551 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3552 numberingModule->tocSL->setMaximum(max_toclevel);
3553 numberingModule->tocSL->setValue(bp_.tocdepth);
3556 numberingModule->setEnabled(false);
3557 numberingModule->tocTW->clear();
3561 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3562 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3563 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3564 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3565 bulletsModule->init();
3568 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3570 latexModule->psdriverCO->setCurrentIndex(nitem);
3574 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3575 if (bp_.is_math_indent) {
3576 Length const mathindent = bp_.getMathIndent();
3578 if (!mathindent.empty()) {
3579 lengthToWidgets(mathsModule->MathIndentLE,
3580 mathsModule->MathIndentLengthCO,
3581 mathindent, default_unit);
3584 mathsModule->MathIndentCO->setCurrentIndex(indent);
3585 enableMathIndent(indent);
3587 switch(bp_.math_numbering_side) {
3588 case BufferParams::LEFT:
3589 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3591 case BufferParams::DEFAULT:
3592 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3594 case BufferParams::RIGHT:
3595 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3598 map<string, string> const & packages = BufferParams::auto_packages();
3599 for (map<string, string>::const_iterator it = packages.begin();
3600 it != packages.end(); ++it) {
3601 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3604 int row = mathsModule->packagesTW->row(item);
3605 switch (bp_.use_package(it->first)) {
3606 case BufferParams::package_off: {
3608 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3609 rb->setChecked(true);
3612 case BufferParams::package_on: {
3614 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3615 rb->setChecked(true);
3618 case BufferParams::package_auto: {
3620 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3621 rb->setChecked(true);
3627 switch (bp_.spacing().getSpace()) {
3628 case Spacing::Other: nitem = 3; break;
3629 case Spacing::Double: nitem = 2; break;
3630 case Spacing::Onehalf: nitem = 1; break;
3631 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3635 string const & layoutID = bp_.baseClassID();
3636 setLayoutComboByIDString(layoutID);
3638 updatePagestyle(documentClass().opt_pagestyle(),
3641 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3642 if (bp_.spacing().getSpace() == Spacing::Other) {
3643 doubleToWidget(textLayoutModule->lspacingLE,
3644 bp_.spacing().getValueAsString());
3648 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3649 textLayoutModule->indentRB->setChecked(true);
3650 string parindent = bp_.getParIndent().asString();
3652 if (!parindent.empty()) {
3653 lengthToWidgets(textLayoutModule->indentLE,
3654 textLayoutModule->indentLengthCO,
3655 parindent, default_unit);
3658 textLayoutModule->indentCO->setCurrentIndex(indent);
3661 textLayoutModule->skipRB->setChecked(true);
3663 switch (bp_.getDefSkip().kind()) {
3664 case VSpace::SMALLSKIP:
3667 case VSpace::MEDSKIP:
3670 case VSpace::BIGSKIP:
3673 case VSpace::LENGTH:
3676 string const length = bp_.getDefSkip().asLyXCommand();
3677 lengthToWidgets(textLayoutModule->skipLE,
3678 textLayoutModule->skipLengthCO,
3679 length, default_unit);
3686 textLayoutModule->skipCO->setCurrentIndex(skip);
3690 textLayoutModule->twoColumnCB->setChecked(
3692 textLayoutModule->justCB->setChecked(bp_.justification);
3694 if (!bp_.options.empty()) {
3695 latexModule->optionsLE->setText(
3696 toqstr(bp_.options));
3698 latexModule->optionsLE->setText(QString());
3702 latexModule->defaultOptionsCB->setChecked(
3703 bp_.use_default_options);
3704 updateSelectedModules();
3705 selectionManager->updateProvidedModules(
3706 bp_.baseClass()->providedModules());
3707 selectionManager->updateExcludedModules(
3708 bp_.baseClass()->excludedModules());
3710 if (!documentClass().options().empty()) {
3711 latexModule->defaultOptionsLE->setText(
3712 toqstr(documentClass().options()));
3714 latexModule->defaultOptionsLE->setText(
3715 toqstr(_("[No options predefined]")));
3718 latexModule->defaultOptionsLE->setEnabled(
3719 bp_.use_default_options
3720 && !documentClass().options().empty());
3722 latexModule->defaultOptionsCB->setEnabled(
3723 !documentClass().options().empty());
3725 if (!bp_.master.empty()) {
3726 latexModule->childDocGB->setChecked(true);
3727 latexModule->childDocLE->setText(
3728 toqstr(bp_.master));
3730 latexModule->childDocLE->setText(QString());
3731 latexModule->childDocGB->setChecked(false);
3735 if (!bufferview() || !buffer().hasChildren()) {
3736 masterChildModule->childrenTW->clear();
3737 includeonlys_.clear();
3738 docPS->showPanel("Child Documents", false);
3739 if (docPS->isCurrentPanel("Child Documents"))
3740 docPS->setCurrentPanel("Document Class");
3742 docPS->showPanel("Child Documents", true);
3743 masterChildModule->setEnabled(true);
3744 includeonlys_ = bp_.getIncludedChildren();
3745 updateIncludeonlys();
3747 masterChildModule->maintainAuxCB->setChecked(
3748 bp_.maintain_unincluded_children);
3751 floatModule->setPlacement(bp_.float_placement);
3752 floatModule->setAlignment(bp_.float_alignment);
3755 // break listings_params to multiple lines
3757 InsetListingsParams(bp_.listings_params).separatedParams();
3758 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3759 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3761 listingsModule->packageCO->setCurrentIndex(nn);
3765 // some languages only work with polyglossia/XeTeX
3766 Language const * lang = lyx::languages.getLanguage(
3767 fromqstr(langModule->languageCO->itemData(
3768 langModule->languageCO->currentIndex()).toString()));
3769 bool const need_fontspec =
3770 lang->babel().empty() && !lang->polyglossia().empty();
3771 bool const os_fonts_available =
3772 bp_.baseClass()->outputType() == lyx::LATEX
3773 && LaTeXFeatures::isAvailable("fontspec");
3774 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3775 fontModule->osFontsCB->setChecked(
3776 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3777 updateFontsize(documentClass().opt_fontsize(),
3780 QString font = toqstr(bp_.fontsRoman());
3781 int rpos = fontModule->fontsRomanCO->findData(font);
3783 rpos = fontModule->fontsRomanCO->count();
3784 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3786 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3787 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3789 font = toqstr(bp_.fontsSans());
3790 int spos = fontModule->fontsSansCO->findData(font);
3792 spos = fontModule->fontsSansCO->count();
3793 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3795 fontModule->fontsSansCO->setCurrentIndex(spos);
3796 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3798 font = toqstr(bp_.fontsTypewriter());
3799 int tpos = fontModule->fontsTypewriterCO->findData(font);
3801 tpos = fontModule->fontsTypewriterCO->count();
3802 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3804 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3805 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3807 font = toqstr(bp_.fontsMath());
3808 int mpos = fontModule->fontsMathCO->findData(font);
3810 mpos = fontModule->fontsMathCO->count();
3811 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3813 fontModule->fontsMathCO->setCurrentIndex(mpos);
3814 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3816 if (bp_.useNonTeXFonts && os_fonts_available) {
3817 fontModule->fontencLA->setEnabled(false);
3818 fontModule->fontencCO->setEnabled(false);
3819 fontModule->fontencLE->setEnabled(false);
3821 fontModule->fontencLA->setEnabled(true);
3822 fontModule->fontencCO->setEnabled(true);
3823 fontModule->fontencLE->setEnabled(true);
3829 if (!bp_.fonts_cjk.empty())
3830 fontModule->cjkFontLE->setText(
3831 toqstr(bp_.fonts_cjk));
3833 fontModule->cjkFontLE->setText(QString());
3835 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3836 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3838 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3839 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3840 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3841 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3842 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3843 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3845 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3847 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3849 if (bp_.fontenc == "auto" || bp_.fontenc == "default") {
3850 fontModule->fontencCO->setCurrentIndex(
3851 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3852 fontModule->fontencLE->setEnabled(false);
3854 fontModule->fontencCO->setCurrentIndex(
3855 fontModule->fontencCO->findData("custom"));
3856 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3860 // This must be set _after_ fonts since updateDefaultFormat()
3861 // checks osFontsCB settings.
3862 // update combobox with formats
3863 updateDefaultFormat();
3864 int index = outputModule->defaultFormatCO->findData(toqstr(
3865 bp_.default_output_format));
3866 // set to default if format is not found
3869 outputModule->defaultFormatCO->setCurrentIndex(index);
3871 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3872 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3873 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3875 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3876 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3877 outputModule->strictCB->setChecked(bp_.html_be_strict);
3878 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3880 outputModule->saveTransientPropertiesCB
3881 ->setChecked(bp_.save_transient_properties);
3884 bool const extern_geometry =
3885 documentClass().provides("geometry");
3886 int const psize = bp_.papersize;
3887 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3888 setCustomPapersize(!extern_geometry && psize == 1);
3889 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3891 bool const landscape =
3892 bp_.orientation == ORIENTATION_LANDSCAPE;
3893 pageLayoutModule->landscapeRB->setChecked(landscape);
3894 pageLayoutModule->portraitRB->setChecked(!landscape);
3895 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3896 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3898 pageLayoutModule->facingPagesCB->setChecked(
3899 bp_.sides == TwoSides);
3901 lengthToWidgets(pageLayoutModule->paperwidthLE,
3902 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3903 lengthToWidgets(pageLayoutModule->paperheightLE,
3904 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3907 Ui::MarginsUi * m = marginsModule;
3911 lengthToWidgets(m->topLE, m->topUnit,
3912 bp_.topmargin, default_unit);
3914 lengthToWidgets(m->bottomLE, m->bottomUnit,
3915 bp_.bottommargin, default_unit);
3917 lengthToWidgets(m->innerLE, m->innerUnit,
3918 bp_.leftmargin, default_unit);
3920 lengthToWidgets(m->outerLE, m->outerUnit,
3921 bp_.rightmargin, default_unit);
3923 lengthToWidgets(m->headheightLE, m->headheightUnit,
3924 bp_.headheight, default_unit);
3926 lengthToWidgets(m->headsepLE, m->headsepUnit,
3927 bp_.headsep, default_unit);
3929 lengthToWidgets(m->footskipLE, m->footskipUnit,
3930 bp_.footskip, default_unit);
3932 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3933 bp_.columnsep, default_unit);
3936 updateUnknownBranches();
3937 branchesModule->update(bp_);
3940 PDFOptions const & pdf = bp_.pdfoptions();
3941 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3942 if (bp_.documentClass().provides("hyperref"))
3943 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3945 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3946 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3947 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3948 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3949 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3951 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3952 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3953 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3955 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3957 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3958 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3959 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3960 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3962 nn = findToken(backref_opts, pdf.backref);
3964 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3966 pdfSupportModule->fullscreenCB->setChecked
3967 (pdf.pagemode == pdf.pagemode_fullscreen);
3969 pdfSupportModule->optionsLE->setText(
3970 toqstr(pdf.quoted_options));
3972 // Make sure that the bc is in the INITIAL state
3973 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3976 // clear changed branches cache
3977 changedBranches_.clear();
3980 nonModuleChanged_ = false;
3981 shellescapeChanged_ = false;
3985 void GuiDocument::saveDocDefault()
3987 // we have to apply the params first
3993 void GuiDocument::updateAvailableModules()
3995 modules_av_model_.clear();
3996 list<modInfoStruct> modInfoList = getModuleInfo();
3997 // Sort names according to the locale
3998 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3999 return 0 < b.name.localeAwareCompare(a.name);
4002 for (modInfoStruct const & m : modInfoList) {
4003 modules_av_model_.insertRow(i, m.name, m.id, m.description);
4009 void GuiDocument::updateSelectedModules()
4011 modules_sel_model_.clear();
4012 list<modInfoStruct> const selModList = getSelectedModules();
4014 for (modInfoStruct const & m : selModList) {
4015 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4021 void GuiDocument::updateIncludeonlys()
4023 masterChildModule->childrenTW->clear();
4024 QString const no = qt_("No");
4025 QString const yes = qt_("Yes");
4027 if (includeonlys_.empty()) {
4028 masterChildModule->includeallRB->setChecked(true);
4029 masterChildModule->childrenTW->setEnabled(false);
4030 masterChildModule->maintainAuxCB->setEnabled(false);
4032 masterChildModule->includeonlyRB->setChecked(true);
4033 masterChildModule->childrenTW->setEnabled(true);
4034 masterChildModule->maintainAuxCB->setEnabled(true);
4036 ListOfBuffers children = buffer().getChildren();
4037 ListOfBuffers::const_iterator it = children.begin();
4038 ListOfBuffers::const_iterator end = children.end();
4039 bool has_unincluded = false;
4040 bool all_unincluded = true;
4041 for (; it != end; ++it) {
4042 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4045 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4046 from_utf8(buffer().filePath())));
4047 item->setText(0, toqstr(name));
4048 item->setText(1, isChildIncluded(name) ? yes : no);
4049 if (!isChildIncluded(name))
4050 has_unincluded = true;
4052 all_unincluded = false;
4054 // Both if all childs are included and if none is included
4055 // is equal to "include all" (i.e., omit \includeonly).
4056 // Thus, reset the GUI.
4057 if (!has_unincluded || all_unincluded) {
4058 masterChildModule->includeallRB->setChecked(true);
4059 masterChildModule->childrenTW->setEnabled(false);
4060 includeonlys_.clear();
4062 // If all are included, we need to update again.
4063 if (!has_unincluded)
4064 updateIncludeonlys();
4068 bool GuiDocument::isBiblatex() const
4070 QString const engine =
4071 biblioModule->citeEngineCO->itemData(
4072 biblioModule->citeEngineCO->currentIndex()).toString();
4074 // this can happen if the cite engine is unknown, which can happen
4075 // if one is using a file that came from someone else, etc. in that
4076 // case, we crash if we proceed.
4077 if (engine.isEmpty())
4080 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4084 void GuiDocument::updateDefaultBiblio(string const & style,
4085 string const & which)
4087 QString const bibstyle = toqstr(style);
4088 biblioModule->defaultBiblioCO->clear();
4093 if (which != "cbx") {
4094 // First the bbx styles
4095 biblioModule->biblatexBbxCO->clear();
4096 QStringList str = texFileList("bbxFiles.lst");
4097 // test whether we have a valid list, otherwise run rescan
4098 if (str.isEmpty()) {
4099 rescanTexStyles("bbx");
4100 str = texFileList("bbxFiles.lst");
4102 for (int i = 0; i != str.size(); ++i)
4103 str[i] = onlyFileName(str[i]);
4104 // sort on filename only (no path)
4107 for (int i = 0; i != str.count(); ++i) {
4108 QString item = changeExtension(str[i], "");
4109 if (item == bibstyle)
4111 biblioModule->biblatexBbxCO->addItem(item);
4114 if (item_nr == -1 && !bibstyle.isEmpty()) {
4115 biblioModule->biblatexBbxCO->addItem(bibstyle);
4116 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4120 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4122 biblioModule->biblatexBbxCO->clearEditText();
4125 if (which != "bbx") {
4126 // now the cbx styles
4127 biblioModule->biblatexCbxCO->clear();
4128 QStringList str = texFileList("cbxFiles.lst");
4129 // test whether we have a valid list, otherwise run rescan
4130 if (str.isEmpty()) {
4131 rescanTexStyles("cbx");
4132 str = texFileList("cbxFiles.lst");
4134 for (int i = 0; i != str.size(); ++i)
4135 str[i] = onlyFileName(str[i]);
4136 // sort on filename only (no path)
4139 for (int i = 0; i != str.count(); ++i) {
4140 QString item = changeExtension(str[i], "");
4141 if (item == bibstyle)
4143 biblioModule->biblatexCbxCO->addItem(item);
4146 if (item_nr == -1 && !bibstyle.isEmpty()) {
4147 biblioModule->biblatexCbxCO->addItem(bibstyle);
4148 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4152 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4154 biblioModule->biblatexCbxCO->clearEditText();
4157 biblioModule->biblatexBbxCO->clear();
4158 biblioModule->biblatexCbxCO->clear();
4159 QStringList str = texFileList("bstFiles.lst");
4160 // test whether we have a valid list, otherwise run rescan
4161 if (str.isEmpty()) {
4162 rescanTexStyles("bst");
4163 str = texFileList("bstFiles.lst");
4165 for (int i = 0; i != str.size(); ++i)
4166 str[i] = onlyFileName(str[i]);
4167 // sort on filename only (no path)
4170 for (int i = 0; i != str.count(); ++i) {
4171 QString item = changeExtension(str[i], "");
4172 if (item == bibstyle)
4174 biblioModule->defaultBiblioCO->addItem(item);
4177 if (item_nr == -1 && !bibstyle.isEmpty()) {
4178 biblioModule->defaultBiblioCO->addItem(bibstyle);
4179 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4183 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4185 biblioModule->defaultBiblioCO->clearEditText();
4188 updateResetDefaultBiblio();
4192 void GuiDocument::updateResetDefaultBiblio()
4194 QString const engine =
4195 biblioModule->citeEngineCO->itemData(
4196 biblioModule->citeEngineCO->currentIndex()).toString();
4197 CiteEngineType const cet =
4198 CiteEngineType(biblioModule->citeStyleCO->itemData(
4199 biblioModule->citeStyleCO->currentIndex()).toInt());
4201 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4203 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4204 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4205 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4206 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4207 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4208 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4210 biblioModule->resetDefaultBiblioPB->setEnabled(
4211 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4215 void GuiDocument::matchBiblatexStyles()
4217 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4222 void GuiDocument::updateContents()
4224 // Nothing to do here as the document settings is not cursor dependant.
4229 void GuiDocument::useClassDefaults()
4231 if (applyPB->isEnabled()) {
4232 int const ret = Alert::prompt(_("Unapplied changes"),
4233 _("Some changes in the dialog were not yet applied.\n"
4234 "If you do not apply now, they will be lost after this action."),
4235 1, 1, _("&Apply"), _("&Dismiss"));
4240 int idx = latexModule->classCO->currentIndex();
4241 string const classname = fromqstr(latexModule->classCO->getData(idx));
4242 if (!bp_.setBaseClass(classname)) {
4243 Alert::error(_("Error"), _("Unable to set document class."));
4246 bp_.useClassDefaults();
4252 void GuiDocument::setLayoutComboByIDString(string const & idString)
4254 if (!latexModule->classCO->set(toqstr(idString)))
4255 Alert::warning(_("Can't set layout!"),
4256 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4260 bool GuiDocument::isValid()
4263 validateListingsParameters().isEmpty() &&
4264 localLayout->isValid() &&
4266 // if we're asking for skips between paragraphs
4267 !textLayoutModule->skipRB->isChecked() ||
4268 // then either we haven't chosen custom
4269 textLayoutModule->skipCO->currentIndex() != 3 ||
4270 // or else a length has been given
4271 !textLayoutModule->skipLE->text().isEmpty()
4274 // if we're asking for indentation
4275 !textLayoutModule->indentRB->isChecked() ||
4276 // then either we haven't chosen custom
4277 textLayoutModule->indentCO->currentIndex() != 1 ||
4278 // or else a length has been given
4279 !textLayoutModule->indentLE->text().isEmpty()
4282 // if we're asking for math indentation
4283 !mathsModule->MathIndentCB->isChecked() ||
4284 // then either we haven't chosen custom
4285 mathsModule->MathIndentCO->currentIndex() != 1 ||
4286 // or else a length has been given
4287 !mathsModule->MathIndentLE->text().isEmpty()
4292 char const * const GuiDocument::fontfamilies[5] = {
4293 "default", "rmdefault", "sfdefault", "ttdefault", ""
4297 char const * GuiDocument::fontfamilies_gui[5] = {
4298 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4302 bool GuiDocument::initialiseParams(string const &)
4304 BufferView const * view = bufferview();
4306 bp_ = BufferParams();
4310 bp_ = view->buffer().params();
4312 updateAvailableModules();
4313 //FIXME It'd be nice to make sure here that the selected
4314 //modules are consistent: That required modules are actually
4315 //selected, and that we don't have conflicts. If so, we could
4316 //at least pop up a warning.
4322 void GuiDocument::clearParams()
4324 bp_ = BufferParams();
4328 BufferId GuiDocument::id() const
4330 BufferView const * const view = bufferview();
4331 return view? &view->buffer() : 0;
4335 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4337 return moduleNames_;
4341 list<GuiDocument::modInfoStruct> const
4342 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4344 list<modInfoStruct> mInfo;
4345 for (string const & name : mods) {
4347 LyXModule const * const mod = theModuleList[name];
4352 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4360 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4362 return makeModuleInfo(params().getModules());
4366 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4368 return makeModuleInfo(params().baseClass()->providedModules());
4372 DocumentClass const & GuiDocument::documentClass() const
4374 return bp_.documentClass();
4378 static void dispatch_bufferparams(Dialog const & dialog,
4379 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4382 ss << "\\begin_header\n";
4383 bp.writeFile(ss, buf);
4384 ss << "\\end_header\n";
4385 dialog.dispatch(FuncRequest(lfun, ss.str()));
4389 void GuiDocument::dispatchParams()
4391 // We need a non-const buffer object.
4392 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4393 // There may be several undo records; group them (bug #8998)
4394 // This handles undo groups automagically
4395 UndoGroupHelper ugh(&buf);
4397 // This must come first so that a language change is correctly noticed
4400 // Apply the BufferParams. Note that this will set the base class
4401 // and then update the buffer's layout.
4402 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4404 if (!params().master.empty()) {
4405 FileName const master_file = support::makeAbsPath(params().master,
4406 support::onlyPath(buffer().absFileName()));
4407 if (isLyXFileName(master_file.absFileName())) {
4408 Buffer * master = checkAndLoadLyXFile(master_file);
4410 if (master->isChild(const_cast<Buffer *>(&buffer())))
4411 const_cast<Buffer &>(buffer()).setParent(master);
4413 Alert::warning(_("Assigned master does not include this file"),
4414 bformat(_("You must include this file in the document\n"
4415 "'%1$s' in order to use the master document\n"
4416 "feature."), from_utf8(params().master)));
4418 Alert::warning(_("Could not load master"),
4419 bformat(_("The master document '%1$s'\n"
4420 "could not be loaded."),
4421 from_utf8(params().master)));
4425 // Generate the colours requested by each new branch.
4426 BranchList & branchlist = params().branchlist();
4427 if (!branchlist.empty()) {
4428 BranchList::const_iterator it = branchlist.begin();
4429 BranchList::const_iterator const end = branchlist.end();
4430 for (; it != end; ++it) {
4431 docstring const & current_branch = it->branch();
4432 Branch const * branch = branchlist.find(current_branch);
4433 string const x11hexname = X11hexname(branch->color());
4434 // display the new color
4435 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4436 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4439 // rename branches in the document
4440 executeBranchRenaming();
4441 // and clear changed branches cache
4442 changedBranches_.clear();
4444 // Generate the colours requested by indices.
4445 IndicesList & indiceslist = params().indiceslist();
4446 if (!indiceslist.empty()) {
4447 IndicesList::const_iterator it = indiceslist.begin();
4448 IndicesList::const_iterator const end = indiceslist.end();
4449 for (; it != end; ++it) {
4450 docstring const & current_index = it->shortcut();
4451 Index const * index = indiceslist.findShortcut(current_index);
4452 string const x11hexname = X11hexname(index->color());
4453 // display the new color
4454 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4455 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4459 // If we used an LFUN, we would not need these two lines:
4460 BufferView * bv = const_cast<BufferView *>(bufferview());
4461 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4465 void GuiDocument::setLanguage() const
4467 Language const * const newL = bp_.language;
4468 if (buffer().params().language == newL)
4471 string const & lang_name = newL->lang();
4472 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4476 void GuiDocument::saveAsDefault() const
4478 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4482 bool GuiDocument::providesOSF(QString const & font) const
4484 if (fontModule->osFontsCB->isChecked())
4485 // FIXME: we should check if the fonts really
4486 // have OSF support. But how?
4488 return theLaTeXFonts().getLaTeXFont(
4489 qstring_to_ucs4(font)).providesOSF(ot1(),
4495 bool GuiDocument::providesSC(QString const & font) const
4497 if (fontModule->osFontsCB->isChecked())
4499 return theLaTeXFonts().getLaTeXFont(
4500 qstring_to_ucs4(font)).providesSC(ot1(),
4506 bool GuiDocument::providesScale(QString const & font) const
4508 if (fontModule->osFontsCB->isChecked())
4510 return theLaTeXFonts().getLaTeXFont(
4511 qstring_to_ucs4(font)).providesScale(ot1(),
4517 bool GuiDocument::providesNoMath(QString const & font) const
4519 if (fontModule->osFontsCB->isChecked())
4521 return theLaTeXFonts().getLaTeXFont(
4522 qstring_to_ucs4(font)).providesNoMath(ot1(),
4527 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4529 if (fontModule->osFontsCB->isChecked())
4531 return theLaTeXFonts().getLaTeXFont(
4532 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4539 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4541 // FIXME Unicode: docstrings would be better for these parameters but this
4542 // change requires a lot of others
4545 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4546 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4547 // Find the first sentence of the description
4548 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4549 int pos = bf.toNextBoundary();
4552 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4553 // Tooltip is the desc followed by the module name
4554 m.description = QString("%1<i>%2</i>")
4555 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4561 void GuiDocument::loadModuleInfo()
4563 moduleNames_.clear();
4564 for (LyXModule const & mod : theModuleList)
4565 if (mod.category().substr(0, 8) != "Citation")
4566 moduleNames_.push_back(modInfo(mod));
4570 void GuiDocument::updateUnknownBranches()
4574 list<docstring> used_branches;
4575 buffer().getUsedBranches(used_branches);
4576 list<docstring>::const_iterator it = used_branches.begin();
4577 QStringList unknown_branches;
4578 for (; it != used_branches.end() ; ++it) {
4579 if (!buffer().params().branchlist().find(*it))
4580 unknown_branches.append(toqstr(*it));
4582 branchesModule->setUnknownBranches(unknown_branches);
4586 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4588 map<docstring, docstring>::iterator it = changedBranches_.begin();
4589 for (; it != changedBranches_.end() ; ++it) {
4590 if (it->second == oldname) {
4591 // branch has already been renamed
4592 it->second = newname;
4597 changedBranches_[oldname] = newname;
4601 void GuiDocument::executeBranchRenaming() const
4603 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4604 for (; it != changedBranches_.end() ; ++it) {
4605 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4606 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4611 void GuiDocument::allPackagesAuto()
4617 void GuiDocument::allPackagesAlways()
4623 void GuiDocument::allPackagesNot()
4629 void GuiDocument::allPackages(int col)
4631 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4633 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4634 rb->setChecked(true);
4639 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4642 } // namespace frontend
4645 #include "moc_GuiDocument.cpp"