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()));
714 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
715 textLayoutModule->lspacingLE));
716 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
717 textLayoutModule->indentLE));
718 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
719 textLayoutModule->skipLE));
721 textLayoutModule->indentCO->addItem(qt_("Default"));
722 textLayoutModule->indentCO->addItem(qt_("Custom"));
723 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
724 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
725 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
726 textLayoutModule->skipCO->addItem(qt_("Custom"));
727 textLayoutModule->lspacingCO->insertItem(
728 Spacing::Single, qt_("Single"));
729 textLayoutModule->lspacingCO->insertItem(
730 Spacing::Onehalf, qt_("OneHalf"));
731 textLayoutModule->lspacingCO->insertItem(
732 Spacing::Double, qt_("Double"));
733 textLayoutModule->lspacingCO->insertItem(
734 Spacing::Other, qt_("Custom"));
735 // initialize the length validator
736 bc().addCheckedLineEdit(textLayoutModule->indentLE);
737 bc().addCheckedLineEdit(textLayoutModule->skipLE);
740 // master/child handling
741 masterChildModule = new UiWidget<Ui::MasterChildUi>;
743 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
744 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
745 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
746 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
747 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
748 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
749 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
750 this, SLOT(change_adaptor()));
751 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
752 this, SLOT(change_adaptor()));
753 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
754 this, SLOT(change_adaptor()));
755 masterChildModule->childrenTW->setColumnCount(2);
756 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
757 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
758 masterChildModule->childrenTW->resizeColumnToContents(1);
759 masterChildModule->childrenTW->resizeColumnToContents(2);
763 outputModule = new UiWidget<Ui::OutputUi>;
765 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
766 this, SLOT(change_adaptor()));
767 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
768 this, SLOT(change_adaptor()));
769 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
770 this, SLOT(change_adaptor()));
771 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
772 this, SLOT(change_adaptor()));
774 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
775 this, SLOT(change_adaptor()));
776 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
777 this, SLOT(change_adaptor()));
778 outputModule->synccustomCB->addItem("");
779 outputModule->synccustomCB->addItem("\\synctex=1");
780 outputModule->synccustomCB->addItem("\\synctex=-1");
781 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
783 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
784 outputModule->synccustomCB));
787 fontModule = new UiWidget<Ui::FontUi>;
788 connect(fontModule->osFontsCB, SIGNAL(clicked()),
789 this, SLOT(change_adaptor()));
790 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
791 this, SLOT(osFontsChanged(bool)));
792 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
793 this, SLOT(change_adaptor()));
794 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
795 this, SLOT(romanChanged(int)));
796 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
797 this, SLOT(change_adaptor()));
798 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
799 this, SLOT(sansChanged(int)));
800 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
801 this, SLOT(change_adaptor()));
802 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
803 this, SLOT(ttChanged(int)));
804 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
805 this, SLOT(change_adaptor()));
806 connect(fontModule->fontencCO, SIGNAL(activated(int)),
807 this, SLOT(change_adaptor()));
808 connect(fontModule->fontencCO, SIGNAL(activated(int)),
809 this, SLOT(fontencChanged(int)));
810 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
811 this, SLOT(change_adaptor()));
812 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
813 this, SLOT(change_adaptor()));
814 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
815 this, SLOT(change_adaptor()));
816 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
817 this, SLOT(change_adaptor()));
818 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
819 this, SLOT(change_adaptor()));
820 connect(fontModule->fontScCB, SIGNAL(clicked()),
821 this, SLOT(change_adaptor()));
822 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
823 this, SLOT(change_adaptor()));
825 fontModule->fontencLE->setValidator(new NoNewLineValidator(
826 fontModule->fontencLE));
827 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
828 fontModule->cjkFontLE));
832 fontModule->fontsizeCO->addItem(qt_("Default"));
833 fontModule->fontsizeCO->addItem(qt_("10"));
834 fontModule->fontsizeCO->addItem(qt_("11"));
835 fontModule->fontsizeCO->addItem(qt_("12"));
837 fontModule->fontencCO->addItem(qt_("Default"));
838 fontModule->fontencCO->addItem(qt_("Custom"));
839 fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
841 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
842 fontModule->fontsDefaultCO->addItem(
843 qt_(GuiDocument::fontfamilies_gui[n]));
845 if (!LaTeXFeatures::isAvailable("fontspec"))
846 fontModule->osFontsCB->setToolTip(
847 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
848 "You need to install the package \"fontspec\" to use this feature"));
852 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
853 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
854 this, SLOT(papersizeChanged(int)));
855 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
856 this, SLOT(papersizeChanged(int)));
857 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
858 this, SLOT(change_adaptor()));
859 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
860 this, SLOT(change_adaptor()));
861 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
862 this, SLOT(change_adaptor()));
863 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
864 this, SLOT(change_adaptor()));
865 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
866 this, SLOT(change_adaptor()));
867 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
868 this, SLOT(change_adaptor()));
869 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
870 this, SLOT(change_adaptor()));
871 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
872 this, SLOT(change_adaptor()));
873 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
874 this, SLOT(change_adaptor()));
875 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
876 this, SLOT(change_adaptor()));
878 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
879 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
880 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
881 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
882 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
883 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
884 pageLayoutModule->paperheightL);
885 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
886 pageLayoutModule->paperwidthL);
888 QComboBox * cb = pageLayoutModule->papersizeCO;
889 cb->addItem(qt_("Default"));
890 cb->addItem(qt_("Custom"));
891 cb->addItem(qt_("US letter"));
892 cb->addItem(qt_("US legal"));
893 cb->addItem(qt_("US executive"));
894 cb->addItem(qt_("A0"));
895 cb->addItem(qt_("A1"));
896 cb->addItem(qt_("A2"));
897 cb->addItem(qt_("A3"));
898 cb->addItem(qt_("A4"));
899 cb->addItem(qt_("A5"));
900 cb->addItem(qt_("A6"));
901 cb->addItem(qt_("B0"));
902 cb->addItem(qt_("B1"));
903 cb->addItem(qt_("B2"));
904 cb->addItem(qt_("B3"));
905 cb->addItem(qt_("B4"));
906 cb->addItem(qt_("B5"));
907 cb->addItem(qt_("B6"));
908 cb->addItem(qt_("C0"));
909 cb->addItem(qt_("C1"));
910 cb->addItem(qt_("C2"));
911 cb->addItem(qt_("C3"));
912 cb->addItem(qt_("C4"));
913 cb->addItem(qt_("C5"));
914 cb->addItem(qt_("C6"));
915 cb->addItem(qt_("JIS B0"));
916 cb->addItem(qt_("JIS B1"));
917 cb->addItem(qt_("JIS B2"));
918 cb->addItem(qt_("JIS B3"));
919 cb->addItem(qt_("JIS B4"));
920 cb->addItem(qt_("JIS B5"));
921 cb->addItem(qt_("JIS B6"));
922 // remove the %-items from the unit choice
923 pageLayoutModule->paperwidthUnitCO->noPercents();
924 pageLayoutModule->paperheightUnitCO->noPercents();
925 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
926 pageLayoutModule->paperheightLE));
927 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
928 pageLayoutModule->paperwidthLE));
932 marginsModule = new UiWidget<Ui::MarginsUi>;
933 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
934 this, SLOT(setCustomMargins(bool)));
935 connect(marginsModule->marginCB, SIGNAL(clicked()),
936 this, SLOT(change_adaptor()));
937 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
938 this, SLOT(change_adaptor()));
939 connect(marginsModule->topUnit, SIGNAL(activated(int)),
940 this, SLOT(change_adaptor()));
941 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
942 this, SLOT(change_adaptor()));
943 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
944 this, SLOT(change_adaptor()));
945 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
946 this, SLOT(change_adaptor()));
947 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
948 this, SLOT(change_adaptor()));
949 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
950 this, SLOT(change_adaptor()));
951 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
952 this, SLOT(change_adaptor()));
953 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
954 this, SLOT(change_adaptor()));
955 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
956 this, SLOT(change_adaptor()));
957 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
958 this, SLOT(change_adaptor()));
959 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
960 this, SLOT(change_adaptor()));
961 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
962 this, SLOT(change_adaptor()));
963 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
964 this, SLOT(change_adaptor()));
965 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
966 this, SLOT(change_adaptor()));
967 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
968 this, SLOT(change_adaptor()));
969 marginsModule->topLE->setValidator(unsignedLengthValidator(
970 marginsModule->topLE));
971 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
972 marginsModule->bottomLE));
973 marginsModule->innerLE->setValidator(unsignedLengthValidator(
974 marginsModule->innerLE));
975 marginsModule->outerLE->setValidator(unsignedLengthValidator(
976 marginsModule->outerLE));
977 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
978 marginsModule->headsepLE));
979 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
980 marginsModule->headheightLE));
981 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
982 marginsModule->footskipLE));
983 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
984 marginsModule->columnsepLE));
986 bc().addCheckedLineEdit(marginsModule->topLE,
987 marginsModule->topL);
988 bc().addCheckedLineEdit(marginsModule->bottomLE,
989 marginsModule->bottomL);
990 bc().addCheckedLineEdit(marginsModule->innerLE,
991 marginsModule->innerL);
992 bc().addCheckedLineEdit(marginsModule->outerLE,
993 marginsModule->outerL);
994 bc().addCheckedLineEdit(marginsModule->headsepLE,
995 marginsModule->headsepL);
996 bc().addCheckedLineEdit(marginsModule->headheightLE,
997 marginsModule->headheightL);
998 bc().addCheckedLineEdit(marginsModule->footskipLE,
999 marginsModule->footskipL);
1000 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1001 marginsModule->columnsepL);
1005 langModule = new UiWidget<Ui::LanguageUi>;
1006 connect(langModule->languageCO, SIGNAL(activated(int)),
1007 this, SLOT(change_adaptor()));
1008 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1009 this, SLOT(change_adaptor()));
1010 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1011 this, SLOT(change_adaptor()));
1012 connect(langModule->encodingCO, SIGNAL(activated(int)),
1013 this, SLOT(change_adaptor()));
1014 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1015 this, SLOT(change_adaptor()));
1016 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1017 this, SLOT(change_adaptor()));
1018 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1019 this, SLOT(change_adaptor()));
1020 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1021 this, SLOT(languagePackageChanged(int)));
1023 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1024 langModule->languagePackageLE));
1026 QAbstractItemModel * language_model = guiApp->languageModel();
1027 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1028 language_model->sort(0);
1029 langModule->languageCO->setModel(language_model);
1030 langModule->languageCO->setModelColumn(0);
1032 // Always put the default encoding in the first position.
1033 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1034 QStringList encodinglist;
1035 Encodings::const_iterator it = encodings.begin();
1036 Encodings::const_iterator const end = encodings.end();
1037 for (; it != end; ++it)
1038 encodinglist.append(qt_(it->guiName()));
1039 encodinglist.sort();
1040 langModule->encodingCO->addItems(encodinglist);
1042 langModule->quoteStyleCO->addItem(qt_("``text''"));
1043 langModule->quoteStyleCO->addItem(qt_("''text''"));
1044 langModule->quoteStyleCO->addItem(qt_(",,text``"));
1045 langModule->quoteStyleCO->addItem(qt_(",,text''"));
1046 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
1047 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
1049 langModule->languagePackageCO->addItem(
1050 qt_("Default"), toqstr("default"));
1051 langModule->languagePackageCO->addItem(
1052 qt_("Automatic"), toqstr("auto"));
1053 langModule->languagePackageCO->addItem(
1054 qt_("Always Babel"), toqstr("babel"));
1055 langModule->languagePackageCO->addItem(
1056 qt_("Custom"), toqstr("custom"));
1057 langModule->languagePackageCO->addItem(
1058 qt_("None[[language package]]"), toqstr("none"));
1062 colorModule = new UiWidget<Ui::ColorUi>;
1063 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1064 this, SLOT(changeFontColor()));
1065 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1066 this, SLOT(deleteFontColor()));
1067 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1068 this, SLOT(changeNoteFontColor()));
1069 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1070 this, SLOT(deleteNoteFontColor()));
1071 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1072 this, SLOT(changeBackgroundColor()));
1073 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1074 this, SLOT(deleteBackgroundColor()));
1075 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1076 this, SLOT(changeBoxBackgroundColor()));
1077 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1078 this, SLOT(deleteBoxBackgroundColor()));
1082 numberingModule = new UiWidget<Ui::NumberingUi>;
1083 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1084 this, SLOT(change_adaptor()));
1085 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1086 this, SLOT(change_adaptor()));
1087 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1088 this, SLOT(updateNumbering()));
1089 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1090 this, SLOT(updateNumbering()));
1091 numberingModule->tocTW->setColumnCount(3);
1092 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1093 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1094 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1095 numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents);
1099 biblioModule = new UiWidget<Ui::BiblioUi>;
1100 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1101 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1102 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1103 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1104 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1105 this, SLOT(change_adaptor()));
1106 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1107 this, SLOT(change_adaptor()));
1108 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1109 this, SLOT(change_adaptor()));
1110 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1111 this, SLOT(change_adaptor()));
1112 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1113 this, SLOT(change_adaptor()));
1114 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1115 this, SLOT(bibtexChanged(int)));
1116 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1117 this, SLOT(change_adaptor()));
1119 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1120 biblioModule->bibtexOptionsLE));
1122 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1123 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1124 biblioModule->citeStyleCO->setCurrentIndex(0);
1126 // NOTE: we do not provide "custom" here for security reasons!
1127 biblioModule->bibtexCO->clear();
1128 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1129 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1130 it != lyxrc.bibtex_alternatives.end(); ++it) {
1131 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1132 biblioModule->bibtexCO->addItem(command, command);
1137 indicesModule = new GuiIndices;
1138 connect(indicesModule, SIGNAL(changed()),
1139 this, SLOT(change_adaptor()));
1143 mathsModule = new UiWidget<Ui::MathsUi>;
1144 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
1145 mathsModule->amsCB, SLOT(setDisabled(bool)));
1146 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
1147 mathsModule->esintCB, SLOT(setDisabled(bool)));
1148 connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)),
1149 mathsModule->mhchemCB, SLOT(setDisabled(bool)));
1150 connect(mathsModule->mathdotsautoCB, SIGNAL(toggled(bool)),
1151 mathsModule->mathdotsCB, SLOT(setDisabled(bool)));
1152 connect(mathsModule->undertildeautoCB, SIGNAL(toggled(bool)),
1153 mathsModule->undertildeCB, SLOT(setDisabled(bool)));
1155 connect(mathsModule->amsCB, SIGNAL(clicked()),
1156 this, SLOT(change_adaptor()));
1157 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
1158 this, SLOT(change_adaptor()));
1159 connect(mathsModule->esintCB, SIGNAL(clicked()),
1160 this, SLOT(change_adaptor()));
1161 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
1162 this, SLOT(change_adaptor()));
1163 connect(mathsModule->mhchemCB, SIGNAL(clicked()),
1164 this, SLOT(change_adaptor()));
1165 connect(mathsModule->mhchemautoCB, SIGNAL(clicked()),
1166 this, SLOT(change_adaptor()));
1167 connect(mathsModule->mathdotsCB, SIGNAL(clicked()),
1168 this, SLOT(change_adaptor()));
1169 connect(mathsModule->mathdotsautoCB, SIGNAL(clicked()),
1170 this, SLOT(change_adaptor()));
1171 connect(mathsModule->undertildeCB, SIGNAL(clicked()),
1172 this, SLOT(change_adaptor()));
1173 connect(mathsModule->undertildeautoCB, SIGNAL(clicked()),
1174 this, SLOT(change_adaptor()));
1178 latexModule = new UiWidget<Ui::LaTeXUi>;
1179 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1180 this, SLOT(change_adaptor()));
1181 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1182 this, SLOT(change_adaptor()));
1183 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1184 this, SLOT(change_adaptor()));
1185 connect(latexModule->classCO, SIGNAL(activated(int)),
1186 this, SLOT(classChanged()));
1187 connect(latexModule->classCO, SIGNAL(activated(int)),
1188 this, SLOT(change_adaptor()));
1189 connect(latexModule->layoutPB, SIGNAL(clicked()),
1190 this, SLOT(browseLayout()));
1191 connect(latexModule->layoutPB, SIGNAL(clicked()),
1192 this, SLOT(change_adaptor()));
1193 connect(latexModule->childDocGB, SIGNAL(clicked()),
1194 this, SLOT(change_adaptor()));
1195 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1196 this, SLOT(change_adaptor()));
1197 connect(latexModule->childDocPB, SIGNAL(clicked()),
1198 this, SLOT(browseMaster()));
1199 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1200 this, SLOT(change_adaptor()));
1201 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1202 this, SLOT(change_adaptor()));
1204 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1205 latexModule->optionsLE));
1206 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1207 latexModule->childDocLE));
1209 // postscript drivers
1210 for (int n = 0; tex_graphics[n][0]; ++n) {
1211 QString enc = qt_(tex_graphics_gui[n]);
1212 latexModule->psdriverCO->addItem(enc);
1215 latexModule->classCO->setModel(&classes_model_);
1216 LayoutFileList const & bcl = LayoutFileList::get();
1217 vector<LayoutFileIndex> classList = bcl.classList();
1218 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1220 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1221 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1222 for (int i = 0; cit != cen; ++cit, ++i) {
1223 LayoutFile const & tc = bcl[*cit];
1224 docstring item = (tc.isTeXClassAvailable()) ?
1225 from_utf8(tc.description()) :
1226 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1227 classes_model_.insertRow(i, toqstr(item), *cit);
1232 branchesModule = new GuiBranches;
1233 connect(branchesModule, SIGNAL(changed()),
1234 this, SLOT(change_adaptor()));
1235 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1236 this, SLOT(branchesRename(docstring const &, docstring const &)));
1237 updateUnknownBranches();
1241 preambleModule = new PreambleModule;
1242 connect(preambleModule, SIGNAL(changed()),
1243 this, SLOT(change_adaptor()));
1245 localLayout = new LocalLayout;
1246 connect(localLayout, SIGNAL(changed()),
1247 this, SLOT(change_adaptor()));
1251 bulletsModule = new BulletsModule;
1252 connect(bulletsModule, SIGNAL(changed()),
1253 this, SLOT(change_adaptor()));
1257 modulesModule = new UiWidget<Ui::ModulesUi>;
1258 modulesModule->availableLV->header()->setVisible(false);
1259 modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents);
1260 modulesModule->availableLV->header()->setStretchLastSection(false);
1262 new ModuleSelectionManager(modulesModule->availableLV,
1263 modulesModule->selectedLV,
1264 modulesModule->addPB, modulesModule->deletePB,
1265 modulesModule->upPB, modulesModule->downPB,
1266 availableModel(), selectedModel(), this);
1267 connect(selectionManager, SIGNAL(updateHook()),
1268 this, SLOT(updateModuleInfo()));
1269 connect(selectionManager, SIGNAL(updateHook()),
1270 this, SLOT(change_adaptor()));
1271 connect(selectionManager, SIGNAL(selectionChanged()),
1272 this, SLOT(modulesChanged()));
1276 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1277 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1278 this, SLOT(change_adaptor()));
1279 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1280 this, SLOT(change_adaptor()));
1281 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1282 this, SLOT(change_adaptor()));
1283 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1284 this, SLOT(change_adaptor()));
1285 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1286 this, SLOT(change_adaptor()));
1287 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1288 this, SLOT(change_adaptor()));
1289 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1290 this, SLOT(change_adaptor()));
1291 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1292 this, SLOT(change_adaptor()));
1293 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1294 this, SLOT(change_adaptor()));
1295 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1296 this, SLOT(change_adaptor()));
1297 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1298 this, SLOT(change_adaptor()));
1299 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1300 this, SLOT(change_adaptor()));
1301 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1302 this, SLOT(change_adaptor()));
1303 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1304 this, SLOT(change_adaptor()));
1305 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1306 this, SLOT(change_adaptor()));
1307 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1308 this, SLOT(change_adaptor()));
1310 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1311 pdfSupportModule->titleLE));
1312 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1313 pdfSupportModule->authorLE));
1314 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1315 pdfSupportModule->subjectLE));
1316 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1317 pdfSupportModule->keywordsLE));
1318 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1319 pdfSupportModule->optionsLE));
1321 for (int i = 0; backref_opts[i][0]; ++i)
1322 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1326 floatModule = new FloatPlacement;
1327 connect(floatModule, SIGNAL(changed()),
1328 this, SLOT(change_adaptor()));
1332 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1333 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1334 this, SLOT(change_adaptor()));
1335 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1336 this, SLOT(change_adaptor()));
1337 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1338 this, SLOT(setListingsMessage()));
1339 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1340 this, SLOT(setListingsMessage()));
1341 listingsModule->listingsTB->setPlainText(
1342 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1346 docPS->addPanel(latexModule, qt_("Document Class"));
1347 docPS->addPanel(masterChildModule, qt_("Child Documents"));
1348 docPS->addPanel(modulesModule, qt_("Modules"));
1349 docPS->addPanel(localLayout, qt_("Local Layout"));
1350 docPS->addPanel(fontModule, qt_("Fonts"));
1351 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1352 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1353 docPS->addPanel(marginsModule, qt_("Page Margins"));
1354 docPS->addPanel(langModule, qt_("Language"));
1355 docPS->addPanel(colorModule, qt_("Colors"));
1356 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1357 docPS->addPanel(biblioModule, qt_("Bibliography"));
1358 docPS->addPanel(indicesModule, qt_("Indexes"));
1359 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1360 docPS->addPanel(mathsModule, qt_("Math Options"));
1361 docPS->addPanel(floatModule, qt_("Float Placement"));
1362 docPS->addPanel(listingsModule, qt_("Listings"));
1363 docPS->addPanel(bulletsModule, qt_("Bullets"));
1364 docPS->addPanel(branchesModule, qt_("Branches"));
1365 docPS->addPanel(outputModule, qt_("Output"));
1366 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1367 docPS->setCurrentPanel(qt_("Document Class"));
1368 // FIXME: hack to work around resizing bug in Qt >= 4.2
1369 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1370 #if QT_VERSION >= 0x040200
1371 docPS->updateGeometry();
1376 void GuiDocument::saveDefaultClicked()
1382 void GuiDocument::useDefaultsClicked()
1388 void GuiDocument::change_adaptor()
1394 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1399 string child = fromqstr(item->text(0));
1403 if (std::find(includeonlys_.begin(),
1404 includeonlys_.end(), child) != includeonlys_.end())
1405 includeonlys_.remove(child);
1407 includeonlys_.push_back(child);
1409 updateIncludeonlys();
1414 QString GuiDocument::validateListingsParameters()
1416 // use a cache here to avoid repeated validation
1417 // of the same parameters
1418 static string param_cache;
1419 static QString msg_cache;
1421 if (listingsModule->bypassCB->isChecked())
1424 string params = fromqstr(listingsModule->listingsED->toPlainText());
1425 if (params != param_cache) {
1426 param_cache = params;
1427 msg_cache = toqstr(InsetListingsParams(params).validate());
1433 void GuiDocument::setListingsMessage()
1435 static bool isOK = true;
1436 QString msg = validateListingsParameters();
1437 if (msg.isEmpty()) {
1441 // listingsTB->setTextColor("black");
1442 listingsModule->listingsTB->setPlainText(
1443 qt_("Input listings parameters below. "
1444 "Enter ? for a list of parameters."));
1447 // listingsTB->setTextColor("red");
1448 listingsModule->listingsTB->setPlainText(msg);
1453 void GuiDocument::setLSpacing(int item)
1455 textLayoutModule->lspacingLE->setEnabled(item == 3);
1459 void GuiDocument::setIndent(int item)
1461 bool const enable = (item == 1);
1462 textLayoutModule->indentLE->setEnabled(enable);
1463 textLayoutModule->indentLengthCO->setEnabled(enable);
1464 textLayoutModule->skipLE->setEnabled(false);
1465 textLayoutModule->skipLengthCO->setEnabled(false);
1470 void GuiDocument::enableIndent(bool indent)
1472 textLayoutModule->skipLE->setEnabled(!indent);
1473 textLayoutModule->skipLengthCO->setEnabled(!indent);
1475 setIndent(textLayoutModule->indentCO->currentIndex());
1479 void GuiDocument::setSkip(int item)
1481 bool const enable = (item == 3);
1482 textLayoutModule->skipLE->setEnabled(enable);
1483 textLayoutModule->skipLengthCO->setEnabled(enable);
1488 void GuiDocument::enableSkip(bool skip)
1490 textLayoutModule->indentLE->setEnabled(!skip);
1491 textLayoutModule->indentLengthCO->setEnabled(!skip);
1493 setSkip(textLayoutModule->skipCO->currentIndex());
1497 void GuiDocument::setMargins()
1499 bool const extern_geometry =
1500 documentClass().provides("geometry");
1501 marginsModule->marginCB->setEnabled(!extern_geometry);
1502 if (extern_geometry) {
1503 marginsModule->marginCB->setChecked(false);
1504 setCustomMargins(true);
1506 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1507 setCustomMargins(!bp_.use_geometry);
1512 void GuiDocument::papersizeChanged(int paper_size)
1514 setCustomPapersize(paper_size == 1);
1518 void GuiDocument::setCustomPapersize(bool custom)
1520 pageLayoutModule->paperwidthL->setEnabled(custom);
1521 pageLayoutModule->paperwidthLE->setEnabled(custom);
1522 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1523 pageLayoutModule->paperheightL->setEnabled(custom);
1524 pageLayoutModule->paperheightLE->setEnabled(custom);
1525 pageLayoutModule->paperheightLE->setFocus();
1526 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1530 void GuiDocument::setColSep()
1532 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1536 void GuiDocument::setCustomMargins(bool custom)
1538 marginsModule->topL->setEnabled(!custom);
1539 marginsModule->topLE->setEnabled(!custom);
1540 marginsModule->topUnit->setEnabled(!custom);
1542 marginsModule->bottomL->setEnabled(!custom);
1543 marginsModule->bottomLE->setEnabled(!custom);
1544 marginsModule->bottomUnit->setEnabled(!custom);
1546 marginsModule->innerL->setEnabled(!custom);
1547 marginsModule->innerLE->setEnabled(!custom);
1548 marginsModule->innerUnit->setEnabled(!custom);
1550 marginsModule->outerL->setEnabled(!custom);
1551 marginsModule->outerLE->setEnabled(!custom);
1552 marginsModule->outerUnit->setEnabled(!custom);
1554 marginsModule->headheightL->setEnabled(!custom);
1555 marginsModule->headheightLE->setEnabled(!custom);
1556 marginsModule->headheightUnit->setEnabled(!custom);
1558 marginsModule->headsepL->setEnabled(!custom);
1559 marginsModule->headsepLE->setEnabled(!custom);
1560 marginsModule->headsepUnit->setEnabled(!custom);
1562 marginsModule->footskipL->setEnabled(!custom);
1563 marginsModule->footskipLE->setEnabled(!custom);
1564 marginsModule->footskipUnit->setEnabled(!custom);
1566 bool const enableColSep = !custom &&
1567 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1568 marginsModule->columnsepL->setEnabled(enableColSep);
1569 marginsModule->columnsepLE->setEnabled(enableColSep);
1570 marginsModule->columnsepUnit->setEnabled(enableColSep);
1574 void GuiDocument::changeBackgroundColor()
1576 QColor const & newColor = QColorDialog::getColor(
1577 rgb2qcolor(set_backgroundcolor), asQWidget());
1578 if (!newColor.isValid())
1580 // set the button color and text
1581 colorModule->backgroundPB->setStyleSheet(
1582 colorButtonStyleSheet(newColor));
1583 colorModule->backgroundPB->setText(qt_("&Change..."));
1585 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1586 is_backgroundcolor = true;
1591 void GuiDocument::deleteBackgroundColor()
1593 // set the button color back to default by setting an empty StyleSheet
1594 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1595 // change button text
1596 colorModule->backgroundPB->setText(qt_("&Default..."));
1597 // save default color (white)
1598 set_backgroundcolor = rgbFromHexName("#ffffff");
1599 is_backgroundcolor = false;
1604 void GuiDocument::changeFontColor()
1606 QColor const & newColor = QColorDialog::getColor(
1607 rgb2qcolor(set_fontcolor), asQWidget());
1608 if (!newColor.isValid())
1610 // set the button color and text
1611 colorModule->fontColorPB->setStyleSheet(
1612 colorButtonStyleSheet(newColor));
1613 colorModule->fontColorPB->setText(qt_("&Change..."));
1615 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1616 is_fontcolor = true;
1621 void GuiDocument::deleteFontColor()
1623 // set the button color back to default by setting an empty StyleSheet
1624 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1625 // change button text
1626 colorModule->fontColorPB->setText(qt_("&Default..."));
1627 // save default color (black)
1628 set_fontcolor = rgbFromHexName("#000000");
1629 is_fontcolor = false;
1634 void GuiDocument::changeNoteFontColor()
1636 QColor const & newColor = QColorDialog::getColor(
1637 rgb2qcolor(set_notefontcolor), asQWidget());
1638 if (!newColor.isValid())
1640 // set the button color
1641 colorModule->noteFontColorPB->setStyleSheet(
1642 colorButtonStyleSheet(newColor));
1644 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1649 void GuiDocument::deleteNoteFontColor()
1651 // set the button color back to pref
1652 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1653 colorModule->noteFontColorPB->setStyleSheet(
1654 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1659 void GuiDocument::changeBoxBackgroundColor()
1661 QColor const & newColor = QColorDialog::getColor(
1662 rgb2qcolor(set_boxbgcolor), asQWidget());
1663 if (!newColor.isValid())
1665 // set the button color
1666 colorModule->boxBackgroundPB->setStyleSheet(
1667 colorButtonStyleSheet(newColor));
1669 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1674 void GuiDocument::deleteBoxBackgroundColor()
1676 // set the button color back to pref
1677 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1678 colorModule->boxBackgroundPB->setStyleSheet(
1679 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1684 void GuiDocument::osFontsChanged(bool nontexfonts)
1686 bool const tex_fonts = !nontexfonts;
1688 updateDefaultFormat();
1689 langModule->encodingCO->setEnabled(tex_fonts &&
1690 !langModule->defaultencodingRB->isChecked());
1691 langModule->defaultencodingRB->setEnabled(tex_fonts);
1692 langModule->otherencodingRB->setEnabled(tex_fonts);
1694 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1695 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1696 fontModule->cjkFontLE->setEnabled(tex_fonts);
1697 fontModule->cjkFontLA->setEnabled(tex_fonts);
1700 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1701 bool scaleable = providesScale(font);
1702 fontModule->scaleSansSB->setEnabled(scaleable);
1703 fontModule->scaleSansLA->setEnabled(scaleable);
1705 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1706 scaleable = providesScale(font);
1707 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1708 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1710 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1711 fontModule->fontScCB->setEnabled(providesSC(font));
1712 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1714 fontModule->fontencLA->setEnabled(tex_fonts);
1715 fontModule->fontencCO->setEnabled(tex_fonts);
1717 fontModule->fontencLE->setEnabled(false);
1719 fontencChanged(fontModule->fontencCO->currentIndex());
1723 void GuiDocument::updateFontsize(string const & items, string const & sel)
1725 fontModule->fontsizeCO->clear();
1726 fontModule->fontsizeCO->addItem(qt_("Default"));
1728 for (int n = 0; !token(items,'|',n).empty(); ++n)
1729 fontModule->fontsizeCO->
1730 addItem(toqstr(token(items,'|',n)));
1732 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1733 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1734 fontModule->fontsizeCO->setCurrentIndex(n);
1741 void GuiDocument::updateFontlist()
1743 fontModule->fontsRomanCO->clear();
1744 fontModule->fontsSansCO->clear();
1745 fontModule->fontsTypewriterCO->clear();
1747 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1748 if (fontModule->osFontsCB->isChecked()) {
1749 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1750 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1751 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1753 QFontDatabase fontdb;
1754 QStringList families(fontdb.families());
1755 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1756 fontModule->fontsRomanCO->addItem(*it, *it);
1757 fontModule->fontsSansCO->addItem(*it, *it);
1758 fontModule->fontsTypewriterCO->addItem(*it, *it);
1763 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1764 QString font = qt_(tex_fonts_roman_gui[n]);
1765 if (!isFontAvailable(tex_fonts_roman[n]))
1766 font += qt_(" (not installed)");
1767 fontModule->fontsRomanCO->addItem(font, qt_(tex_fonts_roman[n]));
1769 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1770 QString font = qt_(tex_fonts_sans_gui[n]);
1771 if (!isFontAvailable(tex_fonts_sans[n]))
1772 font += qt_(" (not installed)");
1773 fontModule->fontsSansCO->addItem(font, qt_(tex_fonts_sans[n]));
1775 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1776 QString font = qt_(tex_fonts_monospaced_gui[n]);
1777 if (!isFontAvailable(tex_fonts_monospaced[n]))
1778 font += qt_(" (not installed)");
1779 fontModule->fontsTypewriterCO->addItem(font, qt_(tex_fonts_monospaced[n]));
1784 void GuiDocument::fontencChanged(int item)
1786 fontModule->fontencLE->setEnabled(item == 1);
1790 void GuiDocument::romanChanged(int item)
1792 if (fontModule->osFontsCB->isChecked())
1794 string const font = tex_fonts_roman[item];
1795 fontModule->fontScCB->setEnabled(providesSC(font));
1796 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1800 void GuiDocument::sansChanged(int item)
1802 if (fontModule->osFontsCB->isChecked())
1804 string const font = tex_fonts_sans[item];
1805 bool scaleable = providesScale(font);
1806 fontModule->scaleSansSB->setEnabled(scaleable);
1807 fontModule->scaleSansLA->setEnabled(scaleable);
1811 void GuiDocument::ttChanged(int item)
1813 if (fontModule->osFontsCB->isChecked())
1815 string const font = tex_fonts_monospaced[item];
1816 bool scaleable = providesScale(font);
1817 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1818 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1822 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1825 pageLayoutModule->pagestyleCO->clear();
1826 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1828 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1829 string style = token(items, '|', n);
1830 QString style_gui = qt_(style);
1831 pagestyles.push_back(pair<string, QString>(style, style_gui));
1832 pageLayoutModule->pagestyleCO->addItem(style_gui);
1835 if (sel == "default") {
1836 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1842 for (size_t i = 0; i < pagestyles.size(); ++i)
1843 if (pagestyles[i].first == sel)
1844 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1847 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1851 void GuiDocument::browseLayout()
1853 QString const label1 = qt_("Layouts|#o#O");
1854 QString const dir1 = toqstr(lyxrc.document_path);
1855 QStringList const filter(qt_("LyX Layout (*.layout)"));
1856 QString file = browseRelToParent(QString(), bufferFilePath(),
1857 qt_("Local layout file"), filter, false,
1860 if (!file.endsWith(".layout"))
1863 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1864 fromqstr(bufferFilePath()));
1866 int const ret = Alert::prompt(_("Local layout file"),
1867 _("The layout file you have selected is a local layout\n"
1868 "file, not one in the system or user directory. Your\n"
1869 "document may not work with this layout if you do not\n"
1870 "keep the layout file in the document directory."),
1871 1, 1, _("&Set Layout"), _("&Cancel"));
1875 // load the layout file
1876 LayoutFileList & bcl = LayoutFileList::get();
1877 string classname = layoutFile.onlyFileName();
1878 // this will update an existing layout if that layout has been loaded before.
1879 LayoutFileIndex name = bcl.addLocalLayout(
1880 classname.substr(0, classname.size() - 7),
1881 layoutFile.onlyPath().absFileName());
1884 Alert::error(_("Error"),
1885 _("Unable to read local layout file."));
1889 // do not trigger classChanged if there is no change.
1890 if (latexModule->classCO->currentText() == toqstr(name))
1894 int idx = latexModule->classCO->findText(toqstr(name));
1896 classes_model_.insertRow(0, toqstr(name), name);
1897 latexModule->classCO->setCurrentIndex(0);
1899 latexModule->classCO->setCurrentIndex(idx);
1905 void GuiDocument::browseMaster()
1907 QString const title = qt_("Select master document");
1908 QString const dir1 = toqstr(lyxrc.document_path);
1909 QString const old = latexModule->childDocLE->text();
1910 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1911 QStringList const filter(qt_("LyX Files (*.lyx)"));
1912 QString file = browseRelToSub(old, docpath, title, filter, false,
1913 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1915 if (!file.isEmpty())
1916 latexModule->childDocLE->setText(file);
1920 void GuiDocument::classChanged()
1922 int idx = latexModule->classCO->currentIndex();
1925 string const classname = classes_model_.getIDString(idx);
1927 // check whether the selected modules have changed.
1928 bool modules_changed = false;
1929 unsigned int const srows = selectedModel()->rowCount();
1930 if (srows != bp_.getModules().size())
1931 modules_changed = true;
1933 list<string>::const_iterator mit = bp_.getModules().begin();
1934 list<string>::const_iterator men = bp_.getModules().end();
1935 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1936 if (selectedModel()->getIDString(i) != *mit) {
1937 modules_changed = true;
1942 if (modules_changed || lyxrc.auto_reset_options) {
1943 if (applyPB->isEnabled()) {
1944 int const ret = Alert::prompt(_("Unapplied changes"),
1945 _("Some changes in the dialog were not yet applied.\n"
1946 "If you do not apply now, they will be lost after this action."),
1947 1, 1, _("&Apply"), _("&Dismiss"));
1953 // We load the TextClass as soon as it is selected. This is
1954 // necessary so that other options in the dialog can be updated
1955 // according to the new class. Note, however, that, if you use
1956 // the scroll wheel when sitting on the combo box, we'll load a
1957 // lot of TextClass objects very quickly....
1958 if (!bp_.setBaseClass(classname)) {
1959 Alert::error(_("Error"), _("Unable to set document class."));
1962 if (lyxrc.auto_reset_options)
1963 bp_.useClassDefaults();
1965 // With the introduction of modules came a distinction between the base
1966 // class and the document class. The former corresponds to the main layout
1967 // file; the latter is that plus the modules (or the document-specific layout,
1968 // or whatever else there could be). Our parameters come from the document
1969 // class. So when we set the base class, we also need to recreate the document
1970 // class. Otherwise, we still have the old one.
1971 bp_.makeDocumentClass();
1976 void GuiDocument::languagePackageChanged(int i)
1978 langModule->languagePackageLE->setEnabled(
1979 langModule->languagePackageCO->itemData(i).toString() == "custom");
1983 void GuiDocument::bibtexChanged(int n)
1985 biblioModule->bibtexOptionsLE->setEnabled(
1986 biblioModule->bibtexCO->itemData(n).toString() != "default");
1993 // both of these should take a vector<docstring>
1995 // This is an insanely complicated attempt to make this sort of thing
1996 // work with RTL languages.
1997 docstring formatStrVec(vector<string> const & v, docstring const & s)
1999 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2003 return translateIfPossible(from_utf8(v[0]));
2004 if (v.size() == 2) {
2005 docstring retval = _("%1$s and %2$s");
2006 retval = subst(retval, _("and"), s);
2007 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2008 translateIfPossible(from_utf8(v[1])));
2010 // The idea here is to format all but the last two items...
2011 int const vSize = v.size();
2012 docstring t2 = _("%1$s, %2$s");
2013 docstring retval = translateIfPossible(from_utf8(v[0]));
2014 for (int i = 1; i < vSize - 2; ++i)
2015 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2016 //...and then to plug them, and the last two, into this schema
2017 docstring t = _("%1$s, %2$s, and %3$s");
2018 t = subst(t, _("and"), s);
2019 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2020 translateIfPossible(from_utf8(v[vSize - 1])));
2023 vector<string> idsToNames(vector<string> const & idList)
2025 vector<string> retval;
2026 vector<string>::const_iterator it = idList.begin();
2027 vector<string>::const_iterator end = idList.end();
2028 for (; it != end; ++it) {
2029 LyXModule const * const mod = theModuleList[*it];
2031 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2032 translateIfPossible(from_utf8(*it)))));
2034 retval.push_back(mod->getName());
2038 } // end anonymous namespace
2041 void GuiDocument::modulesToParams(BufferParams & bp)
2043 // update list of loaded modules
2044 bp.clearLayoutModules();
2045 int const srows = modules_sel_model_.rowCount();
2046 for (int i = 0; i < srows; ++i)
2047 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2049 // update the list of removed modules
2050 bp.clearRemovedModules();
2051 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2052 list<string>::const_iterator rit = reqmods.begin();
2053 list<string>::const_iterator ren = reqmods.end();
2055 // check each of the default modules
2056 for (; rit != ren; rit++) {
2057 list<string>::const_iterator mit = bp.getModules().begin();
2058 list<string>::const_iterator men = bp.getModules().end();
2060 for (; mit != men; mit++) {
2067 // the module isn't present so must have been removed by the user
2068 bp.addRemovedModule(*rit);
2073 void GuiDocument::modulesChanged()
2075 modulesToParams(bp_);
2076 bp_.makeDocumentClass();
2081 void GuiDocument::updateModuleInfo()
2083 selectionManager->update();
2085 //Module description
2086 bool const focus_on_selected = selectionManager->selectedFocused();
2087 QAbstractItemView * lv;
2088 if (focus_on_selected)
2089 lv = modulesModule->selectedLV;
2091 lv= modulesModule->availableLV;
2092 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2093 modulesModule->infoML->document()->clear();
2096 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2097 GuiIdListModel const & id_model =
2098 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2099 string const modName = id_model.getIDString(idx.row());
2100 docstring desc = getModuleDescription(modName);
2102 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2103 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2106 desc += _("Module provided by document class.");
2109 vector<string> pkglist = getPackageList(modName);
2110 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2111 if (!pkgdesc.empty()) {
2114 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2117 pkglist = getRequiredList(modName);
2118 if (!pkglist.empty()) {
2119 vector<string> const reqdescs = idsToNames(pkglist);
2120 pkgdesc = formatStrVec(reqdescs, _("or"));
2123 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2126 pkglist = getExcludedList(modName);
2127 if (!pkglist.empty()) {
2128 vector<string> const reqdescs = idsToNames(pkglist);
2129 pkgdesc = formatStrVec(reqdescs, _( "and"));
2132 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2135 if (!isModuleAvailable(modName)) {
2138 desc += _("WARNING: Some required packages are unavailable!");
2141 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2145 void GuiDocument::updateNumbering()
2147 DocumentClass const & tclass = documentClass();
2149 numberingModule->tocTW->setUpdatesEnabled(false);
2150 numberingModule->tocTW->clear();
2152 int const depth = numberingModule->depthSL->value();
2153 int const toc = numberingModule->tocSL->value();
2154 QString const no = qt_("No");
2155 QString const yes = qt_("Yes");
2156 QTreeWidgetItem * item = 0;
2158 DocumentClass::const_iterator lit = tclass.begin();
2159 DocumentClass::const_iterator len = tclass.end();
2160 for (; lit != len; ++lit) {
2161 int const toclevel = lit->toclevel;
2162 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
2163 item = new QTreeWidgetItem(numberingModule->tocTW);
2164 item->setText(0, toqstr(translateIfPossible(lit->name())));
2165 item->setText(1, (toclevel <= depth) ? yes : no);
2166 item->setText(2, (toclevel <= toc) ? yes : no);
2170 numberingModule->tocTW->setUpdatesEnabled(true);
2171 numberingModule->tocTW->update();
2175 void GuiDocument::updateDefaultFormat()
2179 // make a copy in order to consider unapplied changes
2180 BufferParams param_copy = buffer().params();
2181 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2182 int const idx = latexModule->classCO->currentIndex();
2184 string const classname = classes_model_.getIDString(idx);
2185 param_copy.setBaseClass(classname);
2186 param_copy.makeDocumentClass();
2188 outputModule->defaultFormatCO->blockSignals(true);
2189 outputModule->defaultFormatCO->clear();
2190 outputModule->defaultFormatCO->addItem(qt_("Default"),
2191 QVariant(QString("default")));
2192 typedef vector<Format const *> Formats;
2193 Formats formats = param_copy.exportableFormats(true);
2194 Formats::const_iterator cit = formats.begin();
2195 Formats::const_iterator end = formats.end();
2196 for (; cit != end; ++cit)
2197 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2198 QVariant(toqstr((*cit)->name())));
2199 outputModule->defaultFormatCO->blockSignals(false);
2203 bool GuiDocument::isChildIncluded(string const & child)
2205 if (includeonlys_.empty())
2207 return (std::find(includeonlys_.begin(),
2208 includeonlys_.end(), child) != includeonlys_.end());
2212 void GuiDocument::applyView()
2215 preambleModule->apply(bp_);
2216 localLayout->apply(bp_);
2219 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2220 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2223 bp_.setCiteEngine(ENGINE_BASIC);
2225 if (biblioModule->citeNatbibRB->isChecked()) {
2226 bool const use_numerical_citations =
2227 biblioModule->citeStyleCO->currentIndex();
2228 if (use_numerical_citations)
2229 bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
2231 bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
2233 } else if (biblioModule->citeJurabibRB->isChecked())
2234 bp_.setCiteEngine(ENGINE_JURABIB);
2237 biblioModule->bibtopicCB->isChecked();
2239 string const bibtex_command =
2240 fromqstr(biblioModule->bibtexCO->itemData(
2241 biblioModule->bibtexCO->currentIndex()).toString());
2242 string const bibtex_options =
2243 fromqstr(biblioModule->bibtexOptionsLE->text());
2244 if (bibtex_command == "default" || bibtex_options.empty())
2245 bp_.bibtex_command = bibtex_command;
2247 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2250 indicesModule->apply(bp_);
2252 // language & quotes
2253 if (langModule->defaultencodingRB->isChecked()) {
2254 bp_.inputenc = "auto";
2256 int i = langModule->encodingCO->currentIndex();
2258 bp_.inputenc = "default";
2260 QString const enc_gui =
2261 langModule->encodingCO->currentText();
2262 Encodings::const_iterator it = encodings.begin();
2263 Encodings::const_iterator const end = encodings.end();
2265 for (; it != end; ++it) {
2266 if (qt_(it->guiName()) == enc_gui) {
2267 bp_.inputenc = it->latexName();
2273 // should not happen
2274 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2275 bp_.inputenc = "default";
2280 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2281 switch (langModule->quoteStyleCO->currentIndex()) {
2283 lga = InsetQuotes::EnglishQuotes;
2286 lga = InsetQuotes::SwedishQuotes;
2289 lga = InsetQuotes::GermanQuotes;
2292 lga = InsetQuotes::PolishQuotes;
2295 lga = InsetQuotes::FrenchQuotes;
2298 lga = InsetQuotes::DanishQuotes;
2301 bp_.quotes_language = lga;
2303 QString const lang = langModule->languageCO->itemData(
2304 langModule->languageCO->currentIndex()).toString();
2305 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2307 QString const pack = langModule->languagePackageCO->itemData(
2308 langModule->languagePackageCO->currentIndex()).toString();
2309 if (pack == "custom")
2311 fromqstr(langModule->languagePackageLE->text());
2313 bp_.lang_package = fromqstr(pack);
2316 bp_.backgroundcolor = set_backgroundcolor;
2317 bp_.isbackgroundcolor = is_backgroundcolor;
2318 bp_.fontcolor = set_fontcolor;
2319 bp_.isfontcolor = is_fontcolor;
2320 bp_.notefontcolor = set_notefontcolor;
2321 bp_.boxbgcolor = set_boxbgcolor;
2324 if (bp_.documentClass().hasTocLevels()) {
2325 bp_.tocdepth = numberingModule->tocSL->value();
2326 bp_.secnumdepth = numberingModule->depthSL->value();
2330 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2331 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2332 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2333 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2336 bp_.graphics_driver =
2337 tex_graphics[latexModule->psdriverCO->currentIndex()];
2340 int idx = latexModule->classCO->currentIndex();
2342 string const classname = classes_model_.getIDString(idx);
2343 bp_.setBaseClass(classname);
2347 modulesToParams(bp_);
2350 if (mathsModule->amsautoCB->isChecked())
2351 bp_.use_amsmath = BufferParams::package_auto;
2353 if (mathsModule->amsCB->isChecked())
2354 bp_.use_amsmath = BufferParams::package_on;
2356 bp_.use_amsmath = BufferParams::package_off;
2358 if (mathsModule->esintautoCB->isChecked())
2359 bp_.use_esint = BufferParams::package_auto;
2361 if (mathsModule->esintCB->isChecked())
2362 bp_.use_esint = BufferParams::package_on;
2364 bp_.use_esint = BufferParams::package_off;
2366 if (mathsModule->mhchemautoCB->isChecked())
2367 bp_.use_mhchem = BufferParams::package_auto;
2369 if (mathsModule->mhchemCB->isChecked())
2370 bp_.use_mhchem = BufferParams::package_on;
2372 bp_.use_mhchem = BufferParams::package_off;
2374 if (mathsModule->mathdotsautoCB->isChecked())
2375 bp_.use_mathdots = BufferParams::package_auto;
2377 if (mathsModule->mathdotsCB->isChecked())
2378 bp_.use_mathdots = BufferParams::package_on;
2380 bp_.use_mathdots = BufferParams::package_off;
2382 if (mathsModule->undertildeautoCB->isChecked())
2383 bp_.use_undertilde = BufferParams::package_auto;
2385 if (mathsModule->undertildeCB->isChecked())
2386 bp_.use_undertilde = BufferParams::package_on;
2388 bp_.use_undertilde = BufferParams::package_off;
2392 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2393 bp_.pagestyle = "default";
2395 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2396 for (size_t i = 0; i != pagestyles.size(); ++i)
2397 if (pagestyles[i].second == style_gui)
2398 bp_.pagestyle = pagestyles[i].first;
2402 switch (textLayoutModule->lspacingCO->currentIndex()) {
2404 bp_.spacing().set(Spacing::Single);
2407 bp_.spacing().set(Spacing::Onehalf);
2410 bp_.spacing().set(Spacing::Double);
2413 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2415 bp_.spacing().set(Spacing::Single);
2417 bp_.spacing().set(Spacing::Other, s);
2422 if (textLayoutModule->twoColumnCB->isChecked())
2427 if (textLayoutModule->indentRB->isChecked()) {
2428 // if paragraphs are separated by an indentation
2429 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2430 switch (textLayoutModule->indentCO->currentIndex()) {
2432 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2435 HSpace indent = HSpace(
2436 widgetsToLength(textLayoutModule->indentLE,
2437 textLayoutModule->indentLengthCO)
2439 bp_.setIndentation(indent);
2443 // this should never happen
2444 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2448 // if paragraphs are separated by a skip
2449 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2450 switch (textLayoutModule->skipCO->currentIndex()) {
2452 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2455 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2458 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2463 widgetsToLength(textLayoutModule->skipLE,
2464 textLayoutModule->skipLengthCO)
2470 // this should never happen
2471 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2477 fromqstr(latexModule->optionsLE->text());
2479 bp_.use_default_options =
2480 latexModule->defaultOptionsCB->isChecked();
2482 if (latexModule->childDocGB->isChecked())
2484 fromqstr(latexModule->childDocLE->text());
2486 bp_.master = string();
2489 bp_.clearIncludedChildren();
2490 if (masterChildModule->includeonlyRB->isChecked()) {
2491 list<string>::const_iterator it = includeonlys_.begin();
2492 for (; it != includeonlys_.end() ; ++it) {
2493 bp_.addIncludedChildren(*it);
2496 bp_.maintain_unincluded_children =
2497 masterChildModule->maintainAuxCB->isChecked();
2500 bp_.float_placement = floatModule->get();
2503 // text should have passed validation
2504 bp_.listings_params =
2505 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2508 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
2509 outputModule->defaultFormatCO->currentIndex()).toString());
2511 bool const nontexfonts = fontModule->osFontsCB->isChecked();
2512 bp_.useNonTeXFonts = nontexfonts;
2514 bp_.output_sync = outputModule->outputsyncCB->isChecked();
2515 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2517 int mathfmt = outputModule->mathoutCB->currentIndex();
2520 BufferParams::MathOutput const mo =
2521 static_cast<BufferParams::MathOutput>(mathfmt);
2522 bp_.html_math_output = mo;
2523 bp_.html_be_strict = outputModule->strictCB->isChecked();
2524 bp_.html_math_img_scale = outputModule->mathimgSB->value();
2528 fromqstr(fontModule->fontsRomanCO->
2529 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
2532 fromqstr(fontModule->fontsSansCO->
2533 itemData(fontModule->fontsSansCO->currentIndex()).toString());
2535 bp_.fonts_typewriter =
2536 fromqstr(fontModule->fontsTypewriterCO->
2537 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
2539 if (fontModule->fontencCO->currentIndex() == 0)
2540 bp_.fontenc = "global";
2541 else if (fontModule->fontencCO->currentIndex() == 1)
2542 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2543 else if (fontModule->fontencCO->currentIndex() == 2)
2544 bp_.fontenc = "default";
2547 fromqstr(fontModule->cjkFontLE->text());
2549 bp_.fonts_sans_scale = fontModule->scaleSansSB->value();
2551 bp_.fonts_typewriter_scale = fontModule->scaleTypewriterSB->value();
2553 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
2555 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
2558 bp_.fonts_default_family = "default";
2560 bp_.fonts_default_family = GuiDocument::fontfamilies[
2561 fontModule->fontsDefaultCO->currentIndex()];
2563 if (fontModule->fontsizeCO->currentIndex() == 0)
2564 bp_.fontsize = "default";
2567 fromqstr(fontModule->fontsizeCO->currentText());
2570 bp_.papersize = PAPER_SIZE(
2571 pageLayoutModule->papersizeCO->currentIndex());
2573 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2574 pageLayoutModule->paperwidthUnitCO);
2576 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2577 pageLayoutModule->paperheightUnitCO);
2579 if (pageLayoutModule->facingPagesCB->isChecked())
2580 bp_.sides = TwoSides;
2582 bp_.sides = OneSide;
2584 if (pageLayoutModule->landscapeRB->isChecked())
2585 bp_.orientation = ORIENTATION_LANDSCAPE;
2587 bp_.orientation = ORIENTATION_PORTRAIT;
2590 bp_.use_geometry = !marginsModule->marginCB->isChecked();
2592 Ui::MarginsUi const * m = marginsModule;
2594 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2595 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2596 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2597 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2598 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2599 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2600 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2601 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2604 branchesModule->apply(bp_);
2607 PDFOptions & pdf = bp_.pdfoptions();
2608 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2609 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2610 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2611 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2612 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2614 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2615 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2616 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2617 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2619 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2620 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2621 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2622 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2624 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2625 if (pdfSupportModule->fullscreenCB->isChecked())
2626 pdf.pagemode = pdf.pagemode_fullscreen;
2628 pdf.pagemode.clear();
2629 pdf.quoted_options = pdf.quoted_options_check(
2630 fromqstr(pdfSupportModule->optionsLE->text()));
2634 void GuiDocument::paramsToDialog()
2636 // set the default unit
2637 Length::UNIT const default_unit = Length::defaultUnit();
2640 preambleModule->update(bp_, id());
2641 localLayout->update(bp_, id());
2644 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2645 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
2648 biblioModule->citeDefaultRB->setChecked(
2649 bp_.citeEngine() == ENGINE_BASIC);
2651 biblioModule->citeNatbibRB->setChecked(
2652 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
2653 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
2655 biblioModule->citeStyleCO->setCurrentIndex(
2656 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
2658 biblioModule->citeJurabibRB->setChecked(
2659 bp_.citeEngine() == ENGINE_JURABIB);
2661 biblioModule->bibtopicCB->setChecked(
2666 split(bp_.bibtex_command, command, ' ');
2668 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2670 biblioModule->bibtexCO->setCurrentIndex(bpos);
2671 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
2673 // We reset to default if we do not know the specified compiler
2674 // This is for security reasons
2675 biblioModule->bibtexCO->setCurrentIndex(
2676 biblioModule->bibtexCO->findData(toqstr("default")));
2677 biblioModule->bibtexOptionsLE->clear();
2679 biblioModule->bibtexOptionsLE->setEnabled(
2680 biblioModule->bibtexCO->currentIndex() != 0);
2683 indicesModule->update(bp_);
2685 // language & quotes
2686 int const pos = langModule->languageCO->findData(toqstr(
2687 bp_.language->lang()));
2688 langModule->languageCO->setCurrentIndex(pos);
2690 langModule->quoteStyleCO->setCurrentIndex(
2691 bp_.quotes_language);
2693 bool default_enc = true;
2694 if (bp_.inputenc != "auto") {
2695 default_enc = false;
2696 if (bp_.inputenc == "default") {
2697 langModule->encodingCO->setCurrentIndex(0);
2700 Encodings::const_iterator it = encodings.begin();
2701 Encodings::const_iterator const end = encodings.end();
2702 for (; it != end; ++it) {
2703 if (it->latexName() == bp_.inputenc) {
2704 enc_gui = it->guiName();
2708 int const i = langModule->encodingCO->findText(
2711 langModule->encodingCO->setCurrentIndex(i);
2713 // unknown encoding. Set to default.
2717 langModule->defaultencodingRB->setChecked(default_enc);
2718 langModule->otherencodingRB->setChecked(!default_enc);
2720 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
2722 langModule->languagePackageCO->setCurrentIndex(
2723 langModule->languagePackageCO->findData("custom"));
2724 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
2726 langModule->languagePackageCO->setCurrentIndex(p);
2727 langModule->languagePackageLE->clear();
2731 if (bp_.isfontcolor) {
2732 colorModule->fontColorPB->setStyleSheet(
2733 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2735 set_fontcolor = bp_.fontcolor;
2736 is_fontcolor = bp_.isfontcolor;
2738 colorModule->noteFontColorPB->setStyleSheet(
2739 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2740 set_notefontcolor = bp_.notefontcolor;
2742 if (bp_.isbackgroundcolor) {
2743 colorModule->backgroundPB->setStyleSheet(
2744 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2746 set_backgroundcolor = bp_.backgroundcolor;
2747 is_backgroundcolor = bp_.isbackgroundcolor;
2749 colorModule->boxBackgroundPB->setStyleSheet(
2750 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
2751 set_boxbgcolor = bp_.boxbgcolor;
2754 int const min_toclevel = documentClass().min_toclevel();
2755 int const max_toclevel = documentClass().max_toclevel();
2756 if (documentClass().hasTocLevels()) {
2757 numberingModule->setEnabled(true);
2758 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2759 numberingModule->depthSL->setMaximum(max_toclevel);
2760 numberingModule->depthSL->setValue(bp_.secnumdepth);
2761 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2762 numberingModule->tocSL->setMaximum(max_toclevel);
2763 numberingModule->tocSL->setValue(bp_.tocdepth);
2766 numberingModule->setEnabled(false);
2767 numberingModule->tocTW->clear();
2771 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2772 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2773 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2774 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2775 bulletsModule->init();
2778 int nitem = findToken(tex_graphics, bp_.graphics_driver);
2780 latexModule->psdriverCO->setCurrentIndex(nitem);
2783 mathsModule->amsCB->setChecked(
2784 bp_.use_amsmath == BufferParams::package_on);
2785 mathsModule->amsautoCB->setChecked(
2786 bp_.use_amsmath == BufferParams::package_auto);
2788 mathsModule->esintCB->setChecked(
2789 bp_.use_esint == BufferParams::package_on);
2790 mathsModule->esintautoCB->setChecked(
2791 bp_.use_esint == BufferParams::package_auto);
2793 mathsModule->mhchemCB->setChecked(
2794 bp_.use_mhchem == BufferParams::package_on);
2795 mathsModule->mhchemautoCB->setChecked(
2796 bp_.use_mhchem == BufferParams::package_auto);
2798 mathsModule->mathdotsCB->setChecked(
2799 bp_.use_mathdots == BufferParams::package_on);
2800 mathsModule->mathdotsautoCB->setChecked(
2801 bp_.use_mathdots == BufferParams::package_auto);
2803 mathsModule->undertildeCB->setChecked(
2804 bp_.use_undertilde == BufferParams::package_on);
2805 mathsModule->undertildeautoCB->setChecked(
2806 bp_.use_undertilde == BufferParams::package_auto);
2808 switch (bp_.spacing().getSpace()) {
2809 case Spacing::Other: nitem = 3; break;
2810 case Spacing::Double: nitem = 2; break;
2811 case Spacing::Onehalf: nitem = 1; break;
2812 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2816 string const & layoutID = bp_.baseClassID();
2817 setLayoutComboByIDString(layoutID);
2819 updatePagestyle(documentClass().opt_pagestyle(),
2822 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2823 if (bp_.spacing().getSpace() == Spacing::Other) {
2824 doubleToWidget(textLayoutModule->lspacingLE,
2825 bp_.spacing().getValueAsString());
2829 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2830 textLayoutModule->indentRB->setChecked(true);
2831 string indentation = bp_.getIndentation().asLyXCommand();
2833 if (indentation != "default") {
2834 lengthToWidgets(textLayoutModule->indentLE,
2835 textLayoutModule->indentLengthCO,
2836 indentation, default_unit);
2839 textLayoutModule->indentCO->setCurrentIndex(indent);
2842 textLayoutModule->skipRB->setChecked(true);
2844 switch (bp_.getDefSkip().kind()) {
2845 case VSpace::SMALLSKIP:
2848 case VSpace::MEDSKIP:
2851 case VSpace::BIGSKIP:
2854 case VSpace::LENGTH:
2857 string const length = bp_.getDefSkip().asLyXCommand();
2858 lengthToWidgets(textLayoutModule->skipLE,
2859 textLayoutModule->skipLengthCO,
2860 length, default_unit);
2867 textLayoutModule->skipCO->setCurrentIndex(skip);
2871 textLayoutModule->twoColumnCB->setChecked(
2874 if (!bp_.options.empty()) {
2875 latexModule->optionsLE->setText(
2876 toqstr(bp_.options));
2878 latexModule->optionsLE->setText(QString());
2882 latexModule->defaultOptionsCB->setChecked(
2883 bp_.use_default_options);
2884 updateSelectedModules();
2885 selectionManager->updateProvidedModules(
2886 bp_.baseClass()->providedModules());
2887 selectionManager->updateExcludedModules(
2888 bp_.baseClass()->excludedModules());
2890 if (!documentClass().options().empty()) {
2891 latexModule->defaultOptionsLE->setText(
2892 toqstr(documentClass().options()));
2894 latexModule->defaultOptionsLE->setText(
2895 toqstr(_("[No options predefined]")));
2898 latexModule->defaultOptionsLE->setEnabled(
2899 bp_.use_default_options
2900 && !documentClass().options().empty());
2902 latexModule->defaultOptionsCB->setEnabled(
2903 !documentClass().options().empty());
2905 if (!bp_.master.empty()) {
2906 latexModule->childDocGB->setChecked(true);
2907 latexModule->childDocLE->setText(
2908 toqstr(bp_.master));
2910 latexModule->childDocLE->setText(QString());
2911 latexModule->childDocGB->setChecked(false);
2915 if (!bufferview() || !buffer().hasChildren()) {
2916 masterChildModule->childrenTW->clear();
2917 includeonlys_.clear();
2918 docPS->showPanel(qt_("Child Documents"), false);
2919 if (docPS->isCurrentPanel(qt_("Child Documents")))
2920 docPS->setCurrentPanel(qt_("Document Class"));
2922 docPS->showPanel(qt_("Child Documents"), true);
2923 masterChildModule->setEnabled(true);
2924 includeonlys_ = bp_.getIncludedChildren();
2925 updateIncludeonlys();
2927 masterChildModule->maintainAuxCB->setChecked(
2928 bp_.maintain_unincluded_children);
2931 floatModule->set(bp_.float_placement);
2934 // break listings_params to multiple lines
2936 InsetListingsParams(bp_.listings_params).separatedParams();
2937 listingsModule->listingsED->setPlainText(toqstr(lstparams));
2940 // update combobox with formats
2941 updateDefaultFormat();
2942 int index = outputModule->defaultFormatCO->findData(toqstr(
2943 bp_.default_output_format));
2944 // set to default if format is not found
2947 outputModule->defaultFormatCO->setCurrentIndex(index);
2948 bool const os_fonts_available =
2949 bp_.baseClass()->outputType() == lyx::LATEX
2950 && LaTeXFeatures::isAvailable("fontspec");
2951 fontModule->osFontsCB->setEnabled(os_fonts_available);
2952 fontModule->osFontsCB->setChecked(
2953 os_fonts_available && bp_.useNonTeXFonts);
2955 outputModule->outputsyncCB->setChecked(bp_.output_sync);
2956 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
2958 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
2959 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
2960 outputModule->strictCB->setChecked(bp_.html_be_strict);
2963 updateFontsize(documentClass().opt_fontsize(),
2966 QString font = toqstr(bp_.fonts_roman);
2967 int rpos = fontModule->fontsRomanCO->findData(font);
2969 rpos = fontModule->fontsRomanCO->count();
2970 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
2972 fontModule->fontsRomanCO->setCurrentIndex(rpos);
2974 font = toqstr(bp_.fonts_sans);
2975 int spos = fontModule->fontsSansCO->findData(font);
2977 spos = fontModule->fontsSansCO->count();
2978 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
2980 fontModule->fontsSansCO->setCurrentIndex(spos);
2982 font = toqstr(bp_.fonts_typewriter);
2983 int tpos = fontModule->fontsTypewriterCO->findData(font);
2985 tpos = fontModule->fontsTypewriterCO->count();
2986 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
2988 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
2990 if (bp_.useNonTeXFonts && os_fonts_available) {
2991 fontModule->fontencLA->setEnabled(false);
2992 fontModule->fontencCO->setEnabled(false);
2993 fontModule->fontencLE->setEnabled(false);
2995 fontModule->fontencLA->setEnabled(true);
2996 fontModule->fontencCO->setEnabled(true);
2997 fontModule->fontencLE->setEnabled(true);
3003 if (!bp_.fonts_cjk.empty())
3004 fontModule->cjkFontLE->setText(
3005 toqstr(bp_.fonts_cjk));
3007 fontModule->cjkFontLE->setText(QString());
3009 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3010 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3011 fontModule->scaleSansSB->setValue(bp_.fonts_sans_scale);
3012 fontModule->scaleTypewriterSB->setValue(bp_.fonts_typewriter_scale);
3014 int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3016 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3018 if (bp_.fontenc == "global") {
3019 fontModule->fontencCO->setCurrentIndex(0);
3020 fontModule->fontencLE->setEnabled(false);
3021 } else if (bp_.fontenc == "default") {
3022 fontModule->fontencCO->setCurrentIndex(2);
3023 fontModule->fontencLE->setEnabled(false);
3025 fontModule->fontencCO->setCurrentIndex(1);
3026 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3030 bool const extern_geometry =
3031 documentClass().provides("geometry");
3032 int const psize = bp_.papersize;
3033 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3034 setCustomPapersize(!extern_geometry && psize == 1);
3035 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3037 bool const landscape =
3038 bp_.orientation == ORIENTATION_LANDSCAPE;
3039 pageLayoutModule->landscapeRB->setChecked(landscape);
3040 pageLayoutModule->portraitRB->setChecked(!landscape);
3041 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3042 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3044 pageLayoutModule->facingPagesCB->setChecked(
3045 bp_.sides == TwoSides);
3047 lengthToWidgets(pageLayoutModule->paperwidthLE,
3048 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3049 lengthToWidgets(pageLayoutModule->paperheightLE,
3050 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3053 Ui::MarginsUi * m = marginsModule;
3057 lengthToWidgets(m->topLE, m->topUnit,
3058 bp_.topmargin, default_unit);
3060 lengthToWidgets(m->bottomLE, m->bottomUnit,
3061 bp_.bottommargin, default_unit);
3063 lengthToWidgets(m->innerLE, m->innerUnit,
3064 bp_.leftmargin, default_unit);
3066 lengthToWidgets(m->outerLE, m->outerUnit,
3067 bp_.rightmargin, default_unit);
3069 lengthToWidgets(m->headheightLE, m->headheightUnit,
3070 bp_.headheight, default_unit);
3072 lengthToWidgets(m->headsepLE, m->headsepUnit,
3073 bp_.headsep, default_unit);
3075 lengthToWidgets(m->footskipLE, m->footskipUnit,
3076 bp_.footskip, default_unit);
3078 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3079 bp_.columnsep, default_unit);
3082 updateUnknownBranches();
3083 branchesModule->update(bp_);
3086 PDFOptions const & pdf = bp_.pdfoptions();
3087 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3088 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3089 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3090 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3091 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3093 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3094 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3095 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3097 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3099 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3100 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3101 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3102 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3104 nn = findToken(backref_opts, pdf.backref);
3106 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3108 pdfSupportModule->fullscreenCB->setChecked
3109 (pdf.pagemode == pdf.pagemode_fullscreen);
3111 pdfSupportModule->optionsLE->setText(
3112 toqstr(pdf.quoted_options));
3114 // Make sure that the bc is in the INITIAL state
3115 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3118 // clear changed branches cache
3119 changedBranches_.clear();
3123 void GuiDocument::saveDocDefault()
3125 // we have to apply the params first
3131 void GuiDocument::updateAvailableModules()
3133 modules_av_model_.clear();
3134 list<modInfoStruct> const & modInfoList = getModuleInfo();
3135 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3136 list<modInfoStruct>::const_iterator men = modInfoList.end();
3137 for (int i = 0; mit != men; ++mit, ++i)
3138 modules_av_model_.insertRow(i, mit->name, mit->id,
3143 void GuiDocument::updateSelectedModules()
3145 modules_sel_model_.clear();
3146 list<modInfoStruct> const selModList = getSelectedModules();
3147 list<modInfoStruct>::const_iterator mit = selModList.begin();
3148 list<modInfoStruct>::const_iterator men = selModList.end();
3149 for (int i = 0; mit != men; ++mit, ++i)
3150 modules_sel_model_.insertRow(i, mit->name, mit->id,
3155 void GuiDocument::updateIncludeonlys()
3157 masterChildModule->childrenTW->clear();
3158 QString const no = qt_("No");
3159 QString const yes = qt_("Yes");
3161 if (includeonlys_.empty()) {
3162 masterChildModule->includeallRB->setChecked(true);
3163 masterChildModule->childrenTW->setEnabled(false);
3164 masterChildModule->maintainAuxCB->setEnabled(false);
3166 masterChildModule->includeonlyRB->setChecked(true);
3167 masterChildModule->childrenTW->setEnabled(true);
3168 masterChildModule->maintainAuxCB->setEnabled(true);
3170 QTreeWidgetItem * item = 0;
3171 ListOfBuffers children = buffer().getChildren();
3172 ListOfBuffers::const_iterator it = children.begin();
3173 ListOfBuffers::const_iterator end = children.end();
3174 bool has_unincluded = false;
3175 bool all_unincluded = true;
3176 for (; it != end; ++it) {
3177 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3180 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3181 from_utf8(buffer().filePath())));
3182 item->setText(0, toqstr(name));
3183 item->setText(1, isChildIncluded(name) ? yes : no);
3184 if (!isChildIncluded(name))
3185 has_unincluded = true;
3187 all_unincluded = false;
3189 // Both if all childs are included and if none is included
3190 // is equal to "include all" (i.e., ommit \includeonly).
3191 // Thus, reset the GUI.
3192 if (!has_unincluded || all_unincluded) {
3193 masterChildModule->includeallRB->setChecked(true);
3194 masterChildModule->childrenTW->setEnabled(false);
3195 includeonlys_.clear();
3197 // If all are included, we need to update again.
3198 if (!has_unincluded)
3199 updateIncludeonlys();
3203 void GuiDocument::updateContents()
3205 // Nothing to do here as the document settings is not cursor dependant.
3210 void GuiDocument::useClassDefaults()
3212 if (applyPB->isEnabled()) {
3213 int const ret = Alert::prompt(_("Unapplied changes"),
3214 _("Some changes in the dialog were not yet applied.\n"
3215 "If you do not apply now, they will be lost after this action."),
3216 1, 1, _("&Apply"), _("&Dismiss"));
3221 int idx = latexModule->classCO->currentIndex();
3222 string const classname = classes_model_.getIDString(idx);
3223 if (!bp_.setBaseClass(classname)) {
3224 Alert::error(_("Error"), _("Unable to set document class."));
3227 bp_.useClassDefaults();
3232 void GuiDocument::setLayoutComboByIDString(string const & idString)
3234 int idx = classes_model_.findIDString(idString);
3236 Alert::warning(_("Can't set layout!"),
3237 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3239 latexModule->classCO->setCurrentIndex(idx);
3243 bool GuiDocument::isValid()
3246 validateListingsParameters().isEmpty() &&
3247 localLayout->isValid() &&
3249 // if we're asking for skips between paragraphs
3250 !textLayoutModule->skipRB->isChecked() ||
3251 // then either we haven't chosen custom
3252 textLayoutModule->skipCO->currentIndex() != 3 ||
3253 // or else a length has been given
3254 !textLayoutModule->skipLE->text().isEmpty()
3257 // if we're asking for indentation
3258 !textLayoutModule->indentRB->isChecked() ||
3259 // then either we haven't chosen custom
3260 textLayoutModule->indentCO->currentIndex() != 1 ||
3261 // or else a length has been given
3262 !textLayoutModule->indentLE->text().isEmpty()
3267 char const * const GuiDocument::fontfamilies[5] = {
3268 "default", "rmdefault", "sfdefault", "ttdefault", ""
3272 char const * GuiDocument::fontfamilies_gui[5] = {
3273 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3277 bool GuiDocument::initialiseParams(string const &)
3279 BufferView const * view = bufferview();
3281 bp_ = BufferParams();
3285 bp_ = view->buffer().params();
3287 updateAvailableModules();
3288 //FIXME It'd be nice to make sure here that the selected
3289 //modules are consistent: That required modules are actually
3290 //selected, and that we don't have conflicts. If so, we could
3291 //at least pop up a warning.
3297 void GuiDocument::clearParams()
3299 bp_ = BufferParams();
3303 BufferId GuiDocument::id() const
3305 BufferView const * const view = bufferview();
3306 return view? &view->buffer() : 0;
3310 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3312 return moduleNames_;
3316 list<GuiDocument::modInfoStruct> const
3317 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3319 LayoutModuleList::const_iterator it = mods.begin();
3320 LayoutModuleList::const_iterator end = mods.end();
3321 list<modInfoStruct> mInfo;
3322 for (; it != end; ++it) {
3325 LyXModule const * const mod = theModuleList[*it];
3328 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3330 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3337 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3339 return makeModuleInfo(params().getModules());
3343 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3345 return makeModuleInfo(params().baseClass()->providedModules());
3349 DocumentClass const & GuiDocument::documentClass() const
3351 return bp_.documentClass();
3355 static void dispatch_bufferparams(Dialog const & dialog,
3356 BufferParams const & bp, FuncCode lfun)
3359 ss << "\\begin_header\n";
3361 ss << "\\end_header\n";
3362 dialog.dispatch(FuncRequest(lfun, ss.str()));
3366 void GuiDocument::dispatchParams()
3368 // This must come first so that a language change is correctly noticed
3371 // Apply the BufferParams. Note that this will set the base class
3372 // and then update the buffer's layout.
3373 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3375 if (!params().master.empty()) {
3376 FileName const master_file = support::makeAbsPath(params().master,
3377 support::onlyPath(buffer().absFileName()));
3378 if (isLyXFileName(master_file.absFileName())) {
3379 Buffer * master = checkAndLoadLyXFile(master_file);
3381 if (master->isChild(const_cast<Buffer *>(&buffer())))
3382 const_cast<Buffer &>(buffer()).setParent(master);
3384 Alert::warning(_("Assigned master does not include this file"),
3385 bformat(_("You must include this file in the document\n"
3386 "'%1$s' in order to use the master document\n"
3387 "feature."), from_utf8(params().master)));
3389 Alert::warning(_("Could not load master"),
3390 bformat(_("The master document '%1$s'\n"
3391 "could not be loaded."),
3392 from_utf8(params().master)));
3396 // Generate the colours requested by each new branch.
3397 BranchList & branchlist = params().branchlist();
3398 if (!branchlist.empty()) {
3399 BranchList::const_iterator it = branchlist.begin();
3400 BranchList::const_iterator const end = branchlist.end();
3401 for (; it != end; ++it) {
3402 docstring const & current_branch = it->branch();
3403 Branch const * branch = branchlist.find(current_branch);
3404 string const x11hexname = X11hexname(branch->color());
3405 // display the new color
3406 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3407 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3410 // Open insets of selected branches, close deselected ones
3411 dispatch(FuncRequest(LFUN_INSET_FORALL,
3412 "Branch inset-toggle assign"));
3414 // rename branches in the document
3415 executeBranchRenaming();
3416 // and clear changed branches cache
3417 changedBranches_.clear();
3419 // Generate the colours requested by indices.
3420 IndicesList & indiceslist = params().indiceslist();
3421 if (!indiceslist.empty()) {
3422 IndicesList::const_iterator it = indiceslist.begin();
3423 IndicesList::const_iterator const end = indiceslist.end();
3424 for (; it != end; ++it) {
3425 docstring const & current_index = it->shortcut();
3426 Index const * index = indiceslist.findShortcut(current_index);
3427 string const x11hexname = X11hexname(index->color());
3428 // display the new color
3429 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3430 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3434 // If we used an LFUN, we would not need these two lines:
3435 BufferView * bv = const_cast<BufferView *>(bufferview());
3436 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3440 void GuiDocument::setLanguage() const
3442 Language const * const newL = bp_.language;
3443 if (buffer().params().language == newL)
3446 string const & lang_name = newL->lang();
3447 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3451 void GuiDocument::saveAsDefault() const
3453 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3457 bool GuiDocument::isFontAvailable(string const & font) const
3459 if (font == "default" || font == "cmr"
3460 || font == "cmss" || font == "cmtt")
3461 // these are standard
3463 if (font == "lmodern" || font == "lmss" || font == "lmtt")
3464 return LaTeXFeatures::isAvailable("lmodern");
3465 if (font == "times" || font == "palatino"
3466 || font == "helvet" || font == "courier")
3467 return LaTeXFeatures::isAvailable("psnfss");
3468 if (font == "cmbr" || font == "cmtl")
3469 return LaTeXFeatures::isAvailable("cmbright");
3470 if (font == "utopia")
3471 return LaTeXFeatures::isAvailable("utopia")
3472 || LaTeXFeatures::isAvailable("fourier");
3473 if (font == "beraserif" || font == "berasans"
3474 || font == "beramono")
3475 return LaTeXFeatures::isAvailable("bera");
3476 return LaTeXFeatures::isAvailable(font);
3480 bool GuiDocument::providesOSF(string const & font) const
3482 if (fontModule->osFontsCB->isChecked())
3483 // FIXME: we should check if the fonts really
3484 // have OSF support. But how?
3487 return isFontAvailable("eco");
3488 if (font == "palatino")
3489 return isFontAvailable("mathpazo");
3494 bool GuiDocument::providesSC(string const & font) const
3496 if (fontModule->osFontsCB->isChecked())
3498 if (font == "palatino")
3499 return isFontAvailable("mathpazo");
3500 if (font == "utopia")
3501 return isFontAvailable("fourier");
3506 bool GuiDocument::providesScale(string const & font) const
3508 if (fontModule->osFontsCB->isChecked())
3510 return font == "helvet" || font == "luximono"
3511 || font == "berasans" || font == "beramono";
3515 void GuiDocument::loadModuleInfo()
3517 moduleNames_.clear();
3518 LyXModuleList::const_iterator it = theModuleList.begin();
3519 LyXModuleList::const_iterator end = theModuleList.end();
3520 for (; it != end; ++it) {
3524 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3525 // this is supposed to give us the first sentence of the description
3528 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3529 int const pos = desc.indexOf(".");
3531 desc.truncate(pos + 1);
3532 m.description = desc;
3533 moduleNames_.push_back(m);
3538 void GuiDocument::updateUnknownBranches()
3542 list<docstring> used_branches;
3543 buffer().getUsedBranches(used_branches);
3544 list<docstring>::const_iterator it = used_branches.begin();
3545 QStringList unknown_branches;
3546 for (; it != used_branches.end() ; ++it) {
3547 if (!buffer().params().branchlist().find(*it))
3548 unknown_branches.append(toqstr(*it));
3550 branchesModule->setUnknownBranches(unknown_branches);
3554 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3556 map<docstring, docstring>::iterator it = changedBranches_.begin();
3557 for (; it != changedBranches_.end() ; ++it) {
3558 if (it->second == oldname) {
3559 // branch has already been renamed
3560 it->second = newname;
3565 changedBranches_[oldname] = newname;
3569 void GuiDocument::executeBranchRenaming() const
3571 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3572 for (; it != changedBranches_.end() ; ++it) {
3573 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3574 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3579 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3582 } // namespace frontend
3585 #include "moc_GuiDocument.cpp"