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 QTextCursor 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()));
845 fontModule = new FontModule(this);
846 connect(fontModule->osFontsCB, SIGNAL(clicked()),
847 this, SLOT(change_adaptor()));
848 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
849 this, SLOT(osFontsChanged(bool)));
850 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
851 this, SLOT(change_adaptor()));
852 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
853 this, SLOT(romanChanged(int)));
854 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
855 this, SLOT(change_adaptor()));
856 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
857 this, SLOT(sansChanged(int)));
858 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
859 this, SLOT(change_adaptor()));
860 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
861 this, SLOT(ttChanged(int)));
862 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
863 this, SLOT(change_adaptor()));
864 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
865 this, SLOT(mathFontChanged(int)));
866 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
867 this, SLOT(change_adaptor()));
868 connect(fontModule->fontencCO, SIGNAL(activated(int)),
869 this, SLOT(change_adaptor()));
870 connect(fontModule->fontencCO, SIGNAL(activated(int)),
871 this, SLOT(fontencChanged(int)));
872 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
873 this, SLOT(change_adaptor()));
874 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
875 this, SLOT(change_adaptor()));
876 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
877 this, SLOT(change_adaptor()));
878 connect(fontModule->microtypeCB, SIGNAL(clicked()),
879 this, SLOT(change_adaptor()));
880 connect(fontModule->dashesCB, SIGNAL(clicked()),
881 this, SLOT(change_adaptor()));
882 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
883 this, SLOT(change_adaptor()));
884 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
885 this, SLOT(change_adaptor()));
886 connect(fontModule->fontScCB, SIGNAL(clicked()),
887 this, SLOT(change_adaptor()));
888 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
889 this, SLOT(fontScToggled(bool)));
890 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
891 this, SLOT(change_adaptor()));
892 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
893 this, SLOT(fontOsfToggled(bool)));
895 fontModule->fontencLE->setValidator(new NoNewLineValidator(
896 fontModule->fontencLE));
897 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
898 fontModule->cjkFontLE));
902 fontModule->fontsizeCO->addItem(qt_("Default"));
903 fontModule->fontsizeCO->addItem(qt_("10"));
904 fontModule->fontsizeCO->addItem(qt_("11"));
905 fontModule->fontsizeCO->addItem(qt_("12"));
907 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
908 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
909 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
911 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
912 fontModule->fontsDefaultCO->addItem(
913 qt_(GuiDocument::fontfamilies_gui[n]));
915 if (!LaTeXFeatures::isAvailable("fontspec"))
916 fontModule->osFontsCB->setToolTip(
917 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
918 "You need to install the package \"fontspec\" to use this feature"));
922 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
923 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
924 this, SLOT(papersizeChanged(int)));
925 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
926 this, SLOT(papersizeChanged(int)));
927 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
928 this, SLOT(change_adaptor()));
929 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
930 this, SLOT(change_adaptor()));
931 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
932 this, SLOT(change_adaptor()));
933 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
934 this, SLOT(change_adaptor()));
935 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
936 this, SLOT(change_adaptor()));
937 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
938 this, SLOT(change_adaptor()));
939 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
940 this, SLOT(change_adaptor()));
941 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
942 this, SLOT(change_adaptor()));
943 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
944 this, SLOT(change_adaptor()));
945 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
946 this, SLOT(change_adaptor()));
948 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
949 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
950 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
951 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
952 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
953 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
954 pageLayoutModule->paperheightL);
955 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
956 pageLayoutModule->paperwidthL);
958 QComboBox * cb = pageLayoutModule->papersizeCO;
959 cb->addItem(qt_("Default"));
960 cb->addItem(qt_("Custom"));
961 cb->addItem(qt_("US letter"));
962 cb->addItem(qt_("US legal"));
963 cb->addItem(qt_("US executive"));
964 cb->addItem(qt_("A0"));
965 cb->addItem(qt_("A1"));
966 cb->addItem(qt_("A2"));
967 cb->addItem(qt_("A3"));
968 cb->addItem(qt_("A4"));
969 cb->addItem(qt_("A5"));
970 cb->addItem(qt_("A6"));
971 cb->addItem(qt_("B0"));
972 cb->addItem(qt_("B1"));
973 cb->addItem(qt_("B2"));
974 cb->addItem(qt_("B3"));
975 cb->addItem(qt_("B4"));
976 cb->addItem(qt_("B5"));
977 cb->addItem(qt_("B6"));
978 cb->addItem(qt_("C0"));
979 cb->addItem(qt_("C1"));
980 cb->addItem(qt_("C2"));
981 cb->addItem(qt_("C3"));
982 cb->addItem(qt_("C4"));
983 cb->addItem(qt_("C5"));
984 cb->addItem(qt_("C6"));
985 cb->addItem(qt_("JIS B0"));
986 cb->addItem(qt_("JIS B1"));
987 cb->addItem(qt_("JIS B2"));
988 cb->addItem(qt_("JIS B3"));
989 cb->addItem(qt_("JIS B4"));
990 cb->addItem(qt_("JIS B5"));
991 cb->addItem(qt_("JIS B6"));
992 // remove the %-items from the unit choice
993 pageLayoutModule->paperwidthUnitCO->noPercents();
994 pageLayoutModule->paperheightUnitCO->noPercents();
995 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
996 pageLayoutModule->paperheightLE));
997 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
998 pageLayoutModule->paperwidthLE));
1002 marginsModule = new UiWidget<Ui::MarginsUi>(this);
1003 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1004 this, SLOT(setCustomMargins(bool)));
1005 connect(marginsModule->marginCB, SIGNAL(clicked()),
1006 this, SLOT(change_adaptor()));
1007 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1008 this, SLOT(change_adaptor()));
1009 connect(marginsModule->topUnit, SIGNAL(activated(int)),
1010 this, SLOT(change_adaptor()));
1011 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1012 this, SLOT(change_adaptor()));
1013 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1014 this, SLOT(change_adaptor()));
1015 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1016 this, SLOT(change_adaptor()));
1017 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1018 this, SLOT(change_adaptor()));
1019 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1020 this, SLOT(change_adaptor()));
1021 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1022 this, SLOT(change_adaptor()));
1023 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1024 this, SLOT(change_adaptor()));
1025 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1026 this, SLOT(change_adaptor()));
1027 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1028 this, SLOT(change_adaptor()));
1029 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1030 this, SLOT(change_adaptor()));
1031 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1032 this, SLOT(change_adaptor()));
1033 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1034 this, SLOT(change_adaptor()));
1035 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1036 this, SLOT(change_adaptor()));
1037 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1038 this, SLOT(change_adaptor()));
1039 marginsModule->topLE->setValidator(new LengthValidator(
1040 marginsModule->topLE));
1041 marginsModule->bottomLE->setValidator(new LengthValidator(
1042 marginsModule->bottomLE));
1043 marginsModule->innerLE->setValidator(new LengthValidator(
1044 marginsModule->innerLE));
1045 marginsModule->outerLE->setValidator(new LengthValidator(
1046 marginsModule->outerLE));
1047 marginsModule->headsepLE->setValidator(new LengthValidator(
1048 marginsModule->headsepLE));
1049 marginsModule->headheightLE->setValidator(new LengthValidator(
1050 marginsModule->headheightLE));
1051 marginsModule->footskipLE->setValidator(new LengthValidator(
1052 marginsModule->footskipLE));
1053 marginsModule->columnsepLE->setValidator(new LengthValidator(
1054 marginsModule->columnsepLE));
1056 bc().addCheckedLineEdit(marginsModule->topLE,
1057 marginsModule->topL);
1058 bc().addCheckedLineEdit(marginsModule->bottomLE,
1059 marginsModule->bottomL);
1060 bc().addCheckedLineEdit(marginsModule->innerLE,
1061 marginsModule->innerL);
1062 bc().addCheckedLineEdit(marginsModule->outerLE,
1063 marginsModule->outerL);
1064 bc().addCheckedLineEdit(marginsModule->headsepLE,
1065 marginsModule->headsepL);
1066 bc().addCheckedLineEdit(marginsModule->headheightLE,
1067 marginsModule->headheightL);
1068 bc().addCheckedLineEdit(marginsModule->footskipLE,
1069 marginsModule->footskipL);
1070 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1071 marginsModule->columnsepL);
1075 langModule = new UiWidget<Ui::LanguageUi>(this);
1076 connect(langModule->languageCO, SIGNAL(activated(int)),
1077 this, SLOT(change_adaptor()));
1078 connect(langModule->languageCO, SIGNAL(activated(int)),
1079 this, SLOT(languageChanged(int)));
1080 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1081 this, SLOT(change_adaptor()));
1082 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1083 this, SLOT(change_adaptor()));
1084 connect(langModule->encodingCO, SIGNAL(activated(int)),
1085 this, SLOT(change_adaptor()));
1086 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1087 this, SLOT(change_adaptor()));
1088 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1089 this, SLOT(change_adaptor()));
1090 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1091 this, SLOT(change_adaptor()));
1092 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1093 this, SLOT(languagePackageChanged(int)));
1094 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1095 this, SLOT(change_adaptor()));
1097 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1098 langModule->languagePackageLE));
1100 QAbstractItemModel * language_model = guiApp->languageModel();
1101 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1102 language_model->sort(0);
1103 langModule->languageCO->setModel(language_model);
1104 langModule->languageCO->setModelColumn(0);
1106 // Always put the default encoding in the first position.
1107 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1108 QStringList encodinglist;
1109 for (auto const & encvar : encodings) {
1110 if (!encvar.unsafe() && !encvar.guiName().empty())
1111 encodinglist.append(qt_(encvar.guiName()));
1113 encodinglist.sort();
1114 langModule->encodingCO->addItems(encodinglist);
1116 langModule->languagePackageCO->addItem(
1117 qt_("Default"), toqstr("default"));
1118 langModule->languagePackageCO->addItem(
1119 qt_("Automatic"), toqstr("auto"));
1120 langModule->languagePackageCO->addItem(
1121 qt_("Always Babel"), toqstr("babel"));
1122 langModule->languagePackageCO->addItem(
1123 qt_("Custom"), toqstr("custom"));
1124 langModule->languagePackageCO->addItem(
1125 qt_("None[[language package]]"), toqstr("none"));
1129 colorModule = new UiWidget<Ui::ColorUi>(this);
1130 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1131 this, SLOT(changeFontColor()));
1132 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1133 this, SLOT(deleteFontColor()));
1134 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1135 this, SLOT(changeNoteFontColor()));
1136 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1137 this, SLOT(deleteNoteFontColor()));
1138 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1139 this, SLOT(changeBackgroundColor()));
1140 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1141 this, SLOT(deleteBackgroundColor()));
1142 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1143 this, SLOT(changeBoxBackgroundColor()));
1144 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1145 this, SLOT(deleteBoxBackgroundColor()));
1149 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1150 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1151 this, SLOT(change_adaptor()));
1152 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1153 this, SLOT(change_adaptor()));
1154 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1155 this, SLOT(updateNumbering()));
1156 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1157 this, SLOT(updateNumbering()));
1158 numberingModule->tocTW->setColumnCount(3);
1159 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1160 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1161 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1162 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1165 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1166 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1167 this, SLOT(citeEngineChanged(int)));
1168 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1169 this, SLOT(citeStyleChanged()));
1170 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1171 this, SLOT(biblioChanged()));
1172 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1173 this, SLOT(biblioChanged()));
1174 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1175 this, SLOT(bibtexChanged(int)));
1176 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1177 this, SLOT(biblioChanged()));
1178 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1179 this, SLOT(biblioChanged()));
1180 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1181 this, SLOT(biblioChanged()));
1182 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1183 this, SLOT(biblioChanged()));
1184 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1185 this, SLOT(updateResetDefaultBiblio()));
1186 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1187 this, SLOT(biblioChanged()));
1188 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1189 this, SLOT(biblioChanged()));
1190 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1191 this, SLOT(updateResetDefaultBiblio()));
1192 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1193 this, SLOT(biblioChanged()));
1194 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1195 this, SLOT(biblioChanged()));
1196 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1197 this, SLOT(updateResetDefaultBiblio()));
1198 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1199 this, SLOT(rescanBibFiles()));
1200 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1201 this, SLOT(resetDefaultBibfile()));
1202 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1203 this, SLOT(resetDefaultCbxBibfile()));
1204 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1205 this, SLOT(resetDefaultBbxBibfile()));
1206 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1207 this, SLOT(matchBiblatexStyles()));
1209 biblioModule->citeEngineCO->clear();
1210 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1211 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1212 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1213 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1217 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1218 biblioModule->bibtexOptionsLE));
1219 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1220 biblioModule->defaultBiblioCO->lineEdit()));
1221 biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1222 biblioModule->citePackageOptionsLE));
1224 // NOTE: we do not provide "custom" here for security reasons!
1225 biblioModule->bibtexCO->clear();
1226 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1227 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1228 it != lyxrc.bibtex_alternatives.end(); ++it) {
1229 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1230 biblioModule->bibtexCO->addItem(command, command);
1235 indicesModule = new GuiIndices;
1236 connect(indicesModule, SIGNAL(changed()),
1237 this, SLOT(change_adaptor()));
1241 mathsModule = new UiWidget<Ui::MathsUi>(this);
1242 QStringList headers;
1243 headers << qt_("Package") << qt_("Load automatically")
1244 << qt_("Load always") << qt_("Do not load");
1245 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1246 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1247 map<string, string> const & packages = BufferParams::auto_packages();
1248 mathsModule->packagesTW->setRowCount(packages.size());
1250 for (map<string, string>::const_iterator it = packages.begin();
1251 it != packages.end(); ++it) {
1252 docstring const package = from_ascii(it->first);
1253 QString autoTooltip = qt_(it->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));
1305 mathsModule->packagesTW->setItem(packnum, 0, pack);
1306 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1307 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1308 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1310 connect(autoRB, SIGNAL(clicked()),
1311 this, SLOT(change_adaptor()));
1312 connect(alwaysRB, SIGNAL(clicked()),
1313 this, SLOT(change_adaptor()));
1314 connect(neverRB, SIGNAL(clicked()),
1315 this, SLOT(change_adaptor()));
1318 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1319 this, SLOT(allPackagesAuto()));
1320 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1321 this, SLOT(allPackagesAlways()));
1322 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1323 this, SLOT(allPackagesNot()));
1324 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1325 this, SLOT(change_adaptor()));
1326 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1327 this, SLOT(change_adaptor()));
1328 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1329 this, SLOT(change_adaptor()));
1330 connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1331 this, SLOT(change_adaptor()));
1333 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1334 this, SLOT(change_adaptor()));
1335 connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1336 this, SLOT(allowMathIndent()));
1337 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1338 this, SLOT(change_adaptor()));
1339 connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1340 this, SLOT(enableMathIndent(int)));
1341 connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1342 this, SLOT(change_adaptor()));
1343 connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1344 this, SLOT(change_adaptor()));
1347 mathsModule->MathIndentCO->addItem(qt_("Default"));
1348 mathsModule->MathIndentCO->addItem(qt_("Custom"));
1349 mathsModule->MathIndentLE->setValidator(new LengthValidator(
1350 mathsModule->MathIndentLE));
1351 // initialize the length validator
1352 bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1353 mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1354 mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1355 mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1356 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1360 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1361 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1362 this, SLOT(change_adaptor()));
1363 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1364 this, SLOT(change_adaptor()));
1365 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1366 this, SLOT(change_adaptor()));
1367 connect(latexModule->classCO, SIGNAL(activated(int)),
1368 this, SLOT(classChanged_adaptor()));
1369 connect(latexModule->classCO, SIGNAL(activated(int)),
1370 this, SLOT(change_adaptor()));
1371 connect(latexModule->layoutPB, SIGNAL(clicked()),
1372 this, SLOT(browseLayout()));
1373 connect(latexModule->layoutPB, SIGNAL(clicked()),
1374 this, SLOT(change_adaptor()));
1375 connect(latexModule->childDocGB, SIGNAL(clicked()),
1376 this, SLOT(change_adaptor()));
1377 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1378 this, SLOT(change_adaptor()));
1379 connect(latexModule->childDocPB, SIGNAL(clicked()),
1380 this, SLOT(browseMaster()));
1381 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1382 this, SLOT(change_adaptor()));
1383 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1384 this, SLOT(change_adaptor()));
1386 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1387 latexModule->optionsLE));
1388 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1389 latexModule->childDocLE));
1391 // postscript drivers
1392 for (int n = 0; tex_graphics[n][0]; ++n) {
1393 QString enc = qt_(tex_graphics_gui[n]);
1394 latexModule->psdriverCO->addItem(enc);
1397 LayoutFileList const & bcl = LayoutFileList::get();
1398 vector<LayoutFileIndex> classList = bcl.classList();
1399 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1401 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1402 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1403 for (int i = 0; cit != cen; ++cit, ++i) {
1404 LayoutFile const & tc = bcl[*cit];
1405 bool const available = tc.isTeXClassAvailable();
1406 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1407 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1408 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1410 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1411 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1412 "Please check if you have the matching %1$s class "
1413 "and all required packages (%2$s) installed."),
1414 output_type, from_utf8(tc.prerequisites(", "))));
1416 latexModule->classCO->addItemSort(toqstr(tc.name()),
1418 toqstr(translateIfPossible(from_utf8(tc.category()))),
1420 true, true, true, available);
1425 branchesModule = new GuiBranches(this);
1426 connect(branchesModule, SIGNAL(changed()),
1427 this, SLOT(change_adaptor()));
1428 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1429 this, SLOT(branchesRename(docstring const &, docstring const &)));
1430 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1431 updateUnknownBranches();
1435 preambleModule = new PreambleModule(this);
1436 connect(preambleModule, SIGNAL(changed()),
1437 this, SLOT(change_adaptor()));
1439 localLayout = new LocalLayout(this);
1440 connect(localLayout, SIGNAL(changed()),
1441 this, SLOT(change_adaptor()));
1445 bulletsModule = new BulletsModule(this);
1446 connect(bulletsModule, SIGNAL(changed()),
1447 this, SLOT(change_adaptor()));
1451 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1452 modulesModule->availableLV->header()->setVisible(false);
1453 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1454 modulesModule->availableLV->header()->setStretchLastSection(false);
1456 new ModuleSelectionManager(this, modulesModule->availableLV,
1457 modulesModule->selectedLV,
1458 modulesModule->addPB,
1459 modulesModule->deletePB,
1460 modulesModule->upPB,
1461 modulesModule->downPB,
1462 availableModel(), selectedModel(), this);
1463 connect(selectionManager, SIGNAL(updateHook()),
1464 this, SLOT(updateModuleInfo()));
1465 connect(selectionManager, SIGNAL(selectionChanged()),
1466 this, SLOT(modulesChanged()));
1470 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1471 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1472 this, SLOT(change_adaptor()));
1473 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1474 this, SLOT(change_adaptor()));
1475 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1476 this, SLOT(change_adaptor()));
1477 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1478 this, SLOT(change_adaptor()));
1479 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1480 this, SLOT(change_adaptor()));
1481 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1482 this, SLOT(change_adaptor()));
1483 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1484 this, SLOT(change_adaptor()));
1485 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1486 this, SLOT(change_adaptor()));
1487 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1488 this, SLOT(change_adaptor()));
1489 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1490 this, SLOT(change_adaptor()));
1491 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1492 this, SLOT(change_adaptor()));
1493 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1494 this, SLOT(change_adaptor()));
1495 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1496 this, SLOT(change_adaptor()));
1497 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1498 this, SLOT(change_adaptor()));
1499 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1500 this, SLOT(change_adaptor()));
1501 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1502 this, SLOT(change_adaptor()));
1504 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1505 pdfSupportModule->titleLE));
1506 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1507 pdfSupportModule->authorLE));
1508 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1509 pdfSupportModule->subjectLE));
1510 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1511 pdfSupportModule->keywordsLE));
1512 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1513 pdfSupportModule->optionsLE));
1515 for (int i = 0; backref_opts[i][0]; ++i)
1516 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1520 floatModule = new FloatPlacement;
1521 connect(floatModule, SIGNAL(changed()),
1522 this, SLOT(change_adaptor()));
1526 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1527 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1528 this, SLOT(change_adaptor()));
1529 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1530 this, SLOT(change_adaptor()));
1531 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1532 this, SLOT(setListingsMessage()));
1533 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1534 this, SLOT(change_adaptor()));
1535 connect(listingsModule->packageCO, SIGNAL(activated(int)),
1536 this, SLOT(listingsPackageChanged(int)));
1537 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1538 this, SLOT(setListingsMessage()));
1539 listingsModule->listingsTB->setPlainText(
1540 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1542 for (int i = 0; lst_packages[i][0]; ++i)
1543 listingsModule->packageCO->addItem(lst_packages[i]);
1547 docPS->addPanel(latexModule, N_("Document Class"));
1548 docPS->addPanel(masterChildModule, N_("Child Documents"));
1549 docPS->addPanel(modulesModule, N_("Modules"));
1550 docPS->addPanel(localLayout, N_("Local Layout"));
1551 docPS->addPanel(fontModule, N_("Fonts"));
1552 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1553 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1554 docPS->addPanel(marginsModule, N_("Page Margins"));
1555 docPS->addPanel(langModule, N_("Language"));
1556 docPS->addPanel(colorModule, N_("Colors"));
1557 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1558 docPS->addPanel(biblioModule, N_("Bibliography"));
1559 docPS->addPanel(indicesModule, N_("Indexes"));
1560 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1561 docPS->addPanel(mathsModule, N_("Math Options"));
1562 docPS->addPanel(floatModule, N_("Float Placement"));
1563 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1564 docPS->addPanel(bulletsModule, N_("Bullets"));
1565 docPS->addPanel(branchesModule, N_("Branches"));
1566 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1567 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1568 docPS->setCurrentPanel("Document Class");
1569 // FIXME: hack to work around resizing bug in Qt >= 4.2
1570 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1571 #if QT_VERSION >= 0x040200
1572 docPS->updateGeometry();
1577 void GuiDocument::onBufferViewChanged()
1579 if (isVisibleView())
1580 initialiseParams("");
1584 void GuiDocument::saveDefaultClicked()
1590 void GuiDocument::useDefaultsClicked()
1596 void GuiDocument::change_adaptor()
1598 nonModuleChanged_ = true;
1603 void GuiDocument::shellescapeChanged()
1605 shellescapeChanged_ = true;
1610 void GuiDocument::slotApply()
1612 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1613 bool wasclean = buffer().isClean();
1614 GuiDialog::slotApply();
1615 if (wasclean && only_shellescape_changed)
1616 buffer().markClean();
1617 modulesChanged_ = false;
1621 void GuiDocument::slotOK()
1623 bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1624 bool wasclean = buffer().isClean();
1625 GuiDialog::slotOK();
1626 if (wasclean && only_shellescape_changed)
1627 buffer().markClean();
1628 modulesChanged_ = false;
1632 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1637 string child = fromqstr(item->text(0));
1641 if (std::find(includeonlys_.begin(),
1642 includeonlys_.end(), child) != includeonlys_.end())
1643 includeonlys_.remove(child);
1645 includeonlys_.push_back(child);
1647 updateIncludeonlys();
1652 QString GuiDocument::validateListingsParameters()
1654 if (listingsModule->bypassCB->isChecked())
1656 string const package =
1657 lst_packages[listingsModule->packageCO->currentIndex()];
1658 string params = fromqstr(listingsModule->listingsED->toPlainText());
1659 InsetListingsParams lstparams(params);
1660 lstparams.setMinted(package == "Minted");
1661 return toqstr(lstparams.validate());
1665 void GuiDocument::setListingsMessage()
1668 static bool isOK = true;
1669 QString msg = validateListingsParameters();
1670 if (msg.isEmpty()) {
1674 // listingsTB->setTextColor("black");
1675 listingsModule->listingsTB->setPlainText(
1676 qt_("Input listings parameters below. "
1677 "Enter ? for a list of parameters."));
1680 // listingsTB->setTextColor("red");
1681 listingsModule->listingsTB->setPlainText(msg);
1686 void GuiDocument::listingsPackageChanged(int index)
1688 string const package = lst_packages[index];
1689 if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1690 Alert::warning(_("Pygments driver command not found!"),
1691 _("The driver command necessary to use the minted package\n"
1692 "(pygmentize) has not been found. Make sure you have\n"
1693 "the python-pygments module installed or, if the driver\n"
1694 "is named differently, to add the following line to the\n"
1695 "document preamble:\n\n"
1696 "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1697 "where 'driver' is name of the driver command."));
1702 void GuiDocument::setLSpacing(int item)
1704 textLayoutModule->lspacingLE->setEnabled(item == 3);
1708 void GuiDocument::setIndent(int item)
1710 bool const enable = (item == 1);
1711 textLayoutModule->indentLE->setEnabled(enable);
1712 textLayoutModule->indentLengthCO->setEnabled(enable);
1713 textLayoutModule->skipLE->setEnabled(false);
1714 textLayoutModule->skipLengthCO->setEnabled(false);
1719 void GuiDocument::enableIndent(bool indent)
1721 textLayoutModule->skipLE->setEnabled(!indent);
1722 textLayoutModule->skipLengthCO->setEnabled(!indent);
1724 setIndent(textLayoutModule->indentCO->currentIndex());
1728 void GuiDocument::setSkip(int item)
1730 bool const enable = (item == 3);
1731 textLayoutModule->skipLE->setEnabled(enable);
1732 textLayoutModule->skipLengthCO->setEnabled(enable);
1737 void GuiDocument::enableSkip(bool skip)
1739 textLayoutModule->indentLE->setEnabled(!skip);
1740 textLayoutModule->indentLengthCO->setEnabled(!skip);
1742 setSkip(textLayoutModule->skipCO->currentIndex());
1745 void GuiDocument::allowMathIndent() {
1746 // only disable when not checked, checked does not always allow enabling
1747 if (!mathsModule->MathIndentCB->isChecked()) {
1748 mathsModule->MathIndentLE->setEnabled(false);
1749 mathsModule->MathIndentLengthCO->setEnabled(false);
1751 if (mathsModule->MathIndentCB->isChecked()
1752 && mathsModule->MathIndentCO->currentIndex() == 1) {
1753 mathsModule->MathIndentLE->setEnabled(true);
1754 mathsModule->MathIndentLengthCO->setEnabled(true);
1759 void GuiDocument::enableMathIndent(int item)
1761 bool const enable = (item == 1);
1762 mathsModule->MathIndentLE->setEnabled(enable);
1763 mathsModule->MathIndentLengthCO->setEnabled(enable);
1768 void GuiDocument::setMargins()
1770 bool const extern_geometry =
1771 documentClass().provides("geometry");
1772 marginsModule->marginCB->setEnabled(!extern_geometry);
1773 if (extern_geometry) {
1774 marginsModule->marginCB->setChecked(false);
1775 setCustomMargins(true);
1777 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1778 setCustomMargins(!bp_.use_geometry);
1783 void GuiDocument::papersizeChanged(int paper_size)
1785 setCustomPapersize(paper_size == 1);
1789 void GuiDocument::setCustomPapersize(bool custom)
1791 pageLayoutModule->paperwidthL->setEnabled(custom);
1792 pageLayoutModule->paperwidthLE->setEnabled(custom);
1793 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1794 pageLayoutModule->paperheightL->setEnabled(custom);
1795 pageLayoutModule->paperheightLE->setEnabled(custom);
1796 pageLayoutModule->paperheightLE->setFocus();
1797 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1801 void GuiDocument::setColSep()
1803 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1807 void GuiDocument::setCustomMargins(bool custom)
1809 marginsModule->topL->setEnabled(!custom);
1810 marginsModule->topLE->setEnabled(!custom);
1811 marginsModule->topUnit->setEnabled(!custom);
1813 marginsModule->bottomL->setEnabled(!custom);
1814 marginsModule->bottomLE->setEnabled(!custom);
1815 marginsModule->bottomUnit->setEnabled(!custom);
1817 marginsModule->innerL->setEnabled(!custom);
1818 marginsModule->innerLE->setEnabled(!custom);
1819 marginsModule->innerUnit->setEnabled(!custom);
1821 marginsModule->outerL->setEnabled(!custom);
1822 marginsModule->outerLE->setEnabled(!custom);
1823 marginsModule->outerUnit->setEnabled(!custom);
1825 marginsModule->headheightL->setEnabled(!custom);
1826 marginsModule->headheightLE->setEnabled(!custom);
1827 marginsModule->headheightUnit->setEnabled(!custom);
1829 marginsModule->headsepL->setEnabled(!custom);
1830 marginsModule->headsepLE->setEnabled(!custom);
1831 marginsModule->headsepUnit->setEnabled(!custom);
1833 marginsModule->footskipL->setEnabled(!custom);
1834 marginsModule->footskipLE->setEnabled(!custom);
1835 marginsModule->footskipUnit->setEnabled(!custom);
1837 bool const enableColSep = !custom &&
1838 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1839 marginsModule->columnsepL->setEnabled(enableColSep);
1840 marginsModule->columnsepLE->setEnabled(enableColSep);
1841 marginsModule->columnsepUnit->setEnabled(enableColSep);
1845 void GuiDocument::changeBackgroundColor()
1847 QColor const & newColor = QColorDialog::getColor(
1848 rgb2qcolor(set_backgroundcolor), asQWidget());
1849 if (!newColor.isValid())
1851 // set the button color and text
1852 colorModule->backgroundPB->setStyleSheet(
1853 colorButtonStyleSheet(newColor));
1854 colorModule->backgroundPB->setText(qt_("&Change..."));
1856 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1857 is_backgroundcolor = true;
1862 void GuiDocument::deleteBackgroundColor()
1864 // set the button color back to default by setting an empty StyleSheet
1865 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1866 // change button text
1867 colorModule->backgroundPB->setText(qt_("&Default..."));
1868 // save default color (white)
1869 set_backgroundcolor = rgbFromHexName("#ffffff");
1870 is_backgroundcolor = false;
1875 void GuiDocument::changeFontColor()
1877 QColor const & newColor = QColorDialog::getColor(
1878 rgb2qcolor(set_fontcolor), asQWidget());
1879 if (!newColor.isValid())
1881 // set the button color and text
1882 colorModule->fontColorPB->setStyleSheet(
1883 colorButtonStyleSheet(newColor));
1884 colorModule->fontColorPB->setText(qt_("&Change..."));
1886 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1887 is_fontcolor = true;
1892 void GuiDocument::deleteFontColor()
1894 // set the button color back to default by setting an empty StyleSheet
1895 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1896 // change button text
1897 colorModule->fontColorPB->setText(qt_("&Default..."));
1898 // save default color (black)
1899 set_fontcolor = rgbFromHexName("#000000");
1900 is_fontcolor = false;
1905 void GuiDocument::changeNoteFontColor()
1907 QColor const & newColor = QColorDialog::getColor(
1908 rgb2qcolor(set_notefontcolor), asQWidget());
1909 if (!newColor.isValid())
1911 // set the button color
1912 colorModule->noteFontColorPB->setStyleSheet(
1913 colorButtonStyleSheet(newColor));
1915 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1920 void GuiDocument::deleteNoteFontColor()
1922 // set the button color back to pref
1923 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1924 colorModule->noteFontColorPB->setStyleSheet(
1925 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1930 void GuiDocument::changeBoxBackgroundColor()
1932 QColor const & newColor = QColorDialog::getColor(
1933 rgb2qcolor(set_boxbgcolor), asQWidget());
1934 if (!newColor.isValid())
1936 // set the button color
1937 colorModule->boxBackgroundPB->setStyleSheet(
1938 colorButtonStyleSheet(newColor));
1940 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1945 void GuiDocument::deleteBoxBackgroundColor()
1947 // set the button color back to pref
1948 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1949 colorModule->boxBackgroundPB->setStyleSheet(
1950 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1955 void GuiDocument::updateQuoteStyles(bool const set)
1957 Language const * lang = lyx::languages.getLanguage(
1958 fromqstr(langModule->languageCO->itemData(
1959 langModule->languageCO->currentIndex()).toString()));
1961 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1963 langModule->quoteStyleCO->clear();
1965 bool has_default = false;
1966 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1967 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1968 if (qs == InsetQuotesParams::DynamicQuotes)
1970 bool const langdef = (qs == def);
1972 // add the default style on top
1973 langModule->quoteStyleCO->insertItem(0,
1974 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1978 langModule->quoteStyleCO->addItem(
1979 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1981 if (set && has_default)
1982 // (re)set to the default style
1983 langModule->quoteStyleCO->setCurrentIndex(0);
1987 void GuiDocument::languageChanged(int i)
1989 // some languages only work with polyglossia
1990 Language const * lang = lyx::languages.getLanguage(
1991 fromqstr(langModule->languageCO->itemData(i).toString()));
1992 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1993 // If we force to switch fontspec on, store
1994 // current state (#8717)
1995 if (fontModule->osFontsCB->isEnabled())
1996 forced_fontspec_activation =
1997 !fontModule->osFontsCB->isChecked();
1998 fontModule->osFontsCB->setChecked(true);
1999 fontModule->osFontsCB->setEnabled(false);
2002 fontModule->osFontsCB->setEnabled(true);
2003 // If we have forced to switch fontspec on,
2004 // restore previous state (#8717)
2005 if (forced_fontspec_activation)
2006 fontModule->osFontsCB->setChecked(false);
2007 forced_fontspec_activation = false;
2010 // set appropriate quotation mark style
2011 updateQuoteStyles(true);
2015 void GuiDocument::osFontsChanged(bool nontexfonts)
2017 bool const tex_fonts = !nontexfonts;
2018 // store current fonts
2019 QString const font_roman = fontModule->fontsRomanCO->itemData(
2020 fontModule->fontsRomanCO->currentIndex()).toString();
2021 QString const font_sans = fontModule->fontsSansCO->itemData(
2022 fontModule->fontsSansCO->currentIndex()).toString();
2023 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2024 fontModule->fontsTypewriterCO->currentIndex()).toString();
2025 QString const font_math = fontModule->fontsMathCO->itemData(
2026 fontModule->fontsMathCO->currentIndex()).toString();
2027 int const font_sf_scale = fontModule->scaleSansSB->value();
2028 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2031 // store default format
2032 QString const dformat = outputModule->defaultFormatCO->itemData(
2033 outputModule->defaultFormatCO->currentIndex()).toString();
2034 updateDefaultFormat();
2035 // try to restore default format
2036 int index = outputModule->defaultFormatCO->findData(dformat);
2037 // set to default if format is not found
2040 outputModule->defaultFormatCO->setCurrentIndex(index);
2042 // try to restore fonts which were selected two toggles ago
2043 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2045 fontModule->fontsRomanCO->setCurrentIndex(index);
2046 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2048 fontModule->fontsSansCO->setCurrentIndex(index);
2049 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2051 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2052 index = fontModule->fontsMathCO->findData(fontModule->font_math);
2054 fontModule->fontsMathCO->setCurrentIndex(index);
2055 // save fonts for next next toggle
2056 fontModule->font_roman = font_roman;
2057 fontModule->font_sans = font_sans;
2058 fontModule->font_typewriter = font_typewriter;
2059 fontModule->font_math = font_math;
2060 fontModule->font_sf_scale = font_sf_scale;
2061 fontModule->font_tt_scale = font_tt_scale;
2063 langModule->encodingCO->setEnabled(tex_fonts &&
2064 !langModule->defaultencodingRB->isChecked());
2065 langModule->defaultencodingRB->setEnabled(tex_fonts);
2066 langModule->otherencodingRB->setEnabled(tex_fonts);
2068 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2069 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2070 fontModule->cjkFontLE->setEnabled(tex_fonts);
2071 fontModule->cjkFontLA->setEnabled(tex_fonts);
2073 updateFontOptions();
2075 fontModule->fontencLA->setEnabled(tex_fonts);
2076 fontModule->fontencCO->setEnabled(tex_fonts);
2078 fontModule->fontencLE->setEnabled(false);
2080 fontencChanged(fontModule->fontencCO->currentIndex());
2084 void GuiDocument::mathFontChanged(int)
2086 updateFontOptions();
2090 void GuiDocument::fontOsfToggled(bool state)
2092 if (fontModule->osFontsCB->isChecked())
2094 QString font = fontModule->fontsRomanCO->itemData(
2095 fontModule->fontsRomanCO->currentIndex()).toString();
2096 if (hasMonolithicExpertSet(font))
2097 fontModule->fontScCB->setChecked(state);
2101 void GuiDocument::fontScToggled(bool state)
2103 if (fontModule->osFontsCB->isChecked())
2105 QString font = fontModule->fontsRomanCO->itemData(
2106 fontModule->fontsRomanCO->currentIndex()).toString();
2107 if (hasMonolithicExpertSet(font))
2108 fontModule->fontOsfCB->setChecked(state);
2112 void GuiDocument::updateFontOptions()
2114 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2117 font = fontModule->fontsSansCO->itemData(
2118 fontModule->fontsSansCO->currentIndex()).toString();
2119 bool scaleable = providesScale(font);
2120 fontModule->scaleSansSB->setEnabled(scaleable);
2121 fontModule->scaleSansLA->setEnabled(scaleable);
2123 font = fontModule->fontsTypewriterCO->itemData(
2124 fontModule->fontsTypewriterCO->currentIndex()).toString();
2125 scaleable = providesScale(font);
2126 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2127 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2129 font = fontModule->fontsRomanCO->itemData(
2130 fontModule->fontsRomanCO->currentIndex()).toString();
2131 fontModule->fontScCB->setEnabled(providesSC(font));
2132 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2133 updateMathFonts(font);
2137 void GuiDocument::updateFontsize(string const & items, string const & sel)
2139 fontModule->fontsizeCO->clear();
2140 fontModule->fontsizeCO->addItem(qt_("Default"));
2142 for (int n = 0; !token(items,'|',n).empty(); ++n)
2143 fontModule->fontsizeCO->
2144 addItem(toqstr(token(items,'|',n)));
2146 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2147 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2148 fontModule->fontsizeCO->setCurrentIndex(n);
2155 bool GuiDocument::ot1() const
2157 QString const fontenc =
2158 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2159 return (fontenc == "default"
2160 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2161 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2165 bool GuiDocument::completeFontset() const
2167 return (fontModule->fontsSansCO->itemData(
2168 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2169 && fontModule->fontsSansCO->itemData(
2170 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2174 bool GuiDocument::noMathFont() const
2176 return (fontModule->fontsMathCO->itemData(
2177 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2181 void GuiDocument::updateTexFonts()
2183 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2185 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2186 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2187 for (; it != end; ++it) {
2188 LaTeXFont lf = it->second;
2189 if (lf.name().empty()) {
2190 LYXERR0("Error: Unnamed font: " << it->first);
2193 docstring const family = lf.family();
2194 docstring guiname = translateIfPossible(lf.guiname());
2195 if (!lf.available(ot1(), noMathFont()))
2196 guiname += _(" (not installed)");
2198 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2199 else if (family == "sf")
2200 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2201 else if (family == "tt")
2202 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2203 else if (family == "math")
2204 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2209 void GuiDocument::updateFontlist()
2211 fontModule->fontsRomanCO->clear();
2212 fontModule->fontsSansCO->clear();
2213 fontModule->fontsTypewriterCO->clear();
2214 fontModule->fontsMathCO->clear();
2216 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2217 if (fontModule->osFontsCB->isChecked()) {
2218 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2219 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2220 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2221 QString unimath = qt_("Non-TeX Fonts Default");
2222 if (!LaTeXFeatures::isAvailable("unicode-math"))
2223 unimath += qt_(" (not available)");
2224 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2225 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2227 QFontDatabase fontdb;
2228 QStringList families(fontdb.families());
2229 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2230 fontModule->fontsRomanCO->addItem(*it, *it);
2231 fontModule->fontsSansCO->addItem(*it, *it);
2232 fontModule->fontsTypewriterCO->addItem(*it, *it);
2237 if (rmfonts_.empty())
2240 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2241 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2242 while (rmi != rmfonts_.constEnd()) {
2243 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2247 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2248 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2249 while (sfi != sffonts_.constEnd()) {
2250 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2254 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2255 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2256 while (tti != ttfonts_.constEnd()) {
2257 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2261 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2262 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2263 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2264 while (mmi != mathfonts_.constEnd()) {
2265 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2271 void GuiDocument::fontencChanged(int item)
2273 fontModule->fontencLE->setEnabled(
2274 fontModule->fontencCO->itemData(item).toString() == "custom");
2275 // The availability of TeX fonts depends on the font encoding
2277 updateFontOptions();
2281 void GuiDocument::updateMathFonts(QString const & rm)
2283 if (fontModule->osFontsCB->isChecked())
2285 QString const math =
2286 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2287 int const i = fontModule->fontsMathCO->findData("default");
2288 if (providesNoMath(rm) && i == -1)
2289 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2290 else if (!providesNoMath(rm) && i != -1) {
2291 int const c = fontModule->fontsMathCO->currentIndex();
2292 fontModule->fontsMathCO->removeItem(i);
2294 fontModule->fontsMathCO->setCurrentIndex(0);
2299 void GuiDocument::romanChanged(int item)
2301 if (fontModule->osFontsCB->isChecked())
2303 QString const font =
2304 fontModule->fontsRomanCO->itemData(item).toString();
2305 fontModule->fontScCB->setEnabled(providesSC(font));
2306 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2307 updateMathFonts(font);
2311 void GuiDocument::sansChanged(int item)
2313 if (fontModule->osFontsCB->isChecked())
2315 QString const font =
2316 fontModule->fontsSansCO->itemData(item).toString();
2317 bool scaleable = providesScale(font);
2318 fontModule->scaleSansSB->setEnabled(scaleable);
2319 fontModule->scaleSansLA->setEnabled(scaleable);
2323 void GuiDocument::ttChanged(int item)
2325 if (fontModule->osFontsCB->isChecked())
2327 QString const font =
2328 fontModule->fontsTypewriterCO->itemData(item).toString();
2329 bool scaleable = providesScale(font);
2330 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2331 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2335 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2338 pageLayoutModule->pagestyleCO->clear();
2339 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2341 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2342 string style = token(items, '|', n);
2343 QString style_gui = qt_(style);
2344 pagestyles.push_back(pair<string, QString>(style, style_gui));
2345 pageLayoutModule->pagestyleCO->addItem(style_gui);
2348 if (sel == "default") {
2349 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2355 for (size_t i = 0; i < pagestyles.size(); ++i)
2356 if (pagestyles[i].first == sel)
2357 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2360 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2364 void GuiDocument::browseLayout()
2366 QString const label1 = qt_("Layouts|#o#O");
2367 QString const dir1 = toqstr(lyxrc.document_path);
2368 QStringList const filter(qt_("LyX Layout (*.layout)"));
2369 QString file = browseRelToParent(QString(), bufferFilePath(),
2370 qt_("Local layout file"), filter, false,
2373 if (!file.endsWith(".layout"))
2376 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2377 fromqstr(bufferFilePath()));
2379 int const ret = Alert::prompt(_("Local layout file"),
2380 _("The layout file you have selected is a local layout\n"
2381 "file, not one in the system or user directory.\n"
2382 "Your document will not work with this layout if you\n"
2383 "move the layout file to a different directory."),
2384 1, 1, _("&Set Layout"), _("&Cancel"));
2388 // load the layout file
2389 LayoutFileList & bcl = LayoutFileList::get();
2390 string classname = layoutFile.onlyFileName();
2391 // this will update an existing layout if that layout has been loaded before.
2392 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2393 classname.substr(0, classname.size() - 7),
2394 layoutFile.onlyPath().absFileName()));
2397 Alert::error(_("Error"),
2398 _("Unable to read local layout file."));
2402 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2404 // do not trigger classChanged if there is no change.
2405 if (latexModule->classCO->currentText() == toqstr(name))
2409 bool const avail = latexModule->classCO->set(toqstr(name));
2411 LayoutFile const & tc = bcl[name];
2412 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2413 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2414 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2415 tooltip += '\n' + qt_("This is a local layout file.");
2416 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2417 toqstr(translateIfPossible(from_utf8(tc.category()))),
2419 true, true, true, true);
2420 latexModule->classCO->set(toqstr(name));
2427 void GuiDocument::browseMaster()
2429 QString const title = qt_("Select master document");
2430 QString const dir1 = toqstr(lyxrc.document_path);
2431 QString const old = latexModule->childDocLE->text();
2432 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2433 QStringList const filter(qt_("LyX Files (*.lyx)"));
2434 QString file = browseRelToSub(old, docpath, title, filter, false,
2435 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2437 if (!file.isEmpty())
2438 latexModule->childDocLE->setText(file);
2442 void GuiDocument::classChanged_adaptor()
2444 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2449 void GuiDocument::classChanged()
2451 int idx = latexModule->classCO->currentIndex();
2454 string const classname = fromqstr(latexModule->classCO->getData(idx));
2456 if (applyPB->isEnabled()) {
2457 int const ret = Alert::prompt(_("Unapplied changes"),
2458 _("Some changes in the dialog were not yet applied.\n"
2459 "If you do not apply now, they will be lost after this action."),
2460 1, 1, _("&Apply"), _("&Dismiss"));
2465 // We load the TextClass as soon as it is selected. This is
2466 // necessary so that other options in the dialog can be updated
2467 // according to the new class. Note, however, that, if you use
2468 // the scroll wheel when sitting on the combo box, we'll load a
2469 // lot of TextClass objects very quickly....
2470 if (!bp_.setBaseClass(classname)) {
2471 Alert::error(_("Error"), _("Unable to set document class."));
2474 if (lyxrc.auto_reset_options)
2475 bp_.useClassDefaults();
2477 // With the introduction of modules came a distinction between the base
2478 // class and the document class. The former corresponds to the main layout
2479 // file; the latter is that plus the modules (or the document-specific layout,
2480 // or whatever else there could be). Our parameters come from the document
2481 // class. So when we set the base class, we also need to recreate the document
2482 // class. Otherwise, we still have the old one.
2483 bp_.makeDocumentClass();
2488 void GuiDocument::languagePackageChanged(int i)
2490 langModule->languagePackageLE->setEnabled(
2491 langModule->languagePackageCO->itemData(i).toString() == "custom");
2495 void GuiDocument::biblioChanged()
2497 biblioChanged_ = true;
2502 void GuiDocument::checkPossibleCiteEngines()
2504 // Check if the class provides a specific engine,
2505 // and if so, enforce this.
2506 string force_engine;
2507 if (documentClass().provides("natbib")
2508 || documentClass().provides("natbib-internal"))
2509 force_engine = "natbib";
2510 else if (documentClass().provides("jurabib"))
2511 force_engine = "jurabib";
2512 else if (documentClass().provides("biblatex"))
2513 force_engine = "biblatex";
2514 else if (documentClass().provides("biblatex-natbib"))
2515 force_engine = "biblatex-natbib";
2517 if (!force_engine.empty())
2518 biblioModule->citeEngineCO->setCurrentIndex(
2519 biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2520 biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2524 void GuiDocument::rescanBibFiles()
2527 rescanTexStyles("bbx cbx");
2529 rescanTexStyles("bst");
2533 void GuiDocument::resetDefaultBibfile(string const & which)
2535 QString const engine =
2536 biblioModule->citeEngineCO->itemData(
2537 biblioModule->citeEngineCO->currentIndex()).toString();
2539 CiteEngineType const cet =
2540 CiteEngineType(biblioModule->citeStyleCO->itemData(
2541 biblioModule->citeStyleCO->currentIndex()).toInt());
2543 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2547 void GuiDocument::resetDefaultBbxBibfile()
2549 resetDefaultBibfile("bbx");
2553 void GuiDocument::resetDefaultCbxBibfile()
2555 resetDefaultBibfile("cbx");
2559 void GuiDocument::citeEngineChanged(int n)
2561 QString const engine =
2562 biblioModule->citeEngineCO->itemData(n).toString();
2564 vector<string> const engs =
2565 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2567 updateCiteStyles(engs);
2568 updateEngineDependends();
2569 resetDefaultBibfile();
2574 void GuiDocument::updateEngineDependends()
2576 bool const biblatex = isBiblatex();
2578 // These are only useful with BibTeX
2579 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2580 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2581 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2582 biblioModule->bibtopicCB->setEnabled(!biblatex);
2584 // These are only useful with Biblatex
2585 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2586 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2587 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2588 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2589 biblioModule->resetBbxPB->setEnabled(biblatex);
2590 biblioModule->resetCbxPB->setEnabled(biblatex);
2591 biblioModule->matchBbxPB->setEnabled(biblatex);
2593 // These are useful with biblatex, jurabib and natbib
2594 QString const engine =
2595 biblioModule->citeEngineCO->itemData(
2596 biblioModule->citeEngineCO->currentIndex()).toString();
2597 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2599 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2600 || ce->requires("natbib.sty");
2601 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2602 biblioModule->citePackageOptionsL->setEnabled(citepack);
2606 void GuiDocument::citeStyleChanged()
2608 QString const engine =
2609 biblioModule->citeEngineCO->itemData(
2610 biblioModule->citeEngineCO->currentIndex()).toString();
2611 QString const currentDef = isBiblatex() ?
2612 biblioModule->biblatexBbxCO->currentText()
2613 : biblioModule->defaultBiblioCO->currentText();
2614 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2615 resetDefaultBibfile();
2621 void GuiDocument::bibtexChanged(int n)
2623 biblioModule->bibtexOptionsLE->setEnabled(
2624 biblioModule->bibtexCO->itemData(n).toString() != "default");
2629 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2631 biblioModule->citeStyleCO->clear();
2633 vector<string>::const_iterator it = engs.begin();
2634 vector<string>::const_iterator end = engs.end();
2635 for (; it != end; ++it) {
2636 if (*it == "default")
2637 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2638 ENGINE_TYPE_DEFAULT);
2639 else if (*it == "authoryear")
2640 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2641 ENGINE_TYPE_AUTHORYEAR);
2642 else if (*it == "numerical")
2643 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2644 ENGINE_TYPE_NUMERICAL);
2646 int i = biblioModule->citeStyleCO->findData(sel);
2647 if (biblioModule->citeStyleCO->findData(sel) == -1)
2649 biblioModule->citeStyleCO->setCurrentIndex(i);
2651 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2652 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2656 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2658 engine_types_.clear();
2662 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2664 string style = token(items, '|', n);
2665 engine_types_.push_back(style);
2668 updateCiteStyles(engine_types_, sel);
2674 // both of these should take a vector<docstring>
2676 // This is an insanely complicated attempt to make this sort of thing
2677 // work with RTL languages.
2678 docstring formatStrVec(vector<string> const & v, docstring const & s)
2680 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2684 return translateIfPossible(from_utf8(v[0]));
2685 if (v.size() == 2) {
2686 docstring retval = _("%1$s and %2$s");
2687 retval = subst(retval, _("and"), s);
2688 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2689 translateIfPossible(from_utf8(v[1])));
2691 // The idea here is to format all but the last two items...
2692 int const vSize = v.size();
2693 docstring t2 = _("%1$s, %2$s");
2694 docstring retval = translateIfPossible(from_utf8(v[0]));
2695 for (int i = 1; i < vSize - 2; ++i)
2696 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2697 //...and then to plug them, and the last two, into this schema
2698 docstring t = _("%1$s, %2$s, and %3$s");
2699 t = subst(t, _("and"), s);
2700 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2701 translateIfPossible(from_utf8(v[vSize - 1])));
2704 vector<string> idsToNames(vector<string> const & idList)
2706 vector<string> retval;
2707 vector<string>::const_iterator it = idList.begin();
2708 vector<string>::const_iterator end = idList.end();
2709 for (; it != end; ++it) {
2710 LyXModule const * const mod = theModuleList[*it];
2712 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2713 translateIfPossible(from_utf8(*it)))));
2715 retval.push_back(mod->getName());
2719 } // end anonymous namespace
2722 void GuiDocument::modulesToParams(BufferParams & bp)
2724 // update list of loaded modules
2725 bp.clearLayoutModules();
2726 int const srows = modules_sel_model_.rowCount();
2727 for (int i = 0; i < srows; ++i)
2728 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2730 // update the list of removed modules
2731 bp.clearRemovedModules();
2732 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2733 list<string>::const_iterator rit = reqmods.begin();
2734 list<string>::const_iterator ren = reqmods.end();
2736 // check each of the default modules
2737 for (; rit != ren; ++rit) {
2738 list<string>::const_iterator mit = bp.getModules().begin();
2739 list<string>::const_iterator men = bp.getModules().end();
2741 for (; mit != men; ++mit) {
2748 // the module isn't present so must have been removed by the user
2749 bp.addRemovedModule(*rit);
2754 void GuiDocument::modulesChanged()
2756 modulesToParams(bp_);
2758 if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2759 int const ret = Alert::prompt(_("Unapplied changes"),
2760 _("Some changes in the dialog were not yet applied.\n"
2761 "If you do not apply now, they will be lost after this action."),
2762 1, 1, _("&Apply"), _("&Dismiss"));
2767 modulesChanged_ = true;
2768 bp_.makeDocumentClass();
2774 void GuiDocument::updateModuleInfo()
2776 selectionManager->update();
2778 //Module description
2779 bool const focus_on_selected = selectionManager->selectedFocused();
2780 QAbstractItemView * lv;
2781 if (focus_on_selected)
2782 lv = modulesModule->selectedLV;
2784 lv = modulesModule->availableLV;
2785 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2786 modulesModule->infoML->document()->clear();
2789 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2790 GuiIdListModel const & id_model =
2791 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2792 string const modName = id_model.getIDString(idx.row());
2793 docstring desc = getModuleDescription(modName);
2795 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2796 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2799 desc += _("Module provided by document class.");
2802 docstring cat = getModuleCategory(modName);
2806 desc += bformat(_("Category: %1$s."), cat);
2809 vector<string> pkglist = getPackageList(modName);
2810 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2811 if (!pkgdesc.empty()) {
2814 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2817 pkglist = getRequiredList(modName);
2818 if (!pkglist.empty()) {
2819 vector<string> const reqdescs = idsToNames(pkglist);
2820 pkgdesc = formatStrVec(reqdescs, _("or"));
2823 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2826 pkglist = getExcludedList(modName);
2827 if (!pkglist.empty()) {
2828 vector<string> const reqdescs = idsToNames(pkglist);
2829 pkgdesc = formatStrVec(reqdescs, _( "and"));
2832 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2835 if (!isModuleAvailable(modName)) {
2838 desc += _("WARNING: Some required packages are unavailable!");
2841 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2845 void GuiDocument::updateNumbering()
2847 DocumentClass const & tclass = documentClass();
2849 numberingModule->tocTW->setUpdatesEnabled(false);
2850 numberingModule->tocTW->clear();
2852 int const depth = numberingModule->depthSL->value();
2853 int const toc = numberingModule->tocSL->value();
2854 QString const no = qt_("No");
2855 QString const yes = qt_("Yes");
2856 QTreeWidgetItem * item = 0;
2858 DocumentClass::const_iterator lit = tclass.begin();
2859 DocumentClass::const_iterator len = tclass.end();
2860 for (; lit != len; ++lit) {
2861 int const toclevel = lit->toclevel;
2862 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2863 item = new QTreeWidgetItem(numberingModule->tocTW);
2864 item->setText(0, toqstr(translateIfPossible(lit->name())));
2865 item->setText(1, (toclevel <= depth) ? yes : no);
2866 item->setText(2, (toclevel <= toc) ? yes : no);
2870 numberingModule->tocTW->setUpdatesEnabled(true);
2871 numberingModule->tocTW->update();
2875 void GuiDocument::updateDefaultFormat()
2879 // make a copy in order to consider unapplied changes
2880 BufferParams param_copy = buffer().params();
2881 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2882 int const idx = latexModule->classCO->currentIndex();
2884 string const classname = fromqstr(latexModule->classCO->getData(idx));
2885 param_copy.setBaseClass(classname);
2886 param_copy.makeDocumentClass(true);
2888 outputModule->defaultFormatCO->blockSignals(true);
2889 outputModule->defaultFormatCO->clear();
2890 outputModule->defaultFormatCO->addItem(qt_("Default"),
2891 QVariant(QString("default")));
2892 FormatList const & formats =
2893 param_copy.exportableFormats(true);
2894 for (Format const * f : formats)
2895 outputModule->defaultFormatCO->addItem
2896 (toqstr(translateIfPossible(f->prettyname())),
2897 QVariant(toqstr(f->name())));
2898 outputModule->defaultFormatCO->blockSignals(false);
2902 bool GuiDocument::isChildIncluded(string const & child)
2904 if (includeonlys_.empty())
2906 return (std::find(includeonlys_.begin(),
2907 includeonlys_.end(), child) != includeonlys_.end());
2911 void GuiDocument::applyView()
2914 preambleModule->apply(bp_);
2915 localLayout->apply(bp_);
2918 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2919 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2922 string const engine =
2923 fromqstr(biblioModule->citeEngineCO->itemData(
2924 biblioModule->citeEngineCO->currentIndex()).toString());
2925 bp_.setCiteEngine(engine);
2927 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2928 biblioModule->citeStyleCO->currentIndex()).toInt());
2929 if (theCiteEnginesList[engine]->hasEngineType(style))
2930 bp_.setCiteEngineType(style);
2932 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2934 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2936 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2937 biblioModule->bibunitsCO->currentIndex()).toString());
2939 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2941 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2942 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2943 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2945 string const bibtex_command =
2946 fromqstr(biblioModule->bibtexCO->itemData(
2947 biblioModule->bibtexCO->currentIndex()).toString());
2948 string const bibtex_options =
2949 fromqstr(biblioModule->bibtexOptionsLE->text());
2950 if (bibtex_command == "default" || bibtex_options.empty())
2951 bp_.bibtex_command = bibtex_command;
2953 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2955 if (biblioChanged_) {
2956 buffer().invalidateBibinfoCache();
2957 buffer().removeBiblioTempFiles();
2961 indicesModule->apply(bp_);
2963 // language & quotes
2964 if (langModule->defaultencodingRB->isChecked()) {
2965 bp_.inputenc = "auto";
2967 int i = langModule->encodingCO->currentIndex();
2969 bp_.inputenc = "default";
2971 QString const enc_gui =
2972 langModule->encodingCO->currentText();
2973 Encodings::const_iterator it = encodings.begin();
2974 Encodings::const_iterator const end = encodings.end();
2976 for (; it != end; ++it) {
2977 if (qt_(it->guiName()) == enc_gui &&
2979 bp_.inputenc = it->name();
2985 // should not happen
2986 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2987 bp_.inputenc = "default";
2992 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2993 langModule->quoteStyleCO->currentIndex()).toInt();
2994 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2996 QString const langname = langModule->languageCO->itemData(
2997 langModule->languageCO->currentIndex()).toString();
2998 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2999 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
3000 // If current cursor language was the document language, then update it too.
3001 if (cur.current_font.language() == bp_.language) {
3002 cur.current_font.setLanguage(newlang);
3003 cur.real_current_font.setLanguage(newlang);
3005 bp_.language = newlang;
3007 QString const pack = langModule->languagePackageCO->itemData(
3008 langModule->languagePackageCO->currentIndex()).toString();
3009 if (pack == "custom")
3011 fromqstr(langModule->languagePackageLE->text());
3013 bp_.lang_package = fromqstr(pack);
3016 bp_.backgroundcolor = set_backgroundcolor;
3017 bp_.isbackgroundcolor = is_backgroundcolor;
3018 bp_.fontcolor = set_fontcolor;
3019 bp_.isfontcolor = is_fontcolor;
3020 bp_.notefontcolor = set_notefontcolor;
3021 bp_.boxbgcolor = set_boxbgcolor;
3024 if (bp_.documentClass().hasTocLevels()) {
3025 bp_.tocdepth = numberingModule->tocSL->value();
3026 bp_.secnumdepth = numberingModule->depthSL->value();
3030 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3031 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3032 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3033 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3036 bp_.graphics_driver =
3037 tex_graphics[latexModule->psdriverCO->currentIndex()];
3040 int idx = latexModule->classCO->currentIndex();
3042 string const classname = fromqstr(latexModule->classCO->getData(idx));
3043 bp_.setBaseClass(classname);
3047 modulesToParams(bp_);
3050 map<string, string> const & packages = BufferParams::auto_packages();
3051 for (map<string, string>::const_iterator it = packages.begin();
3052 it != packages.end(); ++it) {
3053 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3056 int row = mathsModule->packagesTW->row(item);
3059 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3060 if (rb->isChecked()) {
3061 bp_.use_package(it->first, BufferParams::package_auto);
3064 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3065 if (rb->isChecked()) {
3066 bp_.use_package(it->first, BufferParams::package_on);
3069 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3070 if (rb->isChecked())
3071 bp_.use_package(it->first, BufferParams::package_off);
3073 // if math is indented
3074 bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3075 if (bp_.is_math_indent) {
3076 // if formulas are indented
3077 switch (mathsModule->MathIndentCO->currentIndex()) {
3079 bp_.setMathIndent(Length());
3082 Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3083 mathsModule->MathIndentLengthCO));
3084 bp_.setMathIndent(mathindent);
3088 // this should never happen
3089 bp_.setMathIndent(Length());
3093 switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3095 bp_.math_numbering_side = BufferParams::LEFT;
3098 bp_.math_numbering_side = BufferParams::DEFAULT;
3101 bp_.math_numbering_side = BufferParams::RIGHT;
3104 // this should never happen
3105 bp_.math_numbering_side = BufferParams::DEFAULT;
3110 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3111 bp_.pagestyle = "default";
3113 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3114 for (size_t i = 0; i != pagestyles.size(); ++i)
3115 if (pagestyles[i].second == style_gui)
3116 bp_.pagestyle = pagestyles[i].first;
3120 switch (textLayoutModule->lspacingCO->currentIndex()) {
3122 bp_.spacing().set(Spacing::Single);
3125 bp_.spacing().set(Spacing::Onehalf);
3128 bp_.spacing().set(Spacing::Double);
3131 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3133 bp_.spacing().set(Spacing::Single);
3135 bp_.spacing().set(Spacing::Other, s);
3140 if (textLayoutModule->twoColumnCB->isChecked())
3145 bp_.justification = textLayoutModule->justCB->isChecked();
3147 if (textLayoutModule->indentRB->isChecked()) {
3148 // if paragraphs are separated by an indentation
3149 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3150 switch (textLayoutModule->indentCO->currentIndex()) {
3152 bp_.setParIndent(Length());
3155 Length parindent(widgetsToLength(textLayoutModule->indentLE,
3156 textLayoutModule->indentLengthCO));
3157 bp_.setParIndent(parindent);
3161 // this should never happen
3162 bp_.setParIndent(Length());
3166 // if paragraphs are separated by a skip
3167 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3168 switch (textLayoutModule->skipCO->currentIndex()) {
3170 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3173 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3176 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3181 widgetsToLength(textLayoutModule->skipLE,
3182 textLayoutModule->skipLengthCO)
3188 // this should never happen
3189 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3195 fromqstr(latexModule->optionsLE->text());
3197 bp_.use_default_options =
3198 latexModule->defaultOptionsCB->isChecked();
3200 if (latexModule->childDocGB->isChecked())
3202 fromqstr(latexModule->childDocLE->text());
3204 bp_.master = string();
3207 bp_.clearIncludedChildren();
3208 if (masterChildModule->includeonlyRB->isChecked()) {
3209 list<string>::const_iterator it = includeonlys_.begin();
3210 for (; it != includeonlys_.end() ; ++it) {
3211 bp_.addIncludedChildren(*it);
3214 bp_.maintain_unincluded_children =
3215 masterChildModule->maintainAuxCB->isChecked();
3218 bp_.float_placement = floatModule->get();
3221 // text should have passed validation
3222 idx = listingsModule->packageCO->currentIndex();
3223 bp_.use_minted = string(lst_packages[idx]) == "Minted";
3224 bp_.listings_params =
3225 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3228 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3229 outputModule->defaultFormatCO->currentIndex()).toString());
3231 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3232 bp_.useNonTeXFonts = nontexfonts;
3234 bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3235 if (!bp_.shell_escape)
3236 theSession().shellescapeFiles().remove(buffer().absFileName());
3237 else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3238 theSession().shellescapeFiles().insert(buffer().absFileName());
3239 Buffer & buf = const_cast<Buffer &>(buffer());
3240 buf.params().shell_escape = bp_.shell_escape;
3242 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3244 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3246 int mathfmt = outputModule->mathoutCB->currentIndex();
3249 BufferParams::MathOutput const mo =
3250 static_cast<BufferParams::MathOutput>(mathfmt);
3251 bp_.html_math_output = mo;
3252 bp_.html_be_strict = outputModule->strictCB->isChecked();
3253 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3254 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3255 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3257 bp_.save_transient_properties =
3258 outputModule->saveTransientPropertiesCB->isChecked();
3261 bp_.fonts_roman[nontexfonts] =
3262 fromqstr(fontModule->fontsRomanCO->
3263 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3264 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3266 bp_.fonts_sans[nontexfonts] =
3267 fromqstr(fontModule->fontsSansCO->
3268 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3269 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3271 bp_.fonts_typewriter[nontexfonts] =
3272 fromqstr(fontModule->fontsTypewriterCO->
3273 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3274 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3276 bp_.fonts_math[nontexfonts] =
3277 fromqstr(fontModule->fontsMathCO->
3278 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3279 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3281 QString const fontenc =
3282 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3283 if (fontenc == "custom")
3284 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3286 bp_.fontenc = fromqstr(fontenc);
3289 fromqstr(fontModule->cjkFontLE->text());
3291 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3292 bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3294 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3295 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3297 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3298 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3300 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3302 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3305 bp_.fonts_default_family = "default";
3307 bp_.fonts_default_family = GuiDocument::fontfamilies[
3308 fontModule->fontsDefaultCO->currentIndex()];
3310 if (fontModule->fontsizeCO->currentIndex() == 0)
3311 bp_.fontsize = "default";
3314 fromqstr(fontModule->fontsizeCO->currentText());
3317 bp_.papersize = PAPER_SIZE(
3318 pageLayoutModule->papersizeCO->currentIndex());
3320 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3321 pageLayoutModule->paperwidthUnitCO);
3323 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3324 pageLayoutModule->paperheightUnitCO);
3326 if (pageLayoutModule->facingPagesCB->isChecked())
3327 bp_.sides = TwoSides;
3329 bp_.sides = OneSide;
3331 if (pageLayoutModule->landscapeRB->isChecked())
3332 bp_.orientation = ORIENTATION_LANDSCAPE;
3334 bp_.orientation = ORIENTATION_PORTRAIT;
3337 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3339 Ui::MarginsUi const * m = marginsModule;
3341 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3342 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3343 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3344 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3345 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3346 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3347 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3348 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3351 branchesModule->apply(bp_);
3354 PDFOptions & pdf = bp_.pdfoptions();
3355 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3356 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3357 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3358 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3359 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3361 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3362 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3363 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3364 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3366 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3367 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3368 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3369 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3371 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3372 if (pdfSupportModule->fullscreenCB->isChecked())
3373 pdf.pagemode = pdf.pagemode_fullscreen;
3375 pdf.pagemode.clear();
3376 pdf.quoted_options = pdf.quoted_options_check(
3377 fromqstr(pdfSupportModule->optionsLE->text()));
3380 nonModuleChanged_ = false;
3381 shellescapeChanged_ = false;
3385 void GuiDocument::paramsToDialog()
3387 // set the default unit
3388 Length::UNIT const default_unit = Length::defaultUnit();
3391 preambleModule->update(bp_, id());
3392 localLayout->update(bp_, id());
3395 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3396 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3399 string const cite_engine = bp_.citeEngine().list().front();
3401 biblioModule->citeEngineCO->setCurrentIndex(
3402 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3404 updateEngineType(documentClass().opt_enginetype(),
3405 bp_.citeEngineType());
3407 checkPossibleCiteEngines();
3409 biblioModule->citeStyleCO->setCurrentIndex(
3410 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3412 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3414 biblioModule->bibunitsCO->clear();
3415 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3416 if (documentClass().hasLaTeXLayout("part"))
3417 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3418 if (documentClass().hasLaTeXLayout("chapter"))
3419 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3420 if (documentClass().hasLaTeXLayout("section"))
3421 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3422 if (documentClass().hasLaTeXLayout("subsection"))
3423 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3424 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3426 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3428 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3430 biblioModule->bibunitsCO->setCurrentIndex(0);
3432 updateEngineDependends();
3435 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3436 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3438 updateDefaultBiblio(bp_.defaultBiblioStyle());
3440 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3444 split(bp_.bibtex_command, command, ' ');
3446 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3448 biblioModule->bibtexCO->setCurrentIndex(bpos);
3449 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3451 // We reset to default if we do not know the specified compiler
3452 // This is for security reasons
3453 biblioModule->bibtexCO->setCurrentIndex(
3454 biblioModule->bibtexCO->findData(toqstr("default")));
3455 biblioModule->bibtexOptionsLE->clear();
3457 biblioModule->bibtexOptionsLE->setEnabled(
3458 biblioModule->bibtexCO->currentIndex() != 0);
3460 biblioChanged_ = false;
3463 // We may be called when there is no Buffer, e.g., when
3464 // the last view has just been closed.
3465 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3466 indicesModule->update(bp_, isReadOnly);
3468 // language & quotes
3469 int const pos = langModule->languageCO->findData(toqstr(
3470 bp_.language->lang()));
3471 langModule->languageCO->setCurrentIndex(pos);
3473 updateQuoteStyles();
3475 langModule->quoteStyleCO->setCurrentIndex(
3476 langModule->quoteStyleCO->findData(bp_.quotes_style));
3477 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3479 bool default_enc = true;
3480 if (bp_.inputenc != "auto") {
3481 default_enc = false;
3482 if (bp_.inputenc == "default") {
3483 langModule->encodingCO->setCurrentIndex(0);
3486 Encodings::const_iterator it = encodings.begin();
3487 Encodings::const_iterator const end = encodings.end();
3488 for (; it != end; ++it) {
3489 if (it->name() == bp_.inputenc &&
3491 enc_gui = it->guiName();
3495 int const i = langModule->encodingCO->findText(
3498 langModule->encodingCO->setCurrentIndex(i);
3500 // unknown encoding. Set to default.
3504 langModule->defaultencodingRB->setChecked(default_enc);
3505 langModule->otherencodingRB->setChecked(!default_enc);
3507 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3509 langModule->languagePackageCO->setCurrentIndex(
3510 langModule->languagePackageCO->findData("custom"));
3511 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3513 langModule->languagePackageCO->setCurrentIndex(p);
3514 langModule->languagePackageLE->clear();
3518 if (bp_.isfontcolor) {
3519 colorModule->fontColorPB->setStyleSheet(
3520 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3522 set_fontcolor = bp_.fontcolor;
3523 is_fontcolor = bp_.isfontcolor;
3525 colorModule->noteFontColorPB->setStyleSheet(
3526 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3527 set_notefontcolor = bp_.notefontcolor;
3529 if (bp_.isbackgroundcolor) {
3530 colorModule->backgroundPB->setStyleSheet(
3531 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3533 set_backgroundcolor = bp_.backgroundcolor;
3534 is_backgroundcolor = bp_.isbackgroundcolor;
3536 colorModule->boxBackgroundPB->setStyleSheet(
3537 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3538 set_boxbgcolor = bp_.boxbgcolor;
3541 int const min_toclevel = documentClass().min_toclevel();
3542 int const max_toclevel = documentClass().max_toclevel();
3543 if (documentClass().hasTocLevels()) {
3544 numberingModule->setEnabled(true);
3545 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3546 numberingModule->depthSL->setMaximum(max_toclevel);
3547 numberingModule->depthSL->setValue(bp_.secnumdepth);
3548 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3549 numberingModule->tocSL->setMaximum(max_toclevel);
3550 numberingModule->tocSL->setValue(bp_.tocdepth);
3553 numberingModule->setEnabled(false);
3554 numberingModule->tocTW->clear();
3558 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3559 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3560 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3561 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3562 bulletsModule->init();
3565 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3567 latexModule->psdriverCO->setCurrentIndex(nitem);
3571 mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3572 if (bp_.is_math_indent) {
3573 Length const mathindent = bp_.getMathIndent();
3575 if (!mathindent.empty()) {
3576 lengthToWidgets(mathsModule->MathIndentLE,
3577 mathsModule->MathIndentLengthCO,
3578 mathindent, default_unit);
3581 mathsModule->MathIndentCO->setCurrentIndex(indent);
3582 enableMathIndent(indent);
3584 switch(bp_.math_numbering_side) {
3585 case BufferParams::LEFT:
3586 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3588 case BufferParams::DEFAULT:
3589 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3591 case BufferParams::RIGHT:
3592 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3595 map<string, string> const & packages = BufferParams::auto_packages();
3596 for (map<string, string>::const_iterator it = packages.begin();
3597 it != packages.end(); ++it) {
3598 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3601 int row = mathsModule->packagesTW->row(item);
3602 switch (bp_.use_package(it->first)) {
3603 case BufferParams::package_off: {
3605 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3606 rb->setChecked(true);
3609 case BufferParams::package_on: {
3611 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3612 rb->setChecked(true);
3615 case BufferParams::package_auto: {
3617 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3618 rb->setChecked(true);
3624 switch (bp_.spacing().getSpace()) {
3625 case Spacing::Other: nitem = 3; break;
3626 case Spacing::Double: nitem = 2; break;
3627 case Spacing::Onehalf: nitem = 1; break;
3628 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3632 string const & layoutID = bp_.baseClassID();
3633 setLayoutComboByIDString(layoutID);
3635 updatePagestyle(documentClass().opt_pagestyle(),
3638 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3639 if (bp_.spacing().getSpace() == Spacing::Other) {
3640 doubleToWidget(textLayoutModule->lspacingLE,
3641 bp_.spacing().getValueAsString());
3645 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3646 textLayoutModule->indentRB->setChecked(true);
3647 string parindent = bp_.getParIndent().asString();
3649 if (!parindent.empty()) {
3650 lengthToWidgets(textLayoutModule->indentLE,
3651 textLayoutModule->indentLengthCO,
3652 parindent, default_unit);
3655 textLayoutModule->indentCO->setCurrentIndex(indent);
3658 textLayoutModule->skipRB->setChecked(true);
3660 switch (bp_.getDefSkip().kind()) {
3661 case VSpace::SMALLSKIP:
3664 case VSpace::MEDSKIP:
3667 case VSpace::BIGSKIP:
3670 case VSpace::LENGTH:
3673 string const length = bp_.getDefSkip().asLyXCommand();
3674 lengthToWidgets(textLayoutModule->skipLE,
3675 textLayoutModule->skipLengthCO,
3676 length, default_unit);
3683 textLayoutModule->skipCO->setCurrentIndex(skip);
3687 textLayoutModule->twoColumnCB->setChecked(
3689 textLayoutModule->justCB->setChecked(bp_.justification);
3691 if (!bp_.options.empty()) {
3692 latexModule->optionsLE->setText(
3693 toqstr(bp_.options));
3695 latexModule->optionsLE->setText(QString());
3699 latexModule->defaultOptionsCB->setChecked(
3700 bp_.use_default_options);
3701 updateSelectedModules();
3702 selectionManager->updateProvidedModules(
3703 bp_.baseClass()->providedModules());
3704 selectionManager->updateExcludedModules(
3705 bp_.baseClass()->excludedModules());
3707 if (!documentClass().options().empty()) {
3708 latexModule->defaultOptionsLE->setText(
3709 toqstr(documentClass().options()));
3711 latexModule->defaultOptionsLE->setText(
3712 toqstr(_("[No options predefined]")));
3715 latexModule->defaultOptionsLE->setEnabled(
3716 bp_.use_default_options
3717 && !documentClass().options().empty());
3719 latexModule->defaultOptionsCB->setEnabled(
3720 !documentClass().options().empty());
3722 if (!bp_.master.empty()) {
3723 latexModule->childDocGB->setChecked(true);
3724 latexModule->childDocLE->setText(
3725 toqstr(bp_.master));
3727 latexModule->childDocLE->setText(QString());
3728 latexModule->childDocGB->setChecked(false);
3732 if (!bufferview() || !buffer().hasChildren()) {
3733 masterChildModule->childrenTW->clear();
3734 includeonlys_.clear();
3735 docPS->showPanel("Child Documents", false);
3736 if (docPS->isCurrentPanel("Child Documents"))
3737 docPS->setCurrentPanel("Document Class");
3739 docPS->showPanel("Child Documents", true);
3740 masterChildModule->setEnabled(true);
3741 includeonlys_ = bp_.getIncludedChildren();
3742 updateIncludeonlys();
3744 masterChildModule->maintainAuxCB->setChecked(
3745 bp_.maintain_unincluded_children);
3748 floatModule->set(bp_.float_placement);
3751 // break listings_params to multiple lines
3753 InsetListingsParams(bp_.listings_params).separatedParams();
3754 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3755 int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3757 listingsModule->packageCO->setCurrentIndex(nn);
3761 // some languages only work with polyglossia/XeTeX
3762 Language const * lang = lyx::languages.getLanguage(
3763 fromqstr(langModule->languageCO->itemData(
3764 langModule->languageCO->currentIndex()).toString()));
3765 bool const need_fontspec =
3766 lang->babel().empty() && !lang->polyglossia().empty();
3767 bool const os_fonts_available =
3768 bp_.baseClass()->outputType() == lyx::LATEX
3769 && LaTeXFeatures::isAvailable("fontspec");
3770 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3771 fontModule->osFontsCB->setChecked(
3772 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3773 updateFontsize(documentClass().opt_fontsize(),
3776 QString font = toqstr(bp_.fontsRoman());
3777 int rpos = fontModule->fontsRomanCO->findData(font);
3779 rpos = fontModule->fontsRomanCO->count();
3780 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3782 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3783 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3785 font = toqstr(bp_.fontsSans());
3786 int spos = fontModule->fontsSansCO->findData(font);
3788 spos = fontModule->fontsSansCO->count();
3789 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3791 fontModule->fontsSansCO->setCurrentIndex(spos);
3792 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3794 font = toqstr(bp_.fontsTypewriter());
3795 int tpos = fontModule->fontsTypewriterCO->findData(font);
3797 tpos = fontModule->fontsTypewriterCO->count();
3798 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3800 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3801 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3803 font = toqstr(bp_.fontsMath());
3804 int mpos = fontModule->fontsMathCO->findData(font);
3806 mpos = fontModule->fontsMathCO->count();
3807 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3809 fontModule->fontsMathCO->setCurrentIndex(mpos);
3810 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3812 if (bp_.useNonTeXFonts && os_fonts_available) {
3813 fontModule->fontencLA->setEnabled(false);
3814 fontModule->fontencCO->setEnabled(false);
3815 fontModule->fontencLE->setEnabled(false);
3817 fontModule->fontencLA->setEnabled(true);
3818 fontModule->fontencCO->setEnabled(true);
3819 fontModule->fontencLE->setEnabled(true);
3825 if (!bp_.fonts_cjk.empty())
3826 fontModule->cjkFontLE->setText(
3827 toqstr(bp_.fonts_cjk));
3829 fontModule->cjkFontLE->setText(QString());
3831 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3832 fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3834 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3835 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3836 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3837 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3838 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3839 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3841 nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3843 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3845 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3846 fontModule->fontencCO->setCurrentIndex(
3847 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3848 fontModule->fontencLE->setEnabled(false);
3850 fontModule->fontencCO->setCurrentIndex(1);
3851 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3855 // This must be set _after_ fonts since updateDefaultFormat()
3856 // checks osFontsCB settings.
3857 // update combobox with formats
3858 updateDefaultFormat();
3859 int index = outputModule->defaultFormatCO->findData(toqstr(
3860 bp_.default_output_format));
3861 // set to default if format is not found
3864 outputModule->defaultFormatCO->setCurrentIndex(index);
3866 outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3867 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3868 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3870 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3871 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3872 outputModule->strictCB->setChecked(bp_.html_be_strict);
3873 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3875 outputModule->saveTransientPropertiesCB
3876 ->setChecked(bp_.save_transient_properties);
3879 bool const extern_geometry =
3880 documentClass().provides("geometry");
3881 int const psize = bp_.papersize;
3882 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3883 setCustomPapersize(!extern_geometry && psize == 1);
3884 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3886 bool const landscape =
3887 bp_.orientation == ORIENTATION_LANDSCAPE;
3888 pageLayoutModule->landscapeRB->setChecked(landscape);
3889 pageLayoutModule->portraitRB->setChecked(!landscape);
3890 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3891 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3893 pageLayoutModule->facingPagesCB->setChecked(
3894 bp_.sides == TwoSides);
3896 lengthToWidgets(pageLayoutModule->paperwidthLE,
3897 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3898 lengthToWidgets(pageLayoutModule->paperheightLE,
3899 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3902 Ui::MarginsUi * m = marginsModule;
3906 lengthToWidgets(m->topLE, m->topUnit,
3907 bp_.topmargin, default_unit);
3909 lengthToWidgets(m->bottomLE, m->bottomUnit,
3910 bp_.bottommargin, default_unit);
3912 lengthToWidgets(m->innerLE, m->innerUnit,
3913 bp_.leftmargin, default_unit);
3915 lengthToWidgets(m->outerLE, m->outerUnit,
3916 bp_.rightmargin, default_unit);
3918 lengthToWidgets(m->headheightLE, m->headheightUnit,
3919 bp_.headheight, default_unit);
3921 lengthToWidgets(m->headsepLE, m->headsepUnit,
3922 bp_.headsep, default_unit);
3924 lengthToWidgets(m->footskipLE, m->footskipUnit,
3925 bp_.footskip, default_unit);
3927 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3928 bp_.columnsep, default_unit);
3931 updateUnknownBranches();
3932 branchesModule->update(bp_);
3935 PDFOptions const & pdf = bp_.pdfoptions();
3936 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3937 if (bp_.documentClass().provides("hyperref"))
3938 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3940 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3941 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3942 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3943 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3944 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3946 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3947 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3948 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3950 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3952 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3953 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3954 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3955 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3957 nn = findToken(backref_opts, pdf.backref);
3959 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3961 pdfSupportModule->fullscreenCB->setChecked
3962 (pdf.pagemode == pdf.pagemode_fullscreen);
3964 pdfSupportModule->optionsLE->setText(
3965 toqstr(pdf.quoted_options));
3967 // Make sure that the bc is in the INITIAL state
3968 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3971 // clear changed branches cache
3972 changedBranches_.clear();
3975 nonModuleChanged_ = false;
3976 shellescapeChanged_ = false;
3980 void GuiDocument::saveDocDefault()
3982 // we have to apply the params first
3988 void GuiDocument::updateAvailableModules()
3990 modules_av_model_.clear();
3991 list<modInfoStruct> modInfoList = getModuleInfo();
3992 // Sort names according to the locale
3993 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3994 return 0 < b.name.localeAwareCompare(a.name);
3997 for (modInfoStruct const & m : modInfoList) {
3998 modules_av_model_.insertRow(i, m.name, m.id, m.description);
4004 void GuiDocument::updateSelectedModules()
4006 modules_sel_model_.clear();
4007 list<modInfoStruct> const selModList = getSelectedModules();
4009 for (modInfoStruct const & m : selModList) {
4010 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4016 void GuiDocument::updateIncludeonlys()
4018 masterChildModule->childrenTW->clear();
4019 QString const no = qt_("No");
4020 QString const yes = qt_("Yes");
4022 if (includeonlys_.empty()) {
4023 masterChildModule->includeallRB->setChecked(true);
4024 masterChildModule->childrenTW->setEnabled(false);
4025 masterChildModule->maintainAuxCB->setEnabled(false);
4027 masterChildModule->includeonlyRB->setChecked(true);
4028 masterChildModule->childrenTW->setEnabled(true);
4029 masterChildModule->maintainAuxCB->setEnabled(true);
4031 ListOfBuffers children = buffer().getChildren();
4032 ListOfBuffers::const_iterator it = children.begin();
4033 ListOfBuffers::const_iterator end = children.end();
4034 bool has_unincluded = false;
4035 bool all_unincluded = true;
4036 for (; it != end; ++it) {
4037 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4040 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4041 from_utf8(buffer().filePath())));
4042 item->setText(0, toqstr(name));
4043 item->setText(1, isChildIncluded(name) ? yes : no);
4044 if (!isChildIncluded(name))
4045 has_unincluded = true;
4047 all_unincluded = false;
4049 // Both if all childs are included and if none is included
4050 // is equal to "include all" (i.e., omit \includeonly).
4051 // Thus, reset the GUI.
4052 if (!has_unincluded || all_unincluded) {
4053 masterChildModule->includeallRB->setChecked(true);
4054 masterChildModule->childrenTW->setEnabled(false);
4055 includeonlys_.clear();
4057 // If all are included, we need to update again.
4058 if (!has_unincluded)
4059 updateIncludeonlys();
4063 bool GuiDocument::isBiblatex() const
4065 QString const engine =
4066 biblioModule->citeEngineCO->itemData(
4067 biblioModule->citeEngineCO->currentIndex()).toString();
4069 // this can happen if the cite engine is unknown, which can happen
4070 // if one is using a file that came from someone else, etc. in that
4071 // case, we crash if we proceed.
4072 if (engine.isEmpty())
4075 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4079 void GuiDocument::updateDefaultBiblio(string const & style,
4080 string const & which)
4082 QString const bibstyle = toqstr(style);
4083 biblioModule->defaultBiblioCO->clear();
4088 if (which != "cbx") {
4089 // First the bbx styles
4090 biblioModule->biblatexBbxCO->clear();
4091 QStringList str = texFileList("bbxFiles.lst");
4092 // test whether we have a valid list, otherwise run rescan
4093 if (str.isEmpty()) {
4094 rescanTexStyles("bbx");
4095 str = texFileList("bbxFiles.lst");
4097 for (int i = 0; i != str.size(); ++i)
4098 str[i] = onlyFileName(str[i]);
4099 // sort on filename only (no path)
4102 for (int i = 0; i != str.count(); ++i) {
4103 QString item = changeExtension(str[i], "");
4104 if (item == bibstyle)
4106 biblioModule->biblatexBbxCO->addItem(item);
4109 if (item_nr == -1 && !bibstyle.isEmpty()) {
4110 biblioModule->biblatexBbxCO->addItem(bibstyle);
4111 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4115 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4117 biblioModule->biblatexBbxCO->clearEditText();
4120 if (which != "bbx") {
4121 // now the cbx styles
4122 biblioModule->biblatexCbxCO->clear();
4123 QStringList str = texFileList("cbxFiles.lst");
4124 // test whether we have a valid list, otherwise run rescan
4125 if (str.isEmpty()) {
4126 rescanTexStyles("cbx");
4127 str = texFileList("cbxFiles.lst");
4129 for (int i = 0; i != str.size(); ++i)
4130 str[i] = onlyFileName(str[i]);
4131 // sort on filename only (no path)
4134 for (int i = 0; i != str.count(); ++i) {
4135 QString item = changeExtension(str[i], "");
4136 if (item == bibstyle)
4138 biblioModule->biblatexCbxCO->addItem(item);
4141 if (item_nr == -1 && !bibstyle.isEmpty()) {
4142 biblioModule->biblatexCbxCO->addItem(bibstyle);
4143 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4147 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4149 biblioModule->biblatexCbxCO->clearEditText();
4152 biblioModule->biblatexBbxCO->clear();
4153 biblioModule->biblatexCbxCO->clear();
4154 QStringList str = texFileList("bstFiles.lst");
4155 // test whether we have a valid list, otherwise run rescan
4156 if (str.isEmpty()) {
4157 rescanTexStyles("bst");
4158 str = texFileList("bstFiles.lst");
4160 for (int i = 0; i != str.size(); ++i)
4161 str[i] = onlyFileName(str[i]);
4162 // sort on filename only (no path)
4165 for (int i = 0; i != str.count(); ++i) {
4166 QString item = changeExtension(str[i], "");
4167 if (item == bibstyle)
4169 biblioModule->defaultBiblioCO->addItem(item);
4172 if (item_nr == -1 && !bibstyle.isEmpty()) {
4173 biblioModule->defaultBiblioCO->addItem(bibstyle);
4174 item_nr = biblioModule->defaultBiblioCO->count() - 1;
4178 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4180 biblioModule->defaultBiblioCO->clearEditText();
4183 updateResetDefaultBiblio();
4187 void GuiDocument::updateResetDefaultBiblio()
4189 QString const engine =
4190 biblioModule->citeEngineCO->itemData(
4191 biblioModule->citeEngineCO->currentIndex()).toString();
4192 CiteEngineType const cet =
4193 CiteEngineType(biblioModule->citeStyleCO->itemData(
4194 biblioModule->citeStyleCO->currentIndex()).toInt());
4196 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4198 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4199 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4200 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4201 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4202 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4203 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4205 biblioModule->resetDefaultBiblioPB->setEnabled(
4206 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4210 void GuiDocument::matchBiblatexStyles()
4212 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4217 void GuiDocument::updateContents()
4219 // Nothing to do here as the document settings is not cursor dependant.
4224 void GuiDocument::useClassDefaults()
4226 if (applyPB->isEnabled()) {
4227 int const ret = Alert::prompt(_("Unapplied changes"),
4228 _("Some changes in the dialog were not yet applied.\n"
4229 "If you do not apply now, they will be lost after this action."),
4230 1, 1, _("&Apply"), _("&Dismiss"));
4235 int idx = latexModule->classCO->currentIndex();
4236 string const classname = fromqstr(latexModule->classCO->getData(idx));
4237 if (!bp_.setBaseClass(classname)) {
4238 Alert::error(_("Error"), _("Unable to set document class."));
4241 bp_.useClassDefaults();
4247 void GuiDocument::setLayoutComboByIDString(string const & idString)
4249 if (!latexModule->classCO->set(toqstr(idString)))
4250 Alert::warning(_("Can't set layout!"),
4251 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4255 bool GuiDocument::isValid()
4258 validateListingsParameters().isEmpty() &&
4259 localLayout->isValid() &&
4261 // if we're asking for skips between paragraphs
4262 !textLayoutModule->skipRB->isChecked() ||
4263 // then either we haven't chosen custom
4264 textLayoutModule->skipCO->currentIndex() != 3 ||
4265 // or else a length has been given
4266 !textLayoutModule->skipLE->text().isEmpty()
4269 // if we're asking for indentation
4270 !textLayoutModule->indentRB->isChecked() ||
4271 // then either we haven't chosen custom
4272 textLayoutModule->indentCO->currentIndex() != 1 ||
4273 // or else a length has been given
4274 !textLayoutModule->indentLE->text().isEmpty()
4277 // if we're asking for math indentation
4278 !mathsModule->MathIndentCB->isChecked() ||
4279 // then either we haven't chosen custom
4280 mathsModule->MathIndentCO->currentIndex() != 1 ||
4281 // or else a length has been given
4282 !mathsModule->MathIndentLE->text().isEmpty()
4287 char const * const GuiDocument::fontfamilies[5] = {
4288 "default", "rmdefault", "sfdefault", "ttdefault", ""
4292 char const * GuiDocument::fontfamilies_gui[5] = {
4293 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4297 bool GuiDocument::initialiseParams(string const &)
4299 BufferView const * view = bufferview();
4301 bp_ = BufferParams();
4305 bp_ = view->buffer().params();
4307 updateAvailableModules();
4308 //FIXME It'd be nice to make sure here that the selected
4309 //modules are consistent: That required modules are actually
4310 //selected, and that we don't have conflicts. If so, we could
4311 //at least pop up a warning.
4317 void GuiDocument::clearParams()
4319 bp_ = BufferParams();
4323 BufferId GuiDocument::id() const
4325 BufferView const * const view = bufferview();
4326 return view? &view->buffer() : 0;
4330 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4332 return moduleNames_;
4336 list<GuiDocument::modInfoStruct> const
4337 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4339 list<modInfoStruct> mInfo;
4340 for (string const & name : mods) {
4342 LyXModule const * const mod = theModuleList[name];
4347 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4355 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4357 return makeModuleInfo(params().getModules());
4361 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4363 return makeModuleInfo(params().baseClass()->providedModules());
4367 DocumentClass const & GuiDocument::documentClass() const
4369 return bp_.documentClass();
4373 static void dispatch_bufferparams(Dialog const & dialog,
4374 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4377 ss << "\\begin_header\n";
4378 bp.writeFile(ss, buf);
4379 ss << "\\end_header\n";
4380 dialog.dispatch(FuncRequest(lfun, ss.str()));
4384 void GuiDocument::dispatchParams()
4386 // We need a non-const buffer object.
4387 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4388 // There may be several undo records; group them (bug #8998)
4389 // This handles undo groups automagically
4390 UndoGroupHelper ugh(&buf);
4392 // This must come first so that a language change is correctly noticed
4395 // Apply the BufferParams. Note that this will set the base class
4396 // and then update the buffer's layout.
4397 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4399 if (!params().master.empty()) {
4400 FileName const master_file = support::makeAbsPath(params().master,
4401 support::onlyPath(buffer().absFileName()));
4402 if (isLyXFileName(master_file.absFileName())) {
4403 Buffer * master = checkAndLoadLyXFile(master_file);
4405 if (master->isChild(const_cast<Buffer *>(&buffer())))
4406 const_cast<Buffer &>(buffer()).setParent(master);
4408 Alert::warning(_("Assigned master does not include this file"),
4409 bformat(_("You must include this file in the document\n"
4410 "'%1$s' in order to use the master document\n"
4411 "feature."), from_utf8(params().master)));
4413 Alert::warning(_("Could not load master"),
4414 bformat(_("The master document '%1$s'\n"
4415 "could not be loaded."),
4416 from_utf8(params().master)));
4420 // Generate the colours requested by each new branch.
4421 BranchList & branchlist = params().branchlist();
4422 if (!branchlist.empty()) {
4423 BranchList::const_iterator it = branchlist.begin();
4424 BranchList::const_iterator const end = branchlist.end();
4425 for (; it != end; ++it) {
4426 docstring const & current_branch = it->branch();
4427 Branch const * branch = branchlist.find(current_branch);
4428 string const x11hexname = X11hexname(branch->color());
4429 // display the new color
4430 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4431 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4434 // rename branches in the document
4435 executeBranchRenaming();
4436 // and clear changed branches cache
4437 changedBranches_.clear();
4439 // Generate the colours requested by indices.
4440 IndicesList & indiceslist = params().indiceslist();
4441 if (!indiceslist.empty()) {
4442 IndicesList::const_iterator it = indiceslist.begin();
4443 IndicesList::const_iterator const end = indiceslist.end();
4444 for (; it != end; ++it) {
4445 docstring const & current_index = it->shortcut();
4446 Index const * index = indiceslist.findShortcut(current_index);
4447 string const x11hexname = X11hexname(index->color());
4448 // display the new color
4449 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4450 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4454 // If we used an LFUN, we would not need these two lines:
4455 BufferView * bv = const_cast<BufferView *>(bufferview());
4456 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4460 void GuiDocument::setLanguage() const
4462 Language const * const newL = bp_.language;
4463 if (buffer().params().language == newL)
4466 string const & lang_name = newL->lang();
4467 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4471 void GuiDocument::saveAsDefault() const
4473 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4477 bool GuiDocument::providesOSF(QString const & font) const
4479 if (fontModule->osFontsCB->isChecked())
4480 // FIXME: we should check if the fonts really
4481 // have OSF support. But how?
4483 return theLaTeXFonts().getLaTeXFont(
4484 qstring_to_ucs4(font)).providesOSF(ot1(),
4490 bool GuiDocument::providesSC(QString const & font) const
4492 if (fontModule->osFontsCB->isChecked())
4494 return theLaTeXFonts().getLaTeXFont(
4495 qstring_to_ucs4(font)).providesSC(ot1(),
4501 bool GuiDocument::providesScale(QString const & font) const
4503 if (fontModule->osFontsCB->isChecked())
4505 return theLaTeXFonts().getLaTeXFont(
4506 qstring_to_ucs4(font)).providesScale(ot1(),
4512 bool GuiDocument::providesNoMath(QString const & font) const
4514 if (fontModule->osFontsCB->isChecked())
4516 return theLaTeXFonts().getLaTeXFont(
4517 qstring_to_ucs4(font)).providesNoMath(ot1(),
4522 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4524 if (fontModule->osFontsCB->isChecked())
4526 return theLaTeXFonts().getLaTeXFont(
4527 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4534 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4536 // FIXME Unicode: docstrings would be better for these parameters but this
4537 // change requires a lot of others
4540 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4541 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4542 // Find the first sentence of the description
4543 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4544 int pos = bf.toNextBoundary();
4547 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4548 // Tooltip is the desc followed by the module name
4549 m.description = QString("%1<i>%2</i>")
4550 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4556 void GuiDocument::loadModuleInfo()
4558 moduleNames_.clear();
4559 for (LyXModule const & mod : theModuleList)
4560 if (mod.category().substr(0, 8) != "Citation")
4561 moduleNames_.push_back(modInfo(mod));
4565 void GuiDocument::updateUnknownBranches()
4569 list<docstring> used_branches;
4570 buffer().getUsedBranches(used_branches);
4571 list<docstring>::const_iterator it = used_branches.begin();
4572 QStringList unknown_branches;
4573 for (; it != used_branches.end() ; ++it) {
4574 if (!buffer().params().branchlist().find(*it))
4575 unknown_branches.append(toqstr(*it));
4577 branchesModule->setUnknownBranches(unknown_branches);
4581 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4583 map<docstring, docstring>::iterator it = changedBranches_.begin();
4584 for (; it != changedBranches_.end() ; ++it) {
4585 if (it->second == oldname) {
4586 // branch has already been renamed
4587 it->second = newname;
4592 changedBranches_[oldname] = newname;
4596 void GuiDocument::executeBranchRenaming() const
4598 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4599 for (; it != changedBranches_.end() ; ++it) {
4600 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4601 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4606 void GuiDocument::allPackagesAuto()
4612 void GuiDocument::allPackagesAlways()
4618 void GuiDocument::allPackagesNot()
4624 void GuiDocument::allPackages(int col)
4626 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4628 (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4629 rb->setChecked(true);
4634 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4637 } // namespace frontend
4640 #include "moc_GuiDocument.cpp"