2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "CategorizedCombo.h"
17 #include "GuiApplication.h"
18 #include "GuiBranches.h"
19 #include "GuiIndices.h"
20 #include "GuiSelectionManager.h"
21 #include "LaTeXHighlighter.h"
22 #include "LengthCombo.h"
23 #include "PanelStack.h"
24 #include "Validator.h"
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "CiteEnginesList.h"
34 #include "ColorCache.h"
35 #include "Converter.h"
38 #include "FloatPlacement.h"
40 #include "FuncRequest.h"
41 #include "IndicesList.h"
43 #include "LaTeXFeatures.h"
44 #include "LaTeXFonts.h"
46 #include "LayoutEnums.h"
47 #include "LayoutModuleList.h"
49 #include "ModuleList.h"
50 #include "OutputParams.h"
51 #include "PDFOptions.h"
52 #include "qt_helpers.h"
55 #include "TextClass.h"
59 #include "insets/InsetListingsParams.h"
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
68 #include "frontends/alert.h"
70 #include <QAbstractItemModel>
71 #include <QHeaderView>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
77 #include <QTextBoundaryFinder>
78 #include <QTextCursor>
88 // a style sheet for buttons
89 // this is for example used for the background color setting button
90 static inline QString colorButtonStyleSheet(QColor const & bgColor)
92 if (bgColor.isValid()) {
93 QString rc = QLatin1String("background-color:");
102 using namespace lyx::support;
107 char const * const tex_graphics[] =
109 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
110 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
111 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
112 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
117 char const * const tex_graphics_gui[] =
119 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
120 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
121 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
122 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
123 "XeTeX", N_("None"), ""
127 char const * backref_opts[] =
129 "false", "section", "slide", "page", ""
133 char const * backref_opts_gui[] =
135 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
139 char const * lst_packages[] =
141 "Listings", "Minted", ""
145 vector<string> engine_types_;
146 vector<pair<string, QString> > pagestyles;
148 QMap<QString, QString> rmfonts_;
149 QMap<QString, QString> sffonts_;
150 QMap<QString, QString> ttfonts_;
151 QMap<QString, QString> mathfonts_;
154 } // anonymous namespace
158 RGBColor set_backgroundcolor;
159 bool is_backgroundcolor;
160 RGBColor set_fontcolor;
162 RGBColor set_notefontcolor;
163 RGBColor set_boxbgcolor;
164 bool forced_fontspec_activation;
167 // used when sorting the textclass list.
168 class less_textclass_avail_desc
169 : public binary_function<string, string, int>
172 bool operator()(string const & lhs, string const & rhs) const
174 // Ordering criteria:
175 // 1. Availability of text class
176 // 2. Description (lexicographic)
177 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
178 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
179 int const order = compare_no_case(
180 translateIfPossible(from_utf8(tc1.description())),
181 translateIfPossible(from_utf8(tc2.description())));
182 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
183 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
192 vector<string> getRequiredList(string const & modName)
194 LyXModule const * const mod = theModuleList[modName];
196 return vector<string>(); //empty such thing
197 return mod->getRequiredModules();
201 vector<string> getExcludedList(string const & modName)
203 LyXModule const * const mod = theModuleList[modName];
205 return vector<string>(); //empty such thing
206 return mod->getExcludedModules();
210 docstring getModuleCategory(string const & modName)
212 LyXModule const * const mod = theModuleList[modName];
215 return from_utf8(mod->category());
219 docstring getModuleDescription(string const & modName)
221 LyXModule const * const mod = theModuleList[modName];
223 return _("Module not found!");
225 return translateIfPossible(from_utf8(mod->getDescription()));
229 vector<string> getPackageList(string const & modName)
231 LyXModule const * const mod = theModuleList[modName];
233 return vector<string>(); //empty such thing
234 return mod->getPackageList();
238 bool isModuleAvailable(string const & modName)
240 LyXModule const * const mod = theModuleList[modName];
243 return mod->isAvailable();
246 } // anonymous namespace
249 /////////////////////////////////////////////////////////////////////
251 // ModuleSelectionManager
253 /////////////////////////////////////////////////////////////////////
255 /// SelectionManager for use with modules
256 class ModuleSelectionManager : public GuiSelectionManager
260 ModuleSelectionManager(QObject * parent,
261 QTreeView * availableLV,
262 QListView * selectedLV,
266 QPushButton * downPB,
267 GuiIdListModel * availableModel,
268 GuiIdListModel * selectedModel,
269 GuiDocument const * container)
270 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
271 upPB, downPB, availableModel, selectedModel),
272 container_(container)
275 void updateProvidedModules(LayoutModuleList const & pm)
276 { provided_modules_ = pm.list(); }
278 void updateExcludedModules(LayoutModuleList const & em)
279 { excluded_modules_ = em.list(); }
282 virtual void updateAddPB();
284 virtual void updateUpPB();
286 virtual void updateDownPB();
288 virtual void updateDelPB();
289 /// returns availableModel as a GuiIdListModel
290 GuiIdListModel * getAvailableModel()
292 return dynamic_cast<GuiIdListModel *>(availableModel);
294 /// returns selectedModel as a GuiIdListModel
295 GuiIdListModel * getSelectedModel()
297 return dynamic_cast<GuiIdListModel *>(selectedModel);
299 /// keeps a list of the modules the text class provides
300 list<string> provided_modules_;
302 list<string> excluded_modules_;
304 GuiDocument const * container_;
307 void ModuleSelectionManager::updateAddPB()
309 int const arows = availableModel->rowCount();
310 QModelIndexList const avail_sels =
311 availableLV->selectionModel()->selectedIndexes();
313 // disable if there aren't any modules (?), if none of them is chosen
314 // in the dialog, or if the chosen one is already selected for use.
315 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
316 addPB->setEnabled(false);
320 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
321 string const modname = getAvailableModel()->getIDString(idx.row());
324 container_->params().layoutModuleCanBeAdded(modname);
325 addPB->setEnabled(enable);
329 void ModuleSelectionManager::updateDownPB()
331 int const srows = selectedModel->rowCount();
333 downPB->setEnabled(false);
336 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
337 int const curRow = curidx.row();
338 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
339 downPB->setEnabled(false);
343 // determine whether immediately succeding element requires this one
344 string const curmodname = getSelectedModel()->getIDString(curRow);
345 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
347 vector<string> reqs = getRequiredList(nextmodname);
349 // if it doesn't require anything....
351 downPB->setEnabled(true);
355 // Enable it if this module isn't required.
356 // FIXME This should perhaps be more flexible and check whether, even
357 // if the next one is required, there is also an earlier one that will do.
359 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
362 void ModuleSelectionManager::updateUpPB()
364 int const srows = selectedModel->rowCount();
366 upPB->setEnabled(false);
370 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
371 int curRow = curIdx.row();
372 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
373 upPB->setEnabled(false);
376 string const curmodname = getSelectedModel()->getIDString(curRow);
378 // determine whether immediately preceding element is required by this one
379 vector<string> reqs = getRequiredList(curmodname);
381 // if this one doesn't require anything....
383 upPB->setEnabled(true);
388 // Enable it if the preceding module isn't required.
389 // NOTE This is less flexible than it might be. We could check whether, even
390 // if the previous one is required, there is an earlier one that would do.
391 string const premod = getSelectedModel()->getIDString(curRow - 1);
392 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
395 void ModuleSelectionManager::updateDelPB()
397 int const srows = selectedModel->rowCount();
399 deletePB->setEnabled(false);
403 QModelIndex const & curidx =
404 selectedLV->selectionModel()->currentIndex();
405 int const curRow = curidx.row();
406 if (curRow < 0 || curRow >= srows) { // invalid index?
407 deletePB->setEnabled(false);
411 string const curmodname = getSelectedModel()->getIDString(curRow);
413 // We're looking here for a reason NOT to enable the button. If we
414 // find one, we disable it and return. If we don't, we'll end up at
415 // the end of the function, and then we enable it.
416 for (int i = curRow + 1; i < srows; ++i) {
417 string const thisMod = getSelectedModel()->getIDString(i);
418 vector<string> reqs = getRequiredList(thisMod);
419 //does this one require us?
420 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
424 // OK, so this module requires us
425 // is there an EARLIER module that also satisfies the require?
426 // NOTE We demand that it be earlier to keep the list of modules
427 // consistent with the rule that a module must be proceeded by a
428 // required module. There would be more flexible ways to proceed,
429 // but that would be a lot more complicated, and the logic here is
430 // already complicated. (That's why I've left the debugging code.)
431 // lyxerr << "Testing " << thisMod << endl;
432 bool foundone = false;
433 for (int j = 0; j < curRow; ++j) {
434 string const mod = getSelectedModel()->getIDString(j);
435 // lyxerr << "In loop: Testing " << mod << endl;
436 // do we satisfy the require?
437 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
438 // lyxerr << mod << " does the trick." << endl;
443 // did we find a module to satisfy the require?
445 // lyxerr << "No matching module found." << endl;
446 deletePB->setEnabled(false);
450 // lyxerr << "All's well that ends well." << endl;
451 deletePB->setEnabled(true);
455 /////////////////////////////////////////////////////////////////////
459 /////////////////////////////////////////////////////////////////////
461 PreambleModule::PreambleModule(QWidget * parent)
462 : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
464 // This is not a memory leak. The object will be destroyed
466 // @ is letter in the LyX user preamble
467 (void) new LaTeXHighlighter(preambleTE->document(), true);
468 preambleTE->setFont(guiApp->typewriterSystemFont());
469 preambleTE->setWordWrapMode(QTextOption::NoWrap);
470 setFocusProxy(preambleTE);
471 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
472 connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
473 connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
474 connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
476 // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
477 const int tabStop = 4;
478 QFontMetrics metrics(preambleTE->currentFont());
479 preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
483 void PreambleModule::checkFindButton()
485 findButtonPB->setEnabled(!findLE->text().isEmpty());
489 void PreambleModule::findText()
491 bool const found = preambleTE->find(findLE->text());
494 QTextCursor qtcur = preambleTE->textCursor();
495 qtcur.movePosition(QTextCursor::Start);
496 preambleTE->setTextCursor(qtcur);
497 preambleTE->find(findLE->text());
502 void PreambleModule::update(BufferParams const & params, BufferId id)
504 QString preamble = toqstr(params.preamble);
505 // Nothing to do if the params and preamble are unchanged.
506 if (id == current_id_
507 && preamble == preambleTE->document()->toPlainText())
510 QTextCursor cur = preambleTE->textCursor();
511 // Save the coords before switching to the new one.
512 preamble_coords_[current_id_] =
513 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
515 // Save the params address for further use.
517 preambleTE->document()->setPlainText(preamble);
518 Coords::const_iterator it = preamble_coords_.find(current_id_);
519 if (it == preamble_coords_.end())
520 // First time we open this one.
521 preamble_coords_[current_id_] = make_pair(0, 0);
523 // Restore saved coords.
524 QTextCursor cur = preambleTE->textCursor();
525 cur.setPosition(it->second.first);
526 preambleTE->setTextCursor(cur);
527 preambleTE->verticalScrollBar()->setValue(it->second.second);
532 void PreambleModule::apply(BufferParams & params)
534 params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
538 void PreambleModule::closeEvent(QCloseEvent * e)
540 // Save the coords before closing.
541 QTextCursor cur = preambleTE->textCursor();
542 preamble_coords_[current_id_] =
543 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
548 /////////////////////////////////////////////////////////////////////
552 /////////////////////////////////////////////////////////////////////
555 LocalLayout::LocalLayout(QWidget * parent)
556 : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
558 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
559 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
560 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
564 void LocalLayout::update(BufferParams const & params, BufferId id)
566 QString layout = toqstr(params.getLocalLayout(false));
567 // Nothing to do if the params and preamble are unchanged.
568 if (id == current_id_
569 && layout == locallayoutTE->document()->toPlainText())
572 // Save the params address for further use.
574 locallayoutTE->document()->setPlainText(layout);
579 void LocalLayout::apply(BufferParams & params)
581 docstring const layout =
582 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
583 params.setLocalLayout(layout, false);
587 void LocalLayout::hideConvert()
589 convertPB->setEnabled(false);
590 convertLB->setText("");
596 void LocalLayout::textChanged()
598 static const QString message =
599 qt_("Press button to check validity...");
600 string const layout =
601 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
603 if (layout.empty()) {
605 validatePB->setEnabled(false);
606 validLB->setText("");
609 } else if (!validatePB->isEnabled()) {
610 // if that's already enabled, we shouldn't need to do anything.
612 validLB->setText(message);
613 validatePB->setEnabled(true);
620 void LocalLayout::convert() {
621 string const layout =
622 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
623 string const newlayout = TextClass::convert(layout);
624 if (!newlayout.empty())
625 locallayoutTE->setPlainText(toqstr(newlayout));
630 void LocalLayout::convertPressed() {
637 void LocalLayout::validate() {
639 static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
640 // Flashy red bold text
641 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
643 string const layout =
644 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
645 if (!layout.empty()) {
646 TextClass::ReturnValues const ret = TextClass::validate(layout);
647 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
648 validatePB->setEnabled(false);
649 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
650 : ivpar.arg(qt_("Layout is invalid!")));
651 if (ret == TextClass::OK_OLDFORMAT) {
653 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
655 if (TextClass::convert(layout).empty()) {
656 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
657 // then maybe the layout is still valid, but its format is more
658 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
659 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
660 convertPB->setEnabled(false);
661 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
662 ? ivpar.arg(qt_("Conversion to current format impossible!"))
663 : vpar.arg(qt_("Conversion to current stable format "
665 convertLB->setText(text);
667 convertPB->setEnabled(true);
668 convertLB->setText(qt_("Convert to current format"));
679 void LocalLayout::validatePressed() {
685 /////////////////////////////////////////////////////////////////////
689 /////////////////////////////////////////////////////////////////////
692 GuiDocument::GuiDocument(GuiView & lv)
693 : GuiDialog(lv, "document", qt_("Document Settings")),
694 biblioChanged_(false), nonModuleChanged_(false),
695 modulesChanged_(false), shellescapeChanged_(false)
699 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
700 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
701 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
702 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
704 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
705 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
707 // Manage the restore, ok, apply, restore and cancel/close buttons
708 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
710 bc().setApply(applyPB);
711 bc().setCancel(closePB);
712 bc().setRestore(restorePB);
716 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
717 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
718 this, SLOT(change_adaptor()));
719 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
720 this, SLOT(setLSpacing(int)));
721 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
722 this, SLOT(change_adaptor()));
724 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
725 this, SLOT(change_adaptor()));
726 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
727 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
728 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
729 this, SLOT(change_adaptor()));
730 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
731 this, SLOT(setIndent(int)));
732 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
733 this, SLOT(change_adaptor()));
734 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
735 this, SLOT(change_adaptor()));
737 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
738 this, SLOT(change_adaptor()));
739 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
740 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
741 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
742 this, SLOT(change_adaptor()));
743 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
744 this, SLOT(setSkip(int)));
745 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
746 this, SLOT(change_adaptor()));
747 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
748 this, SLOT(change_adaptor()));
750 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
751 this, SLOT(enableIndent(bool)));
752 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
753 this, SLOT(enableSkip(bool)));
755 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
756 this, SLOT(change_adaptor()));
757 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
758 this, SLOT(setColSep()));
759 connect(textLayoutModule->justCB, SIGNAL(clicked()),
760 this, SLOT(change_adaptor()));
762 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
763 textLayoutModule->lspacingLE));
764 textLayoutModule->indentLE->setValidator(new LengthValidator(
765 textLayoutModule->indentLE));
766 textLayoutModule->skipLE->setValidator(new LengthValidator(
767 textLayoutModule->skipLE));
769 textLayoutModule->indentCO->addItem(qt_("Default"));
770 textLayoutModule->indentCO->addItem(qt_("Custom"));
771 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
772 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
773 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
774 textLayoutModule->skipCO->addItem(qt_("Custom"));
775 textLayoutModule->lspacingCO->insertItem(
776 Spacing::Single, qt_("Single"));
777 textLayoutModule->lspacingCO->insertItem(
778 Spacing::Onehalf, qt_("OneHalf"));
779 textLayoutModule->lspacingCO->insertItem(
780 Spacing::Double, qt_("Double"));
781 textLayoutModule->lspacingCO->insertItem(
782 Spacing::Other, qt_("Custom"));
783 // initialize the length validator
784 bc().addCheckedLineEdit(textLayoutModule->indentLE);
785 bc().addCheckedLineEdit(textLayoutModule->skipLE);
788 // master/child handling
789 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
791 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
792 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
793 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
794 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
795 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
796 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
797 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
798 this, SLOT(change_adaptor()));
799 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
800 this, SLOT(change_adaptor()));
801 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
802 this, SLOT(change_adaptor()));
803 masterChildModule->childrenTW->setColumnCount(2);
804 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
805 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
806 masterChildModule->childrenTW->resizeColumnToContents(1);
807 masterChildModule->childrenTW->resizeColumnToContents(2);
811 outputModule = new UiWidget<Ui::OutputUi>(this);
813 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
814 this, SLOT(change_adaptor()));
815 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
816 this, SLOT(change_adaptor()));
817 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
818 this, SLOT(change_adaptor()));
819 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
820 this, SLOT(change_adaptor()));
821 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
822 this, SLOT(change_adaptor()));
824 connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
825 this, SLOT(shellescapeChanged()));
826 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
827 this, SLOT(change_adaptor()));
828 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
829 this, SLOT(change_adaptor()));
830 outputModule->synccustomCB->addItem("");
831 outputModule->synccustomCB->addItem("\\synctex=1");
832 outputModule->synccustomCB->addItem("\\synctex=-1");
833 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
835 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
836 outputModule->synccustomCB));
838 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
839 this, SLOT(change_adaptor()));
842 fontModule = new FontModule(this);
843 connect(fontModule->osFontsCB, SIGNAL(clicked()),
844 this, SLOT(change_adaptor()));
845 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
846 this, SLOT(osFontsChanged(bool)));
847 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
848 this, SLOT(change_adaptor()));
849 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
850 this, SLOT(romanChanged(int)));
851 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
852 this, SLOT(change_adaptor()));
853 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
854 this, SLOT(sansChanged(int)));
855 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
856 this, SLOT(change_adaptor()));
857 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
858 this, SLOT(ttChanged(int)));
859 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
860 this, SLOT(change_adaptor()));
861 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
862 this, SLOT(mathFontChanged(int)));
863 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
864 this, SLOT(change_adaptor()));
865 connect(fontModule->fontencCO, SIGNAL(activated(int)),
866 this, SLOT(change_adaptor()));
867 connect(fontModule->fontencCO, SIGNAL(activated(int)),
868 this, SLOT(fontencChanged(int)));
869 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
870 this, SLOT(change_adaptor()));
871 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
872 this, SLOT(change_adaptor()));
873 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
874 this, SLOT(change_adaptor()));
875 connect(fontModule->microtypeCB, SIGNAL(clicked()),
876 this, SLOT(change_adaptor()));
877 connect(fontModule->dashesCB, SIGNAL(clicked()),
878 this, SLOT(change_adaptor()));
879 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
880 this, SLOT(change_adaptor()));
881 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
882 this, SLOT(change_adaptor()));
883 connect(fontModule->fontScCB, SIGNAL(clicked()),
884 this, SLOT(change_adaptor()));
885 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
886 this, SLOT(fontScToggled(bool)));
887 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
888 this, SLOT(change_adaptor()));
889 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
890 this, SLOT(fontOsfToggled(bool)));
892 fontModule->fontencLE->setValidator(new NoNewLineValidator(
893 fontModule->fontencLE));
894 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
895 fontModule->cjkFontLE));
899 fontModule->fontsizeCO->addItem(qt_("Default"));
900 fontModule->fontsizeCO->addItem(qt_("10"));
901 fontModule->fontsizeCO->addItem(qt_("11"));
902 fontModule->fontsizeCO->addItem(qt_("12"));
904 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
905 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
906 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
908 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
909 fontModule->fontsDefaultCO->addItem(
910 qt_(GuiDocument::fontfamilies_gui[n]));
912 if (!LaTeXFeatures::isAvailable("fontspec"))
913 fontModule->osFontsCB->setToolTip(
914 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
915 "You need to install the package \"fontspec\" to use this feature"));
919 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
920 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
921 this, SLOT(papersizeChanged(int)));
922 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
923 this, SLOT(papersizeChanged(int)));
924 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
925 this, SLOT(change_adaptor()));
926 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
927 this, SLOT(change_adaptor()));
928 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
929 this, SLOT(change_adaptor()));
930 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
931 this, SLOT(change_adaptor()));
932 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
933 this, SLOT(change_adaptor()));
934 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
935 this, SLOT(change_adaptor()));
936 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
937 this, SLOT(change_adaptor()));
938 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
939 this, SLOT(change_adaptor()));
940 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
941 this, SLOT(change_adaptor()));
942 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
943 this, SLOT(change_adaptor()));
945 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
946 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
947 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
948 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
949 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
950 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
951 pageLayoutModule->paperheightL);
952 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
953 pageLayoutModule->paperwidthL);
955 QComboBox * cb = pageLayoutModule->papersizeCO;
956 cb->addItem(qt_("Default"));
957 cb->addItem(qt_("Custom"));
958 cb->addItem(qt_("US letter"));
959 cb->addItem(qt_("US legal"));
960 cb->addItem(qt_("US executive"));
961 cb->addItem(qt_("A0"));
962 cb->addItem(qt_("A1"));
963 cb->addItem(qt_("A2"));
964 cb->addItem(qt_("A3"));
965 cb->addItem(qt_("A4"));
966 cb->addItem(qt_("A5"));
967 cb->addItem(qt_("A6"));
968 cb->addItem(qt_("B0"));
969 cb->addItem(qt_("B1"));
970 cb->addItem(qt_("B2"));
971 cb->addItem(qt_("B3"));
972 cb->addItem(qt_("B4"));
973 cb->addItem(qt_("B5"));
974 cb->addItem(qt_("B6"));
975 cb->addItem(qt_("C0"));
976 cb->addItem(qt_("C1"));
977 cb->addItem(qt_("C2"));
978 cb->addItem(qt_("C3"));
979 cb->addItem(qt_("C4"));
980 cb->addItem(qt_("C5"));
981 cb->addItem(qt_("C6"));
982 cb->addItem(qt_("JIS B0"));
983 cb->addItem(qt_("JIS B1"));
984 cb->addItem(qt_("JIS B2"));
985 cb->addItem(qt_("JIS B3"));
986 cb->addItem(qt_("JIS B4"));
987 cb->addItem(qt_("JIS B5"));
988 cb->addItem(qt_("JIS B6"));
989 // remove the %-items from the unit choice
990 pageLayoutModule->paperwidthUnitCO->noPercents();
991 pageLayoutModule->paperheightUnitCO->noPercents();
992 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
993 pageLayoutModule->paperheightLE));
994 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
995 pageLayoutModule->paperwidthLE));
999 marginsModule = new UiWidget<Ui::MarginsUi>(this);
1000 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1001 this, SLOT(setCustomMargins(bool)));
1002 connect(marginsModule->marginCB, SIGNAL(clicked()),
1003 this, SLOT(change_adaptor()));
1004 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1005 this, SLOT(change_adaptor()));
1006 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1007 this, SLOT(change_adaptor()));
1008 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1009 this, SLOT(change_adaptor()));
1010 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1011 this, SLOT(change_adaptor()));
1012 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1013 this, SLOT(change_adaptor()));
1014 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1015 this, SLOT(change_adaptor()));
1016 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1017 this, SLOT(change_adaptor()));
1018 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1019 this, SLOT(change_adaptor()));
1020 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1021 this, SLOT(change_adaptor()));
1022 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1023 this, SLOT(change_adaptor()));
1024 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1025 this, SLOT(change_adaptor()));
1026 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1027 this, SLOT(change_adaptor()));
1028 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1029 this, SLOT(change_adaptor()));
1030 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1031 this, SLOT(change_adaptor()));
1032 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1033 this, SLOT(change_adaptor()));
1034 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1035 this, SLOT(change_adaptor()));
1036 marginsModule->topLE->setValidator(new LengthValidator(
1037 marginsModule->topLE));
1038 marginsModule->bottomLE->setValidator(new LengthValidator(
1039 marginsModule->bottomLE));
1040 marginsModule->innerLE->setValidator(new LengthValidator(
1041 marginsModule->innerLE));
1042 marginsModule->outerLE->setValidator(new LengthValidator(
1043 marginsModule->outerLE));
1044 marginsModule->headsepLE->setValidator(new LengthValidator(
1045 marginsModule->headsepLE));
1046 marginsModule->headheightLE->setValidator(new LengthValidator(
1047 marginsModule->headheightLE));
1048 marginsModule->footskipLE->setValidator(new LengthValidator(
1049 marginsModule->footskipLE));
1050 marginsModule->columnsepLE->setValidator(new LengthValidator(
1051 marginsModule->columnsepLE));
1053 bc().addCheckedLineEdit(marginsModule->topLE,
1054 marginsModule->topL);
1055 bc().addCheckedLineEdit(marginsModule->bottomLE,
1056 marginsModule->bottomL);
1057 bc().addCheckedLineEdit(marginsModule->innerLE,
1058 marginsModule->innerL);
1059 bc().addCheckedLineEdit(marginsModule->outerLE,
1060 marginsModule->outerL);
1061 bc().addCheckedLineEdit(marginsModule->headsepLE,
1062 marginsModule->headsepL);
1063 bc().addCheckedLineEdit(marginsModule->headheightLE,
1064 marginsModule->headheightL);
1065 bc().addCheckedLineEdit(marginsModule->footskipLE,
1066 marginsModule->footskipL);
1067 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1068 marginsModule->columnsepL);
1072 langModule = new UiWidget<Ui::LanguageUi>(this);
1073 connect(langModule->languageCO, SIGNAL(activated(int)),
1074 this, SLOT(change_adaptor()));
1075 connect(langModule->languageCO, SIGNAL(activated(int)),
1076 this, SLOT(languageChanged(int)));
1077 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1078 this, SLOT(change_adaptor()));
1079 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1080 this, SLOT(change_adaptor()));
1081 connect(langModule->encodingCO, SIGNAL(activated(int)),
1082 this, SLOT(change_adaptor()));
1083 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1084 this, SLOT(change_adaptor()));
1085 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1086 this, SLOT(change_adaptor()));
1087 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1088 this, SLOT(change_adaptor()));
1089 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1090 this, SLOT(languagePackageChanged(int)));
1091 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1092 this, SLOT(change_adaptor()));
1094 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1095 langModule->languagePackageLE));
1097 QAbstractItemModel * language_model = guiApp->languageModel();
1098 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1099 language_model->sort(0);
1100 langModule->languageCO->setModel(language_model);
1101 langModule->languageCO->setModelColumn(0);
1103 // Always put the default encoding in the first position.
1104 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1105 QStringList encodinglist;
1106 for (auto const & encvar : encodings) {
1107 if (!encvar.unsafe() && !encvar.guiName().empty())
1108 encodinglist.append(qt_(encvar.guiName()));
1110 encodinglist.sort();
1111 langModule->encodingCO->addItems(encodinglist);
1113 langModule->languagePackageCO->addItem(
1114 qt_("Default"), toqstr("default"));
1115 langModule->languagePackageCO->addItem(
1116 qt_("Automatic"), toqstr("auto"));
1117 langModule->languagePackageCO->addItem(
1118 qt_("Always Babel"), toqstr("babel"));
1119 langModule->languagePackageCO->addItem(
1120 qt_("Custom"), toqstr("custom"));
1121 langModule->languagePackageCO->addItem(
1122 qt_("None[[language package]]"), toqstr("none"));
1126 colorModule = new UiWidget<Ui::ColorUi>(this);
1127 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1128 this, SLOT(changeFontColor()));
1129 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1130 this, SLOT(deleteFontColor()));
1131 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1132 this, SLOT(changeNoteFontColor()));
1133 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1134 this, SLOT(deleteNoteFontColor()));
1135 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1136 this, SLOT(changeBackgroundColor()));
1137 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1138 this, SLOT(deleteBackgroundColor()));
1139 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1140 this, SLOT(changeBoxBackgroundColor()));
1141 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1142 this, SLOT(deleteBoxBackgroundColor()));
1146 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1147 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1148 this, SLOT(change_adaptor()));
1149 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1150 this, SLOT(change_adaptor()));
1151 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1152 this, SLOT(updateNumbering()));
1153 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1154 this, SLOT(updateNumbering()));
1155 numberingModule->tocTW->setColumnCount(3);
1156 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1157 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1158 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1159 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1162 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1163 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1164 this, SLOT(citeEngineChanged(int)));
1165 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1166 this, SLOT(citeStyleChanged()));
1167 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1168 this, SLOT(biblioChanged()));
1169 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1170 this, SLOT(biblioChanged()));
1171 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1172 this, SLOT(bibtexChanged(int)));
1173 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1174 this, SLOT(biblioChanged()));
1175 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1176 this, SLOT(biblioChanged()));
1177 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1178 this, SLOT(biblioChanged()));
1179 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1180 this, SLOT(biblioChanged()));
1181 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1182 this, SLOT(updateResetDefaultBiblio()));
1183 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1184 this, SLOT(biblioChanged()));
1185 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1186 this, SLOT(biblioChanged()));
1187 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1188 this, SLOT(updateResetDefaultBiblio()));
1189 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1190 this, SLOT(biblioChanged()));
1191 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1192 this, SLOT(biblioChanged()));
1193 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1194 this, SLOT(updateResetDefaultBiblio()));
1195 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1196 this, SLOT(rescanBibFiles()));
1197 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1198 this, SLOT(resetDefaultBibfile()));
1199 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1200 this, SLOT(resetDefaultCbxBibfile()));
1201 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1202 this, SLOT(resetDefaultBbxBibfile()));
1203 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1204 this, SLOT(matchBiblatexStyles()));
1206 biblioModule->citeEngineCO->clear();
1207 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1208 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1209 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1210 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1214 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1215 biblioModule->bibtexOptionsLE));
1216 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1217 biblioModule->defaultBiblioCO->lineEdit()));
1218 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1219 biblioModule->citePackageOptionsLE));
1221 // NOTE: we do not provide "custom" here for security reasons!
1222 biblioModule->bibtexCO->clear();
1223 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1224 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1225 it != lyxrc.bibtex_alternatives.end(); ++it) {
1226 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1227 biblioModule->bibtexCO->addItem(command, command);
1232 indicesModule = new GuiIndices;
1233 connect(indicesModule, SIGNAL(changed()),
1234 this, SLOT(change_adaptor()));
1238 mathsModule = new UiWidget<Ui::MathsUi>(this);
1239 QStringList headers;
1240 headers << qt_("Package") << qt_("Load automatically")
1241 << qt_("Load always") << qt_("Do not load");
1242 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1243 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1244 map<string, string> const & packages = BufferParams::auto_packages();
1245 mathsModule->packagesTW->setRowCount(packages.size());
1247 for (map<string, string>::const_iterator it = packages.begin();
1248 it != packages.end(); ++it) {
1249 docstring const package = from_ascii(it->first);
1250 QString autoTooltip = qt_(it->second);
1251 QString alwaysTooltip;
1252 if (package == "amsmath")
1254 qt_("The AMS LaTeX packages are always used");
1256 alwaysTooltip = toqstr(bformat(
1257 _("The LaTeX package %1$s is always used"),
1259 QString neverTooltip;
1260 if (package == "amsmath")
1262 qt_("The AMS LaTeX packages are never used");
1264 neverTooltip = toqstr(bformat(
1265 _("The LaTeX package %1$s is never used"),
1267 QRadioButton * autoRB = new QRadioButton(mathsModule);
1268 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1269 QRadioButton * neverRB = new QRadioButton(mathsModule);
1270 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1271 packageGroup->addButton(autoRB);
1272 packageGroup->addButton(alwaysRB);
1273 packageGroup->addButton(neverRB);
1274 autoRB->setToolTip(autoTooltip);
1275 alwaysRB->setToolTip(alwaysTooltip);
1276 neverRB->setToolTip(neverTooltip);
1278 // Pack the buttons in a layout in order to get proper alignment
1279 QWidget * autoRBWidget = new QWidget();
1280 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1281 autoRBLayout->addWidget(autoRB);
1282 autoRBLayout->setAlignment(Qt::AlignCenter);
1283 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1284 autoRBWidget->setLayout(autoRBLayout);
1286 QWidget * alwaysRBWidget = new QWidget();
1287 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1288 alwaysRBLayout->addWidget(alwaysRB);
1289 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1290 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1291 alwaysRBWidget->setLayout(alwaysRBLayout);
1293 QWidget * neverRBWidget = new QWidget();
1294 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1295 neverRBLayout->addWidget(neverRB);
1296 neverRBLayout->setAlignment(Qt::AlignCenter);
1297 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1298 neverRBWidget->setLayout(neverRBLayout);
1300 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1302 mathsModule->packagesTW->setItem(packnum, 0, pack);
1303 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1304 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1305 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1307 connect(autoRB, SIGNAL(clicked()),
1308 this, SLOT(change_adaptor()));
1309 connect(alwaysRB, SIGNAL(clicked()),
1310 this, SLOT(change_adaptor()));
1311 connect(neverRB, SIGNAL(clicked()),
1312 this, SLOT(change_adaptor()));
1315 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1316 this, SLOT(allPackagesAuto()));
1317 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1318 this, SLOT(allPackagesAlways()));
1319 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1320 this, SLOT(allPackagesNot()));
1321 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1322 this, SLOT(change_adaptor()));
1323 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1324 this, SLOT(change_adaptor()));
1325 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1326 this, SLOT(change_adaptor()));
1327 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1328 this, SLOT(change_adaptor()));
1330 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1331 this, SLOT(change_adaptor()));
1332 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1333 this, SLOT(allowMathIndent()));
1334 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1335 this, SLOT(change_adaptor()));
1336 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1337 this, SLOT(enableMathIndent(int)));
1338 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1339 this, SLOT(change_adaptor()));
1340 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1341 this, SLOT(change_adaptor()));
1344 mathsModule->MathIndentCO->addItem(qt_("Default"));
1345 mathsModule->MathIndentCO->addItem(qt_("Custom"));
1346 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1347 mathsModule->MathIndentLE));
1348 // initialize the length validator
1349 bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1350 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1351 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1352 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1353 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1357 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1358 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1359 this, SLOT(change_adaptor()));
1360 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1361 this, SLOT(change_adaptor()));
1362 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1363 this, SLOT(change_adaptor()));
1364 connect(latexModule->classCO, SIGNAL(activated(int)),
1365 this, SLOT(classChanged_adaptor()));
1366 connect(latexModule->classCO, SIGNAL(activated(int)),
1367 this, SLOT(change_adaptor()));
1368 connect(latexModule->layoutPB, SIGNAL(clicked()),
1369 this, SLOT(browseLayout()));
1370 connect(latexModule->layoutPB, SIGNAL(clicked()),
1371 this, SLOT(change_adaptor()));
1372 connect(latexModule->childDocGB, SIGNAL(clicked()),
1373 this, SLOT(change_adaptor()));
1374 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1375 this, SLOT(change_adaptor()));
1376 connect(latexModule->childDocPB, SIGNAL(clicked()),
1377 this, SLOT(browseMaster()));
1378 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1379 this, SLOT(change_adaptor()));
1380 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1381 this, SLOT(change_adaptor()));
1383 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1384 latexModule->optionsLE));
1385 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1386 latexModule->childDocLE));
1388 // postscript drivers
1389 for (int n = 0; tex_graphics[n][0]; ++n) {
1390 QString enc = qt_(tex_graphics_gui[n]);
1391 latexModule->psdriverCO->addItem(enc);
1394 LayoutFileList const & bcl = LayoutFileList::get();
1395 vector<LayoutFileIndex> classList = bcl.classList();
1396 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1398 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1399 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1400 for (int i = 0; cit != cen; ++cit, ++i) {
1401 LayoutFile const & tc = bcl[*cit];
1402 bool const available = tc.isTeXClassAvailable();
1403 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1404 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1405 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1407 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1408 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1409 "Please check if you have the matching %1$s class "
1410 "and all required packages (%2$s) installed."),
1411 output_type, from_utf8(tc.prerequisites(", "))));
1413 latexModule->classCO->addItemSort(toqstr(tc.name()),
1415 toqstr(translateIfPossible(from_utf8(tc.category()))),
1417 true, true, true, available);
1422 branchesModule = new GuiBranches(this);
1423 connect(branchesModule, SIGNAL(changed()),
1424 this, SLOT(change_adaptor()));
1425 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1426 this, SLOT(branchesRename(docstring const &, docstring const &)));
1427 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1428 updateUnknownBranches();
1432 preambleModule = new PreambleModule(this);
1433 connect(preambleModule, SIGNAL(changed()),
1434 this, SLOT(change_adaptor()));
1436 localLayout = new LocalLayout(this);
1437 connect(localLayout, SIGNAL(changed()),
1438 this, SLOT(change_adaptor()));
1442 bulletsModule = new BulletsModule(this);
1443 connect(bulletsModule, SIGNAL(changed()),
1444 this, SLOT(change_adaptor()));
1448 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1449 modulesModule->availableLV->header()->setVisible(false);
1450 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1451 modulesModule->availableLV->header()->setStretchLastSection(false);
1453 new ModuleSelectionManager(this, modulesModule->availableLV,
1454 modulesModule->selectedLV,
1455 modulesModule->addPB,
1456 modulesModule->deletePB,
1457 modulesModule->upPB,
1458 modulesModule->downPB,
1459 availableModel(), selectedModel(), this);
1460 connect(selectionManager, SIGNAL(updateHook()),
1461 this, SLOT(updateModuleInfo()));
1462 connect(selectionManager, SIGNAL(selectionChanged()),
1463 this, SLOT(modulesChanged()));
1467 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1468 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1469 this, SLOT(change_adaptor()));
1470 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1471 this, SLOT(change_adaptor()));
1472 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1473 this, SLOT(change_adaptor()));
1474 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1475 this, SLOT(change_adaptor()));
1476 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1477 this, SLOT(change_adaptor()));
1478 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1479 this, SLOT(change_adaptor()));
1480 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1481 this, SLOT(change_adaptor()));
1482 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1483 this, SLOT(change_adaptor()));
1484 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1485 this, SLOT(change_adaptor()));
1486 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1487 this, SLOT(change_adaptor()));
1488 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1489 this, SLOT(change_adaptor()));
1490 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1491 this, SLOT(change_adaptor()));
1492 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1493 this, SLOT(change_adaptor()));
1494 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1495 this, SLOT(change_adaptor()));
1496 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1497 this, SLOT(change_adaptor()));
1498 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1499 this, SLOT(change_adaptor()));
1501 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1502 pdfSupportModule->titleLE));
1503 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1504 pdfSupportModule->authorLE));
1505 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1506 pdfSupportModule->subjectLE));
1507 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1508 pdfSupportModule->keywordsLE));
1509 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1510 pdfSupportModule->optionsLE));
1512 for (int i = 0; backref_opts[i][0]; ++i)
1513 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1517 floatModule = new FloatPlacement;
1518 connect(floatModule, SIGNAL(changed()),
1519 this, SLOT(change_adaptor()));
1523 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1524 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1525 this, SLOT(change_adaptor()));
1526 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1527 this, SLOT(change_adaptor()));
1528 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1529 this, SLOT(setListingsMessage()));
1530 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1531 this, SLOT(change_adaptor()));
1532 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1533 this, SLOT(listingsPackageChanged(int)));
1534 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1535 this, SLOT(setListingsMessage()));
1536 listingsModule->listingsTB->setPlainText(
1537 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1539 for (int i = 0; lst_packages[i][0]; ++i)
1540 listingsModule->packageCO->addItem(lst_packages[i]);
1544 docPS->addPanel(latexModule, N_("Document Class"));
1545 docPS->addPanel(masterChildModule, N_("Child Documents"));
1546 docPS->addPanel(modulesModule, N_("Modules"));
1547 docPS->addPanel(localLayout, N_("Local Layout"));
1548 docPS->addPanel(fontModule, N_("Fonts"));
1549 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1550 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1551 docPS->addPanel(marginsModule, N_("Page Margins"));
1552 docPS->addPanel(langModule, N_("Language"));
1553 docPS->addPanel(colorModule, N_("Colors"));
1554 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1555 docPS->addPanel(biblioModule, N_("Bibliography"));
1556 docPS->addPanel(indicesModule, N_("Indexes"));
1557 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1558 docPS->addPanel(mathsModule, N_("Math Options"));
1559 docPS->addPanel(floatModule, N_("Float Placement"));
1560 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1561 docPS->addPanel(bulletsModule, N_("Bullets"));
1562 docPS->addPanel(branchesModule, N_("Branches"));
1563 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1564 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1565 docPS->setCurrentPanel("Document Class");
1566 // FIXME: hack to work around resizing bug in Qt >= 4.2
1567 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1568 #if QT_VERSION >= 0x040200
1569 docPS->updateGeometry();
1574 void GuiDocument::onBufferViewChanged()
1576 if (isVisibleView())
1577 initialiseParams("");
1581 void GuiDocument::saveDefaultClicked()
1587 void GuiDocument::useDefaultsClicked()
1593 void GuiDocument::change_adaptor()
1595 nonModuleChanged_ = true;
1600 void GuiDocument::shellescapeChanged()
1602 shellescapeChanged_ = true;
1607 void GuiDocument::slotApply()
1609 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1610 bool wasclean = buffer().isClean();
1611 GuiDialog::slotApply();
1612 if (wasclean && only_shellescape_changed)
1613 buffer().markClean();
1614 modulesChanged_ = false;
1618 void GuiDocument::slotOK()
1620 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1621 bool wasclean = buffer().isClean();
1622 GuiDialog::slotOK();
1623 if (wasclean && only_shellescape_changed)
1624 buffer().markClean();
1625 modulesChanged_ = false;
1629 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1634 string child = fromqstr(item->text(0));
1638 if (std::find(includeonlys_.begin(),
1639 includeonlys_.end(), child) != includeonlys_.end())
1640 includeonlys_.remove(child);
1642 includeonlys_.push_back(child);
1644 updateIncludeonlys();
1649 QString GuiDocument::validateListingsParameters()
1651 if (listingsModule->bypassCB->isChecked())
1653 string const package =
1654 lst_packages[listingsModule->packageCO->currentIndex()];
1655 string params = fromqstr(listingsModule->listingsED->toPlainText());
1656 InsetListingsParams lstparams(params);
1657 lstparams.setMinted(package == "Minted");
1658 return toqstr(lstparams.validate());
1662 void GuiDocument::setListingsMessage()
1665 static bool isOK = true;
1666 QString msg = validateListingsParameters();
1667 if (msg.isEmpty()) {
1671 // listingsTB->setTextColor("black");
1672 listingsModule->listingsTB->setPlainText(
1673 qt_("Input listings parameters below. "
1674 "Enter ? for a list of parameters."));
1677 // listingsTB->setTextColor("red");
1678 listingsModule->listingsTB->setPlainText(msg);
1683 void GuiDocument::listingsPackageChanged(int index)
1685 string const package = lst_packages[index];
1686 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1687 Alert::warning(_("Pygments driver command not found!"),
1688 _("The driver command necessary to use the minted package\n"
1689 "(pygmentize) has not been found. Make sure you have\n"
1690 "the python-pygments module installed or, if the driver\n"
1691 "is named differently, to add the following line to the\n"
1692 "document preamble:\n\n"
1693 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1694 "where 'driver' is name of the driver command."));
1699 void GuiDocument::setLSpacing(int item)
1701 textLayoutModule->lspacingLE->setEnabled(item == 3);
1705 void GuiDocument::setIndent(int item)
1707 bool const enable = (item == 1);
1708 textLayoutModule->indentLE->setEnabled(enable);
1709 textLayoutModule->indentLengthCO->setEnabled(enable);
1710 textLayoutModule->skipLE->setEnabled(false);
1711 textLayoutModule->skipLengthCO->setEnabled(false);
1716 void GuiDocument::enableIndent(bool indent)
1718 textLayoutModule->skipLE->setEnabled(!indent);
1719 textLayoutModule->skipLengthCO->setEnabled(!indent);
1721 setIndent(textLayoutModule->indentCO->currentIndex());
1725 void GuiDocument::setSkip(int item)
1727 bool const enable = (item == 3);
1728 textLayoutModule->skipLE->setEnabled(enable);
1729 textLayoutModule->skipLengthCO->setEnabled(enable);
1734 void GuiDocument::enableSkip(bool skip)
1736 textLayoutModule->indentLE->setEnabled(!skip);
1737 textLayoutModule->indentLengthCO->setEnabled(!skip);
1739 setSkip(textLayoutModule->skipCO->currentIndex());
1742 void GuiDocument::allowMathIndent() {
1743 // only disable when not checked, checked does not always allow enabling
1744 if (!mathsModule->MathIndentCB->isChecked()) {
1745 mathsModule->MathIndentLE->setEnabled(false);
1746 mathsModule->MathIndentLengthCO->setEnabled(false);
1748 if (mathsModule->MathIndentCB->isChecked()
1749 && mathsModule->MathIndentCO->currentIndex() == 1) {
1750 mathsModule->MathIndentLE->setEnabled(true);
1751 mathsModule->MathIndentLengthCO->setEnabled(true);
1756 void GuiDocument::enableMathIndent(int item)
1758 bool const enable = (item == 1);
1759 mathsModule->MathIndentLE->setEnabled(enable);
1760 mathsModule->MathIndentLengthCO->setEnabled(enable);
1765 void GuiDocument::setMargins()
1767 bool const extern_geometry =
1768 documentClass().provides("geometry");
1769 marginsModule->marginCB->setEnabled(!extern_geometry);
1770 if (extern_geometry) {
1771 marginsModule->marginCB->setChecked(false);
1772 setCustomMargins(true);
1774 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1775 setCustomMargins(!bp_.use_geometry);
1780 void GuiDocument::papersizeChanged(int paper_size)
1782 setCustomPapersize(paper_size == 1);
1786 void GuiDocument::setCustomPapersize(bool custom)
1788 pageLayoutModule->paperwidthL->setEnabled(custom);
1789 pageLayoutModule->paperwidthLE->setEnabled(custom);
1790 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1791 pageLayoutModule->paperheightL->setEnabled(custom);
1792 pageLayoutModule->paperheightLE->setEnabled(custom);
1793 pageLayoutModule->paperheightLE->setFocus();
1794 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1798 void GuiDocument::setColSep()
1800 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1804 void GuiDocument::setCustomMargins(bool custom)
1806 marginsModule->topL->setEnabled(!custom);
1807 marginsModule->topLE->setEnabled(!custom);
1808 marginsModule->topUnit->setEnabled(!custom);
1810 marginsModule->bottomL->setEnabled(!custom);
1811 marginsModule->bottomLE->setEnabled(!custom);
1812 marginsModule->bottomUnit->setEnabled(!custom);
1814 marginsModule->innerL->setEnabled(!custom);
1815 marginsModule->innerLE->setEnabled(!custom);
1816 marginsModule->innerUnit->setEnabled(!custom);
1818 marginsModule->outerL->setEnabled(!custom);
1819 marginsModule->outerLE->setEnabled(!custom);
1820 marginsModule->outerUnit->setEnabled(!custom);
1822 marginsModule->headheightL->setEnabled(!custom);
1823 marginsModule->headheightLE->setEnabled(!custom);
1824 marginsModule->headheightUnit->setEnabled(!custom);
1826 marginsModule->headsepL->setEnabled(!custom);
1827 marginsModule->headsepLE->setEnabled(!custom);
1828 marginsModule->headsepUnit->setEnabled(!custom);
1830 marginsModule->footskipL->setEnabled(!custom);
1831 marginsModule->footskipLE->setEnabled(!custom);
1832 marginsModule->footskipUnit->setEnabled(!custom);
1834 bool const enableColSep = !custom &&
1835 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1836 marginsModule->columnsepL->setEnabled(enableColSep);
1837 marginsModule->columnsepLE->setEnabled(enableColSep);
1838 marginsModule->columnsepUnit->setEnabled(enableColSep);
1842 void GuiDocument::changeBackgroundColor()
1844 QColor const & newColor = QColorDialog::getColor(
1845 rgb2qcolor(set_backgroundcolor), asQWidget());
1846 if (!newColor.isValid())
1848 // set the button color and text
1849 colorModule->backgroundPB->setStyleSheet(
1850 colorButtonStyleSheet(newColor));
1851 colorModule->backgroundPB->setText(qt_("&Change..."));
1853 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1854 is_backgroundcolor = true;
1859 void GuiDocument::deleteBackgroundColor()
1861 // set the button color back to default by setting an empty StyleSheet
1862 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1863 // change button text
1864 colorModule->backgroundPB->setText(qt_("&Default..."));
1865 // save default color (white)
1866 set_backgroundcolor = rgbFromHexName("#ffffff");
1867 is_backgroundcolor = false;
1872 void GuiDocument::changeFontColor()
1874 QColor const & newColor = QColorDialog::getColor(
1875 rgb2qcolor(set_fontcolor), asQWidget());
1876 if (!newColor.isValid())
1878 // set the button color and text
1879 colorModule->fontColorPB->setStyleSheet(
1880 colorButtonStyleSheet(newColor));
1881 colorModule->fontColorPB->setText(qt_("&Change..."));
1883 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1884 is_fontcolor = true;
1889 void GuiDocument::deleteFontColor()
1891 // set the button color back to default by setting an empty StyleSheet
1892 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1893 // change button text
1894 colorModule->fontColorPB->setText(qt_("&Default..."));
1895 // save default color (black)
1896 set_fontcolor = rgbFromHexName("#000000");
1897 is_fontcolor = false;
1902 void GuiDocument::changeNoteFontColor()
1904 QColor const & newColor = QColorDialog::getColor(
1905 rgb2qcolor(set_notefontcolor), asQWidget());
1906 if (!newColor.isValid())
1908 // set the button color
1909 colorModule->noteFontColorPB->setStyleSheet(
1910 colorButtonStyleSheet(newColor));
1912 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1917 void GuiDocument::deleteNoteFontColor()
1919 // set the button color back to pref
1920 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1921 colorModule->noteFontColorPB->setStyleSheet(
1922 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1927 void GuiDocument::changeBoxBackgroundColor()
1929 QColor const & newColor = QColorDialog::getColor(
1930 rgb2qcolor(set_boxbgcolor), asQWidget());
1931 if (!newColor.isValid())
1933 // set the button color
1934 colorModule->boxBackgroundPB->setStyleSheet(
1935 colorButtonStyleSheet(newColor));
1937 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1942 void GuiDocument::deleteBoxBackgroundColor()
1944 // set the button color back to pref
1945 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1946 colorModule->boxBackgroundPB->setStyleSheet(
1947 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1952 void GuiDocument::updateQuoteStyles(bool const set)
1954 Language const * lang = lyx::languages.getLanguage(
1955 fromqstr(langModule->languageCO->itemData(
1956 langModule->languageCO->currentIndex()).toString()));
1958 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1960 langModule->quoteStyleCO->clear();
1962 bool has_default = false;
1963 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1964 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1965 if (qs == InsetQuotesParams::DynamicQuotes)
1967 bool const langdef = (qs == def);
1969 // add the default style on top
1970 langModule->quoteStyleCO->insertItem(0,
1971 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1975 langModule->quoteStyleCO->addItem(
1976 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1978 if (set && has_default)
1979 // (re)set to the default style
1980 langModule->quoteStyleCO->setCurrentIndex(0);
1984 void GuiDocument::languageChanged(int i)
1986 // some languages only work with polyglossia
1987 Language const * lang = lyx::languages.getLanguage(
1988 fromqstr(langModule->languageCO->itemData(i).toString()));
1989 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1990 // If we force to switch fontspec on, store
1991 // current state (#8717)
1992 if (fontModule->osFontsCB->isEnabled())
1993 forced_fontspec_activation =
1994 !fontModule->osFontsCB->isChecked();
1995 fontModule->osFontsCB->setChecked(true);
1996 fontModule->osFontsCB->setEnabled(false);
1999 fontModule->osFontsCB->setEnabled(true);
2000 // If we have forced to switch fontspec on,
2001 // restore previous state (#8717)
2002 if (forced_fontspec_activation)
2003 fontModule->osFontsCB->setChecked(false);
2004 forced_fontspec_activation = false;
2007 // set appropriate quotation mark style
2008 updateQuoteStyles(true);
2012 void GuiDocument::osFontsChanged(bool nontexfonts)
2014 bool const tex_fonts = !nontexfonts;
2015 // store current fonts
2016 QString const font_roman = fontModule->fontsRomanCO->itemData(
2017 fontModule->fontsRomanCO->currentIndex()).toString();
2018 QString const font_sans = fontModule->fontsSansCO->itemData(
2019 fontModule->fontsSansCO->currentIndex()).toString();
2020 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2021 fontModule->fontsTypewriterCO->currentIndex()).toString();
2022 QString const font_math = fontModule->fontsMathCO->itemData(
2023 fontModule->fontsMathCO->currentIndex()).toString();
2024 int const font_sf_scale = fontModule->scaleSansSB->value();
2025 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2028 // store default format
2029 QString const dformat = outputModule->defaultFormatCO->itemData(
2030 outputModule->defaultFormatCO->currentIndex()).toString();
2031 updateDefaultFormat();
2032 // try to restore default format
2033 int index = outputModule->defaultFormatCO->findData(dformat);
2034 // set to default if format is not found
2037 outputModule->defaultFormatCO->setCurrentIndex(index);
2039 // try to restore fonts which were selected two toggles ago
2040 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2042 fontModule->fontsRomanCO->setCurrentIndex(index);
2043 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2045 fontModule->fontsSansCO->setCurrentIndex(index);
2046 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2048 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2049 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2051 fontModule->fontsMathCO->setCurrentIndex(index);
2052 // save fonts for next next toggle
2053 fontModule->font_roman = font_roman;
2054 fontModule->font_sans = font_sans;
2055 fontModule->font_typewriter = font_typewriter;
2056 fontModule->font_math = font_math;
2057 fontModule->font_sf_scale = font_sf_scale;
2058 fontModule->font_tt_scale = font_tt_scale;
2060 langModule->encodingCO->setEnabled(tex_fonts &&
2061 !langModule->defaultencodingRB->isChecked());
2062 langModule->defaultencodingRB->setEnabled(tex_fonts);
2063 langModule->otherencodingRB->setEnabled(tex_fonts);
2065 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2066 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2067 fontModule->cjkFontLE->setEnabled(tex_fonts);
2068 fontModule->cjkFontLA->setEnabled(tex_fonts);
2070 updateFontOptions();
2072 fontModule->fontencLA->setEnabled(tex_fonts);
2073 fontModule->fontencCO->setEnabled(tex_fonts);
2075 fontModule->fontencLE->setEnabled(false);
2077 fontencChanged(fontModule->fontencCO->currentIndex());
2081 void GuiDocument::mathFontChanged(int)
2083 updateFontOptions();
2087 void GuiDocument::fontOsfToggled(bool state)
2089 if (fontModule->osFontsCB->isChecked())
2091 QString font = fontModule->fontsRomanCO->itemData(
2092 fontModule->fontsRomanCO->currentIndex()).toString();
2093 if (hasMonolithicExpertSet(font))
2094 fontModule->fontScCB->setChecked(state);
2098 void GuiDocument::fontScToggled(bool state)
2100 if (fontModule->osFontsCB->isChecked())
2102 QString font = fontModule->fontsRomanCO->itemData(
2103 fontModule->fontsRomanCO->currentIndex()).toString();
2104 if (hasMonolithicExpertSet(font))
2105 fontModule->fontOsfCB->setChecked(state);
2109 void GuiDocument::updateFontOptions()
2111 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2114 font = fontModule->fontsSansCO->itemData(
2115 fontModule->fontsSansCO->currentIndex()).toString();
2116 bool scaleable = providesScale(font);
2117 fontModule->scaleSansSB->setEnabled(scaleable);
2118 fontModule->scaleSansLA->setEnabled(scaleable);
2120 font = fontModule->fontsTypewriterCO->itemData(
2121 fontModule->fontsTypewriterCO->currentIndex()).toString();
2122 scaleable = providesScale(font);
2123 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2124 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2126 font = fontModule->fontsRomanCO->itemData(
2127 fontModule->fontsRomanCO->currentIndex()).toString();
2128 fontModule->fontScCB->setEnabled(providesSC(font));
2129 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2130 updateMathFonts(font);
2134 void GuiDocument::updateFontsize(string const & items, string const & sel)
2136 fontModule->fontsizeCO->clear();
2137 fontModule->fontsizeCO->addItem(qt_("Default"));
2139 for (int n = 0; !token(items,'|',n).empty(); ++n)
2140 fontModule->fontsizeCO->
2141 addItem(toqstr(token(items,'|',n)));
2143 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2144 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2145 fontModule->fontsizeCO->setCurrentIndex(n);
2152 bool GuiDocument::ot1() const
2154 QString const fontenc =
2155 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2156 return (fontenc == "default"
2157 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2158 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2162 bool GuiDocument::completeFontset() const
2164 return (fontModule->fontsSansCO->itemData(
2165 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2166 && fontModule->fontsSansCO->itemData(
2167 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2171 bool GuiDocument::noMathFont() const
2173 return (fontModule->fontsMathCO->itemData(
2174 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2178 void GuiDocument::updateTexFonts()
2180 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2182 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2183 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2184 for (; it != end; ++it) {
2185 LaTeXFont lf = it->second;
2186 if (lf.name().empty()) {
2187 LYXERR0("Error: Unnamed font: " << it->first);
2190 docstring const family = lf.family();
2191 docstring guiname = translateIfPossible(lf.guiname());
2192 if (!lf.available(ot1(), noMathFont()))
2193 guiname += _(" (not installed)");
2195 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2196 else if (family == "sf")
2197 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2198 else if (family == "tt")
2199 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2200 else if (family == "math")
2201 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2206 void GuiDocument::updateFontlist()
2208 fontModule->fontsRomanCO->clear();
2209 fontModule->fontsSansCO->clear();
2210 fontModule->fontsTypewriterCO->clear();
2211 fontModule->fontsMathCO->clear();
2213 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2214 if (fontModule->osFontsCB->isChecked()) {
2215 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2216 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2217 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2218 QString unimath = qt_("Non-TeX Fonts Default");
2219 if (!LaTeXFeatures::isAvailable("unicode-math"))
2220 unimath += qt_(" (not available)");
2221 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2222 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2224 QFontDatabase fontdb;
2225 QStringList families(fontdb.families());
2226 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2227 fontModule->fontsRomanCO->addItem(*it, *it);
2228 fontModule->fontsSansCO->addItem(*it, *it);
2229 fontModule->fontsTypewriterCO->addItem(*it, *it);
2234 if (rmfonts_.empty())
2237 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2238 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2239 while (rmi != rmfonts_.constEnd()) {
2240 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2244 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2245 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2246 while (sfi != sffonts_.constEnd()) {
2247 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2251 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2252 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2253 while (tti != ttfonts_.constEnd()) {
2254 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2258 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2259 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2260 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2261 while (mmi != mathfonts_.constEnd()) {
2262 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2268 void GuiDocument::fontencChanged(int item)
2270 fontModule->fontencLE->setEnabled(
2271 fontModule->fontencCO->itemData(item).toString() == "custom");
2272 // The availability of TeX fonts depends on the font encoding
2274 updateFontOptions();
2278 void GuiDocument::updateMathFonts(QString const & rm)
2280 if (fontModule->osFontsCB->isChecked())
2282 QString const math =
2283 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2284 int const i = fontModule->fontsMathCO->findData("default");
2285 if (providesNoMath(rm) && i == -1)
2286 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2287 else if (!providesNoMath(rm) && i != -1) {
2288 int const c = fontModule->fontsMathCO->currentIndex();
2289 fontModule->fontsMathCO->removeItem(i);
2291 fontModule->fontsMathCO->setCurrentIndex(0);
2296 void GuiDocument::romanChanged(int item)
2298 if (fontModule->osFontsCB->isChecked())
2300 QString const font =
2301 fontModule->fontsRomanCO->itemData(item).toString();
2302 fontModule->fontScCB->setEnabled(providesSC(font));
2303 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2304 updateMathFonts(font);
2308 void GuiDocument::sansChanged(int item)
2310 if (fontModule->osFontsCB->isChecked())
2312 QString const font =
2313 fontModule->fontsSansCO->itemData(item).toString();
2314 bool scaleable = providesScale(font);
2315 fontModule->scaleSansSB->setEnabled(scaleable);
2316 fontModule->scaleSansLA->setEnabled(scaleable);
2320 void GuiDocument::ttChanged(int item)
2322 if (fontModule->osFontsCB->isChecked())
2324 QString const font =
2325 fontModule->fontsTypewriterCO->itemData(item).toString();
2326 bool scaleable = providesScale(font);
2327 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2328 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2332 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2335 pageLayoutModule->pagestyleCO->clear();
2336 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2338 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2339 string style = token(items, '|', n);
2340 QString style_gui = qt_(style);
2341 pagestyles.push_back(pair<string, QString>(style, style_gui));
2342 pageLayoutModule->pagestyleCO->addItem(style_gui);
2345 if (sel == "default") {
2346 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2352 for (size_t i = 0; i < pagestyles.size(); ++i)
2353 if (pagestyles[i].first == sel)
2354 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2357 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2361 void GuiDocument::browseLayout()
2363 QString const label1 = qt_("Layouts|#o#O");
2364 QString const dir1 = toqstr(lyxrc.document_path);
2365 QStringList const filter(qt_("LyX Layout (*.layout)"));
2366 QString file = browseRelToParent(QString(), bufferFilePath(),
2367 qt_("Local layout file"), filter, false,
2370 if (!file.endsWith(".layout"))
2373 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2374 fromqstr(bufferFilePath()));
2376 int const ret = Alert::prompt(_("Local layout file"),
2377 _("The layout file you have selected is a local layout\n"
2378 "file, not one in the system or user directory.\n"
2379 "Your document will not work with this layout if you\n"
2380 "move the layout file to a different directory."),
2381 1, 1, _("&Set Layout"), _("&Cancel"));
2385 // load the layout file
2386 LayoutFileList & bcl = LayoutFileList::get();
2387 string classname = layoutFile.onlyFileName();
2388 // this will update an existing layout if that layout has been loaded before.
2389 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2390 classname.substr(0, classname.size() - 7),
2391 layoutFile.onlyPath().absFileName()));
2394 Alert::error(_("Error"),
2395 _("Unable to read local layout file."));
2399 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2401 // do not trigger classChanged if there is no change.
2402 if (latexModule->classCO->currentText() == toqstr(name))
2406 bool const avail = latexModule->classCO->set(toqstr(name));
2408 LayoutFile const & tc = bcl[name];
2409 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2410 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2411 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2412 tooltip += '\n' + qt_("This is a local layout file.");
2413 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2414 toqstr(translateIfPossible(from_utf8(tc.category()))),
2416 true, true, true, true);
2417 latexModule->classCO->set(toqstr(name));
2424 void GuiDocument::browseMaster()
2426 QString const title = qt_("Select master document");
2427 QString const dir1 = toqstr(lyxrc.document_path);
2428 QString const old = latexModule->childDocLE->text();
2429 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2430 QStringList const filter(qt_("LyX Files (*.lyx)"));
2431 QString file = browseRelToSub(old, docpath, title, filter, false,
2432 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2434 if (!file.isEmpty())
2435 latexModule->childDocLE->setText(file);
2439 void GuiDocument::classChanged_adaptor()
2441 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2446 void GuiDocument::classChanged()
2448 int idx = latexModule->classCO->currentIndex();
2451 string const classname = fromqstr(latexModule->classCO->getData(idx));
2453 if (applyPB->isEnabled()) {
2454 int const ret = Alert::prompt(_("Unapplied changes"),
2455 _("Some changes in the dialog were not yet applied.\n"
2456 "If you do not apply now, they will be lost after this action."),
2457 1, 1, _("&Apply"), _("&Dismiss"));
2462 // We load the TextClass as soon as it is selected. This is
2463 // necessary so that other options in the dialog can be updated
2464 // according to the new class. Note, however, that, if you use
2465 // the scroll wheel when sitting on the combo box, we'll load a
2466 // lot of TextClass objects very quickly....
2467 if (!bp_.setBaseClass(classname)) {
2468 Alert::error(_("Error"), _("Unable to set document class."));
2471 if (lyxrc.auto_reset_options)
2472 bp_.useClassDefaults();
2474 // With the introduction of modules came a distinction between the base
2475 // class and the document class. The former corresponds to the main layout
2476 // file; the latter is that plus the modules (or the document-specific layout,
2477 // or whatever else there could be). Our parameters come from the document
2478 // class. So when we set the base class, we also need to recreate the document
2479 // class. Otherwise, we still have the old one.
2480 bp_.makeDocumentClass();
2485 void GuiDocument::languagePackageChanged(int i)
2487 langModule->languagePackageLE->setEnabled(
2488 langModule->languagePackageCO->itemData(i).toString() == "custom");
2492 void GuiDocument::biblioChanged()
2494 biblioChanged_ = true;
2499 void GuiDocument::checkPossibleCiteEngines()
2501 // Check if the class provides a specific engine,
2502 // and if so, enforce this.
2503 string force_engine;
2504 if (documentClass().provides("natbib")
2505 || documentClass().provides("natbib-internal"))
2506 force_engine = "natbib";
2507 else if (documentClass().provides("jurabib"))
2508 force_engine = "jurabib";
2509 else if (documentClass().provides("biblatex"))
2510 force_engine = "biblatex";
2511 else if (documentClass().provides("biblatex-natbib"))
2512 force_engine = "biblatex-natbib";
2514 if (!force_engine.empty())
2515 biblioModule->citeEngineCO->setCurrentIndex(
2516 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2517 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2521 void GuiDocument::rescanBibFiles()
2524 rescanTexStyles("bbx cbx");
2526 rescanTexStyles("bst");
2530 void GuiDocument::resetDefaultBibfile(string const & which)
2532 QString const engine =
2533 biblioModule->citeEngineCO->itemData(
2534 biblioModule->citeEngineCO->currentIndex()).toString();
2536 CiteEngineType const cet =
2537 CiteEngineType(biblioModule->citeStyleCO->itemData(
2538 biblioModule->citeStyleCO->currentIndex()).toInt());
2540 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2544 void GuiDocument::resetDefaultBbxBibfile()
2546 resetDefaultBibfile("bbx");
2550 void GuiDocument::resetDefaultCbxBibfile()
2552 resetDefaultBibfile("cbx");
2556 void GuiDocument::citeEngineChanged(int n)
2558 QString const engine =
2559 biblioModule->citeEngineCO->itemData(n).toString();
2561 vector<string> const engs =
2562 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2564 updateCiteStyles(engs);
2565 updateEngineDependends();
2566 resetDefaultBibfile();
2571 void GuiDocument::updateEngineDependends()
2573 bool const biblatex = isBiblatex();
2575 // These are only useful with BibTeX
2576 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2577 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2578 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2579 biblioModule->bibtopicCB->setEnabled(!biblatex);
2581 // These are only useful with Biblatex
2582 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2583 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2584 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2585 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2586 biblioModule->resetBbxPB->setEnabled(biblatex);
2587 biblioModule->resetCbxPB->setEnabled(biblatex);
2588 biblioModule->matchBbxPB->setEnabled(biblatex);
2590 // These are useful with biblatex, jurabib and natbib
2591 QString const engine =
2592 biblioModule->citeEngineCO->itemData(
2593 biblioModule->citeEngineCO->currentIndex()).toString();
2594 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2596 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2597 || ce->requires("natbib.sty");
2598 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2599 biblioModule->citePackageOptionsL->setEnabled(citepack);
2603 void GuiDocument::citeStyleChanged()
2605 QString const engine =
2606 biblioModule->citeEngineCO->itemData(
2607 biblioModule->citeEngineCO->currentIndex()).toString();
2608 QString const currentDef = isBiblatex() ?
2609 biblioModule->biblatexBbxCO->currentText()
2610 : biblioModule->defaultBiblioCO->currentText();
2611 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2612 resetDefaultBibfile();
2618 void GuiDocument::bibtexChanged(int n)
2620 biblioModule->bibtexOptionsLE->setEnabled(
2621 biblioModule->bibtexCO->itemData(n).toString() != "default");
2626 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2628 biblioModule->citeStyleCO->clear();
2630 vector<string>::const_iterator it = engs.begin();
2631 vector<string>::const_iterator end = engs.end();
2632 for (; it != end; ++it) {
2633 if (*it == "default")
2634 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2635 ENGINE_TYPE_DEFAULT);
2636 else if (*it == "authoryear")
2637 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2638 ENGINE_TYPE_AUTHORYEAR);
2639 else if (*it == "numerical")
2640 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2641 ENGINE_TYPE_NUMERICAL);
2643 int i = biblioModule->citeStyleCO->findData(sel);
2644 if (biblioModule->citeStyleCO->findData(sel) == -1)
2646 biblioModule->citeStyleCO->setCurrentIndex(i);
2648 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2649 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2653 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2655 engine_types_.clear();
2659 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2661 string style = token(items, '|', n);
2662 engine_types_.push_back(style);
2665 updateCiteStyles(engine_types_, sel);
2671 // both of these should take a vector<docstring>
2673 // This is an insanely complicated attempt to make this sort of thing
2674 // work with RTL languages.
2675 docstring formatStrVec(vector<string> const & v, docstring const & s)
2677 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2681 return translateIfPossible(from_utf8(v[0]));
2682 if (v.size() == 2) {
2683 docstring retval = _("%1$s and %2$s");
2684 retval = subst(retval, _("and"), s);
2685 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2686 translateIfPossible(from_utf8(v[1])));
2688 // The idea here is to format all but the last two items...
2689 int const vSize = v.size();
2690 docstring t2 = _("%1$s, %2$s");
2691 docstring retval = translateIfPossible(from_utf8(v[0]));
2692 for (int i = 1; i < vSize - 2; ++i)
2693 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2694 //...and then to plug them, and the last two, into this schema
2695 docstring t = _("%1$s, %2$s, and %3$s");
2696 t = subst(t, _("and"), s);
2697 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2698 translateIfPossible(from_utf8(v[vSize - 1])));
2701 vector<string> idsToNames(vector<string> const & idList)
2703 vector<string> retval;
2704 vector<string>::const_iterator it = idList.begin();
2705 vector<string>::const_iterator end = idList.end();
2706 for (; it != end; ++it) {
2707 LyXModule const * const mod = theModuleList[*it];
2709 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2710 translateIfPossible(from_utf8(*it)))));
2712 retval.push_back(mod->getName());
2716 } // end anonymous namespace
2719 void GuiDocument::modulesToParams(BufferParams & bp)
2721 // update list of loaded modules
2722 bp.clearLayoutModules();
2723 int const srows = modules_sel_model_.rowCount();
2724 for (int i = 0; i < srows; ++i)
2725 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2727 // update the list of removed modules
2728 bp.clearRemovedModules();
2729 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2730 list<string>::const_iterator rit = reqmods.begin();
2731 list<string>::const_iterator ren = reqmods.end();
2733 // check each of the default modules
2734 for (; rit != ren; ++rit) {
2735 list<string>::const_iterator mit = bp.getModules().begin();
2736 list<string>::const_iterator men = bp.getModules().end();
2738 for (; mit != men; ++mit) {
2745 // the module isn't present so must have been removed by the user
2746 bp.addRemovedModule(*rit);
2751 void GuiDocument::modulesChanged()
2753 modulesToParams(bp_);
2755 if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2756 int const ret = Alert::prompt(_("Unapplied changes"),
2757 _("Some changes in the dialog were not yet applied.\n"
2758 "If you do not apply now, they will be lost after this action."),
2759 1, 1, _("&Apply"), _("&Dismiss"));
2764 modulesChanged_ = true;
2765 bp_.makeDocumentClass();
2771 void GuiDocument::updateModuleInfo()
2773 selectionManager->update();
2775 //Module description
2776 bool const focus_on_selected = selectionManager->selectedFocused();
2777 QAbstractItemView * lv;
2778 if (focus_on_selected)
2779 lv = modulesModule->selectedLV;
2781 lv = modulesModule->availableLV;
2782 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2783 modulesModule->infoML->document()->clear();
2786 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2787 GuiIdListModel const & id_model =
2788 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2789 string const modName = id_model.getIDString(idx.row());
2790 docstring desc = getModuleDescription(modName);
2792 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2793 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2796 desc += _("Module provided by document class.");
2799 docstring cat = getModuleCategory(modName);
2803 desc += bformat(_("Category: %1$s."), cat);
2806 vector<string> pkglist = getPackageList(modName);
2807 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2808 if (!pkgdesc.empty()) {
2811 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2814 pkglist = getRequiredList(modName);
2815 if (!pkglist.empty()) {
2816 vector<string> const reqdescs = idsToNames(pkglist);
2817 pkgdesc = formatStrVec(reqdescs, _("or"));
2820 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2823 pkglist = getExcludedList(modName);
2824 if (!pkglist.empty()) {
2825 vector<string> const reqdescs = idsToNames(pkglist);
2826 pkgdesc = formatStrVec(reqdescs, _( "and"));
2829 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2832 if (!isModuleAvailable(modName)) {
2835 desc += _("WARNING: Some required packages are unavailable!");
2838 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2842 void GuiDocument::updateNumbering()
2844 DocumentClass const & tclass = documentClass();
2846 numberingModule->tocTW->setUpdatesEnabled(false);
2847 numberingModule->tocTW->clear();
2849 int const depth = numberingModule->depthSL->value();
2850 int const toc = numberingModule->tocSL->value();
2851 QString const no = qt_("No");
2852 QString const yes = qt_("Yes");
2853 QTreeWidgetItem * item = 0;
2855 DocumentClass::const_iterator lit = tclass.begin();
2856 DocumentClass::const_iterator len = tclass.end();
2857 for (; lit != len; ++lit) {
2858 int const toclevel = lit->toclevel;
2859 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2860 item = new QTreeWidgetItem(numberingModule->tocTW);
2861 item->setText(0, toqstr(translateIfPossible(lit->name())));
2862 item->setText(1, (toclevel <= depth) ? yes : no);
2863 item->setText(2, (toclevel <= toc) ? yes : no);
2867 numberingModule->tocTW->setUpdatesEnabled(true);
2868 numberingModule->tocTW->update();
2872 void GuiDocument::updateDefaultFormat()
2876 // make a copy in order to consider unapplied changes
2877 BufferParams param_copy = buffer().params();
2878 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2879 int const idx = latexModule->classCO->currentIndex();
2881 string const classname = fromqstr(latexModule->classCO->getData(idx));
2882 param_copy.setBaseClass(classname);
2883 param_copy.makeDocumentClass(true);
2885 outputModule->defaultFormatCO->blockSignals(true);
2886 outputModule->defaultFormatCO->clear();
2887 outputModule->defaultFormatCO->addItem(qt_("Default"),
2888 QVariant(QString("default")));
2889 FormatList const & formats =
2890 param_copy.exportableFormats(true);
2891 for (Format const * f : formats)
2892 outputModule->defaultFormatCO->addItem
2893 (toqstr(translateIfPossible(f->prettyname())),
2894 QVariant(toqstr(f->name())));
2895 outputModule->defaultFormatCO->blockSignals(false);
2899 bool GuiDocument::isChildIncluded(string const & child)
2901 if (includeonlys_.empty())
2903 return (std::find(includeonlys_.begin(),
2904 includeonlys_.end(), child) != includeonlys_.end());
2908 void GuiDocument::applyView()
2911 preambleModule->apply(bp_);
2912 localLayout->apply(bp_);
2915 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2916 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2919 string const engine =
2920 fromqstr(biblioModule->citeEngineCO->itemData(
2921 biblioModule->citeEngineCO->currentIndex()).toString());
2922 bp_.setCiteEngine(engine);
2924 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2925 biblioModule->citeStyleCO->currentIndex()).toInt());
2926 if (theCiteEnginesList[engine]->hasEngineType(style))
2927 bp_.setCiteEngineType(style);
2929 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2931 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2933 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2934 biblioModule->bibunitsCO->currentIndex()).toString());
2936 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2938 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2939 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2940 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2942 string const bibtex_command =
2943 fromqstr(biblioModule->bibtexCO->itemData(
2944 biblioModule->bibtexCO->currentIndex()).toString());
2945 string const bibtex_options =
2946 fromqstr(biblioModule->bibtexOptionsLE->text());
2947 if (bibtex_command == "default" || bibtex_options.empty())
2948 bp_.bibtex_command = bibtex_command;
2950 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2952 if (biblioChanged_) {
2953 buffer().invalidateBibinfoCache();
2954 buffer().removeBiblioTempFiles();
2958 indicesModule->apply(bp_);
2960 // language & quotes
2961 if (langModule->defaultencodingRB->isChecked()) {
2962 bp_.inputenc = "auto";
2964 int i = langModule->encodingCO->currentIndex();
2966 bp_.inputenc = "default";
2968 QString const enc_gui =
2969 langModule->encodingCO->currentText();
2970 Encodings::const_iterator it = encodings.begin();
2971 Encodings::const_iterator const end = encodings.end();
2973 for (; it != end; ++it) {
2974 if (qt_(it->guiName()) == enc_gui &&
2976 bp_.inputenc = it->name();
2982 // should not happen
2983 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2984 bp_.inputenc = "default";
2989 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2990 langModule->quoteStyleCO->currentIndex()).toInt();
2991 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2993 QString const langname = langModule->languageCO->itemData(
2994 langModule->languageCO->currentIndex()).toString();
2995 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2996 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2997 // If current cursor language was the document language, then update it too.
2998 if (cur.current_font.language() == bp_.language) {
2999 cur.current_font.setLanguage(newlang);
3000 cur.real_current_font.setLanguage(newlang);
3002 bp_.language = newlang;
3004 QString const pack = langModule->languagePackageCO->itemData(
3005 langModule->languagePackageCO->currentIndex()).toString();
3006 if (pack == "custom")
3008 fromqstr(langModule->languagePackageLE->text());
3010 bp_.lang_package = fromqstr(pack);
3013 bp_.backgroundcolor = set_backgroundcolor;
3014 bp_.isbackgroundcolor = is_backgroundcolor;
3015 bp_.fontcolor = set_fontcolor;
3016 bp_.isfontcolor = is_fontcolor;
3017 bp_.notefontcolor = set_notefontcolor;
3018 bp_.boxbgcolor = set_boxbgcolor;
3021 if (bp_.documentClass().hasTocLevels()) {
3022 bp_.tocdepth = numberingModule->tocSL->value();
3023 bp_.secnumdepth = numberingModule->depthSL->value();
3027 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3028 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3029 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3030 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3033 bp_.graphics_driver =
3034 tex_graphics[latexModule->psdriverCO->currentIndex()];
3037 int idx = latexModule->classCO->currentIndex();
3039 string const classname = fromqstr(latexModule->classCO->getData(idx));
3040 bp_.setBaseClass(classname);
3044 modulesToParams(bp_);
3047 map<string, string> const & packages = BufferParams::auto_packages();
3048 for (map<string, string>::const_iterator it = packages.begin();
3049 it != packages.end(); ++it) {
3050 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3053 int row = mathsModule->packagesTW->row(item);
3056 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3057 if (rb->isChecked()) {
3058 bp_.use_package(it->first, BufferParams::package_auto);
3061 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3062 if (rb->isChecked()) {
3063 bp_.use_package(it->first, BufferParams::package_on);
3066 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3067 if (rb->isChecked())
3068 bp_.use_package(it->first, BufferParams::package_off);
3070 // if math is indented
3071 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3072 if (bp_.is_math_indent) {
3073 // if formulas are indented
3074 switch (mathsModule->MathIndentCO->currentIndex()) {
3076 bp_.setMathIndent(Length());
3079 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3080 mathsModule->MathIndentLengthCO));
3081 bp_.setMathIndent(mathindent);
3085 // this should never happen
3086 bp_.setMathIndent(Length());
3090 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3092 bp_.math_numbering_side = BufferParams::LEFT;
3095 bp_.math_numbering_side = BufferParams::DEFAULT;
3098 bp_.math_numbering_side = BufferParams::RIGHT;
3101 // this should never happen
3102 bp_.math_numbering_side = BufferParams::DEFAULT;
3107 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3108 bp_.pagestyle = "default";
3110 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3111 for (size_t i = 0; i != pagestyles.size(); ++i)
3112 if (pagestyles[i].second == style_gui)
3113 bp_.pagestyle = pagestyles[i].first;
3117 switch (textLayoutModule->lspacingCO->currentIndex()) {
3119 bp_.spacing().set(Spacing::Single);
3122 bp_.spacing().set(Spacing::Onehalf);
3125 bp_.spacing().set(Spacing::Double);
3128 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3130 bp_.spacing().set(Spacing::Single);
3132 bp_.spacing().set(Spacing::Other, s);
3137 if (textLayoutModule->twoColumnCB->isChecked())
3142 bp_.justification = textLayoutModule->justCB->isChecked();
3144 if (textLayoutModule->indentRB->isChecked()) {
3145 // if paragraphs are separated by an indentation
3146 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3147 switch (textLayoutModule->indentCO->currentIndex()) {
3149 bp_.setParIndent(Length());
3152 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3153 textLayoutModule->indentLengthCO));
3154 bp_.setParIndent(parindent);
3158 // this should never happen
3159 bp_.setParIndent(Length());
3163 // if paragraphs are separated by a skip
3164 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3165 switch (textLayoutModule->skipCO->currentIndex()) {
3167 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3170 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3173 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3178 widgetsToLength(textLayoutModule->skipLE,
3179 textLayoutModule->skipLengthCO)
3185 // this should never happen
3186 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3192 fromqstr(latexModule->optionsLE->text());
3194 bp_.use_default_options =
3195 latexModule->defaultOptionsCB->isChecked();
3197 if (latexModule->childDocGB->isChecked())
3199 fromqstr(latexModule->childDocLE->text());
3201 bp_.master = string();
3204 bp_.clearIncludedChildren();
3205 if (masterChildModule->includeonlyRB->isChecked()) {
3206 list<string>::const_iterator it = includeonlys_.begin();
3207 for (; it != includeonlys_.end() ; ++it) {
3208 bp_.addIncludedChildren(*it);
3211 bp_.maintain_unincluded_children =
3212 masterChildModule->maintainAuxCB->isChecked();
3215 bp_.float_placement = floatModule->get();
3218 // text should have passed validation
3219 idx = listingsModule->packageCO->currentIndex();
3220 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3221 bp_.listings_params =
3222 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3225 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3226 outputModule->defaultFormatCO->currentIndex()).toString());
3228 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3229 bp_.useNonTeXFonts = nontexfonts;
3231 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3232 if (!bp_.shell_escape)
3233 theSession().shellescapeFiles().remove(buffer().absFileName());
3234 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3235 theSession().shellescapeFiles().insert(buffer().absFileName());
3236 Buffer & buf = const_cast<Buffer &>(buffer());
3237 buf.params().shell_escape = bp_.shell_escape;
3239 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3241 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3243 int mathfmt = outputModule->mathoutCB->currentIndex();
3246 BufferParams::MathOutput const mo =
3247 static_cast<BufferParams::MathOutput>(mathfmt);
3248 bp_.html_math_output = mo;
3249 bp_.html_be_strict = outputModule->strictCB->isChecked();
3250 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3251 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3252 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3254 bp_.save_transient_properties =
3255 outputModule->saveTransientPropertiesCB->isChecked();
3258 bp_.fonts_roman[nontexfonts] =
3259 fromqstr(fontModule->fontsRomanCO->
3260 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3261 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3263 bp_.fonts_sans[nontexfonts] =
3264 fromqstr(fontModule->fontsSansCO->
3265 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3266 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3268 bp_.fonts_typewriter[nontexfonts] =
3269 fromqstr(fontModule->fontsTypewriterCO->
3270 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3271 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3273 bp_.fonts_math[nontexfonts] =
3274 fromqstr(fontModule->fontsMathCO->
3275 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3276 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3278 QString const fontenc =
3279 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3280 if (fontenc == "custom")
3281 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3283 bp_.fontenc = fromqstr(fontenc);
3286 fromqstr(fontModule->cjkFontLE->text());
3288 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3289 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3291 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3292 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3294 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3295 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3297 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3299 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3302 bp_.fonts_default_family = "default";
3304 bp_.fonts_default_family = GuiDocument::fontfamilies[
3305 fontModule->fontsDefaultCO->currentIndex()];
3307 if (fontModule->fontsizeCO->currentIndex() == 0)
3308 bp_.fontsize = "default";
3311 fromqstr(fontModule->fontsizeCO->currentText());
3314 bp_.papersize = PAPER_SIZE(
3315 pageLayoutModule->papersizeCO->currentIndex());
3317 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3318 pageLayoutModule->paperwidthUnitCO);
3320 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3321 pageLayoutModule->paperheightUnitCO);
3323 if (pageLayoutModule->facingPagesCB->isChecked())
3324 bp_.sides = TwoSides;
3326 bp_.sides = OneSide;
3328 if (pageLayoutModule->landscapeRB->isChecked())
3329 bp_.orientation = ORIENTATION_LANDSCAPE;
3331 bp_.orientation = ORIENTATION_PORTRAIT;
3334 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3336 Ui::MarginsUi const * m = marginsModule;
3338 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3339 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3340 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3341 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3342 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3343 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3344 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3345 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3348 branchesModule->apply(bp_);
3351 PDFOptions & pdf = bp_.pdfoptions();
3352 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3353 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3354 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3355 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3356 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3358 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3359 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3360 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3361 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3363 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3364 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3365 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3366 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3368 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3369 if (pdfSupportModule->fullscreenCB->isChecked())
3370 pdf.pagemode = pdf.pagemode_fullscreen;
3372 pdf.pagemode.clear();
3373 pdf.quoted_options = pdf.quoted_options_check(
3374 fromqstr(pdfSupportModule->optionsLE->text()));
3377 nonModuleChanged_ = false;
3378 shellescapeChanged_ = false;
3382 void GuiDocument::paramsToDialog()
3384 // set the default unit
3385 Length::UNIT const default_unit = Length::defaultUnit();
3388 preambleModule->update(bp_, id());
3389 localLayout->update(bp_, id());
3392 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3393 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3396 string const cite_engine = bp_.citeEngine().list().front();
3398 biblioModule->citeEngineCO->setCurrentIndex(
3399 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3401 updateEngineType(documentClass().opt_enginetype(),
3402 bp_.citeEngineType());
3404 checkPossibleCiteEngines();
3406 biblioModule->citeStyleCO->setCurrentIndex(
3407 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3409 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3411 biblioModule->bibunitsCO->clear();
3412 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3413 if (documentClass().hasLaTeXLayout("part"))
3414 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3415 if (documentClass().hasLaTeXLayout("chapter"))
3416 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3417 if (documentClass().hasLaTeXLayout("section"))
3418 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3419 if (documentClass().hasLaTeXLayout("subsection"))
3420 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3421 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3423 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3425 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3427 biblioModule->bibunitsCO->setCurrentIndex(0);
3429 updateEngineDependends();
3432 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3433 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3435 updateDefaultBiblio(bp_.defaultBiblioStyle());
3437 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3441 split(bp_.bibtex_command, command, ' ');
3443 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3445 biblioModule->bibtexCO->setCurrentIndex(bpos);
3446 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3448 // We reset to default if we do not know the specified compiler
3449 // This is for security reasons
3450 biblioModule->bibtexCO->setCurrentIndex(
3451 biblioModule->bibtexCO->findData(toqstr("default")));
3452 biblioModule->bibtexOptionsLE->clear();
3454 biblioModule->bibtexOptionsLE->setEnabled(
3455 biblioModule->bibtexCO->currentIndex() != 0);
3457 biblioChanged_ = false;
3460 // We may be called when there is no Buffer, e.g., when
3461 // the last view has just been closed.
3462 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3463 indicesModule->update(bp_, isReadOnly);
3465 // language & quotes
3466 int const pos = langModule->languageCO->findData(toqstr(
3467 bp_.language->lang()));
3468 langModule->languageCO->setCurrentIndex(pos);
3470 updateQuoteStyles();
3472 langModule->quoteStyleCO->setCurrentIndex(
3473 langModule->quoteStyleCO->findData(bp_.quotes_style));
3474 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3476 bool default_enc = true;
3477 if (bp_.inputenc != "auto") {
3478 default_enc = false;
3479 if (bp_.inputenc == "default") {
3480 langModule->encodingCO->setCurrentIndex(0);
3483 Encodings::const_iterator it = encodings.begin();
3484 Encodings::const_iterator const end = encodings.end();
3485 for (; it != end; ++it) {
3486 if (it->name() == bp_.inputenc &&
3488 enc_gui = it->guiName();
3492 int const i = langModule->encodingCO->findText(
3495 langModule->encodingCO->setCurrentIndex(i);
3497 // unknown encoding. Set to default.
3501 langModule->defaultencodingRB->setChecked(default_enc);
3502 langModule->otherencodingRB->setChecked(!default_enc);
3504 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3506 langModule->languagePackageCO->setCurrentIndex(
3507 langModule->languagePackageCO->findData("custom"));
3508 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3510 langModule->languagePackageCO->setCurrentIndex(p);
3511 langModule->languagePackageLE->clear();
3515 if (bp_.isfontcolor) {
3516 colorModule->fontColorPB->setStyleSheet(
3517 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3519 set_fontcolor = bp_.fontcolor;
3520 is_fontcolor = bp_.isfontcolor;
3522 colorModule->noteFontColorPB->setStyleSheet(
3523 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3524 set_notefontcolor = bp_.notefontcolor;
3526 if (bp_.isbackgroundcolor) {
3527 colorModule->backgroundPB->setStyleSheet(
3528 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3530 set_backgroundcolor = bp_.backgroundcolor;
3531 is_backgroundcolor = bp_.isbackgroundcolor;
3533 colorModule->boxBackgroundPB->setStyleSheet(
3534 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3535 set_boxbgcolor = bp_.boxbgcolor;
3538 int const min_toclevel = documentClass().min_toclevel();
3539 int const max_toclevel = documentClass().max_toclevel();
3540 if (documentClass().hasTocLevels()) {
3541 numberingModule->setEnabled(true);
3542 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3543 numberingModule->depthSL->setMaximum(max_toclevel);
3544 numberingModule->depthSL->setValue(bp_.secnumdepth);
3545 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3546 numberingModule->tocSL->setMaximum(max_toclevel);
3547 numberingModule->tocSL->setValue(bp_.tocdepth);
3550 numberingModule->setEnabled(false);
3551 numberingModule->tocTW->clear();
3555 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3556 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3557 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3558 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3559 bulletsModule->init();
3562 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3564 latexModule->psdriverCO->setCurrentIndex(nitem);
3568 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3569 if (bp_.is_math_indent) {
3570 Length const mathindent = bp_.getMathIndent();
3572 if (!mathindent.empty()) {
3573 lengthToWidgets(mathsModule->MathIndentLE,
3574 mathsModule->MathIndentLengthCO,
3575 mathindent, default_unit);
3578 mathsModule->MathIndentCO->setCurrentIndex(indent);
3579 enableMathIndent(indent);
3581 switch(bp_.math_numbering_side) {
3582 case BufferParams::LEFT:
3583 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3585 case BufferParams::DEFAULT:
3586 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3588 case BufferParams::RIGHT:
3589 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3592 map<string, string> const & packages = BufferParams::auto_packages();
3593 for (map<string, string>::const_iterator it = packages.begin();
3594 it != packages.end(); ++it) {
3595 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3598 int row = mathsModule->packagesTW->row(item);
3599 switch (bp_.use_package(it->first)) {
3600 case BufferParams::package_off: {
3602 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3603 rb->setChecked(true);
3606 case BufferParams::package_on: {
3608 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3609 rb->setChecked(true);
3612 case BufferParams::package_auto: {
3614 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3615 rb->setChecked(true);
3621 switch (bp_.spacing().getSpace()) {
3622 case Spacing::Other: nitem = 3; break;
3623 case Spacing::Double: nitem = 2; break;
3624 case Spacing::Onehalf: nitem = 1; break;
3625 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3629 string const & layoutID = bp_.baseClassID();
3630 setLayoutComboByIDString(layoutID);
3632 updatePagestyle(documentClass().opt_pagestyle(),
3635 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3636 if (bp_.spacing().getSpace() == Spacing::Other) {
3637 doubleToWidget(textLayoutModule->lspacingLE,
3638 bp_.spacing().getValueAsString());
3642 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3643 textLayoutModule->indentRB->setChecked(true);
3644 string parindent = bp_.getParIndent().asString();
3646 if (!parindent.empty()) {
3647 lengthToWidgets(textLayoutModule->indentLE,
3648 textLayoutModule->indentLengthCO,
3649 parindent, default_unit);
3652 textLayoutModule->indentCO->setCurrentIndex(indent);
3655 textLayoutModule->skipRB->setChecked(true);
3657 switch (bp_.getDefSkip().kind()) {
3658 case VSpace::SMALLSKIP:
3661 case VSpace::MEDSKIP:
3664 case VSpace::BIGSKIP:
3667 case VSpace::LENGTH:
3670 string const length = bp_.getDefSkip().asLyXCommand();
3671 lengthToWidgets(textLayoutModule->skipLE,
3672 textLayoutModule->skipLengthCO,
3673 length, default_unit);
3680 textLayoutModule->skipCO->setCurrentIndex(skip);
3684 textLayoutModule->twoColumnCB->setChecked(
3686 textLayoutModule->justCB->setChecked(bp_.justification);
3688 if (!bp_.options.empty()) {
3689 latexModule->optionsLE->setText(
3690 toqstr(bp_.options));
3692 latexModule->optionsLE->setText(QString());
3696 latexModule->defaultOptionsCB->setChecked(
3697 bp_.use_default_options);
3698 updateSelectedModules();
3699 selectionManager->updateProvidedModules(
3700 bp_.baseClass()->providedModules());
3701 selectionManager->updateExcludedModules(
3702 bp_.baseClass()->excludedModules());
3704 if (!documentClass().options().empty()) {
3705 latexModule->defaultOptionsLE->setText(
3706 toqstr(documentClass().options()));
3708 latexModule->defaultOptionsLE->setText(
3709 toqstr(_("[No options predefined]")));
3712 latexModule->defaultOptionsLE->setEnabled(
3713 bp_.use_default_options
3714 && !documentClass().options().empty());
3716 latexModule->defaultOptionsCB->setEnabled(
3717 !documentClass().options().empty());
3719 if (!bp_.master.empty()) {
3720 latexModule->childDocGB->setChecked(true);
3721 latexModule->childDocLE->setText(
3722 toqstr(bp_.master));
3724 latexModule->childDocLE->setText(QString());
3725 latexModule->childDocGB->setChecked(false);
3729 if (!bufferview() || !buffer().hasChildren()) {
3730 masterChildModule->childrenTW->clear();
3731 includeonlys_.clear();
3732 docPS->showPanel("Child Documents", false);
3733 if (docPS->isCurrentPanel("Child Documents"))
3734 docPS->setCurrentPanel("Document Class");
3736 docPS->showPanel("Child Documents", true);
3737 masterChildModule->setEnabled(true);
3738 includeonlys_ = bp_.getIncludedChildren();
3739 updateIncludeonlys();
3741 masterChildModule->maintainAuxCB->setChecked(
3742 bp_.maintain_unincluded_children);
3745 floatModule->set(bp_.float_placement);
3748 // break listings_params to multiple lines
3750 InsetListingsParams(bp_.listings_params).separatedParams();
3751 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3752 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3754 listingsModule->packageCO->setCurrentIndex(nn);
3758 // some languages only work with polyglossia/XeTeX
3759 Language const * lang = lyx::languages.getLanguage(
3760 fromqstr(langModule->languageCO->itemData(
3761 langModule->languageCO->currentIndex()).toString()));
3762 bool const need_fontspec =
3763 lang->babel().empty() && !lang->polyglossia().empty();
3764 bool const os_fonts_available =
3765 bp_.baseClass()->outputType() == lyx::LATEX
3766 && LaTeXFeatures::isAvailable("fontspec");
3767 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3768 fontModule->osFontsCB->setChecked(
3769 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3770 updateFontsize(documentClass().opt_fontsize(),
3773 QString font = toqstr(bp_.fontsRoman());
3774 int rpos = fontModule->fontsRomanCO->findData(font);
3776 rpos = fontModule->fontsRomanCO->count();
3777 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3779 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3780 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3782 font = toqstr(bp_.fontsSans());
3783 int spos = fontModule->fontsSansCO->findData(font);
3785 spos = fontModule->fontsSansCO->count();
3786 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3788 fontModule->fontsSansCO->setCurrentIndex(spos);
3789 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3791 font = toqstr(bp_.fontsTypewriter());
3792 int tpos = fontModule->fontsTypewriterCO->findData(font);
3794 tpos = fontModule->fontsTypewriterCO->count();
3795 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3797 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3798 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3800 font = toqstr(bp_.fontsMath());
3801 int mpos = fontModule->fontsMathCO->findData(font);
3803 mpos = fontModule->fontsMathCO->count();
3804 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3806 fontModule->fontsMathCO->setCurrentIndex(mpos);
3807 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3809 if (bp_.useNonTeXFonts && os_fonts_available) {
3810 fontModule->fontencLA->setEnabled(false);
3811 fontModule->fontencCO->setEnabled(false);
3812 fontModule->fontencLE->setEnabled(false);
3814 fontModule->fontencLA->setEnabled(true);
3815 fontModule->fontencCO->setEnabled(true);
3816 fontModule->fontencLE->setEnabled(true);
3822 if (!bp_.fonts_cjk.empty())
3823 fontModule->cjkFontLE->setText(
3824 toqstr(bp_.fonts_cjk));
3826 fontModule->cjkFontLE->setText(QString());
3828 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3829 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3831 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3832 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3833 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3834 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3835 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3836 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3838 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3840 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3842 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3843 fontModule->fontencCO->setCurrentIndex(
3844 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3845 fontModule->fontencLE->setEnabled(false);
3847 fontModule->fontencCO->setCurrentIndex(1);
3848 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3852 // This must be set _after_ fonts since updateDefaultFormat()
3853 // checks osFontsCB settings.
3854 // update combobox with formats
3855 updateDefaultFormat();
3856 int index = outputModule->defaultFormatCO->findData(toqstr(
3857 bp_.default_output_format));
3858 // set to default if format is not found
3861 outputModule->defaultFormatCO->setCurrentIndex(index);
3863 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3864 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3865 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3867 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3868 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3869 outputModule->strictCB->setChecked(bp_.html_be_strict);
3870 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3872 outputModule->saveTransientPropertiesCB
3873 ->setChecked(bp_.save_transient_properties);
3876 bool const extern_geometry =
3877 documentClass().provides("geometry");
3878 int const psize = bp_.papersize;
3879 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3880 setCustomPapersize(!extern_geometry && psize == 1);
3881 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3883 bool const landscape =
3884 bp_.orientation == ORIENTATION_LANDSCAPE;
3885 pageLayoutModule->landscapeRB->setChecked(landscape);
3886 pageLayoutModule->portraitRB->setChecked(!landscape);
3887 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3888 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3890 pageLayoutModule->facingPagesCB->setChecked(
3891 bp_.sides == TwoSides);
3893 lengthToWidgets(pageLayoutModule->paperwidthLE,
3894 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3895 lengthToWidgets(pageLayoutModule->paperheightLE,
3896 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3899 Ui::MarginsUi * m = marginsModule;
3903 lengthToWidgets(m->topLE, m->topUnit,
3904 bp_.topmargin, default_unit);
3906 lengthToWidgets(m->bottomLE, m->bottomUnit,
3907 bp_.bottommargin, default_unit);
3909 lengthToWidgets(m->innerLE, m->innerUnit,
3910 bp_.leftmargin, default_unit);
3912 lengthToWidgets(m->outerLE, m->outerUnit,
3913 bp_.rightmargin, default_unit);
3915 lengthToWidgets(m->headheightLE, m->headheightUnit,
3916 bp_.headheight, default_unit);
3918 lengthToWidgets(m->headsepLE, m->headsepUnit,
3919 bp_.headsep, default_unit);
3921 lengthToWidgets(m->footskipLE, m->footskipUnit,
3922 bp_.footskip, default_unit);
3924 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3925 bp_.columnsep, default_unit);
3928 updateUnknownBranches();
3929 branchesModule->update(bp_);
3932 PDFOptions const & pdf = bp_.pdfoptions();
3933 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3934 if (bp_.documentClass().provides("hyperref"))
3935 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3937 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3938 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3939 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3940 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3941 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3943 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3944 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3945 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3947 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3949 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3950 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3951 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3952 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3954 nn = findToken(backref_opts, pdf.backref);
3956 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3958 pdfSupportModule->fullscreenCB->setChecked
3959 (pdf.pagemode == pdf.pagemode_fullscreen);
3961 pdfSupportModule->optionsLE->setText(
3962 toqstr(pdf.quoted_options));
3964 // Make sure that the bc is in the INITIAL state
3965 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3968 // clear changed branches cache
3969 changedBranches_.clear();
3972 nonModuleChanged_ = false;
3973 shellescapeChanged_ = false;
3977 void GuiDocument::saveDocDefault()
3979 // we have to apply the params first
3985 void GuiDocument::updateAvailableModules()
3987 modules_av_model_.clear();
3988 list<modInfoStruct> modInfoList = getModuleInfo();
3989 // Sort names according to the locale
3990 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3991 return 0 < b.name.localeAwareCompare(a.name);
3994 for (modInfoStruct const & m : modInfoList) {
3995 modules_av_model_.insertRow(i, m.name, m.id, m.description);
4001 void GuiDocument::updateSelectedModules()
4003 modules_sel_model_.clear();
4004 list<modInfoStruct> const selModList = getSelectedModules();
4006 for (modInfoStruct const & m : selModList) {
4007 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4013 void GuiDocument::updateIncludeonlys()
4015 masterChildModule->childrenTW->clear();
4016 QString const no = qt_("No");
4017 QString const yes = qt_("Yes");
4019 if (includeonlys_.empty()) {
4020 masterChildModule->includeallRB->setChecked(true);
4021 masterChildModule->childrenTW->setEnabled(false);
4022 masterChildModule->maintainAuxCB->setEnabled(false);
4024 masterChildModule->includeonlyRB->setChecked(true);
4025 masterChildModule->childrenTW->setEnabled(true);
4026 masterChildModule->maintainAuxCB->setEnabled(true);
4028 ListOfBuffers children = buffer().getChildren();
4029 ListOfBuffers::const_iterator it = children.begin();
4030 ListOfBuffers::const_iterator end = children.end();
4031 bool has_unincluded = false;
4032 bool all_unincluded = true;
4033 for (; it != end; ++it) {
4034 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4037 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4038 from_utf8(buffer().filePath())));
4039 item->setText(0, toqstr(name));
4040 item->setText(1, isChildIncluded(name) ? yes : no);
4041 if (!isChildIncluded(name))
4042 has_unincluded = true;
4044 all_unincluded = false;
4046 // Both if all childs are included and if none is included
4047 // is equal to "include all" (i.e., omit \includeonly).
4048 // Thus, reset the GUI.
4049 if (!has_unincluded || all_unincluded) {
4050 masterChildModule->includeallRB->setChecked(true);
4051 masterChildModule->childrenTW->setEnabled(false);
4052 includeonlys_.clear();
4054 // If all are included, we need to update again.
4055 if (!has_unincluded)
4056 updateIncludeonlys();
4060 bool GuiDocument::isBiblatex() const
4062 QString const engine =
4063 biblioModule->citeEngineCO->itemData(
4064 biblioModule->citeEngineCO->currentIndex()).toString();
4066 // this can happen if the cite engine is unknown, which can happen
4067 // if one is using a file that came from someone else, etc. in that
4068 // case, we crash if we proceed.
4069 if (engine.isEmpty())
4072 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4076 void GuiDocument::updateDefaultBiblio(string const & style,
4077 string const & which)
4079 QString const bibstyle = toqstr(style);
4080 biblioModule->defaultBiblioCO->clear();
4085 if (which != "cbx") {
4086 // First the bbx styles
4087 biblioModule->biblatexBbxCO->clear();
4088 QStringList str = texFileList("bbxFiles.lst");
4089 // test whether we have a valid list, otherwise run rescan
4090 if (str.isEmpty()) {
4091 rescanTexStyles("bbx");
4092 str = texFileList("bbxFiles.lst");
4094 for (int i = 0; i != str.size(); ++i)
4095 str[i] = onlyFileName(str[i]);
4096 // sort on filename only (no path)
4099 for (int i = 0; i != str.count(); ++i) {
4100 QString item = changeExtension(str[i], "");
4101 if (item == bibstyle)
4103 biblioModule->biblatexBbxCO->addItem(item);
4106 if (item_nr == -1 && !bibstyle.isEmpty()) {
4107 biblioModule->biblatexBbxCO->addItem(bibstyle);
4108 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4112 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4114 biblioModule->biblatexBbxCO->clearEditText();
4117 if (which != "bbx") {
4118 // now the cbx styles
4119 biblioModule->biblatexCbxCO->clear();
4120 QStringList str = texFileList("cbxFiles.lst");
4121 // test whether we have a valid list, otherwise run rescan
4122 if (str.isEmpty()) {
4123 rescanTexStyles("cbx");
4124 str = texFileList("cbxFiles.lst");
4126 for (int i = 0; i != str.size(); ++i)
4127 str[i] = onlyFileName(str[i]);
4128 // sort on filename only (no path)
4131 for (int i = 0; i != str.count(); ++i) {
4132 QString item = changeExtension(str[i], "");
4133 if (item == bibstyle)
4135 biblioModule->biblatexCbxCO->addItem(item);
4138 if (item_nr == -1 && !bibstyle.isEmpty()) {
4139 biblioModule->biblatexCbxCO->addItem(bibstyle);
4140 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4144 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4146 biblioModule->biblatexCbxCO->clearEditText();
4149 biblioModule->biblatexBbxCO->clear();
4150 biblioModule->biblatexCbxCO->clear();
4151 QStringList str = texFileList("bstFiles.lst");
4152 // test whether we have a valid list, otherwise run rescan
4153 if (str.isEmpty()) {
4154 rescanTexStyles("bst");
4155 str = texFileList("bstFiles.lst");
4157 for (int i = 0; i != str.size(); ++i)
4158 str[i] = onlyFileName(str[i]);
4159 // sort on filename only (no path)
4162 for (int i = 0; i != str.count(); ++i) {
4163 QString item = changeExtension(str[i], "");
4164 if (item == bibstyle)
4166 biblioModule->defaultBiblioCO->addItem(item);
4169 if (item_nr == -1 && !bibstyle.isEmpty()) {
4170 biblioModule->defaultBiblioCO->addItem(bibstyle);
4171 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4175 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4177 biblioModule->defaultBiblioCO->clearEditText();
4180 updateResetDefaultBiblio();
4184 void GuiDocument::updateResetDefaultBiblio()
4186 QString const engine =
4187 biblioModule->citeEngineCO->itemData(
4188 biblioModule->citeEngineCO->currentIndex()).toString();
4189 CiteEngineType const cet =
4190 CiteEngineType(biblioModule->citeStyleCO->itemData(
4191 biblioModule->citeStyleCO->currentIndex()).toInt());
4193 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4195 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4196 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4197 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4198 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4199 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4200 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4202 biblioModule->resetDefaultBiblioPB->setEnabled(
4203 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4207 void GuiDocument::matchBiblatexStyles()
4209 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4214 void GuiDocument::updateContents()
4216 // Nothing to do here as the document settings is not cursor dependant.
4221 void GuiDocument::useClassDefaults()
4223 if (applyPB->isEnabled()) {
4224 int const ret = Alert::prompt(_("Unapplied changes"),
4225 _("Some changes in the dialog were not yet applied.\n"
4226 "If you do not apply now, they will be lost after this action."),
4227 1, 1, _("&Apply"), _("&Dismiss"));
4232 int idx = latexModule->classCO->currentIndex();
4233 string const classname = fromqstr(latexModule->classCO->getData(idx));
4234 if (!bp_.setBaseClass(classname)) {
4235 Alert::error(_("Error"), _("Unable to set document class."));
4238 bp_.useClassDefaults();
4244 void GuiDocument::setLayoutComboByIDString(string const & idString)
4246 if (!latexModule->classCO->set(toqstr(idString)))
4247 Alert::warning(_("Can't set layout!"),
4248 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4252 bool GuiDocument::isValid()
4255 validateListingsParameters().isEmpty() &&
4256 localLayout->isValid() &&
4258 // if we're asking for skips between paragraphs
4259 !textLayoutModule->skipRB->isChecked() ||
4260 // then either we haven't chosen custom
4261 textLayoutModule->skipCO->currentIndex() != 3 ||
4262 // or else a length has been given
4263 !textLayoutModule->skipLE->text().isEmpty()
4266 // if we're asking for indentation
4267 !textLayoutModule->indentRB->isChecked() ||
4268 // then either we haven't chosen custom
4269 textLayoutModule->indentCO->currentIndex() != 1 ||
4270 // or else a length has been given
4271 !textLayoutModule->indentLE->text().isEmpty()
4274 // if we're asking for math indentation
4275 !mathsModule->MathIndentCB->isChecked() ||
4276 // then either we haven't chosen custom
4277 mathsModule->MathIndentCO->currentIndex() != 1 ||
4278 // or else a length has been given
4279 !mathsModule->MathIndentLE->text().isEmpty()
4284 char const * const GuiDocument::fontfamilies[5] = {
4285 "default", "rmdefault", "sfdefault", "ttdefault", ""
4289 char const * GuiDocument::fontfamilies_gui[5] = {
4290 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4294 bool GuiDocument::initialiseParams(string const &)
4296 BufferView const * view = bufferview();
4298 bp_ = BufferParams();
4302 bp_ = view->buffer().params();
4304 updateAvailableModules();
4305 //FIXME It'd be nice to make sure here that the selected
4306 //modules are consistent: That required modules are actually
4307 //selected, and that we don't have conflicts. If so, we could
4308 //at least pop up a warning.
4314 void GuiDocument::clearParams()
4316 bp_ = BufferParams();
4320 BufferId GuiDocument::id() const
4322 BufferView const * const view = bufferview();
4323 return view? &view->buffer() : 0;
4327 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4329 return moduleNames_;
4333 list<GuiDocument::modInfoStruct> const
4334 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4336 list<modInfoStruct> mInfo;
4337 for (string const & name : mods) {
4339 LyXModule const * const mod = theModuleList[name];
4344 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4352 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4354 return makeModuleInfo(params().getModules());
4358 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4360 return makeModuleInfo(params().baseClass()->providedModules());
4364 DocumentClass const & GuiDocument::documentClass() const
4366 return bp_.documentClass();
4370 static void dispatch_bufferparams(Dialog const & dialog,
4371 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4374 ss << "\\begin_header\n";
4375 bp.writeFile(ss, buf);
4376 ss << "\\end_header\n";
4377 dialog.dispatch(FuncRequest(lfun, ss.str()));
4381 void GuiDocument::dispatchParams()
4383 // We need a non-const buffer object.
4384 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4385 // There may be several undo records; group them (bug #8998)
4386 // This handles undo groups automagically
4387 UndoGroupHelper ugh(&buf);
4389 // This must come first so that a language change is correctly noticed
4392 // Apply the BufferParams. Note that this will set the base class
4393 // and then update the buffer's layout.
4394 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4396 if (!params().master.empty()) {
4397 FileName const master_file = support::makeAbsPath(params().master,
4398 support::onlyPath(buffer().absFileName()));
4399 if (isLyXFileName(master_file.absFileName())) {
4400 Buffer * master = checkAndLoadLyXFile(master_file);
4402 if (master->isChild(const_cast<Buffer *>(&buffer())))
4403 const_cast<Buffer &>(buffer()).setParent(master);
4405 Alert::warning(_("Assigned master does not include this file"),
4406 bformat(_("You must include this file in the document\n"
4407 "'%1$s' in order to use the master document\n"
4408 "feature."), from_utf8(params().master)));
4410 Alert::warning(_("Could not load master"),
4411 bformat(_("The master document '%1$s'\n"
4412 "could not be loaded."),
4413 from_utf8(params().master)));
4417 // Generate the colours requested by each new branch.
4418 BranchList & branchlist = params().branchlist();
4419 if (!branchlist.empty()) {
4420 BranchList::const_iterator it = branchlist.begin();
4421 BranchList::const_iterator const end = branchlist.end();
4422 for (; it != end; ++it) {
4423 docstring const & current_branch = it->branch();
4424 Branch const * branch = branchlist.find(current_branch);
4425 string const x11hexname = X11hexname(branch->color());
4426 // display the new color
4427 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4428 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4431 // rename branches in the document
4432 executeBranchRenaming();
4433 // and clear changed branches cache
4434 changedBranches_.clear();
4436 // Generate the colours requested by indices.
4437 IndicesList & indiceslist = params().indiceslist();
4438 if (!indiceslist.empty()) {
4439 IndicesList::const_iterator it = indiceslist.begin();
4440 IndicesList::const_iterator const end = indiceslist.end();
4441 for (; it != end; ++it) {
4442 docstring const & current_index = it->shortcut();
4443 Index const * index = indiceslist.findShortcut(current_index);
4444 string const x11hexname = X11hexname(index->color());
4445 // display the new color
4446 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4447 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4451 // If we used an LFUN, we would not need these two lines:
4452 BufferView * bv = const_cast<BufferView *>(bufferview());
4453 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4457 void GuiDocument::setLanguage() const
4459 Language const * const newL = bp_.language;
4460 if (buffer().params().language == newL)
4463 string const & lang_name = newL->lang();
4464 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4468 void GuiDocument::saveAsDefault() const
4470 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4474 bool GuiDocument::providesOSF(QString const & font) const
4476 if (fontModule->osFontsCB->isChecked())
4477 // FIXME: we should check if the fonts really
4478 // have OSF support. But how?
4480 return theLaTeXFonts().getLaTeXFont(
4481 qstring_to_ucs4(font)).providesOSF(ot1(),
4487 bool GuiDocument::providesSC(QString const & font) const
4489 if (fontModule->osFontsCB->isChecked())
4491 return theLaTeXFonts().getLaTeXFont(
4492 qstring_to_ucs4(font)).providesSC(ot1(),
4498 bool GuiDocument::providesScale(QString const & font) const
4500 if (fontModule->osFontsCB->isChecked())
4502 return theLaTeXFonts().getLaTeXFont(
4503 qstring_to_ucs4(font)).providesScale(ot1(),
4509 bool GuiDocument::providesNoMath(QString const & font) const
4511 if (fontModule->osFontsCB->isChecked())
4513 return theLaTeXFonts().getLaTeXFont(
4514 qstring_to_ucs4(font)).providesNoMath(ot1(),
4519 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4521 if (fontModule->osFontsCB->isChecked())
4523 return theLaTeXFonts().getLaTeXFont(
4524 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4531 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4533 // FIXME Unicode: docstrings would be better for these parameters but this
4534 // change requires a lot of others
4537 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4538 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4539 // Find the first sentence of the description
4540 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4541 int pos = bf.toNextBoundary();
4544 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4545 // Tooltip is the desc followed by the module name
4546 m.description = QString("%1<i>%2</i>")
4547 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4553 void GuiDocument::loadModuleInfo()
4555 moduleNames_.clear();
4556 for (LyXModule const & mod : theModuleList)
4557 if (mod.category().substr(0, 8) != "Citation")
4558 moduleNames_.push_back(modInfo(mod));
4562 void GuiDocument::updateUnknownBranches()
4566 list<docstring> used_branches;
4567 buffer().getUsedBranches(used_branches);
4568 list<docstring>::const_iterator it = used_branches.begin();
4569 QStringList unknown_branches;
4570 for (; it != used_branches.end() ; ++it) {
4571 if (!buffer().params().branchlist().find(*it))
4572 unknown_branches.append(toqstr(*it));
4574 branchesModule->setUnknownBranches(unknown_branches);
4578 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4580 map<docstring, docstring>::iterator it = changedBranches_.begin();
4581 for (; it != changedBranches_.end() ; ++it) {
4582 if (it->second == oldname) {
4583 // branch has already been renamed
4584 it->second = newname;
4589 changedBranches_[oldname] = newname;
4593 void GuiDocument::executeBranchRenaming() const
4595 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4596 for (; it != changedBranches_.end() ; ++it) {
4597 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4598 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4603 void GuiDocument::allPackagesAuto()
4609 void GuiDocument::allPackagesAlways()
4615 void GuiDocument::allPackagesNot()
4621 void GuiDocument::allPackages(int col)
4623 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4625 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4626 rb->setChecked(true);
4631 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4634 } // namespace frontend
4637 #include "moc_GuiDocument.cpp"