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"
42 #include "IndicesList.h"
44 #include "LaTeXFeatures.h"
45 #include "LaTeXFonts.h"
47 #include "LayoutEnums.h"
48 #include "LayoutModuleList.h"
50 #include "ModuleList.h"
51 #include "OutputParams.h"
52 #include "PDFOptions.h"
53 #include "qt_helpers.h"
55 #include "TextClass.h"
59 #include "insets/InsetListingsParams.h"
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
68 #include "frontends/alert.h"
70 #include <QAbstractItemModel>
71 #include <QHeaderView>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
77 #include <QTextBoundaryFinder>
78 #include <QTextCursor>
88 // a style sheet for buttons
89 // this is for example used for the background color setting button
90 static inline QString colorButtonStyleSheet(QColor const & bgColor)
92 if (bgColor.isValid()) {
93 QString rc = QLatin1String("background-color:");
102 using namespace lyx::support;
107 char const * const tex_graphics[] =
109 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
110 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
111 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
112 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
117 char const * const tex_graphics_gui[] =
119 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
120 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
121 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
122 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
123 "XeTeX", N_("None"), ""
127 char const * backref_opts[] =
129 "false", "section", "slide", "page", ""
133 char const * backref_opts_gui[] =
135 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
139 vector<string> engine_types_;
140 vector<pair<string, QString> > pagestyles;
142 QMap<QString, QString> rmfonts_;
143 QMap<QString, QString> sffonts_;
144 QMap<QString, QString> ttfonts_;
145 QMap<QString, QString> mathfonts_;
148 } // anonymous namespace
152 RGBColor set_backgroundcolor;
153 bool is_backgroundcolor;
154 RGBColor set_fontcolor;
156 RGBColor set_notefontcolor;
157 RGBColor set_boxbgcolor;
158 bool forced_fontspec_activation;
161 // used when sorting the textclass list.
162 class less_textclass_avail_desc
163 : public binary_function<string, string, int>
166 bool operator()(string const & lhs, string const & rhs) const
168 // Ordering criteria:
169 // 1. Availability of text class
170 // 2. Description (lexicographic)
171 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
172 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
173 int const order = compare_no_case(
174 translateIfPossible(from_utf8(tc1.description())),
175 translateIfPossible(from_utf8(tc2.description())));
176 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
177 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
186 vector<string> getRequiredList(string const & modName)
188 LyXModule const * const mod = theModuleList[modName];
190 return vector<string>(); //empty such thing
191 return mod->getRequiredModules();
195 vector<string> getExcludedList(string const & modName)
197 LyXModule const * const mod = theModuleList[modName];
199 return vector<string>(); //empty such thing
200 return mod->getExcludedModules();
204 docstring getModuleCategory(string const & modName)
206 LyXModule const * const mod = theModuleList[modName];
209 return from_utf8(mod->category());
213 docstring getModuleDescription(string const & modName)
215 LyXModule const * const mod = theModuleList[modName];
217 return _("Module not found!");
219 return translateIfPossible(from_utf8(mod->getDescription()));
223 vector<string> getPackageList(string const & modName)
225 LyXModule const * const mod = theModuleList[modName];
227 return vector<string>(); //empty such thing
228 return mod->getPackageList();
232 bool isModuleAvailable(string const & modName)
234 LyXModule const * const mod = theModuleList[modName];
237 return mod->isAvailable();
240 } // anonymous namespace
243 /////////////////////////////////////////////////////////////////////
245 // ModuleSelectionManager
247 /////////////////////////////////////////////////////////////////////
249 /// SelectionManager for use with modules
250 class ModuleSelectionManager : public GuiSelectionManager
254 ModuleSelectionManager(QObject * parent,
255 QTreeView * availableLV,
256 QListView * selectedLV,
260 QPushButton * downPB,
261 GuiIdListModel * availableModel,
262 GuiIdListModel * selectedModel,
263 GuiDocument const * container)
264 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
265 upPB, downPB, availableModel, selectedModel),
266 container_(container)
269 void updateProvidedModules(LayoutModuleList const & pm)
270 { provided_modules_ = pm.list(); }
272 void updateExcludedModules(LayoutModuleList const & em)
273 { excluded_modules_ = em.list(); }
276 virtual void updateAddPB();
278 virtual void updateUpPB();
280 virtual void updateDownPB();
282 virtual void updateDelPB();
283 /// returns availableModel as a GuiIdListModel
284 GuiIdListModel * getAvailableModel()
286 return dynamic_cast<GuiIdListModel *>(availableModel);
288 /// returns selectedModel as a GuiIdListModel
289 GuiIdListModel * getSelectedModel()
291 return dynamic_cast<GuiIdListModel *>(selectedModel);
293 /// keeps a list of the modules the text class provides
294 list<string> provided_modules_;
296 list<string> excluded_modules_;
298 GuiDocument const * container_;
301 void ModuleSelectionManager::updateAddPB()
303 int const arows = availableModel->rowCount();
304 QModelIndexList const avail_sels =
305 availableLV->selectionModel()->selectedIndexes();
307 // disable if there aren't any modules (?), if none of them is chosen
308 // in the dialog, or if the chosen one is already selected for use.
309 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
310 addPB->setEnabled(false);
314 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
315 string const modname = getAvailableModel()->getIDString(idx.row());
318 container_->params().layoutModuleCanBeAdded(modname);
319 addPB->setEnabled(enable);
323 void ModuleSelectionManager::updateDownPB()
325 int const srows = selectedModel->rowCount();
327 downPB->setEnabled(false);
330 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
331 int const curRow = curidx.row();
332 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
333 downPB->setEnabled(false);
337 // determine whether immediately succeding element requires this one
338 string const curmodname = getSelectedModel()->getIDString(curRow);
339 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
341 vector<string> reqs = getRequiredList(nextmodname);
343 // if it doesn't require anything....
345 downPB->setEnabled(true);
349 // Enable it if this module isn't required.
350 // FIXME This should perhaps be more flexible and check whether, even
351 // if the next one is required, there is also an earlier one that will do.
353 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
356 void ModuleSelectionManager::updateUpPB()
358 int const srows = selectedModel->rowCount();
360 upPB->setEnabled(false);
364 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
365 int curRow = curIdx.row();
366 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
367 upPB->setEnabled(false);
370 string const curmodname = getSelectedModel()->getIDString(curRow);
372 // determine whether immediately preceding element is required by this one
373 vector<string> reqs = getRequiredList(curmodname);
375 // if this one doesn't require anything....
377 upPB->setEnabled(true);
382 // Enable it if the preceding module isn't required.
383 // NOTE This is less flexible than it might be. We could check whether, even
384 // if the previous one is required, there is an earlier one that would do.
385 string const premod = getSelectedModel()->getIDString(curRow - 1);
386 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
389 void ModuleSelectionManager::updateDelPB()
391 int const srows = selectedModel->rowCount();
393 deletePB->setEnabled(false);
397 QModelIndex const & curidx =
398 selectedLV->selectionModel()->currentIndex();
399 int const curRow = curidx.row();
400 if (curRow < 0 || curRow >= srows) { // invalid index?
401 deletePB->setEnabled(false);
405 string const curmodname = getSelectedModel()->getIDString(curRow);
407 // We're looking here for a reason NOT to enable the button. If we
408 // find one, we disable it and return. If we don't, we'll end up at
409 // the end of the function, and then we enable it.
410 for (int i = curRow + 1; i < srows; ++i) {
411 string const thisMod = getSelectedModel()->getIDString(i);
412 vector<string> reqs = getRequiredList(thisMod);
413 //does this one require us?
414 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
418 // OK, so this module requires us
419 // is there an EARLIER module that also satisfies the require?
420 // NOTE We demand that it be earlier to keep the list of modules
421 // consistent with the rule that a module must be proceeded by a
422 // required module. There would be more flexible ways to proceed,
423 // but that would be a lot more complicated, and the logic here is
424 // already complicated. (That's why I've left the debugging code.)
425 // lyxerr << "Testing " << thisMod << endl;
426 bool foundone = false;
427 for (int j = 0; j < curRow; ++j) {
428 string const mod = getSelectedModel()->getIDString(j);
429 // lyxerr << "In loop: Testing " << mod << endl;
430 // do we satisfy the require?
431 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
432 // lyxerr << mod << " does the trick." << endl;
437 // did we find a module to satisfy the require?
439 // lyxerr << "No matching module found." << endl;
440 deletePB->setEnabled(false);
444 // lyxerr << "All's well that ends well." << endl;
445 deletePB->setEnabled(true);
449 /////////////////////////////////////////////////////////////////////
453 /////////////////////////////////////////////////////////////////////
455 PreambleModule::PreambleModule(QWidget * parent)
456 : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
458 // This is not a memory leak. The object will be destroyed
460 // @ is letter in the LyX user preamble
461 (void) new LaTeXHighlighter(preambleTE->document(), true);
462 preambleTE->setFont(guiApp->typewriterSystemFont());
463 preambleTE->setWordWrapMode(QTextOption::NoWrap);
464 setFocusProxy(preambleTE);
465 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
469 void PreambleModule::update(BufferParams const & params, BufferId id)
471 QString preamble = toqstr(params.preamble);
472 // Nothing to do if the params and preamble are unchanged.
473 if (id == current_id_
474 && preamble == preambleTE->document()->toPlainText())
477 QTextCursor cur = preambleTE->textCursor();
478 // Save the coords before switching to the new one.
479 preamble_coords_[current_id_] =
480 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
482 // Save the params address for further use.
484 preambleTE->document()->setPlainText(preamble);
485 Coords::const_iterator it = preamble_coords_.find(current_id_);
486 if (it == preamble_coords_.end())
487 // First time we open this one.
488 preamble_coords_[current_id_] = make_pair(0, 0);
490 // Restore saved coords.
491 QTextCursor cur = preambleTE->textCursor();
492 cur.setPosition(it->second.first);
493 preambleTE->setTextCursor(cur);
494 preambleTE->verticalScrollBar()->setValue(it->second.second);
499 void PreambleModule::apply(BufferParams & params)
501 params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
505 void PreambleModule::closeEvent(QCloseEvent * e)
507 // Save the coords before closing.
508 QTextCursor cur = preambleTE->textCursor();
509 preamble_coords_[current_id_] =
510 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
515 /////////////////////////////////////////////////////////////////////
519 /////////////////////////////////////////////////////////////////////
522 LocalLayout::LocalLayout(QWidget * parent)
523 : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
525 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
526 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
527 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
531 void LocalLayout::update(BufferParams const & params, BufferId id)
533 QString layout = toqstr(params.getLocalLayout(false));
534 // Nothing to do if the params and preamble are unchanged.
535 if (id == current_id_
536 && layout == locallayoutTE->document()->toPlainText())
539 // Save the params address for further use.
541 locallayoutTE->document()->setPlainText(layout);
546 void LocalLayout::apply(BufferParams & params)
548 docstring const layout =
549 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
550 params.setLocalLayout(layout, false);
554 void LocalLayout::hideConvert()
556 convertPB->setEnabled(false);
557 convertLB->setText("");
563 void LocalLayout::textChanged()
565 static const QString message =
566 qt_("Press button to check validity...");
567 string const layout =
568 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
570 if (layout.empty()) {
572 validatePB->setEnabled(false);
573 validLB->setText("");
576 } else if (!validatePB->isEnabled()) {
577 // if that's already enabled, we shouldn't need to do anything.
579 validLB->setText(message);
580 validatePB->setEnabled(true);
587 void LocalLayout::convert() {
588 string const layout =
589 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
590 string const newlayout = TextClass::convert(layout);
591 if (!newlayout.empty())
592 locallayoutTE->setPlainText(toqstr(newlayout));
597 void LocalLayout::convertPressed() {
604 void LocalLayout::validate() {
606 static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
607 // Flashy red bold text
608 static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
610 string const layout =
611 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
612 if (!layout.empty()) {
613 TextClass::ReturnValues const ret = TextClass::validate(layout);
614 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
615 validatePB->setEnabled(false);
616 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
617 : ivpar.arg(qt_("Layout is invalid!")));
618 if (ret == TextClass::OK_OLDFORMAT) {
620 // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
622 if (TextClass::convert(layout).empty()) {
623 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
624 // then maybe the layout is still valid, but its format is more
625 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
626 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
627 convertPB->setEnabled(false);
628 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
629 ? ivpar.arg(qt_("Conversion to current format impossible!"))
630 : vpar.arg(qt_("Conversion to current stable format "
632 convertLB->setText(text);
634 convertPB->setEnabled(true);
635 convertLB->setText(qt_("Convert to current format"));
646 void LocalLayout::validatePressed() {
652 /////////////////////////////////////////////////////////////////////
656 /////////////////////////////////////////////////////////////////////
659 GuiDocument::GuiDocument(GuiView & lv)
660 : GuiDialog(lv, "document", qt_("Document Settings")),
661 biblioChanged_(false), nonModuleChanged_(false)
665 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
666 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
667 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
668 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
670 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
671 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
673 // Manage the restore, ok, apply, restore and cancel/close buttons
674 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
676 bc().setApply(applyPB);
677 bc().setCancel(closePB);
678 bc().setRestore(restorePB);
682 textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
683 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
684 this, SLOT(change_adaptor()));
685 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
686 this, SLOT(setLSpacing(int)));
687 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
688 this, SLOT(change_adaptor()));
690 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
691 this, SLOT(change_adaptor()));
692 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
693 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
694 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
695 this, SLOT(change_adaptor()));
696 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
697 this, SLOT(setIndent(int)));
698 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
699 this, SLOT(change_adaptor()));
700 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
701 this, SLOT(change_adaptor()));
703 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
704 this, SLOT(change_adaptor()));
705 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
706 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
707 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
708 this, SLOT(change_adaptor()));
709 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
710 this, SLOT(setSkip(int)));
711 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
712 this, SLOT(change_adaptor()));
713 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
714 this, SLOT(change_adaptor()));
716 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
717 this, SLOT(enableIndent(bool)));
718 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
719 this, SLOT(enableSkip(bool)));
721 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
722 this, SLOT(change_adaptor()));
723 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
724 this, SLOT(setColSep()));
725 connect(textLayoutModule->justCB, SIGNAL(clicked()),
726 this, SLOT(change_adaptor()));
728 connect(textLayoutModule->MathIndentCB, SIGNAL(toggled(bool)),
729 this, SLOT(change_adaptor()));
730 connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
731 this, SLOT(change_adaptor()));
732 connect(textLayoutModule->MathIndentCO, SIGNAL(activated(int)),
733 this, SLOT(setMathIndent(int)));
734 connect(textLayoutModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
735 this, SLOT(change_adaptor()));
736 connect(textLayoutModule->MathIndentLengthCO, SIGNAL(activated(int)),
737 this, SLOT(change_adaptor()));
740 textLayoutModule->MathIndentCO->addItem(qt_("Default"));
741 textLayoutModule->MathIndentCO->addItem(qt_("Custom"));
742 textLayoutModule->MathIndentLE->setValidator(new LengthValidator(
743 textLayoutModule->MathIndentLE));
744 // initialize the length validator
745 bc().addCheckedLineEdit(textLayoutModule->MathIndentLE);
747 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
748 textLayoutModule->lspacingLE));
749 textLayoutModule->indentLE->setValidator(new LengthValidator(
750 textLayoutModule->indentLE));
751 textLayoutModule->skipLE->setValidator(new LengthValidator(
752 textLayoutModule->skipLE));
754 textLayoutModule->indentCO->addItem(qt_("Default"));
755 textLayoutModule->indentCO->addItem(qt_("Custom"));
756 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
757 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
758 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
759 textLayoutModule->skipCO->addItem(qt_("Custom"));
760 textLayoutModule->lspacingCO->insertItem(
761 Spacing::Single, qt_("Single"));
762 textLayoutModule->lspacingCO->insertItem(
763 Spacing::Onehalf, qt_("OneHalf"));
764 textLayoutModule->lspacingCO->insertItem(
765 Spacing::Double, qt_("Double"));
766 textLayoutModule->lspacingCO->insertItem(
767 Spacing::Other, qt_("Custom"));
768 // initialize the length validator
769 bc().addCheckedLineEdit(textLayoutModule->indentLE);
770 bc().addCheckedLineEdit(textLayoutModule->skipLE);
773 // master/child handling
774 masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
776 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
777 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
778 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
779 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
780 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
781 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
782 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
783 this, SLOT(change_adaptor()));
784 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
785 this, SLOT(change_adaptor()));
786 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
787 this, SLOT(change_adaptor()));
788 masterChildModule->childrenTW->setColumnCount(2);
789 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
790 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
791 masterChildModule->childrenTW->resizeColumnToContents(1);
792 masterChildModule->childrenTW->resizeColumnToContents(2);
796 outputModule = new UiWidget<Ui::OutputUi>(this);
798 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
799 this, SLOT(change_adaptor()));
800 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
801 this, SLOT(change_adaptor()));
802 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
803 this, SLOT(change_adaptor()));
804 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
805 this, SLOT(change_adaptor()));
806 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
807 this, SLOT(change_adaptor()));
809 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
810 this, SLOT(change_adaptor()));
811 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
812 this, SLOT(change_adaptor()));
813 outputModule->synccustomCB->addItem("");
814 outputModule->synccustomCB->addItem("\\synctex=1");
815 outputModule->synccustomCB->addItem("\\synctex=-1");
816 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
818 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
819 outputModule->synccustomCB));
821 connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
822 this, SLOT(change_adaptor()));
825 fontModule = new FontModule(this);
826 connect(fontModule->osFontsCB, SIGNAL(clicked()),
827 this, SLOT(change_adaptor()));
828 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
829 this, SLOT(osFontsChanged(bool)));
830 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
831 this, SLOT(change_adaptor()));
832 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
833 this, SLOT(romanChanged(int)));
834 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
835 this, SLOT(change_adaptor()));
836 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
837 this, SLOT(sansChanged(int)));
838 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
839 this, SLOT(change_adaptor()));
840 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
841 this, SLOT(ttChanged(int)));
842 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
843 this, SLOT(change_adaptor()));
844 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
845 this, SLOT(mathFontChanged(int)));
846 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
847 this, SLOT(change_adaptor()));
848 connect(fontModule->fontencCO, SIGNAL(activated(int)),
849 this, SLOT(change_adaptor()));
850 connect(fontModule->fontencCO, SIGNAL(activated(int)),
851 this, SLOT(fontencChanged(int)));
852 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
853 this, SLOT(change_adaptor()));
854 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
855 this, SLOT(change_adaptor()));
856 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
857 this, SLOT(change_adaptor()));
858 connect(fontModule->microtypeCB, SIGNAL(clicked()),
859 this, SLOT(change_adaptor()));
860 connect(fontModule->dashesCB, SIGNAL(clicked()),
861 this, SLOT(change_adaptor()));
862 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
863 this, SLOT(change_adaptor()));
864 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
865 this, SLOT(change_adaptor()));
866 connect(fontModule->fontScCB, SIGNAL(clicked()),
867 this, SLOT(change_adaptor()));
868 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
869 this, SLOT(fontScToggled(bool)));
870 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
871 this, SLOT(change_adaptor()));
872 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
873 this, SLOT(fontOsfToggled(bool)));
875 fontModule->fontencLE->setValidator(new NoNewLineValidator(
876 fontModule->fontencLE));
877 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
878 fontModule->cjkFontLE));
882 fontModule->fontsizeCO->addItem(qt_("Default"));
883 fontModule->fontsizeCO->addItem(qt_("10"));
884 fontModule->fontsizeCO->addItem(qt_("11"));
885 fontModule->fontsizeCO->addItem(qt_("12"));
887 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
888 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
889 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
891 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
892 fontModule->fontsDefaultCO->addItem(
893 qt_(GuiDocument::fontfamilies_gui[n]));
895 if (!LaTeXFeatures::isAvailable("fontspec"))
896 fontModule->osFontsCB->setToolTip(
897 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
898 "You need to install the package \"fontspec\" to use this feature"));
902 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
903 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
904 this, SLOT(papersizeChanged(int)));
905 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
906 this, SLOT(papersizeChanged(int)));
907 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
908 this, SLOT(change_adaptor()));
909 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
910 this, SLOT(change_adaptor()));
911 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
912 this, SLOT(change_adaptor()));
913 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
914 this, SLOT(change_adaptor()));
915 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
916 this, SLOT(change_adaptor()));
917 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
918 this, SLOT(change_adaptor()));
919 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
920 this, SLOT(change_adaptor()));
921 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
922 this, SLOT(change_adaptor()));
923 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
924 this, SLOT(change_adaptor()));
925 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
926 this, SLOT(change_adaptor()));
928 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
929 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
930 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
931 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
932 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
933 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
934 pageLayoutModule->paperheightL);
935 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
936 pageLayoutModule->paperwidthL);
938 QComboBox * cb = pageLayoutModule->papersizeCO;
939 cb->addItem(qt_("Default"));
940 cb->addItem(qt_("Custom"));
941 cb->addItem(qt_("US letter"));
942 cb->addItem(qt_("US legal"));
943 cb->addItem(qt_("US executive"));
944 cb->addItem(qt_("A0"));
945 cb->addItem(qt_("A1"));
946 cb->addItem(qt_("A2"));
947 cb->addItem(qt_("A3"));
948 cb->addItem(qt_("A4"));
949 cb->addItem(qt_("A5"));
950 cb->addItem(qt_("A6"));
951 cb->addItem(qt_("B0"));
952 cb->addItem(qt_("B1"));
953 cb->addItem(qt_("B2"));
954 cb->addItem(qt_("B3"));
955 cb->addItem(qt_("B4"));
956 cb->addItem(qt_("B5"));
957 cb->addItem(qt_("B6"));
958 cb->addItem(qt_("C0"));
959 cb->addItem(qt_("C1"));
960 cb->addItem(qt_("C2"));
961 cb->addItem(qt_("C3"));
962 cb->addItem(qt_("C4"));
963 cb->addItem(qt_("C5"));
964 cb->addItem(qt_("C6"));
965 cb->addItem(qt_("JIS B0"));
966 cb->addItem(qt_("JIS B1"));
967 cb->addItem(qt_("JIS B2"));
968 cb->addItem(qt_("JIS B3"));
969 cb->addItem(qt_("JIS B4"));
970 cb->addItem(qt_("JIS B5"));
971 cb->addItem(qt_("JIS B6"));
972 // remove the %-items from the unit choice
973 pageLayoutModule->paperwidthUnitCO->noPercents();
974 pageLayoutModule->paperheightUnitCO->noPercents();
975 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
976 pageLayoutModule->paperheightLE));
977 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
978 pageLayoutModule->paperwidthLE));
982 marginsModule = new UiWidget<Ui::MarginsUi>(this);
983 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
984 this, SLOT(setCustomMargins(bool)));
985 connect(marginsModule->marginCB, SIGNAL(clicked()),
986 this, SLOT(change_adaptor()));
987 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
988 this, SLOT(change_adaptor()));
989 connect(marginsModule->topUnit, SIGNAL(activated(int)),
990 this, SLOT(change_adaptor()));
991 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
992 this, SLOT(change_adaptor()));
993 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
994 this, SLOT(change_adaptor()));
995 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
996 this, SLOT(change_adaptor()));
997 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
998 this, SLOT(change_adaptor()));
999 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1000 this, SLOT(change_adaptor()));
1001 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1002 this, SLOT(change_adaptor()));
1003 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1004 this, SLOT(change_adaptor()));
1005 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1006 this, SLOT(change_adaptor()));
1007 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1008 this, SLOT(change_adaptor()));
1009 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1010 this, SLOT(change_adaptor()));
1011 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1012 this, SLOT(change_adaptor()));
1013 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1014 this, SLOT(change_adaptor()));
1015 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1016 this, SLOT(change_adaptor()));
1017 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1018 this, SLOT(change_adaptor()));
1019 marginsModule->topLE->setValidator(new LengthValidator(
1020 marginsModule->topLE));
1021 marginsModule->bottomLE->setValidator(new LengthValidator(
1022 marginsModule->bottomLE));
1023 marginsModule->innerLE->setValidator(new LengthValidator(
1024 marginsModule->innerLE));
1025 marginsModule->outerLE->setValidator(new LengthValidator(
1026 marginsModule->outerLE));
1027 marginsModule->headsepLE->setValidator(new LengthValidator(
1028 marginsModule->headsepLE));
1029 marginsModule->headheightLE->setValidator(new LengthValidator(
1030 marginsModule->headheightLE));
1031 marginsModule->footskipLE->setValidator(new LengthValidator(
1032 marginsModule->footskipLE));
1033 marginsModule->columnsepLE->setValidator(new LengthValidator(
1034 marginsModule->columnsepLE));
1036 bc().addCheckedLineEdit(marginsModule->topLE,
1037 marginsModule->topL);
1038 bc().addCheckedLineEdit(marginsModule->bottomLE,
1039 marginsModule->bottomL);
1040 bc().addCheckedLineEdit(marginsModule->innerLE,
1041 marginsModule->innerL);
1042 bc().addCheckedLineEdit(marginsModule->outerLE,
1043 marginsModule->outerL);
1044 bc().addCheckedLineEdit(marginsModule->headsepLE,
1045 marginsModule->headsepL);
1046 bc().addCheckedLineEdit(marginsModule->headheightLE,
1047 marginsModule->headheightL);
1048 bc().addCheckedLineEdit(marginsModule->footskipLE,
1049 marginsModule->footskipL);
1050 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1051 marginsModule->columnsepL);
1055 langModule = new UiWidget<Ui::LanguageUi>(this);
1056 connect(langModule->languageCO, SIGNAL(activated(int)),
1057 this, SLOT(change_adaptor()));
1058 connect(langModule->languageCO, SIGNAL(activated(int)),
1059 this, SLOT(languageChanged(int)));
1060 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1061 this, SLOT(change_adaptor()));
1062 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1063 this, SLOT(change_adaptor()));
1064 connect(langModule->encodingCO, SIGNAL(activated(int)),
1065 this, SLOT(change_adaptor()));
1066 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1067 this, SLOT(change_adaptor()));
1068 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1069 this, SLOT(change_adaptor()));
1070 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1071 this, SLOT(change_adaptor()));
1072 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1073 this, SLOT(languagePackageChanged(int)));
1074 connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1075 this, SLOT(change_adaptor()));
1077 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1078 langModule->languagePackageLE));
1080 QAbstractItemModel * language_model = guiApp->languageModel();
1081 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1082 language_model->sort(0);
1083 langModule->languageCO->setModel(language_model);
1084 langModule->languageCO->setModelColumn(0);
1086 // Always put the default encoding in the first position.
1087 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1088 QStringList encodinglist;
1089 Encodings::const_iterator it = encodings.begin();
1090 Encodings::const_iterator const end = encodings.end();
1091 for (; it != end; ++it)
1093 encodinglist.append(qt_(it->guiName()));
1094 encodinglist.sort();
1095 langModule->encodingCO->addItems(encodinglist);
1097 langModule->languagePackageCO->addItem(
1098 qt_("Default"), toqstr("default"));
1099 langModule->languagePackageCO->addItem(
1100 qt_("Automatic"), toqstr("auto"));
1101 langModule->languagePackageCO->addItem(
1102 qt_("Always Babel"), toqstr("babel"));
1103 langModule->languagePackageCO->addItem(
1104 qt_("Custom"), toqstr("custom"));
1105 langModule->languagePackageCO->addItem(
1106 qt_("None[[language package]]"), toqstr("none"));
1110 colorModule = new UiWidget<Ui::ColorUi>(this);
1111 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1112 this, SLOT(changeFontColor()));
1113 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1114 this, SLOT(deleteFontColor()));
1115 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1116 this, SLOT(changeNoteFontColor()));
1117 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1118 this, SLOT(deleteNoteFontColor()));
1119 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1120 this, SLOT(changeBackgroundColor()));
1121 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1122 this, SLOT(deleteBackgroundColor()));
1123 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1124 this, SLOT(changeBoxBackgroundColor()));
1125 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1126 this, SLOT(deleteBoxBackgroundColor()));
1130 numberingModule = new UiWidget<Ui::NumberingUi>(this);
1131 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1132 this, SLOT(change_adaptor()));
1133 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1134 this, SLOT(change_adaptor()));
1135 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1136 this, SLOT(updateNumbering()));
1137 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1138 this, SLOT(updateNumbering()));
1139 numberingModule->tocTW->setColumnCount(3);
1140 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1141 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1142 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1143 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1146 biblioModule = new UiWidget<Ui::BiblioUi>(this);
1147 connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1148 this, SLOT(citeEngineChanged(int)));
1149 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1150 this, SLOT(citeStyleChanged()));
1151 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1152 this, SLOT(biblioChanged()));
1153 connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1154 this, SLOT(biblioChanged()));
1155 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1156 this, SLOT(bibtexChanged(int)));
1157 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1158 this, SLOT(biblioChanged()));
1159 connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1160 this, SLOT(biblioChanged()));
1161 connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1162 this, SLOT(biblioChanged()));
1163 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1164 this, SLOT(biblioChanged()));
1165 connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1166 this, SLOT(updateResetDefaultBiblio()));
1167 connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1168 this, SLOT(biblioChanged()));
1169 connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1170 this, SLOT(updateResetDefaultBiblio()));
1171 connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1172 this, SLOT(biblioChanged()));
1173 connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1174 this, SLOT(updateResetDefaultBiblio()));
1175 connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1176 this, SLOT(rescanBibFiles()));
1177 connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1178 this, SLOT(resetDefaultBibfile()));
1179 connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1180 this, SLOT(resetDefaultCbxBibfile()));
1181 connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1182 this, SLOT(resetDefaultBbxBibfile()));
1183 connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1184 this, SLOT(matchBiblatexStyles()));
1186 biblioModule->citeEngineCO->clear();
1187 for (LyXCiteEngine const & cet : theCiteEnginesList) {
1188 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1189 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1190 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1194 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1195 biblioModule->bibtexOptionsLE));
1196 biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1197 biblioModule->defaultBiblioCO->lineEdit()));
1199 // NOTE: we do not provide "custom" here for security reasons!
1200 biblioModule->bibtexCO->clear();
1201 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1202 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1203 it != lyxrc.bibtex_alternatives.end(); ++it) {
1204 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1205 biblioModule->bibtexCO->addItem(command, command);
1210 indicesModule = new GuiIndices;
1211 connect(indicesModule, SIGNAL(changed()),
1212 this, SLOT(change_adaptor()));
1216 mathsModule = new UiWidget<Ui::MathsUi>(this);
1217 QStringList headers;
1218 headers << qt_("Package") << qt_("Load automatically")
1219 << qt_("Load always") << qt_("Do not load");
1220 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1221 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1222 map<string, string> const & packages = BufferParams::auto_packages();
1223 mathsModule->packagesTW->setRowCount(packages.size());
1225 for (map<string, string>::const_iterator it = packages.begin();
1226 it != packages.end(); ++it) {
1227 docstring const package = from_ascii(it->first);
1228 QString autoTooltip = qt_(it->second);
1229 QString alwaysTooltip;
1230 if (package == "amsmath")
1232 qt_("The AMS LaTeX packages are always used");
1234 alwaysTooltip = toqstr(bformat(
1235 _("The LaTeX package %1$s is always used"),
1237 QString neverTooltip;
1238 if (package == "amsmath")
1240 qt_("The AMS LaTeX packages are never used");
1242 neverTooltip = toqstr(bformat(
1243 _("The LaTeX package %1$s is never used"),
1245 QRadioButton * autoRB = new QRadioButton(mathsModule);
1246 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1247 QRadioButton * neverRB = new QRadioButton(mathsModule);
1248 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1249 packageGroup->addButton(autoRB);
1250 packageGroup->addButton(alwaysRB);
1251 packageGroup->addButton(neverRB);
1252 autoRB->setToolTip(autoTooltip);
1253 alwaysRB->setToolTip(alwaysTooltip);
1254 neverRB->setToolTip(neverTooltip);
1255 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1256 mathsModule->packagesTW->setItem(i, 0, pack);
1257 mathsModule->packagesTW->setCellWidget(i, 1, autoRB);
1258 mathsModule->packagesTW->setCellWidget(i, 2, alwaysRB);
1259 mathsModule->packagesTW->setCellWidget(i, 3, neverRB);
1261 connect(autoRB, SIGNAL(clicked()),
1262 this, SLOT(change_adaptor()));
1263 connect(alwaysRB, SIGNAL(clicked()),
1264 this, SLOT(change_adaptor()));
1265 connect(neverRB, SIGNAL(clicked()),
1266 this, SLOT(change_adaptor()));
1269 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1270 this, SLOT(allPackagesAuto()));
1271 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1272 this, SLOT(allPackagesAlways()));
1273 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1274 this, SLOT(allPackagesNot()));
1275 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1276 this, SLOT(change_adaptor()));
1277 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1278 this, SLOT(change_adaptor()));
1279 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1280 this, SLOT(change_adaptor()));
1284 latexModule = new UiWidget<Ui::LaTeXUi>(this);
1285 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1286 this, SLOT(change_adaptor()));
1287 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1288 this, SLOT(change_adaptor()));
1289 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1290 this, SLOT(change_adaptor()));
1291 connect(latexModule->classCO, SIGNAL(activated(int)),
1292 this, SLOT(classChanged_adaptor()));
1293 connect(latexModule->classCO, SIGNAL(activated(int)),
1294 this, SLOT(change_adaptor()));
1295 connect(latexModule->layoutPB, SIGNAL(clicked()),
1296 this, SLOT(browseLayout()));
1297 connect(latexModule->layoutPB, SIGNAL(clicked()),
1298 this, SLOT(change_adaptor()));
1299 connect(latexModule->childDocGB, SIGNAL(clicked()),
1300 this, SLOT(change_adaptor()));
1301 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1302 this, SLOT(change_adaptor()));
1303 connect(latexModule->childDocPB, SIGNAL(clicked()),
1304 this, SLOT(browseMaster()));
1305 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1306 this, SLOT(change_adaptor()));
1307 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1308 this, SLOT(change_adaptor()));
1310 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1311 latexModule->optionsLE));
1312 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1313 latexModule->childDocLE));
1315 // postscript drivers
1316 for (int n = 0; tex_graphics[n][0]; ++n) {
1317 QString enc = qt_(tex_graphics_gui[n]);
1318 latexModule->psdriverCO->addItem(enc);
1321 LayoutFileList const & bcl = LayoutFileList::get();
1322 vector<LayoutFileIndex> classList = bcl.classList();
1323 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1325 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1326 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1327 for (int i = 0; cit != cen; ++cit, ++i) {
1328 LayoutFile const & tc = bcl[*cit];
1329 bool const available = tc.isTeXClassAvailable();
1330 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1331 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1332 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1334 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1335 tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1336 "Please check if you have the matching %1$s class "
1337 "and all required packages (%2$s) installed."),
1338 output_type, from_utf8(tc.prerequisites(", "))));
1340 latexModule->classCO->addItemSort(toqstr(tc.name()),
1342 toqstr(translateIfPossible(from_utf8(tc.category()))),
1344 true, true, true, available);
1349 branchesModule = new GuiBranches(this);
1350 connect(branchesModule, SIGNAL(changed()),
1351 this, SLOT(change_adaptor()));
1352 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1353 this, SLOT(branchesRename(docstring const &, docstring const &)));
1354 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1355 updateUnknownBranches();
1359 preambleModule = new PreambleModule(this);
1360 connect(preambleModule, SIGNAL(changed()),
1361 this, SLOT(change_adaptor()));
1363 localLayout = new LocalLayout(this);
1364 connect(localLayout, SIGNAL(changed()),
1365 this, SLOT(change_adaptor()));
1369 bulletsModule = new BulletsModule(this);
1370 connect(bulletsModule, SIGNAL(changed()),
1371 this, SLOT(change_adaptor()));
1375 modulesModule = new UiWidget<Ui::ModulesUi>(this);
1376 modulesModule->availableLV->header()->setVisible(false);
1377 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1378 modulesModule->availableLV->header()->setStretchLastSection(false);
1380 new ModuleSelectionManager(this, modulesModule->availableLV,
1381 modulesModule->selectedLV,
1382 modulesModule->addPB,
1383 modulesModule->deletePB,
1384 modulesModule->upPB,
1385 modulesModule->downPB,
1386 availableModel(), selectedModel(), this);
1387 connect(selectionManager, SIGNAL(updateHook()),
1388 this, SLOT(updateModuleInfo()));
1389 connect(selectionManager, SIGNAL(selectionChanged()),
1390 this, SLOT(modulesChanged()));
1394 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1395 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1396 this, SLOT(change_adaptor()));
1397 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1398 this, SLOT(change_adaptor()));
1399 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1400 this, SLOT(change_adaptor()));
1401 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1402 this, SLOT(change_adaptor()));
1403 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1404 this, SLOT(change_adaptor()));
1405 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1406 this, SLOT(change_adaptor()));
1407 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1408 this, SLOT(change_adaptor()));
1409 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1410 this, SLOT(change_adaptor()));
1411 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1412 this, SLOT(change_adaptor()));
1413 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1414 this, SLOT(change_adaptor()));
1415 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1416 this, SLOT(change_adaptor()));
1417 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1418 this, SLOT(change_adaptor()));
1419 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1420 this, SLOT(change_adaptor()));
1421 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1422 this, SLOT(change_adaptor()));
1423 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1424 this, SLOT(change_adaptor()));
1425 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1426 this, SLOT(change_adaptor()));
1428 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1429 pdfSupportModule->titleLE));
1430 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1431 pdfSupportModule->authorLE));
1432 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1433 pdfSupportModule->subjectLE));
1434 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1435 pdfSupportModule->keywordsLE));
1436 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1437 pdfSupportModule->optionsLE));
1439 for (int i = 0; backref_opts[i][0]; ++i)
1440 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1444 floatModule = new FloatPlacement;
1445 connect(floatModule, SIGNAL(changed()),
1446 this, SLOT(change_adaptor()));
1450 listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1451 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1452 this, SLOT(change_adaptor()));
1453 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1454 this, SLOT(change_adaptor()));
1455 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1456 this, SLOT(setListingsMessage()));
1457 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1458 this, SLOT(setListingsMessage()));
1459 listingsModule->listingsTB->setPlainText(
1460 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1464 docPS->addPanel(latexModule, N_("Document Class"));
1465 docPS->addPanel(masterChildModule, N_("Child Documents"));
1466 docPS->addPanel(modulesModule, N_("Modules"));
1467 docPS->addPanel(localLayout, N_("Local Layout"));
1468 docPS->addPanel(fontModule, N_("Fonts"));
1469 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1470 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1471 docPS->addPanel(marginsModule, N_("Page Margins"));
1472 docPS->addPanel(langModule, N_("Language"));
1473 docPS->addPanel(colorModule, N_("Colors"));
1474 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1475 docPS->addPanel(biblioModule, N_("Bibliography"));
1476 docPS->addPanel(indicesModule, N_("Indexes"));
1477 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1478 docPS->addPanel(mathsModule, N_("Math Options"));
1479 docPS->addPanel(floatModule, N_("Float Placement"));
1480 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1481 docPS->addPanel(bulletsModule, N_("Bullets"));
1482 docPS->addPanel(branchesModule, N_("Branches"));
1483 docPS->addPanel(outputModule, N_("Formats[[output]]"));
1484 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1485 docPS->setCurrentPanel("Document Class");
1486 // FIXME: hack to work around resizing bug in Qt >= 4.2
1487 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1488 #if QT_VERSION >= 0x040200
1489 docPS->updateGeometry();
1494 void GuiDocument::onBufferViewChanged()
1496 if (isVisibleView())
1497 initialiseParams("");
1501 void GuiDocument::saveDefaultClicked()
1507 void GuiDocument::useDefaultsClicked()
1513 void GuiDocument::change_adaptor()
1515 nonModuleChanged_ = true;
1520 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1525 string child = fromqstr(item->text(0));
1529 if (std::find(includeonlys_.begin(),
1530 includeonlys_.end(), child) != includeonlys_.end())
1531 includeonlys_.remove(child);
1533 includeonlys_.push_back(child);
1535 updateIncludeonlys();
1540 QString GuiDocument::validateListingsParameters()
1542 if (listingsModule->bypassCB->isChecked())
1544 string params = fromqstr(listingsModule->listingsED->toPlainText());
1545 return toqstr(InsetListingsParams(params).validate());
1549 void GuiDocument::setListingsMessage()
1552 static bool isOK = true;
1553 QString msg = validateListingsParameters();
1554 if (msg.isEmpty()) {
1558 // listingsTB->setTextColor("black");
1559 listingsModule->listingsTB->setPlainText(
1560 qt_("Input listings parameters below. "
1561 "Enter ? for a list of parameters."));
1564 // listingsTB->setTextColor("red");
1565 listingsModule->listingsTB->setPlainText(msg);
1570 void GuiDocument::setLSpacing(int item)
1572 textLayoutModule->lspacingLE->setEnabled(item == 3);
1576 void GuiDocument::setIndent(int item)
1578 bool const enable = (item == 1);
1579 textLayoutModule->indentLE->setEnabled(enable);
1580 textLayoutModule->indentLengthCO->setEnabled(enable);
1581 textLayoutModule->skipLE->setEnabled(false);
1582 textLayoutModule->skipLengthCO->setEnabled(false);
1587 void GuiDocument::enableIndent(bool indent)
1589 textLayoutModule->skipLE->setEnabled(!indent);
1590 textLayoutModule->skipLengthCO->setEnabled(!indent);
1592 setIndent(textLayoutModule->indentCO->currentIndex());
1596 void GuiDocument::setSkip(int item)
1598 bool const enable = (item == 3);
1599 textLayoutModule->skipLE->setEnabled(enable);
1600 textLayoutModule->skipLengthCO->setEnabled(enable);
1605 void GuiDocument::enableSkip(bool skip)
1607 textLayoutModule->indentLE->setEnabled(!skip);
1608 textLayoutModule->indentLengthCO->setEnabled(!skip);
1610 setSkip(textLayoutModule->skipCO->currentIndex());
1613 void GuiDocument::setMathIndent(int item)
1615 bool const enable = (item == 1);
1616 textLayoutModule->MathIndentLE->setEnabled(enable);
1617 textLayoutModule->MathIndentLengthCO->setEnabled(enable);
1622 void GuiDocument::setMargins()
1624 bool const extern_geometry =
1625 documentClass().provides("geometry");
1626 marginsModule->marginCB->setEnabled(!extern_geometry);
1627 if (extern_geometry) {
1628 marginsModule->marginCB->setChecked(false);
1629 setCustomMargins(true);
1631 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1632 setCustomMargins(!bp_.use_geometry);
1637 void GuiDocument::papersizeChanged(int paper_size)
1639 setCustomPapersize(paper_size == 1);
1643 void GuiDocument::setCustomPapersize(bool custom)
1645 pageLayoutModule->paperwidthL->setEnabled(custom);
1646 pageLayoutModule->paperwidthLE->setEnabled(custom);
1647 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1648 pageLayoutModule->paperheightL->setEnabled(custom);
1649 pageLayoutModule->paperheightLE->setEnabled(custom);
1650 pageLayoutModule->paperheightLE->setFocus();
1651 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1655 void GuiDocument::setColSep()
1657 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1661 void GuiDocument::setCustomMargins(bool custom)
1663 marginsModule->topL->setEnabled(!custom);
1664 marginsModule->topLE->setEnabled(!custom);
1665 marginsModule->topUnit->setEnabled(!custom);
1667 marginsModule->bottomL->setEnabled(!custom);
1668 marginsModule->bottomLE->setEnabled(!custom);
1669 marginsModule->bottomUnit->setEnabled(!custom);
1671 marginsModule->innerL->setEnabled(!custom);
1672 marginsModule->innerLE->setEnabled(!custom);
1673 marginsModule->innerUnit->setEnabled(!custom);
1675 marginsModule->outerL->setEnabled(!custom);
1676 marginsModule->outerLE->setEnabled(!custom);
1677 marginsModule->outerUnit->setEnabled(!custom);
1679 marginsModule->headheightL->setEnabled(!custom);
1680 marginsModule->headheightLE->setEnabled(!custom);
1681 marginsModule->headheightUnit->setEnabled(!custom);
1683 marginsModule->headsepL->setEnabled(!custom);
1684 marginsModule->headsepLE->setEnabled(!custom);
1685 marginsModule->headsepUnit->setEnabled(!custom);
1687 marginsModule->footskipL->setEnabled(!custom);
1688 marginsModule->footskipLE->setEnabled(!custom);
1689 marginsModule->footskipUnit->setEnabled(!custom);
1691 bool const enableColSep = !custom &&
1692 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1693 marginsModule->columnsepL->setEnabled(enableColSep);
1694 marginsModule->columnsepLE->setEnabled(enableColSep);
1695 marginsModule->columnsepUnit->setEnabled(enableColSep);
1699 void GuiDocument::changeBackgroundColor()
1701 QColor const & newColor = QColorDialog::getColor(
1702 rgb2qcolor(set_backgroundcolor), asQWidget());
1703 if (!newColor.isValid())
1705 // set the button color and text
1706 colorModule->backgroundPB->setStyleSheet(
1707 colorButtonStyleSheet(newColor));
1708 colorModule->backgroundPB->setText(qt_("&Change..."));
1710 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1711 is_backgroundcolor = true;
1716 void GuiDocument::deleteBackgroundColor()
1718 // set the button color back to default by setting an empty StyleSheet
1719 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1720 // change button text
1721 colorModule->backgroundPB->setText(qt_("&Default..."));
1722 // save default color (white)
1723 set_backgroundcolor = rgbFromHexName("#ffffff");
1724 is_backgroundcolor = false;
1729 void GuiDocument::changeFontColor()
1731 QColor const & newColor = QColorDialog::getColor(
1732 rgb2qcolor(set_fontcolor), asQWidget());
1733 if (!newColor.isValid())
1735 // set the button color and text
1736 colorModule->fontColorPB->setStyleSheet(
1737 colorButtonStyleSheet(newColor));
1738 colorModule->fontColorPB->setText(qt_("&Change..."));
1740 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1741 is_fontcolor = true;
1746 void GuiDocument::deleteFontColor()
1748 // set the button color back to default by setting an empty StyleSheet
1749 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1750 // change button text
1751 colorModule->fontColorPB->setText(qt_("&Default..."));
1752 // save default color (black)
1753 set_fontcolor = rgbFromHexName("#000000");
1754 is_fontcolor = false;
1759 void GuiDocument::changeNoteFontColor()
1761 QColor const & newColor = QColorDialog::getColor(
1762 rgb2qcolor(set_notefontcolor), asQWidget());
1763 if (!newColor.isValid())
1765 // set the button color
1766 colorModule->noteFontColorPB->setStyleSheet(
1767 colorButtonStyleSheet(newColor));
1769 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1774 void GuiDocument::deleteNoteFontColor()
1776 // set the button color back to pref
1777 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1778 colorModule->noteFontColorPB->setStyleSheet(
1779 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1784 void GuiDocument::changeBoxBackgroundColor()
1786 QColor const & newColor = QColorDialog::getColor(
1787 rgb2qcolor(set_boxbgcolor), asQWidget());
1788 if (!newColor.isValid())
1790 // set the button color
1791 colorModule->boxBackgroundPB->setStyleSheet(
1792 colorButtonStyleSheet(newColor));
1794 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1799 void GuiDocument::deleteBoxBackgroundColor()
1801 // set the button color back to pref
1802 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1803 colorModule->boxBackgroundPB->setStyleSheet(
1804 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1809 void GuiDocument::updateQuoteStyles(bool const set)
1811 Language const * lang = lyx::languages.getLanguage(
1812 fromqstr(langModule->languageCO->itemData(
1813 langModule->languageCO->currentIndex()).toString()));
1815 InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1817 langModule->quoteStyleCO->clear();
1819 bool has_default = false;
1820 for (int i = 0; i < quoteparams.stylescount(); ++i) {
1821 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1822 if (qs == InsetQuotesParams::DynamicQuotes)
1824 bool const langdef = (qs == def);
1826 // add the default style on top
1827 langModule->quoteStyleCO->insertItem(0,
1828 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1832 langModule->quoteStyleCO->addItem(
1833 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1835 if (set && has_default)
1836 // (re)set to the default style
1837 langModule->quoteStyleCO->setCurrentIndex(0);
1841 void GuiDocument::languageChanged(int i)
1843 // some languages only work with polyglossia
1844 Language const * lang = lyx::languages.getLanguage(
1845 fromqstr(langModule->languageCO->itemData(i).toString()));
1846 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1847 // If we force to switch fontspec on, store
1848 // current state (#8717)
1849 if (fontModule->osFontsCB->isEnabled())
1850 forced_fontspec_activation =
1851 !fontModule->osFontsCB->isChecked();
1852 fontModule->osFontsCB->setChecked(true);
1853 fontModule->osFontsCB->setEnabled(false);
1856 fontModule->osFontsCB->setEnabled(true);
1857 // If we have forced to switch fontspec on,
1858 // restore previous state (#8717)
1859 if (forced_fontspec_activation)
1860 fontModule->osFontsCB->setChecked(false);
1861 forced_fontspec_activation = false;
1864 // set appropriate quotation mark style
1865 updateQuoteStyles(true);
1869 void GuiDocument::osFontsChanged(bool nontexfonts)
1871 bool const tex_fonts = !nontexfonts;
1872 // store current fonts
1873 QString const font_roman = fontModule->fontsRomanCO->itemData(
1874 fontModule->fontsRomanCO->currentIndex()).toString();
1875 QString const font_sans = fontModule->fontsSansCO->itemData(
1876 fontModule->fontsSansCO->currentIndex()).toString();
1877 QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
1878 fontModule->fontsTypewriterCO->currentIndex()).toString();
1879 QString const font_math = fontModule->fontsMathCO->itemData(
1880 fontModule->fontsMathCO->currentIndex()).toString();
1881 int const font_sf_scale = fontModule->scaleSansSB->value();
1882 int const font_tt_scale = fontModule->scaleTypewriterSB->value();
1885 // store default format
1886 QString const dformat = outputModule->defaultFormatCO->itemData(
1887 outputModule->defaultFormatCO->currentIndex()).toString();
1888 updateDefaultFormat();
1889 // try to restore default format
1890 int index = outputModule->defaultFormatCO->findData(dformat);
1891 // set to default if format is not found
1894 outputModule->defaultFormatCO->setCurrentIndex(index);
1896 // try to restore fonts which were selected two toggles ago
1897 index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
1899 fontModule->fontsRomanCO->setCurrentIndex(index);
1900 index = fontModule->fontsSansCO->findData(fontModule->font_sans);
1902 fontModule->fontsSansCO->setCurrentIndex(index);
1903 index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
1905 fontModule->fontsTypewriterCO->setCurrentIndex(index);
1906 index = fontModule->fontsMathCO->findData(fontModule->font_math);
1908 fontModule->fontsMathCO->setCurrentIndex(index);
1909 // save fonts for next next toggle
1910 fontModule->font_roman = font_roman;
1911 fontModule->font_sans = font_sans;
1912 fontModule->font_typewriter = font_typewriter;
1913 fontModule->font_math = font_math;
1914 fontModule->font_sf_scale = font_sf_scale;
1915 fontModule->font_tt_scale = font_tt_scale;
1917 langModule->encodingCO->setEnabled(tex_fonts &&
1918 !langModule->defaultencodingRB->isChecked());
1919 langModule->defaultencodingRB->setEnabled(tex_fonts);
1920 langModule->otherencodingRB->setEnabled(tex_fonts);
1922 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1923 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1924 fontModule->cjkFontLE->setEnabled(tex_fonts);
1925 fontModule->cjkFontLA->setEnabled(tex_fonts);
1927 updateFontOptions();
1929 fontModule->fontencLA->setEnabled(tex_fonts);
1930 fontModule->fontencCO->setEnabled(tex_fonts);
1932 fontModule->fontencLE->setEnabled(false);
1934 fontencChanged(fontModule->fontencCO->currentIndex());
1938 void GuiDocument::mathFontChanged(int)
1940 updateFontOptions();
1944 void GuiDocument::fontOsfToggled(bool state)
1946 if (fontModule->osFontsCB->isChecked())
1948 QString font = fontModule->fontsRomanCO->itemData(
1949 fontModule->fontsRomanCO->currentIndex()).toString();
1950 if (hasMonolithicExpertSet(font))
1951 fontModule->fontScCB->setChecked(state);
1955 void GuiDocument::fontScToggled(bool state)
1957 if (fontModule->osFontsCB->isChecked())
1959 QString font = fontModule->fontsRomanCO->itemData(
1960 fontModule->fontsRomanCO->currentIndex()).toString();
1961 if (hasMonolithicExpertSet(font))
1962 fontModule->fontOsfCB->setChecked(state);
1966 void GuiDocument::updateFontOptions()
1968 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
1971 font = fontModule->fontsSansCO->itemData(
1972 fontModule->fontsSansCO->currentIndex()).toString();
1973 bool scaleable = providesScale(font);
1974 fontModule->scaleSansSB->setEnabled(scaleable);
1975 fontModule->scaleSansLA->setEnabled(scaleable);
1977 font = fontModule->fontsTypewriterCO->itemData(
1978 fontModule->fontsTypewriterCO->currentIndex()).toString();
1979 scaleable = providesScale(font);
1980 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1981 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1983 font = fontModule->fontsRomanCO->itemData(
1984 fontModule->fontsRomanCO->currentIndex()).toString();
1985 fontModule->fontScCB->setEnabled(providesSC(font));
1986 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1987 fontModule->dashesCB->setEnabled(tex_fonts);
1988 updateMathFonts(font);
1992 void GuiDocument::updateFontsize(string const & items, string const & sel)
1994 fontModule->fontsizeCO->clear();
1995 fontModule->fontsizeCO->addItem(qt_("Default"));
1997 for (int n = 0; !token(items,'|',n).empty(); ++n)
1998 fontModule->fontsizeCO->
1999 addItem(toqstr(token(items,'|',n)));
2001 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2002 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2003 fontModule->fontsizeCO->setCurrentIndex(n);
2010 bool GuiDocument::ot1() const
2012 QString const fontenc =
2013 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2014 return (fontenc == "default"
2015 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2016 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2020 bool GuiDocument::completeFontset() const
2022 return (fontModule->fontsSansCO->itemData(
2023 fontModule->fontsSansCO->currentIndex()).toString() == "default"
2024 && fontModule->fontsSansCO->itemData(
2025 fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2029 bool GuiDocument::noMathFont() const
2031 return (fontModule->fontsMathCO->itemData(
2032 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2036 void GuiDocument::updateTexFonts()
2038 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2040 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2041 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2042 for (; it != end; ++it) {
2043 LaTeXFont lf = it->second;
2044 if (lf.name().empty()) {
2045 LYXERR0("Error: Unnamed font: " << it->first);
2048 docstring const family = lf.family();
2049 docstring guiname = translateIfPossible(lf.guiname());
2050 if (!lf.available(ot1(), noMathFont()))
2051 guiname += _(" (not installed)");
2053 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2054 else if (family == "sf")
2055 sffonts_.insert(toqstr(guiname), toqstr(it->first));
2056 else if (family == "tt")
2057 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2058 else if (family == "math")
2059 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2064 void GuiDocument::updateFontlist()
2066 fontModule->fontsRomanCO->clear();
2067 fontModule->fontsSansCO->clear();
2068 fontModule->fontsTypewriterCO->clear();
2069 fontModule->fontsMathCO->clear();
2071 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2072 if (fontModule->osFontsCB->isChecked()) {
2073 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2074 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2075 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2076 QString unimath = qt_("Non-TeX Fonts Default");
2077 if (!LaTeXFeatures::isAvailable("unicode-math"))
2078 unimath += qt_(" (not available)");
2079 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2080 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2082 QFontDatabase fontdb;
2083 QStringList families(fontdb.families());
2084 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2085 fontModule->fontsRomanCO->addItem(*it, *it);
2086 fontModule->fontsSansCO->addItem(*it, *it);
2087 fontModule->fontsTypewriterCO->addItem(*it, *it);
2092 if (rmfonts_.empty())
2095 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2096 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2097 while (rmi != rmfonts_.constEnd()) {
2098 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2102 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2103 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2104 while (sfi != sffonts_.constEnd()) {
2105 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2109 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2110 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2111 while (tti != ttfonts_.constEnd()) {
2112 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2116 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2117 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2118 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2119 while (mmi != mathfonts_.constEnd()) {
2120 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2126 void GuiDocument::fontencChanged(int item)
2128 fontModule->fontencLE->setEnabled(
2129 fontModule->fontencCO->itemData(item).toString() == "custom");
2130 // The availability of TeX fonts depends on the font encoding
2132 updateFontOptions();
2136 void GuiDocument::updateMathFonts(QString const & rm)
2138 if (fontModule->osFontsCB->isChecked())
2140 QString const math =
2141 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2142 int const i = fontModule->fontsMathCO->findData("default");
2143 if (providesNoMath(rm) && i == -1)
2144 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2145 else if (!providesNoMath(rm) && i != -1) {
2146 int const c = fontModule->fontsMathCO->currentIndex();
2147 fontModule->fontsMathCO->removeItem(i);
2149 fontModule->fontsMathCO->setCurrentIndex(0);
2154 void GuiDocument::romanChanged(int item)
2156 if (fontModule->osFontsCB->isChecked())
2158 QString const font =
2159 fontModule->fontsRomanCO->itemData(item).toString();
2160 fontModule->fontScCB->setEnabled(providesSC(font));
2161 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2162 updateMathFonts(font);
2166 void GuiDocument::sansChanged(int item)
2168 if (fontModule->osFontsCB->isChecked())
2170 QString const font =
2171 fontModule->fontsSansCO->itemData(item).toString();
2172 bool scaleable = providesScale(font);
2173 fontModule->scaleSansSB->setEnabled(scaleable);
2174 fontModule->scaleSansLA->setEnabled(scaleable);
2178 void GuiDocument::ttChanged(int item)
2180 if (fontModule->osFontsCB->isChecked())
2182 QString const font =
2183 fontModule->fontsTypewriterCO->itemData(item).toString();
2184 bool scaleable = providesScale(font);
2185 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2186 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2190 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2193 pageLayoutModule->pagestyleCO->clear();
2194 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2196 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2197 string style = token(items, '|', n);
2198 QString style_gui = qt_(style);
2199 pagestyles.push_back(pair<string, QString>(style, style_gui));
2200 pageLayoutModule->pagestyleCO->addItem(style_gui);
2203 if (sel == "default") {
2204 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2210 for (size_t i = 0; i < pagestyles.size(); ++i)
2211 if (pagestyles[i].first == sel)
2212 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2215 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2219 void GuiDocument::browseLayout()
2221 QString const label1 = qt_("Layouts|#o#O");
2222 QString const dir1 = toqstr(lyxrc.document_path);
2223 QStringList const filter(qt_("LyX Layout (*.layout)"));
2224 QString file = browseRelToParent(QString(), bufferFilePath(),
2225 qt_("Local layout file"), filter, false,
2228 if (!file.endsWith(".layout"))
2231 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2232 fromqstr(bufferFilePath()));
2234 int const ret = Alert::prompt(_("Local layout file"),
2235 _("The layout file you have selected is a local layout\n"
2236 "file, not one in the system or user directory.\n"
2237 "Your document will not work with this layout if you\n"
2238 "move the layout file to a different directory."),
2239 1, 1, _("&Set Layout"), _("&Cancel"));
2243 // load the layout file
2244 LayoutFileList & bcl = LayoutFileList::get();
2245 string classname = layoutFile.onlyFileName();
2246 // this will update an existing layout if that layout has been loaded before.
2247 LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2248 classname.substr(0, classname.size() - 7),
2249 layoutFile.onlyPath().absFileName()));
2252 Alert::error(_("Error"),
2253 _("Unable to read local layout file."));
2257 const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2259 // do not trigger classChanged if there is no change.
2260 if (latexModule->classCO->currentText() == toqstr(name))
2264 bool const avail = latexModule->classCO->set(toqstr(name));
2266 LayoutFile const & tc = bcl[name];
2267 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2268 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2269 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2270 tooltip += '\n' + qt_("This is a local layout file.");
2271 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2272 toqstr(translateIfPossible(from_utf8(tc.category()))),
2274 true, true, true, true);
2275 latexModule->classCO->set(toqstr(name));
2282 void GuiDocument::browseMaster()
2284 QString const title = qt_("Select master document");
2285 QString const dir1 = toqstr(lyxrc.document_path);
2286 QString const old = latexModule->childDocLE->text();
2287 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2288 QStringList const filter(qt_("LyX Files (*.lyx)"));
2289 QString file = browseRelToSub(old, docpath, title, filter, false,
2290 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2292 if (!file.isEmpty())
2293 latexModule->childDocLE->setText(file);
2297 void GuiDocument::classChanged_adaptor()
2299 const_cast<Buffer &>(buffer()).setLayoutPos(string());
2304 void GuiDocument::classChanged()
2306 int idx = latexModule->classCO->currentIndex();
2309 string const classname = fromqstr(latexModule->classCO->getData(idx));
2311 if (applyPB->isEnabled()) {
2312 int const ret = Alert::prompt(_("Unapplied changes"),
2313 _("Some changes in the dialog were not yet applied.\n"
2314 "If you do not apply now, they will be lost after this action."),
2315 1, 1, _("&Apply"), _("&Dismiss"));
2320 // We load the TextClass as soon as it is selected. This is
2321 // necessary so that other options in the dialog can be updated
2322 // according to the new class. Note, however, that, if you use
2323 // the scroll wheel when sitting on the combo box, we'll load a
2324 // lot of TextClass objects very quickly....
2325 if (!bp_.setBaseClass(classname)) {
2326 Alert::error(_("Error"), _("Unable to set document class."));
2329 if (lyxrc.auto_reset_options)
2330 bp_.useClassDefaults();
2332 // With the introduction of modules came a distinction between the base
2333 // class and the document class. The former corresponds to the main layout
2334 // file; the latter is that plus the modules (or the document-specific layout,
2335 // or whatever else there could be). Our parameters come from the document
2336 // class. So when we set the base class, we also need to recreate the document
2337 // class. Otherwise, we still have the old one.
2338 bp_.makeDocumentClass();
2343 void GuiDocument::languagePackageChanged(int i)
2345 langModule->languagePackageLE->setEnabled(
2346 langModule->languagePackageCO->itemData(i).toString() == "custom");
2350 void GuiDocument::biblioChanged()
2352 biblioChanged_ = true;
2357 void GuiDocument::rescanBibFiles()
2360 rescanTexStyles("bbx cbx");
2362 rescanTexStyles("bst");
2366 void GuiDocument::resetDefaultBibfile(string const & which)
2368 QString const engine =
2369 biblioModule->citeEngineCO->itemData(
2370 biblioModule->citeEngineCO->currentIndex()).toString();
2372 CiteEngineType const cet =
2373 CiteEngineType(biblioModule->citeStyleCO->itemData(
2374 biblioModule->citeStyleCO->currentIndex()).toInt());
2376 updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2380 void GuiDocument::resetDefaultBbxBibfile()
2382 resetDefaultBibfile("bbx");
2386 void GuiDocument::resetDefaultCbxBibfile()
2388 resetDefaultBibfile("cbx");
2392 void GuiDocument::citeEngineChanged(int n)
2394 QString const engine =
2395 biblioModule->citeEngineCO->itemData(n).toString();
2397 vector<string> const engs =
2398 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2400 updateCiteStyles(engs);
2401 updateEngineDependends();
2402 resetDefaultBibfile();
2407 void GuiDocument::updateEngineDependends()
2409 bool const biblatex = isBiblatex();
2411 // These are only useful with BibTeX
2412 biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2413 biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2414 biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2415 biblioModule->bibtopicCB->setEnabled(!biblatex);
2417 // These are only useful with Biblatex
2418 biblioModule->biblatexBbxCO->setEnabled(biblatex);
2419 biblioModule->biblatexBbxLA->setEnabled(biblatex);
2420 biblioModule->biblatexCbxCO->setEnabled(biblatex);
2421 biblioModule->biblatexCbxLA->setEnabled(biblatex);
2422 biblioModule->resetBbxPB->setEnabled(biblatex);
2423 biblioModule->resetCbxPB->setEnabled(biblatex);
2424 biblioModule->matchBbxPB->setEnabled(biblatex);
2426 // These are useful with biblatex, jurabib and natbib
2427 QString const engine =
2428 biblioModule->citeEngineCO->itemData(
2429 biblioModule->citeEngineCO->currentIndex()).toString();
2430 LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2432 bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2433 || ce->requires("natbib.sty");
2434 biblioModule->citePackageOptionsLE->setEnabled(citepack);
2435 biblioModule->citePackageOptionsL->setEnabled(citepack);
2439 void GuiDocument::citeStyleChanged()
2441 QString const engine =
2442 biblioModule->citeEngineCO->itemData(
2443 biblioModule->citeEngineCO->currentIndex()).toString();
2444 QString const currentDef = isBiblatex() ?
2445 biblioModule->biblatexBbxCO->currentText()
2446 : biblioModule->defaultBiblioCO->currentText();
2447 if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2448 resetDefaultBibfile();
2454 void GuiDocument::bibtexChanged(int n)
2456 biblioModule->bibtexOptionsLE->setEnabled(
2457 biblioModule->bibtexCO->itemData(n).toString() != "default");
2462 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2464 biblioModule->citeStyleCO->clear();
2466 vector<string>::const_iterator it = engs.begin();
2467 vector<string>::const_iterator end = engs.end();
2468 for (; it != end; ++it) {
2469 if (*it == "default")
2470 biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2471 ENGINE_TYPE_DEFAULT);
2472 else if (*it == "authoryear")
2473 biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2474 ENGINE_TYPE_AUTHORYEAR);
2475 else if (*it == "numerical")
2476 biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2477 ENGINE_TYPE_NUMERICAL);
2479 int i = biblioModule->citeStyleCO->findData(sel);
2480 if (biblioModule->citeStyleCO->findData(sel) == -1)
2482 biblioModule->citeStyleCO->setCurrentIndex(i);
2484 biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2485 biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2489 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2491 engine_types_.clear();
2495 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2497 string style = token(items, '|', n);
2498 engine_types_.push_back(style);
2501 updateCiteStyles(engine_types_, sel);
2507 // both of these should take a vector<docstring>
2509 // This is an insanely complicated attempt to make this sort of thing
2510 // work with RTL languages.
2511 docstring formatStrVec(vector<string> const & v, docstring const & s)
2513 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2517 return translateIfPossible(from_utf8(v[0]));
2518 if (v.size() == 2) {
2519 docstring retval = _("%1$s and %2$s");
2520 retval = subst(retval, _("and"), s);
2521 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2522 translateIfPossible(from_utf8(v[1])));
2524 // The idea here is to format all but the last two items...
2525 int const vSize = v.size();
2526 docstring t2 = _("%1$s, %2$s");
2527 docstring retval = translateIfPossible(from_utf8(v[0]));
2528 for (int i = 1; i < vSize - 2; ++i)
2529 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2530 //...and then to plug them, and the last two, into this schema
2531 docstring t = _("%1$s, %2$s, and %3$s");
2532 t = subst(t, _("and"), s);
2533 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2534 translateIfPossible(from_utf8(v[vSize - 1])));
2537 vector<string> idsToNames(vector<string> const & idList)
2539 vector<string> retval;
2540 vector<string>::const_iterator it = idList.begin();
2541 vector<string>::const_iterator end = idList.end();
2542 for (; it != end; ++it) {
2543 LyXModule const * const mod = theModuleList[*it];
2545 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2546 translateIfPossible(from_utf8(*it)))));
2548 retval.push_back(mod->getName());
2552 } // end anonymous namespace
2555 void GuiDocument::modulesToParams(BufferParams & bp)
2557 // update list of loaded modules
2558 bp.clearLayoutModules();
2559 int const srows = modules_sel_model_.rowCount();
2560 for (int i = 0; i < srows; ++i)
2561 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2563 // update the list of removed modules
2564 bp.clearRemovedModules();
2565 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2566 list<string>::const_iterator rit = reqmods.begin();
2567 list<string>::const_iterator ren = reqmods.end();
2569 // check each of the default modules
2570 for (; rit != ren; ++rit) {
2571 list<string>::const_iterator mit = bp.getModules().begin();
2572 list<string>::const_iterator men = bp.getModules().end();
2574 for (; mit != men; ++mit) {
2581 // the module isn't present so must have been removed by the user
2582 bp.addRemovedModule(*rit);
2587 void GuiDocument::modulesChanged()
2589 modulesToParams(bp_);
2591 if (applyPB->isEnabled() && nonModuleChanged_) {
2592 int const ret = Alert::prompt(_("Unapplied changes"),
2593 _("Some changes in the dialog were not yet applied.\n"
2594 "If you do not apply now, they will be lost after this action."),
2595 1, 1, _("&Apply"), _("&Dismiss"));
2600 bp_.makeDocumentClass();
2606 void GuiDocument::updateModuleInfo()
2608 selectionManager->update();
2610 //Module description
2611 bool const focus_on_selected = selectionManager->selectedFocused();
2612 QAbstractItemView * lv;
2613 if (focus_on_selected)
2614 lv = modulesModule->selectedLV;
2616 lv = modulesModule->availableLV;
2617 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2618 modulesModule->infoML->document()->clear();
2621 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2622 GuiIdListModel const & id_model =
2623 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2624 string const modName = id_model.getIDString(idx.row());
2625 docstring desc = getModuleDescription(modName);
2627 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2628 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2631 desc += _("Module provided by document class.");
2634 docstring cat = getModuleCategory(modName);
2638 desc += bformat(_("Category: %1$s."), cat);
2641 vector<string> pkglist = getPackageList(modName);
2642 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2643 if (!pkgdesc.empty()) {
2646 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2649 pkglist = getRequiredList(modName);
2650 if (!pkglist.empty()) {
2651 vector<string> const reqdescs = idsToNames(pkglist);
2652 pkgdesc = formatStrVec(reqdescs, _("or"));
2655 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2658 pkglist = getExcludedList(modName);
2659 if (!pkglist.empty()) {
2660 vector<string> const reqdescs = idsToNames(pkglist);
2661 pkgdesc = formatStrVec(reqdescs, _( "and"));
2664 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2667 if (!isModuleAvailable(modName)) {
2670 desc += _("WARNING: Some required packages are unavailable!");
2673 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2677 void GuiDocument::updateNumbering()
2679 DocumentClass const & tclass = documentClass();
2681 numberingModule->tocTW->setUpdatesEnabled(false);
2682 numberingModule->tocTW->clear();
2684 int const depth = numberingModule->depthSL->value();
2685 int const toc = numberingModule->tocSL->value();
2686 QString const no = qt_("No");
2687 QString const yes = qt_("Yes");
2688 QTreeWidgetItem * item = 0;
2690 DocumentClass::const_iterator lit = tclass.begin();
2691 DocumentClass::const_iterator len = tclass.end();
2692 for (; lit != len; ++lit) {
2693 int const toclevel = lit->toclevel;
2694 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2695 item = new QTreeWidgetItem(numberingModule->tocTW);
2696 item->setText(0, toqstr(translateIfPossible(lit->name())));
2697 item->setText(1, (toclevel <= depth) ? yes : no);
2698 item->setText(2, (toclevel <= toc) ? yes : no);
2702 numberingModule->tocTW->setUpdatesEnabled(true);
2703 numberingModule->tocTW->update();
2707 void GuiDocument::updateDefaultFormat()
2711 // make a copy in order to consider unapplied changes
2712 BufferParams param_copy = buffer().params();
2713 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2714 int const idx = latexModule->classCO->currentIndex();
2716 string const classname = fromqstr(latexModule->classCO->getData(idx));
2717 param_copy.setBaseClass(classname);
2718 param_copy.makeDocumentClass(true);
2720 outputModule->defaultFormatCO->blockSignals(true);
2721 outputModule->defaultFormatCO->clear();
2722 outputModule->defaultFormatCO->addItem(qt_("Default"),
2723 QVariant(QString("default")));
2724 FormatList const & formats =
2725 param_copy.exportableFormats(true);
2726 for (Format const * f : formats)
2727 outputModule->defaultFormatCO->addItem
2728 (toqstr(translateIfPossible(f->prettyname())),
2729 QVariant(toqstr(f->name())));
2730 outputModule->defaultFormatCO->blockSignals(false);
2734 bool GuiDocument::isChildIncluded(string const & child)
2736 if (includeonlys_.empty())
2738 return (std::find(includeonlys_.begin(),
2739 includeonlys_.end(), child) != includeonlys_.end());
2743 void GuiDocument::applyView()
2746 preambleModule->apply(bp_);
2747 localLayout->apply(bp_);
2750 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2751 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2754 string const engine =
2755 fromqstr(biblioModule->citeEngineCO->itemData(
2756 biblioModule->citeEngineCO->currentIndex()).toString());
2757 bp_.setCiteEngine(engine);
2759 CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2760 biblioModule->citeStyleCO->currentIndex()).toInt());
2761 if (theCiteEnginesList[engine]->hasEngineType(style))
2762 bp_.setCiteEngineType(style);
2764 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2766 bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2768 bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2769 biblioModule->bibunitsCO->currentIndex()).toString());
2771 bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2773 bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2774 bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2775 bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2777 string const bibtex_command =
2778 fromqstr(biblioModule->bibtexCO->itemData(
2779 biblioModule->bibtexCO->currentIndex()).toString());
2780 string const bibtex_options =
2781 fromqstr(biblioModule->bibtexOptionsLE->text());
2782 if (bibtex_command == "default" || bibtex_options.empty())
2783 bp_.bibtex_command = bibtex_command;
2785 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2787 if (biblioChanged_) {
2788 buffer().invalidateBibinfoCache();
2789 buffer().removeBiblioTempFiles();
2793 indicesModule->apply(bp_);
2795 // language & quotes
2796 if (langModule->defaultencodingRB->isChecked()) {
2797 bp_.inputenc = "auto";
2799 int i = langModule->encodingCO->currentIndex();
2801 bp_.inputenc = "default";
2803 QString const enc_gui =
2804 langModule->encodingCO->currentText();
2805 Encodings::const_iterator it = encodings.begin();
2806 Encodings::const_iterator const end = encodings.end();
2808 for (; it != end; ++it) {
2809 if (qt_(it->guiName()) == enc_gui &&
2811 bp_.inputenc = it->name();
2817 // should not happen
2818 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2819 bp_.inputenc = "default";
2824 bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2825 langModule->quoteStyleCO->currentIndex()).toInt();
2826 bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2828 QString const langname = langModule->languageCO->itemData(
2829 langModule->languageCO->currentIndex()).toString();
2830 Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2831 Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2832 // If current cursor language was the document language, then update it too.
2833 if (cur.current_font.language() == bp_.language) {
2834 cur.current_font.setLanguage(newlang);
2835 cur.real_current_font.setLanguage(newlang);
2837 bp_.language = newlang;
2839 QString const pack = langModule->languagePackageCO->itemData(
2840 langModule->languagePackageCO->currentIndex()).toString();
2841 if (pack == "custom")
2843 fromqstr(langModule->languagePackageLE->text());
2845 bp_.lang_package = fromqstr(pack);
2848 bp_.backgroundcolor = set_backgroundcolor;
2849 bp_.isbackgroundcolor = is_backgroundcolor;
2850 bp_.fontcolor = set_fontcolor;
2851 bp_.isfontcolor = is_fontcolor;
2852 bp_.notefontcolor = set_notefontcolor;
2853 bp_.boxbgcolor = set_boxbgcolor;
2856 if (bp_.documentClass().hasTocLevels()) {
2857 bp_.tocdepth = numberingModule->tocSL->value();
2858 bp_.secnumdepth = numberingModule->depthSL->value();
2862 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2863 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2864 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2865 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2868 bp_.graphics_driver =
2869 tex_graphics[latexModule->psdriverCO->currentIndex()];
2872 int idx = latexModule->classCO->currentIndex();
2874 string const classname = fromqstr(latexModule->classCO->getData(idx));
2875 bp_.setBaseClass(classname);
2879 modulesToParams(bp_);
2882 map<string, string> const & packages = BufferParams::auto_packages();
2883 for (map<string, string>::const_iterator it = packages.begin();
2884 it != packages.end(); ++it) {
2885 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
2888 int row = mathsModule->packagesTW->row(item);
2889 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
2890 if (rb->isChecked()) {
2891 bp_.use_package(it->first, BufferParams::package_auto);
2894 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
2895 if (rb->isChecked()) {
2896 bp_.use_package(it->first, BufferParams::package_on);
2899 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
2900 if (rb->isChecked())
2901 bp_.use_package(it->first, BufferParams::package_off);
2903 bp_.is_math_indent = textLayoutModule->MathIndentCB->isChecked();
2904 // if math is indented
2905 if (bp_.is_math_indent) {
2906 HSpace MathIndentation = HSpace(
2907 widgetsToLength(textLayoutModule->MathIndentLE,
2908 textLayoutModule->MathIndentLengthCO)
2910 bp_.setMathIndentation(MathIndentation);
2914 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2915 bp_.pagestyle = "default";
2917 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2918 for (size_t i = 0; i != pagestyles.size(); ++i)
2919 if (pagestyles[i].second == style_gui)
2920 bp_.pagestyle = pagestyles[i].first;
2924 switch (textLayoutModule->lspacingCO->currentIndex()) {
2926 bp_.spacing().set(Spacing::Single);
2929 bp_.spacing().set(Spacing::Onehalf);
2932 bp_.spacing().set(Spacing::Double);
2935 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2937 bp_.spacing().set(Spacing::Single);
2939 bp_.spacing().set(Spacing::Other, s);
2944 if (textLayoutModule->twoColumnCB->isChecked())
2949 bp_.justification = textLayoutModule->justCB->isChecked();
2951 if (textLayoutModule->indentRB->isChecked()) {
2952 // if paragraphs are separated by an indentation
2953 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2954 switch (textLayoutModule->indentCO->currentIndex()) {
2956 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2959 HSpace indent = HSpace(
2960 widgetsToLength(textLayoutModule->indentLE,
2961 textLayoutModule->indentLengthCO)
2963 bp_.setIndentation(indent);
2967 // this should never happen
2968 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2972 // if paragraphs are separated by a skip
2973 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2974 switch (textLayoutModule->skipCO->currentIndex()) {
2976 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2979 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2982 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2987 widgetsToLength(textLayoutModule->skipLE,
2988 textLayoutModule->skipLengthCO)
2994 // this should never happen
2995 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3000 if (textLayoutModule->MathIndentCB->isChecked()) {
3001 // if formulas are indented
3002 switch (textLayoutModule->MathIndentCO->currentIndex()) {
3004 bp_.setMathIndentation(HSpace(HSpace::DEFAULT));
3007 HSpace MathIndent = HSpace(
3008 widgetsToLength(textLayoutModule->MathIndentLE,
3009 textLayoutModule->MathIndentLengthCO)
3011 bp_.setMathIndentation(MathIndent);
3015 // this should never happen
3016 bp_.setMathIndentation(HSpace(HSpace::DEFAULT));
3022 fromqstr(latexModule->optionsLE->text());
3024 bp_.use_default_options =
3025 latexModule->defaultOptionsCB->isChecked();
3027 if (latexModule->childDocGB->isChecked())
3029 fromqstr(latexModule->childDocLE->text());
3031 bp_.master = string();
3034 bp_.clearIncludedChildren();
3035 if (masterChildModule->includeonlyRB->isChecked()) {
3036 list<string>::const_iterator it = includeonlys_.begin();
3037 for (; it != includeonlys_.end() ; ++it) {
3038 bp_.addIncludedChildren(*it);
3041 bp_.maintain_unincluded_children =
3042 masterChildModule->maintainAuxCB->isChecked();
3045 bp_.float_placement = floatModule->get();
3048 // text should have passed validation
3049 bp_.listings_params =
3050 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3053 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3054 outputModule->defaultFormatCO->currentIndex()).toString());
3056 bool const nontexfonts = fontModule->osFontsCB->isChecked();
3057 bp_.useNonTeXFonts = nontexfonts;
3059 bp_.output_sync = outputModule->outputsyncCB->isChecked();
3061 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3063 int mathfmt = outputModule->mathoutCB->currentIndex();
3066 BufferParams::MathOutput const mo =
3067 static_cast<BufferParams::MathOutput>(mathfmt);
3068 bp_.html_math_output = mo;
3069 bp_.html_be_strict = outputModule->strictCB->isChecked();
3070 bp_.html_css_as_file = outputModule->cssCB->isChecked();
3071 bp_.html_math_img_scale = outputModule->mathimgSB->value();
3072 bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3074 bp_.save_transient_properties =
3075 outputModule->saveTransientPropertiesCB->isChecked();
3078 bp_.fonts_roman[nontexfonts] =
3079 fromqstr(fontModule->fontsRomanCO->
3080 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3081 bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3083 bp_.fonts_sans[nontexfonts] =
3084 fromqstr(fontModule->fontsSansCO->
3085 itemData(fontModule->fontsSansCO->currentIndex()).toString());
3086 bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3088 bp_.fonts_typewriter[nontexfonts] =
3089 fromqstr(fontModule->fontsTypewriterCO->
3090 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3091 bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3093 bp_.fonts_math[nontexfonts] =
3094 fromqstr(fontModule->fontsMathCO->
3095 itemData(fontModule->fontsMathCO->currentIndex()).toString());
3096 bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3098 QString const fontenc =
3099 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3100 if (fontenc == "custom")
3101 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3103 bp_.fontenc = fromqstr(fontenc);
3106 fromqstr(fontModule->cjkFontLE->text());
3108 bp_.use_microtype = fontModule->microtypeCB->isChecked();
3109 bp_.use_dash_ligatures = fontModule->dashesCB->isChecked();
3111 bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3112 bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3114 bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3115 bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3117 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3119 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3122 bp_.fonts_default_family = "default";
3124 bp_.fonts_default_family = GuiDocument::fontfamilies[
3125 fontModule->fontsDefaultCO->currentIndex()];
3127 if (fontModule->fontsizeCO->currentIndex() == 0)
3128 bp_.fontsize = "default";
3131 fromqstr(fontModule->fontsizeCO->currentText());
3134 bp_.papersize = PAPER_SIZE(
3135 pageLayoutModule->papersizeCO->currentIndex());
3137 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3138 pageLayoutModule->paperwidthUnitCO);
3140 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3141 pageLayoutModule->paperheightUnitCO);
3143 if (pageLayoutModule->facingPagesCB->isChecked())
3144 bp_.sides = TwoSides;
3146 bp_.sides = OneSide;
3148 if (pageLayoutModule->landscapeRB->isChecked())
3149 bp_.orientation = ORIENTATION_LANDSCAPE;
3151 bp_.orientation = ORIENTATION_PORTRAIT;
3154 bp_.use_geometry = !marginsModule->marginCB->isChecked();
3156 Ui::MarginsUi const * m = marginsModule;
3158 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3159 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3160 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3161 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3162 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3163 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3164 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3165 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3168 branchesModule->apply(bp_);
3171 PDFOptions & pdf = bp_.pdfoptions();
3172 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3173 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3174 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3175 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3176 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3178 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3179 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3180 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3181 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3183 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3184 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3185 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3186 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3188 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3189 if (pdfSupportModule->fullscreenCB->isChecked())
3190 pdf.pagemode = pdf.pagemode_fullscreen;
3192 pdf.pagemode.clear();
3193 pdf.quoted_options = pdf.quoted_options_check(
3194 fromqstr(pdfSupportModule->optionsLE->text()));
3197 nonModuleChanged_ = false;
3201 void GuiDocument::paramsToDialog()
3203 // set the default unit
3204 Length::UNIT const default_unit = Length::defaultUnit();
3207 preambleModule->update(bp_, id());
3208 localLayout->update(bp_, id());
3211 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3212 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3215 string const cite_engine = bp_.citeEngine().list().front();
3217 biblioModule->citeEngineCO->setCurrentIndex(
3218 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3220 updateEngineType(documentClass().opt_enginetype(),
3221 bp_.citeEngineType());
3223 biblioModule->citeStyleCO->setCurrentIndex(
3224 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3226 biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3228 biblioModule->bibunitsCO->clear();
3229 biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3230 if (documentClass().hasLaTeXLayout("part"))
3231 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3232 if (documentClass().hasLaTeXLayout("chapter"))
3233 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3234 if (documentClass().hasLaTeXLayout("section"))
3235 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3236 if (documentClass().hasLaTeXLayout("subsection"))
3237 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3238 biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3240 int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3242 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3244 biblioModule->bibunitsCO->setCurrentIndex(0);
3246 updateEngineDependends();
3249 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3250 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3252 updateDefaultBiblio(bp_.defaultBiblioStyle());
3254 biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3258 split(bp_.bibtex_command, command, ' ');
3260 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3262 biblioModule->bibtexCO->setCurrentIndex(bpos);
3263 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3265 // We reset to default if we do not know the specified compiler
3266 // This is for security reasons
3267 biblioModule->bibtexCO->setCurrentIndex(
3268 biblioModule->bibtexCO->findData(toqstr("default")));
3269 biblioModule->bibtexOptionsLE->clear();
3271 biblioModule->bibtexOptionsLE->setEnabled(
3272 biblioModule->bibtexCO->currentIndex() != 0);
3274 biblioChanged_ = false;
3277 // We may be called when there is no Buffer, e.g., when
3278 // the last view has just been closed.
3279 bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3280 indicesModule->update(bp_, isReadOnly);
3282 // language & quotes
3283 int const pos = langModule->languageCO->findData(toqstr(
3284 bp_.language->lang()));
3285 langModule->languageCO->setCurrentIndex(pos);
3287 updateQuoteStyles();
3289 langModule->quoteStyleCO->setCurrentIndex(
3290 langModule->quoteStyleCO->findData(bp_.quotes_style));
3291 langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3293 bool default_enc = true;
3294 if (bp_.inputenc != "auto") {
3295 default_enc = false;
3296 if (bp_.inputenc == "default") {
3297 langModule->encodingCO->setCurrentIndex(0);
3300 Encodings::const_iterator it = encodings.begin();
3301 Encodings::const_iterator const end = encodings.end();
3302 for (; it != end; ++it) {
3303 if (it->name() == bp_.inputenc &&
3305 enc_gui = it->guiName();
3309 int const i = langModule->encodingCO->findText(
3312 langModule->encodingCO->setCurrentIndex(i);
3314 // unknown encoding. Set to default.
3318 langModule->defaultencodingRB->setChecked(default_enc);
3319 langModule->otherencodingRB->setChecked(!default_enc);
3321 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3323 langModule->languagePackageCO->setCurrentIndex(
3324 langModule->languagePackageCO->findData("custom"));
3325 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3327 langModule->languagePackageCO->setCurrentIndex(p);
3328 langModule->languagePackageLE->clear();
3332 if (bp_.isfontcolor) {
3333 colorModule->fontColorPB->setStyleSheet(
3334 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3336 set_fontcolor = bp_.fontcolor;
3337 is_fontcolor = bp_.isfontcolor;
3339 colorModule->noteFontColorPB->setStyleSheet(
3340 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3341 set_notefontcolor = bp_.notefontcolor;
3343 if (bp_.isbackgroundcolor) {
3344 colorModule->backgroundPB->setStyleSheet(
3345 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3347 set_backgroundcolor = bp_.backgroundcolor;
3348 is_backgroundcolor = bp_.isbackgroundcolor;
3350 colorModule->boxBackgroundPB->setStyleSheet(
3351 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3352 set_boxbgcolor = bp_.boxbgcolor;
3355 int const min_toclevel = documentClass().min_toclevel();
3356 int const max_toclevel = documentClass().max_toclevel();
3357 if (documentClass().hasTocLevels()) {
3358 numberingModule->setEnabled(true);
3359 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3360 numberingModule->depthSL->setMaximum(max_toclevel);
3361 numberingModule->depthSL->setValue(bp_.secnumdepth);
3362 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3363 numberingModule->tocSL->setMaximum(max_toclevel);
3364 numberingModule->tocSL->setValue(bp_.tocdepth);
3367 numberingModule->setEnabled(false);
3368 numberingModule->tocTW->clear();
3372 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3373 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3374 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3375 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3376 bulletsModule->init();
3379 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3381 latexModule->psdriverCO->setCurrentIndex(nitem);
3385 if (bp_.is_math_indent) {
3386 textLayoutModule->MathIndentCB->setChecked(bp_.is_math_indent);
3387 string MathIndentation = bp_.getMathIndentation().asLyXCommand();
3389 if (MathIndentation != "default") {
3390 lengthToWidgets(textLayoutModule->MathIndentLE,
3391 textLayoutModule->MathIndentLengthCO,
3392 MathIndentation, default_unit);
3395 textLayoutModule->MathIndentCO->setCurrentIndex(MathIndent);
3396 setMathIndent(MathIndent);
3399 map<string, string> const & packages = BufferParams::auto_packages();
3400 for (map<string, string>::const_iterator it = packages.begin();
3401 it != packages.end(); ++it) {
3402 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3405 int row = mathsModule->packagesTW->row(item);
3406 switch (bp_.use_package(it->first)) {
3407 case BufferParams::package_off: {
3408 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
3409 rb->setChecked(true);
3412 case BufferParams::package_on: {
3413 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
3414 rb->setChecked(true);
3417 case BufferParams::package_auto: {
3418 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
3419 rb->setChecked(true);
3425 switch (bp_.spacing().getSpace()) {
3426 case Spacing::Other: nitem = 3; break;
3427 case Spacing::Double: nitem = 2; break;
3428 case Spacing::Onehalf: nitem = 1; break;
3429 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3433 string const & layoutID = bp_.baseClassID();
3434 setLayoutComboByIDString(layoutID);
3436 updatePagestyle(documentClass().opt_pagestyle(),
3439 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3440 if (bp_.spacing().getSpace() == Spacing::Other) {
3441 doubleToWidget(textLayoutModule->lspacingLE,
3442 bp_.spacing().getValueAsString());
3446 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3447 textLayoutModule->indentRB->setChecked(true);
3448 string indentation = bp_.getIndentation().asLyXCommand();
3450 if (indentation != "default") {
3451 lengthToWidgets(textLayoutModule->indentLE,
3452 textLayoutModule->indentLengthCO,
3453 indentation, default_unit);
3456 textLayoutModule->indentCO->setCurrentIndex(indent);
3459 textLayoutModule->skipRB->setChecked(true);
3461 switch (bp_.getDefSkip().kind()) {
3462 case VSpace::SMALLSKIP:
3465 case VSpace::MEDSKIP:
3468 case VSpace::BIGSKIP:
3471 case VSpace::LENGTH:
3474 string const length = bp_.getDefSkip().asLyXCommand();
3475 lengthToWidgets(textLayoutModule->skipLE,
3476 textLayoutModule->skipLengthCO,
3477 length, default_unit);
3484 textLayoutModule->skipCO->setCurrentIndex(skip);
3488 textLayoutModule->twoColumnCB->setChecked(
3490 textLayoutModule->justCB->setChecked(bp_.justification);
3492 if (!bp_.options.empty()) {
3493 latexModule->optionsLE->setText(
3494 toqstr(bp_.options));
3496 latexModule->optionsLE->setText(QString());
3500 latexModule->defaultOptionsCB->setChecked(
3501 bp_.use_default_options);
3502 updateSelectedModules();
3503 selectionManager->updateProvidedModules(
3504 bp_.baseClass()->providedModules());
3505 selectionManager->updateExcludedModules(
3506 bp_.baseClass()->excludedModules());
3508 if (!documentClass().options().empty()) {
3509 latexModule->defaultOptionsLE->setText(
3510 toqstr(documentClass().options()));
3512 latexModule->defaultOptionsLE->setText(
3513 toqstr(_("[No options predefined]")));
3516 latexModule->defaultOptionsLE->setEnabled(
3517 bp_.use_default_options
3518 && !documentClass().options().empty());
3520 latexModule->defaultOptionsCB->setEnabled(
3521 !documentClass().options().empty());
3523 if (!bp_.master.empty()) {
3524 latexModule->childDocGB->setChecked(true);
3525 latexModule->childDocLE->setText(
3526 toqstr(bp_.master));
3528 latexModule->childDocLE->setText(QString());
3529 latexModule->childDocGB->setChecked(false);
3533 if (!bufferview() || !buffer().hasChildren()) {
3534 masterChildModule->childrenTW->clear();
3535 includeonlys_.clear();
3536 docPS->showPanel("Child Documents", false);
3537 if (docPS->isCurrentPanel("Child Documents"))
3538 docPS->setCurrentPanel("Document Class");
3540 docPS->showPanel("Child Documents", true);
3541 masterChildModule->setEnabled(true);
3542 includeonlys_ = bp_.getIncludedChildren();
3543 updateIncludeonlys();
3545 masterChildModule->maintainAuxCB->setChecked(
3546 bp_.maintain_unincluded_children);
3549 floatModule->set(bp_.float_placement);
3552 // break listings_params to multiple lines
3554 InsetListingsParams(bp_.listings_params).separatedParams();
3555 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3558 // some languages only work with polyglossia/XeTeX
3559 Language const * lang = lyx::languages.getLanguage(
3560 fromqstr(langModule->languageCO->itemData(
3561 langModule->languageCO->currentIndex()).toString()));
3562 bool const need_fontspec =
3563 lang->babel().empty() && !lang->polyglossia().empty();
3564 bool const os_fonts_available =
3565 bp_.baseClass()->outputType() == lyx::LATEX
3566 && LaTeXFeatures::isAvailable("fontspec");
3567 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3568 fontModule->osFontsCB->setChecked(
3569 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3570 updateFontsize(documentClass().opt_fontsize(),
3573 QString font = toqstr(bp_.fontsRoman());
3574 int rpos = fontModule->fontsRomanCO->findData(font);
3576 rpos = fontModule->fontsRomanCO->count();
3577 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3579 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3580 fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3582 font = toqstr(bp_.fontsSans());
3583 int spos = fontModule->fontsSansCO->findData(font);
3585 spos = fontModule->fontsSansCO->count();
3586 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3588 fontModule->fontsSansCO->setCurrentIndex(spos);
3589 fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3591 font = toqstr(bp_.fontsTypewriter());
3592 int tpos = fontModule->fontsTypewriterCO->findData(font);
3594 tpos = fontModule->fontsTypewriterCO->count();
3595 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3597 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3598 fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3600 font = toqstr(bp_.fontsMath());
3601 int mpos = fontModule->fontsMathCO->findData(font);
3603 mpos = fontModule->fontsMathCO->count();
3604 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3606 fontModule->fontsMathCO->setCurrentIndex(mpos);
3607 fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3609 if (bp_.useNonTeXFonts && os_fonts_available) {
3610 fontModule->fontencLA->setEnabled(false);
3611 fontModule->fontencCO->setEnabled(false);
3612 fontModule->fontencLE->setEnabled(false);
3614 fontModule->fontencLA->setEnabled(true);
3615 fontModule->fontencCO->setEnabled(true);
3616 fontModule->fontencLE->setEnabled(true);
3622 if (!bp_.fonts_cjk.empty())
3623 fontModule->cjkFontLE->setText(
3624 toqstr(bp_.fonts_cjk));
3626 fontModule->cjkFontLE->setText(QString());
3628 fontModule->microtypeCB->setChecked(bp_.use_microtype);
3629 fontModule->dashesCB->setChecked(bp_.use_dash_ligatures);
3631 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3632 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3633 fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3634 fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3635 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3636 fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3638 int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3640 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3642 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3643 fontModule->fontencCO->setCurrentIndex(
3644 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3645 fontModule->fontencLE->setEnabled(false);
3647 fontModule->fontencCO->setCurrentIndex(1);
3648 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3652 // This must be set _after_ fonts since updateDefaultFormat()
3653 // checks osFontsCB settings.
3654 // update combobox with formats
3655 updateDefaultFormat();
3656 int index = outputModule->defaultFormatCO->findData(toqstr(
3657 bp_.default_output_format));
3658 // set to default if format is not found
3661 outputModule->defaultFormatCO->setCurrentIndex(index);
3663 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3664 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3666 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3667 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3668 outputModule->strictCB->setChecked(bp_.html_be_strict);
3669 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3671 outputModule->saveTransientPropertiesCB
3672 ->setChecked(bp_.save_transient_properties);
3675 bool const extern_geometry =
3676 documentClass().provides("geometry");
3677 int const psize = bp_.papersize;
3678 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3679 setCustomPapersize(!extern_geometry && psize == 1);
3680 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3682 bool const landscape =
3683 bp_.orientation == ORIENTATION_LANDSCAPE;
3684 pageLayoutModule->landscapeRB->setChecked(landscape);
3685 pageLayoutModule->portraitRB->setChecked(!landscape);
3686 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3687 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3689 pageLayoutModule->facingPagesCB->setChecked(
3690 bp_.sides == TwoSides);
3692 lengthToWidgets(pageLayoutModule->paperwidthLE,
3693 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3694 lengthToWidgets(pageLayoutModule->paperheightLE,
3695 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3698 Ui::MarginsUi * m = marginsModule;
3702 lengthToWidgets(m->topLE, m->topUnit,
3703 bp_.topmargin, default_unit);
3705 lengthToWidgets(m->bottomLE, m->bottomUnit,
3706 bp_.bottommargin, default_unit);
3708 lengthToWidgets(m->innerLE, m->innerUnit,
3709 bp_.leftmargin, default_unit);
3711 lengthToWidgets(m->outerLE, m->outerUnit,
3712 bp_.rightmargin, default_unit);
3714 lengthToWidgets(m->headheightLE, m->headheightUnit,
3715 bp_.headheight, default_unit);
3717 lengthToWidgets(m->headsepLE, m->headsepUnit,
3718 bp_.headsep, default_unit);
3720 lengthToWidgets(m->footskipLE, m->footskipUnit,
3721 bp_.footskip, default_unit);
3723 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3724 bp_.columnsep, default_unit);
3727 updateUnknownBranches();
3728 branchesModule->update(bp_);
3731 PDFOptions const & pdf = bp_.pdfoptions();
3732 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3733 if (bp_.documentClass().provides("hyperref"))
3734 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3736 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3737 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3738 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3739 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3740 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3742 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3743 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3744 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3746 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3748 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3749 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3750 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3751 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3753 nn = findToken(backref_opts, pdf.backref);
3755 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3757 pdfSupportModule->fullscreenCB->setChecked
3758 (pdf.pagemode == pdf.pagemode_fullscreen);
3760 pdfSupportModule->optionsLE->setText(
3761 toqstr(pdf.quoted_options));
3763 // Make sure that the bc is in the INITIAL state
3764 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3767 // clear changed branches cache
3768 changedBranches_.clear();
3771 nonModuleChanged_ = false;
3775 void GuiDocument::saveDocDefault()
3777 // we have to apply the params first
3783 void GuiDocument::updateAvailableModules()
3785 modules_av_model_.clear();
3786 list<modInfoStruct> modInfoList = getModuleInfo();
3787 // Sort names according to the locale
3788 modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3789 return 0 < b.name.localeAwareCompare(a.name);
3792 for (modInfoStruct const & m : modInfoList) {
3793 modules_av_model_.insertRow(i, m.name, m.id, m.description);
3799 void GuiDocument::updateSelectedModules()
3801 modules_sel_model_.clear();
3802 list<modInfoStruct> const selModList = getSelectedModules();
3804 for (modInfoStruct const & m : selModList) {
3805 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
3811 void GuiDocument::updateIncludeonlys()
3813 masterChildModule->childrenTW->clear();
3814 QString const no = qt_("No");
3815 QString const yes = qt_("Yes");
3817 if (includeonlys_.empty()) {
3818 masterChildModule->includeallRB->setChecked(true);
3819 masterChildModule->childrenTW->setEnabled(false);
3820 masterChildModule->maintainAuxCB->setEnabled(false);
3822 masterChildModule->includeonlyRB->setChecked(true);
3823 masterChildModule->childrenTW->setEnabled(true);
3824 masterChildModule->maintainAuxCB->setEnabled(true);
3826 ListOfBuffers children = buffer().getChildren();
3827 ListOfBuffers::const_iterator it = children.begin();
3828 ListOfBuffers::const_iterator end = children.end();
3829 bool has_unincluded = false;
3830 bool all_unincluded = true;
3831 for (; it != end; ++it) {
3832 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
3835 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3836 from_utf8(buffer().filePath())));
3837 item->setText(0, toqstr(name));
3838 item->setText(1, isChildIncluded(name) ? yes : no);
3839 if (!isChildIncluded(name))
3840 has_unincluded = true;
3842 all_unincluded = false;
3844 // Both if all childs are included and if none is included
3845 // is equal to "include all" (i.e., ommit \includeonly).
3846 // Thus, reset the GUI.
3847 if (!has_unincluded || all_unincluded) {
3848 masterChildModule->includeallRB->setChecked(true);
3849 masterChildModule->childrenTW->setEnabled(false);
3850 includeonlys_.clear();
3852 // If all are included, we need to update again.
3853 if (!has_unincluded)
3854 updateIncludeonlys();
3858 bool GuiDocument::isBiblatex() const
3860 QString const engine =
3861 biblioModule->citeEngineCO->itemData(
3862 biblioModule->citeEngineCO->currentIndex()).toString();
3864 return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
3868 void GuiDocument::updateDefaultBiblio(string const & style,
3869 string const & which)
3871 QString const bibstyle = toqstr(style);
3872 biblioModule->defaultBiblioCO->clear();
3877 if (which != "cbx") {
3878 // First the bbx styles
3879 biblioModule->biblatexBbxCO->clear();
3880 QStringList str = texFileList("bbxFiles.lst");
3881 // test whether we have a valid list, otherwise run rescan
3882 if (str.isEmpty()) {
3883 rescanTexStyles("bbx");
3884 str = texFileList("bbxFiles.lst");
3886 for (int i = 0; i != str.size(); ++i)
3887 str[i] = onlyFileName(str[i]);
3888 // sort on filename only (no path)
3891 for (int i = 0; i != str.count(); ++i) {
3892 QString item = changeExtension(str[i], "");
3893 if (item == bibstyle)
3895 biblioModule->biblatexBbxCO->addItem(item);
3898 if (item_nr == -1 && !bibstyle.isEmpty()) {
3899 biblioModule->biblatexBbxCO->addItem(bibstyle);
3900 item_nr = biblioModule->biblatexBbxCO->count() - 1;
3904 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
3906 biblioModule->biblatexBbxCO->clearEditText();
3909 if (which != "bbx") {
3910 // now the cbx styles
3911 biblioModule->biblatexCbxCO->clear();
3912 QStringList str = texFileList("cbxFiles.lst");
3913 // test whether we have a valid list, otherwise run rescan
3914 if (str.isEmpty()) {
3915 rescanTexStyles("cbx");
3916 str = texFileList("cbxFiles.lst");
3918 for (int i = 0; i != str.size(); ++i)
3919 str[i] = onlyFileName(str[i]);
3920 // sort on filename only (no path)
3923 for (int i = 0; i != str.count(); ++i) {
3924 QString item = changeExtension(str[i], "");
3925 if (item == bibstyle)
3927 biblioModule->biblatexCbxCO->addItem(item);
3930 if (item_nr == -1 && !bibstyle.isEmpty()) {
3931 biblioModule->biblatexCbxCO->addItem(bibstyle);
3932 item_nr = biblioModule->biblatexCbxCO->count() - 1;
3936 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
3938 biblioModule->biblatexCbxCO->clearEditText();
3941 biblioModule->biblatexBbxCO->clear();
3942 biblioModule->biblatexCbxCO->clear();
3943 QStringList str = texFileList("bstFiles.lst");
3944 // test whether we have a valid list, otherwise run rescan
3945 if (str.isEmpty()) {
3946 rescanTexStyles("bst");
3947 str = texFileList("bstFiles.lst");
3949 for (int i = 0; i != str.size(); ++i)
3950 str[i] = onlyFileName(str[i]);
3951 // sort on filename only (no path)
3954 for (int i = 0; i != str.count(); ++i) {
3955 QString item = changeExtension(str[i], "");
3956 if (item == bibstyle)
3958 biblioModule->defaultBiblioCO->addItem(item);
3961 if (item_nr == -1 && !bibstyle.isEmpty()) {
3962 biblioModule->defaultBiblioCO->addItem(bibstyle);
3963 item_nr = biblioModule->defaultBiblioCO->count() - 1;
3967 biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
3969 biblioModule->defaultBiblioCO->clearEditText();
3972 updateResetDefaultBiblio();
3976 void GuiDocument::updateResetDefaultBiblio()
3978 QString const engine =
3979 biblioModule->citeEngineCO->itemData(
3980 biblioModule->citeEngineCO->currentIndex()).toString();
3981 CiteEngineType const cet =
3982 CiteEngineType(biblioModule->citeStyleCO->itemData(
3983 biblioModule->citeStyleCO->currentIndex()).toInt());
3985 string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
3987 QString const bbx = biblioModule->biblatexBbxCO->currentText();
3988 QString const cbx = biblioModule->biblatexCbxCO->currentText();
3989 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
3990 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
3991 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
3992 && biblioModule->biblatexBbxCO->findText(cbx) != -1);
3994 biblioModule->resetDefaultBiblioPB->setEnabled(
3995 defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
3999 void GuiDocument::matchBiblatexStyles()
4001 updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4006 void GuiDocument::updateContents()
4008 // Nothing to do here as the document settings is not cursor dependant.
4013 void GuiDocument::useClassDefaults()
4015 if (applyPB->isEnabled()) {
4016 int const ret = Alert::prompt(_("Unapplied changes"),
4017 _("Some changes in the dialog were not yet applied.\n"
4018 "If you do not apply now, they will be lost after this action."),
4019 1, 1, _("&Apply"), _("&Dismiss"));
4024 int idx = latexModule->classCO->currentIndex();
4025 string const classname = fromqstr(latexModule->classCO->getData(idx));
4026 if (!bp_.setBaseClass(classname)) {
4027 Alert::error(_("Error"), _("Unable to set document class."));
4030 bp_.useClassDefaults();
4035 void GuiDocument::setLayoutComboByIDString(string const & idString)
4037 if (!latexModule->classCO->set(toqstr(idString)))
4038 Alert::warning(_("Can't set layout!"),
4039 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4043 bool GuiDocument::isValid()
4046 validateListingsParameters().isEmpty() &&
4047 localLayout->isValid() &&
4049 // if we're asking for skips between paragraphs
4050 !textLayoutModule->skipRB->isChecked() ||
4051 // then either we haven't chosen custom
4052 textLayoutModule->skipCO->currentIndex() != 3 ||
4053 // or else a length has been given
4054 !textLayoutModule->skipLE->text().isEmpty()
4057 // if we're asking for indentation
4058 !textLayoutModule->indentRB->isChecked() ||
4059 // then either we haven't chosen custom
4060 textLayoutModule->indentCO->currentIndex() != 1 ||
4061 // or else a length has been given
4062 !textLayoutModule->indentLE->text().isEmpty()
4067 char const * const GuiDocument::fontfamilies[5] = {
4068 "default", "rmdefault", "sfdefault", "ttdefault", ""
4072 char const * GuiDocument::fontfamilies_gui[5] = {
4073 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4077 bool GuiDocument::initialiseParams(string const &)
4079 BufferView const * view = bufferview();
4081 bp_ = BufferParams();
4085 bp_ = view->buffer().params();
4087 updateAvailableModules();
4088 //FIXME It'd be nice to make sure here that the selected
4089 //modules are consistent: That required modules are actually
4090 //selected, and that we don't have conflicts. If so, we could
4091 //at least pop up a warning.
4097 void GuiDocument::clearParams()
4099 bp_ = BufferParams();
4103 BufferId GuiDocument::id() const
4105 BufferView const * const view = bufferview();
4106 return view? &view->buffer() : 0;
4110 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4112 return moduleNames_;
4116 list<GuiDocument::modInfoStruct> const
4117 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4119 list<modInfoStruct> mInfo;
4120 for (string const & name : mods) {
4122 LyXModule const * const mod = theModuleList[name];
4127 m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4135 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4137 return makeModuleInfo(params().getModules());
4141 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4143 return makeModuleInfo(params().baseClass()->providedModules());
4147 DocumentClass const & GuiDocument::documentClass() const
4149 return bp_.documentClass();
4153 static void dispatch_bufferparams(Dialog const & dialog,
4154 BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4157 ss << "\\begin_header\n";
4158 bp.writeFile(ss, buf);
4159 ss << "\\end_header\n";
4160 dialog.dispatch(FuncRequest(lfun, ss.str()));
4164 void GuiDocument::dispatchParams()
4166 // We need a non-const buffer object.
4167 Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4168 // There may be several undo records; group them (bug #8998)
4169 buf.undo().beginUndoGroup();
4171 // This must come first so that a language change is correctly noticed
4174 // Apply the BufferParams. Note that this will set the base class
4175 // and then update the buffer's layout.
4176 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4178 if (!params().master.empty()) {
4179 FileName const master_file = support::makeAbsPath(params().master,
4180 support::onlyPath(buffer().absFileName()));
4181 if (isLyXFileName(master_file.absFileName())) {
4182 Buffer * master = checkAndLoadLyXFile(master_file);
4184 if (master->isChild(const_cast<Buffer *>(&buffer())))
4185 const_cast<Buffer &>(buffer()).setParent(master);
4187 Alert::warning(_("Assigned master does not include this file"),
4188 bformat(_("You must include this file in the document\n"
4189 "'%1$s' in order to use the master document\n"
4190 "feature."), from_utf8(params().master)));
4192 Alert::warning(_("Could not load master"),
4193 bformat(_("The master document '%1$s'\n"
4194 "could not be loaded."),
4195 from_utf8(params().master)));
4199 // Generate the colours requested by each new branch.
4200 BranchList & branchlist = params().branchlist();
4201 if (!branchlist.empty()) {
4202 BranchList::const_iterator it = branchlist.begin();
4203 BranchList::const_iterator const end = branchlist.end();
4204 for (; it != end; ++it) {
4205 docstring const & current_branch = it->branch();
4206 Branch const * branch = branchlist.find(current_branch);
4207 string const x11hexname = X11hexname(branch->color());
4208 // display the new color
4209 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4210 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4213 // Open insets of selected branches, close deselected ones
4214 dispatch(FuncRequest(LFUN_INSET_FORALL,
4215 "Branch inset-toggle assign"));
4217 // rename branches in the document
4218 executeBranchRenaming();
4219 // and clear changed branches cache
4220 changedBranches_.clear();
4222 // Generate the colours requested by indices.
4223 IndicesList & indiceslist = params().indiceslist();
4224 if (!indiceslist.empty()) {
4225 IndicesList::const_iterator it = indiceslist.begin();
4226 IndicesList::const_iterator const end = indiceslist.end();
4227 for (; it != end; ++it) {
4228 docstring const & current_index = it->shortcut();
4229 Index const * index = indiceslist.findShortcut(current_index);
4230 string const x11hexname = X11hexname(index->color());
4231 // display the new color
4232 docstring const str = current_index + ' ' + from_ascii(x11hexname);
4233 dispatch(FuncRequest(LFUN_SET_COLOR, str));
4237 // If we used an LFUN, we would not need these two lines:
4238 BufferView * bv = const_cast<BufferView *>(bufferview());
4239 bv->processUpdateFlags(Update::Force | Update::FitCursor);
4241 // Don't forget to close the group. Note that it is important
4242 // to check that there is no early return in the method.
4243 buf.undo().endUndoGroup();
4247 void GuiDocument::setLanguage() const
4249 Language const * const newL = bp_.language;
4250 if (buffer().params().language == newL)
4253 string const & lang_name = newL->lang();
4254 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4258 void GuiDocument::saveAsDefault() const
4260 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4264 bool GuiDocument::providesOSF(QString const & font) const
4266 if (fontModule->osFontsCB->isChecked())
4267 // FIXME: we should check if the fonts really
4268 // have OSF support. But how?
4270 return theLaTeXFonts().getLaTeXFont(
4271 qstring_to_ucs4(font)).providesOSF(ot1(),
4277 bool GuiDocument::providesSC(QString const & font) const
4279 if (fontModule->osFontsCB->isChecked())
4281 return theLaTeXFonts().getLaTeXFont(
4282 qstring_to_ucs4(font)).providesSC(ot1(),
4288 bool GuiDocument::providesScale(QString const & font) const
4290 if (fontModule->osFontsCB->isChecked())
4292 return theLaTeXFonts().getLaTeXFont(
4293 qstring_to_ucs4(font)).providesScale(ot1(),
4299 bool GuiDocument::providesNoMath(QString const & font) const
4301 if (fontModule->osFontsCB->isChecked())
4303 return theLaTeXFonts().getLaTeXFont(
4304 qstring_to_ucs4(font)).providesNoMath(ot1(),
4309 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4311 if (fontModule->osFontsCB->isChecked())
4313 return theLaTeXFonts().getLaTeXFont(
4314 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4321 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4323 // FIXME Unicode: docstrings would be better for these parameters but this
4324 // change requires a lot of others
4327 m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4328 QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4329 // Find the first sentence of the description
4330 QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4331 int pos = bf.toNextBoundary();
4334 QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4335 // Tooltip is the desc followed by the module name
4336 m.description = QString("%1<i>%2</i>")
4337 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4343 void GuiDocument::loadModuleInfo()
4345 moduleNames_.clear();
4346 for (LyXModule const & mod : theModuleList)
4347 if (mod.category().substr(0, 8) != "Citation")
4348 moduleNames_.push_back(modInfo(mod));
4352 void GuiDocument::updateUnknownBranches()
4356 list<docstring> used_branches;
4357 buffer().getUsedBranches(used_branches);
4358 list<docstring>::const_iterator it = used_branches.begin();
4359 QStringList unknown_branches;
4360 for (; it != used_branches.end() ; ++it) {
4361 if (!buffer().params().branchlist().find(*it))
4362 unknown_branches.append(toqstr(*it));
4364 branchesModule->setUnknownBranches(unknown_branches);
4368 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4370 map<docstring, docstring>::iterator it = changedBranches_.begin();
4371 for (; it != changedBranches_.end() ; ++it) {
4372 if (it->second == oldname) {
4373 // branch has already been renamed
4374 it->second = newname;
4379 changedBranches_[oldname] = newname;
4383 void GuiDocument::executeBranchRenaming() const
4385 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4386 for (; it != changedBranches_.end() ; ++it) {
4387 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4388 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4393 void GuiDocument::allPackagesAuto()
4399 void GuiDocument::allPackagesAlways()
4405 void GuiDocument::allPackagesNot()
4411 void GuiDocument::allPackages(int col)
4413 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4414 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col);
4415 rb->setChecked(true);
4420 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4423 } // namespace frontend
4426 #include "moc_GuiDocument.cpp"