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