2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "CategorizedCombo.h"
17 #include "GuiApplication.h"
18 #include "GuiBranches.h"
19 #include "GuiIndices.h"
20 #include "GuiSelectionManager.h"
21 #include "LaTeXHighlighter.h"
22 #include "LengthCombo.h"
23 #include "PanelStack.h"
24 #include "Validator.h"
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "CiteEnginesList.h"
34 #include "ColorCache.h"
35 #include "Converter.h"
38 #include "FloatPlacement.h"
40 #include "FuncRequest.h"
41 #include "IndicesList.h"
43 #include "LaTeXFeatures.h"
44 #include "LaTeXFonts.h"
46 #include "LayoutEnums.h"
47 #include "LayoutModuleList.h"
49 #include "ModuleList.h"
50 #include "OutputParams.h"
51 #include "PDFOptions.h"
52 #include "qt_helpers.h"
55 #include "TextClass.h"
59 #include "insets/InsetListingsParams.h"
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
68 #include "frontends/alert.h"
70 #include <QAbstractItemModel>
71 #include <QHeaderView>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
77 #include <QTextBoundaryFinder>
78 #include <QTextCursor>
88 // a style sheet for buttons
89 // this is for example used for the background color setting button
90 static inline QString colorButtonStyleSheet(QColor const & bgColor)
92 if (bgColor.isValid()) {
93 QString rc = QLatin1String("background-color:");
102 using namespace lyx::support;
107 char const * const tex_graphics[] =
109 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
110 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
111 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
112 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
117 char const * const tex_graphics_gui[] =
119 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
120 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
121 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
122 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
123 "XeTeX", N_("None"), ""
127 char const * backref_opts[] =
129 "false", "section", "slide", "page", ""
133 char const * backref_opts_gui[] =
135 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
139 char const * lst_packages[] =
141 "Listings", "Minted", ""
145 vector<string> engine_types_;
146 vector<pair<string, QString> > pagestyles;
148 QMap<QString, QString> rmfonts_;
149 QMap<QString, QString> sffonts_;
150 QMap<QString, QString> ttfonts_;
151 QMap<QString, QString> mathfonts_;
154 } // anonymous namespace
158 RGBColor set_backgroundcolor;
159 bool is_backgroundcolor;
160 RGBColor set_fontcolor;
162 RGBColor set_notefontcolor;
163 RGBColor set_boxbgcolor;
164 bool forced_fontspec_activation;
167 // used when sorting the textclass list.
168 class less_textclass_avail_desc
169 : public binary_function<string, string, int>
172 bool operator()(string const & lhs, string const & rhs) const
174 // Ordering criteria:
175 // 1. Availability of text class
176 // 2. Description (lexicographic)
177 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
178 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
179 int const order = compare_no_case(
180 translateIfPossible(from_utf8(tc1.description())),
181 translateIfPossible(from_utf8(tc2.description())));
182 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
183 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
192 vector<string> getRequiredList(string const & modName)
194 LyXModule const * const mod = theModuleList[modName];
196 return vector<string>(); //empty such thing
197 return mod->getRequiredModules();
201 vector<string> getExcludedList(string const & modName)
203 LyXModule const * const mod = theModuleList[modName];
205 return vector<string>(); //empty such thing
206 return mod->getExcludedModules();
210 docstring getModuleCategory(string const & modName)
212 LyXModule const * const mod = theModuleList[modName];
215 return from_utf8(mod->category());
219 docstring getModuleDescription(string const & modName)
221 LyXModule const * const mod = theModuleList[modName];
223 return _("Module not found!");
225 return translateIfPossible(from_utf8(mod->getDescription()));
229 vector<string> getPackageList(string const & modName)
231 LyXModule const * const mod = theModuleList[modName];
233 return vector<string>(); //empty such thing
234 return mod->getPackageList();
238 bool isModuleAvailable(string const & modName)
240 LyXModule const * const mod = theModuleList[modName];
243 return mod->isAvailable();
246 } // anonymous namespace
249 /////////////////////////////////////////////////////////////////////
251 // ModuleSelectionManager
253 /////////////////////////////////////////////////////////////////////
255 /// SelectionManager for use with modules
256 class ModuleSelectionManager : public GuiSelectionManager
260 ModuleSelectionManager(QObject * parent,
261 QTreeView * availableLV,
262 QListView * selectedLV,
266 QPushButton * downPB,
267 GuiIdListModel * availableModel,
268 GuiIdListModel * selectedModel,
269 GuiDocument const * container)
270 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
271 upPB, downPB, availableModel, selectedModel),
272 container_(container)
275 void updateProvidedModules(LayoutModuleList const & pm)
276 { provided_modules_ = pm.list(); }
278 void updateExcludedModules(LayoutModuleList const & em)
279 { excluded_modules_ = em.list(); }
282 virtual void updateAddPB();
284 virtual void updateUpPB();
286 virtual void updateDownPB();
288 virtual void updateDelPB();
289 /// returns availableModel as a GuiIdListModel
290 GuiIdListModel * getAvailableModel()
292 return dynamic_cast<GuiIdListModel *>(availableModel);
294 /// returns selectedModel as a GuiIdListModel
295 GuiIdListModel * getSelectedModel()
297 return dynamic_cast<GuiIdListModel *>(selectedModel);
299 /// keeps a list of the modules the text class provides
300 list<string> provided_modules_;
302 list<string> excluded_modules_;
304 GuiDocument const * container_;
307 void ModuleSelectionManager::updateAddPB()
309 int const arows = availableModel->rowCount();
310 QModelIndexList const avail_sels =
311 availableLV->selectionModel()->selectedIndexes();
313 // disable if there aren't any modules (?), if none of them is chosen
314 // in the dialog, or if the chosen one is already selected for use.
315 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
316 addPB->setEnabled(false);
320 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
321 string const modname = getAvailableModel()->getIDString(idx.row());
324 container_->params().layoutModuleCanBeAdded(modname);
325 addPB->setEnabled(enable);
329 void ModuleSelectionManager::updateDownPB()
331 int const srows = selectedModel->rowCount();
333 downPB->setEnabled(false);
336 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
337 int const curRow = curidx.row();
338 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
339 downPB->setEnabled(false);
343 // determine whether immediately succeding element requires this one
344 string const curmodname = getSelectedModel()->getIDString(curRow);
345 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
347 vector<string> reqs = getRequiredList(nextmodname);
349 // if it doesn't require anything....
351 downPB->setEnabled(true);
355 // Enable it if this module isn't required.
356 // FIXME This should perhaps be more flexible and check whether, even
357 // if the next one is required, there is also an earlier one that will do.
359 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
362 void ModuleSelectionManager::updateUpPB()
364 int const srows = selectedModel->rowCount();
366 upPB->setEnabled(false);
370 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
371 int curRow = curIdx.row();
372 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
373 upPB->setEnabled(false);
376 string const curmodname = getSelectedModel()->getIDString(curRow);
378 // determine whether immediately preceding element is required by this one
379 vector<string> reqs = getRequiredList(curmodname);
381 // if this one doesn't require anything....
383 upPB->setEnabled(true);
388 // Enable it if the preceding module isn't required.
389 // NOTE This is less flexible than it might be. We could check whether, even
390 // if the previous one is required, there is an earlier one that would do.
391 string const premod = getSelectedModel()->getIDString(curRow - 1);
392 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
395 void ModuleSelectionManager::updateDelPB()
397 int const srows = selectedModel->rowCount();
399 deletePB->setEnabled(false);
403 QModelIndex const & curidx =
404 selectedLV->selectionModel()->currentIndex();
405 int const curRow = curidx.row();
406 if (curRow < 0 || curRow >= srows) { // invalid index?
407 deletePB->setEnabled(false);
411 string const curmodname = getSelectedModel()->getIDString(curRow);
413 // We're looking here for a reason NOT to enable the button. If we
414 // find one, we disable it and return. If we don't, we'll end up at
415 // the end of the function, and then we enable it.
416 for (int i = curRow + 1; i < srows; ++i) {
417 string const thisMod = getSelectedModel()->getIDString(i);
418 vector<string> reqs = getRequiredList(thisMod);
419 //does this one require us?
420 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
424 // OK, so this module requires us
425 // is there an EARLIER module that also satisfies the require?
426 // NOTE We demand that it be earlier to keep the list of modules
427 // consistent with the rule that a module must be proceeded by a
428 // required module. There would be more flexible ways to proceed,
429 // but that would be a lot more complicated, and the logic here is
430 // already complicated. (That's why I've left the debugging code.)
431 // lyxerr << "Testing " << thisMod << endl;
432 bool foundone = false;
433 for (int j = 0; j < curRow; ++j) {
434 string const mod = getSelectedModel()->getIDString(j);
435 // lyxerr << "In loop: Testing " << mod << endl;
436 // do we satisfy the require?
437 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
438 // lyxerr << mod << " does the trick." << endl;
443 // did we find a module to satisfy the require?
445 // lyxerr << "No matching module found." << endl;
446 deletePB->setEnabled(false);
450 // lyxerr << "All's well that ends well." << endl;
451 deletePB->setEnabled(true);
455 /////////////////////////////////////////////////////////////////////
459 /////////////////////////////////////////////////////////////////////
461 PreambleModule::PreambleModule(QWidget * parent)
462 : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
464 // This is not a memory leak. The object will be destroyed
466 // @ is letter in the LyX user preamble
467 (void) new LaTeXHighlighter(preambleTE->document(), true);
468 preambleTE->setFont(guiApp->typewriterSystemFont());
469 preambleTE->setWordWrapMode(QTextOption::NoWrap);
470 setFocusProxy(preambleTE);
471 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
472 connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
473 connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
474 connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
479 void PreambleModule::checkFindButton()
481 findButtonPB->setEnabled(!findLE->text().isEmpty());
485 void PreambleModule::findText()
487 bool const found = preambleTE->find(findLE->text());
490 QTextCursor qtcur = preambleTE->textCursor();
491 qtcur.movePosition(QTextCursor::Start);
492 preambleTE->setTextCursor(qtcur);
493 preambleTE->find(findLE->text());
498 void PreambleModule::update(BufferParams const & params, BufferId id)
500 QString preamble = toqstr(params.preamble);
501 // Nothing to do if the params and preamble are unchanged.
502 if (id == current_id_
503 && preamble == preambleTE->document()->toPlainText())
506 QTextCursor cur = preambleTE->textCursor();
507 // Save the coords before switching to the new one.
508 preamble_coords_[current_id_] =
509 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
511 // Save the params address for further use.
513 preambleTE->document()->setPlainText(preamble);
514 Coords::const_iterator it = preamble_coords_.find(current_id_);
515 if (it == preamble_coords_.end())
516 // First time we open this one.
517 preamble_coords_[current_id_] = make_pair(0, 0);
519 // Restore saved coords.
520 cur = preambleTE->textCursor();
521 cur.setPosition(it->second.first);
522 preambleTE->setTextCursor(cur);
523 preambleTE->verticalScrollBar()->setValue(it->second.second);
528 void PreambleModule::apply(BufferParams & params)
530 params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
534 void PreambleModule::closeEvent(QCloseEvent * e)
536 // Save the coords before closing.
537 QTextCursor cur = preambleTE->textCursor();
538 preamble_coords_[current_id_] =
539 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
544 /////////////////////////////////////////////////////////////////////
548 /////////////////////////////////////////////////////////////////////
551 LocalLayout::LocalLayout(QWidget * parent)
552 : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
554 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
555 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
556 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
560 void LocalLayout::update(BufferParams const & params, BufferId id)
562 QString layout = toqstr(params.getLocalLayout(false));
563 // Nothing to do if the params and preamble are unchanged.
564 if (id == current_id_
565 && layout == locallayoutTE->document()->toPlainText())
568 // Save the params address for further use.
570 locallayoutTE->document()->setPlainText(layout);
575 void LocalLayout::apply(BufferParams & params)
577 docstring const layout =
578 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
579 params.setLocalLayout(layout, false);
583 void LocalLayout::hideConvert()
585 convertPB->setEnabled(false);
586 convertLB->setText("");
592 void LocalLayout::textChanged()
594 static const QString message =
595 qt_("Press button to check validity...");
596 string const layout =
597 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
599 if (layout.empty()) {
601 validatePB->setEnabled(false);
602 validLB->setText("");
605 } else if (!validatePB->isEnabled()) {
606 // if that's already enabled, we shouldn't need to do anything.
608 validLB->setText(message);
609 validatePB->setEnabled(true);
616 void LocalLayout::convert() {
617 string const layout =
618 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
619 string const newlayout = TextClass::convert(layout);
620 if (!newlayout.empty())
621 locallayoutTE->setPlainText(toqstr(newlayout));
626 void LocalLayout::convertPressed() {
633 void LocalLayout::validate() {
635 static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
636 // Flashy red bold text
637 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
639 string const layout =
640 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
641 if (!layout.empty()) {
642 TextClass::ReturnValues const ret = TextClass::validate(layout);
643 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
644 validatePB->setEnabled(false);
645 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
646 : ivpar.arg(qt_("Layout is invalid!")));
647 if (ret == TextClass::OK_OLDFORMAT) {
649 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
651 if (TextClass::convert(layout).empty()) {
652 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
653 // then maybe the layout is still valid, but its format is more
654 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
655 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
656 convertPB->setEnabled(false);
657 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
658 ? ivpar.arg(qt_("Conversion to current format impossible!"))
659 : vpar.arg(qt_("Conversion to current stable format "
661 convertLB->setText(text);
663 convertPB->setEnabled(true);
664 convertLB->setText(qt_("Convert to current format"));
675 void LocalLayout::validatePressed() {
681 /////////////////////////////////////////////////////////////////////
685 /////////////////////////////////////////////////////////////////////
688 GuiDocument::GuiDocument(GuiView & lv)
689 : GuiDialog(lv, "document", qt_("Document Settings")),
690 biblioChanged_(false), nonModuleChanged_(false),
691 modulesChanged_(false), shellescapeChanged_(false)
695 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
696 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
697 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
698 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
700 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
701 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
703 // Manage the restore, ok, apply, restore and cancel/close buttons
704 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
706 bc().setApply(applyPB);
707 bc().setCancel(closePB);
708 bc().setRestore(restorePB);
712 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
713 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
714 this, SLOT(change_adaptor()));
715 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
716 this, SLOT(setLSpacing(int)));
717 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
718 this, SLOT(change_adaptor()));
720 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
721 this, SLOT(change_adaptor()));
722 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
723 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
724 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
725 this, SLOT(change_adaptor()));
726 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
727 this, SLOT(setIndent(int)));
728 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
729 this, SLOT(change_adaptor()));
730 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
731 this, SLOT(change_adaptor()));
733 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
734 this, SLOT(change_adaptor()));
735 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
736 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
737 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
738 this, SLOT(change_adaptor()));
739 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
740 this, SLOT(setSkip(int)));
741 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
742 this, SLOT(change_adaptor()));
743 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
744 this, SLOT(change_adaptor()));
746 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
747 this, SLOT(enableIndent(bool)));
748 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
749 this, SLOT(enableSkip(bool)));
751 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
752 this, SLOT(change_adaptor()));
753 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
754 this, SLOT(setColSep()));
755 connect(textLayoutModule->justCB, SIGNAL(clicked()),
756 this, SLOT(change_adaptor()));
758 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
759 textLayoutModule->lspacingLE));
760 textLayoutModule->indentLE->setValidator(new LengthValidator(
761 textLayoutModule->indentLE));
762 textLayoutModule->skipLE->setValidator(new LengthValidator(
763 textLayoutModule->skipLE));
765 textLayoutModule->indentCO->addItem(qt_("Default"));
766 textLayoutModule->indentCO->addItem(qt_("Custom"));
767 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
768 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
769 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
770 textLayoutModule->skipCO->addItem(qt_("Custom"));
771 textLayoutModule->lspacingCO->insertItem(
772 Spacing::Single, qt_("Single"));
773 textLayoutModule->lspacingCO->insertItem(
774 Spacing::Onehalf, qt_("OneHalf"));
775 textLayoutModule->lspacingCO->insertItem(
776 Spacing::Double, qt_("Double"));
777 textLayoutModule->lspacingCO->insertItem(
778 Spacing::Other, qt_("Custom"));
779 // initialize the length validator
780 bc().addCheckedLineEdit(textLayoutModule->indentLE);
781 bc().addCheckedLineEdit(textLayoutModule->skipLE);
784 // master/child handling
785 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
787 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
788 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
789 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
790 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
791 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
792 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
793 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
794 this, SLOT(change_adaptor()));
795 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
796 this, SLOT(change_adaptor()));
797 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
798 this, SLOT(change_adaptor()));
799 masterChildModule->childrenTW->setColumnCount(2);
800 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
801 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
802 masterChildModule->childrenTW->resizeColumnToContents(1);
803 masterChildModule->childrenTW->resizeColumnToContents(2);
807 outputModule = new UiWidget<Ui::OutputUi>(this);
809 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
810 this, SLOT(change_adaptor()));
811 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
812 this, SLOT(change_adaptor()));
813 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
814 this, SLOT(change_adaptor()));
815 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
816 this, SLOT(change_adaptor()));
817 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
818 this, SLOT(change_adaptor()));
820 connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
821 this, SLOT(shellescapeChanged()));
822 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
823 this, SLOT(change_adaptor()));
824 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
825 this, SLOT(change_adaptor()));
826 outputModule->synccustomCB->addItem("");
827 outputModule->synccustomCB->addItem("\\synctex=1");
828 outputModule->synccustomCB->addItem("\\synctex=-1");
829 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
831 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
832 outputModule->synccustomCB));
834 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
835 this, SLOT(change_adaptor()));
838 fontModule = new FontModule(this);
839 connect(fontModule->osFontsCB, SIGNAL(clicked()),
840 this, SLOT(change_adaptor()));
841 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
842 this, SLOT(osFontsChanged(bool)));
843 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
844 this, SLOT(change_adaptor()));
845 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
846 this, SLOT(romanChanged(int)));
847 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
848 this, SLOT(change_adaptor()));
849 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
850 this, SLOT(sansChanged(int)));
851 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
852 this, SLOT(change_adaptor()));
853 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
854 this, SLOT(ttChanged(int)));
855 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
856 this, SLOT(change_adaptor()));
857 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
858 this, SLOT(mathFontChanged(int)));
859 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
860 this, SLOT(change_adaptor()));
861 connect(fontModule->fontencCO, SIGNAL(activated(int)),
862 this, SLOT(change_adaptor()));
863 connect(fontModule->fontencCO, SIGNAL(activated(int)),
864 this, SLOT(fontencChanged(int)));
865 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
866 this, SLOT(change_adaptor()));
867 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
868 this, SLOT(change_adaptor()));
869 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
870 this, SLOT(change_adaptor()));
871 connect(fontModule->microtypeCB, SIGNAL(clicked()),
872 this, SLOT(change_adaptor()));
873 connect(fontModule->dashesCB, SIGNAL(clicked()),
874 this, SLOT(change_adaptor()));
875 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
876 this, SLOT(change_adaptor()));
877 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
878 this, SLOT(change_adaptor()));
879 connect(fontModule->fontScCB, SIGNAL(clicked()),
880 this, SLOT(change_adaptor()));
881 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
882 this, SLOT(fontScToggled(bool)));
883 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
884 this, SLOT(change_adaptor()));
885 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
886 this, SLOT(fontOsfToggled(bool)));
888 fontModule->fontencLE->setValidator(new NoNewLineValidator(
889 fontModule->fontencLE));
890 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
891 fontModule->cjkFontLE));
895 fontModule->fontsizeCO->addItem(qt_("Default"));
896 fontModule->fontsizeCO->addItem(qt_("10"));
897 fontModule->fontsizeCO->addItem(qt_("11"));
898 fontModule->fontsizeCO->addItem(qt_("12"));
900 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
901 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
902 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
904 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
905 fontModule->fontsDefaultCO->addItem(
906 qt_(GuiDocument::fontfamilies_gui[n]));
908 if (!LaTeXFeatures::isAvailable("fontspec"))
909 fontModule->osFontsCB->setToolTip(
910 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
911 "You need to install the package \"fontspec\" to use this feature"));
915 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
916 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
917 this, SLOT(papersizeChanged(int)));
918 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
919 this, SLOT(papersizeChanged(int)));
920 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
921 this, SLOT(change_adaptor()));
922 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
923 this, SLOT(change_adaptor()));
924 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
925 this, SLOT(change_adaptor()));
926 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
927 this, SLOT(change_adaptor()));
928 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
929 this, SLOT(change_adaptor()));
930 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
931 this, SLOT(change_adaptor()));
932 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
933 this, SLOT(change_adaptor()));
934 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
935 this, SLOT(change_adaptor()));
936 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
937 this, SLOT(change_adaptor()));
938 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
939 this, SLOT(change_adaptor()));
941 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
942 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
943 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
944 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
945 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
946 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
947 pageLayoutModule->paperheightL);
948 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
949 pageLayoutModule->paperwidthL);
951 QComboBox * cb = pageLayoutModule->papersizeCO;
952 cb->addItem(qt_("Default"));
953 cb->addItem(qt_("Custom"));
954 cb->addItem(qt_("US letter"));
955 cb->addItem(qt_("US legal"));
956 cb->addItem(qt_("US executive"));
957 cb->addItem(qt_("A0"));
958 cb->addItem(qt_("A1"));
959 cb->addItem(qt_("A2"));
960 cb->addItem(qt_("A3"));
961 cb->addItem(qt_("A4"));
962 cb->addItem(qt_("A5"));
963 cb->addItem(qt_("A6"));
964 cb->addItem(qt_("B0"));
965 cb->addItem(qt_("B1"));
966 cb->addItem(qt_("B2"));
967 cb->addItem(qt_("B3"));
968 cb->addItem(qt_("B4"));
969 cb->addItem(qt_("B5"));
970 cb->addItem(qt_("B6"));
971 cb->addItem(qt_("C0"));
972 cb->addItem(qt_("C1"));
973 cb->addItem(qt_("C2"));
974 cb->addItem(qt_("C3"));
975 cb->addItem(qt_("C4"));
976 cb->addItem(qt_("C5"));
977 cb->addItem(qt_("C6"));
978 cb->addItem(qt_("JIS B0"));
979 cb->addItem(qt_("JIS B1"));
980 cb->addItem(qt_("JIS B2"));
981 cb->addItem(qt_("JIS B3"));
982 cb->addItem(qt_("JIS B4"));
983 cb->addItem(qt_("JIS B5"));
984 cb->addItem(qt_("JIS B6"));
985 // remove the %-items from the unit choice
986 pageLayoutModule->paperwidthUnitCO->noPercents();
987 pageLayoutModule->paperheightUnitCO->noPercents();
988 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
989 pageLayoutModule->paperheightLE));
990 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
991 pageLayoutModule->paperwidthLE));
995 marginsModule = new UiWidget<Ui::MarginsUi>(this);
996 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
997 this, SLOT(setCustomMargins(bool)));
998 connect(marginsModule->marginCB, SIGNAL(clicked()),
999 this, SLOT(change_adaptor()));
1000 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1001 this, SLOT(change_adaptor()));
1002 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1003 this, SLOT(change_adaptor()));
1004 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1005 this, SLOT(change_adaptor()));
1006 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1007 this, SLOT(change_adaptor()));
1008 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1009 this, SLOT(change_adaptor()));
1010 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1011 this, SLOT(change_adaptor()));
1012 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1013 this, SLOT(change_adaptor()));
1014 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1015 this, SLOT(change_adaptor()));
1016 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1017 this, SLOT(change_adaptor()));
1018 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1019 this, SLOT(change_adaptor()));
1020 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1021 this, SLOT(change_adaptor()));
1022 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1023 this, SLOT(change_adaptor()));
1024 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1025 this, SLOT(change_adaptor()));
1026 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1027 this, SLOT(change_adaptor()));
1028 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1029 this, SLOT(change_adaptor()));
1030 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1031 this, SLOT(change_adaptor()));
1032 marginsModule->topLE->setValidator(new LengthValidator(
1033 marginsModule->topLE));
1034 marginsModule->bottomLE->setValidator(new LengthValidator(
1035 marginsModule->bottomLE));
1036 marginsModule->innerLE->setValidator(new LengthValidator(
1037 marginsModule->innerLE));
1038 marginsModule->outerLE->setValidator(new LengthValidator(
1039 marginsModule->outerLE));
1040 marginsModule->headsepLE->setValidator(new LengthValidator(
1041 marginsModule->headsepLE));
1042 marginsModule->headheightLE->setValidator(new LengthValidator(
1043 marginsModule->headheightLE));
1044 marginsModule->footskipLE->setValidator(new LengthValidator(
1045 marginsModule->footskipLE));
1046 marginsModule->columnsepLE->setValidator(new LengthValidator(
1047 marginsModule->columnsepLE));
1049 bc().addCheckedLineEdit(marginsModule->topLE,
1050 marginsModule->topL);
1051 bc().addCheckedLineEdit(marginsModule->bottomLE,
1052 marginsModule->bottomL);
1053 bc().addCheckedLineEdit(marginsModule->innerLE,
1054 marginsModule->innerL);
1055 bc().addCheckedLineEdit(marginsModule->outerLE,
1056 marginsModule->outerL);
1057 bc().addCheckedLineEdit(marginsModule->headsepLE,
1058 marginsModule->headsepL);
1059 bc().addCheckedLineEdit(marginsModule->headheightLE,
1060 marginsModule->headheightL);
1061 bc().addCheckedLineEdit(marginsModule->footskipLE,
1062 marginsModule->footskipL);
1063 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1064 marginsModule->columnsepL);
1068 langModule = new UiWidget<Ui::LanguageUi>(this);
1069 connect(langModule->languageCO, SIGNAL(activated(int)),
1070 this, SLOT(change_adaptor()));
1071 connect(langModule->languageCO, SIGNAL(activated(int)),
1072 this, SLOT(languageChanged(int)));
1073 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1074 this, SLOT(change_adaptor()));
1075 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1076 this, SLOT(change_adaptor()));
1077 connect(langModule->encodingCO, SIGNAL(activated(int)),
1078 this, SLOT(change_adaptor()));
1079 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1080 this, SLOT(change_adaptor()));
1081 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1082 this, SLOT(change_adaptor()));
1083 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1084 this, SLOT(change_adaptor()));
1085 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1086 this, SLOT(languagePackageChanged(int)));
1087 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1088 this, SLOT(change_adaptor()));
1090 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1091 langModule->languagePackageLE));
1093 QAbstractItemModel * language_model = guiApp->languageModel();
1094 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1095 language_model->sort(0);
1096 langModule->languageCO->setModel(language_model);
1097 langModule->languageCO->setModelColumn(0);
1099 // Always put the default encoding in the first position.
1100 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1101 QStringList encodinglist;
1102 for (auto const & encvar : encodings) {
1103 if (!encvar.unsafe() && !encvar.guiName().empty())
1104 encodinglist.append(qt_(encvar.guiName()));
1106 encodinglist.sort();
1107 langModule->encodingCO->addItems(encodinglist);
1109 langModule->languagePackageCO->addItem(
1110 qt_("Default"), toqstr("default"));
1111 langModule->languagePackageCO->addItem(
1112 qt_("Automatic"), toqstr("auto"));
1113 langModule->languagePackageCO->addItem(
1114 qt_("Always Babel"), toqstr("babel"));
1115 langModule->languagePackageCO->addItem(
1116 qt_("Custom"), toqstr("custom"));
1117 langModule->languagePackageCO->addItem(
1118 qt_("None[[language package]]"), toqstr("none"));
1122 colorModule = new UiWidget<Ui::ColorUi>(this);
1123 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1124 this, SLOT(changeFontColor()));
1125 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1126 this, SLOT(deleteFontColor()));
1127 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1128 this, SLOT(changeNoteFontColor()));
1129 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1130 this, SLOT(deleteNoteFontColor()));
1131 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1132 this, SLOT(changeBackgroundColor()));
1133 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1134 this, SLOT(deleteBackgroundColor()));
1135 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1136 this, SLOT(changeBoxBackgroundColor()));
1137 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1138 this, SLOT(deleteBoxBackgroundColor()));
1142 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1143 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1144 this, SLOT(change_adaptor()));
1145 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1146 this, SLOT(change_adaptor()));
1147 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1148 this, SLOT(updateNumbering()));
1149 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1150 this, SLOT(updateNumbering()));
1151 numberingModule->tocTW->setColumnCount(3);
1152 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1153 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1154 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1155 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1158 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1159 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1160 this, SLOT(citeEngineChanged(int)));
1161 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1162 this, SLOT(citeStyleChanged()));
1163 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1164 this, SLOT(biblioChanged()));
1165 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1166 this, SLOT(biblioChanged()));
1167 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1168 this, SLOT(bibtexChanged(int)));
1169 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1170 this, SLOT(biblioChanged()));
1171 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1172 this, SLOT(biblioChanged()));
1173 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1174 this, SLOT(biblioChanged()));
1175 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1176 this, SLOT(biblioChanged()));
1177 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1178 this, SLOT(updateResetDefaultBiblio()));
1179 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1180 this, SLOT(biblioChanged()));
1181 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1182 this, SLOT(biblioChanged()));
1183 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1184 this, SLOT(updateResetDefaultBiblio()));
1185 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1186 this, SLOT(biblioChanged()));
1187 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1188 this, SLOT(biblioChanged()));
1189 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1190 this, SLOT(updateResetDefaultBiblio()));
1191 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1192 this, SLOT(rescanBibFiles()));
1193 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1194 this, SLOT(resetDefaultBibfile()));
1195 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1196 this, SLOT(resetDefaultCbxBibfile()));
1197 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1198 this, SLOT(resetDefaultBbxBibfile()));
1199 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1200 this, SLOT(matchBiblatexStyles()));
1202 biblioModule->citeEngineCO->clear();
1203 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1204 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1205 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1206 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1210 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1211 biblioModule->bibtexOptionsLE));
1212 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1213 biblioModule->defaultBiblioCO->lineEdit()));
1214 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1215 biblioModule->citePackageOptionsLE));
1217 // NOTE: we do not provide "custom" here for security reasons!
1218 biblioModule->bibtexCO->clear();
1219 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1220 for (auto const & alts : lyxrc.bibtex_alternatives) {
1221 QString const command = toqstr(alts).left(toqstr(alts).indexOf(" "));
1222 biblioModule->bibtexCO->addItem(command, command);
1227 indicesModule = new GuiIndices;
1228 connect(indicesModule, SIGNAL(changed()),
1229 this, SLOT(change_adaptor()));
1233 mathsModule = new UiWidget<Ui::MathsUi>(this);
1234 QStringList headers;
1235 headers << qt_("Package") << qt_("Load automatically")
1236 << qt_("Load always") << qt_("Do not load");
1237 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1238 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1239 map<string, string> const & packages = BufferParams::auto_packages();
1240 mathsModule->packagesTW->setRowCount(packages.size());
1242 for (auto const & pkgvar : packages) {
1243 docstring const package = from_ascii(pkgvar.first);
1244 QString autoTooltip = qt_(pkgvar.second);
1245 QString alwaysTooltip;
1246 if (package == "amsmath")
1248 qt_("The AMS LaTeX packages are always used");
1250 alwaysTooltip = toqstr(bformat(
1251 _("The LaTeX package %1$s is always used"),
1253 QString neverTooltip;
1254 if (package == "amsmath")
1256 qt_("The AMS LaTeX packages are never used");
1258 neverTooltip = toqstr(bformat(
1259 _("The LaTeX package %1$s is never used"),
1261 QRadioButton * autoRB = new QRadioButton(mathsModule);
1262 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1263 QRadioButton * neverRB = new QRadioButton(mathsModule);
1264 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1265 packageGroup->addButton(autoRB);
1266 packageGroup->addButton(alwaysRB);
1267 packageGroup->addButton(neverRB);
1268 autoRB->setToolTip(autoTooltip);
1269 alwaysRB->setToolTip(alwaysTooltip);
1270 neverRB->setToolTip(neverTooltip);
1272 // Pack the buttons in a layout in order to get proper alignment
1273 QWidget * autoRBWidget = new QWidget();
1274 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1275 autoRBLayout->addWidget(autoRB);
1276 autoRBLayout->setAlignment(Qt::AlignCenter);
1277 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1278 autoRBWidget->setLayout(autoRBLayout);
1280 QWidget * alwaysRBWidget = new QWidget();
1281 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1282 alwaysRBLayout->addWidget(alwaysRB);
1283 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1284 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1285 alwaysRBWidget->setLayout(alwaysRBLayout);
1287 QWidget * neverRBWidget = new QWidget();
1288 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1289 neverRBLayout->addWidget(neverRB);
1290 neverRBLayout->setAlignment(Qt::AlignCenter);
1291 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1292 neverRBWidget->setLayout(neverRBLayout);
1294 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1295 mathsModule->packagesTW->setItem(packnum, 0, pack);
1296 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1297 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1298 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1300 connect(autoRB, SIGNAL(clicked()),
1301 this, SLOT(change_adaptor()));
1302 connect(alwaysRB, SIGNAL(clicked()),
1303 this, SLOT(change_adaptor()));
1304 connect(neverRB, SIGNAL(clicked()),
1305 this, SLOT(change_adaptor()));
1308 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1309 this, SLOT(allPackagesAuto()));
1310 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1311 this, SLOT(allPackagesAlways()));
1312 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1313 this, SLOT(allPackagesNot()));
1314 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1315 this, SLOT(change_adaptor()));
1316 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1317 this, SLOT(change_adaptor()));
1318 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1319 this, SLOT(change_adaptor()));
1320 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1321 this, SLOT(change_adaptor()));
1323 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1324 this, SLOT(change_adaptor()));
1325 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1326 this, SLOT(allowMathIndent()));
1327 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1328 this, SLOT(change_adaptor()));
1329 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1330 this, SLOT(enableMathIndent(int)));
1331 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1332 this, SLOT(change_adaptor()));
1333 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1334 this, SLOT(change_adaptor()));
1337 mathsModule->MathIndentCO->addItem(qt_("Default"));
1338 mathsModule->MathIndentCO->addItem(qt_("Custom"));
1339 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1340 mathsModule->MathIndentLE));
1341 // initialize the length validator
1342 bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1343 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1344 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1345 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1346 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1350 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1351 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1352 this, SLOT(change_adaptor()));
1353 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1354 this, SLOT(change_adaptor()));
1355 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1356 this, SLOT(change_adaptor()));
1357 connect(latexModule->classCO, SIGNAL(activated(int)),
1358 this, SLOT(classChanged_adaptor()));
1359 connect(latexModule->classCO, SIGNAL(activated(int)),
1360 this, SLOT(change_adaptor()));
1361 connect(latexModule->layoutPB, SIGNAL(clicked()),
1362 this, SLOT(browseLayout()));
1363 connect(latexModule->layoutPB, SIGNAL(clicked()),
1364 this, SLOT(change_adaptor()));
1365 connect(latexModule->childDocGB, SIGNAL(clicked()),
1366 this, SLOT(change_adaptor()));
1367 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1368 this, SLOT(change_adaptor()));
1369 connect(latexModule->childDocPB, SIGNAL(clicked()),
1370 this, SLOT(browseMaster()));
1371 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1372 this, SLOT(change_adaptor()));
1373 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1374 this, SLOT(change_adaptor()));
1376 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1377 latexModule->optionsLE));
1378 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1379 latexModule->childDocLE));
1381 // postscript drivers
1382 for (int n = 0; tex_graphics[n][0]; ++n) {
1383 QString enc = qt_(tex_graphics_gui[n]);
1384 latexModule->psdriverCO->addItem(enc);
1387 LayoutFileList const & bcl = LayoutFileList::get();
1388 vector<LayoutFileIndex> classList = bcl.classList();
1389 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1391 for (auto const & cvar : classList) {
1392 LayoutFile const & tc = bcl[cvar];
1393 bool const available = tc.isTeXClassAvailable();
1394 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1395 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1396 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1398 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1399 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1400 "Please check if you have the matching %1$s class "
1401 "and all required packages (%2$s) installed."),
1402 output_type, from_utf8(tc.prerequisites(", "))));
1404 latexModule->classCO->addItemSort(toqstr(tc.name()),
1406 toqstr(translateIfPossible(from_utf8(tc.category()))),
1408 true, true, true, available);
1413 branchesModule = new GuiBranches(this);
1414 connect(branchesModule, SIGNAL(changed()),
1415 this, SLOT(change_adaptor()));
1416 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1417 this, SLOT(branchesRename(docstring const &, docstring const &)));
1418 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1419 updateUnknownBranches();
1423 preambleModule = new PreambleModule(this);
1424 connect(preambleModule, SIGNAL(changed()),
1425 this, SLOT(change_adaptor()));
1427 localLayout = new LocalLayout(this);
1428 connect(localLayout, SIGNAL(changed()),
1429 this, SLOT(change_adaptor()));
1433 bulletsModule = new BulletsModule(this);
1434 connect(bulletsModule, SIGNAL(changed()),
1435 this, SLOT(change_adaptor()));
1439 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1440 modulesModule->availableLV->header()->setVisible(false);
1441 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1442 modulesModule->availableLV->header()->setStretchLastSection(false);
1444 new ModuleSelectionManager(this, modulesModule->availableLV,
1445 modulesModule->selectedLV,
1446 modulesModule->addPB,
1447 modulesModule->deletePB,
1448 modulesModule->upPB,
1449 modulesModule->downPB,
1450 availableModel(), selectedModel(), this);
1451 connect(selectionManager, SIGNAL(updateHook()),
1452 this, SLOT(updateModuleInfo()));
1453 connect(selectionManager, SIGNAL(selectionChanged()),
1454 this, SLOT(modulesChanged()));
1458 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1459 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1460 this, SLOT(change_adaptor()));
1461 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1462 this, SLOT(change_adaptor()));
1463 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1464 this, SLOT(change_adaptor()));
1465 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1466 this, SLOT(change_adaptor()));
1467 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1468 this, SLOT(change_adaptor()));
1469 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1470 this, SLOT(change_adaptor()));
1471 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1472 this, SLOT(change_adaptor()));
1473 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1474 this, SLOT(change_adaptor()));
1475 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1476 this, SLOT(change_adaptor()));
1477 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1478 this, SLOT(change_adaptor()));
1479 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1480 this, SLOT(change_adaptor()));
1481 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1482 this, SLOT(change_adaptor()));
1483 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1484 this, SLOT(change_adaptor()));
1485 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1486 this, SLOT(change_adaptor()));
1487 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1488 this, SLOT(change_adaptor()));
1489 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1490 this, SLOT(change_adaptor()));
1492 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1493 pdfSupportModule->titleLE));
1494 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1495 pdfSupportModule->authorLE));
1496 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1497 pdfSupportModule->subjectLE));
1498 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1499 pdfSupportModule->keywordsLE));
1500 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1501 pdfSupportModule->optionsLE));
1503 for (int i = 0; backref_opts[i][0]; ++i)
1504 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1508 floatModule = new FloatPlacement;
1509 connect(floatModule, SIGNAL(changed()),
1510 this, SLOT(change_adaptor()));
1514 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1515 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1516 this, SLOT(change_adaptor()));
1517 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1518 this, SLOT(change_adaptor()));
1519 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1520 this, SLOT(setListingsMessage()));
1521 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1522 this, SLOT(change_adaptor()));
1523 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1524 this, SLOT(listingsPackageChanged(int)));
1525 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1526 this, SLOT(setListingsMessage()));
1527 listingsModule->listingsTB->setPlainText(
1528 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1530 for (int i = 0; lst_packages[i][0]; ++i)
1531 listingsModule->packageCO->addItem(lst_packages[i]);
1535 docPS->addPanel(latexModule, N_("Document Class"));
1536 docPS->addPanel(masterChildModule, N_("Child Documents"));
1537 docPS->addPanel(modulesModule, N_("Modules"));
1538 docPS->addPanel(localLayout, N_("Local Layout"));
1539 docPS->addPanel(fontModule, N_("Fonts"));
1540 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1541 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1542 docPS->addPanel(marginsModule, N_("Page Margins"));
1543 docPS->addPanel(langModule, N_("Language"));
1544 docPS->addPanel(colorModule, N_("Colors"));
1545 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1546 docPS->addPanel(biblioModule, N_("Bibliography"));
1547 docPS->addPanel(indicesModule, N_("Indexes"));
1548 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1549 docPS->addPanel(mathsModule, N_("Math Options"));
1550 docPS->addPanel(floatModule, N_("Float Placement"));
1551 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1552 docPS->addPanel(bulletsModule, N_("Bullets"));
1553 docPS->addPanel(branchesModule, N_("Branches"));
1554 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1555 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1556 docPS->setCurrentPanel("Document Class");
1557 // FIXME: hack to work around resizing bug in Qt >= 4.2
1558 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1559 #if QT_VERSION >= 0x040200
1560 docPS->updateGeometry();
1565 void GuiDocument::onBufferViewChanged()
1567 if (isVisibleView())
1568 initialiseParams("");
1572 void GuiDocument::saveDefaultClicked()
1578 void GuiDocument::useDefaultsClicked()
1584 void GuiDocument::change_adaptor()
1586 nonModuleChanged_ = true;
1591 void GuiDocument::shellescapeChanged()
1593 shellescapeChanged_ = true;
1598 void GuiDocument::slotApply()
1600 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1601 bool wasclean = buffer().isClean();
1602 GuiDialog::slotApply();
1603 if (wasclean && only_shellescape_changed)
1604 buffer().markClean();
1605 modulesChanged_ = false;
1609 void GuiDocument::slotOK()
1611 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1612 bool wasclean = buffer().isClean();
1613 GuiDialog::slotOK();
1614 if (wasclean && only_shellescape_changed)
1615 buffer().markClean();
1616 modulesChanged_ = false;
1620 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1625 string child = fromqstr(item->text(0));
1629 if (std::find(includeonlys_.begin(),
1630 includeonlys_.end(), child) != includeonlys_.end())
1631 includeonlys_.remove(child);
1633 includeonlys_.push_back(child);
1635 updateIncludeonlys();
1640 QString GuiDocument::validateListingsParameters()
1642 if (listingsModule->bypassCB->isChecked())
1644 string const package =
1645 lst_packages[listingsModule->packageCO->currentIndex()];
1646 string params = fromqstr(listingsModule->listingsED->toPlainText());
1647 InsetListingsParams lstparams(params);
1648 lstparams.setMinted(package == "Minted");
1649 return toqstr(lstparams.validate());
1653 void GuiDocument::setListingsMessage()
1656 static bool isOK = true;
1657 QString msg = validateListingsParameters();
1658 if (msg.isEmpty()) {
1662 // listingsTB->setTextColor("black");
1663 listingsModule->listingsTB->setPlainText(
1664 qt_("Input listings parameters below. "
1665 "Enter ? for a list of parameters."));
1668 // listingsTB->setTextColor("red");
1669 listingsModule->listingsTB->setPlainText(msg);
1674 void GuiDocument::listingsPackageChanged(int index)
1676 string const package = lst_packages[index];
1677 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1678 Alert::warning(_("Pygments driver command not found!"),
1679 _("The driver command necessary to use the minted package\n"
1680 "(pygmentize) has not been found. Make sure you have\n"
1681 "the python-pygments module installed or, if the driver\n"
1682 "is named differently, to add the following line to the\n"
1683 "document preamble:\n\n"
1684 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1685 "where 'driver' is name of the driver command."));
1690 void GuiDocument::setLSpacing(int item)
1692 textLayoutModule->lspacingLE->setEnabled(item == 3);
1696 void GuiDocument::setIndent(int item)
1698 bool const enable = (item == 1);
1699 textLayoutModule->indentLE->setEnabled(enable);
1700 textLayoutModule->indentLengthCO->setEnabled(enable);
1701 textLayoutModule->skipLE->setEnabled(false);
1702 textLayoutModule->skipLengthCO->setEnabled(false);
1707 void GuiDocument::enableIndent(bool indent)
1709 textLayoutModule->skipLE->setEnabled(!indent);
1710 textLayoutModule->skipLengthCO->setEnabled(!indent);
1712 setIndent(textLayoutModule->indentCO->currentIndex());
1716 void GuiDocument::setSkip(int item)
1718 bool const enable = (item == 3);
1719 textLayoutModule->skipLE->setEnabled(enable);
1720 textLayoutModule->skipLengthCO->setEnabled(enable);
1725 void GuiDocument::enableSkip(bool skip)
1727 textLayoutModule->indentLE->setEnabled(!skip);
1728 textLayoutModule->indentLengthCO->setEnabled(!skip);
1730 setSkip(textLayoutModule->skipCO->currentIndex());
1733 void GuiDocument::allowMathIndent() {
1734 // only disable when not checked, checked does not always allow enabling
1735 if (!mathsModule->MathIndentCB->isChecked()) {
1736 mathsModule->MathIndentLE->setEnabled(false);
1737 mathsModule->MathIndentLengthCO->setEnabled(false);
1739 if (mathsModule->MathIndentCB->isChecked()
1740 && mathsModule->MathIndentCO->currentIndex() == 1) {
1741 mathsModule->MathIndentLE->setEnabled(true);
1742 mathsModule->MathIndentLengthCO->setEnabled(true);
1747 void GuiDocument::enableMathIndent(int item)
1749 bool const enable = (item == 1);
1750 mathsModule->MathIndentLE->setEnabled(enable);
1751 mathsModule->MathIndentLengthCO->setEnabled(enable);
1756 void GuiDocument::setMargins()
1758 bool const extern_geometry =
1759 documentClass().provides("geometry");
1760 marginsModule->marginCB->setEnabled(!extern_geometry);
1761 if (extern_geometry) {
1762 marginsModule->marginCB->setChecked(false);
1763 setCustomMargins(true);
1765 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1766 setCustomMargins(!bp_.use_geometry);
1771 void GuiDocument::papersizeChanged(int paper_size)
1773 setCustomPapersize(paper_size == 1);
1777 void GuiDocument::setCustomPapersize(bool custom)
1779 pageLayoutModule->paperwidthL->setEnabled(custom);
1780 pageLayoutModule->paperwidthLE->setEnabled(custom);
1781 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1782 pageLayoutModule->paperheightL->setEnabled(custom);
1783 pageLayoutModule->paperheightLE->setEnabled(custom);
1784 pageLayoutModule->paperheightLE->setFocus();
1785 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1789 void GuiDocument::setColSep()
1791 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1795 void GuiDocument::setCustomMargins(bool custom)
1797 marginsModule->topL->setEnabled(!custom);
1798 marginsModule->topLE->setEnabled(!custom);
1799 marginsModule->topUnit->setEnabled(!custom);
1801 marginsModule->bottomL->setEnabled(!custom);
1802 marginsModule->bottomLE->setEnabled(!custom);
1803 marginsModule->bottomUnit->setEnabled(!custom);
1805 marginsModule->innerL->setEnabled(!custom);
1806 marginsModule->innerLE->setEnabled(!custom);
1807 marginsModule->innerUnit->setEnabled(!custom);
1809 marginsModule->outerL->setEnabled(!custom);
1810 marginsModule->outerLE->setEnabled(!custom);
1811 marginsModule->outerUnit->setEnabled(!custom);
1813 marginsModule->headheightL->setEnabled(!custom);
1814 marginsModule->headheightLE->setEnabled(!custom);
1815 marginsModule->headheightUnit->setEnabled(!custom);
1817 marginsModule->headsepL->setEnabled(!custom);
1818 marginsModule->headsepLE->setEnabled(!custom);
1819 marginsModule->headsepUnit->setEnabled(!custom);
1821 marginsModule->footskipL->setEnabled(!custom);
1822 marginsModule->footskipLE->setEnabled(!custom);
1823 marginsModule->footskipUnit->setEnabled(!custom);
1825 bool const enableColSep = !custom &&
1826 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1827 marginsModule->columnsepL->setEnabled(enableColSep);
1828 marginsModule->columnsepLE->setEnabled(enableColSep);
1829 marginsModule->columnsepUnit->setEnabled(enableColSep);
1833 void GuiDocument::changeBackgroundColor()
1835 QColor const & newColor = QColorDialog::getColor(
1836 rgb2qcolor(set_backgroundcolor), asQWidget());
1837 if (!newColor.isValid())
1839 // set the button color and text
1840 colorModule->backgroundPB->setStyleSheet(
1841 colorButtonStyleSheet(newColor));
1842 colorModule->backgroundPB->setText(qt_("&Change..."));
1844 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1845 is_backgroundcolor = true;
1850 void GuiDocument::deleteBackgroundColor()
1852 // set the button color back to default by setting an empty StyleSheet
1853 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1854 // change button text
1855 colorModule->backgroundPB->setText(qt_("&Default..."));
1856 // save default color (white)
1857 set_backgroundcolor = rgbFromHexName("#ffffff");
1858 is_backgroundcolor = false;
1863 void GuiDocument::changeFontColor()
1865 QColor const & newColor = QColorDialog::getColor(
1866 rgb2qcolor(set_fontcolor), asQWidget());
1867 if (!newColor.isValid())
1869 // set the button color and text
1870 colorModule->fontColorPB->setStyleSheet(
1871 colorButtonStyleSheet(newColor));
1872 colorModule->fontColorPB->setText(qt_("&Change..."));
1874 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1875 is_fontcolor = true;
1880 void GuiDocument::deleteFontColor()
1882 // set the button color back to default by setting an empty StyleSheet
1883 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1884 // change button text
1885 colorModule->fontColorPB->setText(qt_("&Default..."));
1886 // save default color (black)
1887 set_fontcolor = rgbFromHexName("#000000");
1888 is_fontcolor = false;
1893 void GuiDocument::changeNoteFontColor()
1895 QColor const & newColor = QColorDialog::getColor(
1896 rgb2qcolor(set_notefontcolor), asQWidget());
1897 if (!newColor.isValid())
1899 // set the button color
1900 colorModule->noteFontColorPB->setStyleSheet(
1901 colorButtonStyleSheet(newColor));
1903 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1908 void GuiDocument::deleteNoteFontColor()
1910 // set the button color back to pref
1911 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1912 colorModule->noteFontColorPB->setStyleSheet(
1913 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1918 void GuiDocument::changeBoxBackgroundColor()
1920 QColor const & newColor = QColorDialog::getColor(
1921 rgb2qcolor(set_boxbgcolor), asQWidget());
1922 if (!newColor.isValid())
1924 // set the button color
1925 colorModule->boxBackgroundPB->setStyleSheet(
1926 colorButtonStyleSheet(newColor));
1928 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1933 void GuiDocument::deleteBoxBackgroundColor()
1935 // set the button color back to pref
1936 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1937 colorModule->boxBackgroundPB->setStyleSheet(
1938 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1943 void GuiDocument::updateQuoteStyles(bool const set)
1945 Language const * lang = lyx::languages.getLanguage(
1946 fromqstr(langModule->languageCO->itemData(
1947 langModule->languageCO->currentIndex()).toString()));
1949 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1951 langModule->quoteStyleCO->clear();
1953 bool has_default = false;
1954 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1955 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1956 if (qs == InsetQuotesParams::DynamicQuotes)
1958 bool const langdef = (qs == def);
1960 // add the default style on top
1961 langModule->quoteStyleCO->insertItem(0,
1962 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1966 langModule->quoteStyleCO->addItem(
1967 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1969 if (set && has_default)
1970 // (re)set to the default style
1971 langModule->quoteStyleCO->setCurrentIndex(0);
1975 void GuiDocument::languageChanged(int i)
1977 // some languages only work with polyglossia
1978 Language const * lang = lyx::languages.getLanguage(
1979 fromqstr(langModule->languageCO->itemData(i).toString()));
1980 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1981 // If we force to switch fontspec on, store
1982 // current state (#8717)
1983 if (fontModule->osFontsCB->isEnabled())
1984 forced_fontspec_activation =
1985 !fontModule->osFontsCB->isChecked();
1986 fontModule->osFontsCB->setChecked(true);
1987 fontModule->osFontsCB->setEnabled(false);
1990 fontModule->osFontsCB->setEnabled(true);
1991 // If we have forced to switch fontspec on,
1992 // restore previous state (#8717)
1993 if (forced_fontspec_activation)
1994 fontModule->osFontsCB->setChecked(false);
1995 forced_fontspec_activation = false;
1998 // set appropriate quotation mark style
1999 updateQuoteStyles(true);
2003 void GuiDocument::osFontsChanged(bool nontexfonts)
2005 bool const tex_fonts = !nontexfonts;
2006 // store current fonts
2007 QString const font_roman = fontModule->fontsRomanCO->itemData(
2008 fontModule->fontsRomanCO->currentIndex()).toString();
2009 QString const font_sans = fontModule->fontsSansCO->itemData(
2010 fontModule->fontsSansCO->currentIndex()).toString();
2011 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2012 fontModule->fontsTypewriterCO->currentIndex()).toString();
2013 QString const font_math = fontModule->fontsMathCO->itemData(
2014 fontModule->fontsMathCO->currentIndex()).toString();
2015 int const font_sf_scale = fontModule->scaleSansSB->value();
2016 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2019 // store default format
2020 QString const dformat = outputModule->defaultFormatCO->itemData(
2021 outputModule->defaultFormatCO->currentIndex()).toString();
2022 updateDefaultFormat();
2023 // try to restore default format
2024 int index = outputModule->defaultFormatCO->findData(dformat);
2025 // set to default if format is not found
2028 outputModule->defaultFormatCO->setCurrentIndex(index);
2030 // try to restore fonts which were selected two toggles ago
2031 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2033 fontModule->fontsRomanCO->setCurrentIndex(index);
2034 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2036 fontModule->fontsSansCO->setCurrentIndex(index);
2037 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2039 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2040 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2042 fontModule->fontsMathCO->setCurrentIndex(index);
2043 // save fonts for next next toggle
2044 fontModule->font_roman = font_roman;
2045 fontModule->font_sans = font_sans;
2046 fontModule->font_typewriter = font_typewriter;
2047 fontModule->font_math = font_math;
2048 fontModule->font_sf_scale = font_sf_scale;
2049 fontModule->font_tt_scale = font_tt_scale;
2051 langModule->encodingCO->setEnabled(tex_fonts &&
2052 !langModule->defaultencodingRB->isChecked());
2053 langModule->defaultencodingRB->setEnabled(tex_fonts);
2054 langModule->otherencodingRB->setEnabled(tex_fonts);
2056 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2057 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2058 fontModule->cjkFontLE->setEnabled(tex_fonts);
2059 fontModule->cjkFontLA->setEnabled(tex_fonts);
2061 updateFontOptions();
2063 fontModule->fontencLA->setEnabled(tex_fonts);
2064 fontModule->fontencCO->setEnabled(tex_fonts);
2066 fontModule->fontencLE->setEnabled(false);
2068 fontencChanged(fontModule->fontencCO->currentIndex());
2072 void GuiDocument::mathFontChanged(int)
2074 updateFontOptions();
2078 void GuiDocument::fontOsfToggled(bool state)
2080 if (fontModule->osFontsCB->isChecked())
2082 QString font = fontModule->fontsRomanCO->itemData(
2083 fontModule->fontsRomanCO->currentIndex()).toString();
2084 if (hasMonolithicExpertSet(font))
2085 fontModule->fontScCB->setChecked(state);
2089 void GuiDocument::fontScToggled(bool state)
2091 if (fontModule->osFontsCB->isChecked())
2093 QString font = fontModule->fontsRomanCO->itemData(
2094 fontModule->fontsRomanCO->currentIndex()).toString();
2095 if (hasMonolithicExpertSet(font))
2096 fontModule->fontOsfCB->setChecked(state);
2100 void GuiDocument::updateFontOptions()
2102 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2105 font = fontModule->fontsSansCO->itemData(
2106 fontModule->fontsSansCO->currentIndex()).toString();
2107 bool scaleable = providesScale(font);
2108 fontModule->scaleSansSB->setEnabled(scaleable);
2109 fontModule->scaleSansLA->setEnabled(scaleable);
2111 font = fontModule->fontsTypewriterCO->itemData(
2112 fontModule->fontsTypewriterCO->currentIndex()).toString();
2113 scaleable = providesScale(font);
2114 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2115 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2117 font = fontModule->fontsRomanCO->itemData(
2118 fontModule->fontsRomanCO->currentIndex()).toString();
2119 fontModule->fontScCB->setEnabled(providesSC(font));
2120 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2121 updateMathFonts(font);
2125 void GuiDocument::updateFontsize(string const & items, string const & sel)
2127 fontModule->fontsizeCO->clear();
2128 fontModule->fontsizeCO->addItem(qt_("Default"));
2130 for (int n = 0; !token(items,'|',n).empty(); ++n)
2131 fontModule->fontsizeCO->
2132 addItem(toqstr(token(items,'|',n)));
2134 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2135 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2136 fontModule->fontsizeCO->setCurrentIndex(n);
2143 bool GuiDocument::ot1() const
2145 QString const fontenc =
2146 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2147 return (fontenc == "default"
2148 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2149 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2153 bool GuiDocument::completeFontset() const
2155 return (fontModule->fontsSansCO->itemData(
2156 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2157 && fontModule->fontsSansCO->itemData(
2158 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2162 bool GuiDocument::noMathFont() const
2164 return (fontModule->fontsMathCO->itemData(
2165 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2169 void GuiDocument::updateTexFonts()
2171 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2173 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2174 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2175 for (; it != end; ++it) {
2176 LaTeXFont lf = it->second;
2177 if (lf.name().empty()) {
2178 LYXERR0("Error: Unnamed font: " << it->first);
2181 docstring const family = lf.family();
2182 docstring guiname = translateIfPossible(lf.guiname());
2183 if (!lf.available(ot1(), noMathFont()))
2184 guiname += _(" (not installed)");
2186 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2187 else if (family == "sf")
2188 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2189 else if (family == "tt")
2190 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2191 else if (family == "math")
2192 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2197 void GuiDocument::updateFontlist()
2199 fontModule->fontsRomanCO->clear();
2200 fontModule->fontsSansCO->clear();
2201 fontModule->fontsTypewriterCO->clear();
2202 fontModule->fontsMathCO->clear();
2204 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2205 if (fontModule->osFontsCB->isChecked()) {
2206 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2207 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2208 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2209 QString unimath = qt_("Non-TeX Fonts Default");
2210 if (!LaTeXFeatures::isAvailable("unicode-math"))
2211 unimath += qt_(" (not available)");
2212 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2213 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2215 QFontDatabase fontdb;
2216 QStringList families(fontdb.families());
2217 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2218 fontModule->fontsRomanCO->addItem(*it, *it);
2219 fontModule->fontsSansCO->addItem(*it, *it);
2220 fontModule->fontsTypewriterCO->addItem(*it, *it);
2225 if (rmfonts_.empty())
2228 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2229 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2230 while (rmi != rmfonts_.constEnd()) {
2231 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2235 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2236 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2237 while (sfi != sffonts_.constEnd()) {
2238 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2242 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2243 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2244 while (tti != ttfonts_.constEnd()) {
2245 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2249 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2250 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2251 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2252 while (mmi != mathfonts_.constEnd()) {
2253 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2259 void GuiDocument::fontencChanged(int item)
2261 fontModule->fontencLE->setEnabled(
2262 fontModule->fontencCO->itemData(item).toString() == "custom");
2263 // The availability of TeX fonts depends on the font encoding
2265 updateFontOptions();
2269 void GuiDocument::updateMathFonts(QString const & rm)
2271 if (fontModule->osFontsCB->isChecked())
2273 QString const math =
2274 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2275 int const i = fontModule->fontsMathCO->findData("default");
2276 if (providesNoMath(rm) && i == -1)
2277 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2278 else if (!providesNoMath(rm) && i != -1) {
2279 int const c = fontModule->fontsMathCO->currentIndex();
2280 fontModule->fontsMathCO->removeItem(i);
2282 fontModule->fontsMathCO->setCurrentIndex(0);
2287 void GuiDocument::romanChanged(int item)
2289 if (fontModule->osFontsCB->isChecked())
2291 QString const font =
2292 fontModule->fontsRomanCO->itemData(item).toString();
2293 fontModule->fontScCB->setEnabled(providesSC(font));
2294 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2295 updateMathFonts(font);
2299 void GuiDocument::sansChanged(int item)
2301 if (fontModule->osFontsCB->isChecked())
2303 QString const font =
2304 fontModule->fontsSansCO->itemData(item).toString();
2305 bool scaleable = providesScale(font);
2306 fontModule->scaleSansSB->setEnabled(scaleable);
2307 fontModule->scaleSansLA->setEnabled(scaleable);
2311 void GuiDocument::ttChanged(int item)
2313 if (fontModule->osFontsCB->isChecked())
2315 QString const font =
2316 fontModule->fontsTypewriterCO->itemData(item).toString();
2317 bool scaleable = providesScale(font);
2318 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2319 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2323 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2326 pageLayoutModule->pagestyleCO->clear();
2327 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2329 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2330 string style = token(items, '|', n);
2331 QString style_gui = qt_(style);
2332 pagestyles.push_back(pair<string, QString>(style, style_gui));
2333 pageLayoutModule->pagestyleCO->addItem(style_gui);
2336 if (sel == "default") {
2337 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2343 for (size_t i = 0; i < pagestyles.size(); ++i)
2344 if (pagestyles[i].first == sel)
2345 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2348 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2352 void GuiDocument::browseLayout()
2354 QString const label1 = qt_("Lay&outs");
2355 QString const dir1 = toqstr(lyxrc.document_path);
2356 QStringList const filter(qt_("LyX Layout (*.layout)"));
2357 QString file = browseRelToParent(QString(), bufferFilePath(),
2358 qt_("Local layout file"), filter, false,
2361 if (!file.endsWith(".layout"))
2364 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2365 fromqstr(bufferFilePath()));
2367 int const ret = Alert::prompt(_("Local layout file"),
2368 _("The layout file you have selected is a local layout\n"
2369 "file, not one in the system or user directory.\n"
2370 "Your document will not work with this layout if you\n"
2371 "move the layout file to a different directory."),
2372 1, 1, _("&Set Layout"), _("&Cancel"));
2376 // load the layout file
2377 LayoutFileList & bcl = LayoutFileList::get();
2378 string classname = layoutFile.onlyFileName();
2379 // this will update an existing layout if that layout has been loaded before.
2380 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2381 classname.substr(0, classname.size() - 7),
2382 layoutFile.onlyPath().absFileName()));
2385 Alert::error(_("Error"),
2386 _("Unable to read local layout file."));
2390 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2392 // do not trigger classChanged if there is no change.
2393 if (latexModule->classCO->currentText() == toqstr(name))
2397 bool const avail = latexModule->classCO->set(toqstr(name));
2399 LayoutFile const & tc = bcl[name];
2400 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2401 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2402 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2403 tooltip += '\n' + qt_("This is a local layout file.");
2404 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2405 toqstr(translateIfPossible(from_utf8(tc.category()))),
2407 true, true, true, true);
2408 latexModule->classCO->set(toqstr(name));
2415 void GuiDocument::browseMaster()
2417 QString const title = qt_("Select master document");
2418 QString const dir1 = toqstr(lyxrc.document_path);
2419 QString const old = latexModule->childDocLE->text();
2420 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2421 QStringList const filter(qt_("LyX Files (*.lyx)"));
2422 QString file = browseRelToSub(old, docpath, title, filter, false,
2423 qt_("D&ocuments"), toqstr(lyxrc.document_path));
2425 if (!file.isEmpty())
2426 latexModule->childDocLE->setText(file);
2430 void GuiDocument::classChanged_adaptor()
2432 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2437 void GuiDocument::classChanged()
2439 int idx = latexModule->classCO->currentIndex();
2442 string const classname = fromqstr(latexModule->classCO->getData(idx));
2444 if (applyPB->isEnabled()) {
2445 int const ret = Alert::prompt(_("Unapplied changes"),
2446 _("Some changes in the dialog were not yet applied.\n"
2447 "If you do not apply now, they will be lost after this action."),
2448 1, 1, _("&Apply"), _("&Dismiss"));
2453 // We load the TextClass as soon as it is selected. This is
2454 // necessary so that other options in the dialog can be updated
2455 // according to the new class. Note, however, that, if you use
2456 // the scroll wheel when sitting on the combo box, we'll load a
2457 // lot of TextClass objects very quickly....
2458 if (!bp_.setBaseClass(classname)) {
2459 Alert::error(_("Error"), _("Unable to set document class."));
2462 if (lyxrc.auto_reset_options)
2463 bp_.useClassDefaults();
2465 // With the introduction of modules came a distinction between the base
2466 // class and the document class. The former corresponds to the main layout
2467 // file; the latter is that plus the modules (or the document-specific layout,
2468 // or whatever else there could be). Our parameters come from the document
2469 // class. So when we set the base class, we also need to recreate the document
2470 // class. Otherwise, we still have the old one.
2471 bp_.makeDocumentClass();
2476 void GuiDocument::languagePackageChanged(int i)
2478 langModule->languagePackageLE->setEnabled(
2479 langModule->languagePackageCO->itemData(i).toString() == "custom");
2483 void GuiDocument::biblioChanged()
2485 biblioChanged_ = true;
2490 void GuiDocument::checkPossibleCiteEngines()
2492 // Check if the class provides a specific engine,
2493 // and if so, enforce this.
2494 string force_engine;
2495 if (documentClass().provides("natbib")
2496 || documentClass().provides("natbib-internal"))
2497 force_engine = "natbib";
2498 else if (documentClass().provides("jurabib"))
2499 force_engine = "jurabib";
2500 else if (documentClass().provides("biblatex"))
2501 force_engine = "biblatex";
2502 else if (documentClass().provides("biblatex-natbib"))
2503 force_engine = "biblatex-natbib";
2505 if (!force_engine.empty())
2506 biblioModule->citeEngineCO->setCurrentIndex(
2507 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2508 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2512 void GuiDocument::rescanBibFiles()
2515 rescanTexStyles("bbx cbx");
2517 rescanTexStyles("bst");
2521 void GuiDocument::resetDefaultBibfile(string const & which)
2523 QString const engine =
2524 biblioModule->citeEngineCO->itemData(
2525 biblioModule->citeEngineCO->currentIndex()).toString();
2527 CiteEngineType const cet =
2528 CiteEngineType(biblioModule->citeStyleCO->itemData(
2529 biblioModule->citeStyleCO->currentIndex()).toInt());
2531 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2535 void GuiDocument::resetDefaultBbxBibfile()
2537 resetDefaultBibfile("bbx");
2541 void GuiDocument::resetDefaultCbxBibfile()
2543 resetDefaultBibfile("cbx");
2547 void GuiDocument::citeEngineChanged(int n)
2549 QString const engine =
2550 biblioModule->citeEngineCO->itemData(n).toString();
2552 vector<string> const engs =
2553 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2555 updateCiteStyles(engs);
2556 updateEngineDependends();
2557 resetDefaultBibfile();
2562 void GuiDocument::updateEngineDependends()
2564 bool const biblatex = isBiblatex();
2566 // These are only useful with BibTeX
2567 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2568 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2569 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2570 biblioModule->bibtopicCB->setEnabled(!biblatex);
2572 // These are only useful with Biblatex
2573 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2574 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2575 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2576 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2577 biblioModule->resetBbxPB->setEnabled(biblatex);
2578 biblioModule->resetCbxPB->setEnabled(biblatex);
2579 biblioModule->matchBbxPB->setEnabled(biblatex);
2581 // These are useful with biblatex, jurabib and natbib
2582 QString const engine =
2583 biblioModule->citeEngineCO->itemData(
2584 biblioModule->citeEngineCO->currentIndex()).toString();
2585 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2587 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2588 || ce->requires("natbib.sty");
2589 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2590 biblioModule->citePackageOptionsL->setEnabled(citepack);
2594 void GuiDocument::citeStyleChanged()
2596 QString const engine =
2597 biblioModule->citeEngineCO->itemData(
2598 biblioModule->citeEngineCO->currentIndex()).toString();
2599 QString const currentDef = isBiblatex() ?
2600 biblioModule->biblatexBbxCO->currentText()
2601 : biblioModule->defaultBiblioCO->currentText();
2602 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2603 resetDefaultBibfile();
2609 void GuiDocument::bibtexChanged(int n)
2611 biblioModule->bibtexOptionsLE->setEnabled(
2612 biblioModule->bibtexCO->itemData(n).toString() != "default");
2617 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2619 biblioModule->citeStyleCO->clear();
2621 vector<string>::const_iterator it = engs.begin();
2622 vector<string>::const_iterator end = engs.end();
2623 for (; it != end; ++it) {
2624 if (*it == "default")
2625 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2626 ENGINE_TYPE_DEFAULT);
2627 else if (*it == "authoryear")
2628 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2629 ENGINE_TYPE_AUTHORYEAR);
2630 else if (*it == "numerical")
2631 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2632 ENGINE_TYPE_NUMERICAL);
2634 int i = biblioModule->citeStyleCO->findData(sel);
2635 if (biblioModule->citeStyleCO->findData(sel) == -1)
2637 biblioModule->citeStyleCO->setCurrentIndex(i);
2639 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2640 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2644 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2646 engine_types_.clear();
2650 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2652 string style = token(items, '|', n);
2653 engine_types_.push_back(style);
2656 updateCiteStyles(engine_types_, sel);
2662 // both of these should take a vector<docstring>
2664 // This is an insanely complicated attempt to make this sort of thing
2665 // work with RTL languages.
2666 docstring formatStrVec(vector<string> const & v, docstring const & s)
2668 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2672 return translateIfPossible(from_utf8(v[0]));
2673 if (v.size() == 2) {
2674 docstring retval = _("%1$s and %2$s");
2675 retval = subst(retval, _("and"), s);
2676 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2677 translateIfPossible(from_utf8(v[1])));
2679 // The idea here is to format all but the last two items...
2680 int const vSize = v.size();
2681 docstring t2 = _("%1$s, %2$s");
2682 docstring retval = translateIfPossible(from_utf8(v[0]));
2683 for (int i = 1; i < vSize - 2; ++i)
2684 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2685 //...and then to plug them, and the last two, into this schema
2686 docstring t = _("%1$s, %2$s, and %3$s");
2687 t = subst(t, _("and"), s);
2688 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2689 translateIfPossible(from_utf8(v[vSize - 1])));
2692 vector<string> idsToNames(vector<string> const & idList)
2694 vector<string> retval;
2695 vector<string>::const_iterator it = idList.begin();
2696 vector<string>::const_iterator end = idList.end();
2697 for (; it != end; ++it) {
2698 LyXModule const * const mod = theModuleList[*it];
2700 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2701 translateIfPossible(from_utf8(*it)))));
2703 retval.push_back(mod->getName());
2707 } // end anonymous namespace
2710 void GuiDocument::modulesToParams(BufferParams & bp)
2712 // update list of loaded modules
2713 bp.clearLayoutModules();
2714 int const srows = modules_sel_model_.rowCount();
2715 for (int i = 0; i < srows; ++i)
2716 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2718 // update the list of removed modules
2719 bp.clearRemovedModules();
2720 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2721 list<string>::const_iterator rit = reqmods.begin();
2722 list<string>::const_iterator ren = reqmods.end();
2724 // check each of the default modules
2725 for (; rit != ren; ++rit) {
2726 list<string>::const_iterator mit = bp.getModules().begin();
2727 list<string>::const_iterator men = bp.getModules().end();
2729 for (; mit != men; ++mit) {
2736 // the module isn't present so must have been removed by the user
2737 bp.addRemovedModule(*rit);
2742 void GuiDocument::modulesChanged()
2744 modulesToParams(bp_);
2746 if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2747 int const ret = Alert::prompt(_("Unapplied changes"),
2748 _("Some changes in the dialog were not yet applied.\n"
2749 "If you do not apply now, they will be lost after this action."),
2750 1, 1, _("&Apply"), _("&Dismiss"));
2755 modulesChanged_ = true;
2756 bp_.makeDocumentClass();
2762 void GuiDocument::updateModuleInfo()
2764 selectionManager->update();
2766 //Module description
2767 bool const focus_on_selected = selectionManager->selectedFocused();
2768 QAbstractItemView * lv;
2769 if (focus_on_selected)
2770 lv = modulesModule->selectedLV;
2772 lv = modulesModule->availableLV;
2773 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2774 modulesModule->infoML->document()->clear();
2777 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2778 GuiIdListModel const & id_model =
2779 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2780 string const modName = id_model.getIDString(idx.row());
2781 docstring desc = getModuleDescription(modName);
2783 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2784 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2787 desc += _("Module provided by document class.");
2790 docstring cat = getModuleCategory(modName);
2794 desc += bformat(_("Category: %1$s."), cat);
2797 vector<string> pkglist = getPackageList(modName);
2798 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2799 if (!pkgdesc.empty()) {
2802 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2805 pkglist = getRequiredList(modName);
2806 if (!pkglist.empty()) {
2807 vector<string> const reqdescs = idsToNames(pkglist);
2808 pkgdesc = formatStrVec(reqdescs, _("or"));
2811 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2814 pkglist = getExcludedList(modName);
2815 if (!pkglist.empty()) {
2816 vector<string> const reqdescs = idsToNames(pkglist);
2817 pkgdesc = formatStrVec(reqdescs, _( "and"));
2820 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2823 if (!isModuleAvailable(modName)) {
2826 desc += _("WARNING: Some required packages are unavailable!");
2829 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2833 void GuiDocument::updateNumbering()
2835 DocumentClass const & tclass = documentClass();
2837 numberingModule->tocTW->setUpdatesEnabled(false);
2838 numberingModule->tocTW->clear();
2840 int const depth = numberingModule->depthSL->value();
2841 int const toc = numberingModule->tocSL->value();
2842 QString const no = qt_("No");
2843 QString const yes = qt_("Yes");
2844 QTreeWidgetItem * item = 0;
2846 DocumentClass::const_iterator lit = tclass.begin();
2847 DocumentClass::const_iterator len = tclass.end();
2848 for (; lit != len; ++lit) {
2849 int const toclevel = lit->toclevel;
2850 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2851 item = new QTreeWidgetItem(numberingModule->tocTW);
2852 item->setText(0, toqstr(translateIfPossible(lit->name())));
2853 item->setText(1, (toclevel <= depth) ? yes : no);
2854 item->setText(2, (toclevel <= toc) ? yes : no);
2858 numberingModule->tocTW->setUpdatesEnabled(true);
2859 numberingModule->tocTW->update();
2863 void GuiDocument::updateDefaultFormat()
2867 // make a copy in order to consider unapplied changes
2868 BufferParams param_copy = buffer().params();
2869 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2870 int const idx = latexModule->classCO->currentIndex();
2872 string const classname = fromqstr(latexModule->classCO->getData(idx));
2873 param_copy.setBaseClass(classname);
2874 param_copy.makeDocumentClass(true);
2876 outputModule->defaultFormatCO->blockSignals(true);
2877 outputModule->defaultFormatCO->clear();
2878 outputModule->defaultFormatCO->addItem(qt_("Default"),
2879 QVariant(QString("default")));
2880 FormatList const & formats =
2881 param_copy.exportableFormats(true);
2882 for (Format const * f : formats)
2883 outputModule->defaultFormatCO->addItem
2884 (toqstr(translateIfPossible(f->prettyname())),
2885 QVariant(toqstr(f->name())));
2886 outputModule->defaultFormatCO->blockSignals(false);
2890 bool GuiDocument::isChildIncluded(string const & child)
2892 if (includeonlys_.empty())
2894 return (std::find(includeonlys_.begin(),
2895 includeonlys_.end(), child) != includeonlys_.end());
2899 void GuiDocument::applyView()
2902 preambleModule->apply(bp_);
2903 localLayout->apply(bp_);
2906 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2907 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2910 string const engine =
2911 fromqstr(biblioModule->citeEngineCO->itemData(
2912 biblioModule->citeEngineCO->currentIndex()).toString());
2913 bp_.setCiteEngine(engine);
2915 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2916 biblioModule->citeStyleCO->currentIndex()).toInt());
2917 if (theCiteEnginesList[engine]->hasEngineType(style))
2918 bp_.setCiteEngineType(style);
2920 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2922 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2924 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2925 biblioModule->bibunitsCO->currentIndex()).toString());
2927 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2929 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2930 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2931 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2933 string const bibtex_command =
2934 fromqstr(biblioModule->bibtexCO->itemData(
2935 biblioModule->bibtexCO->currentIndex()).toString());
2936 string const bibtex_options =
2937 fromqstr(biblioModule->bibtexOptionsLE->text());
2938 if (bibtex_command == "default" || bibtex_options.empty())
2939 bp_.bibtex_command = bibtex_command;
2941 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2943 if (biblioChanged_) {
2944 buffer().invalidateBibinfoCache();
2945 buffer().removeBiblioTempFiles();
2949 indicesModule->apply(bp_);
2951 // language & quotes
2952 if (langModule->defaultencodingRB->isChecked()) {
2953 bp_.inputenc = "auto";
2955 int i = langModule->encodingCO->currentIndex();
2957 bp_.inputenc = "default";
2959 QString const enc_gui =
2960 langModule->encodingCO->currentText();
2961 Encodings::const_iterator it = encodings.begin();
2962 Encodings::const_iterator const end = encodings.end();
2964 for (; it != end; ++it) {
2965 if (qt_(it->guiName()) == enc_gui &&
2967 bp_.inputenc = it->name();
2973 // should not happen
2974 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2975 bp_.inputenc = "default";
2980 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2981 langModule->quoteStyleCO->currentIndex()).toInt();
2982 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2984 QString const langname = langModule->languageCO->itemData(
2985 langModule->languageCO->currentIndex()).toString();
2986 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2987 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2988 // If current cursor language was the document language, then update it too.
2989 if (cur.current_font.language() == bp_.language) {
2990 cur.current_font.setLanguage(newlang);
2991 cur.real_current_font.setLanguage(newlang);
2993 bp_.language = newlang;
2995 QString const pack = langModule->languagePackageCO->itemData(
2996 langModule->languagePackageCO->currentIndex()).toString();
2997 if (pack == "custom")
2999 fromqstr(langModule->languagePackageLE->text());
3001 bp_.lang_package = fromqstr(pack);
3004 bp_.backgroundcolor = set_backgroundcolor;
3005 bp_.isbackgroundcolor = is_backgroundcolor;
3006 bp_.fontcolor = set_fontcolor;
3007 bp_.isfontcolor = is_fontcolor;
3008 bp_.notefontcolor = set_notefontcolor;
3009 bp_.boxbgcolor = set_boxbgcolor;
3012 if (bp_.documentClass().hasTocLevels()) {
3013 bp_.tocdepth = numberingModule->tocSL->value();
3014 bp_.secnumdepth = numberingModule->depthSL->value();
3018 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3019 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3020 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3021 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3024 bp_.graphics_driver =
3025 tex_graphics[latexModule->psdriverCO->currentIndex()];
3028 int idx = latexModule->classCO->currentIndex();
3030 string const classname = fromqstr(latexModule->classCO->getData(idx));
3031 bp_.setBaseClass(classname);
3035 modulesToParams(bp_);
3038 map<string, string> const & packages = BufferParams::auto_packages();
3039 for (map<string, string>::const_iterator it = packages.begin();
3040 it != packages.end(); ++it) {
3041 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3044 int row = mathsModule->packagesTW->row(item);
3047 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3048 if (rb->isChecked()) {
3049 bp_.use_package(it->first, BufferParams::package_auto);
3052 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3053 if (rb->isChecked()) {
3054 bp_.use_package(it->first, BufferParams::package_on);
3057 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3058 if (rb->isChecked())
3059 bp_.use_package(it->first, BufferParams::package_off);
3061 // if math is indented
3062 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3063 if (bp_.is_math_indent) {
3064 // if formulas are indented
3065 switch (mathsModule->MathIndentCO->currentIndex()) {
3067 bp_.setMathIndent(Length());
3070 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3071 mathsModule->MathIndentLengthCO));
3072 bp_.setMathIndent(mathindent);
3076 // this should never happen
3077 bp_.setMathIndent(Length());
3081 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3083 bp_.math_numbering_side = BufferParams::LEFT;
3086 bp_.math_numbering_side = BufferParams::DEFAULT;
3089 bp_.math_numbering_side = BufferParams::RIGHT;
3092 // this should never happen
3093 bp_.math_numbering_side = BufferParams::DEFAULT;
3098 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3099 bp_.pagestyle = "default";
3101 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3102 for (size_t i = 0; i != pagestyles.size(); ++i)
3103 if (pagestyles[i].second == style_gui)
3104 bp_.pagestyle = pagestyles[i].first;
3108 switch (textLayoutModule->lspacingCO->currentIndex()) {
3110 bp_.spacing().set(Spacing::Single);
3113 bp_.spacing().set(Spacing::Onehalf);
3116 bp_.spacing().set(Spacing::Double);
3119 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3121 bp_.spacing().set(Spacing::Single);
3123 bp_.spacing().set(Spacing::Other, s);
3128 if (textLayoutModule->twoColumnCB->isChecked())
3133 bp_.justification = textLayoutModule->justCB->isChecked();
3135 if (textLayoutModule->indentRB->isChecked()) {
3136 // if paragraphs are separated by an indentation
3137 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3138 switch (textLayoutModule->indentCO->currentIndex()) {
3140 bp_.setParIndent(Length());
3143 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3144 textLayoutModule->indentLengthCO));
3145 bp_.setParIndent(parindent);
3149 // this should never happen
3150 bp_.setParIndent(Length());
3154 // if paragraphs are separated by a skip
3155 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3156 switch (textLayoutModule->skipCO->currentIndex()) {
3158 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3161 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3164 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3169 widgetsToLength(textLayoutModule->skipLE,
3170 textLayoutModule->skipLengthCO)
3176 // this should never happen
3177 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3183 fromqstr(latexModule->optionsLE->text());
3185 bp_.use_default_options =
3186 latexModule->defaultOptionsCB->isChecked();
3188 if (latexModule->childDocGB->isChecked())
3190 fromqstr(latexModule->childDocLE->text());
3192 bp_.master = string();
3195 bp_.clearIncludedChildren();
3196 if (masterChildModule->includeonlyRB->isChecked()) {
3197 list<string>::const_iterator it = includeonlys_.begin();
3198 for (; it != includeonlys_.end() ; ++it) {
3199 bp_.addIncludedChildren(*it);
3202 bp_.maintain_unincluded_children =
3203 masterChildModule->maintainAuxCB->isChecked();
3206 bp_.float_placement = floatModule->get();
3209 // text should have passed validation
3210 idx = listingsModule->packageCO->currentIndex();
3211 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3212 bp_.listings_params =
3213 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3216 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3217 outputModule->defaultFormatCO->currentIndex()).toString());
3219 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3220 bp_.useNonTeXFonts = nontexfonts;
3222 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3223 if (!bp_.shell_escape)
3224 theSession().shellescapeFiles().remove(buffer().absFileName());
3225 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3226 theSession().shellescapeFiles().insert(buffer().absFileName());
3227 Buffer & buf = const_cast<Buffer &>(buffer());
3228 buf.params().shell_escape = bp_.shell_escape;
3230 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3232 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3234 int mathfmt = outputModule->mathoutCB->currentIndex();
3237 BufferParams::MathOutput const mo =
3238 static_cast<BufferParams::MathOutput>(mathfmt);
3239 bp_.html_math_output = mo;
3240 bp_.html_be_strict = outputModule->strictCB->isChecked();
3241 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3242 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3243 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3245 bp_.save_transient_properties =
3246 outputModule->saveTransientPropertiesCB->isChecked();
3249 bp_.fonts_roman[nontexfonts] =
3250 fromqstr(fontModule->fontsRomanCO->
3251 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3252 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3254 bp_.fonts_sans[nontexfonts] =
3255 fromqstr(fontModule->fontsSansCO->
3256 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3257 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3259 bp_.fonts_typewriter[nontexfonts] =
3260 fromqstr(fontModule->fontsTypewriterCO->
3261 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3262 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3264 bp_.fonts_math[nontexfonts] =
3265 fromqstr(fontModule->fontsMathCO->
3266 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3267 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3269 QString const fontenc =
3270 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3271 if (fontenc == "custom")
3272 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3274 bp_.fontenc = fromqstr(fontenc);
3277 fromqstr(fontModule->cjkFontLE->text());
3279 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3280 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3282 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3283 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3285 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3286 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3288 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3290 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3293 bp_.fonts_default_family = "default";
3295 bp_.fonts_default_family = GuiDocument::fontfamilies[
3296 fontModule->fontsDefaultCO->currentIndex()];
3298 if (fontModule->fontsizeCO->currentIndex() == 0)
3299 bp_.fontsize = "default";
3302 fromqstr(fontModule->fontsizeCO->currentText());
3305 bp_.papersize = PAPER_SIZE(
3306 pageLayoutModule->papersizeCO->currentIndex());
3308 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3309 pageLayoutModule->paperwidthUnitCO);
3311 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3312 pageLayoutModule->paperheightUnitCO);
3314 if (pageLayoutModule->facingPagesCB->isChecked())
3315 bp_.sides = TwoSides;
3317 bp_.sides = OneSide;
3319 if (pageLayoutModule->landscapeRB->isChecked())
3320 bp_.orientation = ORIENTATION_LANDSCAPE;
3322 bp_.orientation = ORIENTATION_PORTRAIT;
3325 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3327 Ui::MarginsUi const * m = marginsModule;
3329 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3330 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3331 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3332 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3333 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3334 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3335 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3336 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3339 branchesModule->apply(bp_);
3342 PDFOptions & pdf = bp_.pdfoptions();
3343 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3344 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3345 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3346 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3347 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3349 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3350 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3351 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3352 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3354 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3355 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3356 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3357 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3359 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3360 if (pdfSupportModule->fullscreenCB->isChecked())
3361 pdf.pagemode = pdf.pagemode_fullscreen;
3363 pdf.pagemode.clear();
3364 pdf.quoted_options = pdf.quoted_options_check(
3365 fromqstr(pdfSupportModule->optionsLE->text()));
3368 nonModuleChanged_ = false;
3369 shellescapeChanged_ = false;
3373 void GuiDocument::paramsToDialog()
3375 // set the default unit
3376 Length::UNIT const default_unit = Length::defaultUnit();
3379 preambleModule->update(bp_, id());
3380 localLayout->update(bp_, id());
3383 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3384 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3387 string const cite_engine = bp_.citeEngine().list().front();
3389 biblioModule->citeEngineCO->setCurrentIndex(
3390 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3392 updateEngineType(documentClass().opt_enginetype(),
3393 bp_.citeEngineType());
3395 checkPossibleCiteEngines();
3397 biblioModule->citeStyleCO->setCurrentIndex(
3398 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3400 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3402 biblioModule->bibunitsCO->clear();
3403 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3404 if (documentClass().hasLaTeXLayout("part"))
3405 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3406 if (documentClass().hasLaTeXLayout("chapter"))
3407 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3408 if (documentClass().hasLaTeXLayout("section"))
3409 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3410 if (documentClass().hasLaTeXLayout("subsection"))
3411 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3412 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3414 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3416 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3418 biblioModule->bibunitsCO->setCurrentIndex(0);
3420 updateEngineDependends();
3423 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3424 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3426 updateDefaultBiblio(bp_.defaultBiblioStyle());
3428 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3432 split(bp_.bibtex_command, command, ' ');
3434 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3436 biblioModule->bibtexCO->setCurrentIndex(bpos);
3437 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3439 // We reset to default if we do not know the specified compiler
3440 // This is for security reasons
3441 biblioModule->bibtexCO->setCurrentIndex(
3442 biblioModule->bibtexCO->findData(toqstr("default")));
3443 biblioModule->bibtexOptionsLE->clear();
3445 biblioModule->bibtexOptionsLE->setEnabled(
3446 biblioModule->bibtexCO->currentIndex() != 0);
3448 biblioChanged_ = false;
3451 // We may be called when there is no Buffer, e.g., when
3452 // the last view has just been closed.
3453 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3454 indicesModule->update(bp_, isReadOnly);
3456 // language & quotes
3457 int const pos = langModule->languageCO->findData(toqstr(
3458 bp_.language->lang()));
3459 langModule->languageCO->setCurrentIndex(pos);
3461 updateQuoteStyles();
3463 langModule->quoteStyleCO->setCurrentIndex(
3464 langModule->quoteStyleCO->findData(bp_.quotes_style));
3465 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3467 bool default_enc = true;
3468 if (bp_.inputenc != "auto") {
3469 default_enc = false;
3470 if (bp_.inputenc == "default") {
3471 langModule->encodingCO->setCurrentIndex(0);
3474 Encodings::const_iterator it = encodings.begin();
3475 Encodings::const_iterator const end = encodings.end();
3476 for (; it != end; ++it) {
3477 if (it->name() == bp_.inputenc &&
3479 enc_gui = it->guiName();
3483 int const i = langModule->encodingCO->findText(
3486 langModule->encodingCO->setCurrentIndex(i);
3488 // unknown encoding. Set to default.
3492 langModule->defaultencodingRB->setChecked(default_enc);
3493 langModule->otherencodingRB->setChecked(!default_enc);
3495 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3497 langModule->languagePackageCO->setCurrentIndex(
3498 langModule->languagePackageCO->findData("custom"));
3499 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3501 langModule->languagePackageCO->setCurrentIndex(p);
3502 langModule->languagePackageLE->clear();
3506 if (bp_.isfontcolor) {
3507 colorModule->fontColorPB->setStyleSheet(
3508 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3510 set_fontcolor = bp_.fontcolor;
3511 is_fontcolor = bp_.isfontcolor;
3513 colorModule->noteFontColorPB->setStyleSheet(
3514 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3515 set_notefontcolor = bp_.notefontcolor;
3517 if (bp_.isbackgroundcolor) {
3518 colorModule->backgroundPB->setStyleSheet(
3519 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3521 set_backgroundcolor = bp_.backgroundcolor;
3522 is_backgroundcolor = bp_.isbackgroundcolor;
3524 colorModule->boxBackgroundPB->setStyleSheet(
3525 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3526 set_boxbgcolor = bp_.boxbgcolor;
3529 int const min_toclevel = documentClass().min_toclevel();
3530 int const max_toclevel = documentClass().max_toclevel();
3531 if (documentClass().hasTocLevels()) {
3532 numberingModule->setEnabled(true);
3533 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3534 numberingModule->depthSL->setMaximum(max_toclevel);
3535 numberingModule->depthSL->setValue(bp_.secnumdepth);
3536 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3537 numberingModule->tocSL->setMaximum(max_toclevel);
3538 numberingModule->tocSL->setValue(bp_.tocdepth);
3541 numberingModule->setEnabled(false);
3542 numberingModule->tocTW->clear();
3546 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3547 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3548 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3549 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3550 bulletsModule->init();
3553 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3555 latexModule->psdriverCO->setCurrentIndex(nitem);
3559 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3560 if (bp_.is_math_indent) {
3561 Length const mathindent = bp_.getMathIndent();
3563 if (!mathindent.empty()) {
3564 lengthToWidgets(mathsModule->MathIndentLE,
3565 mathsModule->MathIndentLengthCO,
3566 mathindent, default_unit);
3569 mathsModule->MathIndentCO->setCurrentIndex(indent);
3570 enableMathIndent(indent);
3572 switch(bp_.math_numbering_side) {
3573 case BufferParams::LEFT:
3574 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3576 case BufferParams::DEFAULT:
3577 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3579 case BufferParams::RIGHT:
3580 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3583 map<string, string> const & packages = BufferParams::auto_packages();
3584 for (map<string, string>::const_iterator it = packages.begin();
3585 it != packages.end(); ++it) {
3586 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3589 int row = mathsModule->packagesTW->row(item);
3590 switch (bp_.use_package(it->first)) {
3591 case BufferParams::package_off: {
3593 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3594 rb->setChecked(true);
3597 case BufferParams::package_on: {
3599 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3600 rb->setChecked(true);
3603 case BufferParams::package_auto: {
3605 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3606 rb->setChecked(true);
3612 switch (bp_.spacing().getSpace()) {
3613 case Spacing::Other: nitem = 3; break;
3614 case Spacing::Double: nitem = 2; break;
3615 case Spacing::Onehalf: nitem = 1; break;
3616 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3620 string const & layoutID = bp_.baseClassID();
3621 setLayoutComboByIDString(layoutID);
3623 updatePagestyle(documentClass().opt_pagestyle(),
3626 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3627 if (bp_.spacing().getSpace() == Spacing::Other) {
3628 doubleToWidget(textLayoutModule->lspacingLE,
3629 bp_.spacing().getValueAsString());
3633 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3634 textLayoutModule->indentRB->setChecked(true);
3635 string parindent = bp_.getParIndent().asString();
3637 if (!parindent.empty()) {
3638 lengthToWidgets(textLayoutModule->indentLE,
3639 textLayoutModule->indentLengthCO,
3640 parindent, default_unit);
3643 textLayoutModule->indentCO->setCurrentIndex(indent);
3646 textLayoutModule->skipRB->setChecked(true);
3648 switch (bp_.getDefSkip().kind()) {
3649 case VSpace::SMALLSKIP:
3652 case VSpace::MEDSKIP:
3655 case VSpace::BIGSKIP:
3658 case VSpace::LENGTH:
3661 string const length = bp_.getDefSkip().asLyXCommand();
3662 lengthToWidgets(textLayoutModule->skipLE,
3663 textLayoutModule->skipLengthCO,
3664 length, default_unit);
3671 textLayoutModule->skipCO->setCurrentIndex(skip);
3675 textLayoutModule->twoColumnCB->setChecked(
3677 textLayoutModule->justCB->setChecked(bp_.justification);
3679 if (!bp_.options.empty()) {
3680 latexModule->optionsLE->setText(
3681 toqstr(bp_.options));
3683 latexModule->optionsLE->setText(QString());
3687 latexModule->defaultOptionsCB->setChecked(
3688 bp_.use_default_options);
3689 updateSelectedModules();
3690 selectionManager->updateProvidedModules(
3691 bp_.baseClass()->providedModules());
3692 selectionManager->updateExcludedModules(
3693 bp_.baseClass()->excludedModules());
3695 if (!documentClass().options().empty()) {
3696 latexModule->defaultOptionsLE->setText(
3697 toqstr(documentClass().options()));
3699 latexModule->defaultOptionsLE->setText(
3700 toqstr(_("[No options predefined]")));
3703 latexModule->defaultOptionsLE->setEnabled(
3704 bp_.use_default_options
3705 && !documentClass().options().empty());
3707 latexModule->defaultOptionsCB->setEnabled(
3708 !documentClass().options().empty());
3710 if (!bp_.master.empty()) {
3711 latexModule->childDocGB->setChecked(true);
3712 latexModule->childDocLE->setText(
3713 toqstr(bp_.master));
3715 latexModule->childDocLE->setText(QString());
3716 latexModule->childDocGB->setChecked(false);
3720 if (!bufferview() || !buffer().hasChildren()) {
3721 masterChildModule->childrenTW->clear();
3722 includeonlys_.clear();
3723 docPS->showPanel("Child Documents", false);
3724 if (docPS->isCurrentPanel("Child Documents"))
3725 docPS->setCurrentPanel("Document Class");
3727 docPS->showPanel("Child Documents", true);
3728 masterChildModule->setEnabled(true);
3729 includeonlys_ = bp_.getIncludedChildren();
3730 updateIncludeonlys();
3732 masterChildModule->maintainAuxCB->setChecked(
3733 bp_.maintain_unincluded_children);
3736 floatModule->set(bp_.float_placement);
3739 // break listings_params to multiple lines
3741 InsetListingsParams(bp_.listings_params).separatedParams();
3742 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3743 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3745 listingsModule->packageCO->setCurrentIndex(nn);
3749 // some languages only work with polyglossia/XeTeX
3750 Language const * lang = lyx::languages.getLanguage(
3751 fromqstr(langModule->languageCO->itemData(
3752 langModule->languageCO->currentIndex()).toString()));
3753 bool const need_fontspec =
3754 lang->babel().empty() && !lang->polyglossia().empty();
3755 bool const os_fonts_available =
3756 bp_.baseClass()->outputType() == lyx::LATEX
3757 && LaTeXFeatures::isAvailable("fontspec");
3758 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3759 fontModule->osFontsCB->setChecked(
3760 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3761 updateFontsize(documentClass().opt_fontsize(),
3764 QString font = toqstr(bp_.fontsRoman());
3765 int rpos = fontModule->fontsRomanCO->findData(font);
3767 rpos = fontModule->fontsRomanCO->count();
3768 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3770 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3771 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3773 font = toqstr(bp_.fontsSans());
3774 int spos = fontModule->fontsSansCO->findData(font);
3776 spos = fontModule->fontsSansCO->count();
3777 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3779 fontModule->fontsSansCO->setCurrentIndex(spos);
3780 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3782 font = toqstr(bp_.fontsTypewriter());
3783 int tpos = fontModule->fontsTypewriterCO->findData(font);
3785 tpos = fontModule->fontsTypewriterCO->count();
3786 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3788 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3789 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3791 font = toqstr(bp_.fontsMath());
3792 int mpos = fontModule->fontsMathCO->findData(font);
3794 mpos = fontModule->fontsMathCO->count();
3795 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3797 fontModule->fontsMathCO->setCurrentIndex(mpos);
3798 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3800 if (bp_.useNonTeXFonts && os_fonts_available) {
3801 fontModule->fontencLA->setEnabled(false);
3802 fontModule->fontencCO->setEnabled(false);
3803 fontModule->fontencLE->setEnabled(false);
3805 fontModule->fontencLA->setEnabled(true);
3806 fontModule->fontencCO->setEnabled(true);
3807 fontModule->fontencLE->setEnabled(true);
3813 if (!bp_.fonts_cjk.empty())
3814 fontModule->cjkFontLE->setText(
3815 toqstr(bp_.fonts_cjk));
3817 fontModule->cjkFontLE->setText(QString());
3819 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3820 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3822 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3823 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3824 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3825 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3826 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3827 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3829 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3831 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3833 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3834 fontModule->fontencCO->setCurrentIndex(
3835 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3836 fontModule->fontencLE->setEnabled(false);
3838 fontModule->fontencCO->setCurrentIndex(1);
3839 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3843 // This must be set _after_ fonts since updateDefaultFormat()
3844 // checks osFontsCB settings.
3845 // update combobox with formats
3846 updateDefaultFormat();
3847 int index = outputModule->defaultFormatCO->findData(toqstr(
3848 bp_.default_output_format));
3849 // set to default if format is not found
3852 outputModule->defaultFormatCO->setCurrentIndex(index);
3854 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3855 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3856 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3858 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3859 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3860 outputModule->strictCB->setChecked(bp_.html_be_strict);
3861 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3863 outputModule->saveTransientPropertiesCB
3864 ->setChecked(bp_.save_transient_properties);
3867 bool const extern_geometry =
3868 documentClass().provides("geometry");
3869 int const psize = bp_.papersize;
3870 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3871 setCustomPapersize(!extern_geometry && psize == 1);
3872 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3874 bool const landscape =
3875 bp_.orientation == ORIENTATION_LANDSCAPE;
3876 pageLayoutModule->landscapeRB->setChecked(landscape);
3877 pageLayoutModule->portraitRB->setChecked(!landscape);
3878 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3879 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3881 pageLayoutModule->facingPagesCB->setChecked(
3882 bp_.sides == TwoSides);
3884 lengthToWidgets(pageLayoutModule->paperwidthLE,
3885 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3886 lengthToWidgets(pageLayoutModule->paperheightLE,
3887 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3890 Ui::MarginsUi * m = marginsModule;
3894 lengthToWidgets(m->topLE, m->topUnit,
3895 bp_.topmargin, default_unit);
3897 lengthToWidgets(m->bottomLE, m->bottomUnit,
3898 bp_.bottommargin, default_unit);
3900 lengthToWidgets(m->innerLE, m->innerUnit,
3901 bp_.leftmargin, default_unit);
3903 lengthToWidgets(m->outerLE, m->outerUnit,
3904 bp_.rightmargin, default_unit);
3906 lengthToWidgets(m->headheightLE, m->headheightUnit,
3907 bp_.headheight, default_unit);
3909 lengthToWidgets(m->headsepLE, m->headsepUnit,
3910 bp_.headsep, default_unit);
3912 lengthToWidgets(m->footskipLE, m->footskipUnit,
3913 bp_.footskip, default_unit);
3915 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3916 bp_.columnsep, default_unit);
3919 updateUnknownBranches();
3920 branchesModule->update(bp_);
3923 PDFOptions const & pdf = bp_.pdfoptions();
3924 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3925 if (bp_.documentClass().provides("hyperref"))
3926 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3928 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3929 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3930 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3931 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3932 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3934 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3935 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3936 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3938 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3940 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3941 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3942 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3943 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3945 nn = findToken(backref_opts, pdf.backref);
3947 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3949 pdfSupportModule->fullscreenCB->setChecked
3950 (pdf.pagemode == pdf.pagemode_fullscreen);
3952 pdfSupportModule->optionsLE->setText(
3953 toqstr(pdf.quoted_options));
3955 // Make sure that the bc is in the INITIAL state
3956 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3959 // clear changed branches cache
3960 changedBranches_.clear();
3963 nonModuleChanged_ = false;
3964 shellescapeChanged_ = false;
3968 void GuiDocument::saveDocDefault()
3970 // we have to apply the params first
3976 void GuiDocument::updateAvailableModules()
3978 modules_av_model_.clear();
3979 list<modInfoStruct> modInfoList = getModuleInfo();
3980 // Sort names according to the locale
3981 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3982 return 0 < b.name.localeAwareCompare(a.name);
3985 for (modInfoStruct const & m : modInfoList) {
3986 modules_av_model_.insertRow(i, m.name, m.id, m.description);
3992 void GuiDocument::updateSelectedModules()
3994 modules_sel_model_.clear();
3995 list<modInfoStruct> const selModList = getSelectedModules();
3997 for (modInfoStruct const & m : selModList) {
3998 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4004 void GuiDocument::updateIncludeonlys()
4006 masterChildModule->childrenTW->clear();
4007 QString const no = qt_("No");
4008 QString const yes = qt_("Yes");
4010 if (includeonlys_.empty()) {
4011 masterChildModule->includeallRB->setChecked(true);
4012 masterChildModule->childrenTW->setEnabled(false);
4013 masterChildModule->maintainAuxCB->setEnabled(false);
4015 masterChildModule->includeonlyRB->setChecked(true);
4016 masterChildModule->childrenTW->setEnabled(true);
4017 masterChildModule->maintainAuxCB->setEnabled(true);
4019 ListOfBuffers children = buffer().getChildren();
4020 ListOfBuffers::const_iterator it = children.begin();
4021 ListOfBuffers::const_iterator end = children.end();
4022 bool has_unincluded = false;
4023 bool all_unincluded = true;
4024 for (; it != end; ++it) {
4025 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4028 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4029 from_utf8(buffer().filePath())));
4030 item->setText(0, toqstr(name));
4031 item->setText(1, isChildIncluded(name) ? yes : no);
4032 if (!isChildIncluded(name))
4033 has_unincluded = true;
4035 all_unincluded = false;
4037 // Both if all childs are included and if none is included
4038 // is equal to "include all" (i.e., omit \includeonly).
4039 // Thus, reset the GUI.
4040 if (!has_unincluded || all_unincluded) {
4041 masterChildModule->includeallRB->setChecked(true);
4042 masterChildModule->childrenTW->setEnabled(false);
4043 includeonlys_.clear();
4045 // If all are included, we need to update again.
4046 if (!has_unincluded)
4047 updateIncludeonlys();
4051 bool GuiDocument::isBiblatex() const
4053 QString const engine =
4054 biblioModule->citeEngineCO->itemData(
4055 biblioModule->citeEngineCO->currentIndex()).toString();
4057 // this can happen if the cite engine is unknown, which can happen
4058 // if one is using a file that came from someone else, etc. in that
4059 // case, we crash if we proceed.
4060 if (engine.isEmpty())
4063 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4067 void GuiDocument::updateDefaultBiblio(string const & style,
4068 string const & which)
4070 QString const bibstyle = toqstr(style);
4071 biblioModule->defaultBiblioCO->clear();
4076 if (which != "cbx") {
4077 // First the bbx styles
4078 biblioModule->biblatexBbxCO->clear();
4079 QStringList str = texFileList("bbxFiles.lst");
4080 // test whether we have a valid list, otherwise run rescan
4081 if (str.isEmpty()) {
4082 rescanTexStyles("bbx");
4083 str = texFileList("bbxFiles.lst");
4085 for (int i = 0; i != str.size(); ++i)
4086 str[i] = onlyFileName(str[i]);
4087 // sort on filename only (no path)
4090 for (int i = 0; i != str.count(); ++i) {
4091 QString item = changeExtension(str[i], "");
4092 if (item == bibstyle)
4094 biblioModule->biblatexBbxCO->addItem(item);
4097 if (item_nr == -1 && !bibstyle.isEmpty()) {
4098 biblioModule->biblatexBbxCO->addItem(bibstyle);
4099 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4103 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4105 biblioModule->biblatexBbxCO->clearEditText();
4108 if (which != "bbx") {
4109 // now the cbx styles
4110 biblioModule->biblatexCbxCO->clear();
4111 QStringList str = texFileList("cbxFiles.lst");
4112 // test whether we have a valid list, otherwise run rescan
4113 if (str.isEmpty()) {
4114 rescanTexStyles("cbx");
4115 str = texFileList("cbxFiles.lst");
4117 for (int i = 0; i != str.size(); ++i)
4118 str[i] = onlyFileName(str[i]);
4119 // sort on filename only (no path)
4122 for (int i = 0; i != str.count(); ++i) {
4123 QString item = changeExtension(str[i], "");
4124 if (item == bibstyle)
4126 biblioModule->biblatexCbxCO->addItem(item);
4129 if (item_nr == -1 && !bibstyle.isEmpty()) {
4130 biblioModule->biblatexCbxCO->addItem(bibstyle);
4131 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4135 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4137 biblioModule->biblatexCbxCO->clearEditText();
4140 biblioModule->biblatexBbxCO->clear();
4141 biblioModule->biblatexCbxCO->clear();
4142 QStringList str = texFileList("bstFiles.lst");
4143 // test whether we have a valid list, otherwise run rescan
4144 if (str.isEmpty()) {
4145 rescanTexStyles("bst");
4146 str = texFileList("bstFiles.lst");
4148 for (int i = 0; i != str.size(); ++i)
4149 str[i] = onlyFileName(str[i]);
4150 // sort on filename only (no path)
4153 for (int i = 0; i != str.count(); ++i) {
4154 QString item = changeExtension(str[i], "");
4155 if (item == bibstyle)
4157 biblioModule->defaultBiblioCO->addItem(item);
4160 if (item_nr == -1 && !bibstyle.isEmpty()) {
4161 biblioModule->defaultBiblioCO->addItem(bibstyle);
4162 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4166 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4168 biblioModule->defaultBiblioCO->clearEditText();
4171 updateResetDefaultBiblio();
4175 void GuiDocument::updateResetDefaultBiblio()
4177 QString const engine =
4178 biblioModule->citeEngineCO->itemData(
4179 biblioModule->citeEngineCO->currentIndex()).toString();
4180 CiteEngineType const cet =
4181 CiteEngineType(biblioModule->citeStyleCO->itemData(
4182 biblioModule->citeStyleCO->currentIndex()).toInt());
4184 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4186 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4187 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4188 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4189 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4190 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4191 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4193 biblioModule->resetDefaultBiblioPB->setEnabled(
4194 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4198 void GuiDocument::matchBiblatexStyles()
4200 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4205 void GuiDocument::updateContents()
4207 // Nothing to do here as the document settings is not cursor dependant.
4212 void GuiDocument::useClassDefaults()
4214 if (applyPB->isEnabled()) {
4215 int const ret = Alert::prompt(_("Unapplied changes"),
4216 _("Some changes in the dialog were not yet applied.\n"
4217 "If you do not apply now, they will be lost after this action."),
4218 1, 1, _("&Apply"), _("&Dismiss"));
4223 int idx = latexModule->classCO->currentIndex();
4224 string const classname = fromqstr(latexModule->classCO->getData(idx));
4225 if (!bp_.setBaseClass(classname)) {
4226 Alert::error(_("Error"), _("Unable to set document class."));
4229 bp_.useClassDefaults();
4235 void GuiDocument::setLayoutComboByIDString(string const & idString)
4237 if (!latexModule->classCO->set(toqstr(idString)))
4238 Alert::warning(_("Can't set layout!"),
4239 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4243 bool GuiDocument::isValid()
4246 validateListingsParameters().isEmpty() &&
4247 localLayout->isValid() &&
4249 // if we're asking for skips between paragraphs
4250 !textLayoutModule->skipRB->isChecked() ||
4251 // then either we haven't chosen custom
4252 textLayoutModule->skipCO->currentIndex() != 3 ||
4253 // or else a length has been given
4254 !textLayoutModule->skipLE->text().isEmpty()
4257 // if we're asking for indentation
4258 !textLayoutModule->indentRB->isChecked() ||
4259 // then either we haven't chosen custom
4260 textLayoutModule->indentCO->currentIndex() != 1 ||
4261 // or else a length has been given
4262 !textLayoutModule->indentLE->text().isEmpty()
4265 // if we're asking for math indentation
4266 !mathsModule->MathIndentCB->isChecked() ||
4267 // then either we haven't chosen custom
4268 mathsModule->MathIndentCO->currentIndex() != 1 ||
4269 // or else a length has been given
4270 !mathsModule->MathIndentLE->text().isEmpty()
4275 char const * const GuiDocument::fontfamilies[5] = {
4276 "default", "rmdefault", "sfdefault", "ttdefault", ""
4280 char const * GuiDocument::fontfamilies_gui[5] = {
4281 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4285 bool GuiDocument::initialiseParams(string const &)
4287 BufferView const * view = bufferview();
4289 bp_ = BufferParams();
4293 bp_ = view->buffer().params();
4295 updateAvailableModules();
4296 //FIXME It'd be nice to make sure here that the selected
4297 //modules are consistent: That required modules are actually
4298 //selected, and that we don't have conflicts. If so, we could
4299 //at least pop up a warning.
4305 void GuiDocument::clearParams()
4307 bp_ = BufferParams();
4311 BufferId GuiDocument::id() const
4313 BufferView const * const view = bufferview();
4314 return view? &view->buffer() : 0;
4318 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4320 return moduleNames_;
4324 list<GuiDocument::modInfoStruct> const
4325 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4327 list<modInfoStruct> mInfo;
4328 for (string const & name : mods) {
4330 LyXModule const * const mod = theModuleList[name];
4335 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4343 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4345 return makeModuleInfo(params().getModules());
4349 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4351 return makeModuleInfo(params().baseClass()->providedModules());
4355 DocumentClass const & GuiDocument::documentClass() const
4357 return bp_.documentClass();
4361 static void dispatch_bufferparams(Dialog const & dialog,
4362 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4365 ss << "\\begin_header\n";
4366 bp.writeFile(ss, buf);
4367 ss << "\\end_header\n";
4368 dialog.dispatch(FuncRequest(lfun, ss.str()));
4372 void GuiDocument::dispatchParams()
4374 // We need a non-const buffer object.
4375 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4376 // There may be several undo records; group them (bug #8998)
4377 // This handles undo groups automagically
4378 UndoGroupHelper ugh(&buf);
4380 // This must come first so that a language change is correctly noticed
4383 // Apply the BufferParams. Note that this will set the base class
4384 // and then update the buffer's layout.
4385 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4387 if (!params().master.empty()) {
4388 FileName const master_file = support::makeAbsPath(params().master,
4389 support::onlyPath(buffer().absFileName()));
4390 if (isLyXFileName(master_file.absFileName())) {
4391 Buffer * master = checkAndLoadLyXFile(master_file);
4393 if (master->isChild(const_cast<Buffer *>(&buffer())))
4394 const_cast<Buffer &>(buffer()).setParent(master);
4396 Alert::warning(_("Assigned master does not include this file"),
4397 bformat(_("You must include this file in the document\n"
4398 "'%1$s' in order to use the master document\n"
4399 "feature."), from_utf8(params().master)));
4401 Alert::warning(_("Could not load master"),
4402 bformat(_("The master document '%1$s'\n"
4403 "could not be loaded."),
4404 from_utf8(params().master)));
4408 // Generate the colours requested by each new branch.
4409 BranchList & branchlist = params().branchlist();
4410 if (!branchlist.empty()) {
4411 BranchList::const_iterator it = branchlist.begin();
4412 BranchList::const_iterator const end = branchlist.end();
4413 for (; it != end; ++it) {
4414 docstring const & current_branch = it->branch();
4415 Branch const * branch = branchlist.find(current_branch);
4416 string const x11hexname = X11hexname(branch->color());
4417 // display the new color
4418 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4419 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4422 // rename branches in the document
4423 executeBranchRenaming();
4424 // and clear changed branches cache
4425 changedBranches_.clear();
4427 // Generate the colours requested by indices.
4428 IndicesList & indiceslist = params().indiceslist();
4429 if (!indiceslist.empty()) {
4430 IndicesList::const_iterator it = indiceslist.begin();
4431 IndicesList::const_iterator const end = indiceslist.end();
4432 for (; it != end; ++it) {
4433 docstring const & current_index = it->shortcut();
4434 Index const * index = indiceslist.findShortcut(current_index);
4435 string const x11hexname = X11hexname(index->color());
4436 // display the new color
4437 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4438 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4442 // If we used an LFUN, we would not need these two lines:
4443 BufferView * bv = const_cast<BufferView *>(bufferview());
4444 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4448 void GuiDocument::setLanguage() const
4450 Language const * const newL = bp_.language;
4451 if (buffer().params().language == newL)
4454 string const & lang_name = newL->lang();
4455 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4459 void GuiDocument::saveAsDefault() const
4461 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4465 bool GuiDocument::providesOSF(QString const & font) const
4467 if (fontModule->osFontsCB->isChecked())
4468 // FIXME: we should check if the fonts really
4469 // have OSF support. But how?
4471 return theLaTeXFonts().getLaTeXFont(
4472 qstring_to_ucs4(font)).providesOSF(ot1(),
4478 bool GuiDocument::providesSC(QString const & font) const
4480 if (fontModule->osFontsCB->isChecked())
4482 return theLaTeXFonts().getLaTeXFont(
4483 qstring_to_ucs4(font)).providesSC(ot1(),
4489 bool GuiDocument::providesScale(QString const & font) const
4491 if (fontModule->osFontsCB->isChecked())
4493 return theLaTeXFonts().getLaTeXFont(
4494 qstring_to_ucs4(font)).providesScale(ot1(),
4500 bool GuiDocument::providesNoMath(QString const & font) const
4502 if (fontModule->osFontsCB->isChecked())
4504 return theLaTeXFonts().getLaTeXFont(
4505 qstring_to_ucs4(font)).providesNoMath(ot1(),
4510 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4512 if (fontModule->osFontsCB->isChecked())
4514 return theLaTeXFonts().getLaTeXFont(
4515 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4522 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4524 // FIXME Unicode: docstrings would be better for these parameters but this
4525 // change requires a lot of others
4528 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4529 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4530 // Find the first sentence of the description
4531 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4532 int pos = bf.toNextBoundary();
4535 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4536 // Tooltip is the desc followed by the module name
4537 m.description = QString("%1<i>%2</i>")
4538 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4544 void GuiDocument::loadModuleInfo()
4546 moduleNames_.clear();
4547 for (LyXModule const & mod : theModuleList)
4548 if (mod.category().substr(0, 8) != "Citation")
4549 moduleNames_.push_back(modInfo(mod));
4553 void GuiDocument::updateUnknownBranches()
4557 list<docstring> used_branches;
4558 buffer().getUsedBranches(used_branches);
4559 list<docstring>::const_iterator it = used_branches.begin();
4560 QStringList unknown_branches;
4561 for (; it != used_branches.end() ; ++it) {
4562 if (!buffer().params().branchlist().find(*it))
4563 unknown_branches.append(toqstr(*it));
4565 branchesModule->setUnknownBranches(unknown_branches);
4569 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4571 map<docstring, docstring>::iterator it = changedBranches_.begin();
4572 for (; it != changedBranches_.end() ; ++it) {
4573 if (it->second == oldname) {
4574 // branch has already been renamed
4575 it->second = newname;
4580 changedBranches_[oldname] = newname;
4584 void GuiDocument::executeBranchRenaming() const
4586 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4587 for (; it != changedBranches_.end() ; ++it) {
4588 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4589 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4594 void GuiDocument::allPackagesAuto()
4600 void GuiDocument::allPackagesAlways()
4606 void GuiDocument::allPackagesNot()
4612 void GuiDocument::allPackages(int col)
4614 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4616 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4617 rb->setChecked(true);
4622 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4625 } // namespace frontend
4628 #include "moc_GuiDocument.cpp"