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 "GuiApplication.h"
17 #include "GuiBranches.h"
18 #include "GuiIndices.h"
19 #include "GuiSelectionManager.h"
20 #include "LaTeXHighlighter.h"
21 #include "LengthCombo.h"
22 #include "PanelStack.h"
23 #include "Validator.h"
25 #include "LayoutFile.h"
26 #include "BranchList.h"
27 #include "buffer_funcs.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
32 #include "ColorCache.h"
34 #include "FloatPlacement.h"
36 #include "FuncRequest.h"
38 #include "IndicesList.h"
40 #include "LaTeXFeatures.h"
42 #include "LayoutModuleList.h"
44 #include "ModuleList.h"
45 #include "OutputParams.h"
46 #include "PDFOptions.h"
47 #include "qt_helpers.h"
49 #include "TextClass.h"
51 #include "insets/InsetListingsParams.h"
53 #include "support/debug.h"
54 #include "support/FileName.h"
55 #include "support/filetools.h"
56 #include "support/gettext.h"
57 #include "support/lassert.h"
58 #include "support/lstrings.h"
60 #include "frontends/alert.h"
62 #include <QAbstractItemModel>
63 #include <QHeaderView>
65 #include <QColorDialog>
66 #include <QCloseEvent>
67 #include <QFontDatabase>
69 #include <QTextCursor>
79 // a style sheet for buttons
80 // this is for example used for the background color setting button
81 static inline QString colorButtonStyleSheet(QColor const & bgColor)
83 if (bgColor.isValid()) {
84 QString rc = QLatin1String("background-color:");
93 using namespace lyx::support;
98 char const * const tex_graphics[] =
100 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
101 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
102 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
103 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
108 char const * const tex_graphics_gui[] =
110 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
111 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
112 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
113 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
114 "XeTeX", N_("None"), ""
118 char const * const tex_fonts_roman[] =
120 "default", "cmr", "lmodern", "ae", "times", "palatino",
121 "charter", "newcent", "bookman", "utopia", "beraserif",
122 "ccfonts", "chancery", ""
126 char const * tex_fonts_roman_gui[] =
128 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
129 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
130 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
131 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
136 char const * const tex_fonts_sans[] =
138 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
142 char const * tex_fonts_sans_gui[] =
144 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
145 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
149 char const * const tex_fonts_monospaced[] =
151 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
155 char const * tex_fonts_monospaced_gui[] =
157 N_("Default"), N_("Computer Modern Typewriter"),
158 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
159 N_("LuxiMono"), N_("CM Typewriter Light"), ""
163 char const * backref_opts[] =
165 "false", "section", "slide", "page", ""
169 char const * backref_opts_gui[] =
171 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
175 char const * packages_gui[][4] =
178 N_("&Use AMS math package automatically"),
179 N_("Use AMS &math package"),
180 N_("The AMS LaTeX packages are only used if symbols from the AMS math toolbars are inserted into formulas")},
182 N_("Use esint package &automatically"),
183 N_("Use &esint package"),
184 N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas")},
186 N_("Use math&dots package automatically"),
187 N_("Use mathdo&ts package"),
188 N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas")},
190 N_("Use mathtools package automatically"),
191 N_("Use mathtools package"),
192 N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas")},
194 N_("Use mhchem &package automatically"),
195 N_("Use mh&chem package"),
196 N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas")},
198 N_("Use u&ndertilde package automatically"),
199 N_("Use undertilde pac&kage"),
200 N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'")},
205 vector<pair<string, QString> > pagestyles;
208 } // anonymous namespace
212 RGBColor set_backgroundcolor;
213 bool is_backgroundcolor;
214 RGBColor set_fontcolor;
216 RGBColor set_notefontcolor;
217 RGBColor set_boxbgcolor;
220 // used when sorting the textclass list.
221 class less_textclass_avail_desc
222 : public binary_function<string, string, int>
225 bool operator()(string const & lhs, string const & rhs) const
227 // Ordering criteria:
228 // 1. Availability of text class
229 // 2. Description (lexicographic)
230 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
231 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
232 int const order = compare_no_case(
233 translateIfPossible(from_utf8(tc1.description())),
234 translateIfPossible(from_utf8(tc2.description())));
235 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
236 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
245 vector<string> getRequiredList(string const & modName)
247 LyXModule const * const mod = theModuleList[modName];
249 return vector<string>(); //empty such thing
250 return mod->getRequiredModules();
254 vector<string> getExcludedList(string const & modName)
256 LyXModule const * const mod = theModuleList[modName];
258 return vector<string>(); //empty such thing
259 return mod->getExcludedModules();
263 docstring getModuleDescription(string const & modName)
265 LyXModule const * const mod = theModuleList[modName];
267 return _("Module not found!");
269 return translateIfPossible(from_utf8(mod->getDescription()));
273 vector<string> getPackageList(string const & modName)
275 LyXModule const * const mod = theModuleList[modName];
277 return vector<string>(); //empty such thing
278 return mod->getPackageList();
282 bool isModuleAvailable(string const & modName)
284 LyXModule const * const mod = theModuleList[modName];
287 return mod->isAvailable();
290 } // anonymous namespace
293 /////////////////////////////////////////////////////////////////////
295 // ModuleSelectionManager
297 /////////////////////////////////////////////////////////////////////
299 /// SelectionManager for use with modules
300 class ModuleSelectionManager : public GuiSelectionManager
304 ModuleSelectionManager(
305 QTreeView * availableLV,
306 QListView * selectedLV,
310 QPushButton * downPB,
311 GuiIdListModel * availableModel,
312 GuiIdListModel * selectedModel,
313 GuiDocument const * container)
314 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
315 upPB, downPB, availableModel, selectedModel), container_(container)
318 void updateProvidedModules(LayoutModuleList const & pm)
319 { provided_modules_ = pm.list(); }
321 void updateExcludedModules(LayoutModuleList const & em)
322 { excluded_modules_ = em.list(); }
325 virtual void updateAddPB();
327 virtual void updateUpPB();
329 virtual void updateDownPB();
331 virtual void updateDelPB();
332 /// returns availableModel as a GuiIdListModel
333 GuiIdListModel * getAvailableModel()
335 return dynamic_cast<GuiIdListModel *>(availableModel);
337 /// returns selectedModel as a GuiIdListModel
338 GuiIdListModel * getSelectedModel()
340 return dynamic_cast<GuiIdListModel *>(selectedModel);
342 /// keeps a list of the modules the text class provides
343 list<string> provided_modules_;
345 list<string> excluded_modules_;
347 GuiDocument const * container_;
350 void ModuleSelectionManager::updateAddPB()
352 int const arows = availableModel->rowCount();
353 QModelIndexList const avail_sels =
354 availableLV->selectionModel()->selectedIndexes();
356 // disable if there aren't any modules (?), if none of them is chosen
357 // in the dialog, or if the chosen one is already selected for use.
358 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
359 addPB->setEnabled(false);
363 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
364 string const modname = getAvailableModel()->getIDString(idx.row());
367 container_->params().moduleCanBeAdded(modname);
368 addPB->setEnabled(enable);
372 void ModuleSelectionManager::updateDownPB()
374 int const srows = selectedModel->rowCount();
376 downPB->setEnabled(false);
379 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
380 int const curRow = curidx.row();
381 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
382 downPB->setEnabled(false);
386 // determine whether immediately succeding element requires this one
387 string const curmodname = getSelectedModel()->getIDString(curRow);
388 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
390 vector<string> reqs = getRequiredList(nextmodname);
392 // if it doesn't require anything....
394 downPB->setEnabled(true);
398 // Enable it if this module isn't required.
399 // FIXME This should perhaps be more flexible and check whether, even
400 // if the next one is required, there is also an earlier one that will do.
402 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
405 void ModuleSelectionManager::updateUpPB()
407 int const srows = selectedModel->rowCount();
409 upPB->setEnabled(false);
413 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
414 int curRow = curIdx.row();
415 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
416 upPB->setEnabled(false);
419 string const curmodname = getSelectedModel()->getIDString(curRow);
421 // determine whether immediately preceding element is required by this one
422 vector<string> reqs = getRequiredList(curmodname);
424 // if this one doesn't require anything....
426 upPB->setEnabled(true);
431 // Enable it if the preceding module isn't required.
432 // NOTE This is less flexible than it might be. We could check whether, even
433 // if the previous one is required, there is an earlier one that would do.
434 string const premod = getSelectedModel()->getIDString(curRow - 1);
435 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
438 void ModuleSelectionManager::updateDelPB()
440 int const srows = selectedModel->rowCount();
442 deletePB->setEnabled(false);
446 QModelIndex const & curidx =
447 selectedLV->selectionModel()->currentIndex();
448 int const curRow = curidx.row();
449 if (curRow < 0 || curRow >= srows) { // invalid index?
450 deletePB->setEnabled(false);
454 string const curmodname = getSelectedModel()->getIDString(curRow);
456 // We're looking here for a reason NOT to enable the button. If we
457 // find one, we disable it and return. If we don't, we'll end up at
458 // the end of the function, and then we enable it.
459 for (int i = curRow + 1; i < srows; ++i) {
460 string const thisMod = getSelectedModel()->getIDString(i);
461 vector<string> reqs = getRequiredList(thisMod);
462 //does this one require us?
463 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
467 // OK, so this module requires us
468 // is there an EARLIER module that also satisfies the require?
469 // NOTE We demand that it be earlier to keep the list of modules
470 // consistent with the rule that a module must be proceeded by a
471 // required module. There would be more flexible ways to proceed,
472 // but that would be a lot more complicated, and the logic here is
473 // already complicated. (That's why I've left the debugging code.)
474 // lyxerr << "Testing " << thisMod << endl;
475 bool foundone = false;
476 for (int j = 0; j < curRow; ++j) {
477 string const mod = getSelectedModel()->getIDString(j);
478 // lyxerr << "In loop: Testing " << mod << endl;
479 // do we satisfy the require?
480 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
481 // lyxerr << mod << " does the trick." << endl;
486 // did we find a module to satisfy the require?
488 // lyxerr << "No matching module found." << endl;
489 deletePB->setEnabled(false);
493 // lyxerr << "All's well that ends well." << endl;
494 deletePB->setEnabled(true);
498 /////////////////////////////////////////////////////////////////////
502 /////////////////////////////////////////////////////////////////////
504 PreambleModule::PreambleModule() : current_id_(0)
506 // This is not a memory leak. The object will be destroyed
508 (void) new LaTeXHighlighter(preambleTE->document());
509 setFocusProxy(preambleTE);
510 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
514 void PreambleModule::update(BufferParams const & params, BufferId id)
516 QString preamble = toqstr(params.preamble);
517 // Nothing to do if the params and preamble are unchanged.
518 if (id == current_id_
519 && preamble == preambleTE->document()->toPlainText())
522 QTextCursor cur = preambleTE->textCursor();
523 // Save the coords before switching to the new one.
524 preamble_coords_[current_id_] =
525 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
527 // Save the params address for further use.
529 preambleTE->document()->setPlainText(preamble);
530 Coords::const_iterator it = preamble_coords_.find(current_id_);
531 if (it == preamble_coords_.end())
532 // First time we open this one.
533 preamble_coords_[current_id_] = make_pair(0, 0);
535 // Restore saved coords.
536 QTextCursor cur = preambleTE->textCursor();
537 cur.setPosition(it->second.first);
538 preambleTE->setTextCursor(cur);
539 preambleTE->verticalScrollBar()->setValue(it->second.second);
544 void PreambleModule::apply(BufferParams & params)
546 params.preamble = fromqstr(preambleTE->document()->toPlainText());
550 void PreambleModule::closeEvent(QCloseEvent * e)
552 // Save the coords before closing.
553 QTextCursor cur = preambleTE->textCursor();
554 preamble_coords_[current_id_] =
555 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
560 /////////////////////////////////////////////////////////////////////
564 /////////////////////////////////////////////////////////////////////
567 LocalLayout::LocalLayout() : current_id_(0), is_valid_(false)
569 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
570 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
571 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
575 void LocalLayout::update(BufferParams const & params, BufferId id)
577 QString layout = toqstr(params.local_layout);
578 // Nothing to do if the params and preamble are unchanged.
579 if (id == current_id_
580 && layout == locallayoutTE->document()->toPlainText())
583 // Save the params address for further use.
585 locallayoutTE->document()->setPlainText(layout);
590 void LocalLayout::apply(BufferParams & params)
592 string const layout = fromqstr(locallayoutTE->document()->toPlainText());
593 params.local_layout = layout;
597 void LocalLayout::textChanged()
599 static const QString unknown = qt_("Press button to check validity...");
602 validLB->setText(unknown);
603 validatePB->setEnabled(true);
604 convertPB->setEnabled(false);
609 void LocalLayout::convert() {
610 string const layout =
611 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
612 string const newlayout = TextClass::convert(layout);
614 if (newlayout.empty()) {
615 Alert::error(_("Conversion Failed!"),
616 _("Failed to convert local layout to current format."));
618 locallayoutTE->setPlainText(toqstr(newlayout));
624 void LocalLayout::convertPressed() {
630 void LocalLayout::validate() {
631 static const QString valid = qt_("Layout is valid!");
632 static const QString vtext =
633 toqstr("<p style=\"font-weight: bold; \">")
634 + valid + toqstr("</p>");
635 static const QString invalid = qt_("Layout is invalid!");
636 static const QString ivtext =
637 toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
638 + invalid + toqstr("</p>");
640 string const layout =
641 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
642 if (layout.empty()) {
644 validatePB->setEnabled(false);
645 validLB->setText("");
649 TextClass::ReturnValues const ret = TextClass::validate(layout);
650 is_valid_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
651 validatePB->setEnabled(false);
652 validLB->setText(is_valid_ ? vtext : ivtext);
653 if (ret == TextClass::OK_OLDFORMAT) {
655 convertPB->setEnabled(true);
656 convertLB->setText(qt_("Convert to current format"));
666 void LocalLayout::validatePressed() {
672 /////////////////////////////////////////////////////////////////////
676 /////////////////////////////////////////////////////////////////////
679 GuiDocument::GuiDocument(GuiView & lv)
680 : GuiDialog(lv, "document", qt_("Document Settings"))
684 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
685 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
686 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
687 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
689 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
690 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
692 // Manage the restore, ok, apply, restore and cancel/close buttons
693 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
695 bc().setApply(applyPB);
696 bc().setCancel(closePB);
697 bc().setRestore(restorePB);
701 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
702 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
703 this, SLOT(change_adaptor()));
704 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
705 this, SLOT(setLSpacing(int)));
706 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
707 this, SLOT(change_adaptor()));
709 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
710 this, SLOT(change_adaptor()));
711 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
712 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
713 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
714 this, SLOT(change_adaptor()));
715 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
716 this, SLOT(setIndent(int)));
717 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
718 this, SLOT(change_adaptor()));
719 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
720 this, SLOT(change_adaptor()));
722 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
723 this, SLOT(change_adaptor()));
724 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
725 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
726 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
727 this, SLOT(change_adaptor()));
728 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
729 this, SLOT(setSkip(int)));
730 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
731 this, SLOT(change_adaptor()));
732 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
733 this, SLOT(change_adaptor()));
735 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
736 this, SLOT(enableIndent(bool)));
737 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
738 this, SLOT(enableSkip(bool)));
740 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
741 this, SLOT(change_adaptor()));
742 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
743 this, SLOT(setColSep()));
744 connect(textLayoutModule->justCB, SIGNAL(clicked()),
745 this, SLOT(change_adaptor()));
747 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
748 textLayoutModule->lspacingLE));
749 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
750 textLayoutModule->indentLE));
751 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
752 textLayoutModule->skipLE));
754 textLayoutModule->indentCO->addItem(qt_("Default"));
755 textLayoutModule->indentCO->addItem(qt_("Custom"));
756 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
757 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
758 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
759 textLayoutModule->skipCO->addItem(qt_("Custom"));
760 textLayoutModule->lspacingCO->insertItem(
761 Spacing::Single, qt_("Single"));
762 textLayoutModule->lspacingCO->insertItem(
763 Spacing::Onehalf, qt_("OneHalf"));
764 textLayoutModule->lspacingCO->insertItem(
765 Spacing::Double, qt_("Double"));
766 textLayoutModule->lspacingCO->insertItem(
767 Spacing::Other, qt_("Custom"));
768 // initialize the length validator
769 bc().addCheckedLineEdit(textLayoutModule->indentLE);
770 bc().addCheckedLineEdit(textLayoutModule->skipLE);
773 // master/child handling
774 masterChildModule = new UiWidget<Ui::MasterChildUi>;
776 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
777 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
778 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
779 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
780 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
781 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
782 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
783 this, SLOT(change_adaptor()));
784 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
785 this, SLOT(change_adaptor()));
786 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
787 this, SLOT(change_adaptor()));
788 masterChildModule->childrenTW->setColumnCount(2);
789 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
790 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
791 masterChildModule->childrenTW->resizeColumnToContents(1);
792 masterChildModule->childrenTW->resizeColumnToContents(2);
796 outputModule = new UiWidget<Ui::OutputUi>;
798 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
799 this, SLOT(change_adaptor()));
800 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
801 this, SLOT(change_adaptor()));
802 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
803 this, SLOT(change_adaptor()));
804 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
805 this, SLOT(change_adaptor()));
806 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
807 this, SLOT(change_adaptor()));
809 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
810 this, SLOT(change_adaptor()));
811 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
812 this, SLOT(change_adaptor()));
813 outputModule->synccustomCB->addItem("");
814 outputModule->synccustomCB->addItem("\\synctex=1");
815 outputModule->synccustomCB->addItem("\\synctex=-1");
816 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
818 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
819 outputModule->synccustomCB));
822 fontModule = new UiWidget<Ui::FontUi>;
823 connect(fontModule->osFontsCB, SIGNAL(clicked()),
824 this, SLOT(change_adaptor()));
825 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
826 this, SLOT(osFontsChanged(bool)));
827 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
828 this, SLOT(change_adaptor()));
829 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
830 this, SLOT(romanChanged(int)));
831 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
832 this, SLOT(change_adaptor()));
833 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
834 this, SLOT(sansChanged(int)));
835 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
836 this, SLOT(change_adaptor()));
837 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
838 this, SLOT(ttChanged(int)));
839 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
840 this, SLOT(change_adaptor()));
841 connect(fontModule->fontencCO, SIGNAL(activated(int)),
842 this, SLOT(change_adaptor()));
843 connect(fontModule->fontencCO, SIGNAL(activated(int)),
844 this, SLOT(fontencChanged(int)));
845 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
846 this, SLOT(change_adaptor()));
847 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
848 this, SLOT(change_adaptor()));
849 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
850 this, SLOT(change_adaptor()));
851 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
852 this, SLOT(change_adaptor()));
853 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
854 this, SLOT(change_adaptor()));
855 connect(fontModule->fontScCB, SIGNAL(clicked()),
856 this, SLOT(change_adaptor()));
857 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
858 this, SLOT(change_adaptor()));
860 fontModule->fontencLE->setValidator(new NoNewLineValidator(
861 fontModule->fontencLE));
862 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
863 fontModule->cjkFontLE));
867 fontModule->fontsizeCO->addItem(qt_("Default"));
868 fontModule->fontsizeCO->addItem(qt_("10"));
869 fontModule->fontsizeCO->addItem(qt_("11"));
870 fontModule->fontsizeCO->addItem(qt_("12"));
872 fontModule->fontencCO->addItem(qt_("Default"));
873 fontModule->fontencCO->addItem(qt_("Custom"));
874 fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
876 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
877 fontModule->fontsDefaultCO->addItem(
878 qt_(GuiDocument::fontfamilies_gui[n]));
880 if (!LaTeXFeatures::isAvailable("fontspec"))
881 fontModule->osFontsCB->setToolTip(
882 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
883 "You need to install the package \"fontspec\" to use this feature"));
887 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
888 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
889 this, SLOT(papersizeChanged(int)));
890 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
891 this, SLOT(papersizeChanged(int)));
892 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
893 this, SLOT(change_adaptor()));
894 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
895 this, SLOT(change_adaptor()));
896 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
897 this, SLOT(change_adaptor()));
898 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
899 this, SLOT(change_adaptor()));
900 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
901 this, SLOT(change_adaptor()));
902 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
903 this, SLOT(change_adaptor()));
904 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
905 this, SLOT(change_adaptor()));
906 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
907 this, SLOT(change_adaptor()));
908 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
909 this, SLOT(change_adaptor()));
910 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
911 this, SLOT(change_adaptor()));
913 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
914 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
915 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
916 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
917 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
918 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
919 pageLayoutModule->paperheightL);
920 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
921 pageLayoutModule->paperwidthL);
923 QComboBox * cb = pageLayoutModule->papersizeCO;
924 cb->addItem(qt_("Default"));
925 cb->addItem(qt_("Custom"));
926 cb->addItem(qt_("US letter"));
927 cb->addItem(qt_("US legal"));
928 cb->addItem(qt_("US executive"));
929 cb->addItem(qt_("A0"));
930 cb->addItem(qt_("A1"));
931 cb->addItem(qt_("A2"));
932 cb->addItem(qt_("A3"));
933 cb->addItem(qt_("A4"));
934 cb->addItem(qt_("A5"));
935 cb->addItem(qt_("A6"));
936 cb->addItem(qt_("B0"));
937 cb->addItem(qt_("B1"));
938 cb->addItem(qt_("B2"));
939 cb->addItem(qt_("B3"));
940 cb->addItem(qt_("B4"));
941 cb->addItem(qt_("B5"));
942 cb->addItem(qt_("B6"));
943 cb->addItem(qt_("C0"));
944 cb->addItem(qt_("C1"));
945 cb->addItem(qt_("C2"));
946 cb->addItem(qt_("C3"));
947 cb->addItem(qt_("C4"));
948 cb->addItem(qt_("C5"));
949 cb->addItem(qt_("C6"));
950 cb->addItem(qt_("JIS B0"));
951 cb->addItem(qt_("JIS B1"));
952 cb->addItem(qt_("JIS B2"));
953 cb->addItem(qt_("JIS B3"));
954 cb->addItem(qt_("JIS B4"));
955 cb->addItem(qt_("JIS B5"));
956 cb->addItem(qt_("JIS B6"));
957 // remove the %-items from the unit choice
958 pageLayoutModule->paperwidthUnitCO->noPercents();
959 pageLayoutModule->paperheightUnitCO->noPercents();
960 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
961 pageLayoutModule->paperheightLE));
962 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
963 pageLayoutModule->paperwidthLE));
967 marginsModule = new UiWidget<Ui::MarginsUi>;
968 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
969 this, SLOT(setCustomMargins(bool)));
970 connect(marginsModule->marginCB, SIGNAL(clicked()),
971 this, SLOT(change_adaptor()));
972 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
973 this, SLOT(change_adaptor()));
974 connect(marginsModule->topUnit, SIGNAL(activated(int)),
975 this, SLOT(change_adaptor()));
976 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
977 this, SLOT(change_adaptor()));
978 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
979 this, SLOT(change_adaptor()));
980 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
981 this, SLOT(change_adaptor()));
982 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
983 this, SLOT(change_adaptor()));
984 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
985 this, SLOT(change_adaptor()));
986 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
987 this, SLOT(change_adaptor()));
988 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
989 this, SLOT(change_adaptor()));
990 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
991 this, SLOT(change_adaptor()));
992 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
993 this, SLOT(change_adaptor()));
994 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
995 this, SLOT(change_adaptor()));
996 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
997 this, SLOT(change_adaptor()));
998 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
999 this, SLOT(change_adaptor()));
1000 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1001 this, SLOT(change_adaptor()));
1002 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1003 this, SLOT(change_adaptor()));
1004 marginsModule->topLE->setValidator(unsignedLengthValidator(
1005 marginsModule->topLE));
1006 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
1007 marginsModule->bottomLE));
1008 marginsModule->innerLE->setValidator(unsignedLengthValidator(
1009 marginsModule->innerLE));
1010 marginsModule->outerLE->setValidator(unsignedLengthValidator(
1011 marginsModule->outerLE));
1012 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
1013 marginsModule->headsepLE));
1014 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
1015 marginsModule->headheightLE));
1016 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
1017 marginsModule->footskipLE));
1018 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
1019 marginsModule->columnsepLE));
1021 bc().addCheckedLineEdit(marginsModule->topLE,
1022 marginsModule->topL);
1023 bc().addCheckedLineEdit(marginsModule->bottomLE,
1024 marginsModule->bottomL);
1025 bc().addCheckedLineEdit(marginsModule->innerLE,
1026 marginsModule->innerL);
1027 bc().addCheckedLineEdit(marginsModule->outerLE,
1028 marginsModule->outerL);
1029 bc().addCheckedLineEdit(marginsModule->headsepLE,
1030 marginsModule->headsepL);
1031 bc().addCheckedLineEdit(marginsModule->headheightLE,
1032 marginsModule->headheightL);
1033 bc().addCheckedLineEdit(marginsModule->footskipLE,
1034 marginsModule->footskipL);
1035 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1036 marginsModule->columnsepL);
1040 langModule = new UiWidget<Ui::LanguageUi>;
1041 connect(langModule->languageCO, SIGNAL(activated(int)),
1042 this, SLOT(change_adaptor()));
1043 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1044 this, SLOT(change_adaptor()));
1045 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1046 this, SLOT(change_adaptor()));
1047 connect(langModule->encodingCO, SIGNAL(activated(int)),
1048 this, SLOT(change_adaptor()));
1049 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1050 this, SLOT(change_adaptor()));
1051 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1052 this, SLOT(change_adaptor()));
1053 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1054 this, SLOT(change_adaptor()));
1055 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1056 this, SLOT(languagePackageChanged(int)));
1058 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1059 langModule->languagePackageLE));
1061 QAbstractItemModel * language_model = guiApp->languageModel();
1062 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1063 language_model->sort(0);
1064 langModule->languageCO->setModel(language_model);
1065 langModule->languageCO->setModelColumn(0);
1067 // Always put the default encoding in the first position.
1068 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1069 QStringList encodinglist;
1070 Encodings::const_iterator it = encodings.begin();
1071 Encodings::const_iterator const end = encodings.end();
1072 for (; it != end; ++it)
1073 encodinglist.append(qt_(it->guiName()));
1074 encodinglist.sort();
1075 langModule->encodingCO->addItems(encodinglist);
1077 langModule->quoteStyleCO->addItem(qt_("``text''"));
1078 langModule->quoteStyleCO->addItem(qt_("''text''"));
1079 langModule->quoteStyleCO->addItem(qt_(",,text``"));
1080 langModule->quoteStyleCO->addItem(qt_(",,text''"));
1081 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
1082 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
1084 langModule->languagePackageCO->addItem(
1085 qt_("Default"), toqstr("default"));
1086 langModule->languagePackageCO->addItem(
1087 qt_("Automatic"), toqstr("auto"));
1088 langModule->languagePackageCO->addItem(
1089 qt_("Always Babel"), toqstr("babel"));
1090 langModule->languagePackageCO->addItem(
1091 qt_("Custom"), toqstr("custom"));
1092 langModule->languagePackageCO->addItem(
1093 qt_("None[[language package]]"), toqstr("none"));
1097 colorModule = new UiWidget<Ui::ColorUi>;
1098 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1099 this, SLOT(changeFontColor()));
1100 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1101 this, SLOT(deleteFontColor()));
1102 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1103 this, SLOT(changeNoteFontColor()));
1104 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1105 this, SLOT(deleteNoteFontColor()));
1106 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1107 this, SLOT(changeBackgroundColor()));
1108 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1109 this, SLOT(deleteBackgroundColor()));
1110 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1111 this, SLOT(changeBoxBackgroundColor()));
1112 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1113 this, SLOT(deleteBoxBackgroundColor()));
1117 numberingModule = new UiWidget<Ui::NumberingUi>;
1118 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1119 this, SLOT(change_adaptor()));
1120 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1121 this, SLOT(change_adaptor()));
1122 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1123 this, SLOT(updateNumbering()));
1124 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1125 this, SLOT(updateNumbering()));
1126 numberingModule->tocTW->setColumnCount(3);
1127 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1128 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1129 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1130 numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents);
1134 biblioModule = new UiWidget<Ui::BiblioUi>;
1135 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)),
1136 this, SLOT(setNumerical(bool)));
1137 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)),
1138 this, SLOT(setAuthorYear(bool)));
1139 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1140 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1141 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1142 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1143 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1144 this, SLOT(biblioChanged()));
1145 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1146 this, SLOT(biblioChanged()));
1147 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1148 this, SLOT(biblioChanged()));
1149 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1150 this, SLOT(biblioChanged()));
1151 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1152 this, SLOT(biblioChanged()));
1153 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1154 this, SLOT(bibtexChanged(int)));
1155 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1156 this, SLOT(biblioChanged()));
1157 connect(biblioModule->bibtexStyleLE, SIGNAL(textChanged(QString)),
1158 this, SLOT(biblioChanged()));
1160 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1161 biblioModule->bibtexOptionsLE));
1162 biblioModule->bibtexStyleLE->setValidator(new NoNewLineValidator(
1163 biblioModule->bibtexStyleLE));
1165 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1166 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1167 biblioModule->citeStyleCO->setCurrentIndex(0);
1169 // NOTE: we do not provide "custom" here for security reasons!
1170 biblioModule->bibtexCO->clear();
1171 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1172 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1173 it != lyxrc.bibtex_alternatives.end(); ++it) {
1174 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1175 biblioModule->bibtexCO->addItem(command, command);
1180 indicesModule = new GuiIndices;
1181 connect(indicesModule, SIGNAL(changed()),
1182 this, SLOT(change_adaptor()));
1186 // FIXME This UI has problems:
1187 // 1) It is not generic, packages_gui needs to be changed for each new package
1188 // 2) Two checkboxes have 4 states, but one is invalid (both pressed)
1189 // 3) The auto cb is not disabled if the use cb is checked
1190 mathsModule = new UiWidget<Ui::MathsUi>;
1191 vector<string> const & packages = BufferParams::auto_packages();
1192 for (size_t i = 0; i < packages.size(); ++i) {
1193 // Use the order of BufferParams::auto_packages() for easier
1194 // access in applyView() and paramsToDialog()
1196 for (n = 0; packages_gui[n][0][0]; n++)
1197 if (packages_gui[n][0] == packages[i])
1199 // If this fires somebody changed
1200 // BufferParams::auto_packages() without adjusting packages_gui
1201 LASSERT(packages_gui[n][0][0], /**/);
1202 QString autoText = qt_(packages_gui[n][1]);
1203 QString alwaysText = qt_(packages_gui[n][2]);
1204 QString autoTooltip = qt_(packages_gui[n][3]);
1205 QString alwaysTooltip;
1206 if (packages[i] == "amsmath")
1208 qt_("The AMS LaTeX packages are always used");
1210 alwaysTooltip = toqstr(bformat(
1211 _("The LaTeX package %1$s is always used"),
1212 from_ascii(packages[i])));
1213 QCheckBox * autoCB = new QCheckBox(autoText, mathsModule);
1214 QCheckBox * alwaysCB = new QCheckBox(alwaysText, mathsModule);
1215 mathsModule->gridLayout->addWidget(autoCB, 2 * i, 0);
1216 mathsModule->gridLayout->addWidget(alwaysCB, 2 * i + 1, 0);
1217 autoCB->setToolTip(autoTooltip);
1218 alwaysCB->setToolTip(alwaysTooltip);
1219 connect(autoCB, SIGNAL(toggled(bool)),
1220 alwaysCB, SLOT(setDisabled(bool)));
1221 connect(autoCB, SIGNAL(clicked()),
1222 this, SLOT(change_adaptor()));
1223 connect(alwaysCB, SIGNAL(clicked()),
1224 this, SLOT(change_adaptor()));
1226 QSpacerItem * spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum,
1227 QSizePolicy::Expanding);
1228 mathsModule->gridLayout->addItem(spacer, 2 * packages.size(), 0);
1232 latexModule = new UiWidget<Ui::LaTeXUi>;
1233 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1234 this, SLOT(change_adaptor()));
1235 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1236 this, SLOT(change_adaptor()));
1237 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1238 this, SLOT(change_adaptor()));
1239 connect(latexModule->classCO, SIGNAL(activated(int)),
1240 this, SLOT(classChanged()));
1241 connect(latexModule->classCO, SIGNAL(activated(int)),
1242 this, SLOT(change_adaptor()));
1243 connect(latexModule->layoutPB, SIGNAL(clicked()),
1244 this, SLOT(browseLayout()));
1245 connect(latexModule->layoutPB, SIGNAL(clicked()),
1246 this, SLOT(change_adaptor()));
1247 connect(latexModule->childDocGB, SIGNAL(clicked()),
1248 this, SLOT(change_adaptor()));
1249 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1250 this, SLOT(change_adaptor()));
1251 connect(latexModule->childDocPB, SIGNAL(clicked()),
1252 this, SLOT(browseMaster()));
1253 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1254 this, SLOT(change_adaptor()));
1255 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1256 this, SLOT(change_adaptor()));
1258 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1259 latexModule->optionsLE));
1260 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1261 latexModule->childDocLE));
1263 // postscript drivers
1264 for (int n = 0; tex_graphics[n][0]; ++n) {
1265 QString enc = qt_(tex_graphics_gui[n]);
1266 latexModule->psdriverCO->addItem(enc);
1269 latexModule->classCO->setModel(&classes_model_);
1270 LayoutFileList const & bcl = LayoutFileList::get();
1271 vector<LayoutFileIndex> classList = bcl.classList();
1272 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1274 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1275 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1276 for (int i = 0; cit != cen; ++cit, ++i) {
1277 LayoutFile const & tc = bcl[*cit];
1278 docstring item = (tc.isTeXClassAvailable()) ?
1279 from_utf8(tc.description()) :
1280 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1281 classes_model_.insertRow(i, toqstr(item), *cit);
1286 branchesModule = new GuiBranches;
1287 connect(branchesModule, SIGNAL(changed()),
1288 this, SLOT(change_adaptor()));
1289 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1290 this, SLOT(branchesRename(docstring const &, docstring const &)));
1291 updateUnknownBranches();
1295 preambleModule = new PreambleModule;
1296 connect(preambleModule, SIGNAL(changed()),
1297 this, SLOT(change_adaptor()));
1299 localLayout = new LocalLayout;
1300 connect(localLayout, SIGNAL(changed()),
1301 this, SLOT(change_adaptor()));
1305 bulletsModule = new BulletsModule;
1306 connect(bulletsModule, SIGNAL(changed()),
1307 this, SLOT(change_adaptor()));
1311 modulesModule = new UiWidget<Ui::ModulesUi>;
1312 modulesModule->availableLV->header()->setVisible(false);
1313 modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents);
1314 modulesModule->availableLV->header()->setStretchLastSection(false);
1316 new ModuleSelectionManager(modulesModule->availableLV,
1317 modulesModule->selectedLV,
1318 modulesModule->addPB, modulesModule->deletePB,
1319 modulesModule->upPB, modulesModule->downPB,
1320 availableModel(), selectedModel(), this);
1321 connect(selectionManager, SIGNAL(updateHook()),
1322 this, SLOT(updateModuleInfo()));
1323 connect(selectionManager, SIGNAL(updateHook()),
1324 this, SLOT(change_adaptor()));
1325 connect(selectionManager, SIGNAL(selectionChanged()),
1326 this, SLOT(modulesChanged()));
1330 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1331 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1332 this, SLOT(change_adaptor()));
1333 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1334 this, SLOT(change_adaptor()));
1335 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1336 this, SLOT(change_adaptor()));
1337 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1338 this, SLOT(change_adaptor()));
1339 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1340 this, SLOT(change_adaptor()));
1341 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1342 this, SLOT(change_adaptor()));
1343 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1344 this, SLOT(change_adaptor()));
1345 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1346 this, SLOT(change_adaptor()));
1347 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1348 this, SLOT(change_adaptor()));
1349 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1350 this, SLOT(change_adaptor()));
1351 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1352 this, SLOT(change_adaptor()));
1353 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1354 this, SLOT(change_adaptor()));
1355 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1356 this, SLOT(change_adaptor()));
1357 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1358 this, SLOT(change_adaptor()));
1359 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1360 this, SLOT(change_adaptor()));
1361 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1362 this, SLOT(change_adaptor()));
1364 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1365 pdfSupportModule->titleLE));
1366 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1367 pdfSupportModule->authorLE));
1368 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1369 pdfSupportModule->subjectLE));
1370 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1371 pdfSupportModule->keywordsLE));
1372 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1373 pdfSupportModule->optionsLE));
1375 for (int i = 0; backref_opts[i][0]; ++i)
1376 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1380 floatModule = new FloatPlacement;
1381 connect(floatModule, SIGNAL(changed()),
1382 this, SLOT(change_adaptor()));
1386 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1387 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1388 this, SLOT(change_adaptor()));
1389 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1390 this, SLOT(change_adaptor()));
1391 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1392 this, SLOT(setListingsMessage()));
1393 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1394 this, SLOT(setListingsMessage()));
1395 listingsModule->listingsTB->setPlainText(
1396 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1400 docPS->addPanel(latexModule, qt_("Document Class"));
1401 docPS->addPanel(masterChildModule, qt_("Child Documents"));
1402 docPS->addPanel(modulesModule, qt_("Modules"));
1403 docPS->addPanel(localLayout, qt_("Local Layout"));
1404 docPS->addPanel(fontModule, qt_("Fonts"));
1405 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1406 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1407 docPS->addPanel(marginsModule, qt_("Page Margins"));
1408 docPS->addPanel(langModule, qt_("Language"));
1409 docPS->addPanel(colorModule, qt_("Colors"));
1410 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1411 docPS->addPanel(biblioModule, qt_("Bibliography"));
1412 docPS->addPanel(indicesModule, qt_("Indexes"));
1413 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1414 docPS->addPanel(mathsModule, qt_("Math Options"));
1415 docPS->addPanel(floatModule, qt_("Float Placement"));
1416 docPS->addPanel(listingsModule, qt_("Listings"));
1417 docPS->addPanel(bulletsModule, qt_("Bullets"));
1418 docPS->addPanel(branchesModule, qt_("Branches"));
1419 docPS->addPanel(outputModule, qt_("Output"));
1420 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1421 docPS->setCurrentPanel(qt_("Document Class"));
1422 // FIXME: hack to work around resizing bug in Qt >= 4.2
1423 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1424 #if QT_VERSION >= 0x040200
1425 docPS->updateGeometry();
1430 void GuiDocument::saveDefaultClicked()
1436 void GuiDocument::useDefaultsClicked()
1442 void GuiDocument::change_adaptor()
1448 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1453 string child = fromqstr(item->text(0));
1457 if (std::find(includeonlys_.begin(),
1458 includeonlys_.end(), child) != includeonlys_.end())
1459 includeonlys_.remove(child);
1461 includeonlys_.push_back(child);
1463 updateIncludeonlys();
1468 QString GuiDocument::validateListingsParameters()
1470 // use a cache here to avoid repeated validation
1471 // of the same parameters
1472 static string param_cache;
1473 static QString msg_cache;
1475 if (listingsModule->bypassCB->isChecked())
1478 string params = fromqstr(listingsModule->listingsED->toPlainText());
1479 if (params != param_cache) {
1480 param_cache = params;
1481 msg_cache = toqstr(InsetListingsParams(params).validate());
1487 void GuiDocument::setListingsMessage()
1489 static bool isOK = true;
1490 QString msg = validateListingsParameters();
1491 if (msg.isEmpty()) {
1495 // listingsTB->setTextColor("black");
1496 listingsModule->listingsTB->setPlainText(
1497 qt_("Input listings parameters below. "
1498 "Enter ? for a list of parameters."));
1501 // listingsTB->setTextColor("red");
1502 listingsModule->listingsTB->setPlainText(msg);
1507 void GuiDocument::setLSpacing(int item)
1509 textLayoutModule->lspacingLE->setEnabled(item == 3);
1513 void GuiDocument::setIndent(int item)
1515 bool const enable = (item == 1);
1516 textLayoutModule->indentLE->setEnabled(enable);
1517 textLayoutModule->indentLengthCO->setEnabled(enable);
1518 textLayoutModule->skipLE->setEnabled(false);
1519 textLayoutModule->skipLengthCO->setEnabled(false);
1524 void GuiDocument::enableIndent(bool indent)
1526 textLayoutModule->skipLE->setEnabled(!indent);
1527 textLayoutModule->skipLengthCO->setEnabled(!indent);
1529 setIndent(textLayoutModule->indentCO->currentIndex());
1533 void GuiDocument::setSkip(int item)
1535 bool const enable = (item == 3);
1536 textLayoutModule->skipLE->setEnabled(enable);
1537 textLayoutModule->skipLengthCO->setEnabled(enable);
1542 void GuiDocument::enableSkip(bool skip)
1544 textLayoutModule->indentLE->setEnabled(!skip);
1545 textLayoutModule->indentLengthCO->setEnabled(!skip);
1547 setSkip(textLayoutModule->skipCO->currentIndex());
1551 void GuiDocument::setMargins()
1553 bool const extern_geometry =
1554 documentClass().provides("geometry");
1555 marginsModule->marginCB->setEnabled(!extern_geometry);
1556 if (extern_geometry) {
1557 marginsModule->marginCB->setChecked(false);
1558 setCustomMargins(true);
1560 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1561 setCustomMargins(!bp_.use_geometry);
1566 void GuiDocument::papersizeChanged(int paper_size)
1568 setCustomPapersize(paper_size == 1);
1572 void GuiDocument::setCustomPapersize(bool custom)
1574 pageLayoutModule->paperwidthL->setEnabled(custom);
1575 pageLayoutModule->paperwidthLE->setEnabled(custom);
1576 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1577 pageLayoutModule->paperheightL->setEnabled(custom);
1578 pageLayoutModule->paperheightLE->setEnabled(custom);
1579 pageLayoutModule->paperheightLE->setFocus();
1580 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1584 void GuiDocument::setColSep()
1586 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1590 void GuiDocument::setCustomMargins(bool custom)
1592 marginsModule->topL->setEnabled(!custom);
1593 marginsModule->topLE->setEnabled(!custom);
1594 marginsModule->topUnit->setEnabled(!custom);
1596 marginsModule->bottomL->setEnabled(!custom);
1597 marginsModule->bottomLE->setEnabled(!custom);
1598 marginsModule->bottomUnit->setEnabled(!custom);
1600 marginsModule->innerL->setEnabled(!custom);
1601 marginsModule->innerLE->setEnabled(!custom);
1602 marginsModule->innerUnit->setEnabled(!custom);
1604 marginsModule->outerL->setEnabled(!custom);
1605 marginsModule->outerLE->setEnabled(!custom);
1606 marginsModule->outerUnit->setEnabled(!custom);
1608 marginsModule->headheightL->setEnabled(!custom);
1609 marginsModule->headheightLE->setEnabled(!custom);
1610 marginsModule->headheightUnit->setEnabled(!custom);
1612 marginsModule->headsepL->setEnabled(!custom);
1613 marginsModule->headsepLE->setEnabled(!custom);
1614 marginsModule->headsepUnit->setEnabled(!custom);
1616 marginsModule->footskipL->setEnabled(!custom);
1617 marginsModule->footskipLE->setEnabled(!custom);
1618 marginsModule->footskipUnit->setEnabled(!custom);
1620 bool const enableColSep = !custom &&
1621 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1622 marginsModule->columnsepL->setEnabled(enableColSep);
1623 marginsModule->columnsepLE->setEnabled(enableColSep);
1624 marginsModule->columnsepUnit->setEnabled(enableColSep);
1628 void GuiDocument::changeBackgroundColor()
1630 QColor const & newColor = QColorDialog::getColor(
1631 rgb2qcolor(set_backgroundcolor), asQWidget());
1632 if (!newColor.isValid())
1634 // set the button color and text
1635 colorModule->backgroundPB->setStyleSheet(
1636 colorButtonStyleSheet(newColor));
1637 colorModule->backgroundPB->setText(qt_("&Change..."));
1639 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1640 is_backgroundcolor = true;
1645 void GuiDocument::deleteBackgroundColor()
1647 // set the button color back to default by setting an empty StyleSheet
1648 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1649 // change button text
1650 colorModule->backgroundPB->setText(qt_("&Default..."));
1651 // save default color (white)
1652 set_backgroundcolor = rgbFromHexName("#ffffff");
1653 is_backgroundcolor = false;
1658 void GuiDocument::changeFontColor()
1660 QColor const & newColor = QColorDialog::getColor(
1661 rgb2qcolor(set_fontcolor), asQWidget());
1662 if (!newColor.isValid())
1664 // set the button color and text
1665 colorModule->fontColorPB->setStyleSheet(
1666 colorButtonStyleSheet(newColor));
1667 colorModule->fontColorPB->setText(qt_("&Change..."));
1669 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1670 is_fontcolor = true;
1675 void GuiDocument::deleteFontColor()
1677 // set the button color back to default by setting an empty StyleSheet
1678 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1679 // change button text
1680 colorModule->fontColorPB->setText(qt_("&Default..."));
1681 // save default color (black)
1682 set_fontcolor = rgbFromHexName("#000000");
1683 is_fontcolor = false;
1688 void GuiDocument::changeNoteFontColor()
1690 QColor const & newColor = QColorDialog::getColor(
1691 rgb2qcolor(set_notefontcolor), asQWidget());
1692 if (!newColor.isValid())
1694 // set the button color
1695 colorModule->noteFontColorPB->setStyleSheet(
1696 colorButtonStyleSheet(newColor));
1698 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1703 void GuiDocument::deleteNoteFontColor()
1705 // set the button color back to pref
1706 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1707 colorModule->noteFontColorPB->setStyleSheet(
1708 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1713 void GuiDocument::changeBoxBackgroundColor()
1715 QColor const & newColor = QColorDialog::getColor(
1716 rgb2qcolor(set_boxbgcolor), asQWidget());
1717 if (!newColor.isValid())
1719 // set the button color
1720 colorModule->boxBackgroundPB->setStyleSheet(
1721 colorButtonStyleSheet(newColor));
1723 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1728 void GuiDocument::deleteBoxBackgroundColor()
1730 // set the button color back to pref
1731 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1732 colorModule->boxBackgroundPB->setStyleSheet(
1733 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1738 void GuiDocument::osFontsChanged(bool nontexfonts)
1740 bool const tex_fonts = !nontexfonts;
1742 updateDefaultFormat();
1743 langModule->encodingCO->setEnabled(tex_fonts &&
1744 !langModule->defaultencodingRB->isChecked());
1745 langModule->defaultencodingRB->setEnabled(tex_fonts);
1746 langModule->otherencodingRB->setEnabled(tex_fonts);
1748 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1749 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1750 fontModule->cjkFontLE->setEnabled(tex_fonts);
1751 fontModule->cjkFontLA->setEnabled(tex_fonts);
1754 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1755 bool scaleable = providesScale(font);
1756 fontModule->scaleSansSB->setEnabled(scaleable);
1757 fontModule->scaleSansLA->setEnabled(scaleable);
1759 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1760 scaleable = providesScale(font);
1761 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1762 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1764 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1765 fontModule->fontScCB->setEnabled(providesSC(font));
1766 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1768 fontModule->fontencLA->setEnabled(tex_fonts);
1769 fontModule->fontencCO->setEnabled(tex_fonts);
1771 fontModule->fontencLE->setEnabled(false);
1773 fontencChanged(fontModule->fontencCO->currentIndex());
1777 void GuiDocument::updateFontsize(string const & items, string const & sel)
1779 fontModule->fontsizeCO->clear();
1780 fontModule->fontsizeCO->addItem(qt_("Default"));
1782 for (int n = 0; !token(items,'|',n).empty(); ++n)
1783 fontModule->fontsizeCO->
1784 addItem(toqstr(token(items,'|',n)));
1786 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1787 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1788 fontModule->fontsizeCO->setCurrentIndex(n);
1795 void GuiDocument::updateFontlist()
1797 fontModule->fontsRomanCO->clear();
1798 fontModule->fontsSansCO->clear();
1799 fontModule->fontsTypewriterCO->clear();
1801 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1802 if (fontModule->osFontsCB->isChecked()) {
1803 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1804 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1805 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1807 QFontDatabase fontdb;
1808 QStringList families(fontdb.families());
1809 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1810 fontModule->fontsRomanCO->addItem(*it, *it);
1811 fontModule->fontsSansCO->addItem(*it, *it);
1812 fontModule->fontsTypewriterCO->addItem(*it, *it);
1817 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1818 QString font = qt_(tex_fonts_roman_gui[n]);
1819 if (!isFontAvailable(tex_fonts_roman[n]))
1820 font += qt_(" (not installed)");
1821 fontModule->fontsRomanCO->addItem(font, qt_(tex_fonts_roman[n]));
1823 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1824 QString font = qt_(tex_fonts_sans_gui[n]);
1825 if (!isFontAvailable(tex_fonts_sans[n]))
1826 font += qt_(" (not installed)");
1827 fontModule->fontsSansCO->addItem(font, qt_(tex_fonts_sans[n]));
1829 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1830 QString font = qt_(tex_fonts_monospaced_gui[n]);
1831 if (!isFontAvailable(tex_fonts_monospaced[n]))
1832 font += qt_(" (not installed)");
1833 fontModule->fontsTypewriterCO->addItem(font, qt_(tex_fonts_monospaced[n]));
1838 void GuiDocument::fontencChanged(int item)
1840 fontModule->fontencLE->setEnabled(item == 1);
1844 void GuiDocument::romanChanged(int item)
1846 if (fontModule->osFontsCB->isChecked())
1848 string const font = tex_fonts_roman[item];
1849 fontModule->fontScCB->setEnabled(providesSC(font));
1850 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1854 void GuiDocument::sansChanged(int item)
1856 if (fontModule->osFontsCB->isChecked())
1858 string const font = tex_fonts_sans[item];
1859 bool scaleable = providesScale(font);
1860 fontModule->scaleSansSB->setEnabled(scaleable);
1861 fontModule->scaleSansLA->setEnabled(scaleable);
1865 void GuiDocument::ttChanged(int item)
1867 if (fontModule->osFontsCB->isChecked())
1869 string const font = tex_fonts_monospaced[item];
1870 bool scaleable = providesScale(font);
1871 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1872 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1876 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1879 pageLayoutModule->pagestyleCO->clear();
1880 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1882 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1883 string style = token(items, '|', n);
1884 QString style_gui = qt_(style);
1885 pagestyles.push_back(pair<string, QString>(style, style_gui));
1886 pageLayoutModule->pagestyleCO->addItem(style_gui);
1889 if (sel == "default") {
1890 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1896 for (size_t i = 0; i < pagestyles.size(); ++i)
1897 if (pagestyles[i].first == sel)
1898 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1901 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1905 void GuiDocument::browseLayout()
1907 QString const label1 = qt_("Layouts|#o#O");
1908 QString const dir1 = toqstr(lyxrc.document_path);
1909 QStringList const filter(qt_("LyX Layout (*.layout)"));
1910 QString file = browseRelToParent(QString(), bufferFilePath(),
1911 qt_("Local layout file"), filter, false,
1914 if (!file.endsWith(".layout"))
1917 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1918 fromqstr(bufferFilePath()));
1920 int const ret = Alert::prompt(_("Local layout file"),
1921 _("The layout file you have selected is a local layout\n"
1922 "file, not one in the system or user directory. Your\n"
1923 "document may not work with this layout if you do not\n"
1924 "keep the layout file in the document directory."),
1925 1, 1, _("&Set Layout"), _("&Cancel"));
1929 // load the layout file
1930 LayoutFileList & bcl = LayoutFileList::get();
1931 string classname = layoutFile.onlyFileName();
1932 // this will update an existing layout if that layout has been loaded before.
1933 LayoutFileIndex name = bcl.addLocalLayout(
1934 classname.substr(0, classname.size() - 7),
1935 layoutFile.onlyPath().absFileName());
1938 Alert::error(_("Error"),
1939 _("Unable to read local layout file."));
1943 // do not trigger classChanged if there is no change.
1944 if (latexModule->classCO->currentText() == toqstr(name))
1948 int idx = latexModule->classCO->findText(toqstr(name));
1950 classes_model_.insertRow(0, toqstr(name), name);
1951 latexModule->classCO->setCurrentIndex(0);
1953 latexModule->classCO->setCurrentIndex(idx);
1959 void GuiDocument::browseMaster()
1961 QString const title = qt_("Select master document");
1962 QString const dir1 = toqstr(lyxrc.document_path);
1963 QString const old = latexModule->childDocLE->text();
1964 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1965 QStringList const filter(qt_("LyX Files (*.lyx)"));
1966 QString file = browseRelToSub(old, docpath, title, filter, false,
1967 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1969 if (!file.isEmpty())
1970 latexModule->childDocLE->setText(file);
1974 void GuiDocument::classChanged()
1976 int idx = latexModule->classCO->currentIndex();
1979 string const classname = classes_model_.getIDString(idx);
1981 // check whether the selected modules have changed.
1982 bool modules_changed = false;
1983 unsigned int const srows = selectedModel()->rowCount();
1984 if (srows != bp_.getModules().size())
1985 modules_changed = true;
1987 list<string>::const_iterator mit = bp_.getModules().begin();
1988 list<string>::const_iterator men = bp_.getModules().end();
1989 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1990 if (selectedModel()->getIDString(i) != *mit) {
1991 modules_changed = true;
1996 if (modules_changed || lyxrc.auto_reset_options) {
1997 if (applyPB->isEnabled()) {
1998 int const ret = Alert::prompt(_("Unapplied changes"),
1999 _("Some changes in the dialog were not yet applied.\n"
2000 "If you do not apply now, they will be lost after this action."),
2001 1, 1, _("&Apply"), _("&Dismiss"));
2007 // We load the TextClass as soon as it is selected. This is
2008 // necessary so that other options in the dialog can be updated
2009 // according to the new class. Note, however, that, if you use
2010 // the scroll wheel when sitting on the combo box, we'll load a
2011 // lot of TextClass objects very quickly....
2012 if (!bp_.setBaseClass(classname)) {
2013 Alert::error(_("Error"), _("Unable to set document class."));
2016 if (lyxrc.auto_reset_options)
2017 bp_.useClassDefaults();
2019 // With the introduction of modules came a distinction between the base
2020 // class and the document class. The former corresponds to the main layout
2021 // file; the latter is that plus the modules (or the document-specific layout,
2022 // or whatever else there could be). Our parameters come from the document
2023 // class. So when we set the base class, we also need to recreate the document
2024 // class. Otherwise, we still have the old one.
2025 bp_.makeDocumentClass();
2030 void GuiDocument::languagePackageChanged(int i)
2032 langModule->languagePackageLE->setEnabled(
2033 langModule->languagePackageCO->itemData(i).toString() == "custom");
2037 void GuiDocument::biblioChanged()
2039 biblioChanged_ = true;
2044 void GuiDocument::bibtexChanged(int n)
2046 biblioModule->bibtexOptionsLE->setEnabled(
2047 biblioModule->bibtexCO->itemData(n).toString() != "default");
2052 void GuiDocument::setAuthorYear(bool authoryear)
2055 biblioModule->citeStyleCO->setCurrentIndex(0);
2060 void GuiDocument::setNumerical(bool numerical)
2063 biblioModule->citeStyleCO->setCurrentIndex(1);
2070 // both of these should take a vector<docstring>
2072 // This is an insanely complicated attempt to make this sort of thing
2073 // work with RTL languages.
2074 docstring formatStrVec(vector<string> const & v, docstring const & s)
2076 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2080 return translateIfPossible(from_utf8(v[0]));
2081 if (v.size() == 2) {
2082 docstring retval = _("%1$s and %2$s");
2083 retval = subst(retval, _("and"), s);
2084 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2085 translateIfPossible(from_utf8(v[1])));
2087 // The idea here is to format all but the last two items...
2088 int const vSize = v.size();
2089 docstring t2 = _("%1$s, %2$s");
2090 docstring retval = translateIfPossible(from_utf8(v[0]));
2091 for (int i = 1; i < vSize - 2; ++i)
2092 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2093 //...and then to plug them, and the last two, into this schema
2094 docstring t = _("%1$s, %2$s, and %3$s");
2095 t = subst(t, _("and"), s);
2096 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2097 translateIfPossible(from_utf8(v[vSize - 1])));
2100 vector<string> idsToNames(vector<string> const & idList)
2102 vector<string> retval;
2103 vector<string>::const_iterator it = idList.begin();
2104 vector<string>::const_iterator end = idList.end();
2105 for (; it != end; ++it) {
2106 LyXModule const * const mod = theModuleList[*it];
2108 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2109 translateIfPossible(from_utf8(*it)))));
2111 retval.push_back(mod->getName());
2115 } // end anonymous namespace
2118 void GuiDocument::modulesToParams(BufferParams & bp)
2120 // update list of loaded modules
2121 bp.clearLayoutModules();
2122 int const srows = modules_sel_model_.rowCount();
2123 for (int i = 0; i < srows; ++i)
2124 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2126 // update the list of removed modules
2127 bp.clearRemovedModules();
2128 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2129 list<string>::const_iterator rit = reqmods.begin();
2130 list<string>::const_iterator ren = reqmods.end();
2132 // check each of the default modules
2133 for (; rit != ren; rit++) {
2134 list<string>::const_iterator mit = bp.getModules().begin();
2135 list<string>::const_iterator men = bp.getModules().end();
2137 for (; mit != men; mit++) {
2144 // the module isn't present so must have been removed by the user
2145 bp.addRemovedModule(*rit);
2150 void GuiDocument::modulesChanged()
2152 modulesToParams(bp_);
2153 bp_.makeDocumentClass();
2158 void GuiDocument::updateModuleInfo()
2160 selectionManager->update();
2162 //Module description
2163 bool const focus_on_selected = selectionManager->selectedFocused();
2164 QAbstractItemView * lv;
2165 if (focus_on_selected)
2166 lv = modulesModule->selectedLV;
2168 lv= modulesModule->availableLV;
2169 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2170 modulesModule->infoML->document()->clear();
2173 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2174 GuiIdListModel const & id_model =
2175 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2176 string const modName = id_model.getIDString(idx.row());
2177 docstring desc = getModuleDescription(modName);
2179 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2180 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2183 desc += _("Module provided by document class.");
2186 vector<string> pkglist = getPackageList(modName);
2187 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2188 if (!pkgdesc.empty()) {
2191 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2194 pkglist = getRequiredList(modName);
2195 if (!pkglist.empty()) {
2196 vector<string> const reqdescs = idsToNames(pkglist);
2197 pkgdesc = formatStrVec(reqdescs, _("or"));
2200 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2203 pkglist = getExcludedList(modName);
2204 if (!pkglist.empty()) {
2205 vector<string> const reqdescs = idsToNames(pkglist);
2206 pkgdesc = formatStrVec(reqdescs, _( "and"));
2209 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2212 if (!isModuleAvailable(modName)) {
2215 desc += _("WARNING: Some required packages are unavailable!");
2218 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2222 void GuiDocument::updateNumbering()
2224 DocumentClass const & tclass = documentClass();
2226 numberingModule->tocTW->setUpdatesEnabled(false);
2227 numberingModule->tocTW->clear();
2229 int const depth = numberingModule->depthSL->value();
2230 int const toc = numberingModule->tocSL->value();
2231 QString const no = qt_("No");
2232 QString const yes = qt_("Yes");
2233 QTreeWidgetItem * item = 0;
2235 DocumentClass::const_iterator lit = tclass.begin();
2236 DocumentClass::const_iterator len = tclass.end();
2237 for (; lit != len; ++lit) {
2238 int const toclevel = lit->toclevel;
2239 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
2240 item = new QTreeWidgetItem(numberingModule->tocTW);
2241 item->setText(0, toqstr(translateIfPossible(lit->name())));
2242 item->setText(1, (toclevel <= depth) ? yes : no);
2243 item->setText(2, (toclevel <= toc) ? yes : no);
2247 numberingModule->tocTW->setUpdatesEnabled(true);
2248 numberingModule->tocTW->update();
2252 void GuiDocument::updateDefaultFormat()
2256 // make a copy in order to consider unapplied changes
2257 BufferParams param_copy = buffer().params();
2258 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2259 int const idx = latexModule->classCO->currentIndex();
2261 string const classname = classes_model_.getIDString(idx);
2262 param_copy.setBaseClass(classname);
2263 param_copy.makeDocumentClass();
2265 outputModule->defaultFormatCO->blockSignals(true);
2266 outputModule->defaultFormatCO->clear();
2267 outputModule->defaultFormatCO->addItem(qt_("Default"),
2268 QVariant(QString("default")));
2269 typedef vector<Format const *> Formats;
2270 Formats formats = param_copy.exportableFormats(true);
2271 Formats::const_iterator cit = formats.begin();
2272 Formats::const_iterator end = formats.end();
2273 for (; cit != end; ++cit)
2274 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2275 QVariant(toqstr((*cit)->name())));
2276 outputModule->defaultFormatCO->blockSignals(false);
2280 bool GuiDocument::isChildIncluded(string const & child)
2282 if (includeonlys_.empty())
2284 return (std::find(includeonlys_.begin(),
2285 includeonlys_.end(), child) != includeonlys_.end());
2289 void GuiDocument::applyView()
2292 preambleModule->apply(bp_);
2293 localLayout->apply(bp_);
2296 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2297 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2300 bp_.setCiteEngine(ENGINE_BASIC);
2302 if (biblioModule->citeNatbibRB->isChecked())
2303 bp_.setCiteEngine(ENGINE_NATBIB);
2304 else if (biblioModule->citeJurabibRB->isChecked())
2305 bp_.setCiteEngine(ENGINE_JURABIB);
2307 if (biblioModule->citeStyleCO->currentIndex())
2308 bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
2310 bp_.setCiteEngineType(ENGINE_TYPE_AUTHORYEAR);
2313 biblioModule->bibtopicCB->isChecked();
2315 bp_.biblio_style = fromqstr(biblioModule->bibtexStyleLE->text());
2317 string const bibtex_command =
2318 fromqstr(biblioModule->bibtexCO->itemData(
2319 biblioModule->bibtexCO->currentIndex()).toString());
2320 string const bibtex_options =
2321 fromqstr(biblioModule->bibtexOptionsLE->text());
2322 if (bibtex_command == "default" || bibtex_options.empty())
2323 bp_.bibtex_command = bibtex_command;
2325 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2327 if (biblioChanged_) {
2328 buffer().invalidateBibinfoCache();
2329 buffer().removeBiblioTempFiles();
2333 indicesModule->apply(bp_);
2335 // language & quotes
2336 if (langModule->defaultencodingRB->isChecked()) {
2337 bp_.inputenc = "auto";
2339 int i = langModule->encodingCO->currentIndex();
2341 bp_.inputenc = "default";
2343 QString const enc_gui =
2344 langModule->encodingCO->currentText();
2345 Encodings::const_iterator it = encodings.begin();
2346 Encodings::const_iterator const end = encodings.end();
2348 for (; it != end; ++it) {
2349 if (qt_(it->guiName()) == enc_gui) {
2350 bp_.inputenc = it->latexName();
2356 // should not happen
2357 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2358 bp_.inputenc = "default";
2363 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2364 switch (langModule->quoteStyleCO->currentIndex()) {
2366 lga = InsetQuotes::EnglishQuotes;
2369 lga = InsetQuotes::SwedishQuotes;
2372 lga = InsetQuotes::GermanQuotes;
2375 lga = InsetQuotes::PolishQuotes;
2378 lga = InsetQuotes::FrenchQuotes;
2381 lga = InsetQuotes::DanishQuotes;
2384 bp_.quotes_language = lga;
2386 QString const lang = langModule->languageCO->itemData(
2387 langModule->languageCO->currentIndex()).toString();
2388 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2390 QString const pack = langModule->languagePackageCO->itemData(
2391 langModule->languagePackageCO->currentIndex()).toString();
2392 if (pack == "custom")
2394 fromqstr(langModule->languagePackageLE->text());
2396 bp_.lang_package = fromqstr(pack);
2399 bp_.backgroundcolor = set_backgroundcolor;
2400 bp_.isbackgroundcolor = is_backgroundcolor;
2401 bp_.fontcolor = set_fontcolor;
2402 bp_.isfontcolor = is_fontcolor;
2403 bp_.notefontcolor = set_notefontcolor;
2404 bp_.boxbgcolor = set_boxbgcolor;
2407 if (bp_.documentClass().hasTocLevels()) {
2408 bp_.tocdepth = numberingModule->tocSL->value();
2409 bp_.secnumdepth = numberingModule->depthSL->value();
2413 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2414 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2415 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2416 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2419 bp_.graphics_driver =
2420 tex_graphics[latexModule->psdriverCO->currentIndex()];
2423 int idx = latexModule->classCO->currentIndex();
2425 string const classname = classes_model_.getIDString(idx);
2426 bp_.setBaseClass(classname);
2430 modulesToParams(bp_);
2433 vector<string> const & packages = BufferParams::auto_packages();
2434 for (size_t n = 0; n < packages.size(); ++n) {
2435 QCheckBox * autoCB = static_cast<QCheckBox *>(
2436 mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget());
2437 if (autoCB->isChecked())
2438 bp_.use_package(packages[n], BufferParams::package_auto);
2440 QCheckBox * alwaysCB = static_cast<QCheckBox *>(
2441 mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget());
2442 if (alwaysCB->isChecked())
2443 bp_.use_package(packages[n], BufferParams::package_on);
2445 bp_.use_package(packages[n], BufferParams::package_off);
2450 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2451 bp_.pagestyle = "default";
2453 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2454 for (size_t i = 0; i != pagestyles.size(); ++i)
2455 if (pagestyles[i].second == style_gui)
2456 bp_.pagestyle = pagestyles[i].first;
2460 switch (textLayoutModule->lspacingCO->currentIndex()) {
2462 bp_.spacing().set(Spacing::Single);
2465 bp_.spacing().set(Spacing::Onehalf);
2468 bp_.spacing().set(Spacing::Double);
2471 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2473 bp_.spacing().set(Spacing::Single);
2475 bp_.spacing().set(Spacing::Other, s);
2480 if (textLayoutModule->twoColumnCB->isChecked())
2485 bp_.justification = textLayoutModule->justCB->isChecked();
2487 if (textLayoutModule->indentRB->isChecked()) {
2488 // if paragraphs are separated by an indentation
2489 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2490 switch (textLayoutModule->indentCO->currentIndex()) {
2492 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2495 HSpace indent = HSpace(
2496 widgetsToLength(textLayoutModule->indentLE,
2497 textLayoutModule->indentLengthCO)
2499 bp_.setIndentation(indent);
2503 // this should never happen
2504 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2508 // if paragraphs are separated by a skip
2509 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2510 switch (textLayoutModule->skipCO->currentIndex()) {
2512 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2515 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2518 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2523 widgetsToLength(textLayoutModule->skipLE,
2524 textLayoutModule->skipLengthCO)
2530 // this should never happen
2531 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2537 fromqstr(latexModule->optionsLE->text());
2539 bp_.use_default_options =
2540 latexModule->defaultOptionsCB->isChecked();
2542 if (latexModule->childDocGB->isChecked())
2544 fromqstr(latexModule->childDocLE->text());
2546 bp_.master = string();
2549 bp_.clearIncludedChildren();
2550 if (masterChildModule->includeonlyRB->isChecked()) {
2551 list<string>::const_iterator it = includeonlys_.begin();
2552 for (; it != includeonlys_.end() ; ++it) {
2553 bp_.addIncludedChildren(*it);
2556 bp_.maintain_unincluded_children =
2557 masterChildModule->maintainAuxCB->isChecked();
2560 bp_.float_placement = floatModule->get();
2563 // text should have passed validation
2564 bp_.listings_params =
2565 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2568 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
2569 outputModule->defaultFormatCO->currentIndex()).toString());
2571 bool const nontexfonts = fontModule->osFontsCB->isChecked();
2572 bp_.useNonTeXFonts = nontexfonts;
2574 bp_.output_sync = outputModule->outputsyncCB->isChecked();
2576 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2578 int mathfmt = outputModule->mathoutCB->currentIndex();
2581 BufferParams::MathOutput const mo =
2582 static_cast<BufferParams::MathOutput>(mathfmt);
2583 bp_.html_math_output = mo;
2584 bp_.html_be_strict = outputModule->strictCB->isChecked();
2585 bp_.html_css_as_file = outputModule->cssCB->isChecked();
2586 bp_.html_math_img_scale = outputModule->mathimgSB->value();
2590 fromqstr(fontModule->fontsRomanCO->
2591 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
2594 fromqstr(fontModule->fontsSansCO->
2595 itemData(fontModule->fontsSansCO->currentIndex()).toString());
2597 bp_.fonts_typewriter =
2598 fromqstr(fontModule->fontsTypewriterCO->
2599 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
2601 if (fontModule->fontencCO->currentIndex() == 0)
2602 bp_.fontenc = "global";
2603 else if (fontModule->fontencCO->currentIndex() == 1)
2604 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2605 else if (fontModule->fontencCO->currentIndex() == 2)
2606 bp_.fontenc = "default";
2609 fromqstr(fontModule->cjkFontLE->text());
2611 bp_.fonts_sans_scale = fontModule->scaleSansSB->value();
2613 bp_.fonts_typewriter_scale = fontModule->scaleTypewriterSB->value();
2615 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
2617 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
2620 bp_.fonts_default_family = "default";
2622 bp_.fonts_default_family = GuiDocument::fontfamilies[
2623 fontModule->fontsDefaultCO->currentIndex()];
2625 if (fontModule->fontsizeCO->currentIndex() == 0)
2626 bp_.fontsize = "default";
2629 fromqstr(fontModule->fontsizeCO->currentText());
2632 bp_.papersize = PAPER_SIZE(
2633 pageLayoutModule->papersizeCO->currentIndex());
2635 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2636 pageLayoutModule->paperwidthUnitCO);
2638 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2639 pageLayoutModule->paperheightUnitCO);
2641 if (pageLayoutModule->facingPagesCB->isChecked())
2642 bp_.sides = TwoSides;
2644 bp_.sides = OneSide;
2646 if (pageLayoutModule->landscapeRB->isChecked())
2647 bp_.orientation = ORIENTATION_LANDSCAPE;
2649 bp_.orientation = ORIENTATION_PORTRAIT;
2652 bp_.use_geometry = !marginsModule->marginCB->isChecked();
2654 Ui::MarginsUi const * m = marginsModule;
2656 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2657 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2658 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2659 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2660 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2661 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2662 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2663 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2666 branchesModule->apply(bp_);
2669 PDFOptions & pdf = bp_.pdfoptions();
2670 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2671 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2672 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2673 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2674 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2676 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2677 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2678 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2679 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2681 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2682 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2683 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2684 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2686 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2687 if (pdfSupportModule->fullscreenCB->isChecked())
2688 pdf.pagemode = pdf.pagemode_fullscreen;
2690 pdf.pagemode.clear();
2691 pdf.quoted_options = pdf.quoted_options_check(
2692 fromqstr(pdfSupportModule->optionsLE->text()));
2696 void GuiDocument::paramsToDialog()
2698 // set the default unit
2699 Length::UNIT const default_unit = Length::defaultUnit();
2702 preambleModule->update(bp_, id());
2703 localLayout->update(bp_, id());
2706 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2707 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
2710 biblioModule->citeDefaultRB->setChecked(
2711 bp_.citeEngine() == ENGINE_BASIC);
2713 biblioModule->citeNatbibRB->setChecked(
2714 bp_.citeEngine() == ENGINE_NATBIB);
2716 biblioModule->citeStyleCO->setCurrentIndex(
2717 bp_.citeEngineType() == ENGINE_TYPE_NUMERICAL);
2719 biblioModule->citeJurabibRB->setChecked(
2720 bp_.citeEngine() == ENGINE_JURABIB);
2722 biblioModule->bibtopicCB->setChecked(
2725 biblioModule->bibtexStyleLE->setText(toqstr(bp_.biblio_style));
2729 split(bp_.bibtex_command, command, ' ');
2731 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2733 biblioModule->bibtexCO->setCurrentIndex(bpos);
2734 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
2736 // We reset to default if we do not know the specified compiler
2737 // This is for security reasons
2738 biblioModule->bibtexCO->setCurrentIndex(
2739 biblioModule->bibtexCO->findData(toqstr("default")));
2740 biblioModule->bibtexOptionsLE->clear();
2742 biblioModule->bibtexOptionsLE->setEnabled(
2743 biblioModule->bibtexCO->currentIndex() != 0);
2745 biblioChanged_ = false;
2748 indicesModule->update(bp_);
2750 // language & quotes
2751 int const pos = langModule->languageCO->findData(toqstr(
2752 bp_.language->lang()));
2753 langModule->languageCO->setCurrentIndex(pos);
2755 langModule->quoteStyleCO->setCurrentIndex(
2756 bp_.quotes_language);
2758 bool default_enc = true;
2759 if (bp_.inputenc != "auto") {
2760 default_enc = false;
2761 if (bp_.inputenc == "default") {
2762 langModule->encodingCO->setCurrentIndex(0);
2765 Encodings::const_iterator it = encodings.begin();
2766 Encodings::const_iterator const end = encodings.end();
2767 for (; it != end; ++it) {
2768 if (it->latexName() == bp_.inputenc) {
2769 enc_gui = it->guiName();
2773 int const i = langModule->encodingCO->findText(
2776 langModule->encodingCO->setCurrentIndex(i);
2778 // unknown encoding. Set to default.
2782 langModule->defaultencodingRB->setChecked(default_enc);
2783 langModule->otherencodingRB->setChecked(!default_enc);
2785 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
2787 langModule->languagePackageCO->setCurrentIndex(
2788 langModule->languagePackageCO->findData("custom"));
2789 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
2791 langModule->languagePackageCO->setCurrentIndex(p);
2792 langModule->languagePackageLE->clear();
2796 if (bp_.isfontcolor) {
2797 colorModule->fontColorPB->setStyleSheet(
2798 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2800 set_fontcolor = bp_.fontcolor;
2801 is_fontcolor = bp_.isfontcolor;
2803 colorModule->noteFontColorPB->setStyleSheet(
2804 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2805 set_notefontcolor = bp_.notefontcolor;
2807 if (bp_.isbackgroundcolor) {
2808 colorModule->backgroundPB->setStyleSheet(
2809 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2811 set_backgroundcolor = bp_.backgroundcolor;
2812 is_backgroundcolor = bp_.isbackgroundcolor;
2814 colorModule->boxBackgroundPB->setStyleSheet(
2815 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
2816 set_boxbgcolor = bp_.boxbgcolor;
2819 int const min_toclevel = documentClass().min_toclevel();
2820 int const max_toclevel = documentClass().max_toclevel();
2821 if (documentClass().hasTocLevels()) {
2822 numberingModule->setEnabled(true);
2823 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2824 numberingModule->depthSL->setMaximum(max_toclevel);
2825 numberingModule->depthSL->setValue(bp_.secnumdepth);
2826 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2827 numberingModule->tocSL->setMaximum(max_toclevel);
2828 numberingModule->tocSL->setValue(bp_.tocdepth);
2831 numberingModule->setEnabled(false);
2832 numberingModule->tocTW->clear();
2836 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2837 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2838 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2839 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2840 bulletsModule->init();
2843 int nitem = findToken(tex_graphics, bp_.graphics_driver);
2845 latexModule->psdriverCO->setCurrentIndex(nitem);
2848 vector<string> const & packages = BufferParams::auto_packages();
2849 for (size_t n = 0; n < packages.size(); ++n) {
2850 QCheckBox * alwaysCB = static_cast<QCheckBox *>(
2851 mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget());
2852 alwaysCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_on);
2853 QCheckBox * autoCB = static_cast<QCheckBox *>(
2854 mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget());
2855 autoCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_auto);
2858 switch (bp_.spacing().getSpace()) {
2859 case Spacing::Other: nitem = 3; break;
2860 case Spacing::Double: nitem = 2; break;
2861 case Spacing::Onehalf: nitem = 1; break;
2862 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2866 string const & layoutID = bp_.baseClassID();
2867 setLayoutComboByIDString(layoutID);
2869 updatePagestyle(documentClass().opt_pagestyle(),
2872 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2873 if (bp_.spacing().getSpace() == Spacing::Other) {
2874 doubleToWidget(textLayoutModule->lspacingLE,
2875 bp_.spacing().getValueAsString());
2879 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2880 textLayoutModule->indentRB->setChecked(true);
2881 string indentation = bp_.getIndentation().asLyXCommand();
2883 if (indentation != "default") {
2884 lengthToWidgets(textLayoutModule->indentLE,
2885 textLayoutModule->indentLengthCO,
2886 indentation, default_unit);
2889 textLayoutModule->indentCO->setCurrentIndex(indent);
2892 textLayoutModule->skipRB->setChecked(true);
2894 switch (bp_.getDefSkip().kind()) {
2895 case VSpace::SMALLSKIP:
2898 case VSpace::MEDSKIP:
2901 case VSpace::BIGSKIP:
2904 case VSpace::LENGTH:
2907 string const length = bp_.getDefSkip().asLyXCommand();
2908 lengthToWidgets(textLayoutModule->skipLE,
2909 textLayoutModule->skipLengthCO,
2910 length, default_unit);
2917 textLayoutModule->skipCO->setCurrentIndex(skip);
2921 textLayoutModule->twoColumnCB->setChecked(
2923 textLayoutModule->justCB->setChecked(bp_.justification);
2925 if (!bp_.options.empty()) {
2926 latexModule->optionsLE->setText(
2927 toqstr(bp_.options));
2929 latexModule->optionsLE->setText(QString());
2933 latexModule->defaultOptionsCB->setChecked(
2934 bp_.use_default_options);
2935 updateSelectedModules();
2936 selectionManager->updateProvidedModules(
2937 bp_.baseClass()->providedModules());
2938 selectionManager->updateExcludedModules(
2939 bp_.baseClass()->excludedModules());
2941 if (!documentClass().options().empty()) {
2942 latexModule->defaultOptionsLE->setText(
2943 toqstr(documentClass().options()));
2945 latexModule->defaultOptionsLE->setText(
2946 toqstr(_("[No options predefined]")));
2949 latexModule->defaultOptionsLE->setEnabled(
2950 bp_.use_default_options
2951 && !documentClass().options().empty());
2953 latexModule->defaultOptionsCB->setEnabled(
2954 !documentClass().options().empty());
2956 if (!bp_.master.empty()) {
2957 latexModule->childDocGB->setChecked(true);
2958 latexModule->childDocLE->setText(
2959 toqstr(bp_.master));
2961 latexModule->childDocLE->setText(QString());
2962 latexModule->childDocGB->setChecked(false);
2966 if (!bufferview() || !buffer().hasChildren()) {
2967 masterChildModule->childrenTW->clear();
2968 includeonlys_.clear();
2969 docPS->showPanel(qt_("Child Documents"), false);
2970 if (docPS->isCurrentPanel(qt_("Child Documents")))
2971 docPS->setCurrentPanel(qt_("Document Class"));
2973 docPS->showPanel(qt_("Child Documents"), true);
2974 masterChildModule->setEnabled(true);
2975 includeonlys_ = bp_.getIncludedChildren();
2976 updateIncludeonlys();
2978 masterChildModule->maintainAuxCB->setChecked(
2979 bp_.maintain_unincluded_children);
2982 floatModule->set(bp_.float_placement);
2985 // break listings_params to multiple lines
2987 InsetListingsParams(bp_.listings_params).separatedParams();
2988 listingsModule->listingsED->setPlainText(toqstr(lstparams));
2991 bool const os_fonts_available =
2992 bp_.baseClass()->outputType() == lyx::LATEX
2993 && LaTeXFeatures::isAvailable("fontspec");
2994 fontModule->osFontsCB->setEnabled(os_fonts_available);
2995 fontModule->osFontsCB->setChecked(
2996 os_fonts_available && bp_.useNonTeXFonts);
2997 updateFontsize(documentClass().opt_fontsize(),
3000 QString font = toqstr(bp_.fonts_roman);
3001 int rpos = fontModule->fontsRomanCO->findData(font);
3003 rpos = fontModule->fontsRomanCO->count();
3004 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3006 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3008 font = toqstr(bp_.fonts_sans);
3009 int spos = fontModule->fontsSansCO->findData(font);
3011 spos = fontModule->fontsSansCO->count();
3012 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3014 fontModule->fontsSansCO->setCurrentIndex(spos);
3016 font = toqstr(bp_.fonts_typewriter);
3017 int tpos = fontModule->fontsTypewriterCO->findData(font);
3019 tpos = fontModule->fontsTypewriterCO->count();
3020 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3022 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3024 if (bp_.useNonTeXFonts && os_fonts_available) {
3025 fontModule->fontencLA->setEnabled(false);
3026 fontModule->fontencCO->setEnabled(false);
3027 fontModule->fontencLE->setEnabled(false);
3029 fontModule->fontencLA->setEnabled(true);
3030 fontModule->fontencCO->setEnabled(true);
3031 fontModule->fontencLE->setEnabled(true);
3037 if (!bp_.fonts_cjk.empty())
3038 fontModule->cjkFontLE->setText(
3039 toqstr(bp_.fonts_cjk));
3041 fontModule->cjkFontLE->setText(QString());
3043 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3044 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3045 fontModule->scaleSansSB->setValue(bp_.fonts_sans_scale);
3046 fontModule->scaleTypewriterSB->setValue(bp_.fonts_typewriter_scale);
3048 int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3050 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3052 if (bp_.fontenc == "global") {
3053 fontModule->fontencCO->setCurrentIndex(0);
3054 fontModule->fontencLE->setEnabled(false);
3055 } else if (bp_.fontenc == "default") {
3056 fontModule->fontencCO->setCurrentIndex(2);
3057 fontModule->fontencLE->setEnabled(false);
3059 fontModule->fontencCO->setCurrentIndex(1);
3060 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3064 // This must be set _after_ fonts since updateDefaultFormat()
3065 // checks osFontsCB settings.
3066 // update combobox with formats
3067 updateDefaultFormat();
3068 int index = outputModule->defaultFormatCO->findData(toqstr(
3069 bp_.default_output_format));
3070 // set to default if format is not found
3073 outputModule->defaultFormatCO->setCurrentIndex(index);
3075 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3076 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3078 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3079 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3080 outputModule->strictCB->setChecked(bp_.html_be_strict);
3081 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3084 bool const extern_geometry =
3085 documentClass().provides("geometry");
3086 int const psize = bp_.papersize;
3087 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3088 setCustomPapersize(!extern_geometry && psize == 1);
3089 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3091 bool const landscape =
3092 bp_.orientation == ORIENTATION_LANDSCAPE;
3093 pageLayoutModule->landscapeRB->setChecked(landscape);
3094 pageLayoutModule->portraitRB->setChecked(!landscape);
3095 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3096 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3098 pageLayoutModule->facingPagesCB->setChecked(
3099 bp_.sides == TwoSides);
3101 lengthToWidgets(pageLayoutModule->paperwidthLE,
3102 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3103 lengthToWidgets(pageLayoutModule->paperheightLE,
3104 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3107 Ui::MarginsUi * m = marginsModule;
3111 lengthToWidgets(m->topLE, m->topUnit,
3112 bp_.topmargin, default_unit);
3114 lengthToWidgets(m->bottomLE, m->bottomUnit,
3115 bp_.bottommargin, default_unit);
3117 lengthToWidgets(m->innerLE, m->innerUnit,
3118 bp_.leftmargin, default_unit);
3120 lengthToWidgets(m->outerLE, m->outerUnit,
3121 bp_.rightmargin, default_unit);
3123 lengthToWidgets(m->headheightLE, m->headheightUnit,
3124 bp_.headheight, default_unit);
3126 lengthToWidgets(m->headsepLE, m->headsepUnit,
3127 bp_.headsep, default_unit);
3129 lengthToWidgets(m->footskipLE, m->footskipUnit,
3130 bp_.footskip, default_unit);
3132 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3133 bp_.columnsep, default_unit);
3136 updateUnknownBranches();
3137 branchesModule->update(bp_);
3140 PDFOptions const & pdf = bp_.pdfoptions();
3141 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3142 if (bp_.documentClass().provides("hyperref"))
3143 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3145 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3146 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3147 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3148 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3149 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3151 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3152 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3153 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3155 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3157 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3158 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3159 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3160 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3162 nn = findToken(backref_opts, pdf.backref);
3164 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3166 pdfSupportModule->fullscreenCB->setChecked
3167 (pdf.pagemode == pdf.pagemode_fullscreen);
3169 pdfSupportModule->optionsLE->setText(
3170 toqstr(pdf.quoted_options));
3172 // Make sure that the bc is in the INITIAL state
3173 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3176 // clear changed branches cache
3177 changedBranches_.clear();
3181 void GuiDocument::saveDocDefault()
3183 // we have to apply the params first
3189 void GuiDocument::updateAvailableModules()
3191 modules_av_model_.clear();
3192 list<modInfoStruct> const & modInfoList = getModuleInfo();
3193 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3194 list<modInfoStruct>::const_iterator men = modInfoList.end();
3195 for (int i = 0; mit != men; ++mit, ++i)
3196 modules_av_model_.insertRow(i, mit->name, mit->id,
3201 void GuiDocument::updateSelectedModules()
3203 modules_sel_model_.clear();
3204 list<modInfoStruct> const selModList = getSelectedModules();
3205 list<modInfoStruct>::const_iterator mit = selModList.begin();
3206 list<modInfoStruct>::const_iterator men = selModList.end();
3207 for (int i = 0; mit != men; ++mit, ++i)
3208 modules_sel_model_.insertRow(i, mit->name, mit->id,
3213 void GuiDocument::updateIncludeonlys()
3215 masterChildModule->childrenTW->clear();
3216 QString const no = qt_("No");
3217 QString const yes = qt_("Yes");
3219 if (includeonlys_.empty()) {
3220 masterChildModule->includeallRB->setChecked(true);
3221 masterChildModule->childrenTW->setEnabled(false);
3222 masterChildModule->maintainAuxCB->setEnabled(false);
3224 masterChildModule->includeonlyRB->setChecked(true);
3225 masterChildModule->childrenTW->setEnabled(true);
3226 masterChildModule->maintainAuxCB->setEnabled(true);
3228 QTreeWidgetItem * item = 0;
3229 ListOfBuffers children = buffer().getChildren();
3230 ListOfBuffers::const_iterator it = children.begin();
3231 ListOfBuffers::const_iterator end = children.end();
3232 bool has_unincluded = false;
3233 bool all_unincluded = true;
3234 for (; it != end; ++it) {
3235 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3238 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3239 from_utf8(buffer().filePath())));
3240 item->setText(0, toqstr(name));
3241 item->setText(1, isChildIncluded(name) ? yes : no);
3242 if (!isChildIncluded(name))
3243 has_unincluded = true;
3245 all_unincluded = false;
3247 // Both if all childs are included and if none is included
3248 // is equal to "include all" (i.e., ommit \includeonly).
3249 // Thus, reset the GUI.
3250 if (!has_unincluded || all_unincluded) {
3251 masterChildModule->includeallRB->setChecked(true);
3252 masterChildModule->childrenTW->setEnabled(false);
3253 includeonlys_.clear();
3255 // If all are included, we need to update again.
3256 if (!has_unincluded)
3257 updateIncludeonlys();
3261 void GuiDocument::updateContents()
3263 // Nothing to do here as the document settings is not cursor dependant.
3268 void GuiDocument::useClassDefaults()
3270 if (applyPB->isEnabled()) {
3271 int const ret = Alert::prompt(_("Unapplied changes"),
3272 _("Some changes in the dialog were not yet applied.\n"
3273 "If you do not apply now, they will be lost after this action."),
3274 1, 1, _("&Apply"), _("&Dismiss"));
3279 int idx = latexModule->classCO->currentIndex();
3280 string const classname = classes_model_.getIDString(idx);
3281 if (!bp_.setBaseClass(classname)) {
3282 Alert::error(_("Error"), _("Unable to set document class."));
3285 bp_.useClassDefaults();
3290 void GuiDocument::setLayoutComboByIDString(string const & idString)
3292 int idx = classes_model_.findIDString(idString);
3294 Alert::warning(_("Can't set layout!"),
3295 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3297 latexModule->classCO->setCurrentIndex(idx);
3301 bool GuiDocument::isValid()
3304 validateListingsParameters().isEmpty() &&
3305 localLayout->isValid() &&
3307 // if we're asking for skips between paragraphs
3308 !textLayoutModule->skipRB->isChecked() ||
3309 // then either we haven't chosen custom
3310 textLayoutModule->skipCO->currentIndex() != 3 ||
3311 // or else a length has been given
3312 !textLayoutModule->skipLE->text().isEmpty()
3315 // if we're asking for indentation
3316 !textLayoutModule->indentRB->isChecked() ||
3317 // then either we haven't chosen custom
3318 textLayoutModule->indentCO->currentIndex() != 1 ||
3319 // or else a length has been given
3320 !textLayoutModule->indentLE->text().isEmpty()
3325 char const * const GuiDocument::fontfamilies[5] = {
3326 "default", "rmdefault", "sfdefault", "ttdefault", ""
3330 char const * GuiDocument::fontfamilies_gui[5] = {
3331 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3335 bool GuiDocument::initialiseParams(string const &)
3337 BufferView const * view = bufferview();
3339 bp_ = BufferParams();
3343 bp_ = view->buffer().params();
3345 updateAvailableModules();
3346 //FIXME It'd be nice to make sure here that the selected
3347 //modules are consistent: That required modules are actually
3348 //selected, and that we don't have conflicts. If so, we could
3349 //at least pop up a warning.
3355 void GuiDocument::clearParams()
3357 bp_ = BufferParams();
3361 BufferId GuiDocument::id() const
3363 BufferView const * const view = bufferview();
3364 return view? &view->buffer() : 0;
3368 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3370 return moduleNames_;
3374 list<GuiDocument::modInfoStruct> const
3375 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3377 LayoutModuleList::const_iterator it = mods.begin();
3378 LayoutModuleList::const_iterator end = mods.end();
3379 list<modInfoStruct> mInfo;
3380 for (; it != end; ++it) {
3383 LyXModule const * const mod = theModuleList[*it];
3386 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3388 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3395 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3397 return makeModuleInfo(params().getModules());
3401 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3403 return makeModuleInfo(params().baseClass()->providedModules());
3407 DocumentClass const & GuiDocument::documentClass() const
3409 return bp_.documentClass();
3413 static void dispatch_bufferparams(Dialog const & dialog,
3414 BufferParams const & bp, FuncCode lfun)
3417 ss << "\\begin_header\n";
3419 ss << "\\end_header\n";
3420 dialog.dispatch(FuncRequest(lfun, ss.str()));
3424 void GuiDocument::dispatchParams()
3426 // This must come first so that a language change is correctly noticed
3429 // Apply the BufferParams. Note that this will set the base class
3430 // and then update the buffer's layout.
3431 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3433 if (!params().master.empty()) {
3434 FileName const master_file = support::makeAbsPath(params().master,
3435 support::onlyPath(buffer().absFileName()));
3436 if (isLyXFileName(master_file.absFileName())) {
3437 Buffer * master = checkAndLoadLyXFile(master_file);
3439 if (master->isChild(const_cast<Buffer *>(&buffer())))
3440 const_cast<Buffer &>(buffer()).setParent(master);
3442 Alert::warning(_("Assigned master does not include this file"),
3443 bformat(_("You must include this file in the document\n"
3444 "'%1$s' in order to use the master document\n"
3445 "feature."), from_utf8(params().master)));
3447 Alert::warning(_("Could not load master"),
3448 bformat(_("The master document '%1$s'\n"
3449 "could not be loaded."),
3450 from_utf8(params().master)));
3454 // Generate the colours requested by each new branch.
3455 BranchList & branchlist = params().branchlist();
3456 if (!branchlist.empty()) {
3457 BranchList::const_iterator it = branchlist.begin();
3458 BranchList::const_iterator const end = branchlist.end();
3459 for (; it != end; ++it) {
3460 docstring const & current_branch = it->branch();
3461 Branch const * branch = branchlist.find(current_branch);
3462 string const x11hexname = X11hexname(branch->color());
3463 // display the new color
3464 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3465 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3468 // Open insets of selected branches, close deselected ones
3469 dispatch(FuncRequest(LFUN_INSET_FORALL,
3470 "Branch inset-toggle assign"));
3472 // rename branches in the document
3473 executeBranchRenaming();
3474 // and clear changed branches cache
3475 changedBranches_.clear();
3477 // Generate the colours requested by indices.
3478 IndicesList & indiceslist = params().indiceslist();
3479 if (!indiceslist.empty()) {
3480 IndicesList::const_iterator it = indiceslist.begin();
3481 IndicesList::const_iterator const end = indiceslist.end();
3482 for (; it != end; ++it) {
3483 docstring const & current_index = it->shortcut();
3484 Index const * index = indiceslist.findShortcut(current_index);
3485 string const x11hexname = X11hexname(index->color());
3486 // display the new color
3487 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3488 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3492 // If we used an LFUN, we would not need these two lines:
3493 BufferView * bv = const_cast<BufferView *>(bufferview());
3494 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3498 void GuiDocument::setLanguage() const
3500 Language const * const newL = bp_.language;
3501 if (buffer().params().language == newL)
3504 string const & lang_name = newL->lang();
3505 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3509 void GuiDocument::saveAsDefault() const
3511 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3515 bool GuiDocument::isFontAvailable(string const & font) const
3517 if (font == "default" || font == "cmr"
3518 || font == "cmss" || font == "cmtt")
3519 // these are standard
3521 if (font == "lmodern" || font == "lmss" || font == "lmtt")
3522 return LaTeXFeatures::isAvailable("lmodern");
3523 if (font == "times" || font == "palatino"
3524 || font == "helvet" || font == "courier")
3525 return LaTeXFeatures::isAvailable("psnfss");
3526 if (font == "cmbr" || font == "cmtl")
3527 return LaTeXFeatures::isAvailable("cmbright");
3528 if (font == "utopia")
3529 return LaTeXFeatures::isAvailable("utopia")
3530 || LaTeXFeatures::isAvailable("fourier");
3531 if (font == "beraserif" || font == "berasans"
3532 || font == "beramono")
3533 return LaTeXFeatures::isAvailable("bera");
3534 return LaTeXFeatures::isAvailable(font);
3538 bool GuiDocument::providesOSF(string const & font) const
3540 if (fontModule->osFontsCB->isChecked())
3541 // FIXME: we should check if the fonts really
3542 // have OSF support. But how?
3545 return isFontAvailable("eco");
3546 if (font == "palatino")
3547 return isFontAvailable("mathpazo");
3552 bool GuiDocument::providesSC(string const & font) const
3554 if (fontModule->osFontsCB->isChecked())
3556 if (font == "palatino")
3557 return isFontAvailable("mathpazo");
3558 if (font == "utopia")
3559 return isFontAvailable("fourier");
3564 bool GuiDocument::providesScale(string const & font) const
3566 if (fontModule->osFontsCB->isChecked())
3568 return font == "helvet" || font == "luximono"
3569 || font == "berasans" || font == "beramono";
3573 void GuiDocument::loadModuleInfo()
3575 moduleNames_.clear();
3576 LyXModuleList::const_iterator it = theModuleList.begin();
3577 LyXModuleList::const_iterator end = theModuleList.end();
3578 for (; it != end; ++it) {
3582 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3583 // this is supposed to give us the first sentence of the description
3586 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3587 int const pos = desc.indexOf(".");
3589 desc.truncate(pos + 1);
3590 m.description = desc;
3591 moduleNames_.push_back(m);
3596 void GuiDocument::updateUnknownBranches()
3600 list<docstring> used_branches;
3601 buffer().getUsedBranches(used_branches);
3602 list<docstring>::const_iterator it = used_branches.begin();
3603 QStringList unknown_branches;
3604 for (; it != used_branches.end() ; ++it) {
3605 if (!buffer().params().branchlist().find(*it))
3606 unknown_branches.append(toqstr(*it));
3608 branchesModule->setUnknownBranches(unknown_branches);
3612 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3614 map<docstring, docstring>::iterator it = changedBranches_.begin();
3615 for (; it != changedBranches_.end() ; ++it) {
3616 if (it->second == oldname) {
3617 // branch has already been renamed
3618 it->second = newname;
3623 changedBranches_[oldname] = newname;
3627 void GuiDocument::executeBranchRenaming() const
3629 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3630 for (; it != changedBranches_.end() ; ++it) {
3631 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3632 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3637 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3640 } // namespace frontend
3643 #include "moc_GuiDocument.cpp"