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/lstrings.h"
59 #include "frontends/alert.h"
61 #include <QAbstractItemModel>
62 #include <QHeaderView>
64 #include <QColorDialog>
65 #include <QCloseEvent>
66 #include <QFontDatabase>
68 #include <QTextCursor>
78 // a style sheet for buttons
79 // this is for example used for the background color setting button
80 static inline QString colorButtonStyleSheet(QColor const & bgColor)
82 if (bgColor.isValid()) {
83 QString rc = QLatin1String("background-color:");
92 using namespace lyx::support;
97 char const * const tex_graphics[] =
99 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
100 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
101 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
102 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
107 char const * const tex_graphics_gui[] =
109 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
110 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
111 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
112 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
113 "XeTeX", N_("None"), ""
117 char const * const tex_fonts_roman[] =
119 "default", "cmr", "lmodern", "ae", "times", "palatino",
120 "charter", "newcent", "bookman", "utopia", "beraserif",
121 "ccfonts", "chancery", ""
125 char const * tex_fonts_roman_gui[] =
127 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
128 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
129 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
130 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
135 char const * const tex_fonts_sans[] =
137 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
141 char const * tex_fonts_sans_gui[] =
143 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
144 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
148 char const * const tex_fonts_monospaced[] =
150 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
154 char const * tex_fonts_monospaced_gui[] =
156 N_("Default"), N_("Computer Modern Typewriter"),
157 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
158 N_("LuxiMono"), N_("CM Typewriter Light"), ""
162 char const * backref_opts[] =
164 "false", "section", "slide", "page", ""
168 char const * backref_opts_gui[] =
170 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
174 vector<pair<string, QString> > pagestyles;
177 } // anonymous namespace
181 RGBColor set_backgroundcolor;
182 bool is_backgroundcolor;
183 RGBColor set_fontcolor;
185 RGBColor set_notefontcolor;
186 RGBColor set_boxbgcolor;
189 // used when sorting the textclass list.
190 class less_textclass_avail_desc
191 : public binary_function<string, string, int>
194 bool operator()(string const & lhs, string const & rhs) const
196 // Ordering criteria:
197 // 1. Availability of text class
198 // 2. Description (lexicographic)
199 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
200 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
201 int const order = compare_no_case(
202 translateIfPossible(from_utf8(tc1.description())),
203 translateIfPossible(from_utf8(tc2.description())));
204 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
205 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
214 vector<string> getRequiredList(string const & modName)
216 LyXModule const * const mod = theModuleList[modName];
218 return vector<string>(); //empty such thing
219 return mod->getRequiredModules();
223 vector<string> getExcludedList(string const & modName)
225 LyXModule const * const mod = theModuleList[modName];
227 return vector<string>(); //empty such thing
228 return mod->getExcludedModules();
232 docstring getModuleDescription(string const & modName)
234 LyXModule const * const mod = theModuleList[modName];
236 return _("Module not found!");
238 return translateIfPossible(from_utf8(mod->getDescription()));
242 vector<string> getPackageList(string const & modName)
244 LyXModule const * const mod = theModuleList[modName];
246 return vector<string>(); //empty such thing
247 return mod->getPackageList();
251 bool isModuleAvailable(string const & modName)
253 LyXModule const * const mod = theModuleList[modName];
256 return mod->isAvailable();
259 } // anonymous namespace
262 /////////////////////////////////////////////////////////////////////
264 // ModuleSelectionManager
266 /////////////////////////////////////////////////////////////////////
268 /// SelectionManager for use with modules
269 class ModuleSelectionManager : public GuiSelectionManager
273 ModuleSelectionManager(
274 QTreeView * availableLV,
275 QListView * selectedLV,
279 QPushButton * downPB,
280 GuiIdListModel * availableModel,
281 GuiIdListModel * selectedModel,
282 GuiDocument const * container)
283 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
284 upPB, downPB, availableModel, selectedModel), container_(container)
287 void updateProvidedModules(LayoutModuleList const & pm)
288 { provided_modules_ = pm.list(); }
290 void updateExcludedModules(LayoutModuleList const & em)
291 { excluded_modules_ = em.list(); }
294 virtual void updateAddPB();
296 virtual void updateUpPB();
298 virtual void updateDownPB();
300 virtual void updateDelPB();
301 /// returns availableModel as a GuiIdListModel
302 GuiIdListModel * getAvailableModel()
304 return dynamic_cast<GuiIdListModel *>(availableModel);
306 /// returns selectedModel as a GuiIdListModel
307 GuiIdListModel * getSelectedModel()
309 return dynamic_cast<GuiIdListModel *>(selectedModel);
311 /// keeps a list of the modules the text class provides
312 list<string> provided_modules_;
314 list<string> excluded_modules_;
316 GuiDocument const * container_;
319 void ModuleSelectionManager::updateAddPB()
321 int const arows = availableModel->rowCount();
322 QModelIndexList const avail_sels =
323 availableLV->selectionModel()->selectedIndexes();
325 // disable if there aren't any modules (?), if none of them is chosen
326 // in the dialog, or if the chosen one is already selected for use.
327 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
328 addPB->setEnabled(false);
332 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
333 string const modname = getAvailableModel()->getIDString(idx.row());
336 container_->params().moduleCanBeAdded(modname);
337 addPB->setEnabled(enable);
341 void ModuleSelectionManager::updateDownPB()
343 int const srows = selectedModel->rowCount();
345 downPB->setEnabled(false);
348 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
349 int const curRow = curidx.row();
350 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
351 downPB->setEnabled(false);
355 // determine whether immediately succeding element requires this one
356 string const curmodname = getSelectedModel()->getIDString(curRow);
357 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
359 vector<string> reqs = getRequiredList(nextmodname);
361 // if it doesn't require anything....
363 downPB->setEnabled(true);
367 // Enable it if this module isn't required.
368 // FIXME This should perhaps be more flexible and check whether, even
369 // if the next one is required, there is also an earlier one that will do.
371 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
374 void ModuleSelectionManager::updateUpPB()
376 int const srows = selectedModel->rowCount();
378 upPB->setEnabled(false);
382 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
383 int curRow = curIdx.row();
384 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
385 upPB->setEnabled(false);
388 string const curmodname = getSelectedModel()->getIDString(curRow);
390 // determine whether immediately preceding element is required by this one
391 vector<string> reqs = getRequiredList(curmodname);
393 // if this one doesn't require anything....
395 upPB->setEnabled(true);
400 // Enable it if the preceding module isn't required.
401 // NOTE This is less flexible than it might be. We could check whether, even
402 // if the previous one is required, there is an earlier one that would do.
403 string const premod = getSelectedModel()->getIDString(curRow - 1);
404 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
407 void ModuleSelectionManager::updateDelPB()
409 int const srows = selectedModel->rowCount();
411 deletePB->setEnabled(false);
415 QModelIndex const & curidx =
416 selectedLV->selectionModel()->currentIndex();
417 int const curRow = curidx.row();
418 if (curRow < 0 || curRow >= srows) { // invalid index?
419 deletePB->setEnabled(false);
423 string const curmodname = getSelectedModel()->getIDString(curRow);
425 // We're looking here for a reason NOT to enable the button. If we
426 // find one, we disable it and return. If we don't, we'll end up at
427 // the end of the function, and then we enable it.
428 for (int i = curRow + 1; i < srows; ++i) {
429 string const thisMod = getSelectedModel()->getIDString(i);
430 vector<string> reqs = getRequiredList(thisMod);
431 //does this one require us?
432 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
436 // OK, so this module requires us
437 // is there an EARLIER module that also satisfies the require?
438 // NOTE We demand that it be earlier to keep the list of modules
439 // consistent with the rule that a module must be proceeded by a
440 // required module. There would be more flexible ways to proceed,
441 // but that would be a lot more complicated, and the logic here is
442 // already complicated. (That's why I've left the debugging code.)
443 // lyxerr << "Testing " << thisMod << endl;
444 bool foundone = false;
445 for (int j = 0; j < curRow; ++j) {
446 string const mod = getSelectedModel()->getIDString(j);
447 // lyxerr << "In loop: Testing " << mod << endl;
448 // do we satisfy the require?
449 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
450 // lyxerr << mod << " does the trick." << endl;
455 // did we find a module to satisfy the require?
457 // lyxerr << "No matching module found." << endl;
458 deletePB->setEnabled(false);
462 // lyxerr << "All's well that ends well." << endl;
463 deletePB->setEnabled(true);
467 /////////////////////////////////////////////////////////////////////
471 /////////////////////////////////////////////////////////////////////
473 PreambleModule::PreambleModule() : current_id_(0)
475 // This is not a memory leak. The object will be destroyed
477 (void) new LaTeXHighlighter(preambleTE->document());
478 setFocusProxy(preambleTE);
479 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
483 void PreambleModule::update(BufferParams const & params, BufferId id)
485 QString preamble = toqstr(params.preamble);
486 // Nothing to do if the params and preamble are unchanged.
487 if (id == current_id_
488 && preamble == preambleTE->document()->toPlainText())
491 QTextCursor cur = preambleTE->textCursor();
492 // Save the coords before switching to the new one.
493 preamble_coords_[current_id_] =
494 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
496 // Save the params address for further use.
498 preambleTE->document()->setPlainText(preamble);
499 Coords::const_iterator it = preamble_coords_.find(current_id_);
500 if (it == preamble_coords_.end())
501 // First time we open this one.
502 preamble_coords_[current_id_] = make_pair(0, 0);
504 // Restore saved coords.
505 QTextCursor cur = preambleTE->textCursor();
506 cur.setPosition(it->second.first);
507 preambleTE->setTextCursor(cur);
508 preambleTE->verticalScrollBar()->setValue(it->second.second);
513 void PreambleModule::apply(BufferParams & params)
515 params.preamble = fromqstr(preambleTE->document()->toPlainText());
519 void PreambleModule::closeEvent(QCloseEvent * e)
521 // Save the coords before closing.
522 QTextCursor cur = preambleTE->textCursor();
523 preamble_coords_[current_id_] =
524 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
529 /////////////////////////////////////////////////////////////////////
533 /////////////////////////////////////////////////////////////////////
536 LocalLayout::LocalLayout() : current_id_(0), is_valid_(false)
538 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
539 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
540 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
544 void LocalLayout::update(BufferParams const & params, BufferId id)
546 QString layout = toqstr(params.local_layout);
547 // Nothing to do if the params and preamble are unchanged.
548 if (id == current_id_
549 && layout == locallayoutTE->document()->toPlainText())
552 // Save the params address for further use.
554 locallayoutTE->document()->setPlainText(layout);
559 void LocalLayout::apply(BufferParams & params)
561 string const layout = fromqstr(locallayoutTE->document()->toPlainText());
562 params.local_layout = layout;
566 void LocalLayout::textChanged()
568 static const QString unknown = qt_("Press button to check validity...");
571 validLB->setText(unknown);
572 validatePB->setEnabled(true);
573 convertPB->setEnabled(false);
578 void LocalLayout::convert() {
579 string const layout =
580 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
581 string const newlayout = TextClass::convert(layout);
583 if (newlayout.empty()) {
584 Alert::error(_("Conversion Failed!"),
585 _("Failed to convert local layout to current format."));
587 locallayoutTE->setPlainText(toqstr(newlayout));
593 void LocalLayout::convertPressed() {
599 void LocalLayout::validate() {
600 static const QString valid = qt_("Layout is valid!");
601 static const QString vtext =
602 toqstr("<p style=\"font-weight: bold; \">")
603 + valid + toqstr("</p>");
604 static const QString invalid = qt_("Layout is invalid!");
605 static const QString ivtext =
606 toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
607 + invalid + toqstr("</p>");
609 string const layout =
610 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
611 if (layout.empty()) {
613 validatePB->setEnabled(false);
614 validLB->setText("");
618 TextClass::ReturnValues const ret = TextClass::validate(layout);
619 is_valid_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
620 validatePB->setEnabled(false);
621 validLB->setText(is_valid_ ? vtext : ivtext);
622 if (ret == TextClass::OK_OLDFORMAT) {
624 convertPB->setEnabled(true);
625 convertLB->setText(qt_("Convert to current format"));
635 void LocalLayout::validatePressed() {
641 /////////////////////////////////////////////////////////////////////
645 /////////////////////////////////////////////////////////////////////
648 GuiDocument::GuiDocument(GuiView & lv)
649 : GuiDialog(lv, "document", qt_("Document Settings"))
653 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
654 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
655 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
656 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
658 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
659 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
661 // Manage the restore, ok, apply, restore and cancel/close buttons
662 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
664 bc().setApply(applyPB);
665 bc().setCancel(closePB);
666 bc().setRestore(restorePB);
670 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
671 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
672 this, SLOT(change_adaptor()));
673 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
674 this, SLOT(setLSpacing(int)));
675 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
676 this, SLOT(change_adaptor()));
678 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
679 this, SLOT(change_adaptor()));
680 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
681 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
682 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
683 this, SLOT(change_adaptor()));
684 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
685 this, SLOT(setIndent(int)));
686 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
687 this, SLOT(change_adaptor()));
688 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
689 this, SLOT(change_adaptor()));
691 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
692 this, SLOT(change_adaptor()));
693 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
694 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
695 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
696 this, SLOT(change_adaptor()));
697 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
698 this, SLOT(setSkip(int)));
699 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
700 this, SLOT(change_adaptor()));
701 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
702 this, SLOT(change_adaptor()));
704 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
705 this, SLOT(enableIndent(bool)));
706 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
707 this, SLOT(enableSkip(bool)));
709 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
710 this, SLOT(change_adaptor()));
711 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
712 this, SLOT(setColSep()));
713 connect(textLayoutModule->justCB, SIGNAL(clicked()),
714 this, SLOT(change_adaptor()));
716 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
717 textLayoutModule->lspacingLE));
718 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
719 textLayoutModule->indentLE));
720 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
721 textLayoutModule->skipLE));
723 textLayoutModule->indentCO->addItem(qt_("Default"));
724 textLayoutModule->indentCO->addItem(qt_("Custom"));
725 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
726 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
727 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
728 textLayoutModule->skipCO->addItem(qt_("Custom"));
729 textLayoutModule->lspacingCO->insertItem(
730 Spacing::Single, qt_("Single"));
731 textLayoutModule->lspacingCO->insertItem(
732 Spacing::Onehalf, qt_("OneHalf"));
733 textLayoutModule->lspacingCO->insertItem(
734 Spacing::Double, qt_("Double"));
735 textLayoutModule->lspacingCO->insertItem(
736 Spacing::Other, qt_("Custom"));
737 // initialize the length validator
738 bc().addCheckedLineEdit(textLayoutModule->indentLE);
739 bc().addCheckedLineEdit(textLayoutModule->skipLE);
742 // master/child handling
743 masterChildModule = new UiWidget<Ui::MasterChildUi>;
745 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
746 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
747 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
748 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
749 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
750 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
751 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
752 this, SLOT(change_adaptor()));
753 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
754 this, SLOT(change_adaptor()));
755 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
756 this, SLOT(change_adaptor()));
757 masterChildModule->childrenTW->setColumnCount(2);
758 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
759 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
760 masterChildModule->childrenTW->resizeColumnToContents(1);
761 masterChildModule->childrenTW->resizeColumnToContents(2);
765 outputModule = new UiWidget<Ui::OutputUi>;
767 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
768 this, SLOT(change_adaptor()));
769 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
770 this, SLOT(change_adaptor()));
771 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
772 this, SLOT(change_adaptor()));
773 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
774 this, SLOT(change_adaptor()));
775 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
776 this, SLOT(change_adaptor()));
778 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
779 this, SLOT(change_adaptor()));
780 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
781 this, SLOT(change_adaptor()));
782 outputModule->synccustomCB->addItem("");
783 outputModule->synccustomCB->addItem("\\synctex=1");
784 outputModule->synccustomCB->addItem("\\synctex=-1");
785 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
787 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
788 outputModule->synccustomCB));
791 fontModule = new UiWidget<Ui::FontUi>;
792 connect(fontModule->osFontsCB, SIGNAL(clicked()),
793 this, SLOT(change_adaptor()));
794 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
795 this, SLOT(osFontsChanged(bool)));
796 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
797 this, SLOT(change_adaptor()));
798 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
799 this, SLOT(romanChanged(int)));
800 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
801 this, SLOT(change_adaptor()));
802 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
803 this, SLOT(sansChanged(int)));
804 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
805 this, SLOT(change_adaptor()));
806 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
807 this, SLOT(ttChanged(int)));
808 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
809 this, SLOT(change_adaptor()));
810 connect(fontModule->fontencCO, SIGNAL(activated(int)),
811 this, SLOT(change_adaptor()));
812 connect(fontModule->fontencCO, SIGNAL(activated(int)),
813 this, SLOT(fontencChanged(int)));
814 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
815 this, SLOT(change_adaptor()));
816 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
817 this, SLOT(change_adaptor()));
818 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
819 this, SLOT(change_adaptor()));
820 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
821 this, SLOT(change_adaptor()));
822 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
823 this, SLOT(change_adaptor()));
824 connect(fontModule->fontScCB, SIGNAL(clicked()),
825 this, SLOT(change_adaptor()));
826 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
827 this, SLOT(change_adaptor()));
829 fontModule->fontencLE->setValidator(new NoNewLineValidator(
830 fontModule->fontencLE));
831 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
832 fontModule->cjkFontLE));
836 fontModule->fontsizeCO->addItem(qt_("Default"));
837 fontModule->fontsizeCO->addItem(qt_("10"));
838 fontModule->fontsizeCO->addItem(qt_("11"));
839 fontModule->fontsizeCO->addItem(qt_("12"));
841 fontModule->fontencCO->addItem(qt_("Default"));
842 fontModule->fontencCO->addItem(qt_("Custom"));
843 fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
845 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
846 fontModule->fontsDefaultCO->addItem(
847 qt_(GuiDocument::fontfamilies_gui[n]));
849 if (!LaTeXFeatures::isAvailable("fontspec"))
850 fontModule->osFontsCB->setToolTip(
851 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
852 "You need to install the package \"fontspec\" to use this feature"));
856 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
857 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
858 this, SLOT(papersizeChanged(int)));
859 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
860 this, SLOT(papersizeChanged(int)));
861 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
862 this, SLOT(change_adaptor()));
863 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
864 this, SLOT(change_adaptor()));
865 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
866 this, SLOT(change_adaptor()));
867 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
868 this, SLOT(change_adaptor()));
869 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
870 this, SLOT(change_adaptor()));
871 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
872 this, SLOT(change_adaptor()));
873 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
874 this, SLOT(change_adaptor()));
875 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
876 this, SLOT(change_adaptor()));
877 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
878 this, SLOT(change_adaptor()));
879 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
880 this, SLOT(change_adaptor()));
882 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
883 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
884 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
885 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
886 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
887 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
888 pageLayoutModule->paperheightL);
889 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
890 pageLayoutModule->paperwidthL);
892 QComboBox * cb = pageLayoutModule->papersizeCO;
893 cb->addItem(qt_("Default"));
894 cb->addItem(qt_("Custom"));
895 cb->addItem(qt_("US letter"));
896 cb->addItem(qt_("US legal"));
897 cb->addItem(qt_("US executive"));
898 cb->addItem(qt_("A0"));
899 cb->addItem(qt_("A1"));
900 cb->addItem(qt_("A2"));
901 cb->addItem(qt_("A3"));
902 cb->addItem(qt_("A4"));
903 cb->addItem(qt_("A5"));
904 cb->addItem(qt_("A6"));
905 cb->addItem(qt_("B0"));
906 cb->addItem(qt_("B1"));
907 cb->addItem(qt_("B2"));
908 cb->addItem(qt_("B3"));
909 cb->addItem(qt_("B4"));
910 cb->addItem(qt_("B5"));
911 cb->addItem(qt_("B6"));
912 cb->addItem(qt_("C0"));
913 cb->addItem(qt_("C1"));
914 cb->addItem(qt_("C2"));
915 cb->addItem(qt_("C3"));
916 cb->addItem(qt_("C4"));
917 cb->addItem(qt_("C5"));
918 cb->addItem(qt_("C6"));
919 cb->addItem(qt_("JIS B0"));
920 cb->addItem(qt_("JIS B1"));
921 cb->addItem(qt_("JIS B2"));
922 cb->addItem(qt_("JIS B3"));
923 cb->addItem(qt_("JIS B4"));
924 cb->addItem(qt_("JIS B5"));
925 cb->addItem(qt_("JIS B6"));
926 // remove the %-items from the unit choice
927 pageLayoutModule->paperwidthUnitCO->noPercents();
928 pageLayoutModule->paperheightUnitCO->noPercents();
929 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
930 pageLayoutModule->paperheightLE));
931 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
932 pageLayoutModule->paperwidthLE));
936 marginsModule = new UiWidget<Ui::MarginsUi>;
937 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
938 this, SLOT(setCustomMargins(bool)));
939 connect(marginsModule->marginCB, SIGNAL(clicked()),
940 this, SLOT(change_adaptor()));
941 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
942 this, SLOT(change_adaptor()));
943 connect(marginsModule->topUnit, SIGNAL(activated(int)),
944 this, SLOT(change_adaptor()));
945 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
946 this, SLOT(change_adaptor()));
947 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
948 this, SLOT(change_adaptor()));
949 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
950 this, SLOT(change_adaptor()));
951 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
952 this, SLOT(change_adaptor()));
953 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
954 this, SLOT(change_adaptor()));
955 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
956 this, SLOT(change_adaptor()));
957 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
958 this, SLOT(change_adaptor()));
959 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
960 this, SLOT(change_adaptor()));
961 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
962 this, SLOT(change_adaptor()));
963 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
964 this, SLOT(change_adaptor()));
965 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
966 this, SLOT(change_adaptor()));
967 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
968 this, SLOT(change_adaptor()));
969 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
970 this, SLOT(change_adaptor()));
971 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
972 this, SLOT(change_adaptor()));
973 marginsModule->topLE->setValidator(unsignedLengthValidator(
974 marginsModule->topLE));
975 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
976 marginsModule->bottomLE));
977 marginsModule->innerLE->setValidator(unsignedLengthValidator(
978 marginsModule->innerLE));
979 marginsModule->outerLE->setValidator(unsignedLengthValidator(
980 marginsModule->outerLE));
981 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
982 marginsModule->headsepLE));
983 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
984 marginsModule->headheightLE));
985 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
986 marginsModule->footskipLE));
987 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
988 marginsModule->columnsepLE));
990 bc().addCheckedLineEdit(marginsModule->topLE,
991 marginsModule->topL);
992 bc().addCheckedLineEdit(marginsModule->bottomLE,
993 marginsModule->bottomL);
994 bc().addCheckedLineEdit(marginsModule->innerLE,
995 marginsModule->innerL);
996 bc().addCheckedLineEdit(marginsModule->outerLE,
997 marginsModule->outerL);
998 bc().addCheckedLineEdit(marginsModule->headsepLE,
999 marginsModule->headsepL);
1000 bc().addCheckedLineEdit(marginsModule->headheightLE,
1001 marginsModule->headheightL);
1002 bc().addCheckedLineEdit(marginsModule->footskipLE,
1003 marginsModule->footskipL);
1004 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1005 marginsModule->columnsepL);
1009 langModule = new UiWidget<Ui::LanguageUi>;
1010 connect(langModule->languageCO, SIGNAL(activated(int)),
1011 this, SLOT(change_adaptor()));
1012 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1013 this, SLOT(change_adaptor()));
1014 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1015 this, SLOT(change_adaptor()));
1016 connect(langModule->encodingCO, SIGNAL(activated(int)),
1017 this, SLOT(change_adaptor()));
1018 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1019 this, SLOT(change_adaptor()));
1020 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1021 this, SLOT(change_adaptor()));
1022 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1023 this, SLOT(change_adaptor()));
1024 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1025 this, SLOT(languagePackageChanged(int)));
1027 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1028 langModule->languagePackageLE));
1030 QAbstractItemModel * language_model = guiApp->languageModel();
1031 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1032 language_model->sort(0);
1033 langModule->languageCO->setModel(language_model);
1034 langModule->languageCO->setModelColumn(0);
1036 // Always put the default encoding in the first position.
1037 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1038 QStringList encodinglist;
1039 Encodings::const_iterator it = encodings.begin();
1040 Encodings::const_iterator const end = encodings.end();
1041 for (; it != end; ++it)
1042 encodinglist.append(qt_(it->guiName()));
1043 encodinglist.sort();
1044 langModule->encodingCO->addItems(encodinglist);
1046 langModule->quoteStyleCO->addItem(qt_("``text''"));
1047 langModule->quoteStyleCO->addItem(qt_("''text''"));
1048 langModule->quoteStyleCO->addItem(qt_(",,text``"));
1049 langModule->quoteStyleCO->addItem(qt_(",,text''"));
1050 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
1051 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
1053 langModule->languagePackageCO->addItem(
1054 qt_("Default"), toqstr("default"));
1055 langModule->languagePackageCO->addItem(
1056 qt_("Automatic"), toqstr("auto"));
1057 langModule->languagePackageCO->addItem(
1058 qt_("Always Babel"), toqstr("babel"));
1059 langModule->languagePackageCO->addItem(
1060 qt_("Custom"), toqstr("custom"));
1061 langModule->languagePackageCO->addItem(
1062 qt_("None[[language package]]"), toqstr("none"));
1066 colorModule = new UiWidget<Ui::ColorUi>;
1067 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1068 this, SLOT(changeFontColor()));
1069 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1070 this, SLOT(deleteFontColor()));
1071 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1072 this, SLOT(changeNoteFontColor()));
1073 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1074 this, SLOT(deleteNoteFontColor()));
1075 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1076 this, SLOT(changeBackgroundColor()));
1077 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1078 this, SLOT(deleteBackgroundColor()));
1079 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1080 this, SLOT(changeBoxBackgroundColor()));
1081 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1082 this, SLOT(deleteBoxBackgroundColor()));
1086 numberingModule = new UiWidget<Ui::NumberingUi>;
1087 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1088 this, SLOT(change_adaptor()));
1089 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1090 this, SLOT(change_adaptor()));
1091 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1092 this, SLOT(updateNumbering()));
1093 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1094 this, SLOT(updateNumbering()));
1095 numberingModule->tocTW->setColumnCount(3);
1096 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1097 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1098 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1099 numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents);
1103 biblioModule = new UiWidget<Ui::BiblioUi>;
1104 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1105 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1106 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1107 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1108 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1109 this, SLOT(biblioChanged()));
1110 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1111 this, SLOT(biblioChanged()));
1112 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1113 this, SLOT(biblioChanged()));
1114 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1115 this, SLOT(biblioChanged()));
1116 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1117 this, SLOT(biblioChanged()));
1118 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1119 this, SLOT(bibtexChanged(int)));
1120 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1121 this, SLOT(biblioChanged()));
1122 connect(biblioModule->bibtexStyleLE, SIGNAL(textChanged(QString)),
1123 this, SLOT(biblioChanged()));
1125 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1126 biblioModule->bibtexOptionsLE));
1127 biblioModule->bibtexStyleLE->setValidator(new NoNewLineValidator(
1128 biblioModule->bibtexStyleLE));
1130 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1131 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1132 biblioModule->citeStyleCO->setCurrentIndex(0);
1134 // NOTE: we do not provide "custom" here for security reasons!
1135 biblioModule->bibtexCO->clear();
1136 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1137 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1138 it != lyxrc.bibtex_alternatives.end(); ++it) {
1139 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1140 biblioModule->bibtexCO->addItem(command, command);
1145 indicesModule = new GuiIndices;
1146 connect(indicesModule, SIGNAL(changed()),
1147 this, SLOT(change_adaptor()));
1151 mathsModule = new UiWidget<Ui::MathsUi>;
1152 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
1153 mathsModule->amsCB, SLOT(setDisabled(bool)));
1154 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
1155 mathsModule->esintCB, SLOT(setDisabled(bool)));
1156 connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)),
1157 mathsModule->mhchemCB, SLOT(setDisabled(bool)));
1158 connect(mathsModule->mathdotsautoCB, SIGNAL(toggled(bool)),
1159 mathsModule->mathdotsCB, SLOT(setDisabled(bool)));
1160 connect(mathsModule->undertildeautoCB, SIGNAL(toggled(bool)),
1161 mathsModule->undertildeCB, SLOT(setDisabled(bool)));
1163 connect(mathsModule->amsCB, SIGNAL(clicked()),
1164 this, SLOT(change_adaptor()));
1165 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
1166 this, SLOT(change_adaptor()));
1167 connect(mathsModule->esintCB, SIGNAL(clicked()),
1168 this, SLOT(change_adaptor()));
1169 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
1170 this, SLOT(change_adaptor()));
1171 connect(mathsModule->mhchemCB, SIGNAL(clicked()),
1172 this, SLOT(change_adaptor()));
1173 connect(mathsModule->mhchemautoCB, SIGNAL(clicked()),
1174 this, SLOT(change_adaptor()));
1175 connect(mathsModule->mathdotsCB, SIGNAL(clicked()),
1176 this, SLOT(change_adaptor()));
1177 connect(mathsModule->mathdotsautoCB, SIGNAL(clicked()),
1178 this, SLOT(change_adaptor()));
1179 connect(mathsModule->undertildeCB, SIGNAL(clicked()),
1180 this, SLOT(change_adaptor()));
1181 connect(mathsModule->undertildeautoCB, SIGNAL(clicked()),
1182 this, SLOT(change_adaptor()));
1186 latexModule = new UiWidget<Ui::LaTeXUi>;
1187 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1188 this, SLOT(change_adaptor()));
1189 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1190 this, SLOT(change_adaptor()));
1191 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1192 this, SLOT(change_adaptor()));
1193 connect(latexModule->classCO, SIGNAL(activated(int)),
1194 this, SLOT(classChanged()));
1195 connect(latexModule->classCO, SIGNAL(activated(int)),
1196 this, SLOT(change_adaptor()));
1197 connect(latexModule->layoutPB, SIGNAL(clicked()),
1198 this, SLOT(browseLayout()));
1199 connect(latexModule->layoutPB, SIGNAL(clicked()),
1200 this, SLOT(change_adaptor()));
1201 connect(latexModule->childDocGB, SIGNAL(clicked()),
1202 this, SLOT(change_adaptor()));
1203 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1204 this, SLOT(change_adaptor()));
1205 connect(latexModule->childDocPB, SIGNAL(clicked()),
1206 this, SLOT(browseMaster()));
1207 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1208 this, SLOT(change_adaptor()));
1209 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1210 this, SLOT(change_adaptor()));
1212 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1213 latexModule->optionsLE));
1214 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1215 latexModule->childDocLE));
1217 // postscript drivers
1218 for (int n = 0; tex_graphics[n][0]; ++n) {
1219 QString enc = qt_(tex_graphics_gui[n]);
1220 latexModule->psdriverCO->addItem(enc);
1223 latexModule->classCO->setModel(&classes_model_);
1224 LayoutFileList const & bcl = LayoutFileList::get();
1225 vector<LayoutFileIndex> classList = bcl.classList();
1226 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1228 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1229 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1230 for (int i = 0; cit != cen; ++cit, ++i) {
1231 LayoutFile const & tc = bcl[*cit];
1232 docstring item = (tc.isTeXClassAvailable()) ?
1233 from_utf8(tc.description()) :
1234 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1235 classes_model_.insertRow(i, toqstr(item), *cit);
1240 branchesModule = new GuiBranches;
1241 connect(branchesModule, SIGNAL(changed()),
1242 this, SLOT(change_adaptor()));
1243 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1244 this, SLOT(branchesRename(docstring const &, docstring const &)));
1245 updateUnknownBranches();
1249 preambleModule = new PreambleModule;
1250 connect(preambleModule, SIGNAL(changed()),
1251 this, SLOT(change_adaptor()));
1253 localLayout = new LocalLayout;
1254 connect(localLayout, SIGNAL(changed()),
1255 this, SLOT(change_adaptor()));
1259 bulletsModule = new BulletsModule;
1260 connect(bulletsModule, SIGNAL(changed()),
1261 this, SLOT(change_adaptor()));
1265 modulesModule = new UiWidget<Ui::ModulesUi>;
1266 modulesModule->availableLV->header()->setVisible(false);
1267 modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents);
1268 modulesModule->availableLV->header()->setStretchLastSection(false);
1270 new ModuleSelectionManager(modulesModule->availableLV,
1271 modulesModule->selectedLV,
1272 modulesModule->addPB, modulesModule->deletePB,
1273 modulesModule->upPB, modulesModule->downPB,
1274 availableModel(), selectedModel(), this);
1275 connect(selectionManager, SIGNAL(updateHook()),
1276 this, SLOT(updateModuleInfo()));
1277 connect(selectionManager, SIGNAL(updateHook()),
1278 this, SLOT(change_adaptor()));
1279 connect(selectionManager, SIGNAL(selectionChanged()),
1280 this, SLOT(modulesChanged()));
1284 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1285 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1286 this, SLOT(change_adaptor()));
1287 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1288 this, SLOT(change_adaptor()));
1289 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1290 this, SLOT(change_adaptor()));
1291 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1292 this, SLOT(change_adaptor()));
1293 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1294 this, SLOT(change_adaptor()));
1295 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1296 this, SLOT(change_adaptor()));
1297 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1298 this, SLOT(change_adaptor()));
1299 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1300 this, SLOT(change_adaptor()));
1301 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1302 this, SLOT(change_adaptor()));
1303 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1304 this, SLOT(change_adaptor()));
1305 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1306 this, SLOT(change_adaptor()));
1307 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1308 this, SLOT(change_adaptor()));
1309 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1310 this, SLOT(change_adaptor()));
1311 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1312 this, SLOT(change_adaptor()));
1313 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1314 this, SLOT(change_adaptor()));
1315 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1316 this, SLOT(change_adaptor()));
1318 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1319 pdfSupportModule->titleLE));
1320 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1321 pdfSupportModule->authorLE));
1322 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1323 pdfSupportModule->subjectLE));
1324 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1325 pdfSupportModule->keywordsLE));
1326 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1327 pdfSupportModule->optionsLE));
1329 for (int i = 0; backref_opts[i][0]; ++i)
1330 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1334 floatModule = new FloatPlacement;
1335 connect(floatModule, SIGNAL(changed()),
1336 this, SLOT(change_adaptor()));
1340 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1341 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1342 this, SLOT(change_adaptor()));
1343 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1344 this, SLOT(change_adaptor()));
1345 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1346 this, SLOT(setListingsMessage()));
1347 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1348 this, SLOT(setListingsMessage()));
1349 listingsModule->listingsTB->setPlainText(
1350 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1354 docPS->addPanel(latexModule, qt_("Document Class"));
1355 docPS->addPanel(masterChildModule, qt_("Child Documents"));
1356 docPS->addPanel(modulesModule, qt_("Modules"));
1357 docPS->addPanel(localLayout, qt_("Local Layout"));
1358 docPS->addPanel(fontModule, qt_("Fonts"));
1359 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1360 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1361 docPS->addPanel(marginsModule, qt_("Page Margins"));
1362 docPS->addPanel(langModule, qt_("Language"));
1363 docPS->addPanel(colorModule, qt_("Colors"));
1364 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1365 docPS->addPanel(biblioModule, qt_("Bibliography"));
1366 docPS->addPanel(indicesModule, qt_("Indexes"));
1367 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1368 docPS->addPanel(mathsModule, qt_("Math Options"));
1369 docPS->addPanel(floatModule, qt_("Float Placement"));
1370 docPS->addPanel(listingsModule, qt_("Listings"));
1371 docPS->addPanel(bulletsModule, qt_("Bullets"));
1372 docPS->addPanel(branchesModule, qt_("Branches"));
1373 docPS->addPanel(outputModule, qt_("Output"));
1374 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1375 docPS->setCurrentPanel(qt_("Document Class"));
1376 // FIXME: hack to work around resizing bug in Qt >= 4.2
1377 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1378 #if QT_VERSION >= 0x040200
1379 docPS->updateGeometry();
1384 void GuiDocument::saveDefaultClicked()
1390 void GuiDocument::useDefaultsClicked()
1396 void GuiDocument::change_adaptor()
1402 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1407 string child = fromqstr(item->text(0));
1411 if (std::find(includeonlys_.begin(),
1412 includeonlys_.end(), child) != includeonlys_.end())
1413 includeonlys_.remove(child);
1415 includeonlys_.push_back(child);
1417 updateIncludeonlys();
1422 QString GuiDocument::validateListingsParameters()
1424 // use a cache here to avoid repeated validation
1425 // of the same parameters
1426 static string param_cache;
1427 static QString msg_cache;
1429 if (listingsModule->bypassCB->isChecked())
1432 string params = fromqstr(listingsModule->listingsED->toPlainText());
1433 if (params != param_cache) {
1434 param_cache = params;
1435 msg_cache = toqstr(InsetListingsParams(params).validate());
1441 void GuiDocument::setListingsMessage()
1443 static bool isOK = true;
1444 QString msg = validateListingsParameters();
1445 if (msg.isEmpty()) {
1449 // listingsTB->setTextColor("black");
1450 listingsModule->listingsTB->setPlainText(
1451 qt_("Input listings parameters below. "
1452 "Enter ? for a list of parameters."));
1455 // listingsTB->setTextColor("red");
1456 listingsModule->listingsTB->setPlainText(msg);
1461 void GuiDocument::setLSpacing(int item)
1463 textLayoutModule->lspacingLE->setEnabled(item == 3);
1467 void GuiDocument::setIndent(int item)
1469 bool const enable = (item == 1);
1470 textLayoutModule->indentLE->setEnabled(enable);
1471 textLayoutModule->indentLengthCO->setEnabled(enable);
1472 textLayoutModule->skipLE->setEnabled(false);
1473 textLayoutModule->skipLengthCO->setEnabled(false);
1478 void GuiDocument::enableIndent(bool indent)
1480 textLayoutModule->skipLE->setEnabled(!indent);
1481 textLayoutModule->skipLengthCO->setEnabled(!indent);
1483 setIndent(textLayoutModule->indentCO->currentIndex());
1487 void GuiDocument::setSkip(int item)
1489 bool const enable = (item == 3);
1490 textLayoutModule->skipLE->setEnabled(enable);
1491 textLayoutModule->skipLengthCO->setEnabled(enable);
1496 void GuiDocument::enableSkip(bool skip)
1498 textLayoutModule->indentLE->setEnabled(!skip);
1499 textLayoutModule->indentLengthCO->setEnabled(!skip);
1501 setSkip(textLayoutModule->skipCO->currentIndex());
1505 void GuiDocument::setMargins()
1507 bool const extern_geometry =
1508 documentClass().provides("geometry");
1509 marginsModule->marginCB->setEnabled(!extern_geometry);
1510 if (extern_geometry) {
1511 marginsModule->marginCB->setChecked(false);
1512 setCustomMargins(true);
1514 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1515 setCustomMargins(!bp_.use_geometry);
1520 void GuiDocument::papersizeChanged(int paper_size)
1522 setCustomPapersize(paper_size == 1);
1526 void GuiDocument::setCustomPapersize(bool custom)
1528 pageLayoutModule->paperwidthL->setEnabled(custom);
1529 pageLayoutModule->paperwidthLE->setEnabled(custom);
1530 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1531 pageLayoutModule->paperheightL->setEnabled(custom);
1532 pageLayoutModule->paperheightLE->setEnabled(custom);
1533 pageLayoutModule->paperheightLE->setFocus();
1534 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1538 void GuiDocument::setColSep()
1540 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1544 void GuiDocument::setCustomMargins(bool custom)
1546 marginsModule->topL->setEnabled(!custom);
1547 marginsModule->topLE->setEnabled(!custom);
1548 marginsModule->topUnit->setEnabled(!custom);
1550 marginsModule->bottomL->setEnabled(!custom);
1551 marginsModule->bottomLE->setEnabled(!custom);
1552 marginsModule->bottomUnit->setEnabled(!custom);
1554 marginsModule->innerL->setEnabled(!custom);
1555 marginsModule->innerLE->setEnabled(!custom);
1556 marginsModule->innerUnit->setEnabled(!custom);
1558 marginsModule->outerL->setEnabled(!custom);
1559 marginsModule->outerLE->setEnabled(!custom);
1560 marginsModule->outerUnit->setEnabled(!custom);
1562 marginsModule->headheightL->setEnabled(!custom);
1563 marginsModule->headheightLE->setEnabled(!custom);
1564 marginsModule->headheightUnit->setEnabled(!custom);
1566 marginsModule->headsepL->setEnabled(!custom);
1567 marginsModule->headsepLE->setEnabled(!custom);
1568 marginsModule->headsepUnit->setEnabled(!custom);
1570 marginsModule->footskipL->setEnabled(!custom);
1571 marginsModule->footskipLE->setEnabled(!custom);
1572 marginsModule->footskipUnit->setEnabled(!custom);
1574 bool const enableColSep = !custom &&
1575 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1576 marginsModule->columnsepL->setEnabled(enableColSep);
1577 marginsModule->columnsepLE->setEnabled(enableColSep);
1578 marginsModule->columnsepUnit->setEnabled(enableColSep);
1582 void GuiDocument::changeBackgroundColor()
1584 QColor const & newColor = QColorDialog::getColor(
1585 rgb2qcolor(set_backgroundcolor), asQWidget());
1586 if (!newColor.isValid())
1588 // set the button color and text
1589 colorModule->backgroundPB->setStyleSheet(
1590 colorButtonStyleSheet(newColor));
1591 colorModule->backgroundPB->setText(qt_("&Change..."));
1593 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1594 is_backgroundcolor = true;
1599 void GuiDocument::deleteBackgroundColor()
1601 // set the button color back to default by setting an empty StyleSheet
1602 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1603 // change button text
1604 colorModule->backgroundPB->setText(qt_("&Default..."));
1605 // save default color (white)
1606 set_backgroundcolor = rgbFromHexName("#ffffff");
1607 is_backgroundcolor = false;
1612 void GuiDocument::changeFontColor()
1614 QColor const & newColor = QColorDialog::getColor(
1615 rgb2qcolor(set_fontcolor), asQWidget());
1616 if (!newColor.isValid())
1618 // set the button color and text
1619 colorModule->fontColorPB->setStyleSheet(
1620 colorButtonStyleSheet(newColor));
1621 colorModule->fontColorPB->setText(qt_("&Change..."));
1623 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1624 is_fontcolor = true;
1629 void GuiDocument::deleteFontColor()
1631 // set the button color back to default by setting an empty StyleSheet
1632 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1633 // change button text
1634 colorModule->fontColorPB->setText(qt_("&Default..."));
1635 // save default color (black)
1636 set_fontcolor = rgbFromHexName("#000000");
1637 is_fontcolor = false;
1642 void GuiDocument::changeNoteFontColor()
1644 QColor const & newColor = QColorDialog::getColor(
1645 rgb2qcolor(set_notefontcolor), asQWidget());
1646 if (!newColor.isValid())
1648 // set the button color
1649 colorModule->noteFontColorPB->setStyleSheet(
1650 colorButtonStyleSheet(newColor));
1652 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1657 void GuiDocument::deleteNoteFontColor()
1659 // set the button color back to pref
1660 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1661 colorModule->noteFontColorPB->setStyleSheet(
1662 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1667 void GuiDocument::changeBoxBackgroundColor()
1669 QColor const & newColor = QColorDialog::getColor(
1670 rgb2qcolor(set_boxbgcolor), asQWidget());
1671 if (!newColor.isValid())
1673 // set the button color
1674 colorModule->boxBackgroundPB->setStyleSheet(
1675 colorButtonStyleSheet(newColor));
1677 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1682 void GuiDocument::deleteBoxBackgroundColor()
1684 // set the button color back to pref
1685 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1686 colorModule->boxBackgroundPB->setStyleSheet(
1687 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1692 void GuiDocument::osFontsChanged(bool nontexfonts)
1694 bool const tex_fonts = !nontexfonts;
1696 updateDefaultFormat();
1697 langModule->encodingCO->setEnabled(tex_fonts &&
1698 !langModule->defaultencodingRB->isChecked());
1699 langModule->defaultencodingRB->setEnabled(tex_fonts);
1700 langModule->otherencodingRB->setEnabled(tex_fonts);
1702 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1703 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1704 fontModule->cjkFontLE->setEnabled(tex_fonts);
1705 fontModule->cjkFontLA->setEnabled(tex_fonts);
1708 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1709 bool scaleable = providesScale(font);
1710 fontModule->scaleSansSB->setEnabled(scaleable);
1711 fontModule->scaleSansLA->setEnabled(scaleable);
1713 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1714 scaleable = providesScale(font);
1715 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1716 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1718 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1719 fontModule->fontScCB->setEnabled(providesSC(font));
1720 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1722 fontModule->fontencLA->setEnabled(tex_fonts);
1723 fontModule->fontencCO->setEnabled(tex_fonts);
1725 fontModule->fontencLE->setEnabled(false);
1727 fontencChanged(fontModule->fontencCO->currentIndex());
1731 void GuiDocument::updateFontsize(string const & items, string const & sel)
1733 fontModule->fontsizeCO->clear();
1734 fontModule->fontsizeCO->addItem(qt_("Default"));
1736 for (int n = 0; !token(items,'|',n).empty(); ++n)
1737 fontModule->fontsizeCO->
1738 addItem(toqstr(token(items,'|',n)));
1740 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1741 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1742 fontModule->fontsizeCO->setCurrentIndex(n);
1749 void GuiDocument::updateFontlist()
1751 fontModule->fontsRomanCO->clear();
1752 fontModule->fontsSansCO->clear();
1753 fontModule->fontsTypewriterCO->clear();
1755 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1756 if (fontModule->osFontsCB->isChecked()) {
1757 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1758 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1759 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1761 QFontDatabase fontdb;
1762 QStringList families(fontdb.families());
1763 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1764 fontModule->fontsRomanCO->addItem(*it, *it);
1765 fontModule->fontsSansCO->addItem(*it, *it);
1766 fontModule->fontsTypewriterCO->addItem(*it, *it);
1771 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1772 QString font = qt_(tex_fonts_roman_gui[n]);
1773 if (!isFontAvailable(tex_fonts_roman[n]))
1774 font += qt_(" (not installed)");
1775 fontModule->fontsRomanCO->addItem(font, qt_(tex_fonts_roman[n]));
1777 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1778 QString font = qt_(tex_fonts_sans_gui[n]);
1779 if (!isFontAvailable(tex_fonts_sans[n]))
1780 font += qt_(" (not installed)");
1781 fontModule->fontsSansCO->addItem(font, qt_(tex_fonts_sans[n]));
1783 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1784 QString font = qt_(tex_fonts_monospaced_gui[n]);
1785 if (!isFontAvailable(tex_fonts_monospaced[n]))
1786 font += qt_(" (not installed)");
1787 fontModule->fontsTypewriterCO->addItem(font, qt_(tex_fonts_monospaced[n]));
1792 void GuiDocument::fontencChanged(int item)
1794 fontModule->fontencLE->setEnabled(item == 1);
1798 void GuiDocument::romanChanged(int item)
1800 if (fontModule->osFontsCB->isChecked())
1802 string const font = tex_fonts_roman[item];
1803 fontModule->fontScCB->setEnabled(providesSC(font));
1804 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1808 void GuiDocument::sansChanged(int item)
1810 if (fontModule->osFontsCB->isChecked())
1812 string const font = tex_fonts_sans[item];
1813 bool scaleable = providesScale(font);
1814 fontModule->scaleSansSB->setEnabled(scaleable);
1815 fontModule->scaleSansLA->setEnabled(scaleable);
1819 void GuiDocument::ttChanged(int item)
1821 if (fontModule->osFontsCB->isChecked())
1823 string const font = tex_fonts_monospaced[item];
1824 bool scaleable = providesScale(font);
1825 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1826 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1830 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1833 pageLayoutModule->pagestyleCO->clear();
1834 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1836 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1837 string style = token(items, '|', n);
1838 QString style_gui = qt_(style);
1839 pagestyles.push_back(pair<string, QString>(style, style_gui));
1840 pageLayoutModule->pagestyleCO->addItem(style_gui);
1843 if (sel == "default") {
1844 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1850 for (size_t i = 0; i < pagestyles.size(); ++i)
1851 if (pagestyles[i].first == sel)
1852 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1855 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1859 void GuiDocument::browseLayout()
1861 QString const label1 = qt_("Layouts|#o#O");
1862 QString const dir1 = toqstr(lyxrc.document_path);
1863 QStringList const filter(qt_("LyX Layout (*.layout)"));
1864 QString file = browseRelToParent(QString(), bufferFilePath(),
1865 qt_("Local layout file"), filter, false,
1868 if (!file.endsWith(".layout"))
1871 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1872 fromqstr(bufferFilePath()));
1874 int const ret = Alert::prompt(_("Local layout file"),
1875 _("The layout file you have selected is a local layout\n"
1876 "file, not one in the system or user directory. Your\n"
1877 "document may not work with this layout if you do not\n"
1878 "keep the layout file in the document directory."),
1879 1, 1, _("&Set Layout"), _("&Cancel"));
1883 // load the layout file
1884 LayoutFileList & bcl = LayoutFileList::get();
1885 string classname = layoutFile.onlyFileName();
1886 // this will update an existing layout if that layout has been loaded before.
1887 LayoutFileIndex name = bcl.addLocalLayout(
1888 classname.substr(0, classname.size() - 7),
1889 layoutFile.onlyPath().absFileName());
1892 Alert::error(_("Error"),
1893 _("Unable to read local layout file."));
1897 // do not trigger classChanged if there is no change.
1898 if (latexModule->classCO->currentText() == toqstr(name))
1902 int idx = latexModule->classCO->findText(toqstr(name));
1904 classes_model_.insertRow(0, toqstr(name), name);
1905 latexModule->classCO->setCurrentIndex(0);
1907 latexModule->classCO->setCurrentIndex(idx);
1913 void GuiDocument::browseMaster()
1915 QString const title = qt_("Select master document");
1916 QString const dir1 = toqstr(lyxrc.document_path);
1917 QString const old = latexModule->childDocLE->text();
1918 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1919 QStringList const filter(qt_("LyX Files (*.lyx)"));
1920 QString file = browseRelToSub(old, docpath, title, filter, false,
1921 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1923 if (!file.isEmpty())
1924 latexModule->childDocLE->setText(file);
1928 void GuiDocument::classChanged()
1930 int idx = latexModule->classCO->currentIndex();
1933 string const classname = classes_model_.getIDString(idx);
1935 // check whether the selected modules have changed.
1936 bool modules_changed = false;
1937 unsigned int const srows = selectedModel()->rowCount();
1938 if (srows != bp_.getModules().size())
1939 modules_changed = true;
1941 list<string>::const_iterator mit = bp_.getModules().begin();
1942 list<string>::const_iterator men = bp_.getModules().end();
1943 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1944 if (selectedModel()->getIDString(i) != *mit) {
1945 modules_changed = true;
1950 if (modules_changed || lyxrc.auto_reset_options) {
1951 if (applyPB->isEnabled()) {
1952 int const ret = Alert::prompt(_("Unapplied changes"),
1953 _("Some changes in the dialog were not yet applied.\n"
1954 "If you do not apply now, they will be lost after this action."),
1955 1, 1, _("&Apply"), _("&Dismiss"));
1961 // We load the TextClass as soon as it is selected. This is
1962 // necessary so that other options in the dialog can be updated
1963 // according to the new class. Note, however, that, if you use
1964 // the scroll wheel when sitting on the combo box, we'll load a
1965 // lot of TextClass objects very quickly....
1966 if (!bp_.setBaseClass(classname)) {
1967 Alert::error(_("Error"), _("Unable to set document class."));
1970 if (lyxrc.auto_reset_options)
1971 bp_.useClassDefaults();
1973 // With the introduction of modules came a distinction between the base
1974 // class and the document class. The former corresponds to the main layout
1975 // file; the latter is that plus the modules (or the document-specific layout,
1976 // or whatever else there could be). Our parameters come from the document
1977 // class. So when we set the base class, we also need to recreate the document
1978 // class. Otherwise, we still have the old one.
1979 bp_.makeDocumentClass();
1984 void GuiDocument::languagePackageChanged(int i)
1986 langModule->languagePackageLE->setEnabled(
1987 langModule->languagePackageCO->itemData(i).toString() == "custom");
1991 void GuiDocument::biblioChanged()
1993 biblioChanged_ = true;
1998 void GuiDocument::bibtexChanged(int n)
2000 biblioModule->bibtexOptionsLE->setEnabled(
2001 biblioModule->bibtexCO->itemData(n).toString() != "default");
2008 // both of these should take a vector<docstring>
2010 // This is an insanely complicated attempt to make this sort of thing
2011 // work with RTL languages.
2012 docstring formatStrVec(vector<string> const & v, docstring const & s)
2014 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2018 return translateIfPossible(from_utf8(v[0]));
2019 if (v.size() == 2) {
2020 docstring retval = _("%1$s and %2$s");
2021 retval = subst(retval, _("and"), s);
2022 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2023 translateIfPossible(from_utf8(v[1])));
2025 // The idea here is to format all but the last two items...
2026 int const vSize = v.size();
2027 docstring t2 = _("%1$s, %2$s");
2028 docstring retval = translateIfPossible(from_utf8(v[0]));
2029 for (int i = 1; i < vSize - 2; ++i)
2030 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2031 //...and then to plug them, and the last two, into this schema
2032 docstring t = _("%1$s, %2$s, and %3$s");
2033 t = subst(t, _("and"), s);
2034 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2035 translateIfPossible(from_utf8(v[vSize - 1])));
2038 vector<string> idsToNames(vector<string> const & idList)
2040 vector<string> retval;
2041 vector<string>::const_iterator it = idList.begin();
2042 vector<string>::const_iterator end = idList.end();
2043 for (; it != end; ++it) {
2044 LyXModule const * const mod = theModuleList[*it];
2046 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2047 translateIfPossible(from_utf8(*it)))));
2049 retval.push_back(mod->getName());
2053 } // end anonymous namespace
2056 void GuiDocument::modulesToParams(BufferParams & bp)
2058 // update list of loaded modules
2059 bp.clearLayoutModules();
2060 int const srows = modules_sel_model_.rowCount();
2061 for (int i = 0; i < srows; ++i)
2062 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2064 // update the list of removed modules
2065 bp.clearRemovedModules();
2066 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2067 list<string>::const_iterator rit = reqmods.begin();
2068 list<string>::const_iterator ren = reqmods.end();
2070 // check each of the default modules
2071 for (; rit != ren; rit++) {
2072 list<string>::const_iterator mit = bp.getModules().begin();
2073 list<string>::const_iterator men = bp.getModules().end();
2075 for (; mit != men; mit++) {
2082 // the module isn't present so must have been removed by the user
2083 bp.addRemovedModule(*rit);
2088 void GuiDocument::modulesChanged()
2090 modulesToParams(bp_);
2091 bp_.makeDocumentClass();
2096 void GuiDocument::updateModuleInfo()
2098 selectionManager->update();
2100 //Module description
2101 bool const focus_on_selected = selectionManager->selectedFocused();
2102 QAbstractItemView * lv;
2103 if (focus_on_selected)
2104 lv = modulesModule->selectedLV;
2106 lv= modulesModule->availableLV;
2107 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2108 modulesModule->infoML->document()->clear();
2111 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2112 GuiIdListModel const & id_model =
2113 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2114 string const modName = id_model.getIDString(idx.row());
2115 docstring desc = getModuleDescription(modName);
2117 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2118 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2121 desc += _("Module provided by document class.");
2124 vector<string> pkglist = getPackageList(modName);
2125 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2126 if (!pkgdesc.empty()) {
2129 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2132 pkglist = getRequiredList(modName);
2133 if (!pkglist.empty()) {
2134 vector<string> const reqdescs = idsToNames(pkglist);
2135 pkgdesc = formatStrVec(reqdescs, _("or"));
2138 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2141 pkglist = getExcludedList(modName);
2142 if (!pkglist.empty()) {
2143 vector<string> const reqdescs = idsToNames(pkglist);
2144 pkgdesc = formatStrVec(reqdescs, _( "and"));
2147 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2150 if (!isModuleAvailable(modName)) {
2153 desc += _("WARNING: Some required packages are unavailable!");
2156 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2160 void GuiDocument::updateNumbering()
2162 DocumentClass const & tclass = documentClass();
2164 numberingModule->tocTW->setUpdatesEnabled(false);
2165 numberingModule->tocTW->clear();
2167 int const depth = numberingModule->depthSL->value();
2168 int const toc = numberingModule->tocSL->value();
2169 QString const no = qt_("No");
2170 QString const yes = qt_("Yes");
2171 QTreeWidgetItem * item = 0;
2173 DocumentClass::const_iterator lit = tclass.begin();
2174 DocumentClass::const_iterator len = tclass.end();
2175 for (; lit != len; ++lit) {
2176 int const toclevel = lit->toclevel;
2177 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
2178 item = new QTreeWidgetItem(numberingModule->tocTW);
2179 item->setText(0, toqstr(translateIfPossible(lit->name())));
2180 item->setText(1, (toclevel <= depth) ? yes : no);
2181 item->setText(2, (toclevel <= toc) ? yes : no);
2185 numberingModule->tocTW->setUpdatesEnabled(true);
2186 numberingModule->tocTW->update();
2190 void GuiDocument::updateDefaultFormat()
2194 // make a copy in order to consider unapplied changes
2195 BufferParams param_copy = buffer().params();
2196 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2197 int const idx = latexModule->classCO->currentIndex();
2199 string const classname = classes_model_.getIDString(idx);
2200 param_copy.setBaseClass(classname);
2201 param_copy.makeDocumentClass();
2203 outputModule->defaultFormatCO->blockSignals(true);
2204 outputModule->defaultFormatCO->clear();
2205 outputModule->defaultFormatCO->addItem(qt_("Default"),
2206 QVariant(QString("default")));
2207 typedef vector<Format const *> Formats;
2208 Formats formats = param_copy.exportableFormats(true);
2209 Formats::const_iterator cit = formats.begin();
2210 Formats::const_iterator end = formats.end();
2211 for (; cit != end; ++cit)
2212 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2213 QVariant(toqstr((*cit)->name())));
2214 outputModule->defaultFormatCO->blockSignals(false);
2218 bool GuiDocument::isChildIncluded(string const & child)
2220 if (includeonlys_.empty())
2222 return (std::find(includeonlys_.begin(),
2223 includeonlys_.end(), child) != includeonlys_.end());
2227 void GuiDocument::applyView()
2230 preambleModule->apply(bp_);
2231 localLayout->apply(bp_);
2234 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2235 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2238 bp_.setCiteEngine(ENGINE_BASIC);
2240 if (biblioModule->citeNatbibRB->isChecked()) {
2241 bool const use_numerical_citations =
2242 biblioModule->citeStyleCO->currentIndex();
2243 if (use_numerical_citations)
2244 bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
2246 bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
2248 } else if (biblioModule->citeJurabibRB->isChecked())
2249 bp_.setCiteEngine(ENGINE_JURABIB);
2252 biblioModule->bibtopicCB->isChecked();
2254 bp_.biblio_style = fromqstr(biblioModule->bibtexStyleLE->text());
2256 string const bibtex_command =
2257 fromqstr(biblioModule->bibtexCO->itemData(
2258 biblioModule->bibtexCO->currentIndex()).toString());
2259 string const bibtex_options =
2260 fromqstr(biblioModule->bibtexOptionsLE->text());
2261 if (bibtex_command == "default" || bibtex_options.empty())
2262 bp_.bibtex_command = bibtex_command;
2264 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2266 if (biblioChanged_) {
2267 buffer().invalidateBibinfoCache();
2268 buffer().removeBiblioTempFiles();
2272 indicesModule->apply(bp_);
2274 // language & quotes
2275 if (langModule->defaultencodingRB->isChecked()) {
2276 bp_.inputenc = "auto";
2278 int i = langModule->encodingCO->currentIndex();
2280 bp_.inputenc = "default";
2282 QString const enc_gui =
2283 langModule->encodingCO->currentText();
2284 Encodings::const_iterator it = encodings.begin();
2285 Encodings::const_iterator const end = encodings.end();
2287 for (; it != end; ++it) {
2288 if (qt_(it->guiName()) == enc_gui) {
2289 bp_.inputenc = it->latexName();
2295 // should not happen
2296 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2297 bp_.inputenc = "default";
2302 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2303 switch (langModule->quoteStyleCO->currentIndex()) {
2305 lga = InsetQuotes::EnglishQuotes;
2308 lga = InsetQuotes::SwedishQuotes;
2311 lga = InsetQuotes::GermanQuotes;
2314 lga = InsetQuotes::PolishQuotes;
2317 lga = InsetQuotes::FrenchQuotes;
2320 lga = InsetQuotes::DanishQuotes;
2323 bp_.quotes_language = lga;
2325 QString const lang = langModule->languageCO->itemData(
2326 langModule->languageCO->currentIndex()).toString();
2327 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2329 QString const pack = langModule->languagePackageCO->itemData(
2330 langModule->languagePackageCO->currentIndex()).toString();
2331 if (pack == "custom")
2333 fromqstr(langModule->languagePackageLE->text());
2335 bp_.lang_package = fromqstr(pack);
2338 bp_.backgroundcolor = set_backgroundcolor;
2339 bp_.isbackgroundcolor = is_backgroundcolor;
2340 bp_.fontcolor = set_fontcolor;
2341 bp_.isfontcolor = is_fontcolor;
2342 bp_.notefontcolor = set_notefontcolor;
2343 bp_.boxbgcolor = set_boxbgcolor;
2346 if (bp_.documentClass().hasTocLevels()) {
2347 bp_.tocdepth = numberingModule->tocSL->value();
2348 bp_.secnumdepth = numberingModule->depthSL->value();
2352 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2353 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2354 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2355 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2358 bp_.graphics_driver =
2359 tex_graphics[latexModule->psdriverCO->currentIndex()];
2362 int idx = latexModule->classCO->currentIndex();
2364 string const classname = classes_model_.getIDString(idx);
2365 bp_.setBaseClass(classname);
2369 modulesToParams(bp_);
2372 if (mathsModule->amsautoCB->isChecked())
2373 bp_.use_amsmath = BufferParams::package_auto;
2375 if (mathsModule->amsCB->isChecked())
2376 bp_.use_amsmath = BufferParams::package_on;
2378 bp_.use_amsmath = BufferParams::package_off;
2380 if (mathsModule->esintautoCB->isChecked())
2381 bp_.use_esint = BufferParams::package_auto;
2383 if (mathsModule->esintCB->isChecked())
2384 bp_.use_esint = BufferParams::package_on;
2386 bp_.use_esint = BufferParams::package_off;
2388 if (mathsModule->mhchemautoCB->isChecked())
2389 bp_.use_mhchem = BufferParams::package_auto;
2391 if (mathsModule->mhchemCB->isChecked())
2392 bp_.use_mhchem = BufferParams::package_on;
2394 bp_.use_mhchem = BufferParams::package_off;
2396 if (mathsModule->mathdotsautoCB->isChecked())
2397 bp_.use_mathdots = BufferParams::package_auto;
2399 if (mathsModule->mathdotsCB->isChecked())
2400 bp_.use_mathdots = BufferParams::package_on;
2402 bp_.use_mathdots = BufferParams::package_off;
2404 if (mathsModule->undertildeautoCB->isChecked())
2405 bp_.use_undertilde = BufferParams::package_auto;
2407 if (mathsModule->undertildeCB->isChecked())
2408 bp_.use_undertilde = BufferParams::package_on;
2410 bp_.use_undertilde = BufferParams::package_off;
2414 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2415 bp_.pagestyle = "default";
2417 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2418 for (size_t i = 0; i != pagestyles.size(); ++i)
2419 if (pagestyles[i].second == style_gui)
2420 bp_.pagestyle = pagestyles[i].first;
2424 switch (textLayoutModule->lspacingCO->currentIndex()) {
2426 bp_.spacing().set(Spacing::Single);
2429 bp_.spacing().set(Spacing::Onehalf);
2432 bp_.spacing().set(Spacing::Double);
2435 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2437 bp_.spacing().set(Spacing::Single);
2439 bp_.spacing().set(Spacing::Other, s);
2444 if (textLayoutModule->twoColumnCB->isChecked())
2449 bp_.justification = textLayoutModule->justCB->isChecked();
2451 if (textLayoutModule->indentRB->isChecked()) {
2452 // if paragraphs are separated by an indentation
2453 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2454 switch (textLayoutModule->indentCO->currentIndex()) {
2456 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2459 HSpace indent = HSpace(
2460 widgetsToLength(textLayoutModule->indentLE,
2461 textLayoutModule->indentLengthCO)
2463 bp_.setIndentation(indent);
2467 // this should never happen
2468 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2472 // if paragraphs are separated by a skip
2473 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2474 switch (textLayoutModule->skipCO->currentIndex()) {
2476 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2479 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2482 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2487 widgetsToLength(textLayoutModule->skipLE,
2488 textLayoutModule->skipLengthCO)
2494 // this should never happen
2495 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2501 fromqstr(latexModule->optionsLE->text());
2503 bp_.use_default_options =
2504 latexModule->defaultOptionsCB->isChecked();
2506 if (latexModule->childDocGB->isChecked())
2508 fromqstr(latexModule->childDocLE->text());
2510 bp_.master = string();
2513 bp_.clearIncludedChildren();
2514 if (masterChildModule->includeonlyRB->isChecked()) {
2515 list<string>::const_iterator it = includeonlys_.begin();
2516 for (; it != includeonlys_.end() ; ++it) {
2517 bp_.addIncludedChildren(*it);
2520 bp_.maintain_unincluded_children =
2521 masterChildModule->maintainAuxCB->isChecked();
2524 bp_.float_placement = floatModule->get();
2527 // text should have passed validation
2528 bp_.listings_params =
2529 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2532 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
2533 outputModule->defaultFormatCO->currentIndex()).toString());
2535 bool const nontexfonts = fontModule->osFontsCB->isChecked();
2536 bp_.useNonTeXFonts = nontexfonts;
2538 bp_.output_sync = outputModule->outputsyncCB->isChecked();
2540 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2542 int mathfmt = outputModule->mathoutCB->currentIndex();
2545 BufferParams::MathOutput const mo =
2546 static_cast<BufferParams::MathOutput>(mathfmt);
2547 bp_.html_math_output = mo;
2548 bp_.html_be_strict = outputModule->strictCB->isChecked();
2549 bp_.html_css_as_file = outputModule->cssCB->isChecked();
2550 bp_.html_math_img_scale = outputModule->mathimgSB->value();
2554 fromqstr(fontModule->fontsRomanCO->
2555 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
2558 fromqstr(fontModule->fontsSansCO->
2559 itemData(fontModule->fontsSansCO->currentIndex()).toString());
2561 bp_.fonts_typewriter =
2562 fromqstr(fontModule->fontsTypewriterCO->
2563 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
2565 if (fontModule->fontencCO->currentIndex() == 0)
2566 bp_.fontenc = "global";
2567 else if (fontModule->fontencCO->currentIndex() == 1)
2568 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2569 else if (fontModule->fontencCO->currentIndex() == 2)
2570 bp_.fontenc = "default";
2573 fromqstr(fontModule->cjkFontLE->text());
2575 bp_.fonts_sans_scale = fontModule->scaleSansSB->value();
2577 bp_.fonts_typewriter_scale = fontModule->scaleTypewriterSB->value();
2579 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
2581 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
2584 bp_.fonts_default_family = "default";
2586 bp_.fonts_default_family = GuiDocument::fontfamilies[
2587 fontModule->fontsDefaultCO->currentIndex()];
2589 if (fontModule->fontsizeCO->currentIndex() == 0)
2590 bp_.fontsize = "default";
2593 fromqstr(fontModule->fontsizeCO->currentText());
2596 bp_.papersize = PAPER_SIZE(
2597 pageLayoutModule->papersizeCO->currentIndex());
2599 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2600 pageLayoutModule->paperwidthUnitCO);
2602 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2603 pageLayoutModule->paperheightUnitCO);
2605 if (pageLayoutModule->facingPagesCB->isChecked())
2606 bp_.sides = TwoSides;
2608 bp_.sides = OneSide;
2610 if (pageLayoutModule->landscapeRB->isChecked())
2611 bp_.orientation = ORIENTATION_LANDSCAPE;
2613 bp_.orientation = ORIENTATION_PORTRAIT;
2616 bp_.use_geometry = !marginsModule->marginCB->isChecked();
2618 Ui::MarginsUi const * m = marginsModule;
2620 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2621 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2622 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2623 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2624 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2625 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2626 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2627 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2630 branchesModule->apply(bp_);
2633 PDFOptions & pdf = bp_.pdfoptions();
2634 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2635 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2636 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2637 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2638 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2640 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2641 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2642 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2643 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2645 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2646 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2647 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2648 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2650 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2651 if (pdfSupportModule->fullscreenCB->isChecked())
2652 pdf.pagemode = pdf.pagemode_fullscreen;
2654 pdf.pagemode.clear();
2655 pdf.quoted_options = pdf.quoted_options_check(
2656 fromqstr(pdfSupportModule->optionsLE->text()));
2660 void GuiDocument::paramsToDialog()
2662 // set the default unit
2663 Length::UNIT const default_unit = Length::defaultUnit();
2666 preambleModule->update(bp_, id());
2667 localLayout->update(bp_, id());
2670 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2671 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
2674 biblioModule->citeDefaultRB->setChecked(
2675 bp_.citeEngine() == ENGINE_BASIC);
2677 biblioModule->citeNatbibRB->setChecked(
2678 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
2679 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
2681 biblioModule->citeStyleCO->setCurrentIndex(
2682 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
2684 biblioModule->citeJurabibRB->setChecked(
2685 bp_.citeEngine() == ENGINE_JURABIB);
2687 biblioModule->bibtopicCB->setChecked(
2690 biblioModule->bibtexStyleLE->setText(toqstr(bp_.biblio_style));
2694 split(bp_.bibtex_command, command, ' ');
2696 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2698 biblioModule->bibtexCO->setCurrentIndex(bpos);
2699 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
2701 // We reset to default if we do not know the specified compiler
2702 // This is for security reasons
2703 biblioModule->bibtexCO->setCurrentIndex(
2704 biblioModule->bibtexCO->findData(toqstr("default")));
2705 biblioModule->bibtexOptionsLE->clear();
2707 biblioModule->bibtexOptionsLE->setEnabled(
2708 biblioModule->bibtexCO->currentIndex() != 0);
2711 indicesModule->update(bp_);
2713 // language & quotes
2714 int const pos = langModule->languageCO->findData(toqstr(
2715 bp_.language->lang()));
2716 langModule->languageCO->setCurrentIndex(pos);
2718 langModule->quoteStyleCO->setCurrentIndex(
2719 bp_.quotes_language);
2721 bool default_enc = true;
2722 if (bp_.inputenc != "auto") {
2723 default_enc = false;
2724 if (bp_.inputenc == "default") {
2725 langModule->encodingCO->setCurrentIndex(0);
2728 Encodings::const_iterator it = encodings.begin();
2729 Encodings::const_iterator const end = encodings.end();
2730 for (; it != end; ++it) {
2731 if (it->latexName() == bp_.inputenc) {
2732 enc_gui = it->guiName();
2736 int const i = langModule->encodingCO->findText(
2739 langModule->encodingCO->setCurrentIndex(i);
2741 // unknown encoding. Set to default.
2745 langModule->defaultencodingRB->setChecked(default_enc);
2746 langModule->otherencodingRB->setChecked(!default_enc);
2748 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
2750 langModule->languagePackageCO->setCurrentIndex(
2751 langModule->languagePackageCO->findData("custom"));
2752 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
2754 langModule->languagePackageCO->setCurrentIndex(p);
2755 langModule->languagePackageLE->clear();
2759 if (bp_.isfontcolor) {
2760 colorModule->fontColorPB->setStyleSheet(
2761 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2763 set_fontcolor = bp_.fontcolor;
2764 is_fontcolor = bp_.isfontcolor;
2766 colorModule->noteFontColorPB->setStyleSheet(
2767 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2768 set_notefontcolor = bp_.notefontcolor;
2770 if (bp_.isbackgroundcolor) {
2771 colorModule->backgroundPB->setStyleSheet(
2772 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2774 set_backgroundcolor = bp_.backgroundcolor;
2775 is_backgroundcolor = bp_.isbackgroundcolor;
2777 colorModule->boxBackgroundPB->setStyleSheet(
2778 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
2779 set_boxbgcolor = bp_.boxbgcolor;
2782 int const min_toclevel = documentClass().min_toclevel();
2783 int const max_toclevel = documentClass().max_toclevel();
2784 if (documentClass().hasTocLevels()) {
2785 numberingModule->setEnabled(true);
2786 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2787 numberingModule->depthSL->setMaximum(max_toclevel);
2788 numberingModule->depthSL->setValue(bp_.secnumdepth);
2789 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2790 numberingModule->tocSL->setMaximum(max_toclevel);
2791 numberingModule->tocSL->setValue(bp_.tocdepth);
2794 numberingModule->setEnabled(false);
2795 numberingModule->tocTW->clear();
2799 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2800 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2801 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2802 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2803 bulletsModule->init();
2806 int nitem = findToken(tex_graphics, bp_.graphics_driver);
2808 latexModule->psdriverCO->setCurrentIndex(nitem);
2811 mathsModule->amsCB->setChecked(
2812 bp_.use_amsmath == BufferParams::package_on);
2813 mathsModule->amsautoCB->setChecked(
2814 bp_.use_amsmath == BufferParams::package_auto);
2816 mathsModule->esintCB->setChecked(
2817 bp_.use_esint == BufferParams::package_on);
2818 mathsModule->esintautoCB->setChecked(
2819 bp_.use_esint == BufferParams::package_auto);
2821 mathsModule->mhchemCB->setChecked(
2822 bp_.use_mhchem == BufferParams::package_on);
2823 mathsModule->mhchemautoCB->setChecked(
2824 bp_.use_mhchem == BufferParams::package_auto);
2826 mathsModule->mathdotsCB->setChecked(
2827 bp_.use_mathdots == BufferParams::package_on);
2828 mathsModule->mathdotsautoCB->setChecked(
2829 bp_.use_mathdots == BufferParams::package_auto);
2831 mathsModule->undertildeCB->setChecked(
2832 bp_.use_undertilde == BufferParams::package_on);
2833 mathsModule->undertildeautoCB->setChecked(
2834 bp_.use_undertilde == BufferParams::package_auto);
2836 switch (bp_.spacing().getSpace()) {
2837 case Spacing::Other: nitem = 3; break;
2838 case Spacing::Double: nitem = 2; break;
2839 case Spacing::Onehalf: nitem = 1; break;
2840 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2844 string const & layoutID = bp_.baseClassID();
2845 setLayoutComboByIDString(layoutID);
2847 updatePagestyle(documentClass().opt_pagestyle(),
2850 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2851 if (bp_.spacing().getSpace() == Spacing::Other) {
2852 doubleToWidget(textLayoutModule->lspacingLE,
2853 bp_.spacing().getValueAsString());
2857 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2858 textLayoutModule->indentRB->setChecked(true);
2859 string indentation = bp_.getIndentation().asLyXCommand();
2861 if (indentation != "default") {
2862 lengthToWidgets(textLayoutModule->indentLE,
2863 textLayoutModule->indentLengthCO,
2864 indentation, default_unit);
2867 textLayoutModule->indentCO->setCurrentIndex(indent);
2870 textLayoutModule->skipRB->setChecked(true);
2872 switch (bp_.getDefSkip().kind()) {
2873 case VSpace::SMALLSKIP:
2876 case VSpace::MEDSKIP:
2879 case VSpace::BIGSKIP:
2882 case VSpace::LENGTH:
2885 string const length = bp_.getDefSkip().asLyXCommand();
2886 lengthToWidgets(textLayoutModule->skipLE,
2887 textLayoutModule->skipLengthCO,
2888 length, default_unit);
2895 textLayoutModule->skipCO->setCurrentIndex(skip);
2899 textLayoutModule->twoColumnCB->setChecked(
2901 textLayoutModule->justCB->setChecked(bp_.justification);
2903 if (!bp_.options.empty()) {
2904 latexModule->optionsLE->setText(
2905 toqstr(bp_.options));
2907 latexModule->optionsLE->setText(QString());
2911 latexModule->defaultOptionsCB->setChecked(
2912 bp_.use_default_options);
2913 updateSelectedModules();
2914 selectionManager->updateProvidedModules(
2915 bp_.baseClass()->providedModules());
2916 selectionManager->updateExcludedModules(
2917 bp_.baseClass()->excludedModules());
2919 if (!documentClass().options().empty()) {
2920 latexModule->defaultOptionsLE->setText(
2921 toqstr(documentClass().options()));
2923 latexModule->defaultOptionsLE->setText(
2924 toqstr(_("[No options predefined]")));
2927 latexModule->defaultOptionsLE->setEnabled(
2928 bp_.use_default_options
2929 && !documentClass().options().empty());
2931 latexModule->defaultOptionsCB->setEnabled(
2932 !documentClass().options().empty());
2934 if (!bp_.master.empty()) {
2935 latexModule->childDocGB->setChecked(true);
2936 latexModule->childDocLE->setText(
2937 toqstr(bp_.master));
2939 latexModule->childDocLE->setText(QString());
2940 latexModule->childDocGB->setChecked(false);
2944 if (!bufferview() || !buffer().hasChildren()) {
2945 masterChildModule->childrenTW->clear();
2946 includeonlys_.clear();
2947 docPS->showPanel(qt_("Child Documents"), false);
2948 if (docPS->isCurrentPanel(qt_("Child Documents")))
2949 docPS->setCurrentPanel(qt_("Document Class"));
2951 docPS->showPanel(qt_("Child Documents"), true);
2952 masterChildModule->setEnabled(true);
2953 includeonlys_ = bp_.getIncludedChildren();
2954 updateIncludeonlys();
2956 masterChildModule->maintainAuxCB->setChecked(
2957 bp_.maintain_unincluded_children);
2960 floatModule->set(bp_.float_placement);
2963 // break listings_params to multiple lines
2965 InsetListingsParams(bp_.listings_params).separatedParams();
2966 listingsModule->listingsED->setPlainText(toqstr(lstparams));
2969 // update combobox with formats
2970 updateDefaultFormat();
2971 int index = outputModule->defaultFormatCO->findData(toqstr(
2972 bp_.default_output_format));
2973 // set to default if format is not found
2976 outputModule->defaultFormatCO->setCurrentIndex(index);
2977 bool const os_fonts_available =
2978 bp_.baseClass()->outputType() == lyx::LATEX
2979 && LaTeXFeatures::isAvailable("fontspec");
2980 fontModule->osFontsCB->setEnabled(os_fonts_available);
2981 fontModule->osFontsCB->setChecked(
2982 os_fonts_available && bp_.useNonTeXFonts);
2984 outputModule->outputsyncCB->setChecked(bp_.output_sync);
2985 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
2987 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
2988 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
2989 outputModule->strictCB->setChecked(bp_.html_be_strict);
2990 outputModule->cssCB->setChecked(bp_.html_css_as_file);
2993 updateFontsize(documentClass().opt_fontsize(),
2996 QString font = toqstr(bp_.fonts_roman);
2997 int rpos = fontModule->fontsRomanCO->findData(font);
2999 rpos = fontModule->fontsRomanCO->count();
3000 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3002 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3004 font = toqstr(bp_.fonts_sans);
3005 int spos = fontModule->fontsSansCO->findData(font);
3007 spos = fontModule->fontsSansCO->count();
3008 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3010 fontModule->fontsSansCO->setCurrentIndex(spos);
3012 font = toqstr(bp_.fonts_typewriter);
3013 int tpos = fontModule->fontsTypewriterCO->findData(font);
3015 tpos = fontModule->fontsTypewriterCO->count();
3016 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3018 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3020 if (bp_.useNonTeXFonts && os_fonts_available) {
3021 fontModule->fontencLA->setEnabled(false);
3022 fontModule->fontencCO->setEnabled(false);
3023 fontModule->fontencLE->setEnabled(false);
3025 fontModule->fontencLA->setEnabled(true);
3026 fontModule->fontencCO->setEnabled(true);
3027 fontModule->fontencLE->setEnabled(true);
3033 if (!bp_.fonts_cjk.empty())
3034 fontModule->cjkFontLE->setText(
3035 toqstr(bp_.fonts_cjk));
3037 fontModule->cjkFontLE->setText(QString());
3039 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3040 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3041 fontModule->scaleSansSB->setValue(bp_.fonts_sans_scale);
3042 fontModule->scaleTypewriterSB->setValue(bp_.fonts_typewriter_scale);
3044 int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3046 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3048 if (bp_.fontenc == "global") {
3049 fontModule->fontencCO->setCurrentIndex(0);
3050 fontModule->fontencLE->setEnabled(false);
3051 } else if (bp_.fontenc == "default") {
3052 fontModule->fontencCO->setCurrentIndex(2);
3053 fontModule->fontencLE->setEnabled(false);
3055 fontModule->fontencCO->setCurrentIndex(1);
3056 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3060 bool const extern_geometry =
3061 documentClass().provides("geometry");
3062 int const psize = bp_.papersize;
3063 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3064 setCustomPapersize(!extern_geometry && psize == 1);
3065 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3067 bool const landscape =
3068 bp_.orientation == ORIENTATION_LANDSCAPE;
3069 pageLayoutModule->landscapeRB->setChecked(landscape);
3070 pageLayoutModule->portraitRB->setChecked(!landscape);
3071 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3072 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3074 pageLayoutModule->facingPagesCB->setChecked(
3075 bp_.sides == TwoSides);
3077 lengthToWidgets(pageLayoutModule->paperwidthLE,
3078 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3079 lengthToWidgets(pageLayoutModule->paperheightLE,
3080 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3083 Ui::MarginsUi * m = marginsModule;
3087 lengthToWidgets(m->topLE, m->topUnit,
3088 bp_.topmargin, default_unit);
3090 lengthToWidgets(m->bottomLE, m->bottomUnit,
3091 bp_.bottommargin, default_unit);
3093 lengthToWidgets(m->innerLE, m->innerUnit,
3094 bp_.leftmargin, default_unit);
3096 lengthToWidgets(m->outerLE, m->outerUnit,
3097 bp_.rightmargin, default_unit);
3099 lengthToWidgets(m->headheightLE, m->headheightUnit,
3100 bp_.headheight, default_unit);
3102 lengthToWidgets(m->headsepLE, m->headsepUnit,
3103 bp_.headsep, default_unit);
3105 lengthToWidgets(m->footskipLE, m->footskipUnit,
3106 bp_.footskip, default_unit);
3108 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3109 bp_.columnsep, default_unit);
3112 updateUnknownBranches();
3113 branchesModule->update(bp_);
3116 PDFOptions const & pdf = bp_.pdfoptions();
3117 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3118 if (bp_.documentClass().provides("hyperref"))
3119 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3121 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3122 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3123 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3124 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3125 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3127 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3128 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3129 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3131 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3133 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3134 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3135 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3136 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3138 nn = findToken(backref_opts, pdf.backref);
3140 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3142 pdfSupportModule->fullscreenCB->setChecked
3143 (pdf.pagemode == pdf.pagemode_fullscreen);
3145 pdfSupportModule->optionsLE->setText(
3146 toqstr(pdf.quoted_options));
3148 // Make sure that the bc is in the INITIAL state
3149 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3152 // clear changed branches cache
3153 changedBranches_.clear();
3157 void GuiDocument::saveDocDefault()
3159 // we have to apply the params first
3165 void GuiDocument::updateAvailableModules()
3167 modules_av_model_.clear();
3168 list<modInfoStruct> const & modInfoList = getModuleInfo();
3169 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3170 list<modInfoStruct>::const_iterator men = modInfoList.end();
3171 for (int i = 0; mit != men; ++mit, ++i)
3172 modules_av_model_.insertRow(i, mit->name, mit->id,
3177 void GuiDocument::updateSelectedModules()
3179 modules_sel_model_.clear();
3180 list<modInfoStruct> const selModList = getSelectedModules();
3181 list<modInfoStruct>::const_iterator mit = selModList.begin();
3182 list<modInfoStruct>::const_iterator men = selModList.end();
3183 for (int i = 0; mit != men; ++mit, ++i)
3184 modules_sel_model_.insertRow(i, mit->name, mit->id,
3189 void GuiDocument::updateIncludeonlys()
3191 masterChildModule->childrenTW->clear();
3192 QString const no = qt_("No");
3193 QString const yes = qt_("Yes");
3195 if (includeonlys_.empty()) {
3196 masterChildModule->includeallRB->setChecked(true);
3197 masterChildModule->childrenTW->setEnabled(false);
3198 masterChildModule->maintainAuxCB->setEnabled(false);
3200 masterChildModule->includeonlyRB->setChecked(true);
3201 masterChildModule->childrenTW->setEnabled(true);
3202 masterChildModule->maintainAuxCB->setEnabled(true);
3204 QTreeWidgetItem * item = 0;
3205 ListOfBuffers children = buffer().getChildren();
3206 ListOfBuffers::const_iterator it = children.begin();
3207 ListOfBuffers::const_iterator end = children.end();
3208 bool has_unincluded = false;
3209 bool all_unincluded = true;
3210 for (; it != end; ++it) {
3211 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3214 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3215 from_utf8(buffer().filePath())));
3216 item->setText(0, toqstr(name));
3217 item->setText(1, isChildIncluded(name) ? yes : no);
3218 if (!isChildIncluded(name))
3219 has_unincluded = true;
3221 all_unincluded = false;
3223 // Both if all childs are included and if none is included
3224 // is equal to "include all" (i.e., ommit \includeonly).
3225 // Thus, reset the GUI.
3226 if (!has_unincluded || all_unincluded) {
3227 masterChildModule->includeallRB->setChecked(true);
3228 masterChildModule->childrenTW->setEnabled(false);
3229 includeonlys_.clear();
3231 // If all are included, we need to update again.
3232 if (!has_unincluded)
3233 updateIncludeonlys();
3237 void GuiDocument::updateContents()
3239 // Nothing to do here as the document settings is not cursor dependant.
3244 void GuiDocument::useClassDefaults()
3246 if (applyPB->isEnabled()) {
3247 int const ret = Alert::prompt(_("Unapplied changes"),
3248 _("Some changes in the dialog were not yet applied.\n"
3249 "If you do not apply now, they will be lost after this action."),
3250 1, 1, _("&Apply"), _("&Dismiss"));
3255 int idx = latexModule->classCO->currentIndex();
3256 string const classname = classes_model_.getIDString(idx);
3257 if (!bp_.setBaseClass(classname)) {
3258 Alert::error(_("Error"), _("Unable to set document class."));
3261 bp_.useClassDefaults();
3266 void GuiDocument::setLayoutComboByIDString(string const & idString)
3268 int idx = classes_model_.findIDString(idString);
3270 Alert::warning(_("Can't set layout!"),
3271 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3273 latexModule->classCO->setCurrentIndex(idx);
3277 bool GuiDocument::isValid()
3280 validateListingsParameters().isEmpty() &&
3281 localLayout->isValid() &&
3283 // if we're asking for skips between paragraphs
3284 !textLayoutModule->skipRB->isChecked() ||
3285 // then either we haven't chosen custom
3286 textLayoutModule->skipCO->currentIndex() != 3 ||
3287 // or else a length has been given
3288 !textLayoutModule->skipLE->text().isEmpty()
3291 // if we're asking for indentation
3292 !textLayoutModule->indentRB->isChecked() ||
3293 // then either we haven't chosen custom
3294 textLayoutModule->indentCO->currentIndex() != 1 ||
3295 // or else a length has been given
3296 !textLayoutModule->indentLE->text().isEmpty()
3301 char const * const GuiDocument::fontfamilies[5] = {
3302 "default", "rmdefault", "sfdefault", "ttdefault", ""
3306 char const * GuiDocument::fontfamilies_gui[5] = {
3307 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3311 bool GuiDocument::initialiseParams(string const &)
3313 BufferView const * view = bufferview();
3315 bp_ = BufferParams();
3319 bp_ = view->buffer().params();
3321 updateAvailableModules();
3322 //FIXME It'd be nice to make sure here that the selected
3323 //modules are consistent: That required modules are actually
3324 //selected, and that we don't have conflicts. If so, we could
3325 //at least pop up a warning.
3331 void GuiDocument::clearParams()
3333 bp_ = BufferParams();
3337 BufferId GuiDocument::id() const
3339 BufferView const * const view = bufferview();
3340 return view? &view->buffer() : 0;
3344 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3346 return moduleNames_;
3350 list<GuiDocument::modInfoStruct> const
3351 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3353 LayoutModuleList::const_iterator it = mods.begin();
3354 LayoutModuleList::const_iterator end = mods.end();
3355 list<modInfoStruct> mInfo;
3356 for (; it != end; ++it) {
3359 LyXModule const * const mod = theModuleList[*it];
3362 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3364 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3371 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3373 return makeModuleInfo(params().getModules());
3377 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3379 return makeModuleInfo(params().baseClass()->providedModules());
3383 DocumentClass const & GuiDocument::documentClass() const
3385 return bp_.documentClass();
3389 static void dispatch_bufferparams(Dialog const & dialog,
3390 BufferParams const & bp, FuncCode lfun)
3393 ss << "\\begin_header\n";
3395 ss << "\\end_header\n";
3396 dialog.dispatch(FuncRequest(lfun, ss.str()));
3400 void GuiDocument::dispatchParams()
3402 // This must come first so that a language change is correctly noticed
3405 // Apply the BufferParams. Note that this will set the base class
3406 // and then update the buffer's layout.
3407 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3409 if (!params().master.empty()) {
3410 FileName const master_file = support::makeAbsPath(params().master,
3411 support::onlyPath(buffer().absFileName()));
3412 if (isLyXFileName(master_file.absFileName())) {
3413 Buffer * master = checkAndLoadLyXFile(master_file);
3415 if (master->isChild(const_cast<Buffer *>(&buffer())))
3416 const_cast<Buffer &>(buffer()).setParent(master);
3418 Alert::warning(_("Assigned master does not include this file"),
3419 bformat(_("You must include this file in the document\n"
3420 "'%1$s' in order to use the master document\n"
3421 "feature."), from_utf8(params().master)));
3423 Alert::warning(_("Could not load master"),
3424 bformat(_("The master document '%1$s'\n"
3425 "could not be loaded."),
3426 from_utf8(params().master)));
3430 // Generate the colours requested by each new branch.
3431 BranchList & branchlist = params().branchlist();
3432 if (!branchlist.empty()) {
3433 BranchList::const_iterator it = branchlist.begin();
3434 BranchList::const_iterator const end = branchlist.end();
3435 for (; it != end; ++it) {
3436 docstring const & current_branch = it->branch();
3437 Branch const * branch = branchlist.find(current_branch);
3438 string const x11hexname = X11hexname(branch->color());
3439 // display the new color
3440 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3441 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3444 // Open insets of selected branches, close deselected ones
3445 dispatch(FuncRequest(LFUN_INSET_FORALL,
3446 "Branch inset-toggle assign"));
3448 // rename branches in the document
3449 executeBranchRenaming();
3450 // and clear changed branches cache
3451 changedBranches_.clear();
3453 // Generate the colours requested by indices.
3454 IndicesList & indiceslist = params().indiceslist();
3455 if (!indiceslist.empty()) {
3456 IndicesList::const_iterator it = indiceslist.begin();
3457 IndicesList::const_iterator const end = indiceslist.end();
3458 for (; it != end; ++it) {
3459 docstring const & current_index = it->shortcut();
3460 Index const * index = indiceslist.findShortcut(current_index);
3461 string const x11hexname = X11hexname(index->color());
3462 // display the new color
3463 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3464 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3468 // If we used an LFUN, we would not need these two lines:
3469 BufferView * bv = const_cast<BufferView *>(bufferview());
3470 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3474 void GuiDocument::setLanguage() const
3476 Language const * const newL = bp_.language;
3477 if (buffer().params().language == newL)
3480 string const & lang_name = newL->lang();
3481 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3485 void GuiDocument::saveAsDefault() const
3487 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3491 bool GuiDocument::isFontAvailable(string const & font) const
3493 if (font == "default" || font == "cmr"
3494 || font == "cmss" || font == "cmtt")
3495 // these are standard
3497 if (font == "lmodern" || font == "lmss" || font == "lmtt")
3498 return LaTeXFeatures::isAvailable("lmodern");
3499 if (font == "times" || font == "palatino"
3500 || font == "helvet" || font == "courier")
3501 return LaTeXFeatures::isAvailable("psnfss");
3502 if (font == "cmbr" || font == "cmtl")
3503 return LaTeXFeatures::isAvailable("cmbright");
3504 if (font == "utopia")
3505 return LaTeXFeatures::isAvailable("utopia")
3506 || LaTeXFeatures::isAvailable("fourier");
3507 if (font == "beraserif" || font == "berasans"
3508 || font == "beramono")
3509 return LaTeXFeatures::isAvailable("bera");
3510 return LaTeXFeatures::isAvailable(font);
3514 bool GuiDocument::providesOSF(string const & font) const
3516 if (fontModule->osFontsCB->isChecked())
3517 // FIXME: we should check if the fonts really
3518 // have OSF support. But how?
3521 return isFontAvailable("eco");
3522 if (font == "palatino")
3523 return isFontAvailable("mathpazo");
3528 bool GuiDocument::providesSC(string const & font) const
3530 if (fontModule->osFontsCB->isChecked())
3532 if (font == "palatino")
3533 return isFontAvailable("mathpazo");
3534 if (font == "utopia")
3535 return isFontAvailable("fourier");
3540 bool GuiDocument::providesScale(string const & font) const
3542 if (fontModule->osFontsCB->isChecked())
3544 return font == "helvet" || font == "luximono"
3545 || font == "berasans" || font == "beramono";
3549 void GuiDocument::loadModuleInfo()
3551 moduleNames_.clear();
3552 LyXModuleList::const_iterator it = theModuleList.begin();
3553 LyXModuleList::const_iterator end = theModuleList.end();
3554 for (; it != end; ++it) {
3558 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3559 // this is supposed to give us the first sentence of the description
3562 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3563 int const pos = desc.indexOf(".");
3565 desc.truncate(pos + 1);
3566 m.description = desc;
3567 moduleNames_.push_back(m);
3572 void GuiDocument::updateUnknownBranches()
3576 list<docstring> used_branches;
3577 buffer().getUsedBranches(used_branches);
3578 list<docstring>::const_iterator it = used_branches.begin();
3579 QStringList unknown_branches;
3580 for (; it != used_branches.end() ; ++it) {
3581 if (!buffer().params().branchlist().find(*it))
3582 unknown_branches.append(toqstr(*it));
3584 branchesModule->setUnknownBranches(unknown_branches);
3588 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3590 map<docstring, docstring>::iterator it = changedBranches_.begin();
3591 for (; it != changedBranches_.end() ; ++it) {
3592 if (it->second == oldname) {
3593 // branch has already been renamed
3594 it->second = newname;
3599 changedBranches_[oldname] = newname;
3603 void GuiDocument::executeBranchRenaming() const
3605 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3606 for (; it != changedBranches_.end() ; ++it) {
3607 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3608 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3613 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3616 } // namespace frontend
3619 #include "moc_GuiDocument.cpp"