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"
33 #include "ColorCache.h"
35 #include "FloatPlacement.h"
37 #include "FuncRequest.h"
39 #include "IndicesList.h"
41 #include "LaTeXFeatures.h"
42 #include "LaTeXFonts.h"
44 #include "LayoutEnums.h"
45 #include "LayoutModuleList.h"
47 #include "ModuleList.h"
48 #include "OutputParams.h"
49 #include "PDFOptions.h"
50 #include "qt_helpers.h"
52 #include "TextClass.h"
54 #include "insets/InsetListingsParams.h"
56 #include "support/debug.h"
57 #include "support/FileName.h"
58 #include "support/filetools.h"
59 #include "support/gettext.h"
60 #include "support/lassert.h"
61 #include "support/lstrings.h"
63 #include "frontends/alert.h"
65 #include <QAbstractItemModel>
66 #include <QHeaderView>
68 #include <QColorDialog>
69 #include <QCloseEvent>
70 #include <QFontDatabase>
72 #include <QTextCursor>
82 // a style sheet for buttons
83 // this is for example used for the background color setting button
84 static inline QString colorButtonStyleSheet(QColor const & bgColor)
86 if (bgColor.isValid()) {
87 QString rc = QLatin1String("background-color:");
96 using namespace lyx::support;
101 char const * const tex_graphics[] =
103 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
104 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
105 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
106 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
111 char const * const tex_graphics_gui[] =
113 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
114 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
115 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
116 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
117 "XeTeX", N_("None"), ""
121 char const * backref_opts[] =
123 "false", "section", "slide", "page", ""
127 char const * backref_opts_gui[] =
129 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
133 vector<string> engine_types_;
134 vector<pair<string, QString> > pagestyles;
136 QMap<QString, QString> rmfonts_;
137 QMap<QString, QString> sffonts_;
138 QMap<QString, QString> ttfonts_;
139 QMap<QString, QString> mathfonts_;
142 } // anonymous namespace
146 RGBColor set_backgroundcolor;
147 bool is_backgroundcolor;
148 RGBColor set_fontcolor;
150 RGBColor set_notefontcolor;
151 RGBColor set_boxbgcolor;
152 bool forced_fontspec_activation;
155 // used when sorting the textclass list.
156 class less_textclass_avail_desc
157 : public binary_function<string, string, int>
160 bool operator()(string const & lhs, string const & rhs) const
162 // Ordering criteria:
163 // 1. Availability of text class
164 // 2. Description (lexicographic)
165 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
166 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
167 int const order = compare_no_case(
168 translateIfPossible(from_utf8(tc1.description())),
169 translateIfPossible(from_utf8(tc2.description())));
170 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
171 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
180 vector<string> getRequiredList(string const & modName)
182 LyXModule const * const mod = theModuleList[modName];
184 return vector<string>(); //empty such thing
185 return mod->getRequiredModules();
189 vector<string> getExcludedList(string const & modName)
191 LyXModule const * const mod = theModuleList[modName];
193 return vector<string>(); //empty such thing
194 return mod->getExcludedModules();
198 docstring getModuleCategory(string const & modName)
200 LyXModule const * const mod = theModuleList[modName];
203 return from_utf8(mod->category());
207 docstring getModuleDescription(string const & modName)
209 LyXModule const * const mod = theModuleList[modName];
211 return _("Module not found!");
213 return translateIfPossible(from_utf8(mod->getDescription()));
217 vector<string> getPackageList(string const & modName)
219 LyXModule const * const mod = theModuleList[modName];
221 return vector<string>(); //empty such thing
222 return mod->getPackageList();
226 bool isModuleAvailable(string const & modName)
228 LyXModule const * const mod = theModuleList[modName];
231 return mod->isAvailable();
234 } // anonymous namespace
237 /////////////////////////////////////////////////////////////////////
239 // ModuleSelectionManager
241 /////////////////////////////////////////////////////////////////////
243 /// SelectionManager for use with modules
244 class ModuleSelectionManager : public GuiSelectionManager
248 ModuleSelectionManager(
249 QTreeView * availableLV,
250 QListView * selectedLV,
254 QPushButton * downPB,
255 GuiIdListModel * availableModel,
256 GuiIdListModel * selectedModel,
257 GuiDocument const * container)
258 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
259 upPB, downPB, availableModel, selectedModel), container_(container)
262 void updateProvidedModules(LayoutModuleList const & pm)
263 { provided_modules_ = pm.list(); }
265 void updateExcludedModules(LayoutModuleList const & em)
266 { excluded_modules_ = em.list(); }
269 virtual void updateAddPB();
271 virtual void updateUpPB();
273 virtual void updateDownPB();
275 virtual void updateDelPB();
276 /// returns availableModel as a GuiIdListModel
277 GuiIdListModel * getAvailableModel()
279 return dynamic_cast<GuiIdListModel *>(availableModel);
281 /// returns selectedModel as a GuiIdListModel
282 GuiIdListModel * getSelectedModel()
284 return dynamic_cast<GuiIdListModel *>(selectedModel);
286 /// keeps a list of the modules the text class provides
287 list<string> provided_modules_;
289 list<string> excluded_modules_;
291 GuiDocument const * container_;
294 void ModuleSelectionManager::updateAddPB()
296 int const arows = availableModel->rowCount();
297 QModelIndexList const avail_sels =
298 availableLV->selectionModel()->selectedIndexes();
300 // disable if there aren't any modules (?), if none of them is chosen
301 // in the dialog, or if the chosen one is already selected for use.
302 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
303 addPB->setEnabled(false);
307 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
308 string const modname = getAvailableModel()->getIDString(idx.row());
311 container_->params().layoutModuleCanBeAdded(modname);
312 addPB->setEnabled(enable);
316 void ModuleSelectionManager::updateDownPB()
318 int const srows = selectedModel->rowCount();
320 downPB->setEnabled(false);
323 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
324 int const curRow = curidx.row();
325 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
326 downPB->setEnabled(false);
330 // determine whether immediately succeding element requires this one
331 string const curmodname = getSelectedModel()->getIDString(curRow);
332 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
334 vector<string> reqs = getRequiredList(nextmodname);
336 // if it doesn't require anything....
338 downPB->setEnabled(true);
342 // Enable it if this module isn't required.
343 // FIXME This should perhaps be more flexible and check whether, even
344 // if the next one is required, there is also an earlier one that will do.
346 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
349 void ModuleSelectionManager::updateUpPB()
351 int const srows = selectedModel->rowCount();
353 upPB->setEnabled(false);
357 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
358 int curRow = curIdx.row();
359 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
360 upPB->setEnabled(false);
363 string const curmodname = getSelectedModel()->getIDString(curRow);
365 // determine whether immediately preceding element is required by this one
366 vector<string> reqs = getRequiredList(curmodname);
368 // if this one doesn't require anything....
370 upPB->setEnabled(true);
375 // Enable it if the preceding module isn't required.
376 // NOTE This is less flexible than it might be. We could check whether, even
377 // if the previous one is required, there is an earlier one that would do.
378 string const premod = getSelectedModel()->getIDString(curRow - 1);
379 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
382 void ModuleSelectionManager::updateDelPB()
384 int const srows = selectedModel->rowCount();
386 deletePB->setEnabled(false);
390 QModelIndex const & curidx =
391 selectedLV->selectionModel()->currentIndex();
392 int const curRow = curidx.row();
393 if (curRow < 0 || curRow >= srows) { // invalid index?
394 deletePB->setEnabled(false);
398 string const curmodname = getSelectedModel()->getIDString(curRow);
400 // We're looking here for a reason NOT to enable the button. If we
401 // find one, we disable it and return. If we don't, we'll end up at
402 // the end of the function, and then we enable it.
403 for (int i = curRow + 1; i < srows; ++i) {
404 string const thisMod = getSelectedModel()->getIDString(i);
405 vector<string> reqs = getRequiredList(thisMod);
406 //does this one require us?
407 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
411 // OK, so this module requires us
412 // is there an EARLIER module that also satisfies the require?
413 // NOTE We demand that it be earlier to keep the list of modules
414 // consistent with the rule that a module must be proceeded by a
415 // required module. There would be more flexible ways to proceed,
416 // but that would be a lot more complicated, and the logic here is
417 // already complicated. (That's why I've left the debugging code.)
418 // lyxerr << "Testing " << thisMod << endl;
419 bool foundone = false;
420 for (int j = 0; j < curRow; ++j) {
421 string const mod = getSelectedModel()->getIDString(j);
422 // lyxerr << "In loop: Testing " << mod << endl;
423 // do we satisfy the require?
424 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
425 // lyxerr << mod << " does the trick." << endl;
430 // did we find a module to satisfy the require?
432 // lyxerr << "No matching module found." << endl;
433 deletePB->setEnabled(false);
437 // lyxerr << "All's well that ends well." << endl;
438 deletePB->setEnabled(true);
442 /////////////////////////////////////////////////////////////////////
446 /////////////////////////////////////////////////////////////////////
448 PreambleModule::PreambleModule() : current_id_(0)
450 // This is not a memory leak. The object will be destroyed
452 (void) new LaTeXHighlighter(preambleTE->document());
453 setFocusProxy(preambleTE);
454 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
458 void PreambleModule::update(BufferParams const & params, BufferId id)
460 QString preamble = toqstr(params.preamble);
461 // Nothing to do if the params and preamble are unchanged.
462 if (id == current_id_
463 && preamble == preambleTE->document()->toPlainText())
466 QTextCursor cur = preambleTE->textCursor();
467 // Save the coords before switching to the new one.
468 preamble_coords_[current_id_] =
469 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
471 // Save the params address for further use.
473 preambleTE->document()->setPlainText(preamble);
474 Coords::const_iterator it = preamble_coords_.find(current_id_);
475 if (it == preamble_coords_.end())
476 // First time we open this one.
477 preamble_coords_[current_id_] = make_pair(0, 0);
479 // Restore saved coords.
480 QTextCursor cur = preambleTE->textCursor();
481 cur.setPosition(it->second.first);
482 preambleTE->setTextCursor(cur);
483 preambleTE->verticalScrollBar()->setValue(it->second.second);
488 void PreambleModule::apply(BufferParams & params)
490 params.preamble = fromqstr(preambleTE->document()->toPlainText());
494 void PreambleModule::closeEvent(QCloseEvent * e)
496 // Save the coords before closing.
497 QTextCursor cur = preambleTE->textCursor();
498 preamble_coords_[current_id_] =
499 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
504 /////////////////////////////////////////////////////////////////////
508 /////////////////////////////////////////////////////////////////////
511 LocalLayout::LocalLayout() : current_id_(0), validated_(false)
513 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
514 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
515 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
519 void LocalLayout::update(BufferParams const & params, BufferId id)
521 QString layout = toqstr(params.getLocalLayout(false));
522 // Nothing to do if the params and preamble are unchanged.
523 if (id == current_id_
524 && layout == locallayoutTE->document()->toPlainText())
527 // Save the params address for further use.
529 locallayoutTE->document()->setPlainText(layout);
534 void LocalLayout::apply(BufferParams & params)
536 string const layout = fromqstr(locallayoutTE->document()->toPlainText());
537 params.setLocalLayout(layout, false);
541 void LocalLayout::textChanged()
543 static const QString message =
544 qt_("Press button to check validity...");
545 string const layout =
546 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
548 if (layout.empty()) {
550 validatePB->setEnabled(false);
551 validLB->setText("");
555 } else if (!validatePB->isEnabled()) {
556 // if that's already enabled, we shouldn't need to do anything.
558 validLB->setText(message);
559 validatePB->setEnabled(true);
560 convertPB->setEnabled(false);
566 void LocalLayout::convert() {
567 string const layout =
568 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
569 string const newlayout = TextClass::convert(layout);
571 if (newlayout.empty()) {
572 Alert::error(_("Conversion Failed!"),
573 _("Failed to convert local layout to current format."));
575 locallayoutTE->setPlainText(toqstr(newlayout));
581 void LocalLayout::convertPressed() {
587 void LocalLayout::validate() {
588 static const QString valid = qt_("Layout is valid!");
589 static const QString vtext =
590 toqstr("<p style=\"font-weight: bold; \">")
591 + valid + toqstr("</p>");
592 static const QString invalid = qt_("Layout is invalid!");
593 static const QString ivtext =
594 toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
595 + invalid + toqstr("</p>");
597 string const layout =
598 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
599 if (!layout.empty()) {
600 TextClass::ReturnValues const ret = TextClass::validate(layout);
601 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
602 validatePB->setEnabled(false);
603 validLB->setText(validated_ ? vtext : ivtext);
604 if (ret == TextClass::OK_OLDFORMAT) {
606 convertPB->setEnabled(true);
607 convertLB->setText(qt_("Convert to current format"));
617 void LocalLayout::validatePressed() {
623 /////////////////////////////////////////////////////////////////////
627 /////////////////////////////////////////////////////////////////////
630 GuiDocument::GuiDocument(GuiView & lv)
631 : GuiDialog(lv, "document", qt_("Document Settings"))
635 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
636 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
637 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
638 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
640 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
641 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
643 // Manage the restore, ok, apply, restore and cancel/close buttons
644 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
646 bc().setApply(applyPB);
647 bc().setCancel(closePB);
648 bc().setRestore(restorePB);
652 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
653 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
654 this, SLOT(change_adaptor()));
655 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
656 this, SLOT(setLSpacing(int)));
657 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
658 this, SLOT(change_adaptor()));
660 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
661 this, SLOT(change_adaptor()));
662 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
663 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
664 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
665 this, SLOT(change_adaptor()));
666 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
667 this, SLOT(setIndent(int)));
668 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
669 this, SLOT(change_adaptor()));
670 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
671 this, SLOT(change_adaptor()));
673 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
674 this, SLOT(change_adaptor()));
675 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
676 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
677 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
678 this, SLOT(change_adaptor()));
679 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
680 this, SLOT(setSkip(int)));
681 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
682 this, SLOT(change_adaptor()));
683 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
684 this, SLOT(change_adaptor()));
686 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
687 this, SLOT(enableIndent(bool)));
688 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
689 this, SLOT(enableSkip(bool)));
691 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
692 this, SLOT(change_adaptor()));
693 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
694 this, SLOT(setColSep()));
695 connect(textLayoutModule->justCB, SIGNAL(clicked()),
696 this, SLOT(change_adaptor()));
698 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
699 textLayoutModule->lspacingLE));
700 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
701 textLayoutModule->indentLE));
702 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
703 textLayoutModule->skipLE));
705 textLayoutModule->indentCO->addItem(qt_("Default"));
706 textLayoutModule->indentCO->addItem(qt_("Custom"));
707 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
708 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
709 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
710 textLayoutModule->skipCO->addItem(qt_("Custom"));
711 textLayoutModule->lspacingCO->insertItem(
712 Spacing::Single, qt_("Single"));
713 textLayoutModule->lspacingCO->insertItem(
714 Spacing::Onehalf, qt_("OneHalf"));
715 textLayoutModule->lspacingCO->insertItem(
716 Spacing::Double, qt_("Double"));
717 textLayoutModule->lspacingCO->insertItem(
718 Spacing::Other, qt_("Custom"));
719 // initialize the length validator
720 bc().addCheckedLineEdit(textLayoutModule->indentLE);
721 bc().addCheckedLineEdit(textLayoutModule->skipLE);
724 // master/child handling
725 masterChildModule = new UiWidget<Ui::MasterChildUi>;
727 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
728 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
729 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
730 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
731 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
732 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
733 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
734 this, SLOT(change_adaptor()));
735 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
736 this, SLOT(change_adaptor()));
737 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
738 this, SLOT(change_adaptor()));
739 masterChildModule->childrenTW->setColumnCount(2);
740 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
741 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
742 masterChildModule->childrenTW->resizeColumnToContents(1);
743 masterChildModule->childrenTW->resizeColumnToContents(2);
747 outputModule = new UiWidget<Ui::OutputUi>;
749 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
750 this, SLOT(change_adaptor()));
751 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
752 this, SLOT(change_adaptor()));
753 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
754 this, SLOT(change_adaptor()));
755 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
756 this, SLOT(change_adaptor()));
757 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
758 this, SLOT(change_adaptor()));
760 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
761 this, SLOT(change_adaptor()));
762 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
763 this, SLOT(change_adaptor()));
764 outputModule->synccustomCB->addItem("");
765 outputModule->synccustomCB->addItem("\\synctex=1");
766 outputModule->synccustomCB->addItem("\\synctex=-1");
767 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
769 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
770 outputModule->synccustomCB));
773 fontModule = new UiWidget<Ui::FontUi>;
774 connect(fontModule->osFontsCB, SIGNAL(clicked()),
775 this, SLOT(change_adaptor()));
776 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
777 this, SLOT(osFontsChanged(bool)));
778 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
779 this, SLOT(change_adaptor()));
780 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
781 this, SLOT(romanChanged(int)));
782 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
783 this, SLOT(change_adaptor()));
784 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
785 this, SLOT(sansChanged(int)));
786 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
787 this, SLOT(change_adaptor()));
788 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
789 this, SLOT(ttChanged(int)));
790 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
791 this, SLOT(change_adaptor()));
792 connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
793 this, SLOT(mathFontChanged(int)));
794 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
795 this, SLOT(change_adaptor()));
796 connect(fontModule->fontencCO, SIGNAL(activated(int)),
797 this, SLOT(change_adaptor()));
798 connect(fontModule->fontencCO, SIGNAL(activated(int)),
799 this, SLOT(fontencChanged(int)));
800 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
801 this, SLOT(change_adaptor()));
802 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
803 this, SLOT(change_adaptor()));
804 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
805 this, SLOT(change_adaptor()));
806 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
807 this, SLOT(change_adaptor()));
808 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
809 this, SLOT(change_adaptor()));
810 connect(fontModule->fontScCB, SIGNAL(clicked()),
811 this, SLOT(change_adaptor()));
812 connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
813 this, SLOT(fontScToggled(bool)));
814 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
815 this, SLOT(change_adaptor()));
816 connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
817 this, SLOT(fontOsfToggled(bool)));
819 fontModule->fontencLE->setValidator(new NoNewLineValidator(
820 fontModule->fontencLE));
821 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
822 fontModule->cjkFontLE));
826 fontModule->fontsizeCO->addItem(qt_("Default"));
827 fontModule->fontsizeCO->addItem(qt_("10"));
828 fontModule->fontsizeCO->addItem(qt_("11"));
829 fontModule->fontsizeCO->addItem(qt_("12"));
831 fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
832 fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
833 fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
835 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
836 fontModule->fontsDefaultCO->addItem(
837 qt_(GuiDocument::fontfamilies_gui[n]));
839 if (!LaTeXFeatures::isAvailable("fontspec"))
840 fontModule->osFontsCB->setToolTip(
841 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
842 "You need to install the package \"fontspec\" to use this feature"));
846 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
847 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
848 this, SLOT(papersizeChanged(int)));
849 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
850 this, SLOT(papersizeChanged(int)));
851 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
852 this, SLOT(change_adaptor()));
853 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
854 this, SLOT(change_adaptor()));
855 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
856 this, SLOT(change_adaptor()));
857 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
858 this, SLOT(change_adaptor()));
859 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
860 this, SLOT(change_adaptor()));
861 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
862 this, SLOT(change_adaptor()));
863 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
864 this, SLOT(change_adaptor()));
865 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
866 this, SLOT(change_adaptor()));
867 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
868 this, SLOT(change_adaptor()));
869 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
870 this, SLOT(change_adaptor()));
872 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
873 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
874 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
875 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
876 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
877 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
878 pageLayoutModule->paperheightL);
879 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
880 pageLayoutModule->paperwidthL);
882 QComboBox * cb = pageLayoutModule->papersizeCO;
883 cb->addItem(qt_("Default"));
884 cb->addItem(qt_("Custom"));
885 cb->addItem(qt_("US letter"));
886 cb->addItem(qt_("US legal"));
887 cb->addItem(qt_("US executive"));
888 cb->addItem(qt_("A0"));
889 cb->addItem(qt_("A1"));
890 cb->addItem(qt_("A2"));
891 cb->addItem(qt_("A3"));
892 cb->addItem(qt_("A4"));
893 cb->addItem(qt_("A5"));
894 cb->addItem(qt_("A6"));
895 cb->addItem(qt_("B0"));
896 cb->addItem(qt_("B1"));
897 cb->addItem(qt_("B2"));
898 cb->addItem(qt_("B3"));
899 cb->addItem(qt_("B4"));
900 cb->addItem(qt_("B5"));
901 cb->addItem(qt_("B6"));
902 cb->addItem(qt_("C0"));
903 cb->addItem(qt_("C1"));
904 cb->addItem(qt_("C2"));
905 cb->addItem(qt_("C3"));
906 cb->addItem(qt_("C4"));
907 cb->addItem(qt_("C5"));
908 cb->addItem(qt_("C6"));
909 cb->addItem(qt_("JIS B0"));
910 cb->addItem(qt_("JIS B1"));
911 cb->addItem(qt_("JIS B2"));
912 cb->addItem(qt_("JIS B3"));
913 cb->addItem(qt_("JIS B4"));
914 cb->addItem(qt_("JIS B5"));
915 cb->addItem(qt_("JIS B6"));
916 // remove the %-items from the unit choice
917 pageLayoutModule->paperwidthUnitCO->noPercents();
918 pageLayoutModule->paperheightUnitCO->noPercents();
919 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
920 pageLayoutModule->paperheightLE));
921 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
922 pageLayoutModule->paperwidthLE));
926 marginsModule = new UiWidget<Ui::MarginsUi>;
927 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
928 this, SLOT(setCustomMargins(bool)));
929 connect(marginsModule->marginCB, SIGNAL(clicked()),
930 this, SLOT(change_adaptor()));
931 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
932 this, SLOT(change_adaptor()));
933 connect(marginsModule->topUnit, SIGNAL(activated(int)),
934 this, SLOT(change_adaptor()));
935 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
936 this, SLOT(change_adaptor()));
937 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
938 this, SLOT(change_adaptor()));
939 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
940 this, SLOT(change_adaptor()));
941 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
942 this, SLOT(change_adaptor()));
943 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
944 this, SLOT(change_adaptor()));
945 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
946 this, SLOT(change_adaptor()));
947 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
948 this, SLOT(change_adaptor()));
949 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
950 this, SLOT(change_adaptor()));
951 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
952 this, SLOT(change_adaptor()));
953 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
954 this, SLOT(change_adaptor()));
955 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
956 this, SLOT(change_adaptor()));
957 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
958 this, SLOT(change_adaptor()));
959 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
960 this, SLOT(change_adaptor()));
961 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
962 this, SLOT(change_adaptor()));
963 marginsModule->topLE->setValidator(unsignedLengthValidator(
964 marginsModule->topLE));
965 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
966 marginsModule->bottomLE));
967 marginsModule->innerLE->setValidator(unsignedLengthValidator(
968 marginsModule->innerLE));
969 marginsModule->outerLE->setValidator(unsignedLengthValidator(
970 marginsModule->outerLE));
971 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
972 marginsModule->headsepLE));
973 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
974 marginsModule->headheightLE));
975 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
976 marginsModule->footskipLE));
977 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
978 marginsModule->columnsepLE));
980 bc().addCheckedLineEdit(marginsModule->topLE,
981 marginsModule->topL);
982 bc().addCheckedLineEdit(marginsModule->bottomLE,
983 marginsModule->bottomL);
984 bc().addCheckedLineEdit(marginsModule->innerLE,
985 marginsModule->innerL);
986 bc().addCheckedLineEdit(marginsModule->outerLE,
987 marginsModule->outerL);
988 bc().addCheckedLineEdit(marginsModule->headsepLE,
989 marginsModule->headsepL);
990 bc().addCheckedLineEdit(marginsModule->headheightLE,
991 marginsModule->headheightL);
992 bc().addCheckedLineEdit(marginsModule->footskipLE,
993 marginsModule->footskipL);
994 bc().addCheckedLineEdit(marginsModule->columnsepLE,
995 marginsModule->columnsepL);
999 langModule = new UiWidget<Ui::LanguageUi>;
1000 connect(langModule->languageCO, SIGNAL(activated(int)),
1001 this, SLOT(change_adaptor()));
1002 connect(langModule->languageCO, SIGNAL(activated(int)),
1003 this, SLOT(languageChanged(int)));
1004 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1005 this, SLOT(change_adaptor()));
1006 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1007 this, SLOT(change_adaptor()));
1008 connect(langModule->encodingCO, SIGNAL(activated(int)),
1009 this, SLOT(change_adaptor()));
1010 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1011 this, SLOT(change_adaptor()));
1012 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1013 this, SLOT(change_adaptor()));
1014 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1015 this, SLOT(change_adaptor()));
1016 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1017 this, SLOT(languagePackageChanged(int)));
1019 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1020 langModule->languagePackageLE));
1022 QAbstractItemModel * language_model = guiApp->languageModel();
1023 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1024 language_model->sort(0);
1025 langModule->languageCO->setModel(language_model);
1026 langModule->languageCO->setModelColumn(0);
1028 // Always put the default encoding in the first position.
1029 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1030 QStringList encodinglist;
1031 Encodings::const_iterator it = encodings.begin();
1032 Encodings::const_iterator const end = encodings.end();
1033 for (; it != end; ++it)
1035 encodinglist.append(qt_(it->guiName()));
1036 encodinglist.sort();
1037 langModule->encodingCO->addItems(encodinglist);
1039 langModule->quoteStyleCO->addItem(
1040 qt_("``text''"),InsetQuotes::EnglishQuotes);
1041 langModule->quoteStyleCO->addItem(
1042 qt_("''text''"), InsetQuotes::SwedishQuotes);
1043 langModule->quoteStyleCO->addItem
1044 (qt_(",,text``"), InsetQuotes::GermanQuotes);
1045 langModule->quoteStyleCO->addItem(
1046 qt_(",,text''"), InsetQuotes::PolishQuotes);
1047 langModule->quoteStyleCO->addItem(
1048 qt_("<<text>>"), InsetQuotes::FrenchQuotes);
1049 langModule->quoteStyleCO->addItem(
1050 qt_(">>text<<"), InsetQuotes::DanishQuotes);
1052 langModule->languagePackageCO->addItem(
1053 qt_("Default"), toqstr("default"));
1054 langModule->languagePackageCO->addItem(
1055 qt_("Automatic"), toqstr("auto"));
1056 langModule->languagePackageCO->addItem(
1057 qt_("Always Babel"), toqstr("babel"));
1058 langModule->languagePackageCO->addItem(
1059 qt_("Custom"), toqstr("custom"));
1060 langModule->languagePackageCO->addItem(
1061 qt_("None[[language package]]"), toqstr("none"));
1065 colorModule = new UiWidget<Ui::ColorUi>;
1066 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1067 this, SLOT(changeFontColor()));
1068 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1069 this, SLOT(deleteFontColor()));
1070 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1071 this, SLOT(changeNoteFontColor()));
1072 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1073 this, SLOT(deleteNoteFontColor()));
1074 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1075 this, SLOT(changeBackgroundColor()));
1076 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1077 this, SLOT(deleteBackgroundColor()));
1078 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1079 this, SLOT(changeBoxBackgroundColor()));
1080 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1081 this, SLOT(deleteBoxBackgroundColor()));
1085 numberingModule = new UiWidget<Ui::NumberingUi>;
1086 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1087 this, SLOT(change_adaptor()));
1088 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1089 this, SLOT(change_adaptor()));
1090 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1091 this, SLOT(updateNumbering()));
1092 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1093 this, SLOT(updateNumbering()));
1094 numberingModule->tocTW->setColumnCount(3);
1095 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1096 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1097 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1098 setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1101 biblioModule = new UiWidget<Ui::BiblioUi>;
1102 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)),
1103 this, SLOT(setNumerical(bool)));
1104 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)),
1105 this, SLOT(setAuthorYear(bool)));
1106 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1107 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1108 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1109 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1110 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1111 this, SLOT(biblioChanged()));
1112 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1113 this, SLOT(biblioChanged()));
1114 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1115 this, SLOT(biblioChanged()));
1116 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1117 this, SLOT(biblioChanged()));
1118 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1119 this, SLOT(biblioChanged()));
1120 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1121 this, SLOT(bibtexChanged(int)));
1122 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1123 this, SLOT(biblioChanged()));
1124 connect(biblioModule->bibtexStyleLE, SIGNAL(textChanged(QString)),
1125 this, SLOT(biblioChanged()));
1127 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1128 biblioModule->bibtexOptionsLE));
1129 biblioModule->bibtexStyleLE->setValidator(new NoNewLineValidator(
1130 biblioModule->bibtexStyleLE));
1132 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1133 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1134 biblioModule->citeStyleCO->setCurrentIndex(0);
1136 // NOTE: we do not provide "custom" here for security reasons!
1137 biblioModule->bibtexCO->clear();
1138 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1139 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1140 it != lyxrc.bibtex_alternatives.end(); ++it) {
1141 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1142 biblioModule->bibtexCO->addItem(command, command);
1147 indicesModule = new GuiIndices;
1148 connect(indicesModule, SIGNAL(changed()),
1149 this, SLOT(change_adaptor()));
1153 mathsModule = new UiWidget<Ui::MathsUi>;
1154 QStringList headers;
1155 headers << qt_("Package") << qt_("Load automatically")
1156 << qt_("Load always") << qt_("Do not load");
1157 mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1158 setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1159 map<string, string> const & packages = BufferParams::auto_packages();
1160 mathsModule->packagesTW->setRowCount(packages.size());
1162 for (map<string, string>::const_iterator it = packages.begin();
1163 it != packages.end(); ++it) {
1164 docstring const package = from_ascii(it->first);
1165 QString autoTooltip = qt_(it->second);
1166 QString alwaysTooltip;
1167 if (package == "amsmath")
1169 qt_("The AMS LaTeX packages are always used");
1171 alwaysTooltip = toqstr(bformat(
1172 _("The LaTeX package %1$s is always used"),
1174 QString neverTooltip;
1175 if (package == "amsmath")
1177 qt_("The AMS LaTeX packages are never used");
1179 neverTooltip = toqstr(bformat(
1180 _("The LaTeX package %1$s is never used"),
1182 QRadioButton * autoRB = new QRadioButton(mathsModule);
1183 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1184 QRadioButton * neverRB = new QRadioButton(mathsModule);
1185 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1186 packageGroup->addButton(autoRB);
1187 packageGroup->addButton(alwaysRB);
1188 packageGroup->addButton(neverRB);
1189 autoRB->setToolTip(autoTooltip);
1190 alwaysRB->setToolTip(alwaysTooltip);
1191 neverRB->setToolTip(neverTooltip);
1192 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1193 mathsModule->packagesTW->setItem(i, 0, pack);
1194 mathsModule->packagesTW->setCellWidget(i, 1, autoRB);
1195 mathsModule->packagesTW->setCellWidget(i, 2, alwaysRB);
1196 mathsModule->packagesTW->setCellWidget(i, 3, neverRB);
1198 connect(autoRB, SIGNAL(clicked()),
1199 this, SLOT(change_adaptor()));
1200 connect(alwaysRB, SIGNAL(clicked()),
1201 this, SLOT(change_adaptor()));
1202 connect(neverRB, SIGNAL(clicked()),
1203 this, SLOT(change_adaptor()));
1206 connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1207 this, SLOT(allPackagesAuto()));
1208 connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1209 this, SLOT(allPackagesAlways()));
1210 connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1211 this, SLOT(allPackagesNot()));
1215 latexModule = new UiWidget<Ui::LaTeXUi>;
1216 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1217 this, SLOT(change_adaptor()));
1218 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1219 this, SLOT(change_adaptor()));
1220 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1221 this, SLOT(change_adaptor()));
1222 connect(latexModule->classCO, SIGNAL(activated(int)),
1223 this, SLOT(classChanged()));
1224 connect(latexModule->classCO, SIGNAL(activated(int)),
1225 this, SLOT(change_adaptor()));
1226 connect(latexModule->layoutPB, SIGNAL(clicked()),
1227 this, SLOT(browseLayout()));
1228 connect(latexModule->layoutPB, SIGNAL(clicked()),
1229 this, SLOT(change_adaptor()));
1230 connect(latexModule->childDocGB, SIGNAL(clicked()),
1231 this, SLOT(change_adaptor()));
1232 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1233 this, SLOT(change_adaptor()));
1234 connect(latexModule->childDocPB, SIGNAL(clicked()),
1235 this, SLOT(browseMaster()));
1236 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1237 this, SLOT(change_adaptor()));
1238 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1239 this, SLOT(change_adaptor()));
1241 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1242 latexModule->optionsLE));
1243 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1244 latexModule->childDocLE));
1246 // postscript drivers
1247 for (int n = 0; tex_graphics[n][0]; ++n) {
1248 QString enc = qt_(tex_graphics_gui[n]);
1249 latexModule->psdriverCO->addItem(enc);
1252 LayoutFileList const & bcl = LayoutFileList::get();
1253 vector<LayoutFileIndex> classList = bcl.classList();
1254 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1256 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1257 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1258 for (int i = 0; cit != cen; ++cit, ++i) {
1259 LayoutFile const & tc = bcl[*cit];
1260 bool const available = tc.isTeXClassAvailable();
1261 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1262 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1263 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1265 docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1266 tooltip += '\n' + toqstr(wrap(bformat(_("Class not found by LyX. "
1267 "Please check if you have the matching %1$s class "
1268 "and all required packages (%2$s) installed."),
1269 output_type, from_utf8(tc.prerequisites(", ")))));
1271 latexModule->classCO->addItemSort(toqstr(tc.name()),
1273 toqstr(translateIfPossible(from_utf8(tc.category()))),
1275 true, true, true, available);
1280 branchesModule = new GuiBranches;
1281 connect(branchesModule, SIGNAL(changed()),
1282 this, SLOT(change_adaptor()));
1283 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1284 this, SLOT(branchesRename(docstring const &, docstring const &)));
1285 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1286 updateUnknownBranches();
1290 preambleModule = new PreambleModule;
1291 connect(preambleModule, SIGNAL(changed()),
1292 this, SLOT(change_adaptor()));
1294 localLayout = new LocalLayout;
1295 connect(localLayout, SIGNAL(changed()),
1296 this, SLOT(change_adaptor()));
1300 bulletsModule = new BulletsModule;
1301 connect(bulletsModule, SIGNAL(changed()),
1302 this, SLOT(change_adaptor()));
1306 modulesModule = new UiWidget<Ui::ModulesUi>;
1307 modulesModule->availableLV->header()->setVisible(false);
1308 setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1309 modulesModule->availableLV->header()->setStretchLastSection(false);
1311 new ModuleSelectionManager(modulesModule->availableLV,
1312 modulesModule->selectedLV,
1313 modulesModule->addPB, modulesModule->deletePB,
1314 modulesModule->upPB, modulesModule->downPB,
1315 availableModel(), selectedModel(), this);
1316 connect(selectionManager, SIGNAL(updateHook()),
1317 this, SLOT(updateModuleInfo()));
1318 connect(selectionManager, SIGNAL(updateHook()),
1319 this, SLOT(change_adaptor()));
1320 connect(selectionManager, SIGNAL(selectionChanged()),
1321 this, SLOT(modulesChanged()));
1325 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1326 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1327 this, SLOT(change_adaptor()));
1328 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1329 this, SLOT(change_adaptor()));
1330 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1331 this, SLOT(change_adaptor()));
1332 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1333 this, SLOT(change_adaptor()));
1334 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1335 this, SLOT(change_adaptor()));
1336 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1337 this, SLOT(change_adaptor()));
1338 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1339 this, SLOT(change_adaptor()));
1340 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1341 this, SLOT(change_adaptor()));
1342 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1343 this, SLOT(change_adaptor()));
1344 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1345 this, SLOT(change_adaptor()));
1346 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1347 this, SLOT(change_adaptor()));
1348 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1349 this, SLOT(change_adaptor()));
1350 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1351 this, SLOT(change_adaptor()));
1352 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1353 this, SLOT(change_adaptor()));
1354 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1355 this, SLOT(change_adaptor()));
1356 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1357 this, SLOT(change_adaptor()));
1359 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1360 pdfSupportModule->titleLE));
1361 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1362 pdfSupportModule->authorLE));
1363 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1364 pdfSupportModule->subjectLE));
1365 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1366 pdfSupportModule->keywordsLE));
1367 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1368 pdfSupportModule->optionsLE));
1370 for (int i = 0; backref_opts[i][0]; ++i)
1371 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1375 floatModule = new FloatPlacement;
1376 connect(floatModule, SIGNAL(changed()),
1377 this, SLOT(change_adaptor()));
1381 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1382 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1383 this, SLOT(change_adaptor()));
1384 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1385 this, SLOT(change_adaptor()));
1386 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1387 this, SLOT(setListingsMessage()));
1388 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1389 this, SLOT(setListingsMessage()));
1390 listingsModule->listingsTB->setPlainText(
1391 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1395 docPS->addPanel(latexModule, N_("Document Class"));
1396 docPS->addPanel(masterChildModule, N_("Child Documents"));
1397 docPS->addPanel(modulesModule, N_("Modules"));
1398 docPS->addPanel(localLayout, N_("Local Layout"));
1399 docPS->addPanel(fontModule, N_("Fonts"));
1400 docPS->addPanel(textLayoutModule, N_("Text Layout"));
1401 docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1402 docPS->addPanel(marginsModule, N_("Page Margins"));
1403 docPS->addPanel(langModule, N_("Language"));
1404 docPS->addPanel(colorModule, N_("Colors"));
1405 docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1406 docPS->addPanel(biblioModule, N_("Bibliography"));
1407 docPS->addPanel(indicesModule, N_("Indexes"));
1408 docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1409 docPS->addPanel(mathsModule, N_("Math Options"));
1410 docPS->addPanel(floatModule, N_("Float Placement"));
1411 docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1412 docPS->addPanel(bulletsModule, N_("Bullets"));
1413 docPS->addPanel(branchesModule, N_("Branches"));
1414 docPS->addPanel(outputModule, N_("Output"));
1415 docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1416 docPS->setCurrentPanel("Document Class");
1417 // FIXME: hack to work around resizing bug in Qt >= 4.2
1418 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1419 #if QT_VERSION >= 0x040200
1420 docPS->updateGeometry();
1425 void GuiDocument::saveDefaultClicked()
1431 void GuiDocument::useDefaultsClicked()
1437 void GuiDocument::change_adaptor()
1443 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1448 string child = fromqstr(item->text(0));
1452 if (std::find(includeonlys_.begin(),
1453 includeonlys_.end(), child) != includeonlys_.end())
1454 includeonlys_.remove(child);
1456 includeonlys_.push_back(child);
1458 updateIncludeonlys();
1463 QString GuiDocument::validateListingsParameters()
1465 // use a cache here to avoid repeated validation
1466 // of the same parameters
1467 static string param_cache;
1468 static QString msg_cache;
1470 if (listingsModule->bypassCB->isChecked())
1473 string params = fromqstr(listingsModule->listingsED->toPlainText());
1474 if (params != param_cache) {
1475 param_cache = params;
1476 msg_cache = toqstr(InsetListingsParams(params).validate());
1482 void GuiDocument::setListingsMessage()
1484 static bool isOK = true;
1485 QString msg = validateListingsParameters();
1486 if (msg.isEmpty()) {
1490 // listingsTB->setTextColor("black");
1491 listingsModule->listingsTB->setPlainText(
1492 qt_("Input listings parameters below. "
1493 "Enter ? for a list of parameters."));
1496 // listingsTB->setTextColor("red");
1497 listingsModule->listingsTB->setPlainText(msg);
1502 void GuiDocument::setLSpacing(int item)
1504 textLayoutModule->lspacingLE->setEnabled(item == 3);
1508 void GuiDocument::setIndent(int item)
1510 bool const enable = (item == 1);
1511 textLayoutModule->indentLE->setEnabled(enable);
1512 textLayoutModule->indentLengthCO->setEnabled(enable);
1513 textLayoutModule->skipLE->setEnabled(false);
1514 textLayoutModule->skipLengthCO->setEnabled(false);
1519 void GuiDocument::enableIndent(bool indent)
1521 textLayoutModule->skipLE->setEnabled(!indent);
1522 textLayoutModule->skipLengthCO->setEnabled(!indent);
1524 setIndent(textLayoutModule->indentCO->currentIndex());
1528 void GuiDocument::setSkip(int item)
1530 bool const enable = (item == 3);
1531 textLayoutModule->skipLE->setEnabled(enable);
1532 textLayoutModule->skipLengthCO->setEnabled(enable);
1537 void GuiDocument::enableSkip(bool skip)
1539 textLayoutModule->indentLE->setEnabled(!skip);
1540 textLayoutModule->indentLengthCO->setEnabled(!skip);
1542 setSkip(textLayoutModule->skipCO->currentIndex());
1546 void GuiDocument::setMargins()
1548 bool const extern_geometry =
1549 documentClass().provides("geometry");
1550 marginsModule->marginCB->setEnabled(!extern_geometry);
1551 if (extern_geometry) {
1552 marginsModule->marginCB->setChecked(false);
1553 setCustomMargins(true);
1555 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1556 setCustomMargins(!bp_.use_geometry);
1561 void GuiDocument::papersizeChanged(int paper_size)
1563 setCustomPapersize(paper_size == 1);
1567 void GuiDocument::setCustomPapersize(bool custom)
1569 pageLayoutModule->paperwidthL->setEnabled(custom);
1570 pageLayoutModule->paperwidthLE->setEnabled(custom);
1571 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1572 pageLayoutModule->paperheightL->setEnabled(custom);
1573 pageLayoutModule->paperheightLE->setEnabled(custom);
1574 pageLayoutModule->paperheightLE->setFocus();
1575 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1579 void GuiDocument::setColSep()
1581 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1585 void GuiDocument::setCustomMargins(bool custom)
1587 marginsModule->topL->setEnabled(!custom);
1588 marginsModule->topLE->setEnabled(!custom);
1589 marginsModule->topUnit->setEnabled(!custom);
1591 marginsModule->bottomL->setEnabled(!custom);
1592 marginsModule->bottomLE->setEnabled(!custom);
1593 marginsModule->bottomUnit->setEnabled(!custom);
1595 marginsModule->innerL->setEnabled(!custom);
1596 marginsModule->innerLE->setEnabled(!custom);
1597 marginsModule->innerUnit->setEnabled(!custom);
1599 marginsModule->outerL->setEnabled(!custom);
1600 marginsModule->outerLE->setEnabled(!custom);
1601 marginsModule->outerUnit->setEnabled(!custom);
1603 marginsModule->headheightL->setEnabled(!custom);
1604 marginsModule->headheightLE->setEnabled(!custom);
1605 marginsModule->headheightUnit->setEnabled(!custom);
1607 marginsModule->headsepL->setEnabled(!custom);
1608 marginsModule->headsepLE->setEnabled(!custom);
1609 marginsModule->headsepUnit->setEnabled(!custom);
1611 marginsModule->footskipL->setEnabled(!custom);
1612 marginsModule->footskipLE->setEnabled(!custom);
1613 marginsModule->footskipUnit->setEnabled(!custom);
1615 bool const enableColSep = !custom &&
1616 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1617 marginsModule->columnsepL->setEnabled(enableColSep);
1618 marginsModule->columnsepLE->setEnabled(enableColSep);
1619 marginsModule->columnsepUnit->setEnabled(enableColSep);
1623 void GuiDocument::changeBackgroundColor()
1625 QColor const & newColor = QColorDialog::getColor(
1626 rgb2qcolor(set_backgroundcolor), asQWidget());
1627 if (!newColor.isValid())
1629 // set the button color and text
1630 colorModule->backgroundPB->setStyleSheet(
1631 colorButtonStyleSheet(newColor));
1632 colorModule->backgroundPB->setText(qt_("&Change..."));
1634 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1635 is_backgroundcolor = true;
1640 void GuiDocument::deleteBackgroundColor()
1642 // set the button color back to default by setting an empty StyleSheet
1643 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1644 // change button text
1645 colorModule->backgroundPB->setText(qt_("&Default..."));
1646 // save default color (white)
1647 set_backgroundcolor = rgbFromHexName("#ffffff");
1648 is_backgroundcolor = false;
1653 void GuiDocument::changeFontColor()
1655 QColor const & newColor = QColorDialog::getColor(
1656 rgb2qcolor(set_fontcolor), asQWidget());
1657 if (!newColor.isValid())
1659 // set the button color and text
1660 colorModule->fontColorPB->setStyleSheet(
1661 colorButtonStyleSheet(newColor));
1662 colorModule->fontColorPB->setText(qt_("&Change..."));
1664 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1665 is_fontcolor = true;
1670 void GuiDocument::deleteFontColor()
1672 // set the button color back to default by setting an empty StyleSheet
1673 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1674 // change button text
1675 colorModule->fontColorPB->setText(qt_("&Default..."));
1676 // save default color (black)
1677 set_fontcolor = rgbFromHexName("#000000");
1678 is_fontcolor = false;
1683 void GuiDocument::changeNoteFontColor()
1685 QColor const & newColor = QColorDialog::getColor(
1686 rgb2qcolor(set_notefontcolor), asQWidget());
1687 if (!newColor.isValid())
1689 // set the button color
1690 colorModule->noteFontColorPB->setStyleSheet(
1691 colorButtonStyleSheet(newColor));
1693 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1698 void GuiDocument::deleteNoteFontColor()
1700 // set the button color back to pref
1701 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1702 colorModule->noteFontColorPB->setStyleSheet(
1703 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1708 void GuiDocument::changeBoxBackgroundColor()
1710 QColor const & newColor = QColorDialog::getColor(
1711 rgb2qcolor(set_boxbgcolor), asQWidget());
1712 if (!newColor.isValid())
1714 // set the button color
1715 colorModule->boxBackgroundPB->setStyleSheet(
1716 colorButtonStyleSheet(newColor));
1718 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1723 void GuiDocument::deleteBoxBackgroundColor()
1725 // set the button color back to pref
1726 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1727 colorModule->boxBackgroundPB->setStyleSheet(
1728 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1733 void GuiDocument::languageChanged(int i)
1735 // some languages only work with polyglossia/XeTeX
1736 Language const * lang = lyx::languages.getLanguage(
1737 fromqstr(langModule->languageCO->itemData(i).toString()));
1738 if (lang->babel().empty() && !lang->polyglossia().empty()) {
1739 // If we force to switch fontspec on, store
1740 // current state (#8717)
1741 if (fontModule->osFontsCB->isEnabled())
1742 forced_fontspec_activation =
1743 !fontModule->osFontsCB->isChecked();
1744 fontModule->osFontsCB->setChecked(true);
1745 fontModule->osFontsCB->setEnabled(false);
1748 fontModule->osFontsCB->setEnabled(true);
1749 // If we have forced to switch fontspec on,
1750 // restore previous state (#8717)
1751 if (forced_fontspec_activation)
1752 fontModule->osFontsCB->setChecked(false);
1753 forced_fontspec_activation = false;
1756 // set appropriate quotation mark style
1757 if (!lang->quoteStyle().empty()) {
1758 langModule->quoteStyleCO->setCurrentIndex(
1759 bp_.getQuoteStyle(lang->quoteStyle()));
1764 void GuiDocument::osFontsChanged(bool nontexfonts)
1766 bool const tex_fonts = !nontexfonts;
1768 // store default format
1769 QString const dformat = outputModule->defaultFormatCO->itemData(
1770 outputModule->defaultFormatCO->currentIndex()).toString();
1771 updateDefaultFormat();
1772 // try to restore default format
1773 int index = outputModule->defaultFormatCO->findData(dformat);
1774 // set to default if format is not found
1777 outputModule->defaultFormatCO->setCurrentIndex(index);
1778 langModule->encodingCO->setEnabled(tex_fonts &&
1779 !langModule->defaultencodingRB->isChecked());
1780 langModule->defaultencodingRB->setEnabled(tex_fonts);
1781 langModule->otherencodingRB->setEnabled(tex_fonts);
1783 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1784 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1785 fontModule->cjkFontLE->setEnabled(tex_fonts);
1786 fontModule->cjkFontLA->setEnabled(tex_fonts);
1788 updateFontOptions();
1790 fontModule->fontencLA->setEnabled(tex_fonts);
1791 fontModule->fontencCO->setEnabled(tex_fonts);
1793 fontModule->fontencLE->setEnabled(false);
1795 fontencChanged(fontModule->fontencCO->currentIndex());
1799 void GuiDocument::mathFontChanged(int)
1801 updateFontOptions();
1805 void GuiDocument::fontOsfToggled(bool state)
1807 if (fontModule->osFontsCB->isChecked())
1809 QString font = fontModule->fontsRomanCO->itemData(
1810 fontModule->fontsRomanCO->currentIndex()).toString();
1811 if (hasMonolithicExpertSet(font))
1812 fontModule->fontScCB->setChecked(state);
1816 void GuiDocument::fontScToggled(bool state)
1818 if (fontModule->osFontsCB->isChecked())
1820 QString font = fontModule->fontsRomanCO->itemData(
1821 fontModule->fontsRomanCO->currentIndex()).toString();
1822 if (hasMonolithicExpertSet(font))
1823 fontModule->fontOsfCB->setChecked(state);
1827 void GuiDocument::updateFontOptions()
1829 bool const tex_fonts = !fontModule->osFontsCB->isChecked();
1832 font = fontModule->fontsSansCO->itemData(
1833 fontModule->fontsSansCO->currentIndex()).toString();
1834 bool scaleable = providesScale(font);
1835 fontModule->scaleSansSB->setEnabled(scaleable);
1836 fontModule->scaleSansLA->setEnabled(scaleable);
1838 font = fontModule->fontsTypewriterCO->itemData(
1839 fontModule->fontsTypewriterCO->currentIndex()).toString();
1840 scaleable = providesScale(font);
1841 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1842 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1844 font = fontModule->fontsRomanCO->itemData(
1845 fontModule->fontsRomanCO->currentIndex()).toString();
1846 fontModule->fontScCB->setEnabled(providesSC(font));
1847 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1848 updateMathFonts(font);
1852 void GuiDocument::updateFontsize(string const & items, string const & sel)
1854 fontModule->fontsizeCO->clear();
1855 fontModule->fontsizeCO->addItem(qt_("Default"));
1857 for (int n = 0; !token(items,'|',n).empty(); ++n)
1858 fontModule->fontsizeCO->
1859 addItem(toqstr(token(items,'|',n)));
1861 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1862 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1863 fontModule->fontsizeCO->setCurrentIndex(n);
1870 bool GuiDocument::ot1() const
1872 QString const fontenc =
1873 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
1874 return (fontenc == "default"
1875 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
1876 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
1880 bool GuiDocument::completeFontset() const
1882 return (fontModule->fontsSansCO->itemData(
1883 fontModule->fontsSansCO->currentIndex()).toString() == "default"
1884 && fontModule->fontsSansCO->itemData(
1885 fontModule->fontsSansCO->currentIndex()).toString() == "default");
1889 bool GuiDocument::noMathFont() const
1891 return (fontModule->fontsMathCO->itemData(
1892 fontModule->fontsMathCO->currentIndex()).toString() == "default");
1896 void GuiDocument::updateTexFonts()
1898 LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
1900 LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
1901 LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
1902 for (; it != end; ++it) {
1903 LaTeXFont lf = it->second;
1904 if (lf.name().empty()) {
1905 LYXERR0("Error: Unnamed font: " << it->first);
1908 docstring const family = lf.family();
1909 docstring guiname = translateIfPossible(lf.guiname());
1910 if (!lf.available(ot1(), noMathFont()))
1911 guiname += _(" (not installed)");
1913 rmfonts_.insert(toqstr(guiname), toqstr(it->first));
1914 else if (family == "sf")
1915 sffonts_.insert(toqstr(guiname), toqstr(it->first));
1916 else if (family == "tt")
1917 ttfonts_.insert(toqstr(guiname), toqstr(it->first));
1918 else if (family == "math")
1919 mathfonts_.insert(toqstr(guiname), toqstr(it->first));
1924 void GuiDocument::updateFontlist()
1926 fontModule->fontsRomanCO->clear();
1927 fontModule->fontsSansCO->clear();
1928 fontModule->fontsTypewriterCO->clear();
1929 fontModule->fontsMathCO->clear();
1931 // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
1932 if (fontModule->osFontsCB->isChecked()) {
1933 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1934 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1935 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1936 QString unimath = qt_("Non-TeX Fonts Default");
1937 if (!LaTeXFeatures::isAvailable("unicode-math"))
1938 unimath += qt_(" (not available)");
1939 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
1940 fontModule->fontsMathCO->addItem(unimath, QString("default"));
1942 QFontDatabase fontdb;
1943 QStringList families(fontdb.families());
1944 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1945 fontModule->fontsRomanCO->addItem(*it, *it);
1946 fontModule->fontsSansCO->addItem(*it, *it);
1947 fontModule->fontsTypewriterCO->addItem(*it, *it);
1952 if (rmfonts_.empty())
1955 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1956 QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
1957 while (rmi != rmfonts_.constEnd()) {
1958 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
1962 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1963 QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
1964 while (sfi != sffonts_.constEnd()) {
1965 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
1969 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1970 QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
1971 while (tti != ttfonts_.constEnd()) {
1972 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
1976 fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
1977 fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
1978 QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
1979 while (mmi != mathfonts_.constEnd()) {
1980 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
1986 void GuiDocument::fontencChanged(int item)
1988 fontModule->fontencLE->setEnabled(
1989 fontModule->fontencCO->itemData(item).toString() == "custom");
1990 // The availability of TeX fonts depends on the font encoding
1992 updateFontOptions();
1996 void GuiDocument::updateMathFonts(QString const & rm)
1998 if (fontModule->osFontsCB->isChecked())
2000 QString const math =
2001 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2002 int const i = fontModule->fontsMathCO->findData("default");
2003 if (providesNoMath(rm) && i == -1)
2004 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2005 else if (!providesNoMath(rm) && i != -1) {
2006 int const c = fontModule->fontsMathCO->currentIndex();
2007 fontModule->fontsMathCO->removeItem(i);
2009 fontModule->fontsMathCO->setCurrentIndex(0);
2014 void GuiDocument::romanChanged(int item)
2016 if (fontModule->osFontsCB->isChecked())
2018 QString const font =
2019 fontModule->fontsRomanCO->itemData(item).toString();
2020 fontModule->fontScCB->setEnabled(providesSC(font));
2021 fontModule->fontOsfCB->setEnabled(providesOSF(font));
2022 updateMathFonts(font);
2026 void GuiDocument::sansChanged(int item)
2028 if (fontModule->osFontsCB->isChecked())
2030 QString const font =
2031 fontModule->fontsSansCO->itemData(item).toString();
2032 bool scaleable = providesScale(font);
2033 fontModule->scaleSansSB->setEnabled(scaleable);
2034 fontModule->scaleSansLA->setEnabled(scaleable);
2038 void GuiDocument::ttChanged(int item)
2040 if (fontModule->osFontsCB->isChecked())
2042 QString const font =
2043 fontModule->fontsTypewriterCO->itemData(item).toString();
2044 bool scaleable = providesScale(font);
2045 fontModule->scaleTypewriterSB->setEnabled(scaleable);
2046 fontModule->scaleTypewriterLA->setEnabled(scaleable);
2050 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2053 pageLayoutModule->pagestyleCO->clear();
2054 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2056 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2057 string style = token(items, '|', n);
2058 QString style_gui = qt_(style);
2059 pagestyles.push_back(pair<string, QString>(style, style_gui));
2060 pageLayoutModule->pagestyleCO->addItem(style_gui);
2063 if (sel == "default") {
2064 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2070 for (size_t i = 0; i < pagestyles.size(); ++i)
2071 if (pagestyles[i].first == sel)
2072 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2075 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2079 void GuiDocument::browseLayout()
2081 QString const label1 = qt_("Layouts|#o#O");
2082 QString const dir1 = toqstr(lyxrc.document_path);
2083 QStringList const filter(qt_("LyX Layout (*.layout)"));
2084 QString file = browseRelToParent(QString(), bufferFilePath(),
2085 qt_("Local layout file"), filter, false,
2088 if (!file.endsWith(".layout"))
2091 FileName layoutFile = support::makeAbsPath(fromqstr(file),
2092 fromqstr(bufferFilePath()));
2094 int const ret = Alert::prompt(_("Local layout file"),
2095 _("The layout file you have selected is a local layout\n"
2096 "file, not one in the system or user directory. Your\n"
2097 "document may not work with this layout if you do not\n"
2098 "keep the layout file in the document directory."),
2099 1, 1, _("&Set Layout"), _("&Cancel"));
2103 // load the layout file
2104 LayoutFileList & bcl = LayoutFileList::get();
2105 string classname = layoutFile.onlyFileName();
2106 // this will update an existing layout if that layout has been loaded before.
2107 LayoutFileIndex name = bcl.addLocalLayout(
2108 classname.substr(0, classname.size() - 7),
2109 layoutFile.onlyPath().absFileName());
2112 Alert::error(_("Error"),
2113 _("Unable to read local layout file."));
2117 // do not trigger classChanged if there is no change.
2118 if (latexModule->classCO->currentText() == toqstr(name))
2122 bool const avail = latexModule->classCO->set(toqstr(name));
2124 LayoutFile const & tc = bcl[name];
2125 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2126 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2127 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2128 tooltip += '\n' + qt_("This is a local layout file.");
2129 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2130 toqstr(translateIfPossible(from_utf8(tc.category()))),
2132 true, true, true, true);
2133 latexModule->classCO->set(toqstr(name));
2140 void GuiDocument::browseMaster()
2142 QString const title = qt_("Select master document");
2143 QString const dir1 = toqstr(lyxrc.document_path);
2144 QString const old = latexModule->childDocLE->text();
2145 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2146 QStringList const filter(qt_("LyX Files (*.lyx)"));
2147 QString file = browseRelToSub(old, docpath, title, filter, false,
2148 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
2150 if (!file.isEmpty())
2151 latexModule->childDocLE->setText(file);
2155 void GuiDocument::classChanged()
2157 int idx = latexModule->classCO->currentIndex();
2160 string const classname = fromqstr(latexModule->classCO->getData(idx));
2162 // check whether the selected modules have changed.
2163 bool modules_changed = false;
2164 unsigned int const srows = selectedModel()->rowCount();
2165 if (srows != bp_.getModules().size())
2166 modules_changed = true;
2168 list<string>::const_iterator mit = bp_.getModules().begin();
2169 list<string>::const_iterator men = bp_.getModules().end();
2170 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
2171 if (selectedModel()->getIDString(i) != *mit) {
2172 modules_changed = true;
2177 if (modules_changed || lyxrc.auto_reset_options) {
2178 if (applyPB->isEnabled()) {
2179 int const ret = Alert::prompt(_("Unapplied changes"),
2180 _("Some changes in the dialog were not yet applied.\n"
2181 "If you do not apply now, they will be lost after this action."),
2182 1, 1, _("&Apply"), _("&Dismiss"));
2188 // We load the TextClass as soon as it is selected. This is
2189 // necessary so that other options in the dialog can be updated
2190 // according to the new class. Note, however, that, if you use
2191 // the scroll wheel when sitting on the combo box, we'll load a
2192 // lot of TextClass objects very quickly....
2193 if (!bp_.setBaseClass(classname)) {
2194 Alert::error(_("Error"), _("Unable to set document class."));
2197 if (lyxrc.auto_reset_options)
2198 bp_.useClassDefaults();
2200 // With the introduction of modules came a distinction between the base
2201 // class and the document class. The former corresponds to the main layout
2202 // file; the latter is that plus the modules (or the document-specific layout,
2203 // or whatever else there could be). Our parameters come from the document
2204 // class. So when we set the base class, we also need to recreate the document
2205 // class. Otherwise, we still have the old one.
2206 bp_.makeDocumentClass();
2211 void GuiDocument::languagePackageChanged(int i)
2213 langModule->languagePackageLE->setEnabled(
2214 langModule->languagePackageCO->itemData(i).toString() == "custom");
2218 void GuiDocument::biblioChanged()
2220 biblioChanged_ = true;
2225 void GuiDocument::bibtexChanged(int n)
2227 biblioModule->bibtexOptionsLE->setEnabled(
2228 biblioModule->bibtexCO->itemData(n).toString() != "default");
2233 void GuiDocument::setAuthorYear(bool authoryear)
2236 biblioModule->citeStyleCO->setCurrentIndex(0);
2241 void GuiDocument::setNumerical(bool numerical)
2244 biblioModule->citeStyleCO->setCurrentIndex(1);
2249 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2251 engine_types_.clear();
2255 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2257 string style = token(items, '|', n);
2258 engine_types_.push_back(style);
2262 case ENGINE_TYPE_AUTHORYEAR:
2263 biblioModule->citeStyleCO->setCurrentIndex(0);
2265 case ENGINE_TYPE_NUMERICAL:
2266 case ENGINE_TYPE_DEFAULT:
2267 biblioModule->citeStyleCO->setCurrentIndex(1);
2271 biblioModule->citationStyleL->setEnabled(nn > 1);
2272 biblioModule->citeStyleCO->setEnabled(nn > 1);
2277 // If the textclass allows only one of authoryear or numerical,
2278 // we have no choice but to force that engine type.
2279 if (engine_types_[0] == "authoryear")
2280 biblioModule->citeStyleCO->setCurrentIndex(0);
2282 biblioModule->citeStyleCO->setCurrentIndex(1);
2288 // both of these should take a vector<docstring>
2290 // This is an insanely complicated attempt to make this sort of thing
2291 // work with RTL languages.
2292 docstring formatStrVec(vector<string> const & v, docstring const & s)
2294 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2298 return translateIfPossible(from_utf8(v[0]));
2299 if (v.size() == 2) {
2300 docstring retval = _("%1$s and %2$s");
2301 retval = subst(retval, _("and"), s);
2302 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2303 translateIfPossible(from_utf8(v[1])));
2305 // The idea here is to format all but the last two items...
2306 int const vSize = v.size();
2307 docstring t2 = _("%1$s, %2$s");
2308 docstring retval = translateIfPossible(from_utf8(v[0]));
2309 for (int i = 1; i < vSize - 2; ++i)
2310 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2311 //...and then to plug them, and the last two, into this schema
2312 docstring t = _("%1$s, %2$s, and %3$s");
2313 t = subst(t, _("and"), s);
2314 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2315 translateIfPossible(from_utf8(v[vSize - 1])));
2318 vector<string> idsToNames(vector<string> const & idList)
2320 vector<string> retval;
2321 vector<string>::const_iterator it = idList.begin();
2322 vector<string>::const_iterator end = idList.end();
2323 for (; it != end; ++it) {
2324 LyXModule const * const mod = theModuleList[*it];
2326 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2327 translateIfPossible(from_utf8(*it)))));
2329 retval.push_back(mod->getName());
2333 } // end anonymous namespace
2336 void GuiDocument::modulesToParams(BufferParams & bp)
2338 // update list of loaded modules
2339 bp.clearLayoutModules();
2340 int const srows = modules_sel_model_.rowCount();
2341 for (int i = 0; i < srows; ++i)
2342 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2344 // update the list of removed modules
2345 bp.clearRemovedModules();
2346 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2347 list<string>::const_iterator rit = reqmods.begin();
2348 list<string>::const_iterator ren = reqmods.end();
2350 // check each of the default modules
2351 for (; rit != ren; ++rit) {
2352 list<string>::const_iterator mit = bp.getModules().begin();
2353 list<string>::const_iterator men = bp.getModules().end();
2355 for (; mit != men; ++mit) {
2362 // the module isn't present so must have been removed by the user
2363 bp.addRemovedModule(*rit);
2368 void GuiDocument::modulesChanged()
2370 modulesToParams(bp_);
2371 bp_.makeDocumentClass();
2376 void GuiDocument::updateModuleInfo()
2378 selectionManager->update();
2380 //Module description
2381 bool const focus_on_selected = selectionManager->selectedFocused();
2382 QAbstractItemView * lv;
2383 if (focus_on_selected)
2384 lv = modulesModule->selectedLV;
2386 lv = modulesModule->availableLV;
2387 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2388 modulesModule->infoML->document()->clear();
2391 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2392 GuiIdListModel const & id_model =
2393 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2394 string const modName = id_model.getIDString(idx.row());
2395 docstring desc = getModuleDescription(modName);
2397 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2398 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2401 desc += _("Module provided by document class.");
2404 docstring cat = getModuleCategory(modName);
2408 desc += bformat(_("Category: %1$s."), cat);
2411 vector<string> pkglist = getPackageList(modName);
2412 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2413 if (!pkgdesc.empty()) {
2416 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2419 pkglist = getRequiredList(modName);
2420 if (!pkglist.empty()) {
2421 vector<string> const reqdescs = idsToNames(pkglist);
2422 pkgdesc = formatStrVec(reqdescs, _("or"));
2425 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2428 pkglist = getExcludedList(modName);
2429 if (!pkglist.empty()) {
2430 vector<string> const reqdescs = idsToNames(pkglist);
2431 pkgdesc = formatStrVec(reqdescs, _( "and"));
2434 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2437 if (!isModuleAvailable(modName)) {
2440 desc += _("WARNING: Some required packages are unavailable!");
2443 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2447 void GuiDocument::updateNumbering()
2449 DocumentClass const & tclass = documentClass();
2451 numberingModule->tocTW->setUpdatesEnabled(false);
2452 numberingModule->tocTW->clear();
2454 int const depth = numberingModule->depthSL->value();
2455 int const toc = numberingModule->tocSL->value();
2456 QString const no = qt_("No");
2457 QString const yes = qt_("Yes");
2458 QTreeWidgetItem * item = 0;
2460 DocumentClass::const_iterator lit = tclass.begin();
2461 DocumentClass::const_iterator len = tclass.end();
2462 for (; lit != len; ++lit) {
2463 int const toclevel = lit->toclevel;
2464 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2465 item = new QTreeWidgetItem(numberingModule->tocTW);
2466 item->setText(0, toqstr(translateIfPossible(lit->name())));
2467 item->setText(1, (toclevel <= depth) ? yes : no);
2468 item->setText(2, (toclevel <= toc) ? yes : no);
2472 numberingModule->tocTW->setUpdatesEnabled(true);
2473 numberingModule->tocTW->update();
2477 void GuiDocument::updateDefaultFormat()
2481 // make a copy in order to consider unapplied changes
2482 BufferParams param_copy = buffer().params();
2483 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2484 int const idx = latexModule->classCO->currentIndex();
2486 string const classname = fromqstr(latexModule->classCO->getData(idx));
2487 param_copy.setBaseClass(classname);
2488 param_copy.makeDocumentClass();
2490 outputModule->defaultFormatCO->blockSignals(true);
2491 outputModule->defaultFormatCO->clear();
2492 outputModule->defaultFormatCO->addItem(qt_("Default"),
2493 QVariant(QString("default")));
2494 typedef vector<Format const *> Formats;
2495 Formats formats = param_copy.exportableFormats(true);
2496 sort(formats.begin(), formats.end(), Format::formatSorter);
2497 Formats::const_iterator cit = formats.begin();
2498 Formats::const_iterator end = formats.end();
2499 for (; cit != end; ++cit)
2500 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2501 QVariant(toqstr((*cit)->name())));
2502 outputModule->defaultFormatCO->blockSignals(false);
2506 bool GuiDocument::isChildIncluded(string const & child)
2508 if (includeonlys_.empty())
2510 return (std::find(includeonlys_.begin(),
2511 includeonlys_.end(), child) != includeonlys_.end());
2515 void GuiDocument::applyView()
2518 preambleModule->apply(bp_);
2519 localLayout->apply(bp_);
2522 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2523 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2526 if (biblioModule->citeNatbibRB->isChecked())
2527 bp_.setCiteEngine("natbib");
2528 else if (biblioModule->citeJurabibRB->isChecked())
2529 bp_.setCiteEngine("jurabib");
2530 if (biblioModule->citeDefaultRB->isChecked()) {
2531 bp_.setCiteEngine("basic");
2532 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2535 if (biblioModule->citeStyleCO->currentIndex())
2536 bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
2538 bp_.setCiteEngineType(ENGINE_TYPE_AUTHORYEAR);
2541 biblioModule->bibtopicCB->isChecked();
2543 bp_.biblio_style = fromqstr(biblioModule->bibtexStyleLE->text());
2545 string const bibtex_command =
2546 fromqstr(biblioModule->bibtexCO->itemData(
2547 biblioModule->bibtexCO->currentIndex()).toString());
2548 string const bibtex_options =
2549 fromqstr(biblioModule->bibtexOptionsLE->text());
2550 if (bibtex_command == "default" || bibtex_options.empty())
2551 bp_.bibtex_command = bibtex_command;
2553 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2555 if (biblioChanged_) {
2556 buffer().invalidateBibinfoCache();
2557 buffer().removeBiblioTempFiles();
2561 indicesModule->apply(bp_);
2563 // language & quotes
2564 if (langModule->defaultencodingRB->isChecked()) {
2565 bp_.inputenc = "auto";
2567 int i = langModule->encodingCO->currentIndex();
2569 bp_.inputenc = "default";
2571 QString const enc_gui =
2572 langModule->encodingCO->currentText();
2573 Encodings::const_iterator it = encodings.begin();
2574 Encodings::const_iterator const end = encodings.end();
2576 for (; it != end; ++it) {
2577 if (qt_(it->guiName()) == enc_gui &&
2579 bp_.inputenc = it->name();
2585 // should not happen
2586 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2587 bp_.inputenc = "default";
2592 bp_.quotes_language = (InsetQuotes::QuoteLanguage) langModule->quoteStyleCO->itemData(
2593 langModule->quoteStyleCO->currentIndex()).toInt();
2595 QString const lang = langModule->languageCO->itemData(
2596 langModule->languageCO->currentIndex()).toString();
2597 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2599 QString const pack = langModule->languagePackageCO->itemData(
2600 langModule->languagePackageCO->currentIndex()).toString();
2601 if (pack == "custom")
2603 fromqstr(langModule->languagePackageLE->text());
2605 bp_.lang_package = fromqstr(pack);
2608 bp_.backgroundcolor = set_backgroundcolor;
2609 bp_.isbackgroundcolor = is_backgroundcolor;
2610 bp_.fontcolor = set_fontcolor;
2611 bp_.isfontcolor = is_fontcolor;
2612 bp_.notefontcolor = set_notefontcolor;
2613 bp_.boxbgcolor = set_boxbgcolor;
2616 if (bp_.documentClass().hasTocLevels()) {
2617 bp_.tocdepth = numberingModule->tocSL->value();
2618 bp_.secnumdepth = numberingModule->depthSL->value();
2622 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2623 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2624 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2625 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2628 bp_.graphics_driver =
2629 tex_graphics[latexModule->psdriverCO->currentIndex()];
2632 int idx = latexModule->classCO->currentIndex();
2634 string const classname = fromqstr(latexModule->classCO->getData(idx));
2635 bp_.setBaseClass(classname);
2639 modulesToParams(bp_);
2642 map<string, string> const & packages = BufferParams::auto_packages();
2643 for (map<string, string>::const_iterator it = packages.begin();
2644 it != packages.end(); ++it) {
2645 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
2648 int row = mathsModule->packagesTW->row(item);
2649 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
2650 if (rb->isChecked()) {
2651 bp_.use_package(it->first, BufferParams::package_auto);
2654 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
2655 if (rb->isChecked()) {
2656 bp_.use_package(it->first, BufferParams::package_on);
2659 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
2660 if (rb->isChecked())
2661 bp_.use_package(it->first, BufferParams::package_off);
2665 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2666 bp_.pagestyle = "default";
2668 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2669 for (size_t i = 0; i != pagestyles.size(); ++i)
2670 if (pagestyles[i].second == style_gui)
2671 bp_.pagestyle = pagestyles[i].first;
2675 switch (textLayoutModule->lspacingCO->currentIndex()) {
2677 bp_.spacing().set(Spacing::Single);
2680 bp_.spacing().set(Spacing::Onehalf);
2683 bp_.spacing().set(Spacing::Double);
2686 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2688 bp_.spacing().set(Spacing::Single);
2690 bp_.spacing().set(Spacing::Other, s);
2695 if (textLayoutModule->twoColumnCB->isChecked())
2700 bp_.justification = textLayoutModule->justCB->isChecked();
2702 if (textLayoutModule->indentRB->isChecked()) {
2703 // if paragraphs are separated by an indentation
2704 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2705 switch (textLayoutModule->indentCO->currentIndex()) {
2707 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2710 HSpace indent = HSpace(
2711 widgetsToLength(textLayoutModule->indentLE,
2712 textLayoutModule->indentLengthCO)
2714 bp_.setIndentation(indent);
2718 // this should never happen
2719 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2723 // if paragraphs are separated by a skip
2724 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2725 switch (textLayoutModule->skipCO->currentIndex()) {
2727 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2730 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2733 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2738 widgetsToLength(textLayoutModule->skipLE,
2739 textLayoutModule->skipLengthCO)
2745 // this should never happen
2746 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2752 fromqstr(latexModule->optionsLE->text());
2754 bp_.use_default_options =
2755 latexModule->defaultOptionsCB->isChecked();
2757 if (latexModule->childDocGB->isChecked())
2759 fromqstr(latexModule->childDocLE->text());
2761 bp_.master = string();
2764 bp_.clearIncludedChildren();
2765 if (masterChildModule->includeonlyRB->isChecked()) {
2766 list<string>::const_iterator it = includeonlys_.begin();
2767 for (; it != includeonlys_.end() ; ++it) {
2768 bp_.addIncludedChildren(*it);
2771 bp_.maintain_unincluded_children =
2772 masterChildModule->maintainAuxCB->isChecked();
2775 bp_.float_placement = floatModule->get();
2778 // text should have passed validation
2779 bp_.listings_params =
2780 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2783 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
2784 outputModule->defaultFormatCO->currentIndex()).toString());
2786 bool const nontexfonts = fontModule->osFontsCB->isChecked();
2787 bp_.useNonTeXFonts = nontexfonts;
2789 bp_.output_sync = outputModule->outputsyncCB->isChecked();
2791 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2793 int mathfmt = outputModule->mathoutCB->currentIndex();
2796 BufferParams::MathOutput const mo =
2797 static_cast<BufferParams::MathOutput>(mathfmt);
2798 bp_.html_math_output = mo;
2799 bp_.html_be_strict = outputModule->strictCB->isChecked();
2800 bp_.html_css_as_file = outputModule->cssCB->isChecked();
2801 bp_.html_math_img_scale = outputModule->mathimgSB->value();
2805 fromqstr(fontModule->fontsRomanCO->
2806 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
2809 fromqstr(fontModule->fontsSansCO->
2810 itemData(fontModule->fontsSansCO->currentIndex()).toString());
2812 bp_.fonts_typewriter =
2813 fromqstr(fontModule->fontsTypewriterCO->
2814 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
2817 fromqstr(fontModule->fontsMathCO->
2818 itemData(fontModule->fontsMathCO->currentIndex()).toString());
2820 QString const fontenc =
2821 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2822 if (fontenc == "custom")
2823 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2825 bp_.fontenc = fromqstr(fontenc);
2828 fromqstr(fontModule->cjkFontLE->text());
2830 bp_.fonts_sans_scale = fontModule->scaleSansSB->value();
2832 bp_.fonts_typewriter_scale = fontModule->scaleTypewriterSB->value();
2834 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
2836 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
2839 bp_.fonts_default_family = "default";
2841 bp_.fonts_default_family = GuiDocument::fontfamilies[
2842 fontModule->fontsDefaultCO->currentIndex()];
2844 if (fontModule->fontsizeCO->currentIndex() == 0)
2845 bp_.fontsize = "default";
2848 fromqstr(fontModule->fontsizeCO->currentText());
2851 bp_.papersize = PAPER_SIZE(
2852 pageLayoutModule->papersizeCO->currentIndex());
2854 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2855 pageLayoutModule->paperwidthUnitCO);
2857 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2858 pageLayoutModule->paperheightUnitCO);
2860 if (pageLayoutModule->facingPagesCB->isChecked())
2861 bp_.sides = TwoSides;
2863 bp_.sides = OneSide;
2865 if (pageLayoutModule->landscapeRB->isChecked())
2866 bp_.orientation = ORIENTATION_LANDSCAPE;
2868 bp_.orientation = ORIENTATION_PORTRAIT;
2871 bp_.use_geometry = !marginsModule->marginCB->isChecked();
2873 Ui::MarginsUi const * m = marginsModule;
2875 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2876 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2877 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2878 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2879 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2880 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2881 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2882 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2885 branchesModule->apply(bp_);
2888 PDFOptions & pdf = bp_.pdfoptions();
2889 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2890 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2891 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2892 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2893 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2895 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2896 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2897 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2898 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2900 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2901 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2902 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2903 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2905 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2906 if (pdfSupportModule->fullscreenCB->isChecked())
2907 pdf.pagemode = pdf.pagemode_fullscreen;
2909 pdf.pagemode.clear();
2910 pdf.quoted_options = pdf.quoted_options_check(
2911 fromqstr(pdfSupportModule->optionsLE->text()));
2915 void GuiDocument::paramsToDialog()
2917 // set the default unit
2918 Length::UNIT const default_unit = Length::defaultUnit();
2921 preambleModule->update(bp_, id());
2922 localLayout->update(bp_, id());
2925 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2926 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
2929 string const cite_engine = bp_.citeEngine().list().front();
2931 biblioModule->citeDefaultRB->setChecked(
2932 cite_engine == "basic");
2934 biblioModule->citeJurabibRB->setChecked(
2935 cite_engine == "jurabib");
2937 biblioModule->citeNatbibRB->setChecked(
2938 cite_engine == "natbib");
2940 biblioModule->citeStyleCO->setCurrentIndex(
2941 bp_.citeEngineType() & ENGINE_TYPE_NUMERICAL);
2943 updateEngineType(documentClass().opt_enginetype(),
2944 bp_.citeEngineType());
2946 biblioModule->bibtopicCB->setChecked(
2949 biblioModule->bibtexStyleLE->setText(toqstr(bp_.biblio_style));
2953 split(bp_.bibtex_command, command, ' ');
2955 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2957 biblioModule->bibtexCO->setCurrentIndex(bpos);
2958 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
2960 // We reset to default if we do not know the specified compiler
2961 // This is for security reasons
2962 biblioModule->bibtexCO->setCurrentIndex(
2963 biblioModule->bibtexCO->findData(toqstr("default")));
2964 biblioModule->bibtexOptionsLE->clear();
2966 biblioModule->bibtexOptionsLE->setEnabled(
2967 biblioModule->bibtexCO->currentIndex() != 0);
2969 biblioChanged_ = false;
2972 indicesModule->update(bp_);
2974 // language & quotes
2975 int const pos = langModule->languageCO->findData(toqstr(
2976 bp_.language->lang()));
2977 langModule->languageCO->setCurrentIndex(pos);
2979 langModule->quoteStyleCO->setCurrentIndex(
2980 bp_.quotes_language);
2982 bool default_enc = true;
2983 if (bp_.inputenc != "auto") {
2984 default_enc = false;
2985 if (bp_.inputenc == "default") {
2986 langModule->encodingCO->setCurrentIndex(0);
2989 Encodings::const_iterator it = encodings.begin();
2990 Encodings::const_iterator const end = encodings.end();
2991 for (; it != end; ++it) {
2992 if (it->name() == bp_.inputenc &&
2994 enc_gui = it->guiName();
2998 int const i = langModule->encodingCO->findText(
3001 langModule->encodingCO->setCurrentIndex(i);
3003 // unknown encoding. Set to default.
3007 langModule->defaultencodingRB->setChecked(default_enc);
3008 langModule->otherencodingRB->setChecked(!default_enc);
3010 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3012 langModule->languagePackageCO->setCurrentIndex(
3013 langModule->languagePackageCO->findData("custom"));
3014 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3016 langModule->languagePackageCO->setCurrentIndex(p);
3017 langModule->languagePackageLE->clear();
3021 if (bp_.isfontcolor) {
3022 colorModule->fontColorPB->setStyleSheet(
3023 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3025 set_fontcolor = bp_.fontcolor;
3026 is_fontcolor = bp_.isfontcolor;
3028 colorModule->noteFontColorPB->setStyleSheet(
3029 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3030 set_notefontcolor = bp_.notefontcolor;
3032 if (bp_.isbackgroundcolor) {
3033 colorModule->backgroundPB->setStyleSheet(
3034 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3036 set_backgroundcolor = bp_.backgroundcolor;
3037 is_backgroundcolor = bp_.isbackgroundcolor;
3039 colorModule->boxBackgroundPB->setStyleSheet(
3040 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3041 set_boxbgcolor = bp_.boxbgcolor;
3044 int const min_toclevel = documentClass().min_toclevel();
3045 int const max_toclevel = documentClass().max_toclevel();
3046 if (documentClass().hasTocLevels()) {
3047 numberingModule->setEnabled(true);
3048 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3049 numberingModule->depthSL->setMaximum(max_toclevel);
3050 numberingModule->depthSL->setValue(bp_.secnumdepth);
3051 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3052 numberingModule->tocSL->setMaximum(max_toclevel);
3053 numberingModule->tocSL->setValue(bp_.tocdepth);
3056 numberingModule->setEnabled(false);
3057 numberingModule->tocTW->clear();
3061 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3062 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3063 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3064 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3065 bulletsModule->init();
3068 int nitem = findToken(tex_graphics, bp_.graphics_driver);
3070 latexModule->psdriverCO->setCurrentIndex(nitem);
3073 map<string, string> const & packages = BufferParams::auto_packages();
3074 for (map<string, string>::const_iterator it = packages.begin();
3075 it != packages.end(); ++it) {
3076 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3079 int row = mathsModule->packagesTW->row(item);
3080 switch (bp_.use_package(it->first)) {
3081 case BufferParams::package_off: {
3082 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
3083 rb->setChecked(true);
3086 case BufferParams::package_on: {
3087 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
3088 rb->setChecked(true);
3091 case BufferParams::package_auto: {
3092 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
3093 rb->setChecked(true);
3099 switch (bp_.spacing().getSpace()) {
3100 case Spacing::Other: nitem = 3; break;
3101 case Spacing::Double: nitem = 2; break;
3102 case Spacing::Onehalf: nitem = 1; break;
3103 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3107 string const & layoutID = bp_.baseClassID();
3108 setLayoutComboByIDString(layoutID);
3110 updatePagestyle(documentClass().opt_pagestyle(),
3113 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3114 if (bp_.spacing().getSpace() == Spacing::Other) {
3115 doubleToWidget(textLayoutModule->lspacingLE,
3116 bp_.spacing().getValueAsString());
3120 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3121 textLayoutModule->indentRB->setChecked(true);
3122 string indentation = bp_.getIndentation().asLyXCommand();
3124 if (indentation != "default") {
3125 lengthToWidgets(textLayoutModule->indentLE,
3126 textLayoutModule->indentLengthCO,
3127 indentation, default_unit);
3130 textLayoutModule->indentCO->setCurrentIndex(indent);
3133 textLayoutModule->skipRB->setChecked(true);
3135 switch (bp_.getDefSkip().kind()) {
3136 case VSpace::SMALLSKIP:
3139 case VSpace::MEDSKIP:
3142 case VSpace::BIGSKIP:
3145 case VSpace::LENGTH:
3148 string const length = bp_.getDefSkip().asLyXCommand();
3149 lengthToWidgets(textLayoutModule->skipLE,
3150 textLayoutModule->skipLengthCO,
3151 length, default_unit);
3158 textLayoutModule->skipCO->setCurrentIndex(skip);
3162 textLayoutModule->twoColumnCB->setChecked(
3164 textLayoutModule->justCB->setChecked(bp_.justification);
3166 if (!bp_.options.empty()) {
3167 latexModule->optionsLE->setText(
3168 toqstr(bp_.options));
3170 latexModule->optionsLE->setText(QString());
3174 latexModule->defaultOptionsCB->setChecked(
3175 bp_.use_default_options);
3176 updateSelectedModules();
3177 selectionManager->updateProvidedModules(
3178 bp_.baseClass()->providedModules());
3179 selectionManager->updateExcludedModules(
3180 bp_.baseClass()->excludedModules());
3182 if (!documentClass().options().empty()) {
3183 latexModule->defaultOptionsLE->setText(
3184 toqstr(documentClass().options()));
3186 latexModule->defaultOptionsLE->setText(
3187 toqstr(_("[No options predefined]")));
3190 latexModule->defaultOptionsLE->setEnabled(
3191 bp_.use_default_options
3192 && !documentClass().options().empty());
3194 latexModule->defaultOptionsCB->setEnabled(
3195 !documentClass().options().empty());
3197 if (!bp_.master.empty()) {
3198 latexModule->childDocGB->setChecked(true);
3199 latexModule->childDocLE->setText(
3200 toqstr(bp_.master));
3202 latexModule->childDocLE->setText(QString());
3203 latexModule->childDocGB->setChecked(false);
3207 if (!bufferview() || !buffer().hasChildren()) {
3208 masterChildModule->childrenTW->clear();
3209 includeonlys_.clear();
3210 docPS->showPanel("Child Documents", false);
3211 if (docPS->isCurrentPanel("Child Documents"))
3212 docPS->setCurrentPanel("Document Class");
3214 docPS->showPanel("Child Documents", true);
3215 masterChildModule->setEnabled(true);
3216 includeonlys_ = bp_.getIncludedChildren();
3217 updateIncludeonlys();
3219 masterChildModule->maintainAuxCB->setChecked(
3220 bp_.maintain_unincluded_children);
3223 floatModule->set(bp_.float_placement);
3226 // break listings_params to multiple lines
3228 InsetListingsParams(bp_.listings_params).separatedParams();
3229 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3232 // some languages only work with polyglossia/XeTeX
3233 Language const * lang = lyx::languages.getLanguage(
3234 fromqstr(langModule->languageCO->itemData(
3235 langModule->languageCO->currentIndex()).toString()));
3236 bool const need_fontspec =
3237 lang->babel().empty() && !lang->polyglossia().empty();
3238 bool const os_fonts_available =
3239 bp_.baseClass()->outputType() == lyx::LATEX
3240 && LaTeXFeatures::isAvailable("fontspec");
3241 fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3242 fontModule->osFontsCB->setChecked(
3243 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3244 updateFontsize(documentClass().opt_fontsize(),
3247 QString font = toqstr(bp_.fonts_roman);
3248 int rpos = fontModule->fontsRomanCO->findData(font);
3250 rpos = fontModule->fontsRomanCO->count();
3251 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3253 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3255 font = toqstr(bp_.fonts_sans);
3256 int spos = fontModule->fontsSansCO->findData(font);
3258 spos = fontModule->fontsSansCO->count();
3259 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3261 fontModule->fontsSansCO->setCurrentIndex(spos);
3263 font = toqstr(bp_.fonts_typewriter);
3264 int tpos = fontModule->fontsTypewriterCO->findData(font);
3266 tpos = fontModule->fontsTypewriterCO->count();
3267 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3269 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3271 font = toqstr(bp_.fonts_math);
3272 int mpos = fontModule->fontsMathCO->findData(font);
3274 mpos = fontModule->fontsMathCO->count();
3275 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3277 fontModule->fontsMathCO->setCurrentIndex(mpos);
3279 if (bp_.useNonTeXFonts && os_fonts_available) {
3280 fontModule->fontencLA->setEnabled(false);
3281 fontModule->fontencCO->setEnabled(false);
3282 fontModule->fontencLE->setEnabled(false);
3284 fontModule->fontencLA->setEnabled(true);
3285 fontModule->fontencCO->setEnabled(true);
3286 fontModule->fontencLE->setEnabled(true);
3292 if (!bp_.fonts_cjk.empty())
3293 fontModule->cjkFontLE->setText(
3294 toqstr(bp_.fonts_cjk));
3296 fontModule->cjkFontLE->setText(QString());
3298 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3299 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3300 fontModule->scaleSansSB->setValue(bp_.fonts_sans_scale);
3301 fontModule->scaleTypewriterSB->setValue(bp_.fonts_typewriter_scale);
3303 int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3305 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3307 if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3308 fontModule->fontencCO->setCurrentIndex(
3309 fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3310 fontModule->fontencLE->setEnabled(false);
3312 fontModule->fontencCO->setCurrentIndex(1);
3313 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3317 // This must be set _after_ fonts since updateDefaultFormat()
3318 // checks osFontsCB settings.
3319 // update combobox with formats
3320 updateDefaultFormat();
3321 int index = outputModule->defaultFormatCO->findData(toqstr(
3322 bp_.default_output_format));
3323 // set to default if format is not found
3326 outputModule->defaultFormatCO->setCurrentIndex(index);
3328 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3329 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3331 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3332 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3333 outputModule->strictCB->setChecked(bp_.html_be_strict);
3334 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3337 bool const extern_geometry =
3338 documentClass().provides("geometry");
3339 int const psize = bp_.papersize;
3340 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3341 setCustomPapersize(!extern_geometry && psize == 1);
3342 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3344 bool const landscape =
3345 bp_.orientation == ORIENTATION_LANDSCAPE;
3346 pageLayoutModule->landscapeRB->setChecked(landscape);
3347 pageLayoutModule->portraitRB->setChecked(!landscape);
3348 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3349 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3351 pageLayoutModule->facingPagesCB->setChecked(
3352 bp_.sides == TwoSides);
3354 lengthToWidgets(pageLayoutModule->paperwidthLE,
3355 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3356 lengthToWidgets(pageLayoutModule->paperheightLE,
3357 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3360 Ui::MarginsUi * m = marginsModule;
3364 lengthToWidgets(m->topLE, m->topUnit,
3365 bp_.topmargin, default_unit);
3367 lengthToWidgets(m->bottomLE, m->bottomUnit,
3368 bp_.bottommargin, default_unit);
3370 lengthToWidgets(m->innerLE, m->innerUnit,
3371 bp_.leftmargin, default_unit);
3373 lengthToWidgets(m->outerLE, m->outerUnit,
3374 bp_.rightmargin, default_unit);
3376 lengthToWidgets(m->headheightLE, m->headheightUnit,
3377 bp_.headheight, default_unit);
3379 lengthToWidgets(m->headsepLE, m->headsepUnit,
3380 bp_.headsep, default_unit);
3382 lengthToWidgets(m->footskipLE, m->footskipUnit,
3383 bp_.footskip, default_unit);
3385 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3386 bp_.columnsep, default_unit);
3389 updateUnknownBranches();
3390 branchesModule->update(bp_);
3393 PDFOptions const & pdf = bp_.pdfoptions();
3394 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3395 if (bp_.documentClass().provides("hyperref"))
3396 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3398 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3399 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3400 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3401 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3402 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3404 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3405 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3406 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3408 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3410 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3411 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3412 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3413 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3415 nn = findToken(backref_opts, pdf.backref);
3417 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3419 pdfSupportModule->fullscreenCB->setChecked
3420 (pdf.pagemode == pdf.pagemode_fullscreen);
3422 pdfSupportModule->optionsLE->setText(
3423 toqstr(pdf.quoted_options));
3425 // Make sure that the bc is in the INITIAL state
3426 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3429 // clear changed branches cache
3430 changedBranches_.clear();
3434 void GuiDocument::saveDocDefault()
3436 // we have to apply the params first
3442 void GuiDocument::updateAvailableModules()
3444 modules_av_model_.clear();
3445 list<modInfoStruct> const & modInfoList = getModuleInfo();
3446 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3447 list<modInfoStruct>::const_iterator men = modInfoList.end();
3448 for (int i = 0; mit != men; ++mit, ++i)
3449 modules_av_model_.insertRow(i, mit->name, mit->id,
3454 void GuiDocument::updateSelectedModules()
3456 modules_sel_model_.clear();
3457 list<modInfoStruct> const selModList = getSelectedModules();
3458 list<modInfoStruct>::const_iterator mit = selModList.begin();
3459 list<modInfoStruct>::const_iterator men = selModList.end();
3460 for (int i = 0; mit != men; ++mit, ++i)
3461 modules_sel_model_.insertRow(i, mit->name, mit->id,
3466 void GuiDocument::updateIncludeonlys()
3468 masterChildModule->childrenTW->clear();
3469 QString const no = qt_("No");
3470 QString const yes = qt_("Yes");
3472 if (includeonlys_.empty()) {
3473 masterChildModule->includeallRB->setChecked(true);
3474 masterChildModule->childrenTW->setEnabled(false);
3475 masterChildModule->maintainAuxCB->setEnabled(false);
3477 masterChildModule->includeonlyRB->setChecked(true);
3478 masterChildModule->childrenTW->setEnabled(true);
3479 masterChildModule->maintainAuxCB->setEnabled(true);
3481 QTreeWidgetItem * item = 0;
3482 ListOfBuffers children = buffer().getChildren();
3483 ListOfBuffers::const_iterator it = children.begin();
3484 ListOfBuffers::const_iterator end = children.end();
3485 bool has_unincluded = false;
3486 bool all_unincluded = true;
3487 for (; it != end; ++it) {
3488 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3491 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3492 from_utf8(buffer().filePath())));
3493 item->setText(0, toqstr(name));
3494 item->setText(1, isChildIncluded(name) ? yes : no);
3495 if (!isChildIncluded(name))
3496 has_unincluded = true;
3498 all_unincluded = false;
3500 // Both if all childs are included and if none is included
3501 // is equal to "include all" (i.e., ommit \includeonly).
3502 // Thus, reset the GUI.
3503 if (!has_unincluded || all_unincluded) {
3504 masterChildModule->includeallRB->setChecked(true);
3505 masterChildModule->childrenTW->setEnabled(false);
3506 includeonlys_.clear();
3508 // If all are included, we need to update again.
3509 if (!has_unincluded)
3510 updateIncludeonlys();
3514 void GuiDocument::updateContents()
3516 // Nothing to do here as the document settings is not cursor dependant.
3521 void GuiDocument::useClassDefaults()
3523 if (applyPB->isEnabled()) {
3524 int const ret = Alert::prompt(_("Unapplied changes"),
3525 _("Some changes in the dialog were not yet applied.\n"
3526 "If you do not apply now, they will be lost after this action."),
3527 1, 1, _("&Apply"), _("&Dismiss"));
3532 int idx = latexModule->classCO->currentIndex();
3533 string const classname = fromqstr(latexModule->classCO->getData(idx));
3534 if (!bp_.setBaseClass(classname)) {
3535 Alert::error(_("Error"), _("Unable to set document class."));
3538 bp_.useClassDefaults();
3543 void GuiDocument::setLayoutComboByIDString(string const & idString)
3545 if (!latexModule->classCO->set(toqstr(idString)))
3546 Alert::warning(_("Can't set layout!"),
3547 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3551 bool GuiDocument::isValid()
3554 validateListingsParameters().isEmpty() &&
3555 localLayout->isValid() &&
3557 // if we're asking for skips between paragraphs
3558 !textLayoutModule->skipRB->isChecked() ||
3559 // then either we haven't chosen custom
3560 textLayoutModule->skipCO->currentIndex() != 3 ||
3561 // or else a length has been given
3562 !textLayoutModule->skipLE->text().isEmpty()
3565 // if we're asking for indentation
3566 !textLayoutModule->indentRB->isChecked() ||
3567 // then either we haven't chosen custom
3568 textLayoutModule->indentCO->currentIndex() != 1 ||
3569 // or else a length has been given
3570 !textLayoutModule->indentLE->text().isEmpty()
3575 char const * const GuiDocument::fontfamilies[5] = {
3576 "default", "rmdefault", "sfdefault", "ttdefault", ""
3580 char const * GuiDocument::fontfamilies_gui[5] = {
3581 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3585 bool GuiDocument::initialiseParams(string const &)
3587 BufferView const * view = bufferview();
3589 bp_ = BufferParams();
3593 bp_ = view->buffer().params();
3595 updateAvailableModules();
3596 //FIXME It'd be nice to make sure here that the selected
3597 //modules are consistent: That required modules are actually
3598 //selected, and that we don't have conflicts. If so, we could
3599 //at least pop up a warning.
3605 void GuiDocument::clearParams()
3607 bp_ = BufferParams();
3611 BufferId GuiDocument::id() const
3613 BufferView const * const view = bufferview();
3614 return view? &view->buffer() : 0;
3618 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3620 return moduleNames_;
3624 list<GuiDocument::modInfoStruct> const
3625 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3627 LayoutModuleList::const_iterator it = mods.begin();
3628 LayoutModuleList::const_iterator end = mods.end();
3629 list<modInfoStruct> mInfo;
3630 for (; it != end; ++it) {
3633 LyXModule const * const mod = theModuleList[*it];
3636 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3638 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3645 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3647 return makeModuleInfo(params().getModules());
3651 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3653 return makeModuleInfo(params().baseClass()->providedModules());
3657 DocumentClass const & GuiDocument::documentClass() const
3659 return bp_.documentClass();
3663 static void dispatch_bufferparams(Dialog const & dialog,
3664 BufferParams const & bp, FuncCode lfun)
3667 ss << "\\begin_header\n";
3669 ss << "\\end_header\n";
3670 dialog.dispatch(FuncRequest(lfun, ss.str()));
3674 void GuiDocument::dispatchParams()
3676 // This must come first so that a language change is correctly noticed
3679 // Apply the BufferParams. Note that this will set the base class
3680 // and then update the buffer's layout.
3681 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3683 if (!params().master.empty()) {
3684 FileName const master_file = support::makeAbsPath(params().master,
3685 support::onlyPath(buffer().absFileName()));
3686 if (isLyXFileName(master_file.absFileName())) {
3687 Buffer * master = checkAndLoadLyXFile(master_file);
3689 if (master->isChild(const_cast<Buffer *>(&buffer())))
3690 const_cast<Buffer &>(buffer()).setParent(master);
3692 Alert::warning(_("Assigned master does not include this file"),
3693 bformat(_("You must include this file in the document\n"
3694 "'%1$s' in order to use the master document\n"
3695 "feature."), from_utf8(params().master)));
3697 Alert::warning(_("Could not load master"),
3698 bformat(_("The master document '%1$s'\n"
3699 "could not be loaded."),
3700 from_utf8(params().master)));
3704 // Generate the colours requested by each new branch.
3705 BranchList & branchlist = params().branchlist();
3706 if (!branchlist.empty()) {
3707 BranchList::const_iterator it = branchlist.begin();
3708 BranchList::const_iterator const end = branchlist.end();
3709 for (; it != end; ++it) {
3710 docstring const & current_branch = it->branch();
3711 Branch const * branch = branchlist.find(current_branch);
3712 string const x11hexname = X11hexname(branch->color());
3713 // display the new color
3714 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3715 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3718 // Open insets of selected branches, close deselected ones
3719 dispatch(FuncRequest(LFUN_INSET_FORALL,
3720 "Branch inset-toggle assign"));
3722 // rename branches in the document
3723 executeBranchRenaming();
3724 // and clear changed branches cache
3725 changedBranches_.clear();
3727 // Generate the colours requested by indices.
3728 IndicesList & indiceslist = params().indiceslist();
3729 if (!indiceslist.empty()) {
3730 IndicesList::const_iterator it = indiceslist.begin();
3731 IndicesList::const_iterator const end = indiceslist.end();
3732 for (; it != end; ++it) {
3733 docstring const & current_index = it->shortcut();
3734 Index const * index = indiceslist.findShortcut(current_index);
3735 string const x11hexname = X11hexname(index->color());
3736 // display the new color
3737 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3738 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3742 // If we used an LFUN, we would not need these two lines:
3743 BufferView * bv = const_cast<BufferView *>(bufferview());
3744 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3748 void GuiDocument::setLanguage() const
3750 Language const * const newL = bp_.language;
3751 if (buffer().params().language == newL)
3754 string const & lang_name = newL->lang();
3755 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3759 void GuiDocument::saveAsDefault() const
3761 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3765 bool GuiDocument::providesOSF(QString const & font) const
3767 if (fontModule->osFontsCB->isChecked())
3768 // FIXME: we should check if the fonts really
3769 // have OSF support. But how?
3771 return theLaTeXFonts().getLaTeXFont(
3772 qstring_to_ucs4(font)).providesOSF(ot1(),
3778 bool GuiDocument::providesSC(QString const & font) const
3780 if (fontModule->osFontsCB->isChecked())
3782 return theLaTeXFonts().getLaTeXFont(
3783 qstring_to_ucs4(font)).providesSC(ot1(),
3789 bool GuiDocument::providesScale(QString const & font) const
3791 if (fontModule->osFontsCB->isChecked())
3793 return theLaTeXFonts().getLaTeXFont(
3794 qstring_to_ucs4(font)).providesScale(ot1(),
3800 bool GuiDocument::providesNoMath(QString const & font) const
3802 if (fontModule->osFontsCB->isChecked())
3804 return theLaTeXFonts().getLaTeXFont(
3805 qstring_to_ucs4(font)).providesNoMath(ot1(),
3810 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
3812 if (fontModule->osFontsCB->isChecked())
3814 return theLaTeXFonts().getLaTeXFont(
3815 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
3821 void GuiDocument::loadModuleInfo()
3823 moduleNames_.clear();
3824 LyXModuleList::const_iterator it = theModuleList.begin();
3825 LyXModuleList::const_iterator end = theModuleList.end();
3826 for (; it != end; ++it) {
3830 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3831 // this is supposed to give us the first sentence of the description
3834 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3835 int const pos = desc.indexOf(".");
3837 desc.truncate(pos + 1);
3838 m.description = desc;
3839 if (it->category().substr(0, 8) != "Citation")
3840 moduleNames_.push_back(m);
3845 void GuiDocument::updateUnknownBranches()
3849 list<docstring> used_branches;
3850 buffer().getUsedBranches(used_branches);
3851 list<docstring>::const_iterator it = used_branches.begin();
3852 QStringList unknown_branches;
3853 for (; it != used_branches.end() ; ++it) {
3854 if (!buffer().params().branchlist().find(*it))
3855 unknown_branches.append(toqstr(*it));
3857 branchesModule->setUnknownBranches(unknown_branches);
3861 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3863 map<docstring, docstring>::iterator it = changedBranches_.begin();
3864 for (; it != changedBranches_.end() ; ++it) {
3865 if (it->second == oldname) {
3866 // branch has already been renamed
3867 it->second = newname;
3872 changedBranches_[oldname] = newname;
3876 void GuiDocument::executeBranchRenaming() const
3878 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3879 for (; it != changedBranches_.end() ; ++it) {
3880 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3881 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3886 void GuiDocument::allPackagesAuto()
3892 void GuiDocument::allPackagesAlways()
3898 void GuiDocument::allPackagesNot()
3904 void GuiDocument::allPackages(int col)
3906 for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
3907 QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col);
3908 rb->setChecked(true);
3913 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3916 } // namespace frontend
3919 #include "moc_GuiDocument.cpp"