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 locallayoutTE->setFont(guiApp->typewriterSystemFont());
559 locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
560 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
561 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
562 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
566 void LocalLayout::update(BufferParams const & params, BufferId id)
568 QString layout = toqstr(params.getLocalLayout(false));
569 // Nothing to do if the params and preamble are unchanged.
570 if (id == current_id_
571 && layout == locallayoutTE->document()->toPlainText())
574 // Save the params address for further use.
576 locallayoutTE->document()->setPlainText(layout);
581 void LocalLayout::apply(BufferParams & params)
583 docstring const layout =
584 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
585 params.setLocalLayout(layout, false);
589 void LocalLayout::hideConvert()
591 convertPB->setEnabled(false);
592 convertLB->setText("");
598 void LocalLayout::textChanged()
600 static const QString message =
601 qt_("Press button to check validity...");
602 string const layout =
603 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
605 if (layout.empty()) {
607 validatePB->setEnabled(false);
608 validLB->setText("");
611 } else if (!validatePB->isEnabled()) {
612 // if that's already enabled, we shouldn't need to do anything.
614 validLB->setText(message);
615 validatePB->setEnabled(true);
622 void LocalLayout::convert() {
623 string const layout =
624 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
625 string const newlayout = TextClass::convert(layout);
626 if (!newlayout.empty())
627 locallayoutTE->setPlainText(toqstr(newlayout));
632 void LocalLayout::convertPressed() {
639 void LocalLayout::validate() {
641 static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
642 // Flashy red bold text
643 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
645 string const layout =
646 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
647 if (!layout.empty()) {
648 TextClass::ReturnValues const ret = TextClass::validate(layout);
649 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
650 validatePB->setEnabled(false);
651 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
652 : ivpar.arg(qt_("Layout is invalid!")));
653 if (ret == TextClass::OK_OLDFORMAT) {
655 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
657 if (TextClass::convert(layout).empty()) {
658 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
659 // then maybe the layout is still valid, but its format is more
660 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
661 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
662 convertPB->setEnabled(false);
663 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
664 ? ivpar.arg(qt_("Conversion to current format impossible!"))
665 : vpar.arg(qt_("Conversion to current stable format "
667 convertLB->setText(text);
669 convertPB->setEnabled(true);
670 convertLB->setText(qt_("Convert to current format"));
681 void LocalLayout::validatePressed() {
687 /////////////////////////////////////////////////////////////////////
691 /////////////////////////////////////////////////////////////////////
694 GuiDocument::GuiDocument(GuiView & lv)
695 : GuiDialog(lv, "document", qt_("Document Settings")),
696 biblioChanged_(false), nonModuleChanged_(false),
697 modulesChanged_(false), shellescapeChanged_(false)
701 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
702 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
703 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
704 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
706 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
707 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
709 // Manage the restore, ok, apply, restore and cancel/close buttons
710 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
712 bc().setApply(applyPB);
713 bc().setCancel(closePB);
714 bc().setRestore(restorePB);
718 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
719 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
720 this, SLOT(change_adaptor()));
721 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
722 this, SLOT(setLSpacing(int)));
723 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
724 this, SLOT(change_adaptor()));
726 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
727 this, SLOT(change_adaptor()));
728 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
729 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
730 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
731 this, SLOT(change_adaptor()));
732 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
733 this, SLOT(setIndent(int)));
734 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
735 this, SLOT(change_adaptor()));
736 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
737 this, SLOT(change_adaptor()));
739 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
740 this, SLOT(change_adaptor()));
741 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
742 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
743 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
744 this, SLOT(change_adaptor()));
745 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
746 this, SLOT(setSkip(int)));
747 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
748 this, SLOT(change_adaptor()));
749 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
750 this, SLOT(change_adaptor()));
752 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
753 this, SLOT(enableIndent(bool)));
754 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
755 this, SLOT(enableSkip(bool)));
757 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
758 this, SLOT(change_adaptor()));
759 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
760 this, SLOT(setColSep()));
761 connect(textLayoutModule->justCB, SIGNAL(clicked()),
762 this, SLOT(change_adaptor()));
764 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
765 textLayoutModule->lspacingLE));
766 textLayoutModule->indentLE->setValidator(new LengthValidator(
767 textLayoutModule->indentLE));
768 textLayoutModule->skipLE->setValidator(new LengthValidator(
769 textLayoutModule->skipLE));
771 textLayoutModule->indentCO->addItem(qt_("Default"));
772 textLayoutModule->indentCO->addItem(qt_("Custom"));
773 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
774 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
775 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
776 textLayoutModule->skipCO->addItem(qt_("Custom"));
777 textLayoutModule->lspacingCO->insertItem(
778 Spacing::Single, qt_("Single"));
779 textLayoutModule->lspacingCO->insertItem(
780 Spacing::Onehalf, qt_("OneHalf"));
781 textLayoutModule->lspacingCO->insertItem(
782 Spacing::Double, qt_("Double"));
783 textLayoutModule->lspacingCO->insertItem(
784 Spacing::Other, qt_("Custom"));
785 // initialize the length validator
786 bc().addCheckedLineEdit(textLayoutModule->indentLE);
787 bc().addCheckedLineEdit(textLayoutModule->skipLE);
790 // master/child handling
791 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
793 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
794 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
795 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
796 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
797 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
798 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
799 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
800 this, SLOT(change_adaptor()));
801 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
802 this, SLOT(change_adaptor()));
803 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
804 this, SLOT(change_adaptor()));
805 masterChildModule->childrenTW->setColumnCount(2);
806 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
807 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
808 masterChildModule->childrenTW->resizeColumnToContents(1);
809 masterChildModule->childrenTW->resizeColumnToContents(2);
813 outputModule = new UiWidget<Ui::OutputUi>(this);
815 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
816 this, SLOT(change_adaptor()));
817 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
818 this, SLOT(change_adaptor()));
819 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
820 this, SLOT(change_adaptor()));
821 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
822 this, SLOT(change_adaptor()));
823 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
824 this, SLOT(change_adaptor()));
826 connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
827 this, SLOT(shellescapeChanged()));
828 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
829 this, SLOT(change_adaptor()));
830 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
831 this, SLOT(change_adaptor()));
832 outputModule->synccustomCB->addItem("");
833 outputModule->synccustomCB->addItem("\\synctex=1");
834 outputModule->synccustomCB->addItem("\\synctex=-1");
835 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
837 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
838 outputModule->synccustomCB));
840 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
841 this, SLOT(change_adaptor()));
844 fontModule = new FontModule(this);
845 connect(fontModule->osFontsCB, SIGNAL(clicked()),
846 this, SLOT(change_adaptor()));
847 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
848 this, SLOT(osFontsChanged(bool)));
849 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
850 this, SLOT(change_adaptor()));
851 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
852 this, SLOT(romanChanged(int)));
853 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
854 this, SLOT(change_adaptor()));
855 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
856 this, SLOT(sansChanged(int)));
857 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
858 this, SLOT(change_adaptor()));
859 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
860 this, SLOT(ttChanged(int)));
861 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
862 this, SLOT(change_adaptor()));
863 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
864 this, SLOT(mathFontChanged(int)));
865 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
866 this, SLOT(change_adaptor()));
867 connect(fontModule->fontencCO, SIGNAL(activated(int)),
868 this, SLOT(change_adaptor()));
869 connect(fontModule->fontencCO, SIGNAL(activated(int)),
870 this, SLOT(fontencChanged(int)));
871 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
872 this, SLOT(change_adaptor()));
873 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
874 this, SLOT(change_adaptor()));
875 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
876 this, SLOT(change_adaptor()));
877 connect(fontModule->microtypeCB, SIGNAL(clicked()),
878 this, SLOT(change_adaptor()));
879 connect(fontModule->dashesCB, SIGNAL(clicked()),
880 this, SLOT(change_adaptor()));
881 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
882 this, SLOT(change_adaptor()));
883 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
884 this, SLOT(change_adaptor()));
885 connect(fontModule->fontScCB, SIGNAL(clicked()),
886 this, SLOT(change_adaptor()));
887 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
888 this, SLOT(fontScToggled(bool)));
889 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
890 this, SLOT(change_adaptor()));
891 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
892 this, SLOT(fontOsfToggled(bool)));
894 fontModule->fontencLE->setValidator(new NoNewLineValidator(
895 fontModule->fontencLE));
896 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
897 fontModule->cjkFontLE));
901 fontModule->fontsizeCO->addItem(qt_("Default"));
902 fontModule->fontsizeCO->addItem(qt_("10"));
903 fontModule->fontsizeCO->addItem(qt_("11"));
904 fontModule->fontsizeCO->addItem(qt_("12"));
906 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
907 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
908 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
910 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
911 fontModule->fontsDefaultCO->addItem(
912 qt_(GuiDocument::fontfamilies_gui[n]));
914 if (!LaTeXFeatures::isAvailable("fontspec"))
915 fontModule->osFontsCB->setToolTip(
916 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
917 "You need to install the package \"fontspec\" to use this feature"));
921 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
922 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
923 this, SLOT(papersizeChanged(int)));
924 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
925 this, SLOT(papersizeChanged(int)));
926 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
927 this, SLOT(change_adaptor()));
928 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
929 this, SLOT(change_adaptor()));
930 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
931 this, SLOT(change_adaptor()));
932 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
933 this, SLOT(change_adaptor()));
934 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
935 this, SLOT(change_adaptor()));
936 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
937 this, SLOT(change_adaptor()));
938 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
939 this, SLOT(change_adaptor()));
940 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
941 this, SLOT(change_adaptor()));
942 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
943 this, SLOT(change_adaptor()));
944 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
945 this, SLOT(change_adaptor()));
947 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
948 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
949 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
950 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
951 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
952 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
953 pageLayoutModule->paperheightL);
954 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
955 pageLayoutModule->paperwidthL);
957 QComboBox * cb = pageLayoutModule->papersizeCO;
958 cb->addItem(qt_("Default"));
959 cb->addItem(qt_("Custom"));
960 cb->addItem(qt_("US letter"));
961 cb->addItem(qt_("US legal"));
962 cb->addItem(qt_("US executive"));
963 cb->addItem(qt_("A0"));
964 cb->addItem(qt_("A1"));
965 cb->addItem(qt_("A2"));
966 cb->addItem(qt_("A3"));
967 cb->addItem(qt_("A4"));
968 cb->addItem(qt_("A5"));
969 cb->addItem(qt_("A6"));
970 cb->addItem(qt_("B0"));
971 cb->addItem(qt_("B1"));
972 cb->addItem(qt_("B2"));
973 cb->addItem(qt_("B3"));
974 cb->addItem(qt_("B4"));
975 cb->addItem(qt_("B5"));
976 cb->addItem(qt_("B6"));
977 cb->addItem(qt_("C0"));
978 cb->addItem(qt_("C1"));
979 cb->addItem(qt_("C2"));
980 cb->addItem(qt_("C3"));
981 cb->addItem(qt_("C4"));
982 cb->addItem(qt_("C5"));
983 cb->addItem(qt_("C6"));
984 cb->addItem(qt_("JIS B0"));
985 cb->addItem(qt_("JIS B1"));
986 cb->addItem(qt_("JIS B2"));
987 cb->addItem(qt_("JIS B3"));
988 cb->addItem(qt_("JIS B4"));
989 cb->addItem(qt_("JIS B5"));
990 cb->addItem(qt_("JIS B6"));
991 // remove the %-items from the unit choice
992 pageLayoutModule->paperwidthUnitCO->noPercents();
993 pageLayoutModule->paperheightUnitCO->noPercents();
994 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
995 pageLayoutModule->paperheightLE));
996 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
997 pageLayoutModule->paperwidthLE));
1001 marginsModule = new UiWidget<Ui::MarginsUi>(this);
1002 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1003 this, SLOT(setCustomMargins(bool)));
1004 connect(marginsModule->marginCB, SIGNAL(clicked()),
1005 this, SLOT(change_adaptor()));
1006 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1007 this, SLOT(change_adaptor()));
1008 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1009 this, SLOT(change_adaptor()));
1010 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1011 this, SLOT(change_adaptor()));
1012 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1013 this, SLOT(change_adaptor()));
1014 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1015 this, SLOT(change_adaptor()));
1016 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1017 this, SLOT(change_adaptor()));
1018 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1019 this, SLOT(change_adaptor()));
1020 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1021 this, SLOT(change_adaptor()));
1022 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1023 this, SLOT(change_adaptor()));
1024 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1025 this, SLOT(change_adaptor()));
1026 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1027 this, SLOT(change_adaptor()));
1028 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1029 this, SLOT(change_adaptor()));
1030 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1031 this, SLOT(change_adaptor()));
1032 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1033 this, SLOT(change_adaptor()));
1034 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1035 this, SLOT(change_adaptor()));
1036 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1037 this, SLOT(change_adaptor()));
1038 marginsModule->topLE->setValidator(new LengthValidator(
1039 marginsModule->topLE));
1040 marginsModule->bottomLE->setValidator(new LengthValidator(
1041 marginsModule->bottomLE));
1042 marginsModule->innerLE->setValidator(new LengthValidator(
1043 marginsModule->innerLE));
1044 marginsModule->outerLE->setValidator(new LengthValidator(
1045 marginsModule->outerLE));
1046 marginsModule->headsepLE->setValidator(new LengthValidator(
1047 marginsModule->headsepLE));
1048 marginsModule->headheightLE->setValidator(new LengthValidator(
1049 marginsModule->headheightLE));
1050 marginsModule->footskipLE->setValidator(new LengthValidator(
1051 marginsModule->footskipLE));
1052 marginsModule->columnsepLE->setValidator(new LengthValidator(
1053 marginsModule->columnsepLE));
1055 bc().addCheckedLineEdit(marginsModule->topLE,
1056 marginsModule->topL);
1057 bc().addCheckedLineEdit(marginsModule->bottomLE,
1058 marginsModule->bottomL);
1059 bc().addCheckedLineEdit(marginsModule->innerLE,
1060 marginsModule->innerL);
1061 bc().addCheckedLineEdit(marginsModule->outerLE,
1062 marginsModule->outerL);
1063 bc().addCheckedLineEdit(marginsModule->headsepLE,
1064 marginsModule->headsepL);
1065 bc().addCheckedLineEdit(marginsModule->headheightLE,
1066 marginsModule->headheightL);
1067 bc().addCheckedLineEdit(marginsModule->footskipLE,
1068 marginsModule->footskipL);
1069 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1070 marginsModule->columnsepL);
1074 langModule = new UiWidget<Ui::LanguageUi>(this);
1075 connect(langModule->languageCO, SIGNAL(activated(int)),
1076 this, SLOT(change_adaptor()));
1077 connect(langModule->languageCO, SIGNAL(activated(int)),
1078 this, SLOT(languageChanged(int)));
1079 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1080 this, SLOT(change_adaptor()));
1081 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1082 this, SLOT(change_adaptor()));
1083 connect(langModule->encodingCO, SIGNAL(activated(int)),
1084 this, SLOT(change_adaptor()));
1085 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1086 this, SLOT(change_adaptor()));
1087 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1088 this, SLOT(change_adaptor()));
1089 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1090 this, SLOT(change_adaptor()));
1091 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1092 this, SLOT(languagePackageChanged(int)));
1093 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1094 this, SLOT(change_adaptor()));
1096 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1097 langModule->languagePackageLE));
1099 QAbstractItemModel * language_model = guiApp->languageModel();
1100 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1101 language_model->sort(0);
1102 langModule->languageCO->setModel(language_model);
1103 langModule->languageCO->setModelColumn(0);
1105 // Always put the default encoding in the first position.
1106 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1107 QStringList encodinglist;
1108 for (auto const & encvar : encodings) {
1109 if (!encvar.unsafe() && !encvar.guiName().empty())
1110 encodinglist.append(qt_(encvar.guiName()));
1112 encodinglist.sort();
1113 langModule->encodingCO->addItems(encodinglist);
1115 langModule->languagePackageCO->addItem(
1116 qt_("Default"), toqstr("default"));
1117 langModule->languagePackageCO->addItem(
1118 qt_("Automatic"), toqstr("auto"));
1119 langModule->languagePackageCO->addItem(
1120 qt_("Always Babel"), toqstr("babel"));
1121 langModule->languagePackageCO->addItem(
1122 qt_("Custom"), toqstr("custom"));
1123 langModule->languagePackageCO->addItem(
1124 qt_("None[[language package]]"), toqstr("none"));
1128 colorModule = new UiWidget<Ui::ColorUi>(this);
1129 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1130 this, SLOT(changeFontColor()));
1131 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1132 this, SLOT(deleteFontColor()));
1133 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1134 this, SLOT(changeNoteFontColor()));
1135 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1136 this, SLOT(deleteNoteFontColor()));
1137 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1138 this, SLOT(changeBackgroundColor()));
1139 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1140 this, SLOT(deleteBackgroundColor()));
1141 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1142 this, SLOT(changeBoxBackgroundColor()));
1143 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1144 this, SLOT(deleteBoxBackgroundColor()));
1148 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1149 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1150 this, SLOT(change_adaptor()));
1151 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1152 this, SLOT(change_adaptor()));
1153 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1154 this, SLOT(updateNumbering()));
1155 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1156 this, SLOT(updateNumbering()));
1157 numberingModule->tocTW->setColumnCount(3);
1158 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1159 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1160 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1161 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1164 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1165 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1166 this, SLOT(citeEngineChanged(int)));
1167 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1168 this, SLOT(citeStyleChanged()));
1169 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1170 this, SLOT(biblioChanged()));
1171 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1172 this, SLOT(biblioChanged()));
1173 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1174 this, SLOT(bibtexChanged(int)));
1175 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1176 this, SLOT(biblioChanged()));
1177 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1178 this, SLOT(biblioChanged()));
1179 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1180 this, SLOT(biblioChanged()));
1181 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1182 this, SLOT(biblioChanged()));
1183 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1184 this, SLOT(updateResetDefaultBiblio()));
1185 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1186 this, SLOT(biblioChanged()));
1187 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1188 this, SLOT(biblioChanged()));
1189 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1190 this, SLOT(updateResetDefaultBiblio()));
1191 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1192 this, SLOT(biblioChanged()));
1193 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1194 this, SLOT(biblioChanged()));
1195 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1196 this, SLOT(updateResetDefaultBiblio()));
1197 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1198 this, SLOT(rescanBibFiles()));
1199 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1200 this, SLOT(resetDefaultBibfile()));
1201 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1202 this, SLOT(resetDefaultCbxBibfile()));
1203 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1204 this, SLOT(resetDefaultBbxBibfile()));
1205 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1206 this, SLOT(matchBiblatexStyles()));
1208 biblioModule->citeEngineCO->clear();
1209 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1210 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1211 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1212 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1216 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1217 biblioModule->bibtexOptionsLE));
1218 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1219 biblioModule->defaultBiblioCO->lineEdit()));
1220 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1221 biblioModule->citePackageOptionsLE));
1223 // NOTE: we do not provide "custom" here for security reasons!
1224 biblioModule->bibtexCO->clear();
1225 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1226 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1227 it != lyxrc.bibtex_alternatives.end(); ++it) {
1228 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1229 biblioModule->bibtexCO->addItem(command, command);
1234 indicesModule = new GuiIndices;
1235 connect(indicesModule, SIGNAL(changed()),
1236 this, SLOT(change_adaptor()));
1240 mathsModule = new UiWidget<Ui::MathsUi>(this);
1241 QStringList headers;
1242 headers << qt_("Package") << qt_("Load automatically")
1243 << qt_("Load always") << qt_("Do not load");
1244 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1245 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1246 map<string, string> const & packages = BufferParams::auto_packages();
1247 mathsModule->packagesTW->setRowCount(packages.size());
1249 for (map<string, string>::const_iterator it = packages.begin();
1250 it != packages.end(); ++it) {
1251 docstring const package = from_ascii(it->first);
1252 QString autoTooltip = qt_(it->second);
1253 QString alwaysTooltip;
1254 if (package == "amsmath")
1256 qt_("The AMS LaTeX packages are always used");
1258 alwaysTooltip = toqstr(bformat(
1259 _("The LaTeX package %1$s is always used"),
1261 QString neverTooltip;
1262 if (package == "amsmath")
1264 qt_("The AMS LaTeX packages are never used");
1266 neverTooltip = toqstr(bformat(
1267 _("The LaTeX package %1$s is never used"),
1269 QRadioButton * autoRB = new QRadioButton(mathsModule);
1270 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1271 QRadioButton * neverRB = new QRadioButton(mathsModule);
1272 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1273 packageGroup->addButton(autoRB);
1274 packageGroup->addButton(alwaysRB);
1275 packageGroup->addButton(neverRB);
1276 autoRB->setToolTip(autoTooltip);
1277 alwaysRB->setToolTip(alwaysTooltip);
1278 neverRB->setToolTip(neverTooltip);
1280 // Pack the buttons in a layout in order to get proper alignment
1281 QWidget * autoRBWidget = new QWidget();
1282 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1283 autoRBLayout->addWidget(autoRB);
1284 autoRBLayout->setAlignment(Qt::AlignCenter);
1285 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1286 autoRBWidget->setLayout(autoRBLayout);
1288 QWidget * alwaysRBWidget = new QWidget();
1289 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1290 alwaysRBLayout->addWidget(alwaysRB);
1291 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1292 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1293 alwaysRBWidget->setLayout(alwaysRBLayout);
1295 QWidget * neverRBWidget = new QWidget();
1296 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1297 neverRBLayout->addWidget(neverRB);
1298 neverRBLayout->setAlignment(Qt::AlignCenter);
1299 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1300 neverRBWidget->setLayout(neverRBLayout);
1302 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1304 mathsModule->packagesTW->setItem(packnum, 0, pack);
1305 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1306 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1307 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1309 connect(autoRB, SIGNAL(clicked()),
1310 this, SLOT(change_adaptor()));
1311 connect(alwaysRB, SIGNAL(clicked()),
1312 this, SLOT(change_adaptor()));
1313 connect(neverRB, SIGNAL(clicked()),
1314 this, SLOT(change_adaptor()));
1317 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1318 this, SLOT(allPackagesAuto()));
1319 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1320 this, SLOT(allPackagesAlways()));
1321 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1322 this, SLOT(allPackagesNot()));
1323 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1324 this, SLOT(change_adaptor()));
1325 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1326 this, SLOT(change_adaptor()));
1327 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1328 this, SLOT(change_adaptor()));
1329 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1330 this, SLOT(change_adaptor()));
1332 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1333 this, SLOT(change_adaptor()));
1334 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1335 this, SLOT(allowMathIndent()));
1336 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1337 this, SLOT(change_adaptor()));
1338 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1339 this, SLOT(enableMathIndent(int)));
1340 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1341 this, SLOT(change_adaptor()));
1342 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1343 this, SLOT(change_adaptor()));
1346 mathsModule->MathIndentCO->addItem(qt_("Default"));
1347 mathsModule->MathIndentCO->addItem(qt_("Custom"));
1348 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1349 mathsModule->MathIndentLE));
1350 // initialize the length validator
1351 bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1352 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1353 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1354 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1355 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1359 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1360 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1361 this, SLOT(change_adaptor()));
1362 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1363 this, SLOT(change_adaptor()));
1364 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1365 this, SLOT(change_adaptor()));
1366 connect(latexModule->classCO, SIGNAL(activated(int)),
1367 this, SLOT(classChanged_adaptor()));
1368 connect(latexModule->classCO, SIGNAL(activated(int)),
1369 this, SLOT(change_adaptor()));
1370 connect(latexModule->layoutPB, SIGNAL(clicked()),
1371 this, SLOT(browseLayout()));
1372 connect(latexModule->layoutPB, SIGNAL(clicked()),
1373 this, SLOT(change_adaptor()));
1374 connect(latexModule->childDocGB, SIGNAL(clicked()),
1375 this, SLOT(change_adaptor()));
1376 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1377 this, SLOT(change_adaptor()));
1378 connect(latexModule->childDocPB, SIGNAL(clicked()),
1379 this, SLOT(browseMaster()));
1380 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1381 this, SLOT(change_adaptor()));
1382 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1383 this, SLOT(change_adaptor()));
1385 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1386 latexModule->optionsLE));
1387 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1388 latexModule->childDocLE));
1390 // postscript drivers
1391 for (int n = 0; tex_graphics[n][0]; ++n) {
1392 QString enc = qt_(tex_graphics_gui[n]);
1393 latexModule->psdriverCO->addItem(enc);
1396 LayoutFileList const & bcl = LayoutFileList::get();
1397 vector<LayoutFileIndex> classList = bcl.classList();
1398 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1400 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1401 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1402 for (int i = 0; cit != cen; ++cit, ++i) {
1403 LayoutFile const & tc = bcl[*cit];
1404 bool const available = tc.isTeXClassAvailable();
1405 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1406 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1407 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1409 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1410 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1411 "Please check if you have the matching %1$s class "
1412 "and all required packages (%2$s) installed."),
1413 output_type, from_utf8(tc.prerequisites(", "))));
1415 latexModule->classCO->addItemSort(toqstr(tc.name()),
1417 toqstr(translateIfPossible(from_utf8(tc.category()))),
1419 true, true, true, available);
1424 branchesModule = new GuiBranches(this);
1425 connect(branchesModule, SIGNAL(changed()),
1426 this, SLOT(change_adaptor()));
1427 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1428 this, SLOT(branchesRename(docstring const &, docstring const &)));
1429 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1430 updateUnknownBranches();
1434 preambleModule = new PreambleModule(this);
1435 connect(preambleModule, SIGNAL(changed()),
1436 this, SLOT(change_adaptor()));
1438 localLayout = new LocalLayout(this);
1439 connect(localLayout, SIGNAL(changed()),
1440 this, SLOT(change_adaptor()));
1444 bulletsModule = new BulletsModule(this);
1445 connect(bulletsModule, SIGNAL(changed()),
1446 this, SLOT(change_adaptor()));
1450 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1451 modulesModule->availableLV->header()->setVisible(false);
1452 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1453 modulesModule->availableLV->header()->setStretchLastSection(false);
1455 new ModuleSelectionManager(this, modulesModule->availableLV,
1456 modulesModule->selectedLV,
1457 modulesModule->addPB,
1458 modulesModule->deletePB,
1459 modulesModule->upPB,
1460 modulesModule->downPB,
1461 availableModel(), selectedModel(), this);
1462 connect(selectionManager, SIGNAL(updateHook()),
1463 this, SLOT(updateModuleInfo()));
1464 connect(selectionManager, SIGNAL(selectionChanged()),
1465 this, SLOT(modulesChanged()));
1469 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1470 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1471 this, SLOT(change_adaptor()));
1472 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1473 this, SLOT(change_adaptor()));
1474 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1475 this, SLOT(change_adaptor()));
1476 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1477 this, SLOT(change_adaptor()));
1478 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1479 this, SLOT(change_adaptor()));
1480 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1481 this, SLOT(change_adaptor()));
1482 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1483 this, SLOT(change_adaptor()));
1484 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1485 this, SLOT(change_adaptor()));
1486 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1487 this, SLOT(change_adaptor()));
1488 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1489 this, SLOT(change_adaptor()));
1490 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1491 this, SLOT(change_adaptor()));
1492 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1493 this, SLOT(change_adaptor()));
1494 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1495 this, SLOT(change_adaptor()));
1496 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1497 this, SLOT(change_adaptor()));
1498 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1499 this, SLOT(change_adaptor()));
1500 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1501 this, SLOT(change_adaptor()));
1503 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1504 pdfSupportModule->titleLE));
1505 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1506 pdfSupportModule->authorLE));
1507 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1508 pdfSupportModule->subjectLE));
1509 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1510 pdfSupportModule->keywordsLE));
1511 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1512 pdfSupportModule->optionsLE));
1514 for (int i = 0; backref_opts[i][0]; ++i)
1515 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1519 floatModule = new FloatPlacement;
1520 connect(floatModule, SIGNAL(changed()),
1521 this, SLOT(change_adaptor()));
1525 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1526 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1527 this, SLOT(change_adaptor()));
1528 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1529 this, SLOT(change_adaptor()));
1530 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1531 this, SLOT(setListingsMessage()));
1532 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1533 this, SLOT(change_adaptor()));
1534 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1535 this, SLOT(listingsPackageChanged(int)));
1536 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1537 this, SLOT(setListingsMessage()));
1538 listingsModule->listingsTB->setPlainText(
1539 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1541 for (int i = 0; lst_packages[i][0]; ++i)
1542 listingsModule->packageCO->addItem(lst_packages[i]);
1546 docPS->addPanel(latexModule, N_("Document Class"));
1547 docPS->addPanel(masterChildModule, N_("Child Documents"));
1548 docPS->addPanel(modulesModule, N_("Modules"));
1549 docPS->addPanel(localLayout, N_("Local Layout"));
1550 docPS->addPanel(fontModule, N_("Fonts"));
1551 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1552 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1553 docPS->addPanel(marginsModule, N_("Page Margins"));
1554 docPS->addPanel(langModule, N_("Language"));
1555 docPS->addPanel(colorModule, N_("Colors"));
1556 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1557 docPS->addPanel(biblioModule, N_("Bibliography"));
1558 docPS->addPanel(indicesModule, N_("Indexes"));
1559 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1560 docPS->addPanel(mathsModule, N_("Math Options"));
1561 docPS->addPanel(floatModule, N_("Float Placement"));
1562 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1563 docPS->addPanel(bulletsModule, N_("Bullets"));
1564 docPS->addPanel(branchesModule, N_("Branches"));
1565 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1566 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1567 docPS->setCurrentPanel("Document Class");
1568 // FIXME: hack to work around resizing bug in Qt >= 4.2
1569 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1570 #if QT_VERSION >= 0x040200
1571 docPS->updateGeometry();
1576 void GuiDocument::onBufferViewChanged()
1578 if (isVisibleView())
1579 initialiseParams("");
1583 void GuiDocument::saveDefaultClicked()
1589 void GuiDocument::useDefaultsClicked()
1595 void GuiDocument::change_adaptor()
1597 nonModuleChanged_ = true;
1602 void GuiDocument::shellescapeChanged()
1604 shellescapeChanged_ = true;
1609 void GuiDocument::slotApply()
1611 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1612 bool wasclean = buffer().isClean();
1613 GuiDialog::slotApply();
1614 if (wasclean && only_shellescape_changed)
1615 buffer().markClean();
1616 modulesChanged_ = false;
1620 void GuiDocument::slotOK()
1622 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1623 bool wasclean = buffer().isClean();
1624 GuiDialog::slotOK();
1625 if (wasclean && only_shellescape_changed)
1626 buffer().markClean();
1627 modulesChanged_ = false;
1631 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1636 string child = fromqstr(item->text(0));
1640 if (std::find(includeonlys_.begin(),
1641 includeonlys_.end(), child) != includeonlys_.end())
1642 includeonlys_.remove(child);
1644 includeonlys_.push_back(child);
1646 updateIncludeonlys();
1651 QString GuiDocument::validateListingsParameters()
1653 if (listingsModule->bypassCB->isChecked())
1655 string const package =
1656 lst_packages[listingsModule->packageCO->currentIndex()];
1657 string params = fromqstr(listingsModule->listingsED->toPlainText());
1658 InsetListingsParams lstparams(params);
1659 lstparams.setMinted(package == "Minted");
1660 return toqstr(lstparams.validate());
1664 void GuiDocument::setListingsMessage()
1667 static bool isOK = true;
1668 QString msg = validateListingsParameters();
1669 if (msg.isEmpty()) {
1673 // listingsTB->setTextColor("black");
1674 listingsModule->listingsTB->setPlainText(
1675 qt_("Input listings parameters below. "
1676 "Enter ? for a list of parameters."));
1679 // listingsTB->setTextColor("red");
1680 listingsModule->listingsTB->setPlainText(msg);
1685 void GuiDocument::listingsPackageChanged(int index)
1687 string const package = lst_packages[index];
1688 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1689 Alert::warning(_("Pygments driver command not found!"),
1690 _("The driver command necessary to use the minted package\n"
1691 "(pygmentize) has not been found. Make sure you have\n"
1692 "the python-pygments module installed or, if the driver\n"
1693 "is named differently, to add the following line to the\n"
1694 "document preamble:\n\n"
1695 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1696 "where 'driver' is name of the driver command."));
1701 void GuiDocument::setLSpacing(int item)
1703 textLayoutModule->lspacingLE->setEnabled(item == 3);
1707 void GuiDocument::setIndent(int item)
1709 bool const enable = (item == 1);
1710 textLayoutModule->indentLE->setEnabled(enable);
1711 textLayoutModule->indentLengthCO->setEnabled(enable);
1712 textLayoutModule->skipLE->setEnabled(false);
1713 textLayoutModule->skipLengthCO->setEnabled(false);
1718 void GuiDocument::enableIndent(bool indent)
1720 textLayoutModule->skipLE->setEnabled(!indent);
1721 textLayoutModule->skipLengthCO->setEnabled(!indent);
1723 setIndent(textLayoutModule->indentCO->currentIndex());
1727 void GuiDocument::setSkip(int item)
1729 bool const enable = (item == 3);
1730 textLayoutModule->skipLE->setEnabled(enable);
1731 textLayoutModule->skipLengthCO->setEnabled(enable);
1736 void GuiDocument::enableSkip(bool skip)
1738 textLayoutModule->indentLE->setEnabled(!skip);
1739 textLayoutModule->indentLengthCO->setEnabled(!skip);
1741 setSkip(textLayoutModule->skipCO->currentIndex());
1744 void GuiDocument::allowMathIndent() {
1745 // only disable when not checked, checked does not always allow enabling
1746 if (!mathsModule->MathIndentCB->isChecked()) {
1747 mathsModule->MathIndentLE->setEnabled(false);
1748 mathsModule->MathIndentLengthCO->setEnabled(false);
1750 if (mathsModule->MathIndentCB->isChecked()
1751 && mathsModule->MathIndentCO->currentIndex() == 1) {
1752 mathsModule->MathIndentLE->setEnabled(true);
1753 mathsModule->MathIndentLengthCO->setEnabled(true);
1758 void GuiDocument::enableMathIndent(int item)
1760 bool const enable = (item == 1);
1761 mathsModule->MathIndentLE->setEnabled(enable);
1762 mathsModule->MathIndentLengthCO->setEnabled(enable);
1767 void GuiDocument::setMargins()
1769 bool const extern_geometry =
1770 documentClass().provides("geometry");
1771 marginsModule->marginCB->setEnabled(!extern_geometry);
1772 if (extern_geometry) {
1773 marginsModule->marginCB->setChecked(false);
1774 setCustomMargins(true);
1776 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1777 setCustomMargins(!bp_.use_geometry);
1782 void GuiDocument::papersizeChanged(int paper_size)
1784 setCustomPapersize(paper_size == 1);
1788 void GuiDocument::setCustomPapersize(bool custom)
1790 pageLayoutModule->paperwidthL->setEnabled(custom);
1791 pageLayoutModule->paperwidthLE->setEnabled(custom);
1792 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1793 pageLayoutModule->paperheightL->setEnabled(custom);
1794 pageLayoutModule->paperheightLE->setEnabled(custom);
1795 pageLayoutModule->paperheightLE->setFocus();
1796 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1800 void GuiDocument::setColSep()
1802 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1806 void GuiDocument::setCustomMargins(bool custom)
1808 marginsModule->topL->setEnabled(!custom);
1809 marginsModule->topLE->setEnabled(!custom);
1810 marginsModule->topUnit->setEnabled(!custom);
1812 marginsModule->bottomL->setEnabled(!custom);
1813 marginsModule->bottomLE->setEnabled(!custom);
1814 marginsModule->bottomUnit->setEnabled(!custom);
1816 marginsModule->innerL->setEnabled(!custom);
1817 marginsModule->innerLE->setEnabled(!custom);
1818 marginsModule->innerUnit->setEnabled(!custom);
1820 marginsModule->outerL->setEnabled(!custom);
1821 marginsModule->outerLE->setEnabled(!custom);
1822 marginsModule->outerUnit->setEnabled(!custom);
1824 marginsModule->headheightL->setEnabled(!custom);
1825 marginsModule->headheightLE->setEnabled(!custom);
1826 marginsModule->headheightUnit->setEnabled(!custom);
1828 marginsModule->headsepL->setEnabled(!custom);
1829 marginsModule->headsepLE->setEnabled(!custom);
1830 marginsModule->headsepUnit->setEnabled(!custom);
1832 marginsModule->footskipL->setEnabled(!custom);
1833 marginsModule->footskipLE->setEnabled(!custom);
1834 marginsModule->footskipUnit->setEnabled(!custom);
1836 bool const enableColSep = !custom &&
1837 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1838 marginsModule->columnsepL->setEnabled(enableColSep);
1839 marginsModule->columnsepLE->setEnabled(enableColSep);
1840 marginsModule->columnsepUnit->setEnabled(enableColSep);
1844 void GuiDocument::changeBackgroundColor()
1846 QColor const & newColor = QColorDialog::getColor(
1847 rgb2qcolor(set_backgroundcolor), asQWidget());
1848 if (!newColor.isValid())
1850 // set the button color and text
1851 colorModule->backgroundPB->setStyleSheet(
1852 colorButtonStyleSheet(newColor));
1853 colorModule->backgroundPB->setText(qt_("&Change..."));
1855 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1856 is_backgroundcolor = true;
1861 void GuiDocument::deleteBackgroundColor()
1863 // set the button color back to default by setting an empty StyleSheet
1864 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1865 // change button text
1866 colorModule->backgroundPB->setText(qt_("&Default..."));
1867 // save default color (white)
1868 set_backgroundcolor = rgbFromHexName("#ffffff");
1869 is_backgroundcolor = false;
1874 void GuiDocument::changeFontColor()
1876 QColor const & newColor = QColorDialog::getColor(
1877 rgb2qcolor(set_fontcolor), asQWidget());
1878 if (!newColor.isValid())
1880 // set the button color and text
1881 colorModule->fontColorPB->setStyleSheet(
1882 colorButtonStyleSheet(newColor));
1883 colorModule->fontColorPB->setText(qt_("&Change..."));
1885 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1886 is_fontcolor = true;
1891 void GuiDocument::deleteFontColor()
1893 // set the button color back to default by setting an empty StyleSheet
1894 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1895 // change button text
1896 colorModule->fontColorPB->setText(qt_("&Default..."));
1897 // save default color (black)
1898 set_fontcolor = rgbFromHexName("#000000");
1899 is_fontcolor = false;
1904 void GuiDocument::changeNoteFontColor()
1906 QColor const & newColor = QColorDialog::getColor(
1907 rgb2qcolor(set_notefontcolor), asQWidget());
1908 if (!newColor.isValid())
1910 // set the button color
1911 colorModule->noteFontColorPB->setStyleSheet(
1912 colorButtonStyleSheet(newColor));
1914 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1919 void GuiDocument::deleteNoteFontColor()
1921 // set the button color back to pref
1922 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1923 colorModule->noteFontColorPB->setStyleSheet(
1924 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1929 void GuiDocument::changeBoxBackgroundColor()
1931 QColor const & newColor = QColorDialog::getColor(
1932 rgb2qcolor(set_boxbgcolor), asQWidget());
1933 if (!newColor.isValid())
1935 // set the button color
1936 colorModule->boxBackgroundPB->setStyleSheet(
1937 colorButtonStyleSheet(newColor));
1939 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1944 void GuiDocument::deleteBoxBackgroundColor()
1946 // set the button color back to pref
1947 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1948 colorModule->boxBackgroundPB->setStyleSheet(
1949 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1954 void GuiDocument::updateQuoteStyles(bool const set)
1956 Language const * lang = lyx::languages.getLanguage(
1957 fromqstr(langModule->languageCO->itemData(
1958 langModule->languageCO->currentIndex()).toString()));
1960 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1962 langModule->quoteStyleCO->clear();
1964 bool has_default = false;
1965 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1966 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1967 if (qs == InsetQuotesParams::DynamicQuotes)
1969 bool const langdef = (qs == def);
1971 // add the default style on top
1972 langModule->quoteStyleCO->insertItem(0,
1973 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1977 langModule->quoteStyleCO->addItem(
1978 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1980 if (set && has_default)
1981 // (re)set to the default style
1982 langModule->quoteStyleCO->setCurrentIndex(0);
1986 void GuiDocument::languageChanged(int i)
1988 // some languages only work with polyglossia
1989 Language const * lang = lyx::languages.getLanguage(
1990 fromqstr(langModule->languageCO->itemData(i).toString()));
1991 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1992 // If we force to switch fontspec on, store
1993 // current state (#8717)
1994 if (fontModule->osFontsCB->isEnabled())
1995 forced_fontspec_activation =
1996 !fontModule->osFontsCB->isChecked();
1997 fontModule->osFontsCB->setChecked(true);
1998 fontModule->osFontsCB->setEnabled(false);
2001 fontModule->osFontsCB->setEnabled(true);
2002 // If we have forced to switch fontspec on,
2003 // restore previous state (#8717)
2004 if (forced_fontspec_activation)
2005 fontModule->osFontsCB->setChecked(false);
2006 forced_fontspec_activation = false;
2009 // set appropriate quotation mark style
2010 updateQuoteStyles(true);
2014 void GuiDocument::osFontsChanged(bool nontexfonts)
2016 bool const tex_fonts = !nontexfonts;
2017 // store current fonts
2018 QString const font_roman = fontModule->fontsRomanCO->itemData(
2019 fontModule->fontsRomanCO->currentIndex()).toString();
2020 QString const font_sans = fontModule->fontsSansCO->itemData(
2021 fontModule->fontsSansCO->currentIndex()).toString();
2022 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2023 fontModule->fontsTypewriterCO->currentIndex()).toString();
2024 QString const font_math = fontModule->fontsMathCO->itemData(
2025 fontModule->fontsMathCO->currentIndex()).toString();
2026 int const font_sf_scale = fontModule->scaleSansSB->value();
2027 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2030 // store default format
2031 QString const dformat = outputModule->defaultFormatCO->itemData(
2032 outputModule->defaultFormatCO->currentIndex()).toString();
2033 updateDefaultFormat();
2034 // try to restore default format
2035 int index = outputModule->defaultFormatCO->findData(dformat);
2036 // set to default if format is not found
2039 outputModule->defaultFormatCO->setCurrentIndex(index);
2041 // try to restore fonts which were selected two toggles ago
2042 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2044 fontModule->fontsRomanCO->setCurrentIndex(index);
2045 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2047 fontModule->fontsSansCO->setCurrentIndex(index);
2048 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2050 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2051 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2053 fontModule->fontsMathCO->setCurrentIndex(index);
2054 // save fonts for next next toggle
2055 fontModule->font_roman = font_roman;
2056 fontModule->font_sans = font_sans;
2057 fontModule->font_typewriter = font_typewriter;
2058 fontModule->font_math = font_math;
2059 fontModule->font_sf_scale = font_sf_scale;
2060 fontModule->font_tt_scale = font_tt_scale;
2062 langModule->encodingCO->setEnabled(tex_fonts &&
2063 !langModule->defaultencodingRB->isChecked());
2064 langModule->defaultencodingRB->setEnabled(tex_fonts);
2065 langModule->otherencodingRB->setEnabled(tex_fonts);
2067 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2068 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2069 fontModule->cjkFontLE->setEnabled(tex_fonts);
2070 fontModule->cjkFontLA->setEnabled(tex_fonts);
2072 updateFontOptions();
2074 fontModule->fontencLA->setEnabled(tex_fonts);
2075 fontModule->fontencCO->setEnabled(tex_fonts);
2077 fontModule->fontencLE->setEnabled(false);
2079 fontencChanged(fontModule->fontencCO->currentIndex());
2083 void GuiDocument::mathFontChanged(int)
2085 updateFontOptions();
2089 void GuiDocument::fontOsfToggled(bool state)
2091 if (fontModule->osFontsCB->isChecked())
2093 QString font = fontModule->fontsRomanCO->itemData(
2094 fontModule->fontsRomanCO->currentIndex()).toString();
2095 if (hasMonolithicExpertSet(font))
2096 fontModule->fontScCB->setChecked(state);
2100 void GuiDocument::fontScToggled(bool state)
2102 if (fontModule->osFontsCB->isChecked())
2104 QString font = fontModule->fontsRomanCO->itemData(
2105 fontModule->fontsRomanCO->currentIndex()).toString();
2106 if (hasMonolithicExpertSet(font))
2107 fontModule->fontOsfCB->setChecked(state);
2111 void GuiDocument::updateFontOptions()
2113 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2116 font = fontModule->fontsSansCO->itemData(
2117 fontModule->fontsSansCO->currentIndex()).toString();
2118 bool scaleable = providesScale(font);
2119 fontModule->scaleSansSB->setEnabled(scaleable);
2120 fontModule->scaleSansLA->setEnabled(scaleable);
2122 font = fontModule->fontsTypewriterCO->itemData(
2123 fontModule->fontsTypewriterCO->currentIndex()).toString();
2124 scaleable = providesScale(font);
2125 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2126 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2128 font = fontModule->fontsRomanCO->itemData(
2129 fontModule->fontsRomanCO->currentIndex()).toString();
2130 fontModule->fontScCB->setEnabled(providesSC(font));
2131 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2132 updateMathFonts(font);
2136 void GuiDocument::updateFontsize(string const & items, string const & sel)
2138 fontModule->fontsizeCO->clear();
2139 fontModule->fontsizeCO->addItem(qt_("Default"));
2141 for (int n = 0; !token(items,'|',n).empty(); ++n)
2142 fontModule->fontsizeCO->
2143 addItem(toqstr(token(items,'|',n)));
2145 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2146 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2147 fontModule->fontsizeCO->setCurrentIndex(n);
2154 bool GuiDocument::ot1() const
2156 QString const fontenc =
2157 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2158 return (fontenc == "default"
2159 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2160 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2164 bool GuiDocument::completeFontset() const
2166 return (fontModule->fontsSansCO->itemData(
2167 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2168 && fontModule->fontsSansCO->itemData(
2169 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2173 bool GuiDocument::noMathFont() const
2175 return (fontModule->fontsMathCO->itemData(
2176 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2180 void GuiDocument::updateTexFonts()
2182 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2184 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2185 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2186 for (; it != end; ++it) {
2187 LaTeXFont lf = it->second;
2188 if (lf.name().empty()) {
2189 LYXERR0("Error: Unnamed font: " << it->first);
2192 docstring const family = lf.family();
2193 docstring guiname = translateIfPossible(lf.guiname());
2194 if (!lf.available(ot1(), noMathFont()))
2195 guiname += _(" (not installed)");
2197 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2198 else if (family == "sf")
2199 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2200 else if (family == "tt")
2201 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2202 else if (family == "math")
2203 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2208 void GuiDocument::updateFontlist()
2210 fontModule->fontsRomanCO->clear();
2211 fontModule->fontsSansCO->clear();
2212 fontModule->fontsTypewriterCO->clear();
2213 fontModule->fontsMathCO->clear();
2215 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2216 if (fontModule->osFontsCB->isChecked()) {
2217 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2218 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2219 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2220 QString unimath = qt_("Non-TeX Fonts Default");
2221 if (!LaTeXFeatures::isAvailable("unicode-math"))
2222 unimath += qt_(" (not available)");
2223 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2224 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2226 QFontDatabase fontdb;
2227 QStringList families(fontdb.families());
2228 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2229 fontModule->fontsRomanCO->addItem(*it, *it);
2230 fontModule->fontsSansCO->addItem(*it, *it);
2231 fontModule->fontsTypewriterCO->addItem(*it, *it);
2236 if (rmfonts_.empty())
2239 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2240 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2241 while (rmi != rmfonts_.constEnd()) {
2242 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2246 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2247 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2248 while (sfi != sffonts_.constEnd()) {
2249 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2253 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2254 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2255 while (tti != ttfonts_.constEnd()) {
2256 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2260 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2261 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2262 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2263 while (mmi != mathfonts_.constEnd()) {
2264 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2270 void GuiDocument::fontencChanged(int item)
2272 fontModule->fontencLE->setEnabled(
2273 fontModule->fontencCO->itemData(item).toString() == "custom");
2274 // The availability of TeX fonts depends on the font encoding
2276 updateFontOptions();
2280 void GuiDocument::updateMathFonts(QString const & rm)
2282 if (fontModule->osFontsCB->isChecked())
2284 QString const math =
2285 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2286 int const i = fontModule->fontsMathCO->findData("default");
2287 if (providesNoMath(rm) && i == -1)
2288 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2289 else if (!providesNoMath(rm) && i != -1) {
2290 int const c = fontModule->fontsMathCO->currentIndex();
2291 fontModule->fontsMathCO->removeItem(i);
2293 fontModule->fontsMathCO->setCurrentIndex(0);
2298 void GuiDocument::romanChanged(int item)
2300 if (fontModule->osFontsCB->isChecked())
2302 QString const font =
2303 fontModule->fontsRomanCO->itemData(item).toString();
2304 fontModule->fontScCB->setEnabled(providesSC(font));
2305 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2306 updateMathFonts(font);
2310 void GuiDocument::sansChanged(int item)
2312 if (fontModule->osFontsCB->isChecked())
2314 QString const font =
2315 fontModule->fontsSansCO->itemData(item).toString();
2316 bool scaleable = providesScale(font);
2317 fontModule->scaleSansSB->setEnabled(scaleable);
2318 fontModule->scaleSansLA->setEnabled(scaleable);
2322 void GuiDocument::ttChanged(int item)
2324 if (fontModule->osFontsCB->isChecked())
2326 QString const font =
2327 fontModule->fontsTypewriterCO->itemData(item).toString();
2328 bool scaleable = providesScale(font);
2329 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2330 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2334 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2337 pageLayoutModule->pagestyleCO->clear();
2338 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2340 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2341 string style = token(items, '|', n);
2342 QString style_gui = qt_(style);
2343 pagestyles.push_back(pair<string, QString>(style, style_gui));
2344 pageLayoutModule->pagestyleCO->addItem(style_gui);
2347 if (sel == "default") {
2348 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2354 for (size_t i = 0; i < pagestyles.size(); ++i)
2355 if (pagestyles[i].first == sel)
2356 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2359 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2363 void GuiDocument::browseLayout()
2365 QString const label1 = qt_("Layouts|#o#O");
2366 QString const dir1 = toqstr(lyxrc.document_path);
2367 QStringList const filter(qt_("LyX Layout (*.layout)"));
2368 QString file = browseRelToParent(QString(), bufferFilePath(),
2369 qt_("Local layout file"), filter, false,
2372 if (!file.endsWith(".layout"))
2375 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2376 fromqstr(bufferFilePath()));
2378 int const ret = Alert::prompt(_("Local layout file"),
2379 _("The layout file you have selected is a local layout\n"
2380 "file, not one in the system or user directory.\n"
2381 "Your document will not work with this layout if you\n"
2382 "move the layout file to a different directory."),
2383 1, 1, _("&Set Layout"), _("&Cancel"));
2387 // load the layout file
2388 LayoutFileList & bcl = LayoutFileList::get();
2389 string classname = layoutFile.onlyFileName();
2390 // this will update an existing layout if that layout has been loaded before.
2391 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2392 classname.substr(0, classname.size() - 7),
2393 layoutFile.onlyPath().absFileName()));
2396 Alert::error(_("Error"),
2397 _("Unable to read local layout file."));
2401 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2403 // do not trigger classChanged if there is no change.
2404 if (latexModule->classCO->currentText() == toqstr(name))
2408 bool const avail = latexModule->classCO->set(toqstr(name));
2410 LayoutFile const & tc = bcl[name];
2411 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2412 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2413 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2414 tooltip += '\n' + qt_("This is a local layout file.");
2415 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2416 toqstr(translateIfPossible(from_utf8(tc.category()))),
2418 true, true, true, true);
2419 latexModule->classCO->set(toqstr(name));
2426 void GuiDocument::browseMaster()
2428 QString const title = qt_("Select master document");
2429 QString const dir1 = toqstr(lyxrc.document_path);
2430 QString const old = latexModule->childDocLE->text();
2431 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2432 QStringList const filter(qt_("LyX Files (*.lyx)"));
2433 QString file = browseRelToSub(old, docpath, title, filter, false,
2434 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2436 if (!file.isEmpty())
2437 latexModule->childDocLE->setText(file);
2441 void GuiDocument::classChanged_adaptor()
2443 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2448 void GuiDocument::classChanged()
2450 int idx = latexModule->classCO->currentIndex();
2453 string const classname = fromqstr(latexModule->classCO->getData(idx));
2455 if (applyPB->isEnabled()) {
2456 int const ret = Alert::prompt(_("Unapplied changes"),
2457 _("Some changes in the dialog were not yet applied.\n"
2458 "If you do not apply now, they will be lost after this action."),
2459 1, 1, _("&Apply"), _("&Dismiss"));
2464 // We load the TextClass as soon as it is selected. This is
2465 // necessary so that other options in the dialog can be updated
2466 // according to the new class. Note, however, that, if you use
2467 // the scroll wheel when sitting on the combo box, we'll load a
2468 // lot of TextClass objects very quickly....
2469 if (!bp_.setBaseClass(classname)) {
2470 Alert::error(_("Error"), _("Unable to set document class."));
2473 if (lyxrc.auto_reset_options)
2474 bp_.useClassDefaults();
2476 // With the introduction of modules came a distinction between the base
2477 // class and the document class. The former corresponds to the main layout
2478 // file; the latter is that plus the modules (or the document-specific layout,
2479 // or whatever else there could be). Our parameters come from the document
2480 // class. So when we set the base class, we also need to recreate the document
2481 // class. Otherwise, we still have the old one.
2482 bp_.makeDocumentClass();
2487 void GuiDocument::languagePackageChanged(int i)
2489 langModule->languagePackageLE->setEnabled(
2490 langModule->languagePackageCO->itemData(i).toString() == "custom");
2494 void GuiDocument::biblioChanged()
2496 biblioChanged_ = true;
2501 void GuiDocument::checkPossibleCiteEngines()
2503 // Check if the class provides a specific engine,
2504 // and if so, enforce this.
2505 string force_engine;
2506 if (documentClass().provides("natbib")
2507 || documentClass().provides("natbib-internal"))
2508 force_engine = "natbib";
2509 else if (documentClass().provides("jurabib"))
2510 force_engine = "jurabib";
2511 else if (documentClass().provides("biblatex"))
2512 force_engine = "biblatex";
2513 else if (documentClass().provides("biblatex-natbib"))
2514 force_engine = "biblatex-natbib";
2516 if (!force_engine.empty())
2517 biblioModule->citeEngineCO->setCurrentIndex(
2518 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2519 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2523 void GuiDocument::rescanBibFiles()
2526 rescanTexStyles("bbx cbx");
2528 rescanTexStyles("bst");
2532 void GuiDocument::resetDefaultBibfile(string const & which)
2534 QString const engine =
2535 biblioModule->citeEngineCO->itemData(
2536 biblioModule->citeEngineCO->currentIndex()).toString();
2538 CiteEngineType const cet =
2539 CiteEngineType(biblioModule->citeStyleCO->itemData(
2540 biblioModule->citeStyleCO->currentIndex()).toInt());
2542 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2546 void GuiDocument::resetDefaultBbxBibfile()
2548 resetDefaultBibfile("bbx");
2552 void GuiDocument::resetDefaultCbxBibfile()
2554 resetDefaultBibfile("cbx");
2558 void GuiDocument::citeEngineChanged(int n)
2560 QString const engine =
2561 biblioModule->citeEngineCO->itemData(n).toString();
2563 vector<string> const engs =
2564 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2566 updateCiteStyles(engs);
2567 updateEngineDependends();
2568 resetDefaultBibfile();
2573 void GuiDocument::updateEngineDependends()
2575 bool const biblatex = isBiblatex();
2577 // These are only useful with BibTeX
2578 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2579 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2580 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2581 biblioModule->bibtopicCB->setEnabled(!biblatex);
2583 // These are only useful with Biblatex
2584 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2585 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2586 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2587 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2588 biblioModule->resetBbxPB->setEnabled(biblatex);
2589 biblioModule->resetCbxPB->setEnabled(biblatex);
2590 biblioModule->matchBbxPB->setEnabled(biblatex);
2592 // These are useful with biblatex, jurabib and natbib
2593 QString const engine =
2594 biblioModule->citeEngineCO->itemData(
2595 biblioModule->citeEngineCO->currentIndex()).toString();
2596 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2598 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2599 || ce->requires("natbib.sty");
2600 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2601 biblioModule->citePackageOptionsL->setEnabled(citepack);
2605 void GuiDocument::citeStyleChanged()
2607 QString const engine =
2608 biblioModule->citeEngineCO->itemData(
2609 biblioModule->citeEngineCO->currentIndex()).toString();
2610 QString const currentDef = isBiblatex() ?
2611 biblioModule->biblatexBbxCO->currentText()
2612 : biblioModule->defaultBiblioCO->currentText();
2613 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2614 resetDefaultBibfile();
2620 void GuiDocument::bibtexChanged(int n)
2622 biblioModule->bibtexOptionsLE->setEnabled(
2623 biblioModule->bibtexCO->itemData(n).toString() != "default");
2628 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2630 biblioModule->citeStyleCO->clear();
2632 vector<string>::const_iterator it = engs.begin();
2633 vector<string>::const_iterator end = engs.end();
2634 for (; it != end; ++it) {
2635 if (*it == "default")
2636 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2637 ENGINE_TYPE_DEFAULT);
2638 else if (*it == "authoryear")
2639 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2640 ENGINE_TYPE_AUTHORYEAR);
2641 else if (*it == "numerical")
2642 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2643 ENGINE_TYPE_NUMERICAL);
2645 int i = biblioModule->citeStyleCO->findData(sel);
2646 if (biblioModule->citeStyleCO->findData(sel) == -1)
2648 biblioModule->citeStyleCO->setCurrentIndex(i);
2650 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2651 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2655 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2657 engine_types_.clear();
2661 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2663 string style = token(items, '|', n);
2664 engine_types_.push_back(style);
2667 updateCiteStyles(engine_types_, sel);
2673 // both of these should take a vector<docstring>
2675 // This is an insanely complicated attempt to make this sort of thing
2676 // work with RTL languages.
2677 docstring formatStrVec(vector<string> const & v, docstring const & s)
2679 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2683 return translateIfPossible(from_utf8(v[0]));
2684 if (v.size() == 2) {
2685 docstring retval = _("%1$s and %2$s");
2686 retval = subst(retval, _("and"), s);
2687 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2688 translateIfPossible(from_utf8(v[1])));
2690 // The idea here is to format all but the last two items...
2691 int const vSize = v.size();
2692 docstring t2 = _("%1$s, %2$s");
2693 docstring retval = translateIfPossible(from_utf8(v[0]));
2694 for (int i = 1; i < vSize - 2; ++i)
2695 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2696 //...and then to plug them, and the last two, into this schema
2697 docstring t = _("%1$s, %2$s, and %3$s");
2698 t = subst(t, _("and"), s);
2699 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2700 translateIfPossible(from_utf8(v[vSize - 1])));
2703 vector<string> idsToNames(vector<string> const & idList)
2705 vector<string> retval;
2706 vector<string>::const_iterator it = idList.begin();
2707 vector<string>::const_iterator end = idList.end();
2708 for (; it != end; ++it) {
2709 LyXModule const * const mod = theModuleList[*it];
2711 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2712 translateIfPossible(from_utf8(*it)))));
2714 retval.push_back(mod->getName());
2718 } // end anonymous namespace
2721 void GuiDocument::modulesToParams(BufferParams & bp)
2723 // update list of loaded modules
2724 bp.clearLayoutModules();
2725 int const srows = modules_sel_model_.rowCount();
2726 for (int i = 0; i < srows; ++i)
2727 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2729 // update the list of removed modules
2730 bp.clearRemovedModules();
2731 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2732 list<string>::const_iterator rit = reqmods.begin();
2733 list<string>::const_iterator ren = reqmods.end();
2735 // check each of the default modules
2736 for (; rit != ren; ++rit) {
2737 list<string>::const_iterator mit = bp.getModules().begin();
2738 list<string>::const_iterator men = bp.getModules().end();
2740 for (; mit != men; ++mit) {
2747 // the module isn't present so must have been removed by the user
2748 bp.addRemovedModule(*rit);
2753 void GuiDocument::modulesChanged()
2755 modulesToParams(bp_);
2757 if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2758 int const ret = Alert::prompt(_("Unapplied changes"),
2759 _("Some changes in the dialog were not yet applied.\n"
2760 "If you do not apply now, they will be lost after this action."),
2761 1, 1, _("&Apply"), _("&Dismiss"));
2766 modulesChanged_ = true;
2767 bp_.makeDocumentClass();
2773 void GuiDocument::updateModuleInfo()
2775 selectionManager->update();
2777 //Module description
2778 bool const focus_on_selected = selectionManager->selectedFocused();
2779 QAbstractItemView * lv;
2780 if (focus_on_selected)
2781 lv = modulesModule->selectedLV;
2783 lv = modulesModule->availableLV;
2784 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2785 modulesModule->infoML->document()->clear();
2788 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2789 GuiIdListModel const & id_model =
2790 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2791 string const modName = id_model.getIDString(idx.row());
2792 docstring desc = getModuleDescription(modName);
2794 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2795 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2798 desc += _("Module provided by document class.");
2801 docstring cat = getModuleCategory(modName);
2805 desc += bformat(_("Category: %1$s."), cat);
2808 vector<string> pkglist = getPackageList(modName);
2809 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2810 if (!pkgdesc.empty()) {
2813 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2816 pkglist = getRequiredList(modName);
2817 if (!pkglist.empty()) {
2818 vector<string> const reqdescs = idsToNames(pkglist);
2819 pkgdesc = formatStrVec(reqdescs, _("or"));
2822 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2825 pkglist = getExcludedList(modName);
2826 if (!pkglist.empty()) {
2827 vector<string> const reqdescs = idsToNames(pkglist);
2828 pkgdesc = formatStrVec(reqdescs, _( "and"));
2831 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2834 if (!isModuleAvailable(modName)) {
2837 desc += _("WARNING: Some required packages are unavailable!");
2840 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2844 void GuiDocument::updateNumbering()
2846 DocumentClass const & tclass = documentClass();
2848 numberingModule->tocTW->setUpdatesEnabled(false);
2849 numberingModule->tocTW->clear();
2851 int const depth = numberingModule->depthSL->value();
2852 int const toc = numberingModule->tocSL->value();
2853 QString const no = qt_("No");
2854 QString const yes = qt_("Yes");
2855 QTreeWidgetItem * item = 0;
2857 DocumentClass::const_iterator lit = tclass.begin();
2858 DocumentClass::const_iterator len = tclass.end();
2859 for (; lit != len; ++lit) {
2860 int const toclevel = lit->toclevel;
2861 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2862 item = new QTreeWidgetItem(numberingModule->tocTW);
2863 item->setText(0, toqstr(translateIfPossible(lit->name())));
2864 item->setText(1, (toclevel <= depth) ? yes : no);
2865 item->setText(2, (toclevel <= toc) ? yes : no);
2869 numberingModule->tocTW->setUpdatesEnabled(true);
2870 numberingModule->tocTW->update();
2874 void GuiDocument::updateDefaultFormat()
2878 // make a copy in order to consider unapplied changes
2879 BufferParams param_copy = buffer().params();
2880 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2881 int const idx = latexModule->classCO->currentIndex();
2883 string const classname = fromqstr(latexModule->classCO->getData(idx));
2884 param_copy.setBaseClass(classname);
2885 param_copy.makeDocumentClass(true);
2887 outputModule->defaultFormatCO->blockSignals(true);
2888 outputModule->defaultFormatCO->clear();
2889 outputModule->defaultFormatCO->addItem(qt_("Default"),
2890 QVariant(QString("default")));
2891 FormatList const & formats =
2892 param_copy.exportableFormats(true);
2893 for (Format const * f : formats)
2894 outputModule->defaultFormatCO->addItem
2895 (toqstr(translateIfPossible(f->prettyname())),
2896 QVariant(toqstr(f->name())));
2897 outputModule->defaultFormatCO->blockSignals(false);
2901 bool GuiDocument::isChildIncluded(string const & child)
2903 if (includeonlys_.empty())
2905 return (std::find(includeonlys_.begin(),
2906 includeonlys_.end(), child) != includeonlys_.end());
2910 void GuiDocument::applyView()
2913 preambleModule->apply(bp_);
2914 localLayout->apply(bp_);
2917 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2918 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2921 string const engine =
2922 fromqstr(biblioModule->citeEngineCO->itemData(
2923 biblioModule->citeEngineCO->currentIndex()).toString());
2924 bp_.setCiteEngine(engine);
2926 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2927 biblioModule->citeStyleCO->currentIndex()).toInt());
2928 if (theCiteEnginesList[engine]->hasEngineType(style))
2929 bp_.setCiteEngineType(style);
2931 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2933 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2935 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2936 biblioModule->bibunitsCO->currentIndex()).toString());
2938 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2940 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2941 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2942 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2944 string const bibtex_command =
2945 fromqstr(biblioModule->bibtexCO->itemData(
2946 biblioModule->bibtexCO->currentIndex()).toString());
2947 string const bibtex_options =
2948 fromqstr(biblioModule->bibtexOptionsLE->text());
2949 if (bibtex_command == "default" || bibtex_options.empty())
2950 bp_.bibtex_command = bibtex_command;
2952 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2954 if (biblioChanged_) {
2955 buffer().invalidateBibinfoCache();
2956 buffer().removeBiblioTempFiles();
2960 indicesModule->apply(bp_);
2962 // language & quotes
2963 if (langModule->defaultencodingRB->isChecked()) {
2964 bp_.inputenc = "auto";
2966 int i = langModule->encodingCO->currentIndex();
2968 bp_.inputenc = "default";
2970 QString const enc_gui =
2971 langModule->encodingCO->currentText();
2972 Encodings::const_iterator it = encodings.begin();
2973 Encodings::const_iterator const end = encodings.end();
2975 for (; it != end; ++it) {
2976 if (qt_(it->guiName()) == enc_gui &&
2978 bp_.inputenc = it->name();
2984 // should not happen
2985 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2986 bp_.inputenc = "default";
2991 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2992 langModule->quoteStyleCO->currentIndex()).toInt();
2993 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2995 QString const langname = langModule->languageCO->itemData(
2996 langModule->languageCO->currentIndex()).toString();
2997 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2998 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2999 // If current cursor language was the document language, then update it too.
3000 if (cur.current_font.language() == bp_.language) {
3001 cur.current_font.setLanguage(newlang);
3002 cur.real_current_font.setLanguage(newlang);
3004 bp_.language = newlang;
3006 QString const pack = langModule->languagePackageCO->itemData(
3007 langModule->languagePackageCO->currentIndex()).toString();
3008 if (pack == "custom")
3010 fromqstr(langModule->languagePackageLE->text());
3012 bp_.lang_package = fromqstr(pack);
3015 bp_.backgroundcolor = set_backgroundcolor;
3016 bp_.isbackgroundcolor = is_backgroundcolor;
3017 bp_.fontcolor = set_fontcolor;
3018 bp_.isfontcolor = is_fontcolor;
3019 bp_.notefontcolor = set_notefontcolor;
3020 bp_.boxbgcolor = set_boxbgcolor;
3023 if (bp_.documentClass().hasTocLevels()) {
3024 bp_.tocdepth = numberingModule->tocSL->value();
3025 bp_.secnumdepth = numberingModule->depthSL->value();
3029 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3030 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3031 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3032 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3035 bp_.graphics_driver =
3036 tex_graphics[latexModule->psdriverCO->currentIndex()];
3039 int idx = latexModule->classCO->currentIndex();
3041 string const classname = fromqstr(latexModule->classCO->getData(idx));
3042 bp_.setBaseClass(classname);
3046 modulesToParams(bp_);
3049 map<string, string> const & packages = BufferParams::auto_packages();
3050 for (map<string, string>::const_iterator it = packages.begin();
3051 it != packages.end(); ++it) {
3052 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3055 int row = mathsModule->packagesTW->row(item);
3058 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3059 if (rb->isChecked()) {
3060 bp_.use_package(it->first, BufferParams::package_auto);
3063 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3064 if (rb->isChecked()) {
3065 bp_.use_package(it->first, BufferParams::package_on);
3068 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3069 if (rb->isChecked())
3070 bp_.use_package(it->first, BufferParams::package_off);
3072 // if math is indented
3073 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3074 if (bp_.is_math_indent) {
3075 // if formulas are indented
3076 switch (mathsModule->MathIndentCO->currentIndex()) {
3078 bp_.setMathIndent(Length());
3081 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3082 mathsModule->MathIndentLengthCO));
3083 bp_.setMathIndent(mathindent);
3087 // this should never happen
3088 bp_.setMathIndent(Length());
3092 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3094 bp_.math_numbering_side = BufferParams::LEFT;
3097 bp_.math_numbering_side = BufferParams::DEFAULT;
3100 bp_.math_numbering_side = BufferParams::RIGHT;
3103 // this should never happen
3104 bp_.math_numbering_side = BufferParams::DEFAULT;
3109 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3110 bp_.pagestyle = "default";
3112 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3113 for (size_t i = 0; i != pagestyles.size(); ++i)
3114 if (pagestyles[i].second == style_gui)
3115 bp_.pagestyle = pagestyles[i].first;
3119 switch (textLayoutModule->lspacingCO->currentIndex()) {
3121 bp_.spacing().set(Spacing::Single);
3124 bp_.spacing().set(Spacing::Onehalf);
3127 bp_.spacing().set(Spacing::Double);
3130 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3132 bp_.spacing().set(Spacing::Single);
3134 bp_.spacing().set(Spacing::Other, s);
3139 if (textLayoutModule->twoColumnCB->isChecked())
3144 bp_.justification = textLayoutModule->justCB->isChecked();
3146 if (textLayoutModule->indentRB->isChecked()) {
3147 // if paragraphs are separated by an indentation
3148 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3149 switch (textLayoutModule->indentCO->currentIndex()) {
3151 bp_.setParIndent(Length());
3154 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3155 textLayoutModule->indentLengthCO));
3156 bp_.setParIndent(parindent);
3160 // this should never happen
3161 bp_.setParIndent(Length());
3165 // if paragraphs are separated by a skip
3166 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3167 switch (textLayoutModule->skipCO->currentIndex()) {
3169 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3172 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3175 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3180 widgetsToLength(textLayoutModule->skipLE,
3181 textLayoutModule->skipLengthCO)
3187 // this should never happen
3188 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3194 fromqstr(latexModule->optionsLE->text());
3196 bp_.use_default_options =
3197 latexModule->defaultOptionsCB->isChecked();
3199 if (latexModule->childDocGB->isChecked())
3201 fromqstr(latexModule->childDocLE->text());
3203 bp_.master = string();
3206 bp_.clearIncludedChildren();
3207 if (masterChildModule->includeonlyRB->isChecked()) {
3208 list<string>::const_iterator it = includeonlys_.begin();
3209 for (; it != includeonlys_.end() ; ++it) {
3210 bp_.addIncludedChildren(*it);
3213 bp_.maintain_unincluded_children =
3214 masterChildModule->maintainAuxCB->isChecked();
3217 bp_.float_placement = floatModule->get();
3220 // text should have passed validation
3221 idx = listingsModule->packageCO->currentIndex();
3222 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3223 bp_.listings_params =
3224 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3227 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3228 outputModule->defaultFormatCO->currentIndex()).toString());
3230 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3231 bp_.useNonTeXFonts = nontexfonts;
3233 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3234 if (!bp_.shell_escape)
3235 theSession().shellescapeFiles().remove(buffer().absFileName());
3236 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3237 theSession().shellescapeFiles().insert(buffer().absFileName());
3238 Buffer & buf = const_cast<Buffer &>(buffer());
3239 buf.params().shell_escape = bp_.shell_escape;
3241 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3243 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3245 int mathfmt = outputModule->mathoutCB->currentIndex();
3248 BufferParams::MathOutput const mo =
3249 static_cast<BufferParams::MathOutput>(mathfmt);
3250 bp_.html_math_output = mo;
3251 bp_.html_be_strict = outputModule->strictCB->isChecked();
3252 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3253 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3254 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3256 bp_.save_transient_properties =
3257 outputModule->saveTransientPropertiesCB->isChecked();
3260 bp_.fonts_roman[nontexfonts] =
3261 fromqstr(fontModule->fontsRomanCO->
3262 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3263 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3265 bp_.fonts_sans[nontexfonts] =
3266 fromqstr(fontModule->fontsSansCO->
3267 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3268 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3270 bp_.fonts_typewriter[nontexfonts] =
3271 fromqstr(fontModule->fontsTypewriterCO->
3272 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3273 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3275 bp_.fonts_math[nontexfonts] =
3276 fromqstr(fontModule->fontsMathCO->
3277 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3278 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3280 QString const fontenc =
3281 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3282 if (fontenc == "custom")
3283 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3285 bp_.fontenc = fromqstr(fontenc);
3288 fromqstr(fontModule->cjkFontLE->text());
3290 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3291 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3293 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3294 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3296 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3297 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3299 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3301 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3304 bp_.fonts_default_family = "default";
3306 bp_.fonts_default_family = GuiDocument::fontfamilies[
3307 fontModule->fontsDefaultCO->currentIndex()];
3309 if (fontModule->fontsizeCO->currentIndex() == 0)
3310 bp_.fontsize = "default";
3313 fromqstr(fontModule->fontsizeCO->currentText());
3316 bp_.papersize = PAPER_SIZE(
3317 pageLayoutModule->papersizeCO->currentIndex());
3319 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3320 pageLayoutModule->paperwidthUnitCO);
3322 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3323 pageLayoutModule->paperheightUnitCO);
3325 if (pageLayoutModule->facingPagesCB->isChecked())
3326 bp_.sides = TwoSides;
3328 bp_.sides = OneSide;
3330 if (pageLayoutModule->landscapeRB->isChecked())
3331 bp_.orientation = ORIENTATION_LANDSCAPE;
3333 bp_.orientation = ORIENTATION_PORTRAIT;
3336 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3338 Ui::MarginsUi const * m = marginsModule;
3340 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3341 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3342 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3343 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3344 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3345 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3346 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3347 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3350 branchesModule->apply(bp_);
3353 PDFOptions & pdf = bp_.pdfoptions();
3354 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3355 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3356 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3357 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3358 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3360 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3361 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3362 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3363 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3365 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3366 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3367 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3368 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3370 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3371 if (pdfSupportModule->fullscreenCB->isChecked())
3372 pdf.pagemode = pdf.pagemode_fullscreen;
3374 pdf.pagemode.clear();
3375 pdf.quoted_options = pdf.quoted_options_check(
3376 fromqstr(pdfSupportModule->optionsLE->text()));
3379 nonModuleChanged_ = false;
3380 shellescapeChanged_ = false;
3384 void GuiDocument::paramsToDialog()
3386 // set the default unit
3387 Length::UNIT const default_unit = Length::defaultUnit();
3390 preambleModule->update(bp_, id());
3391 localLayout->update(bp_, id());
3394 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3395 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3398 string const cite_engine = bp_.citeEngine().list().front();
3400 biblioModule->citeEngineCO->setCurrentIndex(
3401 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3403 updateEngineType(documentClass().opt_enginetype(),
3404 bp_.citeEngineType());
3406 checkPossibleCiteEngines();
3408 biblioModule->citeStyleCO->setCurrentIndex(
3409 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3411 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3413 biblioModule->bibunitsCO->clear();
3414 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3415 if (documentClass().hasLaTeXLayout("part"))
3416 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3417 if (documentClass().hasLaTeXLayout("chapter"))
3418 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3419 if (documentClass().hasLaTeXLayout("section"))
3420 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3421 if (documentClass().hasLaTeXLayout("subsection"))
3422 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3423 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3425 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3427 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3429 biblioModule->bibunitsCO->setCurrentIndex(0);
3431 updateEngineDependends();
3434 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3435 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3437 updateDefaultBiblio(bp_.defaultBiblioStyle());
3439 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3443 split(bp_.bibtex_command, command, ' ');
3445 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3447 biblioModule->bibtexCO->setCurrentIndex(bpos);
3448 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3450 // We reset to default if we do not know the specified compiler
3451 // This is for security reasons
3452 biblioModule->bibtexCO->setCurrentIndex(
3453 biblioModule->bibtexCO->findData(toqstr("default")));
3454 biblioModule->bibtexOptionsLE->clear();
3456 biblioModule->bibtexOptionsLE->setEnabled(
3457 biblioModule->bibtexCO->currentIndex() != 0);
3459 biblioChanged_ = false;
3462 // We may be called when there is no Buffer, e.g., when
3463 // the last view has just been closed.
3464 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3465 indicesModule->update(bp_, isReadOnly);
3467 // language & quotes
3468 int const pos = langModule->languageCO->findData(toqstr(
3469 bp_.language->lang()));
3470 langModule->languageCO->setCurrentIndex(pos);
3472 updateQuoteStyles();
3474 langModule->quoteStyleCO->setCurrentIndex(
3475 langModule->quoteStyleCO->findData(bp_.quotes_style));
3476 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3478 bool default_enc = true;
3479 if (bp_.inputenc != "auto") {
3480 default_enc = false;
3481 if (bp_.inputenc == "default") {
3482 langModule->encodingCO->setCurrentIndex(0);
3485 Encodings::const_iterator it = encodings.begin();
3486 Encodings::const_iterator const end = encodings.end();
3487 for (; it != end; ++it) {
3488 if (it->name() == bp_.inputenc &&
3490 enc_gui = it->guiName();
3494 int const i = langModule->encodingCO->findText(
3497 langModule->encodingCO->setCurrentIndex(i);
3499 // unknown encoding. Set to default.
3503 langModule->defaultencodingRB->setChecked(default_enc);
3504 langModule->otherencodingRB->setChecked(!default_enc);
3506 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3508 langModule->languagePackageCO->setCurrentIndex(
3509 langModule->languagePackageCO->findData("custom"));
3510 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3512 langModule->languagePackageCO->setCurrentIndex(p);
3513 langModule->languagePackageLE->clear();
3517 if (bp_.isfontcolor) {
3518 colorModule->fontColorPB->setStyleSheet(
3519 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3521 set_fontcolor = bp_.fontcolor;
3522 is_fontcolor = bp_.isfontcolor;
3524 colorModule->noteFontColorPB->setStyleSheet(
3525 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3526 set_notefontcolor = bp_.notefontcolor;
3528 if (bp_.isbackgroundcolor) {
3529 colorModule->backgroundPB->setStyleSheet(
3530 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3532 set_backgroundcolor = bp_.backgroundcolor;
3533 is_backgroundcolor = bp_.isbackgroundcolor;
3535 colorModule->boxBackgroundPB->setStyleSheet(
3536 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3537 set_boxbgcolor = bp_.boxbgcolor;
3540 int const min_toclevel = documentClass().min_toclevel();
3541 int const max_toclevel = documentClass().max_toclevel();
3542 if (documentClass().hasTocLevels()) {
3543 numberingModule->setEnabled(true);
3544 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3545 numberingModule->depthSL->setMaximum(max_toclevel);
3546 numberingModule->depthSL->setValue(bp_.secnumdepth);
3547 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3548 numberingModule->tocSL->setMaximum(max_toclevel);
3549 numberingModule->tocSL->setValue(bp_.tocdepth);
3552 numberingModule->setEnabled(false);
3553 numberingModule->tocTW->clear();
3557 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3558 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3559 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3560 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3561 bulletsModule->init();
3564 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3566 latexModule->psdriverCO->setCurrentIndex(nitem);
3570 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3571 if (bp_.is_math_indent) {
3572 Length const mathindent = bp_.getMathIndent();
3574 if (!mathindent.empty()) {
3575 lengthToWidgets(mathsModule->MathIndentLE,
3576 mathsModule->MathIndentLengthCO,
3577 mathindent, default_unit);
3580 mathsModule->MathIndentCO->setCurrentIndex(indent);
3581 enableMathIndent(indent);
3583 switch(bp_.math_numbering_side) {
3584 case BufferParams::LEFT:
3585 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3587 case BufferParams::DEFAULT:
3588 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3590 case BufferParams::RIGHT:
3591 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3594 map<string, string> const & packages = BufferParams::auto_packages();
3595 for (map<string, string>::const_iterator it = packages.begin();
3596 it != packages.end(); ++it) {
3597 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3600 int row = mathsModule->packagesTW->row(item);
3601 switch (bp_.use_package(it->first)) {
3602 case BufferParams::package_off: {
3604 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3605 rb->setChecked(true);
3608 case BufferParams::package_on: {
3610 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3611 rb->setChecked(true);
3614 case BufferParams::package_auto: {
3616 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3617 rb->setChecked(true);
3623 switch (bp_.spacing().getSpace()) {
3624 case Spacing::Other: nitem = 3; break;
3625 case Spacing::Double: nitem = 2; break;
3626 case Spacing::Onehalf: nitem = 1; break;
3627 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3631 string const & layoutID = bp_.baseClassID();
3632 setLayoutComboByIDString(layoutID);
3634 updatePagestyle(documentClass().opt_pagestyle(),
3637 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3638 if (bp_.spacing().getSpace() == Spacing::Other) {
3639 doubleToWidget(textLayoutModule->lspacingLE,
3640 bp_.spacing().getValueAsString());
3644 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3645 textLayoutModule->indentRB->setChecked(true);
3646 string parindent = bp_.getParIndent().asString();
3648 if (!parindent.empty()) {
3649 lengthToWidgets(textLayoutModule->indentLE,
3650 textLayoutModule->indentLengthCO,
3651 parindent, default_unit);
3654 textLayoutModule->indentCO->setCurrentIndex(indent);
3657 textLayoutModule->skipRB->setChecked(true);
3659 switch (bp_.getDefSkip().kind()) {
3660 case VSpace::SMALLSKIP:
3663 case VSpace::MEDSKIP:
3666 case VSpace::BIGSKIP:
3669 case VSpace::LENGTH:
3672 string const length = bp_.getDefSkip().asLyXCommand();
3673 lengthToWidgets(textLayoutModule->skipLE,
3674 textLayoutModule->skipLengthCO,
3675 length, default_unit);
3682 textLayoutModule->skipCO->setCurrentIndex(skip);
3686 textLayoutModule->twoColumnCB->setChecked(
3688 textLayoutModule->justCB->setChecked(bp_.justification);
3690 if (!bp_.options.empty()) {
3691 latexModule->optionsLE->setText(
3692 toqstr(bp_.options));
3694 latexModule->optionsLE->setText(QString());
3698 latexModule->defaultOptionsCB->setChecked(
3699 bp_.use_default_options);
3700 updateSelectedModules();
3701 selectionManager->updateProvidedModules(
3702 bp_.baseClass()->providedModules());
3703 selectionManager->updateExcludedModules(
3704 bp_.baseClass()->excludedModules());
3706 if (!documentClass().options().empty()) {
3707 latexModule->defaultOptionsLE->setText(
3708 toqstr(documentClass().options()));
3710 latexModule->defaultOptionsLE->setText(
3711 toqstr(_("[No options predefined]")));
3714 latexModule->defaultOptionsLE->setEnabled(
3715 bp_.use_default_options
3716 && !documentClass().options().empty());
3718 latexModule->defaultOptionsCB->setEnabled(
3719 !documentClass().options().empty());
3721 if (!bp_.master.empty()) {
3722 latexModule->childDocGB->setChecked(true);
3723 latexModule->childDocLE->setText(
3724 toqstr(bp_.master));
3726 latexModule->childDocLE->setText(QString());
3727 latexModule->childDocGB->setChecked(false);
3731 if (!bufferview() || !buffer().hasChildren()) {
3732 masterChildModule->childrenTW->clear();
3733 includeonlys_.clear();
3734 docPS->showPanel("Child Documents", false);
3735 if (docPS->isCurrentPanel("Child Documents"))
3736 docPS->setCurrentPanel("Document Class");
3738 docPS->showPanel("Child Documents", true);
3739 masterChildModule->setEnabled(true);
3740 includeonlys_ = bp_.getIncludedChildren();
3741 updateIncludeonlys();
3743 masterChildModule->maintainAuxCB->setChecked(
3744 bp_.maintain_unincluded_children);
3747 floatModule->set(bp_.float_placement);
3750 // break listings_params to multiple lines
3752 InsetListingsParams(bp_.listings_params).separatedParams();
3753 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3754 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3756 listingsModule->packageCO->setCurrentIndex(nn);
3760 // some languages only work with polyglossia/XeTeX
3761 Language const * lang = lyx::languages.getLanguage(
3762 fromqstr(langModule->languageCO->itemData(
3763 langModule->languageCO->currentIndex()).toString()));
3764 bool const need_fontspec =
3765 lang->babel().empty() && !lang->polyglossia().empty();
3766 bool const os_fonts_available =
3767 bp_.baseClass()->outputType() == lyx::LATEX
3768 && LaTeXFeatures::isAvailable("fontspec");
3769 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3770 fontModule->osFontsCB->setChecked(
3771 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3772 updateFontsize(documentClass().opt_fontsize(),
3775 QString font = toqstr(bp_.fontsRoman());
3776 int rpos = fontModule->fontsRomanCO->findData(font);
3778 rpos = fontModule->fontsRomanCO->count();
3779 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3781 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3782 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3784 font = toqstr(bp_.fontsSans());
3785 int spos = fontModule->fontsSansCO->findData(font);
3787 spos = fontModule->fontsSansCO->count();
3788 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3790 fontModule->fontsSansCO->setCurrentIndex(spos);
3791 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3793 font = toqstr(bp_.fontsTypewriter());
3794 int tpos = fontModule->fontsTypewriterCO->findData(font);
3796 tpos = fontModule->fontsTypewriterCO->count();
3797 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3799 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3800 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3802 font = toqstr(bp_.fontsMath());
3803 int mpos = fontModule->fontsMathCO->findData(font);
3805 mpos = fontModule->fontsMathCO->count();
3806 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3808 fontModule->fontsMathCO->setCurrentIndex(mpos);
3809 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3811 if (bp_.useNonTeXFonts && os_fonts_available) {
3812 fontModule->fontencLA->setEnabled(false);
3813 fontModule->fontencCO->setEnabled(false);
3814 fontModule->fontencLE->setEnabled(false);
3816 fontModule->fontencLA->setEnabled(true);
3817 fontModule->fontencCO->setEnabled(true);
3818 fontModule->fontencLE->setEnabled(true);
3824 if (!bp_.fonts_cjk.empty())
3825 fontModule->cjkFontLE->setText(
3826 toqstr(bp_.fonts_cjk));
3828 fontModule->cjkFontLE->setText(QString());
3830 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3831 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3833 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3834 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3835 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3836 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3837 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3838 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3840 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3842 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3844 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3845 fontModule->fontencCO->setCurrentIndex(
3846 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3847 fontModule->fontencLE->setEnabled(false);
3849 fontModule->fontencCO->setCurrentIndex(1);
3850 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3854 // This must be set _after_ fonts since updateDefaultFormat()
3855 // checks osFontsCB settings.
3856 // update combobox with formats
3857 updateDefaultFormat();
3858 int index = outputModule->defaultFormatCO->findData(toqstr(
3859 bp_.default_output_format));
3860 // set to default if format is not found
3863 outputModule->defaultFormatCO->setCurrentIndex(index);
3865 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3866 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3867 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3869 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3870 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3871 outputModule->strictCB->setChecked(bp_.html_be_strict);
3872 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3874 outputModule->saveTransientPropertiesCB
3875 ->setChecked(bp_.save_transient_properties);
3878 bool const extern_geometry =
3879 documentClass().provides("geometry");
3880 int const psize = bp_.papersize;
3881 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3882 setCustomPapersize(!extern_geometry && psize == 1);
3883 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3885 bool const landscape =
3886 bp_.orientation == ORIENTATION_LANDSCAPE;
3887 pageLayoutModule->landscapeRB->setChecked(landscape);
3888 pageLayoutModule->portraitRB->setChecked(!landscape);
3889 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3890 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3892 pageLayoutModule->facingPagesCB->setChecked(
3893 bp_.sides == TwoSides);
3895 lengthToWidgets(pageLayoutModule->paperwidthLE,
3896 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3897 lengthToWidgets(pageLayoutModule->paperheightLE,
3898 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3901 Ui::MarginsUi * m = marginsModule;
3905 lengthToWidgets(m->topLE, m->topUnit,
3906 bp_.topmargin, default_unit);
3908 lengthToWidgets(m->bottomLE, m->bottomUnit,
3909 bp_.bottommargin, default_unit);
3911 lengthToWidgets(m->innerLE, m->innerUnit,
3912 bp_.leftmargin, default_unit);
3914 lengthToWidgets(m->outerLE, m->outerUnit,
3915 bp_.rightmargin, default_unit);
3917 lengthToWidgets(m->headheightLE, m->headheightUnit,
3918 bp_.headheight, default_unit);
3920 lengthToWidgets(m->headsepLE, m->headsepUnit,
3921 bp_.headsep, default_unit);
3923 lengthToWidgets(m->footskipLE, m->footskipUnit,
3924 bp_.footskip, default_unit);
3926 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3927 bp_.columnsep, default_unit);
3930 updateUnknownBranches();
3931 branchesModule->update(bp_);
3934 PDFOptions const & pdf = bp_.pdfoptions();
3935 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3936 if (bp_.documentClass().provides("hyperref"))
3937 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3939 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3940 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3941 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3942 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3943 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3945 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3946 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3947 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3949 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3951 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3952 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3953 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3954 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3956 nn = findToken(backref_opts, pdf.backref);
3958 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3960 pdfSupportModule->fullscreenCB->setChecked
3961 (pdf.pagemode == pdf.pagemode_fullscreen);
3963 pdfSupportModule->optionsLE->setText(
3964 toqstr(pdf.quoted_options));
3966 // Make sure that the bc is in the INITIAL state
3967 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3970 // clear changed branches cache
3971 changedBranches_.clear();
3974 nonModuleChanged_ = false;
3975 shellescapeChanged_ = false;
3979 void GuiDocument::saveDocDefault()
3981 // we have to apply the params first
3987 void GuiDocument::updateAvailableModules()
3989 modules_av_model_.clear();
3990 list<modInfoStruct> modInfoList = getModuleInfo();
3991 // Sort names according to the locale
3992 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3993 return 0 < b.name.localeAwareCompare(a.name);
3996 for (modInfoStruct const & m : modInfoList) {
3997 modules_av_model_.insertRow(i, m.name, m.id, m.description);
4003 void GuiDocument::updateSelectedModules()
4005 modules_sel_model_.clear();
4006 list<modInfoStruct> const selModList = getSelectedModules();
4008 for (modInfoStruct const & m : selModList) {
4009 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4015 void GuiDocument::updateIncludeonlys()
4017 masterChildModule->childrenTW->clear();
4018 QString const no = qt_("No");
4019 QString const yes = qt_("Yes");
4021 if (includeonlys_.empty()) {
4022 masterChildModule->includeallRB->setChecked(true);
4023 masterChildModule->childrenTW->setEnabled(false);
4024 masterChildModule->maintainAuxCB->setEnabled(false);
4026 masterChildModule->includeonlyRB->setChecked(true);
4027 masterChildModule->childrenTW->setEnabled(true);
4028 masterChildModule->maintainAuxCB->setEnabled(true);
4030 ListOfBuffers children = buffer().getChildren();
4031 ListOfBuffers::const_iterator it = children.begin();
4032 ListOfBuffers::const_iterator end = children.end();
4033 bool has_unincluded = false;
4034 bool all_unincluded = true;
4035 for (; it != end; ++it) {
4036 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4039 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4040 from_utf8(buffer().filePath())));
4041 item->setText(0, toqstr(name));
4042 item->setText(1, isChildIncluded(name) ? yes : no);
4043 if (!isChildIncluded(name))
4044 has_unincluded = true;
4046 all_unincluded = false;
4048 // Both if all childs are included and if none is included
4049 // is equal to "include all" (i.e., omit \includeonly).
4050 // Thus, reset the GUI.
4051 if (!has_unincluded || all_unincluded) {
4052 masterChildModule->includeallRB->setChecked(true);
4053 masterChildModule->childrenTW->setEnabled(false);
4054 includeonlys_.clear();
4056 // If all are included, we need to update again.
4057 if (!has_unincluded)
4058 updateIncludeonlys();
4062 bool GuiDocument::isBiblatex() const
4064 QString const engine =
4065 biblioModule->citeEngineCO->itemData(
4066 biblioModule->citeEngineCO->currentIndex()).toString();
4068 // this can happen if the cite engine is unknown, which can happen
4069 // if one is using a file that came from someone else, etc. in that
4070 // case, we crash if we proceed.
4071 if (engine.isEmpty())
4074 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4078 void GuiDocument::updateDefaultBiblio(string const & style,
4079 string const & which)
4081 QString const bibstyle = toqstr(style);
4082 biblioModule->defaultBiblioCO->clear();
4087 if (which != "cbx") {
4088 // First the bbx styles
4089 biblioModule->biblatexBbxCO->clear();
4090 QStringList str = texFileList("bbxFiles.lst");
4091 // test whether we have a valid list, otherwise run rescan
4092 if (str.isEmpty()) {
4093 rescanTexStyles("bbx");
4094 str = texFileList("bbxFiles.lst");
4096 for (int i = 0; i != str.size(); ++i)
4097 str[i] = onlyFileName(str[i]);
4098 // sort on filename only (no path)
4101 for (int i = 0; i != str.count(); ++i) {
4102 QString item = changeExtension(str[i], "");
4103 if (item == bibstyle)
4105 biblioModule->biblatexBbxCO->addItem(item);
4108 if (item_nr == -1 && !bibstyle.isEmpty()) {
4109 biblioModule->biblatexBbxCO->addItem(bibstyle);
4110 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4114 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4116 biblioModule->biblatexBbxCO->clearEditText();
4119 if (which != "bbx") {
4120 // now the cbx styles
4121 biblioModule->biblatexCbxCO->clear();
4122 QStringList str = texFileList("cbxFiles.lst");
4123 // test whether we have a valid list, otherwise run rescan
4124 if (str.isEmpty()) {
4125 rescanTexStyles("cbx");
4126 str = texFileList("cbxFiles.lst");
4128 for (int i = 0; i != str.size(); ++i)
4129 str[i] = onlyFileName(str[i]);
4130 // sort on filename only (no path)
4133 for (int i = 0; i != str.count(); ++i) {
4134 QString item = changeExtension(str[i], "");
4135 if (item == bibstyle)
4137 biblioModule->biblatexCbxCO->addItem(item);
4140 if (item_nr == -1 && !bibstyle.isEmpty()) {
4141 biblioModule->biblatexCbxCO->addItem(bibstyle);
4142 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4146 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4148 biblioModule->biblatexCbxCO->clearEditText();
4151 biblioModule->biblatexBbxCO->clear();
4152 biblioModule->biblatexCbxCO->clear();
4153 QStringList str = texFileList("bstFiles.lst");
4154 // test whether we have a valid list, otherwise run rescan
4155 if (str.isEmpty()) {
4156 rescanTexStyles("bst");
4157 str = texFileList("bstFiles.lst");
4159 for (int i = 0; i != str.size(); ++i)
4160 str[i] = onlyFileName(str[i]);
4161 // sort on filename only (no path)
4164 for (int i = 0; i != str.count(); ++i) {
4165 QString item = changeExtension(str[i], "");
4166 if (item == bibstyle)
4168 biblioModule->defaultBiblioCO->addItem(item);
4171 if (item_nr == -1 && !bibstyle.isEmpty()) {
4172 biblioModule->defaultBiblioCO->addItem(bibstyle);
4173 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4177 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4179 biblioModule->defaultBiblioCO->clearEditText();
4182 updateResetDefaultBiblio();
4186 void GuiDocument::updateResetDefaultBiblio()
4188 QString const engine =
4189 biblioModule->citeEngineCO->itemData(
4190 biblioModule->citeEngineCO->currentIndex()).toString();
4191 CiteEngineType const cet =
4192 CiteEngineType(biblioModule->citeStyleCO->itemData(
4193 biblioModule->citeStyleCO->currentIndex()).toInt());
4195 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4197 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4198 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4199 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4200 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4201 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4202 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4204 biblioModule->resetDefaultBiblioPB->setEnabled(
4205 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4209 void GuiDocument::matchBiblatexStyles()
4211 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4216 void GuiDocument::updateContents()
4218 // Nothing to do here as the document settings is not cursor dependant.
4223 void GuiDocument::useClassDefaults()
4225 if (applyPB->isEnabled()) {
4226 int const ret = Alert::prompt(_("Unapplied changes"),
4227 _("Some changes in the dialog were not yet applied.\n"
4228 "If you do not apply now, they will be lost after this action."),
4229 1, 1, _("&Apply"), _("&Dismiss"));
4234 int idx = latexModule->classCO->currentIndex();
4235 string const classname = fromqstr(latexModule->classCO->getData(idx));
4236 if (!bp_.setBaseClass(classname)) {
4237 Alert::error(_("Error"), _("Unable to set document class."));
4240 bp_.useClassDefaults();
4246 void GuiDocument::setLayoutComboByIDString(string const & idString)
4248 if (!latexModule->classCO->set(toqstr(idString)))
4249 Alert::warning(_("Can't set layout!"),
4250 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4254 bool GuiDocument::isValid()
4257 validateListingsParameters().isEmpty() &&
4258 localLayout->isValid() &&
4260 // if we're asking for skips between paragraphs
4261 !textLayoutModule->skipRB->isChecked() ||
4262 // then either we haven't chosen custom
4263 textLayoutModule->skipCO->currentIndex() != 3 ||
4264 // or else a length has been given
4265 !textLayoutModule->skipLE->text().isEmpty()
4268 // if we're asking for indentation
4269 !textLayoutModule->indentRB->isChecked() ||
4270 // then either we haven't chosen custom
4271 textLayoutModule->indentCO->currentIndex() != 1 ||
4272 // or else a length has been given
4273 !textLayoutModule->indentLE->text().isEmpty()
4276 // if we're asking for math indentation
4277 !mathsModule->MathIndentCB->isChecked() ||
4278 // then either we haven't chosen custom
4279 mathsModule->MathIndentCO->currentIndex() != 1 ||
4280 // or else a length has been given
4281 !mathsModule->MathIndentLE->text().isEmpty()
4286 char const * const GuiDocument::fontfamilies[5] = {
4287 "default", "rmdefault", "sfdefault", "ttdefault", ""
4291 char const * GuiDocument::fontfamilies_gui[5] = {
4292 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4296 bool GuiDocument::initialiseParams(string const &)
4298 BufferView const * view = bufferview();
4300 bp_ = BufferParams();
4304 bp_ = view->buffer().params();
4306 updateAvailableModules();
4307 //FIXME It'd be nice to make sure here that the selected
4308 //modules are consistent: That required modules are actually
4309 //selected, and that we don't have conflicts. If so, we could
4310 //at least pop up a warning.
4316 void GuiDocument::clearParams()
4318 bp_ = BufferParams();
4322 BufferId GuiDocument::id() const
4324 BufferView const * const view = bufferview();
4325 return view? &view->buffer() : 0;
4329 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4331 return moduleNames_;
4335 list<GuiDocument::modInfoStruct> const
4336 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4338 list<modInfoStruct> mInfo;
4339 for (string const & name : mods) {
4341 LyXModule const * const mod = theModuleList[name];
4346 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4354 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4356 return makeModuleInfo(params().getModules());
4360 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4362 return makeModuleInfo(params().baseClass()->providedModules());
4366 DocumentClass const & GuiDocument::documentClass() const
4368 return bp_.documentClass();
4372 static void dispatch_bufferparams(Dialog const & dialog,
4373 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4376 ss << "\\begin_header\n";
4377 bp.writeFile(ss, buf);
4378 ss << "\\end_header\n";
4379 dialog.dispatch(FuncRequest(lfun, ss.str()));
4383 void GuiDocument::dispatchParams()
4385 // We need a non-const buffer object.
4386 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4387 // There may be several undo records; group them (bug #8998)
4388 // This handles undo groups automagically
4389 UndoGroupHelper ugh(&buf);
4391 // This must come first so that a language change is correctly noticed
4394 // Apply the BufferParams. Note that this will set the base class
4395 // and then update the buffer's layout.
4396 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4398 if (!params().master.empty()) {
4399 FileName const master_file = support::makeAbsPath(params().master,
4400 support::onlyPath(buffer().absFileName()));
4401 if (isLyXFileName(master_file.absFileName())) {
4402 Buffer * master = checkAndLoadLyXFile(master_file);
4404 if (master->isChild(const_cast<Buffer *>(&buffer())))
4405 const_cast<Buffer &>(buffer()).setParent(master);
4407 Alert::warning(_("Assigned master does not include this file"),
4408 bformat(_("You must include this file in the document\n"
4409 "'%1$s' in order to use the master document\n"
4410 "feature."), from_utf8(params().master)));
4412 Alert::warning(_("Could not load master"),
4413 bformat(_("The master document '%1$s'\n"
4414 "could not be loaded."),
4415 from_utf8(params().master)));
4419 // Generate the colours requested by each new branch.
4420 BranchList & branchlist = params().branchlist();
4421 if (!branchlist.empty()) {
4422 BranchList::const_iterator it = branchlist.begin();
4423 BranchList::const_iterator const end = branchlist.end();
4424 for (; it != end; ++it) {
4425 docstring const & current_branch = it->branch();
4426 Branch const * branch = branchlist.find(current_branch);
4427 string const x11hexname = X11hexname(branch->color());
4428 // display the new color
4429 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4430 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4433 // rename branches in the document
4434 executeBranchRenaming();
4435 // and clear changed branches cache
4436 changedBranches_.clear();
4438 // Generate the colours requested by indices.
4439 IndicesList & indiceslist = params().indiceslist();
4440 if (!indiceslist.empty()) {
4441 IndicesList::const_iterator it = indiceslist.begin();
4442 IndicesList::const_iterator const end = indiceslist.end();
4443 for (; it != end; ++it) {
4444 docstring const & current_index = it->shortcut();
4445 Index const * index = indiceslist.findShortcut(current_index);
4446 string const x11hexname = X11hexname(index->color());
4447 // display the new color
4448 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4449 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4453 // If we used an LFUN, we would not need these two lines:
4454 BufferView * bv = const_cast<BufferView *>(bufferview());
4455 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4459 void GuiDocument::setLanguage() const
4461 Language const * const newL = bp_.language;
4462 if (buffer().params().language == newL)
4465 string const & lang_name = newL->lang();
4466 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4470 void GuiDocument::saveAsDefault() const
4472 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4476 bool GuiDocument::providesOSF(QString const & font) const
4478 if (fontModule->osFontsCB->isChecked())
4479 // FIXME: we should check if the fonts really
4480 // have OSF support. But how?
4482 return theLaTeXFonts().getLaTeXFont(
4483 qstring_to_ucs4(font)).providesOSF(ot1(),
4489 bool GuiDocument::providesSC(QString const & font) const
4491 if (fontModule->osFontsCB->isChecked())
4493 return theLaTeXFonts().getLaTeXFont(
4494 qstring_to_ucs4(font)).providesSC(ot1(),
4500 bool GuiDocument::providesScale(QString const & font) const
4502 if (fontModule->osFontsCB->isChecked())
4504 return theLaTeXFonts().getLaTeXFont(
4505 qstring_to_ucs4(font)).providesScale(ot1(),
4511 bool GuiDocument::providesNoMath(QString const & font) const
4513 if (fontModule->osFontsCB->isChecked())
4515 return theLaTeXFonts().getLaTeXFont(
4516 qstring_to_ucs4(font)).providesNoMath(ot1(),
4521 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4523 if (fontModule->osFontsCB->isChecked())
4525 return theLaTeXFonts().getLaTeXFont(
4526 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4533 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4535 // FIXME Unicode: docstrings would be better for these parameters but this
4536 // change requires a lot of others
4539 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4540 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4541 // Find the first sentence of the description
4542 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4543 int pos = bf.toNextBoundary();
4546 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4547 // Tooltip is the desc followed by the module name
4548 m.description = QString("%1<i>%2</i>")
4549 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4555 void GuiDocument::loadModuleInfo()
4557 moduleNames_.clear();
4558 for (LyXModule const & mod : theModuleList)
4559 if (mod.category().substr(0, 8) != "Citation")
4560 moduleNames_.push_back(modInfo(mod));
4564 void GuiDocument::updateUnknownBranches()
4568 list<docstring> used_branches;
4569 buffer().getUsedBranches(used_branches);
4570 list<docstring>::const_iterator it = used_branches.begin();
4571 QStringList unknown_branches;
4572 for (; it != used_branches.end() ; ++it) {
4573 if (!buffer().params().branchlist().find(*it))
4574 unknown_branches.append(toqstr(*it));
4576 branchesModule->setUnknownBranches(unknown_branches);
4580 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4582 map<docstring, docstring>::iterator it = changedBranches_.begin();
4583 for (; it != changedBranches_.end() ; ++it) {
4584 if (it->second == oldname) {
4585 // branch has already been renamed
4586 it->second = newname;
4591 changedBranches_[oldname] = newname;
4595 void GuiDocument::executeBranchRenaming() const
4597 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4598 for (; it != changedBranches_.end() ; ++it) {
4599 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4600 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4605 void GuiDocument::allPackagesAuto()
4611 void GuiDocument::allPackagesAlways()
4617 void GuiDocument::allPackagesNot()
4623 void GuiDocument::allPackages(int col)
4625 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4627 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4628 rb->setChecked(true);
4633 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4636 } // namespace frontend
4639 #include "moc_GuiDocument.cpp"