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()));
543 void LocalLayout::update(BufferParams const & params, BufferId id)
545 QString layout = toqstr(params.local_layout);
546 // Nothing to do if the params and preamble are unchanged.
547 if (id == current_id_
548 && layout == locallayoutTE->document()->toPlainText())
551 // Save the params address for further use.
553 locallayoutTE->document()->setPlainText(layout);
558 void LocalLayout::apply(BufferParams & params)
560 string const layout = fromqstr(locallayoutTE->document()->toPlainText());
561 params.local_layout = layout;
565 void LocalLayout::textChanged()
567 static const QString unknown = qt_("Press button to check validity...");
570 infoLB->setText(unknown);
571 validatePB->setEnabled(true);
576 void LocalLayout::validate() {
577 static const QString valid = qt_("Layout is valid!");
578 static const QString vtext =
579 toqstr("<p style=\"font-weight: bold; \">")
580 + valid + toqstr("</p>");
581 static const QString invalid = qt_("Layout is invalid!");
582 static const QString ivtext =
583 toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
584 + invalid + toqstr("</p>");
586 string const layout = fromqstr(locallayoutTE->document()->toPlainText());
590 is_valid_ = TextClass::validate(layout);
591 infoLB->setText(is_valid_ ? vtext : ivtext);
592 validatePB->setEnabled(false);
596 void LocalLayout::validatePressed() {
602 /////////////////////////////////////////////////////////////////////
606 /////////////////////////////////////////////////////////////////////
609 GuiDocument::GuiDocument(GuiView & lv)
610 : GuiDialog(lv, "document", qt_("Document Settings"))
614 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
615 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
616 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
617 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
619 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
620 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
622 // Manage the restore, ok, apply, restore and cancel/close buttons
623 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
625 bc().setApply(applyPB);
626 bc().setCancel(closePB);
627 bc().setRestore(restorePB);
631 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
632 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
633 this, SLOT(change_adaptor()));
634 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
635 this, SLOT(setLSpacing(int)));
636 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
637 this, SLOT(change_adaptor()));
639 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
640 this, SLOT(change_adaptor()));
641 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
642 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
643 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
644 this, SLOT(change_adaptor()));
645 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
646 this, SLOT(setIndent(int)));
647 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
648 this, SLOT(change_adaptor()));
649 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
650 this, SLOT(change_adaptor()));
652 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
653 this, SLOT(change_adaptor()));
654 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
655 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
656 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
657 this, SLOT(change_adaptor()));
658 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
659 this, SLOT(setSkip(int)));
660 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
661 this, SLOT(change_adaptor()));
662 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
663 this, SLOT(change_adaptor()));
665 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
666 this, SLOT(enableIndent(bool)));
667 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
668 this, SLOT(enableSkip(bool)));
670 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
671 this, SLOT(change_adaptor()));
672 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
673 this, SLOT(setColSep()));
675 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
676 textLayoutModule->lspacingLE));
677 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
678 textLayoutModule->indentLE));
679 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
680 textLayoutModule->skipLE));
682 textLayoutModule->indentCO->addItem(qt_("Default"));
683 textLayoutModule->indentCO->addItem(qt_("Custom"));
684 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
685 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
686 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
687 textLayoutModule->skipCO->addItem(qt_("Custom"));
688 textLayoutModule->lspacingCO->insertItem(
689 Spacing::Single, qt_("Single"));
690 textLayoutModule->lspacingCO->insertItem(
691 Spacing::Onehalf, qt_("OneHalf"));
692 textLayoutModule->lspacingCO->insertItem(
693 Spacing::Double, qt_("Double"));
694 textLayoutModule->lspacingCO->insertItem(
695 Spacing::Other, qt_("Custom"));
696 // initialize the length validator
697 bc().addCheckedLineEdit(textLayoutModule->indentLE);
698 bc().addCheckedLineEdit(textLayoutModule->skipLE);
701 // master/child handling
702 masterChildModule = new UiWidget<Ui::MasterChildUi>;
704 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
705 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
706 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
707 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
708 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
709 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
710 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
711 this, SLOT(change_adaptor()));
712 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
713 this, SLOT(change_adaptor()));
714 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
715 this, SLOT(change_adaptor()));
716 masterChildModule->childrenTW->setColumnCount(2);
717 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
718 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
719 masterChildModule->childrenTW->resizeColumnToContents(1);
720 masterChildModule->childrenTW->resizeColumnToContents(2);
724 outputModule = new UiWidget<Ui::OutputUi>;
726 connect(outputModule->xetexCB, SIGNAL(clicked()),
727 this, SLOT(change_adaptor()));
728 connect(outputModule->xetexCB, SIGNAL(toggled(bool)),
729 this, SLOT(xetexChanged(bool)));
730 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
731 this, SLOT(change_adaptor()));
732 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
733 this, SLOT(change_adaptor()));
734 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
735 this, SLOT(change_adaptor()));
736 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
737 this, SLOT(change_adaptor()));
739 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
740 this, SLOT(change_adaptor()));
741 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
742 this, SLOT(change_adaptor()));
743 outputModule->synccustomCB->addItem("");
744 outputModule->synccustomCB->addItem("\\synctex=1");
745 outputModule->synccustomCB->addItem("\\synctex=-1");
746 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
749 fontModule = new UiWidget<Ui::FontUi>;
750 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
751 this, SLOT(change_adaptor()));
752 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
753 this, SLOT(romanChanged(int)));
754 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
755 this, SLOT(change_adaptor()));
756 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
757 this, SLOT(sansChanged(int)));
758 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
759 this, SLOT(change_adaptor()));
760 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
761 this, SLOT(ttChanged(int)));
762 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
763 this, SLOT(change_adaptor()));
764 connect(fontModule->fontencCO, SIGNAL(activated(int)),
765 this, SLOT(change_adaptor()));
766 connect(fontModule->fontencCO, SIGNAL(activated(int)),
767 this, SLOT(fontencChanged(int)));
768 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
769 this, SLOT(change_adaptor()));
770 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
771 this, SLOT(change_adaptor()));
772 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
773 this, SLOT(change_adaptor()));
774 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
775 this, SLOT(change_adaptor()));
776 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
777 this, SLOT(change_adaptor()));
778 connect(fontModule->fontScCB, SIGNAL(clicked()),
779 this, SLOT(change_adaptor()));
780 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
781 this, SLOT(change_adaptor()));
785 fontModule->fontsizeCO->addItem(qt_("Default"));
786 fontModule->fontsizeCO->addItem(qt_("10"));
787 fontModule->fontsizeCO->addItem(qt_("11"));
788 fontModule->fontsizeCO->addItem(qt_("12"));
790 fontModule->fontencCO->addItem(qt_("Default"));
791 fontModule->fontencCO->addItem(qt_("Custom"));
792 fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
794 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
795 fontModule->fontsDefaultCO->addItem(
796 qt_(GuiDocument::fontfamilies_gui[n]));
800 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
801 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
802 this, SLOT(papersizeChanged(int)));
803 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
804 this, SLOT(papersizeChanged(int)));
805 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
806 this, SLOT(change_adaptor()));
807 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
808 this, SLOT(change_adaptor()));
809 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
810 this, SLOT(change_adaptor()));
811 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
812 this, SLOT(change_adaptor()));
813 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
814 this, SLOT(change_adaptor()));
815 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
816 this, SLOT(change_adaptor()));
817 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
818 this, SLOT(change_adaptor()));
819 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
820 this, SLOT(change_adaptor()));
821 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
822 this, SLOT(change_adaptor()));
823 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
824 this, SLOT(change_adaptor()));
826 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
827 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
828 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
829 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
830 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
831 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
832 pageLayoutModule->paperheightL);
833 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
834 pageLayoutModule->paperwidthL);
836 QComboBox * cb = pageLayoutModule->papersizeCO;
837 cb->addItem(qt_("Default"));
838 cb->addItem(qt_("Custom"));
839 cb->addItem(qt_("US letter"));
840 cb->addItem(qt_("US legal"));
841 cb->addItem(qt_("US executive"));
842 cb->addItem(qt_("A0"));
843 cb->addItem(qt_("A1"));
844 cb->addItem(qt_("A2"));
845 cb->addItem(qt_("A3"));
846 cb->addItem(qt_("A4"));
847 cb->addItem(qt_("A5"));
848 cb->addItem(qt_("A6"));
849 cb->addItem(qt_("B0"));
850 cb->addItem(qt_("B1"));
851 cb->addItem(qt_("B2"));
852 cb->addItem(qt_("B3"));
853 cb->addItem(qt_("B4"));
854 cb->addItem(qt_("B5"));
855 cb->addItem(qt_("B6"));
856 cb->addItem(qt_("C0"));
857 cb->addItem(qt_("C1"));
858 cb->addItem(qt_("C2"));
859 cb->addItem(qt_("C3"));
860 cb->addItem(qt_("C4"));
861 cb->addItem(qt_("C5"));
862 cb->addItem(qt_("C6"));
863 cb->addItem(qt_("JIS B0"));
864 cb->addItem(qt_("JIS B1"));
865 cb->addItem(qt_("JIS B2"));
866 cb->addItem(qt_("JIS B3"));
867 cb->addItem(qt_("JIS B4"));
868 cb->addItem(qt_("JIS B5"));
869 cb->addItem(qt_("JIS B6"));
870 // remove the %-items from the unit choice
871 pageLayoutModule->paperwidthUnitCO->noPercents();
872 pageLayoutModule->paperheightUnitCO->noPercents();
873 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
874 pageLayoutModule->paperheightLE));
875 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
876 pageLayoutModule->paperwidthLE));
880 marginsModule = new UiWidget<Ui::MarginsUi>;
881 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
882 this, SLOT(setCustomMargins(bool)));
883 connect(marginsModule->marginCB, SIGNAL(clicked()),
884 this, SLOT(change_adaptor()));
885 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
886 this, SLOT(change_adaptor()));
887 connect(marginsModule->topUnit, SIGNAL(activated(int)),
888 this, SLOT(change_adaptor()));
889 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
890 this, SLOT(change_adaptor()));
891 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
892 this, SLOT(change_adaptor()));
893 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
894 this, SLOT(change_adaptor()));
895 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
896 this, SLOT(change_adaptor()));
897 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
898 this, SLOT(change_adaptor()));
899 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
900 this, SLOT(change_adaptor()));
901 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
902 this, SLOT(change_adaptor()));
903 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
904 this, SLOT(change_adaptor()));
905 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
906 this, SLOT(change_adaptor()));
907 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
908 this, SLOT(change_adaptor()));
909 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
910 this, SLOT(change_adaptor()));
911 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
912 this, SLOT(change_adaptor()));
913 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
914 this, SLOT(change_adaptor()));
915 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
916 this, SLOT(change_adaptor()));
917 marginsModule->topLE->setValidator(unsignedLengthValidator(
918 marginsModule->topLE));
919 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
920 marginsModule->bottomLE));
921 marginsModule->innerLE->setValidator(unsignedLengthValidator(
922 marginsModule->innerLE));
923 marginsModule->outerLE->setValidator(unsignedLengthValidator(
924 marginsModule->outerLE));
925 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
926 marginsModule->headsepLE));
927 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
928 marginsModule->headheightLE));
929 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
930 marginsModule->footskipLE));
931 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
932 marginsModule->columnsepLE));
934 bc().addCheckedLineEdit(marginsModule->topLE,
935 marginsModule->topL);
936 bc().addCheckedLineEdit(marginsModule->bottomLE,
937 marginsModule->bottomL);
938 bc().addCheckedLineEdit(marginsModule->innerLE,
939 marginsModule->innerL);
940 bc().addCheckedLineEdit(marginsModule->outerLE,
941 marginsModule->outerL);
942 bc().addCheckedLineEdit(marginsModule->headsepLE,
943 marginsModule->headsepL);
944 bc().addCheckedLineEdit(marginsModule->headheightLE,
945 marginsModule->headheightL);
946 bc().addCheckedLineEdit(marginsModule->footskipLE,
947 marginsModule->footskipL);
948 bc().addCheckedLineEdit(marginsModule->columnsepLE,
949 marginsModule->columnsepL);
953 langModule = new UiWidget<Ui::LanguageUi>;
954 connect(langModule->languageCO, SIGNAL(activated(int)),
955 this, SLOT(change_adaptor()));
956 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
957 this, SLOT(change_adaptor()));
958 connect(langModule->otherencodingRB, SIGNAL(clicked()),
959 this, SLOT(change_adaptor()));
960 connect(langModule->encodingCO, SIGNAL(activated(int)),
961 this, SLOT(change_adaptor()));
962 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
963 this, SLOT(change_adaptor()));
965 QAbstractItemModel * language_model = guiApp->languageModel();
966 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
967 language_model->sort(0);
968 langModule->languageCO->setModel(language_model);
969 langModule->languageCO->setModelColumn(0);
971 // Always put the default encoding in the first position.
972 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
973 QStringList encodinglist;
974 Encodings::const_iterator it = encodings.begin();
975 Encodings::const_iterator const end = encodings.end();
976 for (; it != end; ++it)
977 encodinglist.append(qt_(it->guiName()));
979 langModule->encodingCO->addItems(encodinglist);
981 langModule->quoteStyleCO->addItem(qt_("``text''"));
982 langModule->quoteStyleCO->addItem(qt_("''text''"));
983 langModule->quoteStyleCO->addItem(qt_(",,text``"));
984 langModule->quoteStyleCO->addItem(qt_(",,text''"));
985 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
986 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
990 colorModule = new UiWidget<Ui::ColorUi>;
991 connect(colorModule->fontColorPB, SIGNAL(clicked()),
992 this, SLOT(changeFontColor()));
993 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
994 this, SLOT(deleteFontColor()));
995 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
996 this, SLOT(changeNoteFontColor()));
997 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
998 this, SLOT(deleteNoteFontColor()));
999 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1000 this, SLOT(changeBackgroundColor()));
1001 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1002 this, SLOT(deleteBackgroundColor()));
1003 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1004 this, SLOT(changeBoxBackgroundColor()));
1005 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1006 this, SLOT(deleteBoxBackgroundColor()));
1010 numberingModule = new UiWidget<Ui::NumberingUi>;
1011 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1012 this, SLOT(change_adaptor()));
1013 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1014 this, SLOT(change_adaptor()));
1015 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1016 this, SLOT(updateNumbering()));
1017 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1018 this, SLOT(updateNumbering()));
1019 numberingModule->tocTW->setColumnCount(3);
1020 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1021 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1022 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1026 biblioModule = new UiWidget<Ui::BiblioUi>;
1027 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1028 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1029 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1030 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1031 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1032 this, SLOT(change_adaptor()));
1033 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1034 this, SLOT(change_adaptor()));
1035 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1036 this, SLOT(change_adaptor()));
1037 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1038 this, SLOT(change_adaptor()));
1039 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1040 this, SLOT(change_adaptor()));
1041 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1042 this, SLOT(bibtexChanged(int)));
1043 connect(biblioModule->bibtexOptionsED, SIGNAL(textChanged(QString)),
1044 this, SLOT(change_adaptor()));
1046 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1047 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1048 biblioModule->citeStyleCO->setCurrentIndex(0);
1050 biblioModule->bibtexCO->clear();
1051 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1052 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1053 it != lyxrc.bibtex_alternatives.end(); ++it) {
1054 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1055 biblioModule->bibtexCO->addItem(command, command);
1060 indicesModule = new GuiIndices;
1061 connect(indicesModule, SIGNAL(changed()),
1062 this, SLOT(change_adaptor()));
1066 mathsModule = new UiWidget<Ui::MathsUi>;
1067 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
1068 mathsModule->amsCB, SLOT(setDisabled(bool)));
1069 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
1070 mathsModule->esintCB, SLOT(setDisabled(bool)));
1071 connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)),
1072 mathsModule->mhchemCB, SLOT(setDisabled(bool)));
1074 connect(mathsModule->amsCB, SIGNAL(clicked()),
1075 this, SLOT(change_adaptor()));
1076 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
1077 this, SLOT(change_adaptor()));
1078 connect(mathsModule->esintCB, SIGNAL(clicked()),
1079 this, SLOT(change_adaptor()));
1080 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
1081 this, SLOT(change_adaptor()));
1082 connect(mathsModule->mhchemCB, SIGNAL(clicked()),
1083 this, SLOT(change_adaptor()));
1084 connect(mathsModule->mhchemautoCB, SIGNAL(clicked()),
1085 this, SLOT(change_adaptor()));
1086 connect(mathsModule->mathdotsCB, SIGNAL(clicked()),
1087 this, SLOT(change_adaptor()));
1091 latexModule = new UiWidget<Ui::LaTeXUi>;
1092 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1093 this, SLOT(change_adaptor()));
1094 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1095 this, SLOT(change_adaptor()));
1096 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1097 this, SLOT(change_adaptor()));
1098 connect(latexModule->classCO, SIGNAL(activated(int)),
1099 this, SLOT(classChanged()));
1100 connect(latexModule->classCO, SIGNAL(activated(int)),
1101 this, SLOT(change_adaptor()));
1102 connect(latexModule->layoutPB, SIGNAL(clicked()),
1103 this, SLOT(browseLayout()));
1104 connect(latexModule->layoutPB, SIGNAL(clicked()),
1105 this, SLOT(change_adaptor()));
1106 connect(latexModule->childDocGB, SIGNAL(clicked()),
1107 this, SLOT(change_adaptor()));
1108 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1109 this, SLOT(change_adaptor()));
1110 connect(latexModule->childDocPB, SIGNAL(clicked()),
1111 this, SLOT(browseMaster()));
1112 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1113 this, SLOT(change_adaptor()));
1115 // postscript drivers
1116 for (int n = 0; tex_graphics[n][0]; ++n) {
1117 QString enc = qt_(tex_graphics_gui[n]);
1118 latexModule->psdriverCO->addItem(enc);
1121 latexModule->classCO->setModel(&classes_model_);
1122 LayoutFileList const & bcl = LayoutFileList::get();
1123 vector<LayoutFileIndex> classList = bcl.classList();
1124 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1126 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1127 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1128 for (int i = 0; cit != cen; ++cit, ++i) {
1129 LayoutFile const & tc = bcl[*cit];
1130 docstring item = (tc.isTeXClassAvailable()) ?
1131 from_utf8(tc.description()) :
1132 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1133 classes_model_.insertRow(i, toqstr(item), *cit);
1138 branchesModule = new GuiBranches;
1139 connect(branchesModule, SIGNAL(changed()),
1140 this, SLOT(change_adaptor()));
1141 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1142 this, SLOT(branchesRename(docstring const &, docstring const &)));
1143 updateUnknownBranches();
1147 preambleModule = new PreambleModule;
1148 connect(preambleModule, SIGNAL(changed()),
1149 this, SLOT(change_adaptor()));
1151 localLayout = new LocalLayout;
1152 connect(localLayout, SIGNAL(changed()),
1153 this, SLOT(change_adaptor()));
1157 bulletsModule = new BulletsModule;
1158 connect(bulletsModule, SIGNAL(changed()),
1159 this, SLOT(change_adaptor()));
1163 modulesModule = new UiWidget<Ui::ModulesUi>;
1164 modulesModule->availableLV->header()->setVisible(false);
1166 new ModuleSelectionManager(modulesModule->availableLV,
1167 modulesModule->selectedLV,
1168 modulesModule->addPB, modulesModule->deletePB,
1169 modulesModule->upPB, modulesModule->downPB,
1170 availableModel(), selectedModel(), this);
1171 connect(selectionManager, SIGNAL(updateHook()),
1172 this, SLOT(updateModuleInfo()));
1173 connect(selectionManager, SIGNAL(updateHook()),
1174 this, SLOT(change_adaptor()));
1175 connect(selectionManager, SIGNAL(selectionChanged()),
1176 this, SLOT(modulesChanged()));
1180 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1181 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1182 this, SLOT(change_adaptor()));
1183 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1184 this, SLOT(change_adaptor()));
1185 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1186 this, SLOT(change_adaptor()));
1187 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1188 this, SLOT(change_adaptor()));
1189 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1190 this, SLOT(change_adaptor()));
1191 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1192 this, SLOT(change_adaptor()));
1193 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1194 this, SLOT(change_adaptor()));
1195 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1196 this, SLOT(change_adaptor()));
1197 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1198 this, SLOT(change_adaptor()));
1199 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1200 this, SLOT(change_adaptor()));
1201 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1202 this, SLOT(change_adaptor()));
1203 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1204 this, SLOT(change_adaptor()));
1205 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1206 this, SLOT(change_adaptor()));
1207 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1208 this, SLOT(change_adaptor()));
1209 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1210 this, SLOT(change_adaptor()));
1211 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1212 this, SLOT(change_adaptor()));
1214 for (int i = 0; backref_opts[i][0]; ++i)
1215 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1219 floatModule = new FloatPlacement;
1220 connect(floatModule, SIGNAL(changed()),
1221 this, SLOT(change_adaptor()));
1225 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1226 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1227 this, SLOT(change_adaptor()));
1228 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1229 this, SLOT(change_adaptor()));
1230 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1231 this, SLOT(setListingsMessage()));
1232 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1233 this, SLOT(setListingsMessage()));
1234 listingsModule->listingsTB->setPlainText(
1235 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1239 docPS->addPanel(latexModule, qt_("Document Class"));
1240 docPS->addPanel(masterChildModule, qt_("Child Documents"));
1241 docPS->addPanel(modulesModule, qt_("Modules"));
1242 docPS->addPanel(fontModule, qt_("Fonts"));
1243 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1244 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1245 docPS->addPanel(marginsModule, qt_("Page Margins"));
1246 docPS->addPanel(langModule, qt_("Language"));
1247 docPS->addPanel(colorModule, qt_("Colors"));
1248 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1249 docPS->addPanel(biblioModule, qt_("Bibliography"));
1250 docPS->addPanel(indicesModule, qt_("Indexes"));
1251 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1252 docPS->addPanel(mathsModule, qt_("Math Options"));
1253 docPS->addPanel(floatModule, qt_("Float Placement"));
1254 docPS->addPanel(listingsModule, qt_("Listings"));
1255 docPS->addPanel(bulletsModule, qt_("Bullets"));
1256 docPS->addPanel(branchesModule, qt_("Branches"));
1257 docPS->addPanel(outputModule, qt_("Output"));
1258 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1259 docPS->addPanel(localLayout, qt_("Local Layout"));
1260 docPS->setCurrentPanel(qt_("Document Class"));
1261 // FIXME: hack to work around resizing bug in Qt >= 4.2
1262 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1263 #if QT_VERSION >= 0x040200
1264 docPS->updateGeometry();
1269 void GuiDocument::saveDefaultClicked()
1275 void GuiDocument::useDefaultsClicked()
1281 void GuiDocument::change_adaptor()
1287 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1292 string child = fromqstr(item->text(0));
1296 if (std::find(includeonlys_.begin(),
1297 includeonlys_.end(), child) != includeonlys_.end())
1298 includeonlys_.remove(child);
1300 includeonlys_.push_back(child);
1302 updateIncludeonlys();
1307 QString GuiDocument::validateListingsParameters()
1309 // use a cache here to avoid repeated validation
1310 // of the same parameters
1311 static string param_cache;
1312 static QString msg_cache;
1314 if (listingsModule->bypassCB->isChecked())
1317 string params = fromqstr(listingsModule->listingsED->toPlainText());
1318 if (params != param_cache) {
1319 param_cache = params;
1320 msg_cache = toqstr(InsetListingsParams(params).validate());
1326 void GuiDocument::setListingsMessage()
1328 static bool isOK = true;
1329 QString msg = validateListingsParameters();
1330 if (msg.isEmpty()) {
1334 // listingsTB->setTextColor("black");
1335 listingsModule->listingsTB->setPlainText(
1336 qt_("Input listings parameters below. "
1337 "Enter ? for a list of parameters."));
1340 // listingsTB->setTextColor("red");
1341 listingsModule->listingsTB->setPlainText(msg);
1346 void GuiDocument::setLSpacing(int item)
1348 textLayoutModule->lspacingLE->setEnabled(item == 3);
1352 void GuiDocument::setIndent(int item)
1354 bool const enable = (item == 1);
1355 textLayoutModule->indentLE->setEnabled(enable);
1356 textLayoutModule->indentLengthCO->setEnabled(enable);
1357 textLayoutModule->skipLE->setEnabled(false);
1358 textLayoutModule->skipLengthCO->setEnabled(false);
1363 void GuiDocument::enableIndent(bool indent)
1365 textLayoutModule->skipLE->setEnabled(!indent);
1366 textLayoutModule->skipLengthCO->setEnabled(!indent);
1368 setIndent(textLayoutModule->indentCO->currentIndex());
1372 void GuiDocument::setSkip(int item)
1374 bool const enable = (item == 3);
1375 textLayoutModule->skipLE->setEnabled(enable);
1376 textLayoutModule->skipLengthCO->setEnabled(enable);
1381 void GuiDocument::enableSkip(bool skip)
1383 textLayoutModule->indentLE->setEnabled(!skip);
1384 textLayoutModule->indentLengthCO->setEnabled(!skip);
1386 setSkip(textLayoutModule->skipCO->currentIndex());
1390 void GuiDocument::setMargins()
1392 bool const extern_geometry =
1393 documentClass().provides("geometry");
1394 marginsModule->marginCB->setEnabled(!extern_geometry);
1395 if (extern_geometry) {
1396 marginsModule->marginCB->setChecked(false);
1397 setCustomMargins(true);
1399 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1400 setCustomMargins(!bp_.use_geometry);
1405 void GuiDocument::papersizeChanged(int paper_size)
1407 setCustomPapersize(paper_size == 1);
1411 void GuiDocument::setCustomPapersize(bool custom)
1413 pageLayoutModule->paperwidthL->setEnabled(custom);
1414 pageLayoutModule->paperwidthLE->setEnabled(custom);
1415 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1416 pageLayoutModule->paperheightL->setEnabled(custom);
1417 pageLayoutModule->paperheightLE->setEnabled(custom);
1418 pageLayoutModule->paperheightLE->setFocus();
1419 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1423 void GuiDocument::setColSep()
1425 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1429 void GuiDocument::setCustomMargins(bool custom)
1431 marginsModule->topL->setEnabled(!custom);
1432 marginsModule->topLE->setEnabled(!custom);
1433 marginsModule->topUnit->setEnabled(!custom);
1435 marginsModule->bottomL->setEnabled(!custom);
1436 marginsModule->bottomLE->setEnabled(!custom);
1437 marginsModule->bottomUnit->setEnabled(!custom);
1439 marginsModule->innerL->setEnabled(!custom);
1440 marginsModule->innerLE->setEnabled(!custom);
1441 marginsModule->innerUnit->setEnabled(!custom);
1443 marginsModule->outerL->setEnabled(!custom);
1444 marginsModule->outerLE->setEnabled(!custom);
1445 marginsModule->outerUnit->setEnabled(!custom);
1447 marginsModule->headheightL->setEnabled(!custom);
1448 marginsModule->headheightLE->setEnabled(!custom);
1449 marginsModule->headheightUnit->setEnabled(!custom);
1451 marginsModule->headsepL->setEnabled(!custom);
1452 marginsModule->headsepLE->setEnabled(!custom);
1453 marginsModule->headsepUnit->setEnabled(!custom);
1455 marginsModule->footskipL->setEnabled(!custom);
1456 marginsModule->footskipLE->setEnabled(!custom);
1457 marginsModule->footskipUnit->setEnabled(!custom);
1459 bool const enableColSep = !custom &&
1460 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1461 marginsModule->columnsepL->setEnabled(enableColSep);
1462 marginsModule->columnsepLE->setEnabled(enableColSep);
1463 marginsModule->columnsepUnit->setEnabled(enableColSep);
1467 void GuiDocument::changeBackgroundColor()
1469 QColor const & newColor = QColorDialog::getColor(
1470 rgb2qcolor(set_backgroundcolor), asQWidget());
1471 if (!newColor.isValid())
1473 // set the button color and text
1474 colorModule->backgroundPB->setStyleSheet(
1475 colorButtonStyleSheet(newColor));
1476 colorModule->backgroundPB->setText(toqstr("Change..."));
1478 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1479 is_backgroundcolor = true;
1484 void GuiDocument::deleteBackgroundColor()
1486 // set the button color back to default by setting an epmty StyleSheet
1487 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1488 // change button text
1489 colorModule->backgroundPB->setText(toqstr("Default..."));
1490 // save default color (white)
1491 set_backgroundcolor = rgbFromHexName("#ffffff");
1492 is_backgroundcolor = false;
1497 void GuiDocument::changeFontColor()
1499 QColor const & newColor = QColorDialog::getColor(
1500 rgb2qcolor(set_fontcolor), asQWidget());
1501 if (!newColor.isValid())
1503 // set the button color and text
1504 colorModule->fontColorPB->setStyleSheet(
1505 colorButtonStyleSheet(newColor));
1506 colorModule->fontColorPB->setText(toqstr("Change..."));
1508 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1509 is_fontcolor = true;
1514 void GuiDocument::deleteFontColor()
1516 // set the button color back to default by setting an epmty StyleSheet
1517 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1518 // change button text
1519 colorModule->fontColorPB->setText(toqstr("Default..."));
1520 // save default color (black)
1521 set_fontcolor = rgbFromHexName("#000000");
1522 is_fontcolor = false;
1527 void GuiDocument::changeNoteFontColor()
1529 QColor const & newColor = QColorDialog::getColor(
1530 rgb2qcolor(set_notefontcolor), asQWidget());
1531 if (!newColor.isValid())
1533 // set the button color
1534 colorModule->noteFontColorPB->setStyleSheet(
1535 colorButtonStyleSheet(newColor));
1537 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1542 void GuiDocument::deleteNoteFontColor()
1544 // set the button color back to light gray
1545 colorModule->noteFontColorPB->setStyleSheet(
1546 colorButtonStyleSheet(QColor(204, 204, 204, 255)));
1547 // save light gray as the set color
1548 set_notefontcolor = rgbFromHexName("#cccccc");
1553 void GuiDocument::changeBoxBackgroundColor()
1555 QColor const & newColor = QColorDialog::getColor(
1556 rgb2qcolor(set_boxbgcolor), asQWidget());
1557 if (!newColor.isValid())
1559 // set the button color
1560 colorModule->boxBackgroundPB->setStyleSheet(
1561 colorButtonStyleSheet(newColor));
1563 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1568 void GuiDocument::deleteBoxBackgroundColor()
1570 // set the button color back to red
1571 colorModule->boxBackgroundPB->setStyleSheet(
1572 colorButtonStyleSheet(QColor(Qt::red)));
1573 // save red as the set color
1574 set_boxbgcolor = rgbFromHexName("#ff0000");
1579 void GuiDocument::xetexChanged(bool xetex)
1582 updateDefaultFormat();
1583 langModule->encodingCO->setEnabled(!xetex &&
1584 !langModule->defaultencodingRB->isChecked());
1585 langModule->defaultencodingRB->setEnabled(!xetex);
1586 langModule->otherencodingRB->setEnabled(!xetex);
1588 fontModule->fontsDefaultCO->setEnabled(!xetex);
1589 fontModule->fontsDefaultLA->setEnabled(!xetex);
1590 fontModule->cjkFontLE->setEnabled(!xetex);
1591 fontModule->cjkFontLA->setEnabled(!xetex);
1594 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1595 bool scaleable = providesScale(font);
1596 fontModule->scaleSansSB->setEnabled(scaleable);
1597 fontModule->scaleSansLA->setEnabled(scaleable);
1599 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1600 scaleable = providesScale(font);
1601 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1602 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1604 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1605 fontModule->fontScCB->setEnabled(providesSC(font));
1606 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1608 fontModule->fontencLA->setEnabled(!xetex);
1609 fontModule->fontencCO->setEnabled(!xetex);
1611 fontModule->fontencLE->setEnabled(false);
1613 fontencChanged(fontModule->fontencCO->currentIndex());
1617 void GuiDocument::updateFontsize(string const & items, string const & sel)
1619 fontModule->fontsizeCO->clear();
1620 fontModule->fontsizeCO->addItem(qt_("Default"));
1622 for (int n = 0; !token(items,'|',n).empty(); ++n)
1623 fontModule->fontsizeCO->
1624 addItem(toqstr(token(items,'|',n)));
1626 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1627 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1628 fontModule->fontsizeCO->setCurrentIndex(n);
1635 void GuiDocument::updateFontlist()
1637 fontModule->fontsRomanCO->clear();
1638 fontModule->fontsSansCO->clear();
1639 fontModule->fontsTypewriterCO->clear();
1641 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1642 if (outputModule->xetexCB->isChecked()) {
1643 fontModule->fontsRomanCO->addItem(qt_("Default"));
1644 fontModule->fontsSansCO->addItem(qt_("Default"));
1645 fontModule->fontsTypewriterCO->addItem(qt_("Default"));
1647 QFontDatabase fontdb;
1648 QStringList families(fontdb.families());
1649 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1650 fontModule->fontsRomanCO->addItem(*it);
1651 fontModule->fontsSansCO->addItem(*it);
1652 fontModule->fontsTypewriterCO->addItem(*it);
1657 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1658 QString font = qt_(tex_fonts_roman_gui[n]);
1659 if (!isFontAvailable(tex_fonts_roman[n]))
1660 font += qt_(" (not installed)");
1661 fontModule->fontsRomanCO->addItem(font);
1663 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1664 QString font = qt_(tex_fonts_sans_gui[n]);
1665 if (!isFontAvailable(tex_fonts_sans[n]))
1666 font += qt_(" (not installed)");
1667 fontModule->fontsSansCO->addItem(font);
1669 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1670 QString font = qt_(tex_fonts_monospaced_gui[n]);
1671 if (!isFontAvailable(tex_fonts_monospaced[n]))
1672 font += qt_(" (not installed)");
1673 fontModule->fontsTypewriterCO->addItem(font);
1678 void GuiDocument::fontencChanged(int item)
1680 fontModule->fontencLE->setEnabled(item == 1);
1684 void GuiDocument::romanChanged(int item)
1686 if (outputModule->xetexCB->isChecked())
1688 string const font = tex_fonts_roman[item];
1689 fontModule->fontScCB->setEnabled(providesSC(font));
1690 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1694 void GuiDocument::sansChanged(int item)
1696 if (outputModule->xetexCB->isChecked())
1698 string const font = tex_fonts_sans[item];
1699 bool scaleable = providesScale(font);
1700 fontModule->scaleSansSB->setEnabled(scaleable);
1701 fontModule->scaleSansLA->setEnabled(scaleable);
1705 void GuiDocument::ttChanged(int item)
1707 if (outputModule->xetexCB->isChecked())
1709 string const font = tex_fonts_monospaced[item];
1710 bool scaleable = providesScale(font);
1711 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1712 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1716 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1719 pageLayoutModule->pagestyleCO->clear();
1720 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1722 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1723 string style = token(items, '|', n);
1724 QString style_gui = qt_(style);
1725 pagestyles.push_back(pair<string, QString>(style, style_gui));
1726 pageLayoutModule->pagestyleCO->addItem(style_gui);
1729 if (sel == "default") {
1730 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1736 for (size_t i = 0; i < pagestyles.size(); ++i)
1737 if (pagestyles[i].first == sel)
1738 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1741 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1745 void GuiDocument::browseLayout()
1747 QString const label1 = qt_("Layouts|#o#O");
1748 QString const dir1 = toqstr(lyxrc.document_path);
1749 QStringList const filter(qt_("LyX Layout (*.layout)"));
1750 QString file = browseRelFile(QString(), bufferFilePath(),
1751 qt_("Local layout file"), filter, false,
1754 if (!file.endsWith(".layout"))
1757 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1758 fromqstr(bufferFilePath()));
1760 int const ret = Alert::prompt(_("Local layout file"),
1761 _("The layout file you have selected is a local layout\n"
1762 "file, not one in the system or user directory. Your\n"
1763 "document may not work with this layout if you do not\n"
1764 "keep the layout file in the document directory."),
1765 1, 1, _("&Set Layout"), _("&Cancel"));
1769 // load the layout file
1770 LayoutFileList & bcl = LayoutFileList::get();
1771 string classname = layoutFile.onlyFileName();
1772 // this will update an existing layout if that layout has been loaded before.
1773 LayoutFileIndex name = bcl.addLocalLayout(
1774 classname.substr(0, classname.size() - 7),
1775 layoutFile.onlyPath().absFileName());
1778 Alert::error(_("Error"),
1779 _("Unable to read local layout file."));
1783 // do not trigger classChanged if there is no change.
1784 if (latexModule->classCO->currentText() == toqstr(name))
1788 int idx = latexModule->classCO->findText(toqstr(name));
1790 classes_model_.insertRow(0, toqstr(name), name);
1791 latexModule->classCO->setCurrentIndex(0);
1793 latexModule->classCO->setCurrentIndex(idx);
1799 void GuiDocument::browseMaster()
1801 QString const title = qt_("Select master document");
1802 QString const dir1 = toqstr(lyxrc.document_path);
1803 QString const old = latexModule->childDocLE->text();
1804 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1805 QStringList const filter(qt_("LyX Files (*.lyx)"));
1806 QString file = browseRelFile(old, docpath, title, filter, false,
1807 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1809 if (!file.isEmpty())
1810 latexModule->childDocLE->setText(file);
1814 void GuiDocument::classChanged()
1816 int idx = latexModule->classCO->currentIndex();
1819 string const classname = classes_model_.getIDString(idx);
1821 // check whether the selected modules have changed.
1822 bool modules_changed = false;
1823 unsigned int const srows = selectedModel()->rowCount();
1824 if (srows != bp_.getModules().size())
1825 modules_changed = true;
1827 list<string>::const_iterator mit = bp_.getModules().begin();
1828 list<string>::const_iterator men = bp_.getModules().end();
1829 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1830 if (selectedModel()->getIDString(i) != *mit) {
1831 modules_changed = true;
1836 if (modules_changed || lyxrc.auto_reset_options) {
1837 if (applyPB->isEnabled()) {
1838 int const ret = Alert::prompt(_("Unapplied changes"),
1839 _("Some changes in the dialog were not yet applied.\n"
1840 "If you do not apply now, they will be lost after this action."),
1841 1, 1, _("&Apply"), _("&Dismiss"));
1847 // We load the TextClass as soon as it is selected. This is
1848 // necessary so that other options in the dialog can be updated
1849 // according to the new class. Note, however, that, if you use
1850 // the scroll wheel when sitting on the combo box, we'll load a
1851 // lot of TextClass objects very quickly....
1852 if (!bp_.setBaseClass(classname)) {
1853 Alert::error(_("Error"), _("Unable to set document class."));
1856 if (lyxrc.auto_reset_options)
1857 bp_.useClassDefaults();
1859 // With the introduction of modules came a distinction between the base
1860 // class and the document class. The former corresponds to the main layout
1861 // file; the latter is that plus the modules (or the document-specific layout,
1862 // or whatever else there could be). Our parameters come from the document
1863 // class. So when we set the base class, we also need to recreate the document
1864 // class. Otherwise, we still have the old one.
1865 bp_.makeDocumentClass();
1870 void GuiDocument::bibtexChanged(int n)
1872 biblioModule->bibtexOptionsED->setEnabled(n != 0);
1878 // This is an insanely complicated attempt to make this sort of thing
1879 // work with RTL languages.
1880 docstring formatStrVec(vector<string> const & v, docstring const & s)
1882 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1886 return from_utf8(v[0]);
1887 if (v.size() == 2) {
1888 docstring retval = _("%1$s and %2$s");
1889 retval = subst(retval, _("and"), s);
1890 return bformat(retval, from_utf8(v[0]), from_utf8(v[1]));
1892 // The idea here is to format all but the last two items...
1893 int const vSize = v.size();
1894 docstring t2 = _("%1$s, %2$s");
1895 docstring retval = from_utf8(v[0]);
1896 for (int i = 1; i < vSize - 2; ++i)
1897 retval = bformat(t2, retval, from_utf8(v[i]));
1898 //...and then to plug them, and the last two, into this schema
1899 docstring t = _("%1$s, %2$s, and %3$s");
1900 t = subst(t, _("and"), s);
1901 return bformat(t, retval, from_utf8(v[vSize - 2]), from_utf8(v[vSize - 1]));
1904 vector<string> idsToNames(vector<string> const & idList)
1906 vector<string> retval;
1907 vector<string>::const_iterator it = idList.begin();
1908 vector<string>::const_iterator end = idList.end();
1909 for (; it != end; ++it) {
1910 LyXModule const * const mod = theModuleList[*it];
1912 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"), from_utf8(*it))));
1914 retval.push_back(mod->getName());
1918 } // end anonymous namespace
1921 void GuiDocument::modulesToParams(BufferParams & bp)
1923 // update list of loaded modules
1924 bp.clearLayoutModules();
1925 int const srows = modules_sel_model_.rowCount();
1926 for (int i = 0; i < srows; ++i)
1927 bp.addLayoutModule(modules_sel_model_.getIDString(i));
1929 // update the list of removed modules
1930 bp.clearRemovedModules();
1931 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
1932 list<string>::const_iterator rit = reqmods.begin();
1933 list<string>::const_iterator ren = reqmods.end();
1935 // check each of the default modules
1936 for (; rit != ren; rit++) {
1937 list<string>::const_iterator mit = bp.getModules().begin();
1938 list<string>::const_iterator men = bp.getModules().end();
1940 for (; mit != men; mit++) {
1947 // the module isn't present so must have been removed by the user
1948 bp.addRemovedModule(*rit);
1953 void GuiDocument::modulesChanged()
1955 modulesToParams(bp_);
1956 bp_.makeDocumentClass();
1961 void GuiDocument::updateModuleInfo()
1963 selectionManager->update();
1965 //Module description
1966 bool const focus_on_selected = selectionManager->selectedFocused();
1967 QAbstractItemView * lv;
1968 if (focus_on_selected)
1969 lv = modulesModule->selectedLV;
1971 lv= modulesModule->availableLV;
1972 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1973 modulesModule->infoML->document()->clear();
1976 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1977 GuiIdListModel const & id_model =
1978 focus_on_selected ? modules_sel_model_ : modules_av_model_;
1979 string const modName = id_model.getIDString(idx.row());
1980 docstring desc = getModuleDescription(modName);
1982 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
1983 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
1986 desc += _("Module provided by document class.");
1989 vector<string> pkglist = getPackageList(modName);
1990 docstring pkgdesc = formatStrVec(pkglist, _("and"));
1991 if (!pkgdesc.empty()) {
1994 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1997 pkglist = getRequiredList(modName);
1998 if (!pkglist.empty()) {
1999 vector<string> const reqdescs = idsToNames(pkglist);
2000 pkgdesc = formatStrVec(reqdescs, _("or"));
2003 desc += bformat(_("Module required: %1$s."), pkgdesc);
2006 pkglist = getExcludedList(modName);
2007 if (!pkglist.empty()) {
2008 vector<string> const reqdescs = idsToNames(pkglist);
2009 pkgdesc = formatStrVec(reqdescs, _( "and"));
2012 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2015 if (!isModuleAvailable(modName)) {
2018 desc += _("WARNING: Some required packages are unavailable!");
2021 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2025 void GuiDocument::updateNumbering()
2027 DocumentClass const & tclass = documentClass();
2029 numberingModule->tocTW->setUpdatesEnabled(false);
2030 numberingModule->tocTW->clear();
2032 int const depth = numberingModule->depthSL->value();
2033 int const toc = numberingModule->tocSL->value();
2034 QString const no = qt_("No");
2035 QString const yes = qt_("Yes");
2036 QTreeWidgetItem * item = 0;
2038 DocumentClass::const_iterator lit = tclass.begin();
2039 DocumentClass::const_iterator len = tclass.end();
2040 for (; lit != len; ++lit) {
2041 int const toclevel = lit->toclevel;
2042 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
2043 item = new QTreeWidgetItem(numberingModule->tocTW);
2044 item->setText(0, toqstr(translateIfPossible(lit->name())));
2045 item->setText(1, (toclevel <= depth) ? yes : no);
2046 item->setText(2, (toclevel <= toc) ? yes : no);
2050 numberingModule->tocTW->setUpdatesEnabled(true);
2051 numberingModule->tocTW->update();
2055 void GuiDocument::updateDefaultFormat()
2059 // make a copy in order to consider unapplied changes
2060 Buffer * tmpbuf = buffer().clone();
2061 tmpbuf->params().useXetex = outputModule->xetexCB->isChecked();
2062 int idx = latexModule->classCO->currentIndex();
2064 string const classname = classes_model_.getIDString(idx);
2065 tmpbuf->params().setBaseClass(classname);
2066 tmpbuf->params().makeDocumentClass();
2068 outputModule->defaultFormatCO->blockSignals(true);
2069 outputModule->defaultFormatCO->clear();
2070 outputModule->defaultFormatCO->addItem(qt_("Default"),
2071 QVariant(QString("default")));
2072 typedef vector<Format const *> Formats;
2073 Formats formats = tmpbuf->exportableFormats(true);
2074 Formats::const_iterator cit = formats.begin();
2075 Formats::const_iterator end = formats.end();
2076 for (; cit != end; ++cit)
2077 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2078 QVariant(toqstr((*cit)->name())));
2079 outputModule->defaultFormatCO->blockSignals(false);
2085 bool GuiDocument::isChildIncluded(string const & child)
2087 if (includeonlys_.empty())
2089 return (std::find(includeonlys_.begin(),
2090 includeonlys_.end(), child) != includeonlys_.end());
2094 void GuiDocument::applyView()
2097 preambleModule->apply(bp_);
2098 localLayout->apply(bp_);
2101 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2104 bp_.setCiteEngine(ENGINE_BASIC);
2106 if (biblioModule->citeNatbibRB->isChecked()) {
2107 bool const use_numerical_citations =
2108 biblioModule->citeStyleCO->currentIndex();
2109 if (use_numerical_citations)
2110 bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
2112 bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
2114 } else if (biblioModule->citeJurabibRB->isChecked())
2115 bp_.setCiteEngine(ENGINE_JURABIB);
2118 biblioModule->bibtopicCB->isChecked();
2120 string const bibtex_command =
2121 fromqstr(biblioModule->bibtexCO->itemData(
2122 biblioModule->bibtexCO->currentIndex()).toString());
2123 string const bibtex_options =
2124 fromqstr(biblioModule->bibtexOptionsED->text());
2125 if (bibtex_command == "default" || bibtex_options.empty())
2126 bp_.bibtex_command = bibtex_command;
2128 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2131 indicesModule->apply(bp_);
2133 // language & quotes
2134 if (langModule->defaultencodingRB->isChecked()) {
2135 bp_.inputenc = "auto";
2137 int i = langModule->encodingCO->currentIndex();
2139 bp_.inputenc = "default";
2141 QString const enc_gui =
2142 langModule->encodingCO->currentText();
2143 Encodings::const_iterator it = encodings.begin();
2144 Encodings::const_iterator const end = encodings.end();
2146 for (; it != end; ++it) {
2147 if (qt_(it->guiName()) == enc_gui) {
2148 bp_.inputenc = it->latexName();
2154 // should not happen
2155 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2156 bp_.inputenc = "default";
2161 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2162 switch (langModule->quoteStyleCO->currentIndex()) {
2164 lga = InsetQuotes::EnglishQuotes;
2167 lga = InsetQuotes::SwedishQuotes;
2170 lga = InsetQuotes::GermanQuotes;
2173 lga = InsetQuotes::PolishQuotes;
2176 lga = InsetQuotes::FrenchQuotes;
2179 lga = InsetQuotes::DanishQuotes;
2182 bp_.quotes_language = lga;
2184 QString const lang = langModule->languageCO->itemData(
2185 langModule->languageCO->currentIndex()).toString();
2186 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2189 bp_.backgroundcolor = set_backgroundcolor;
2190 bp_.isbackgroundcolor = is_backgroundcolor;
2191 bp_.fontcolor = set_fontcolor;
2192 bp_.isfontcolor = is_fontcolor;
2193 bp_.notefontcolor = set_notefontcolor;
2194 bp_.boxbgcolor = set_boxbgcolor;
2197 if (bp_.documentClass().hasTocLevels()) {
2198 bp_.tocdepth = numberingModule->tocSL->value();
2199 bp_.secnumdepth = numberingModule->depthSL->value();
2203 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2204 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2205 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2206 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2209 bp_.graphicsDriver =
2210 tex_graphics[latexModule->psdriverCO->currentIndex()];
2213 int idx = latexModule->classCO->currentIndex();
2215 string const classname = classes_model_.getIDString(idx);
2216 bp_.setBaseClass(classname);
2220 modulesToParams(bp_);
2223 if (mathsModule->amsautoCB->isChecked())
2224 bp_.use_amsmath = BufferParams::package_auto;
2226 if (mathsModule->amsCB->isChecked())
2227 bp_.use_amsmath = BufferParams::package_on;
2229 bp_.use_amsmath = BufferParams::package_off;
2231 if (mathsModule->esintautoCB->isChecked())
2232 bp_.use_esint = BufferParams::package_auto;
2234 if (mathsModule->esintCB->isChecked())
2235 bp_.use_esint = BufferParams::package_on;
2237 bp_.use_esint = BufferParams::package_off;
2239 if (mathsModule->mhchemautoCB->isChecked())
2240 bp_.use_mhchem = BufferParams::package_auto;
2242 if (mathsModule->mhchemCB->isChecked())
2243 bp_.use_mhchem = BufferParams::package_on;
2245 bp_.use_mhchem = BufferParams::package_off;
2247 if (mathsModule->mathdotsCB->isChecked())
2248 bp_.use_mathdots = true;
2250 bp_.use_mathdots = false;
2253 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2254 bp_.pagestyle = "default";
2256 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2257 for (size_t i = 0; i != pagestyles.size(); ++i)
2258 if (pagestyles[i].second == style_gui)
2259 bp_.pagestyle = pagestyles[i].first;
2263 switch (textLayoutModule->lspacingCO->currentIndex()) {
2265 bp_.spacing().set(Spacing::Single);
2268 bp_.spacing().set(Spacing::Onehalf);
2271 bp_.spacing().set(Spacing::Double);
2274 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2276 bp_.spacing().set(Spacing::Single);
2278 bp_.spacing().set(Spacing::Other, s);
2283 if (textLayoutModule->twoColumnCB->isChecked())
2288 if (textLayoutModule->indentRB->isChecked()) {
2289 // if paragraphs are separated by an indentation
2290 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2291 switch (textLayoutModule->indentCO->currentIndex()) {
2293 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2296 HSpace indent = HSpace(
2297 widgetsToLength(textLayoutModule->indentLE,
2298 textLayoutModule->indentLengthCO)
2300 bp_.setIndentation(indent);
2304 // this should never happen
2305 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2309 // if paragraphs are separated by a skip
2310 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2311 switch (textLayoutModule->skipCO->currentIndex()) {
2313 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2316 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2319 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2324 widgetsToLength(textLayoutModule->skipLE,
2325 textLayoutModule->skipLengthCO)
2331 // this should never happen
2332 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2338 fromqstr(latexModule->optionsLE->text());
2340 bp_.use_default_options =
2341 latexModule->defaultOptionsCB->isChecked();
2343 if (latexModule->childDocGB->isChecked())
2345 fromqstr(latexModule->childDocLE->text());
2347 bp_.master = string();
2350 bp_.clearIncludedChildren();
2351 if (masterChildModule->includeonlyRB->isChecked()) {
2352 list<string>::const_iterator it = includeonlys_.begin();
2353 for (; it != includeonlys_.end() ; ++it) {
2354 bp_.addIncludedChildren(*it);
2357 bp_.maintain_unincluded_children =
2358 masterChildModule->maintainAuxCB->isChecked();
2361 bp_.float_placement = floatModule->get();
2364 // text should have passed validation
2365 bp_.listings_params =
2366 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2369 bp_.defaultOutputFormat = fromqstr(outputModule->defaultFormatCO->itemData(
2370 outputModule->defaultFormatCO->currentIndex()).toString());
2372 bool const xetex = outputModule->xetexCB->isChecked();
2373 bp_.useXetex = xetex;
2375 bp_.output_sync = outputModule->outputsyncCB->isChecked();
2376 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2378 int mathfmt = outputModule->mathoutCB->currentIndex();
2381 BufferParams::MathOutput const mo =
2382 static_cast<BufferParams::MathOutput>(mathfmt);
2383 bp_.html_math_output = mo;
2384 bp_.html_be_strict = outputModule->strictCB->isChecked();
2385 bp_.html_math_img_scale = outputModule->mathimgSB->value();
2389 if (fontModule->fontsRomanCO->currentIndex() == 0)
2390 bp_.fontsRoman = "default";
2393 fromqstr(fontModule->fontsRomanCO->currentText());
2395 if (fontModule->fontsSansCO->currentIndex() == 0)
2396 bp_.fontsSans = "default";
2399 fromqstr(fontModule->fontsSansCO->currentText());
2401 if (fontModule->fontsTypewriterCO->currentIndex() == 0)
2402 bp_.fontsTypewriter = "default";
2404 bp_.fontsTypewriter =
2405 fromqstr(fontModule->fontsTypewriterCO->currentText());
2408 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
2411 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
2413 bp_.fontsTypewriter =
2414 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
2417 if (fontModule->fontencCO->currentIndex() == 0)
2418 bp_.fontenc = "global";
2419 else if (fontModule->fontencCO->currentIndex() == 1)
2420 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2421 else if (fontModule->fontencCO->currentIndex() == 2)
2422 bp_.fontenc = "default";
2425 fromqstr(fontModule->cjkFontLE->text());
2427 bp_.fontsSansScale = fontModule->scaleSansSB->value();
2429 bp_.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
2431 bp_.fontsSC = fontModule->fontScCB->isChecked();
2433 bp_.fontsOSF = fontModule->fontOsfCB->isChecked();
2436 bp_.fontsDefaultFamily = "default";
2438 bp_.fontsDefaultFamily = GuiDocument::fontfamilies[
2439 fontModule->fontsDefaultCO->currentIndex()];
2441 if (fontModule->fontsizeCO->currentIndex() == 0)
2442 bp_.fontsize = "default";
2445 fromqstr(fontModule->fontsizeCO->currentText());
2448 bp_.papersize = PAPER_SIZE(
2449 pageLayoutModule->papersizeCO->currentIndex());
2451 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2452 pageLayoutModule->paperwidthUnitCO);
2454 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2455 pageLayoutModule->paperheightUnitCO);
2457 if (pageLayoutModule->facingPagesCB->isChecked())
2458 bp_.sides = TwoSides;
2460 bp_.sides = OneSide;
2462 if (pageLayoutModule->landscapeRB->isChecked())
2463 bp_.orientation = ORIENTATION_LANDSCAPE;
2465 bp_.orientation = ORIENTATION_PORTRAIT;
2468 bp_.use_geometry = !marginsModule->marginCB->isChecked();
2470 Ui::MarginsUi const * m = marginsModule;
2472 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2473 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2474 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2475 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2476 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2477 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2478 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2479 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2482 branchesModule->apply(bp_);
2485 PDFOptions & pdf = bp_.pdfoptions();
2486 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2487 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2488 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2489 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2490 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2492 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2493 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2494 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2495 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2497 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2498 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2499 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2500 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2502 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2503 if (pdfSupportModule->fullscreenCB->isChecked())
2504 pdf.pagemode = pdf.pagemode_fullscreen;
2506 pdf.pagemode.clear();
2507 pdf.quoted_options = pdf.quoted_options_check(
2508 fromqstr(pdfSupportModule->optionsLE->text()));
2512 void GuiDocument::paramsToDialog()
2514 // set the default unit
2515 Length::UNIT const defaultUnit = Length::defaultUnit();
2518 preambleModule->update(bp_, id());
2519 localLayout->update(bp_, id());
2522 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2525 biblioModule->citeDefaultRB->setChecked(
2526 bp_.citeEngine() == ENGINE_BASIC);
2528 biblioModule->citeNatbibRB->setChecked(
2529 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
2530 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
2532 biblioModule->citeStyleCO->setCurrentIndex(
2533 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
2535 biblioModule->citeJurabibRB->setChecked(
2536 bp_.citeEngine() == ENGINE_JURABIB);
2538 biblioModule->bibtopicCB->setChecked(
2543 split(bp_.bibtex_command, command, ' ');
2545 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2547 biblioModule->bibtexCO->setCurrentIndex(bpos);
2548 biblioModule->bibtexOptionsED->setText(toqstr(options).trimmed());
2550 biblioModule->bibtexCO->setCurrentIndex(0);
2551 biblioModule->bibtexOptionsED->clear();
2553 biblioModule->bibtexOptionsED->setEnabled(
2554 biblioModule->bibtexCO->currentIndex() != 0);
2557 indicesModule->update(bp_);
2559 // language & quotes
2560 int const pos = langModule->languageCO->findData(toqstr(
2561 bp_.language->lang()));
2562 langModule->languageCO->setCurrentIndex(pos);
2564 langModule->quoteStyleCO->setCurrentIndex(
2565 bp_.quotes_language);
2567 bool default_enc = true;
2568 if (bp_.inputenc != "auto") {
2569 default_enc = false;
2570 if (bp_.inputenc == "default") {
2571 langModule->encodingCO->setCurrentIndex(0);
2574 Encodings::const_iterator it = encodings.begin();
2575 Encodings::const_iterator const end = encodings.end();
2576 for (; it != end; ++it) {
2577 if (it->latexName() == bp_.inputenc) {
2578 enc_gui = it->guiName();
2582 int const i = langModule->encodingCO->findText(
2585 langModule->encodingCO->setCurrentIndex(i);
2587 // unknown encoding. Set to default.
2591 langModule->defaultencodingRB->setChecked(default_enc);
2592 langModule->otherencodingRB->setChecked(!default_enc);
2595 if (bp_.isfontcolor) {
2596 colorModule->fontColorPB->setStyleSheet(
2597 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2599 set_fontcolor = bp_.fontcolor;
2600 is_fontcolor = bp_.isfontcolor;
2602 colorModule->noteFontColorPB->setStyleSheet(
2603 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2604 set_notefontcolor = bp_.notefontcolor;
2606 if (bp_.isbackgroundcolor) {
2607 colorModule->backgroundPB->setStyleSheet(
2608 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2610 set_backgroundcolor = bp_.backgroundcolor;
2611 is_backgroundcolor = bp_.isbackgroundcolor;
2613 colorModule->boxBackgroundPB->setStyleSheet(
2614 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
2615 set_boxbgcolor = bp_.boxbgcolor;
2618 int const min_toclevel = documentClass().min_toclevel();
2619 int const max_toclevel = documentClass().max_toclevel();
2620 if (documentClass().hasTocLevels()) {
2621 numberingModule->setEnabled(true);
2622 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2623 numberingModule->depthSL->setMaximum(max_toclevel);
2624 numberingModule->depthSL->setValue(bp_.secnumdepth);
2625 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2626 numberingModule->tocSL->setMaximum(max_toclevel);
2627 numberingModule->tocSL->setValue(bp_.tocdepth);
2630 numberingModule->setEnabled(false);
2631 numberingModule->tocTW->clear();
2635 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2636 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2637 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2638 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2639 bulletsModule->init();
2642 int nitem = findToken(tex_graphics, bp_.graphicsDriver);
2644 latexModule->psdriverCO->setCurrentIndex(nitem);
2647 mathsModule->amsCB->setChecked(
2648 bp_.use_amsmath == BufferParams::package_on);
2649 mathsModule->amsautoCB->setChecked(
2650 bp_.use_amsmath == BufferParams::package_auto);
2652 mathsModule->esintCB->setChecked(
2653 bp_.use_esint == BufferParams::package_on);
2654 mathsModule->esintautoCB->setChecked(
2655 bp_.use_esint == BufferParams::package_auto);
2657 mathsModule->mhchemCB->setChecked(
2658 bp_.use_mhchem == BufferParams::package_on);
2659 mathsModule->mhchemautoCB->setChecked(
2660 bp_.use_mhchem == BufferParams::package_auto);
2662 mathsModule->mathdotsCB->setChecked(bp_.use_mathdots);
2664 switch (bp_.spacing().getSpace()) {
2665 case Spacing::Other: nitem = 3; break;
2666 case Spacing::Double: nitem = 2; break;
2667 case Spacing::Onehalf: nitem = 1; break;
2668 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2672 string const & layoutID = bp_.baseClassID();
2673 setLayoutComboByIDString(layoutID);
2675 updatePagestyle(documentClass().opt_pagestyle(),
2678 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2679 if (bp_.spacing().getSpace() == Spacing::Other) {
2680 doubleToWidget(textLayoutModule->lspacingLE,
2681 bp_.spacing().getValueAsString());
2685 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2686 textLayoutModule->indentRB->setChecked(true);
2687 string indentation = bp_.getIndentation().asLyXCommand();
2689 if (indentation != "default") {
2690 lengthToWidgets(textLayoutModule->indentLE,
2691 textLayoutModule->indentLengthCO,
2692 indentation, defaultUnit);
2695 textLayoutModule->indentCO->setCurrentIndex(indent);
2698 textLayoutModule->skipRB->setChecked(true);
2700 switch (bp_.getDefSkip().kind()) {
2701 case VSpace::SMALLSKIP:
2704 case VSpace::MEDSKIP:
2707 case VSpace::BIGSKIP:
2710 case VSpace::LENGTH:
2713 string const length = bp_.getDefSkip().asLyXCommand();
2714 lengthToWidgets(textLayoutModule->skipLE,
2715 textLayoutModule->skipLengthCO,
2716 length, defaultUnit);
2723 textLayoutModule->skipCO->setCurrentIndex(skip);
2727 textLayoutModule->twoColumnCB->setChecked(
2730 if (!bp_.options.empty()) {
2731 latexModule->optionsLE->setText(
2732 toqstr(bp_.options));
2734 latexModule->optionsLE->setText(QString());
2738 latexModule->defaultOptionsCB->setChecked(
2739 bp_.use_default_options);
2740 updateSelectedModules();
2741 selectionManager->updateProvidedModules(
2742 bp_.baseClass()->providedModules());
2743 selectionManager->updateExcludedModules(
2744 bp_.baseClass()->excludedModules());
2746 if (!documentClass().options().empty()) {
2747 latexModule->defaultOptionsLE->setText(
2748 toqstr(documentClass().options()));
2750 latexModule->defaultOptionsLE->setText(
2751 toqstr(_("[No options predefined]")));
2754 latexModule->defaultOptionsLE->setEnabled(
2755 bp_.use_default_options
2756 && !documentClass().options().empty());
2758 latexModule->defaultOptionsCB->setEnabled(
2759 !documentClass().options().empty());
2761 if (!bp_.master.empty()) {
2762 latexModule->childDocGB->setChecked(true);
2763 latexModule->childDocLE->setText(
2764 toqstr(bp_.master));
2766 latexModule->childDocLE->setText(QString());
2767 latexModule->childDocGB->setChecked(false);
2771 std::vector<Buffer *> children;
2773 children = buffer().getChildren(false);
2774 if (children.empty()) {
2775 masterChildModule->childrenTW->clear();
2776 includeonlys_.clear();
2777 docPS->showPanel(qt_("Child Documents"), false);
2778 if (docPS->isCurrentPanel(qt_("Child Documents")))
2779 docPS->setCurrentPanel(qt_("Document Class"));
2781 docPS->showPanel(qt_("Child Documents"), true);
2782 masterChildModule->setEnabled(true);
2783 includeonlys_ = bp_.getIncludedChildren();
2784 updateIncludeonlys();
2786 masterChildModule->maintainAuxCB->setChecked(
2787 bp_.maintain_unincluded_children);
2790 floatModule->set(bp_.float_placement);
2793 // break listings_params to multiple lines
2795 InsetListingsParams(bp_.listings_params).separatedParams();
2796 listingsModule->listingsED->setPlainText(toqstr(lstparams));
2799 // update combobox with formats
2800 updateDefaultFormat();
2801 int index = outputModule->defaultFormatCO->findData(toqstr(
2802 bp_.defaultOutputFormat));
2803 // set to default if format is not found
2806 outputModule->defaultFormatCO->setCurrentIndex(index);
2807 outputModule->xetexCB->setEnabled(bp_.baseClass()->outputType() == lyx::LATEX);
2808 outputModule->xetexCB->setChecked(
2809 bp_.baseClass()->outputType() == lyx::LATEX && bp_.useXetex);
2811 outputModule->outputsyncCB->setChecked(bp_.output_sync);
2812 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
2814 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
2815 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
2816 outputModule->strictCB->setChecked(bp_.html_be_strict);
2819 updateFontsize(documentClass().opt_fontsize(),
2823 fontModule->fontencLA->setEnabled(false);
2824 fontModule->fontencCO->setEnabled(false);
2825 fontModule->fontencLE->setEnabled(false);
2826 for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
2827 if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fontsRoman)) {
2828 fontModule->fontsRomanCO->setCurrentIndex(i);
2833 for (int i = 0; i < fontModule->fontsSansCO->count(); ++i) {
2834 if (fontModule->fontsSansCO->itemText(i) == toqstr(bp_.fontsSans)) {
2835 fontModule->fontsSansCO->setCurrentIndex(i);
2839 for (int i = 0; i < fontModule->fontsTypewriterCO->count(); ++i) {
2840 if (fontModule->fontsTypewriterCO->itemText(i) ==
2841 toqstr(bp_.fontsTypewriter)) {
2842 fontModule->fontsTypewriterCO->setCurrentIndex(i);
2847 fontModule->fontencLA->setEnabled(true);
2848 fontModule->fontencCO->setEnabled(true);
2849 fontModule->fontencLE->setEnabled(true);
2850 int n = findToken(tex_fonts_roman, bp_.fontsRoman);
2852 fontModule->fontsRomanCO->setCurrentIndex(n);
2856 n = findToken(tex_fonts_sans, bp_.fontsSans);
2858 fontModule->fontsSansCO->setCurrentIndex(n);
2862 n = findToken(tex_fonts_monospaced, bp_.fontsTypewriter);
2864 fontModule->fontsTypewriterCO->setCurrentIndex(n);
2869 if (!bp_.fontsCJK.empty())
2870 fontModule->cjkFontLE->setText(
2871 toqstr(bp_.fontsCJK));
2873 fontModule->cjkFontLE->setText(QString());
2875 fontModule->fontScCB->setChecked(bp_.fontsSC);
2876 fontModule->fontOsfCB->setChecked(bp_.fontsOSF);
2877 fontModule->scaleSansSB->setValue(bp_.fontsSansScale);
2878 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale);
2880 int nn = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily);
2882 fontModule->fontsDefaultCO->setCurrentIndex(nn);
2884 if (bp_.fontenc == "global") {
2885 fontModule->fontencCO->setCurrentIndex(0);
2886 fontModule->fontencLE->setEnabled(false);
2887 } else if (bp_.fontenc == "default") {
2888 fontModule->fontencCO->setCurrentIndex(2);
2889 fontModule->fontencLE->setEnabled(false);
2891 fontModule->fontencCO->setCurrentIndex(1);
2892 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
2896 bool const extern_geometry =
2897 documentClass().provides("geometry");
2898 int const psize = bp_.papersize;
2899 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
2900 setCustomPapersize(!extern_geometry && psize == 1);
2901 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
2903 bool const landscape =
2904 bp_.orientation == ORIENTATION_LANDSCAPE;
2905 pageLayoutModule->landscapeRB->setChecked(landscape);
2906 pageLayoutModule->portraitRB->setChecked(!landscape);
2907 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
2908 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
2910 pageLayoutModule->facingPagesCB->setChecked(
2911 bp_.sides == TwoSides);
2913 lengthToWidgets(pageLayoutModule->paperwidthLE,
2914 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, defaultUnit);
2915 lengthToWidgets(pageLayoutModule->paperheightLE,
2916 pageLayoutModule->paperheightUnitCO, bp_.paperheight, defaultUnit);
2919 Ui::MarginsUi * m = marginsModule;
2923 lengthToWidgets(m->topLE, m->topUnit,
2924 bp_.topmargin, defaultUnit);
2926 lengthToWidgets(m->bottomLE, m->bottomUnit,
2927 bp_.bottommargin, defaultUnit);
2929 lengthToWidgets(m->innerLE, m->innerUnit,
2930 bp_.leftmargin, defaultUnit);
2932 lengthToWidgets(m->outerLE, m->outerUnit,
2933 bp_.rightmargin, defaultUnit);
2935 lengthToWidgets(m->headheightLE, m->headheightUnit,
2936 bp_.headheight, defaultUnit);
2938 lengthToWidgets(m->headsepLE, m->headsepUnit,
2939 bp_.headsep, defaultUnit);
2941 lengthToWidgets(m->footskipLE, m->footskipUnit,
2942 bp_.footskip, defaultUnit);
2944 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2945 bp_.columnsep, defaultUnit);
2948 updateUnknownBranches();
2949 branchesModule->update(bp_);
2952 PDFOptions const & pdf = bp_.pdfoptions();
2953 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2954 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2955 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2956 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2957 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2959 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2960 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2961 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2963 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2965 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2966 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2967 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2968 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2970 nn = findToken(backref_opts, pdf.backref);
2972 pdfSupportModule->backrefCO->setCurrentIndex(nn);
2974 pdfSupportModule->fullscreenCB->setChecked
2975 (pdf.pagemode == pdf.pagemode_fullscreen);
2977 pdfSupportModule->optionsLE->setText(
2978 toqstr(pdf.quoted_options));
2980 // Make sure that the bc is in the INITIAL state
2981 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2984 // clear changed branches cache
2985 changedBranches_.clear();
2989 void GuiDocument::saveDocDefault()
2991 // we have to apply the params first
2997 void GuiDocument::updateAvailableModules()
2999 modules_av_model_.clear();
3000 list<modInfoStruct> const & modInfoList = getModuleInfo();
3001 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3002 list<modInfoStruct>::const_iterator men = modInfoList.end();
3003 for (int i = 0; mit != men; ++mit, ++i)
3004 modules_av_model_.insertRow(i, mit->name, mit->id,
3009 void GuiDocument::updateSelectedModules()
3011 modules_sel_model_.clear();
3012 list<modInfoStruct> const selModList = getSelectedModules();
3013 list<modInfoStruct>::const_iterator mit = selModList.begin();
3014 list<modInfoStruct>::const_iterator men = selModList.end();
3015 for (int i = 0; mit != men; ++mit, ++i)
3016 modules_sel_model_.insertRow(i, mit->name, mit->id,
3021 void GuiDocument::updateIncludeonlys()
3023 masterChildModule->childrenTW->clear();
3024 QString const no = qt_("No");
3025 QString const yes = qt_("Yes");
3027 if (includeonlys_.empty()) {
3028 masterChildModule->includeallRB->setChecked(true);
3029 masterChildModule->childrenTW->setEnabled(false);
3030 masterChildModule->maintainAuxCB->setEnabled(false);
3032 masterChildModule->includeonlyRB->setChecked(true);
3033 masterChildModule->childrenTW->setEnabled(true);
3034 masterChildModule->maintainAuxCB->setEnabled(true);
3036 QTreeWidgetItem * item = 0;
3037 std::vector<Buffer *> children = buffer().getChildren(false);
3038 vector<Buffer *>::const_iterator it = children.begin();
3039 vector<Buffer *>::const_iterator end = children.end();
3040 bool has_unincluded = false;
3041 bool all_unincluded = true;
3042 for (; it != end; ++it) {
3043 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3046 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3047 from_utf8(buffer().filePath())));
3048 item->setText(0, toqstr(name));
3049 item->setText(1, isChildIncluded(name) ? yes : no);
3050 if (!isChildIncluded(name))
3051 has_unincluded = true;
3053 all_unincluded = false;
3055 // Both if all childs are included and if none is included
3056 // is equal to "include all" (i.e., ommit \includeonly).
3057 // Thus, reset the GUI.
3058 if (!has_unincluded || all_unincluded) {
3059 masterChildModule->includeallRB->setChecked(true);
3060 masterChildModule->childrenTW->setEnabled(false);
3061 includeonlys_.clear();
3063 // If all are included, we need to update again.
3064 if (!has_unincluded)
3065 updateIncludeonlys();
3069 void GuiDocument::updateContents()
3071 // Nothing to do here as the document settings is not cursor dependant.
3076 void GuiDocument::useClassDefaults()
3078 if (applyPB->isEnabled()) {
3079 int const ret = Alert::prompt(_("Unapplied changes"),
3080 _("Some changes in the dialog were not yet applied.\n"
3081 "If you do not apply now, they will be lost after this action."),
3082 1, 1, _("&Apply"), _("&Dismiss"));
3087 int idx = latexModule->classCO->currentIndex();
3088 string const classname = classes_model_.getIDString(idx);
3089 if (!bp_.setBaseClass(classname)) {
3090 Alert::error(_("Error"), _("Unable to set document class."));
3093 bp_.useClassDefaults();
3098 void GuiDocument::setLayoutComboByIDString(string const & idString)
3100 int idx = classes_model_.findIDString(idString);
3102 Alert::warning(_("Can't set layout!"),
3103 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3105 latexModule->classCO->setCurrentIndex(idx);
3109 bool GuiDocument::isValid()
3112 validateListingsParameters().isEmpty() &&
3113 localLayout->isValid() &&
3115 // if we're asking for skips between paragraphs
3116 !textLayoutModule->skipRB->isChecked() ||
3117 // then either we haven't chosen custom
3118 textLayoutModule->skipCO->currentIndex() != 3 ||
3119 // or else a length has been given
3120 !textLayoutModule->skipLE->text().isEmpty()
3123 // if we're asking for indentation
3124 !textLayoutModule->indentRB->isChecked() ||
3125 // then either we haven't chosen custom
3126 textLayoutModule->indentCO->currentIndex() != 1 ||
3127 // or else a length has been given
3128 !textLayoutModule->indentLE->text().isEmpty()
3133 char const * const GuiDocument::fontfamilies[5] = {
3134 "default", "rmdefault", "sfdefault", "ttdefault", ""
3138 char const * GuiDocument::fontfamilies_gui[5] = {
3139 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3143 bool GuiDocument::initialiseParams(string const &)
3145 BufferView const * view = bufferview();
3147 bp_ = BufferParams();
3151 bp_ = view->buffer().params();
3153 updateAvailableModules();
3154 //FIXME It'd be nice to make sure here that the selected
3155 //modules are consistent: That required modules are actually
3156 //selected, and that we don't have conflicts. If so, we could
3157 //at least pop up a warning.
3163 void GuiDocument::clearParams()
3165 bp_ = BufferParams();
3169 BufferId GuiDocument::id() const
3171 BufferView const * const view = bufferview();
3172 return view? &view->buffer() : 0;
3176 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3178 return moduleNames_;
3182 list<GuiDocument::modInfoStruct> const
3183 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3185 LayoutModuleList::const_iterator it = mods.begin();
3186 LayoutModuleList::const_iterator end = mods.end();
3187 list<modInfoStruct> mInfo;
3188 for (; it != end; ++it) {
3191 LyXModule const * const mod = theModuleList[*it];
3194 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3196 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3203 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3205 return makeModuleInfo(params().getModules());
3209 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3211 return makeModuleInfo(params().baseClass()->providedModules());
3215 DocumentClass const & GuiDocument::documentClass() const
3217 return bp_.documentClass();
3221 static void dispatch_bufferparams(Dialog const & dialog,
3222 BufferParams const & bp, FuncCode lfun)
3225 ss << "\\begin_header\n";
3227 ss << "\\end_header\n";
3228 dialog.dispatch(FuncRequest(lfun, ss.str()));
3232 void GuiDocument::dispatchParams()
3234 // This must come first so that a language change is correctly noticed
3237 // Apply the BufferParams. Note that this will set the base class
3238 // and then update the buffer's layout.
3239 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3241 if (!params().master.empty()) {
3242 FileName const master_file = support::makeAbsPath(params().master,
3243 support::onlyPath(buffer().absFileName()));
3244 if (isLyXFileName(master_file.absFileName())) {
3245 Buffer * master = checkAndLoadLyXFile(master_file);
3247 if (master->isChild(const_cast<Buffer *>(&buffer())))
3248 const_cast<Buffer &>(buffer()).setParent(master);
3250 Alert::warning(_("Assigned master does not include this file"),
3251 bformat(_("You must include this file in the document\n"
3252 "'%1$s' in order to use the master document\n"
3253 "feature."), from_utf8(params().master)));
3255 Alert::warning(_("Could not load master"),
3256 bformat(_("The master document '%1$s'\n"
3257 "could not be loaded."),
3258 from_utf8(params().master)));
3262 // Generate the colours requested by each new branch.
3263 BranchList & branchlist = params().branchlist();
3264 if (!branchlist.empty()) {
3265 BranchList::const_iterator it = branchlist.begin();
3266 BranchList::const_iterator const end = branchlist.end();
3267 for (; it != end; ++it) {
3268 docstring const & current_branch = it->branch();
3269 Branch const * branch = branchlist.find(current_branch);
3270 string const x11hexname = X11hexname(branch->color());
3271 // display the new color
3272 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3273 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3276 // Open insets of selected branches, close deselected ones
3277 dispatch(FuncRequest(LFUN_INSET_FORALL,
3278 "Branch inset-toggle assign"));
3280 // rename branches in the document
3281 executeBranchRenaming();
3282 // and clear changed branches cache
3283 changedBranches_.clear();
3285 // Generate the colours requested by indices.
3286 IndicesList & indiceslist = params().indiceslist();
3287 if (!indiceslist.empty()) {
3288 IndicesList::const_iterator it = indiceslist.begin();
3289 IndicesList::const_iterator const end = indiceslist.end();
3290 for (; it != end; ++it) {
3291 docstring const & current_index = it->shortcut();
3292 Index const * index = indiceslist.findShortcut(current_index);
3293 string const x11hexname = X11hexname(index->color());
3294 // display the new color
3295 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3296 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3299 // FIXME: If we used an LFUN, we would not need those two lines:
3300 BufferView * bv = const_cast<BufferView *>(bufferview());
3301 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3305 void GuiDocument::setLanguage() const
3307 Language const * const newL = bp_.language;
3308 if (buffer().params().language == newL)
3311 string const & lang_name = newL->lang();
3312 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3316 void GuiDocument::saveAsDefault() const
3318 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3322 bool GuiDocument::isFontAvailable(string const & font) const
3324 if (font == "default" || font == "cmr"
3325 || font == "cmss" || font == "cmtt")
3326 // these are standard
3328 if (font == "lmodern" || font == "lmss" || font == "lmtt")
3329 return LaTeXFeatures::isAvailable("lmodern");
3330 if (font == "times" || font == "palatino"
3331 || font == "helvet" || font == "courier")
3332 return LaTeXFeatures::isAvailable("psnfss");
3333 if (font == "cmbr" || font == "cmtl")
3334 return LaTeXFeatures::isAvailable("cmbright");
3335 if (font == "utopia")
3336 return LaTeXFeatures::isAvailable("utopia")
3337 || LaTeXFeatures::isAvailable("fourier");
3338 if (font == "beraserif" || font == "berasans"
3339 || font == "beramono")
3340 return LaTeXFeatures::isAvailable("bera");
3341 return LaTeXFeatures::isAvailable(font);
3345 bool GuiDocument::providesOSF(string const & font) const
3347 if (outputModule->xetexCB->isChecked())
3348 // FIXME: we should check if the fonts really
3349 // have OSF support. But how?
3352 return isFontAvailable("eco");
3353 if (font == "palatino")
3354 return isFontAvailable("mathpazo");
3359 bool GuiDocument::providesSC(string const & font) const
3361 if (outputModule->xetexCB->isChecked())
3363 if (font == "palatino")
3364 return isFontAvailable("mathpazo");
3365 if (font == "utopia")
3366 return isFontAvailable("fourier");
3371 bool GuiDocument::providesScale(string const & font) const
3373 if (outputModule->xetexCB->isChecked())
3375 return font == "helvet" || font == "luximono"
3376 || font == "berasans" || font == "beramono";
3380 void GuiDocument::loadModuleInfo()
3382 moduleNames_.clear();
3383 LyXModuleList::const_iterator it = theModuleList.begin();
3384 LyXModuleList::const_iterator end = theModuleList.end();
3385 for (; it != end; ++it) {
3389 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3390 // this is supposed to give us the first sentence of the description
3393 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3394 int const pos = desc.indexOf(".");
3396 desc.truncate(pos + 1);
3397 m.description = desc;
3398 moduleNames_.push_back(m);
3403 void GuiDocument::updateUnknownBranches()
3407 list<docstring> used_branches;
3408 buffer().getUsedBranches(used_branches);
3409 list<docstring>::const_iterator it = used_branches.begin();
3410 QStringList unknown_branches;
3411 for (; it != used_branches.end() ; ++it) {
3412 if (!buffer().params().branchlist().find(*it))
3413 unknown_branches.append(toqstr(*it));
3415 branchesModule->setUnknownBranches(unknown_branches);
3419 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3421 map<docstring, docstring>::iterator it = changedBranches_.begin();
3422 for (; it != changedBranches_.end() ; ++it) {
3423 if (it->second == oldname) {
3424 // branch has already been renamed
3425 it->second = newname;
3430 changedBranches_[oldname] = newname;
3434 void GuiDocument::executeBranchRenaming() const
3436 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3437 for (; it != changedBranches_.end() ; ++it) {
3438 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3439 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3444 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3447 } // namespace frontend
3450 #include "moc_GuiDocument.cpp"