2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "GuiApplication.h"
17 #include "GuiBranches.h"
18 #include "GuiIndices.h"
19 #include "GuiSelectionManager.h"
20 #include "LaTeXHighlighter.h"
21 #include "LengthCombo.h"
22 #include "PanelStack.h"
23 #include "Validator.h"
25 #include "LayoutFile.h"
26 #include "BranchList.h"
27 #include "buffer_funcs.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
32 #include "ColorCache.h"
34 #include "FloatPlacement.h"
36 #include "FuncRequest.h"
38 #include "IndicesList.h"
40 #include "LaTeXFeatures.h"
42 #include "LayoutModuleList.h"
44 #include "ModuleList.h"
45 #include "OutputParams.h"
46 #include "PDFOptions.h"
47 #include "qt_helpers.h"
49 #include "TextClass.h"
51 #include "insets/InsetListingsParams.h"
53 #include "support/debug.h"
54 #include "support/FileName.h"
55 #include "support/filetools.h"
56 #include "support/gettext.h"
57 #include "support/lassert.h"
58 #include "support/lstrings.h"
60 #include "frontends/alert.h"
62 #include <QAbstractItemModel>
63 #include <QHeaderView>
65 #include <QColorDialog>
66 #include <QCloseEvent>
67 #include <QFontDatabase>
69 #include <QTextCursor>
79 // a style sheet for buttons
80 // this is for example used for the background color setting button
81 static inline QString colorButtonStyleSheet(QColor const & bgColor)
83 if (bgColor.isValid()) {
84 QString rc = QLatin1String("background-color:");
93 using namespace lyx::support;
98 char const * const tex_graphics[] =
100 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
101 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
102 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
103 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
108 char const * const tex_graphics_gui[] =
110 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
111 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
112 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
113 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
114 "XeTeX", N_("None"), ""
118 char const * const tex_fonts_roman[] =
120 "default", "cmr", "lmodern", "ae", "times", "palatino",
121 "charter", "newcent", "bookman", "utopia", "beraserif",
122 "ccfonts", "chancery", ""
126 char const * tex_fonts_roman_gui[] =
128 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
129 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
130 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
131 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
136 char const * const tex_fonts_sans[] =
138 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
142 char const * tex_fonts_sans_gui[] =
144 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
145 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
149 char const * const tex_fonts_monospaced[] =
151 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
155 char const * tex_fonts_monospaced_gui[] =
157 N_("Default"), N_("Computer Modern Typewriter"),
158 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
159 N_("LuxiMono"), N_("CM Typewriter Light"), ""
163 char const * backref_opts[] =
165 "false", "section", "slide", "page", ""
169 char const * backref_opts_gui[] =
171 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
175 char const * packages_gui[][4] =
178 N_("&Use AMS math package automatically"),
179 N_("Use AMS &math package"),
180 N_("The AMS LaTeX packages are only used if symbols from the AMS math toolbars are inserted into formulas")},
182 N_("Use esint package &automatically"),
183 N_("Use &esint package"),
184 N_("The LaTeX package esint is only used if special integral symbols are inserted into formulas")},
186 N_("Use math&dots package automatically"),
187 N_("Use mathdo&ts package"),
188 N_("The LaTeX package mathdots is only used if the command \\iddots is inserted into formulas")},
190 N_("Use mathtools package automatically"),
191 N_("Use mathtools package"),
192 N_("The LaTeX package mathtools is only used if some mathematical relations are inserted into formulas")},
194 N_("Use mhchem &package automatically"),
195 N_("Use mh&chem package"),
196 N_("The LaTeX package mhchem is only used if either the command \\ce or \\cf is inserted into formulas")},
198 N_("Use u&ndertilde package automatically"),
199 N_("Use undertilde pac&kage"),
200 N_("The LaTeX package undertilde is only used if you use the math frame decoration 'utilde'")},
205 vector<string> engine_types_;
206 vector<pair<string, QString> > pagestyles;
209 } // anonymous namespace
213 RGBColor set_backgroundcolor;
214 bool is_backgroundcolor;
215 RGBColor set_fontcolor;
217 RGBColor set_notefontcolor;
218 RGBColor set_boxbgcolor;
221 // used when sorting the textclass list.
222 class less_textclass_avail_desc
223 : public binary_function<string, string, int>
226 bool operator()(string const & lhs, string const & rhs) const
228 // Ordering criteria:
229 // 1. Availability of text class
230 // 2. Description (lexicographic)
231 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
232 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
233 int const order = compare_no_case(
234 translateIfPossible(from_utf8(tc1.description())),
235 translateIfPossible(from_utf8(tc2.description())));
236 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
237 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
246 vector<string> getRequiredList(string const & modName)
248 LyXModule const * const mod = theModuleList[modName];
250 return vector<string>(); //empty such thing
251 return mod->getRequiredModules();
255 vector<string> getExcludedList(string const & modName)
257 LyXModule const * const mod = theModuleList[modName];
259 return vector<string>(); //empty such thing
260 return mod->getExcludedModules();
264 docstring getModuleCategory(string const & modName)
266 LyXModule const * const mod = theModuleList[modName];
269 return from_utf8(mod->category());
273 docstring getModuleDescription(string const & modName)
275 LyXModule const * const mod = theModuleList[modName];
277 return _("Module not found!");
279 return translateIfPossible(from_utf8(mod->getDescription()));
283 vector<string> getPackageList(string const & modName)
285 LyXModule const * const mod = theModuleList[modName];
287 return vector<string>(); //empty such thing
288 return mod->getPackageList();
292 bool isModuleAvailable(string const & modName)
294 LyXModule const * const mod = theModuleList[modName];
297 return mod->isAvailable();
300 } // anonymous namespace
303 /////////////////////////////////////////////////////////////////////
305 // ModuleSelectionManager
307 /////////////////////////////////////////////////////////////////////
309 /// SelectionManager for use with modules
310 class ModuleSelectionManager : public GuiSelectionManager
314 ModuleSelectionManager(
315 QTreeView * availableLV,
316 QListView * selectedLV,
320 QPushButton * downPB,
321 GuiIdListModel * availableModel,
322 GuiIdListModel * selectedModel,
323 GuiDocument const * container)
324 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
325 upPB, downPB, availableModel, selectedModel), container_(container)
328 void updateProvidedModules(LayoutModuleList const & pm)
329 { provided_modules_ = pm.list(); }
331 void updateExcludedModules(LayoutModuleList const & em)
332 { excluded_modules_ = em.list(); }
335 virtual void updateAddPB();
337 virtual void updateUpPB();
339 virtual void updateDownPB();
341 virtual void updateDelPB();
342 /// returns availableModel as a GuiIdListModel
343 GuiIdListModel * getAvailableModel()
345 return dynamic_cast<GuiIdListModel *>(availableModel);
347 /// returns selectedModel as a GuiIdListModel
348 GuiIdListModel * getSelectedModel()
350 return dynamic_cast<GuiIdListModel *>(selectedModel);
352 /// keeps a list of the modules the text class provides
353 list<string> provided_modules_;
355 list<string> excluded_modules_;
357 GuiDocument const * container_;
360 void ModuleSelectionManager::updateAddPB()
362 int const arows = availableModel->rowCount();
363 QModelIndexList const avail_sels =
364 availableLV->selectionModel()->selectedIndexes();
366 // disable if there aren't any modules (?), if none of them is chosen
367 // in the dialog, or if the chosen one is already selected for use.
368 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
369 addPB->setEnabled(false);
373 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
374 string const modname = getAvailableModel()->getIDString(idx.row());
377 container_->params().moduleCanBeAdded(modname);
378 addPB->setEnabled(enable);
382 void ModuleSelectionManager::updateDownPB()
384 int const srows = selectedModel->rowCount();
386 downPB->setEnabled(false);
389 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
390 int const curRow = curidx.row();
391 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
392 downPB->setEnabled(false);
396 // determine whether immediately succeding element requires this one
397 string const curmodname = getSelectedModel()->getIDString(curRow);
398 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
400 vector<string> reqs = getRequiredList(nextmodname);
402 // if it doesn't require anything....
404 downPB->setEnabled(true);
408 // Enable it if this module isn't required.
409 // FIXME This should perhaps be more flexible and check whether, even
410 // if the next one is required, there is also an earlier one that will do.
412 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
415 void ModuleSelectionManager::updateUpPB()
417 int const srows = selectedModel->rowCount();
419 upPB->setEnabled(false);
423 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
424 int curRow = curIdx.row();
425 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
426 upPB->setEnabled(false);
429 string const curmodname = getSelectedModel()->getIDString(curRow);
431 // determine whether immediately preceding element is required by this one
432 vector<string> reqs = getRequiredList(curmodname);
434 // if this one doesn't require anything....
436 upPB->setEnabled(true);
441 // Enable it if the preceding module isn't required.
442 // NOTE This is less flexible than it might be. We could check whether, even
443 // if the previous one is required, there is an earlier one that would do.
444 string const premod = getSelectedModel()->getIDString(curRow - 1);
445 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
448 void ModuleSelectionManager::updateDelPB()
450 int const srows = selectedModel->rowCount();
452 deletePB->setEnabled(false);
456 QModelIndex const & curidx =
457 selectedLV->selectionModel()->currentIndex();
458 int const curRow = curidx.row();
459 if (curRow < 0 || curRow >= srows) { // invalid index?
460 deletePB->setEnabled(false);
464 string const curmodname = getSelectedModel()->getIDString(curRow);
466 // We're looking here for a reason NOT to enable the button. If we
467 // find one, we disable it and return. If we don't, we'll end up at
468 // the end of the function, and then we enable it.
469 for (int i = curRow + 1; i < srows; ++i) {
470 string const thisMod = getSelectedModel()->getIDString(i);
471 vector<string> reqs = getRequiredList(thisMod);
472 //does this one require us?
473 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
477 // OK, so this module requires us
478 // is there an EARLIER module that also satisfies the require?
479 // NOTE We demand that it be earlier to keep the list of modules
480 // consistent with the rule that a module must be proceeded by a
481 // required module. There would be more flexible ways to proceed,
482 // but that would be a lot more complicated, and the logic here is
483 // already complicated. (That's why I've left the debugging code.)
484 // lyxerr << "Testing " << thisMod << endl;
485 bool foundone = false;
486 for (int j = 0; j < curRow; ++j) {
487 string const mod = getSelectedModel()->getIDString(j);
488 // lyxerr << "In loop: Testing " << mod << endl;
489 // do we satisfy the require?
490 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
491 // lyxerr << mod << " does the trick." << endl;
496 // did we find a module to satisfy the require?
498 // lyxerr << "No matching module found." << endl;
499 deletePB->setEnabled(false);
503 // lyxerr << "All's well that ends well." << endl;
504 deletePB->setEnabled(true);
508 /////////////////////////////////////////////////////////////////////
512 /////////////////////////////////////////////////////////////////////
514 PreambleModule::PreambleModule() : current_id_(0)
516 // This is not a memory leak. The object will be destroyed
518 (void) new LaTeXHighlighter(preambleTE->document());
519 setFocusProxy(preambleTE);
520 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
524 void PreambleModule::update(BufferParams const & params, BufferId id)
526 QString preamble = toqstr(params.preamble);
527 // Nothing to do if the params and preamble are unchanged.
528 if (id == current_id_
529 && preamble == preambleTE->document()->toPlainText())
532 QTextCursor cur = preambleTE->textCursor();
533 // Save the coords before switching to the new one.
534 preamble_coords_[current_id_] =
535 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
537 // Save the params address for further use.
539 preambleTE->document()->setPlainText(preamble);
540 Coords::const_iterator it = preamble_coords_.find(current_id_);
541 if (it == preamble_coords_.end())
542 // First time we open this one.
543 preamble_coords_[current_id_] = make_pair(0, 0);
545 // Restore saved coords.
546 QTextCursor cur = preambleTE->textCursor();
547 cur.setPosition(it->second.first);
548 preambleTE->setTextCursor(cur);
549 preambleTE->verticalScrollBar()->setValue(it->second.second);
554 void PreambleModule::apply(BufferParams & params)
556 params.preamble = fromqstr(preambleTE->document()->toPlainText());
560 void PreambleModule::closeEvent(QCloseEvent * e)
562 // Save the coords before closing.
563 QTextCursor cur = preambleTE->textCursor();
564 preamble_coords_[current_id_] =
565 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
570 /////////////////////////////////////////////////////////////////////
574 /////////////////////////////////////////////////////////////////////
577 LocalLayout::LocalLayout() : current_id_(0), is_valid_(false)
579 connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
580 connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
581 connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
585 void LocalLayout::update(BufferParams const & params, BufferId id)
587 QString layout = toqstr(params.local_layout);
588 // Nothing to do if the params and preamble are unchanged.
589 if (id == current_id_
590 && layout == locallayoutTE->document()->toPlainText())
593 // Save the params address for further use.
595 locallayoutTE->document()->setPlainText(layout);
600 void LocalLayout::apply(BufferParams & params)
602 string const layout = fromqstr(locallayoutTE->document()->toPlainText());
603 params.local_layout = layout;
607 void LocalLayout::textChanged()
609 static const QString unknown = qt_("Press button to check validity...");
612 validLB->setText(unknown);
613 validatePB->setEnabled(true);
614 convertPB->setEnabled(false);
619 void LocalLayout::convert() {
620 string const layout =
621 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
622 string const newlayout = TextClass::convert(layout);
624 if (newlayout.empty()) {
625 Alert::error(_("Conversion Failed!"),
626 _("Failed to convert local layout to current format."));
628 locallayoutTE->setPlainText(toqstr(newlayout));
634 void LocalLayout::convertPressed() {
640 void LocalLayout::validate() {
641 static const QString valid = qt_("Layout is valid!");
642 static const QString vtext =
643 toqstr("<p style=\"font-weight: bold; \">")
644 + valid + toqstr("</p>");
645 static const QString invalid = qt_("Layout is invalid!");
646 static const QString ivtext =
647 toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
648 + invalid + toqstr("</p>");
650 string const layout =
651 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
652 if (layout.empty()) {
654 validatePB->setEnabled(false);
655 validLB->setText("");
659 TextClass::ReturnValues const ret = TextClass::validate(layout);
660 is_valid_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
661 validatePB->setEnabled(false);
662 validLB->setText(is_valid_ ? vtext : ivtext);
663 if (ret == TextClass::OK_OLDFORMAT) {
665 convertPB->setEnabled(true);
666 convertLB->setText(qt_("Convert to current format"));
676 void LocalLayout::validatePressed() {
682 /////////////////////////////////////////////////////////////////////
686 /////////////////////////////////////////////////////////////////////
689 GuiDocument::GuiDocument(GuiView & lv)
690 : GuiDialog(lv, "document", qt_("Document Settings"))
694 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
695 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
696 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
697 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
699 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
700 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
702 // Manage the restore, ok, apply, restore and cancel/close buttons
703 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
705 bc().setApply(applyPB);
706 bc().setCancel(closePB);
707 bc().setRestore(restorePB);
711 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
712 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
713 this, SLOT(change_adaptor()));
714 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
715 this, SLOT(setLSpacing(int)));
716 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
717 this, SLOT(change_adaptor()));
719 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
720 this, SLOT(change_adaptor()));
721 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
722 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
723 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
724 this, SLOT(change_adaptor()));
725 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
726 this, SLOT(setIndent(int)));
727 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
728 this, SLOT(change_adaptor()));
729 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
730 this, SLOT(change_adaptor()));
732 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
733 this, SLOT(change_adaptor()));
734 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
735 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
736 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
737 this, SLOT(change_adaptor()));
738 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
739 this, SLOT(setSkip(int)));
740 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
741 this, SLOT(change_adaptor()));
742 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
743 this, SLOT(change_adaptor()));
745 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
746 this, SLOT(enableIndent(bool)));
747 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
748 this, SLOT(enableSkip(bool)));
750 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
751 this, SLOT(change_adaptor()));
752 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
753 this, SLOT(setColSep()));
754 connect(textLayoutModule->justCB, SIGNAL(clicked()),
755 this, SLOT(change_adaptor()));
757 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
758 textLayoutModule->lspacingLE));
759 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
760 textLayoutModule->indentLE));
761 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
762 textLayoutModule->skipLE));
764 textLayoutModule->indentCO->addItem(qt_("Default"));
765 textLayoutModule->indentCO->addItem(qt_("Custom"));
766 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
767 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
768 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
769 textLayoutModule->skipCO->addItem(qt_("Custom"));
770 textLayoutModule->lspacingCO->insertItem(
771 Spacing::Single, qt_("Single"));
772 textLayoutModule->lspacingCO->insertItem(
773 Spacing::Onehalf, qt_("OneHalf"));
774 textLayoutModule->lspacingCO->insertItem(
775 Spacing::Double, qt_("Double"));
776 textLayoutModule->lspacingCO->insertItem(
777 Spacing::Other, qt_("Custom"));
778 // initialize the length validator
779 bc().addCheckedLineEdit(textLayoutModule->indentLE);
780 bc().addCheckedLineEdit(textLayoutModule->skipLE);
783 // master/child handling
784 masterChildModule = new UiWidget<Ui::MasterChildUi>;
786 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
787 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
788 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
789 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
790 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
791 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
792 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
793 this, SLOT(change_adaptor()));
794 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
795 this, SLOT(change_adaptor()));
796 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
797 this, SLOT(change_adaptor()));
798 masterChildModule->childrenTW->setColumnCount(2);
799 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
800 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
801 masterChildModule->childrenTW->resizeColumnToContents(1);
802 masterChildModule->childrenTW->resizeColumnToContents(2);
806 outputModule = new UiWidget<Ui::OutputUi>;
808 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
809 this, SLOT(change_adaptor()));
810 connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
811 this, SLOT(change_adaptor()));
812 connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
813 this, SLOT(change_adaptor()));
814 connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
815 this, SLOT(change_adaptor()));
816 connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
817 this, SLOT(change_adaptor()));
819 connect(outputModule->outputsyncCB, SIGNAL(clicked()),
820 this, SLOT(change_adaptor()));
821 connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
822 this, SLOT(change_adaptor()));
823 outputModule->synccustomCB->addItem("");
824 outputModule->synccustomCB->addItem("\\synctex=1");
825 outputModule->synccustomCB->addItem("\\synctex=-1");
826 outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
828 outputModule->synccustomCB->setValidator(new NoNewLineValidator(
829 outputModule->synccustomCB));
832 fontModule = new UiWidget<Ui::FontUi>;
833 connect(fontModule->osFontsCB, SIGNAL(clicked()),
834 this, SLOT(change_adaptor()));
835 connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
836 this, SLOT(osFontsChanged(bool)));
837 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
838 this, SLOT(change_adaptor()));
839 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
840 this, SLOT(romanChanged(int)));
841 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
842 this, SLOT(change_adaptor()));
843 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
844 this, SLOT(sansChanged(int)));
845 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
846 this, SLOT(change_adaptor()));
847 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
848 this, SLOT(ttChanged(int)));
849 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
850 this, SLOT(change_adaptor()));
851 connect(fontModule->fontencCO, SIGNAL(activated(int)),
852 this, SLOT(change_adaptor()));
853 connect(fontModule->fontencCO, SIGNAL(activated(int)),
854 this, SLOT(fontencChanged(int)));
855 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
856 this, SLOT(change_adaptor()));
857 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
858 this, SLOT(change_adaptor()));
859 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
860 this, SLOT(change_adaptor()));
861 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
862 this, SLOT(change_adaptor()));
863 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
864 this, SLOT(change_adaptor()));
865 connect(fontModule->fontScCB, SIGNAL(clicked()),
866 this, SLOT(change_adaptor()));
867 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
868 this, SLOT(change_adaptor()));
870 fontModule->fontencLE->setValidator(new NoNewLineValidator(
871 fontModule->fontencLE));
872 fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
873 fontModule->cjkFontLE));
877 fontModule->fontsizeCO->addItem(qt_("Default"));
878 fontModule->fontsizeCO->addItem(qt_("10"));
879 fontModule->fontsizeCO->addItem(qt_("11"));
880 fontModule->fontsizeCO->addItem(qt_("12"));
882 fontModule->fontencCO->addItem(qt_("Default"));
883 fontModule->fontencCO->addItem(qt_("Custom"));
884 fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
886 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
887 fontModule->fontsDefaultCO->addItem(
888 qt_(GuiDocument::fontfamilies_gui[n]));
890 if (!LaTeXFeatures::isAvailable("fontspec"))
891 fontModule->osFontsCB->setToolTip(
892 qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
893 "You need to install the package \"fontspec\" to use this feature"));
897 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
898 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
899 this, SLOT(papersizeChanged(int)));
900 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
901 this, SLOT(papersizeChanged(int)));
902 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
903 this, SLOT(change_adaptor()));
904 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
905 this, SLOT(change_adaptor()));
906 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
907 this, SLOT(change_adaptor()));
908 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
909 this, SLOT(change_adaptor()));
910 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
911 this, SLOT(change_adaptor()));
912 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
913 this, SLOT(change_adaptor()));
914 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
915 this, SLOT(change_adaptor()));
916 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
917 this, SLOT(change_adaptor()));
918 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
919 this, SLOT(change_adaptor()));
920 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
921 this, SLOT(change_adaptor()));
923 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
924 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
925 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
926 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
927 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
928 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
929 pageLayoutModule->paperheightL);
930 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
931 pageLayoutModule->paperwidthL);
933 QComboBox * cb = pageLayoutModule->papersizeCO;
934 cb->addItem(qt_("Default"));
935 cb->addItem(qt_("Custom"));
936 cb->addItem(qt_("US letter"));
937 cb->addItem(qt_("US legal"));
938 cb->addItem(qt_("US executive"));
939 cb->addItem(qt_("A0"));
940 cb->addItem(qt_("A1"));
941 cb->addItem(qt_("A2"));
942 cb->addItem(qt_("A3"));
943 cb->addItem(qt_("A4"));
944 cb->addItem(qt_("A5"));
945 cb->addItem(qt_("A6"));
946 cb->addItem(qt_("B0"));
947 cb->addItem(qt_("B1"));
948 cb->addItem(qt_("B2"));
949 cb->addItem(qt_("B3"));
950 cb->addItem(qt_("B4"));
951 cb->addItem(qt_("B5"));
952 cb->addItem(qt_("B6"));
953 cb->addItem(qt_("C0"));
954 cb->addItem(qt_("C1"));
955 cb->addItem(qt_("C2"));
956 cb->addItem(qt_("C3"));
957 cb->addItem(qt_("C4"));
958 cb->addItem(qt_("C5"));
959 cb->addItem(qt_("C6"));
960 cb->addItem(qt_("JIS B0"));
961 cb->addItem(qt_("JIS B1"));
962 cb->addItem(qt_("JIS B2"));
963 cb->addItem(qt_("JIS B3"));
964 cb->addItem(qt_("JIS B4"));
965 cb->addItem(qt_("JIS B5"));
966 cb->addItem(qt_("JIS B6"));
967 // remove the %-items from the unit choice
968 pageLayoutModule->paperwidthUnitCO->noPercents();
969 pageLayoutModule->paperheightUnitCO->noPercents();
970 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
971 pageLayoutModule->paperheightLE));
972 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
973 pageLayoutModule->paperwidthLE));
977 marginsModule = new UiWidget<Ui::MarginsUi>;
978 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
979 this, SLOT(setCustomMargins(bool)));
980 connect(marginsModule->marginCB, SIGNAL(clicked()),
981 this, SLOT(change_adaptor()));
982 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
983 this, SLOT(change_adaptor()));
984 connect(marginsModule->topUnit, SIGNAL(activated(int)),
985 this, SLOT(change_adaptor()));
986 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
987 this, SLOT(change_adaptor()));
988 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
989 this, SLOT(change_adaptor()));
990 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
991 this, SLOT(change_adaptor()));
992 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
993 this, SLOT(change_adaptor()));
994 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
995 this, SLOT(change_adaptor()));
996 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
997 this, SLOT(change_adaptor()));
998 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
999 this, SLOT(change_adaptor()));
1000 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1001 this, SLOT(change_adaptor()));
1002 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1003 this, SLOT(change_adaptor()));
1004 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1005 this, SLOT(change_adaptor()));
1006 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1007 this, SLOT(change_adaptor()));
1008 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1009 this, SLOT(change_adaptor()));
1010 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1011 this, SLOT(change_adaptor()));
1012 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1013 this, SLOT(change_adaptor()));
1014 marginsModule->topLE->setValidator(unsignedLengthValidator(
1015 marginsModule->topLE));
1016 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
1017 marginsModule->bottomLE));
1018 marginsModule->innerLE->setValidator(unsignedLengthValidator(
1019 marginsModule->innerLE));
1020 marginsModule->outerLE->setValidator(unsignedLengthValidator(
1021 marginsModule->outerLE));
1022 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
1023 marginsModule->headsepLE));
1024 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
1025 marginsModule->headheightLE));
1026 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
1027 marginsModule->footskipLE));
1028 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
1029 marginsModule->columnsepLE));
1031 bc().addCheckedLineEdit(marginsModule->topLE,
1032 marginsModule->topL);
1033 bc().addCheckedLineEdit(marginsModule->bottomLE,
1034 marginsModule->bottomL);
1035 bc().addCheckedLineEdit(marginsModule->innerLE,
1036 marginsModule->innerL);
1037 bc().addCheckedLineEdit(marginsModule->outerLE,
1038 marginsModule->outerL);
1039 bc().addCheckedLineEdit(marginsModule->headsepLE,
1040 marginsModule->headsepL);
1041 bc().addCheckedLineEdit(marginsModule->headheightLE,
1042 marginsModule->headheightL);
1043 bc().addCheckedLineEdit(marginsModule->footskipLE,
1044 marginsModule->footskipL);
1045 bc().addCheckedLineEdit(marginsModule->columnsepLE,
1046 marginsModule->columnsepL);
1050 langModule = new UiWidget<Ui::LanguageUi>;
1051 connect(langModule->languageCO, SIGNAL(activated(int)),
1052 this, SLOT(change_adaptor()));
1053 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1054 this, SLOT(change_adaptor()));
1055 connect(langModule->otherencodingRB, SIGNAL(clicked()),
1056 this, SLOT(change_adaptor()));
1057 connect(langModule->encodingCO, SIGNAL(activated(int)),
1058 this, SLOT(change_adaptor()));
1059 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1060 this, SLOT(change_adaptor()));
1061 connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1062 this, SLOT(change_adaptor()));
1063 connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1064 this, SLOT(change_adaptor()));
1065 connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1066 this, SLOT(languagePackageChanged(int)));
1068 langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1069 langModule->languagePackageLE));
1071 QAbstractItemModel * language_model = guiApp->languageModel();
1072 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1073 language_model->sort(0);
1074 langModule->languageCO->setModel(language_model);
1075 langModule->languageCO->setModelColumn(0);
1077 // Always put the default encoding in the first position.
1078 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1079 QStringList encodinglist;
1080 Encodings::const_iterator it = encodings.begin();
1081 Encodings::const_iterator const end = encodings.end();
1082 for (; it != end; ++it)
1083 encodinglist.append(qt_(it->guiName()));
1084 encodinglist.sort();
1085 langModule->encodingCO->addItems(encodinglist);
1087 langModule->quoteStyleCO->addItem(qt_("``text''"));
1088 langModule->quoteStyleCO->addItem(qt_("''text''"));
1089 langModule->quoteStyleCO->addItem(qt_(",,text``"));
1090 langModule->quoteStyleCO->addItem(qt_(",,text''"));
1091 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
1092 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
1094 langModule->languagePackageCO->addItem(
1095 qt_("Default"), toqstr("default"));
1096 langModule->languagePackageCO->addItem(
1097 qt_("Automatic"), toqstr("auto"));
1098 langModule->languagePackageCO->addItem(
1099 qt_("Always Babel"), toqstr("babel"));
1100 langModule->languagePackageCO->addItem(
1101 qt_("Custom"), toqstr("custom"));
1102 langModule->languagePackageCO->addItem(
1103 qt_("None[[language package]]"), toqstr("none"));
1107 colorModule = new UiWidget<Ui::ColorUi>;
1108 connect(colorModule->fontColorPB, SIGNAL(clicked()),
1109 this, SLOT(changeFontColor()));
1110 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1111 this, SLOT(deleteFontColor()));
1112 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1113 this, SLOT(changeNoteFontColor()));
1114 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1115 this, SLOT(deleteNoteFontColor()));
1116 connect(colorModule->backgroundPB, SIGNAL(clicked()),
1117 this, SLOT(changeBackgroundColor()));
1118 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1119 this, SLOT(deleteBackgroundColor()));
1120 connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1121 this, SLOT(changeBoxBackgroundColor()));
1122 connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1123 this, SLOT(deleteBoxBackgroundColor()));
1127 numberingModule = new UiWidget<Ui::NumberingUi>;
1128 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1129 this, SLOT(change_adaptor()));
1130 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1131 this, SLOT(change_adaptor()));
1132 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1133 this, SLOT(updateNumbering()));
1134 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1135 this, SLOT(updateNumbering()));
1136 numberingModule->tocTW->setColumnCount(3);
1137 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1138 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1139 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1140 numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents);
1144 biblioModule = new UiWidget<Ui::BiblioUi>;
1145 connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)),
1146 this, SLOT(setNumerical(bool)));
1147 connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)),
1148 this, SLOT(setAuthorYear(bool)));
1149 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1150 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1151 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1152 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1153 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1154 this, SLOT(biblioChanged()));
1155 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1156 this, SLOT(biblioChanged()));
1157 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1158 this, SLOT(biblioChanged()));
1159 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1160 this, SLOT(biblioChanged()));
1161 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1162 this, SLOT(biblioChanged()));
1163 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1164 this, SLOT(bibtexChanged(int)));
1165 connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1166 this, SLOT(biblioChanged()));
1167 connect(biblioModule->bibtexStyleLE, SIGNAL(textChanged(QString)),
1168 this, SLOT(biblioChanged()));
1170 biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1171 biblioModule->bibtexOptionsLE));
1172 biblioModule->bibtexStyleLE->setValidator(new NoNewLineValidator(
1173 biblioModule->bibtexStyleLE));
1175 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1176 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1177 biblioModule->citeStyleCO->setCurrentIndex(0);
1179 // NOTE: we do not provide "custom" here for security reasons!
1180 biblioModule->bibtexCO->clear();
1181 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1182 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1183 it != lyxrc.bibtex_alternatives.end(); ++it) {
1184 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1185 biblioModule->bibtexCO->addItem(command, command);
1190 indicesModule = new GuiIndices;
1191 connect(indicesModule, SIGNAL(changed()),
1192 this, SLOT(change_adaptor()));
1196 // FIXME This UI has problems:
1197 // 1) It is not generic, packages_gui needs to be changed for each new package
1198 // 2) Two checkboxes have 4 states, but one is invalid (both pressed)
1199 // 3) The auto cb is not disabled if the use cb is checked
1200 mathsModule = new UiWidget<Ui::MathsUi>;
1201 vector<string> const & packages = BufferParams::auto_packages();
1202 for (size_t i = 0; i < packages.size(); ++i) {
1203 // Use the order of BufferParams::auto_packages() for easier
1204 // access in applyView() and paramsToDialog()
1206 for (n = 0; packages_gui[n][0][0]; n++)
1207 if (packages_gui[n][0] == packages[i])
1209 // If this fires somebody changed
1210 // BufferParams::auto_packages() without adjusting packages_gui
1211 LASSERT(packages_gui[n][0][0], /**/);
1212 QString autoText = qt_(packages_gui[n][1]);
1213 QString alwaysText = qt_(packages_gui[n][2]);
1214 QString autoTooltip = qt_(packages_gui[n][3]);
1215 QString alwaysTooltip;
1216 if (packages[i] == "amsmath")
1218 qt_("The AMS LaTeX packages are always used");
1220 alwaysTooltip = toqstr(bformat(
1221 _("The LaTeX package %1$s is always used"),
1222 from_ascii(packages[i])));
1223 QCheckBox * autoCB = new QCheckBox(autoText, mathsModule);
1224 QCheckBox * alwaysCB = new QCheckBox(alwaysText, mathsModule);
1225 mathsModule->gridLayout->addWidget(autoCB, 2 * i, 0);
1226 mathsModule->gridLayout->addWidget(alwaysCB, 2 * i + 1, 0);
1227 autoCB->setToolTip(autoTooltip);
1228 alwaysCB->setToolTip(alwaysTooltip);
1229 connect(autoCB, SIGNAL(toggled(bool)),
1230 alwaysCB, SLOT(setDisabled(bool)));
1231 connect(autoCB, SIGNAL(clicked()),
1232 this, SLOT(change_adaptor()));
1233 connect(alwaysCB, SIGNAL(clicked()),
1234 this, SLOT(change_adaptor()));
1236 QSpacerItem * spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum,
1237 QSizePolicy::Expanding);
1238 mathsModule->gridLayout->addItem(spacer, 2 * packages.size(), 0);
1242 latexModule = new UiWidget<Ui::LaTeXUi>;
1243 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1244 this, SLOT(change_adaptor()));
1245 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1246 this, SLOT(change_adaptor()));
1247 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1248 this, SLOT(change_adaptor()));
1249 connect(latexModule->classCO, SIGNAL(activated(int)),
1250 this, SLOT(classChanged()));
1251 connect(latexModule->classCO, SIGNAL(activated(int)),
1252 this, SLOT(change_adaptor()));
1253 connect(latexModule->layoutPB, SIGNAL(clicked()),
1254 this, SLOT(browseLayout()));
1255 connect(latexModule->layoutPB, SIGNAL(clicked()),
1256 this, SLOT(change_adaptor()));
1257 connect(latexModule->childDocGB, SIGNAL(clicked()),
1258 this, SLOT(change_adaptor()));
1259 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1260 this, SLOT(change_adaptor()));
1261 connect(latexModule->childDocPB, SIGNAL(clicked()),
1262 this, SLOT(browseMaster()));
1263 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1264 this, SLOT(change_adaptor()));
1265 connect(latexModule->refstyleCB, SIGNAL(clicked()),
1266 this, SLOT(change_adaptor()));
1268 latexModule->optionsLE->setValidator(new NoNewLineValidator(
1269 latexModule->optionsLE));
1270 latexModule->childDocLE->setValidator(new NoNewLineValidator(
1271 latexModule->childDocLE));
1273 // postscript drivers
1274 for (int n = 0; tex_graphics[n][0]; ++n) {
1275 QString enc = qt_(tex_graphics_gui[n]);
1276 latexModule->psdriverCO->addItem(enc);
1279 latexModule->classCO->setModel(&classes_model_);
1280 LayoutFileList const & bcl = LayoutFileList::get();
1281 vector<LayoutFileIndex> classList = bcl.classList();
1282 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1284 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1285 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1286 for (int i = 0; cit != cen; ++cit, ++i) {
1287 LayoutFile const & tc = bcl[*cit];
1288 docstring item = (tc.isTeXClassAvailable()) ?
1289 from_utf8(tc.description()) :
1290 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1291 classes_model_.insertRow(i, toqstr(item), *cit);
1296 branchesModule = new GuiBranches;
1297 connect(branchesModule, SIGNAL(changed()),
1298 this, SLOT(change_adaptor()));
1299 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1300 this, SLOT(branchesRename(docstring const &, docstring const &)));
1301 connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1302 updateUnknownBranches();
1306 preambleModule = new PreambleModule;
1307 connect(preambleModule, SIGNAL(changed()),
1308 this, SLOT(change_adaptor()));
1310 localLayout = new LocalLayout;
1311 connect(localLayout, SIGNAL(changed()),
1312 this, SLOT(change_adaptor()));
1316 bulletsModule = new BulletsModule;
1317 connect(bulletsModule, SIGNAL(changed()),
1318 this, SLOT(change_adaptor()));
1322 modulesModule = new UiWidget<Ui::ModulesUi>;
1323 modulesModule->availableLV->header()->setVisible(false);
1324 modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents);
1325 modulesModule->availableLV->header()->setStretchLastSection(false);
1327 new ModuleSelectionManager(modulesModule->availableLV,
1328 modulesModule->selectedLV,
1329 modulesModule->addPB, modulesModule->deletePB,
1330 modulesModule->upPB, modulesModule->downPB,
1331 availableModel(), selectedModel(), this);
1332 connect(selectionManager, SIGNAL(updateHook()),
1333 this, SLOT(updateModuleInfo()));
1334 connect(selectionManager, SIGNAL(updateHook()),
1335 this, SLOT(change_adaptor()));
1336 connect(selectionManager, SIGNAL(selectionChanged()),
1337 this, SLOT(modulesChanged()));
1341 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1342 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1343 this, SLOT(change_adaptor()));
1344 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1345 this, SLOT(change_adaptor()));
1346 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1347 this, SLOT(change_adaptor()));
1348 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1349 this, SLOT(change_adaptor()));
1350 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1351 this, SLOT(change_adaptor()));
1352 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1353 this, SLOT(change_adaptor()));
1354 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1355 this, SLOT(change_adaptor()));
1356 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1357 this, SLOT(change_adaptor()));
1358 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1359 this, SLOT(change_adaptor()));
1360 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1361 this, SLOT(change_adaptor()));
1362 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1363 this, SLOT(change_adaptor()));
1364 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1365 this, SLOT(change_adaptor()));
1366 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1367 this, SLOT(change_adaptor()));
1368 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1369 this, SLOT(change_adaptor()));
1370 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1371 this, SLOT(change_adaptor()));
1372 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1373 this, SLOT(change_adaptor()));
1375 pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1376 pdfSupportModule->titleLE));
1377 pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1378 pdfSupportModule->authorLE));
1379 pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1380 pdfSupportModule->subjectLE));
1381 pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1382 pdfSupportModule->keywordsLE));
1383 pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1384 pdfSupportModule->optionsLE));
1386 for (int i = 0; backref_opts[i][0]; ++i)
1387 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1391 floatModule = new FloatPlacement;
1392 connect(floatModule, SIGNAL(changed()),
1393 this, SLOT(change_adaptor()));
1397 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1398 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1399 this, SLOT(change_adaptor()));
1400 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1401 this, SLOT(change_adaptor()));
1402 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1403 this, SLOT(setListingsMessage()));
1404 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1405 this, SLOT(setListingsMessage()));
1406 listingsModule->listingsTB->setPlainText(
1407 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1411 docPS->addPanel(latexModule, qt_("Document Class"));
1412 docPS->addPanel(masterChildModule, qt_("Child Documents"));
1413 docPS->addPanel(modulesModule, qt_("Modules"));
1414 docPS->addPanel(localLayout, qt_("Local Layout"));
1415 docPS->addPanel(fontModule, qt_("Fonts"));
1416 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1417 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1418 docPS->addPanel(marginsModule, qt_("Page Margins"));
1419 docPS->addPanel(langModule, qt_("Language"));
1420 docPS->addPanel(colorModule, qt_("Colors"));
1421 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1422 docPS->addPanel(biblioModule, qt_("Bibliography"));
1423 docPS->addPanel(indicesModule, qt_("Indexes"));
1424 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1425 docPS->addPanel(mathsModule, qt_("Math Options"));
1426 docPS->addPanel(floatModule, qt_("Float Placement"));
1427 docPS->addPanel(listingsModule, qt_("Listings"));
1428 docPS->addPanel(bulletsModule, qt_("Bullets"));
1429 docPS->addPanel(branchesModule, qt_("Branches"));
1430 docPS->addPanel(outputModule, qt_("Output"));
1431 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1432 docPS->setCurrentPanel(qt_("Document Class"));
1433 // FIXME: hack to work around resizing bug in Qt >= 4.2
1434 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1435 #if QT_VERSION >= 0x040200
1436 docPS->updateGeometry();
1441 void GuiDocument::saveDefaultClicked()
1447 void GuiDocument::useDefaultsClicked()
1453 void GuiDocument::change_adaptor()
1459 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1464 string child = fromqstr(item->text(0));
1468 if (std::find(includeonlys_.begin(),
1469 includeonlys_.end(), child) != includeonlys_.end())
1470 includeonlys_.remove(child);
1472 includeonlys_.push_back(child);
1474 updateIncludeonlys();
1479 QString GuiDocument::validateListingsParameters()
1481 // use a cache here to avoid repeated validation
1482 // of the same parameters
1483 static string param_cache;
1484 static QString msg_cache;
1486 if (listingsModule->bypassCB->isChecked())
1489 string params = fromqstr(listingsModule->listingsED->toPlainText());
1490 if (params != param_cache) {
1491 param_cache = params;
1492 msg_cache = toqstr(InsetListingsParams(params).validate());
1498 void GuiDocument::setListingsMessage()
1500 static bool isOK = true;
1501 QString msg = validateListingsParameters();
1502 if (msg.isEmpty()) {
1506 // listingsTB->setTextColor("black");
1507 listingsModule->listingsTB->setPlainText(
1508 qt_("Input listings parameters below. "
1509 "Enter ? for a list of parameters."));
1512 // listingsTB->setTextColor("red");
1513 listingsModule->listingsTB->setPlainText(msg);
1518 void GuiDocument::setLSpacing(int item)
1520 textLayoutModule->lspacingLE->setEnabled(item == 3);
1524 void GuiDocument::setIndent(int item)
1526 bool const enable = (item == 1);
1527 textLayoutModule->indentLE->setEnabled(enable);
1528 textLayoutModule->indentLengthCO->setEnabled(enable);
1529 textLayoutModule->skipLE->setEnabled(false);
1530 textLayoutModule->skipLengthCO->setEnabled(false);
1535 void GuiDocument::enableIndent(bool indent)
1537 textLayoutModule->skipLE->setEnabled(!indent);
1538 textLayoutModule->skipLengthCO->setEnabled(!indent);
1540 setIndent(textLayoutModule->indentCO->currentIndex());
1544 void GuiDocument::setSkip(int item)
1546 bool const enable = (item == 3);
1547 textLayoutModule->skipLE->setEnabled(enable);
1548 textLayoutModule->skipLengthCO->setEnabled(enable);
1553 void GuiDocument::enableSkip(bool skip)
1555 textLayoutModule->indentLE->setEnabled(!skip);
1556 textLayoutModule->indentLengthCO->setEnabled(!skip);
1558 setSkip(textLayoutModule->skipCO->currentIndex());
1562 void GuiDocument::setMargins()
1564 bool const extern_geometry =
1565 documentClass().provides("geometry");
1566 marginsModule->marginCB->setEnabled(!extern_geometry);
1567 if (extern_geometry) {
1568 marginsModule->marginCB->setChecked(false);
1569 setCustomMargins(true);
1571 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1572 setCustomMargins(!bp_.use_geometry);
1577 void GuiDocument::papersizeChanged(int paper_size)
1579 setCustomPapersize(paper_size == 1);
1583 void GuiDocument::setCustomPapersize(bool custom)
1585 pageLayoutModule->paperwidthL->setEnabled(custom);
1586 pageLayoutModule->paperwidthLE->setEnabled(custom);
1587 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1588 pageLayoutModule->paperheightL->setEnabled(custom);
1589 pageLayoutModule->paperheightLE->setEnabled(custom);
1590 pageLayoutModule->paperheightLE->setFocus();
1591 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1595 void GuiDocument::setColSep()
1597 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1601 void GuiDocument::setCustomMargins(bool custom)
1603 marginsModule->topL->setEnabled(!custom);
1604 marginsModule->topLE->setEnabled(!custom);
1605 marginsModule->topUnit->setEnabled(!custom);
1607 marginsModule->bottomL->setEnabled(!custom);
1608 marginsModule->bottomLE->setEnabled(!custom);
1609 marginsModule->bottomUnit->setEnabled(!custom);
1611 marginsModule->innerL->setEnabled(!custom);
1612 marginsModule->innerLE->setEnabled(!custom);
1613 marginsModule->innerUnit->setEnabled(!custom);
1615 marginsModule->outerL->setEnabled(!custom);
1616 marginsModule->outerLE->setEnabled(!custom);
1617 marginsModule->outerUnit->setEnabled(!custom);
1619 marginsModule->headheightL->setEnabled(!custom);
1620 marginsModule->headheightLE->setEnabled(!custom);
1621 marginsModule->headheightUnit->setEnabled(!custom);
1623 marginsModule->headsepL->setEnabled(!custom);
1624 marginsModule->headsepLE->setEnabled(!custom);
1625 marginsModule->headsepUnit->setEnabled(!custom);
1627 marginsModule->footskipL->setEnabled(!custom);
1628 marginsModule->footskipLE->setEnabled(!custom);
1629 marginsModule->footskipUnit->setEnabled(!custom);
1631 bool const enableColSep = !custom &&
1632 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1633 marginsModule->columnsepL->setEnabled(enableColSep);
1634 marginsModule->columnsepLE->setEnabled(enableColSep);
1635 marginsModule->columnsepUnit->setEnabled(enableColSep);
1639 void GuiDocument::changeBackgroundColor()
1641 QColor const & newColor = QColorDialog::getColor(
1642 rgb2qcolor(set_backgroundcolor), asQWidget());
1643 if (!newColor.isValid())
1645 // set the button color and text
1646 colorModule->backgroundPB->setStyleSheet(
1647 colorButtonStyleSheet(newColor));
1648 colorModule->backgroundPB->setText(qt_("&Change..."));
1650 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1651 is_backgroundcolor = true;
1656 void GuiDocument::deleteBackgroundColor()
1658 // set the button color back to default by setting an empty StyleSheet
1659 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1660 // change button text
1661 colorModule->backgroundPB->setText(qt_("&Default..."));
1662 // save default color (white)
1663 set_backgroundcolor = rgbFromHexName("#ffffff");
1664 is_backgroundcolor = false;
1669 void GuiDocument::changeFontColor()
1671 QColor const & newColor = QColorDialog::getColor(
1672 rgb2qcolor(set_fontcolor), asQWidget());
1673 if (!newColor.isValid())
1675 // set the button color and text
1676 colorModule->fontColorPB->setStyleSheet(
1677 colorButtonStyleSheet(newColor));
1678 colorModule->fontColorPB->setText(qt_("&Change..."));
1680 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1681 is_fontcolor = true;
1686 void GuiDocument::deleteFontColor()
1688 // set the button color back to default by setting an empty StyleSheet
1689 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1690 // change button text
1691 colorModule->fontColorPB->setText(qt_("&Default..."));
1692 // save default color (black)
1693 set_fontcolor = rgbFromHexName("#000000");
1694 is_fontcolor = false;
1699 void GuiDocument::changeNoteFontColor()
1701 QColor const & newColor = QColorDialog::getColor(
1702 rgb2qcolor(set_notefontcolor), asQWidget());
1703 if (!newColor.isValid())
1705 // set the button color
1706 colorModule->noteFontColorPB->setStyleSheet(
1707 colorButtonStyleSheet(newColor));
1709 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1714 void GuiDocument::deleteNoteFontColor()
1716 // set the button color back to pref
1717 theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1718 colorModule->noteFontColorPB->setStyleSheet(
1719 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1724 void GuiDocument::changeBoxBackgroundColor()
1726 QColor const & newColor = QColorDialog::getColor(
1727 rgb2qcolor(set_boxbgcolor), asQWidget());
1728 if (!newColor.isValid())
1730 // set the button color
1731 colorModule->boxBackgroundPB->setStyleSheet(
1732 colorButtonStyleSheet(newColor));
1734 set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1739 void GuiDocument::deleteBoxBackgroundColor()
1741 // set the button color back to pref
1742 theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1743 colorModule->boxBackgroundPB->setStyleSheet(
1744 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1749 void GuiDocument::osFontsChanged(bool nontexfonts)
1751 bool const tex_fonts = !nontexfonts;
1753 updateDefaultFormat();
1754 langModule->encodingCO->setEnabled(tex_fonts &&
1755 !langModule->defaultencodingRB->isChecked());
1756 langModule->defaultencodingRB->setEnabled(tex_fonts);
1757 langModule->otherencodingRB->setEnabled(tex_fonts);
1759 fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1760 fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1761 fontModule->cjkFontLE->setEnabled(tex_fonts);
1762 fontModule->cjkFontLA->setEnabled(tex_fonts);
1765 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1766 bool scaleable = providesScale(font);
1767 fontModule->scaleSansSB->setEnabled(scaleable);
1768 fontModule->scaleSansLA->setEnabled(scaleable);
1770 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1771 scaleable = providesScale(font);
1772 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1773 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1775 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1776 fontModule->fontScCB->setEnabled(providesSC(font));
1777 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1779 fontModule->fontencLA->setEnabled(tex_fonts);
1780 fontModule->fontencCO->setEnabled(tex_fonts);
1782 fontModule->fontencLE->setEnabled(false);
1784 fontencChanged(fontModule->fontencCO->currentIndex());
1788 void GuiDocument::updateFontsize(string const & items, string const & sel)
1790 fontModule->fontsizeCO->clear();
1791 fontModule->fontsizeCO->addItem(qt_("Default"));
1793 for (int n = 0; !token(items,'|',n).empty(); ++n)
1794 fontModule->fontsizeCO->
1795 addItem(toqstr(token(items,'|',n)));
1797 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1798 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1799 fontModule->fontsizeCO->setCurrentIndex(n);
1806 void GuiDocument::updateFontlist()
1808 fontModule->fontsRomanCO->clear();
1809 fontModule->fontsSansCO->clear();
1810 fontModule->fontsTypewriterCO->clear();
1812 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1813 if (fontModule->osFontsCB->isChecked()) {
1814 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1815 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1816 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1818 QFontDatabase fontdb;
1819 QStringList families(fontdb.families());
1820 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1821 fontModule->fontsRomanCO->addItem(*it, *it);
1822 fontModule->fontsSansCO->addItem(*it, *it);
1823 fontModule->fontsTypewriterCO->addItem(*it, *it);
1828 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1829 QString font = qt_(tex_fonts_roman_gui[n]);
1830 if (!isFontAvailable(tex_fonts_roman[n]))
1831 font += qt_(" (not installed)");
1832 fontModule->fontsRomanCO->addItem(font, qt_(tex_fonts_roman[n]));
1834 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1835 QString font = qt_(tex_fonts_sans_gui[n]);
1836 if (!isFontAvailable(tex_fonts_sans[n]))
1837 font += qt_(" (not installed)");
1838 fontModule->fontsSansCO->addItem(font, qt_(tex_fonts_sans[n]));
1840 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1841 QString font = qt_(tex_fonts_monospaced_gui[n]);
1842 if (!isFontAvailable(tex_fonts_monospaced[n]))
1843 font += qt_(" (not installed)");
1844 fontModule->fontsTypewriterCO->addItem(font, qt_(tex_fonts_monospaced[n]));
1849 void GuiDocument::fontencChanged(int item)
1851 fontModule->fontencLE->setEnabled(item == 1);
1855 void GuiDocument::romanChanged(int item)
1857 if (fontModule->osFontsCB->isChecked())
1859 string const font = tex_fonts_roman[item];
1860 fontModule->fontScCB->setEnabled(providesSC(font));
1861 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1865 void GuiDocument::sansChanged(int item)
1867 if (fontModule->osFontsCB->isChecked())
1869 string const font = tex_fonts_sans[item];
1870 bool scaleable = providesScale(font);
1871 fontModule->scaleSansSB->setEnabled(scaleable);
1872 fontModule->scaleSansLA->setEnabled(scaleable);
1876 void GuiDocument::ttChanged(int item)
1878 if (fontModule->osFontsCB->isChecked())
1880 string const font = tex_fonts_monospaced[item];
1881 bool scaleable = providesScale(font);
1882 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1883 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1887 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1890 pageLayoutModule->pagestyleCO->clear();
1891 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1893 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1894 string style = token(items, '|', n);
1895 QString style_gui = qt_(style);
1896 pagestyles.push_back(pair<string, QString>(style, style_gui));
1897 pageLayoutModule->pagestyleCO->addItem(style_gui);
1900 if (sel == "default") {
1901 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1907 for (size_t i = 0; i < pagestyles.size(); ++i)
1908 if (pagestyles[i].first == sel)
1909 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1912 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1916 void GuiDocument::browseLayout()
1918 QString const label1 = qt_("Layouts|#o#O");
1919 QString const dir1 = toqstr(lyxrc.document_path);
1920 QStringList const filter(qt_("LyX Layout (*.layout)"));
1921 QString file = browseRelToParent(QString(), bufferFilePath(),
1922 qt_("Local layout file"), filter, false,
1925 if (!file.endsWith(".layout"))
1928 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1929 fromqstr(bufferFilePath()));
1931 int const ret = Alert::prompt(_("Local layout file"),
1932 _("The layout file you have selected is a local layout\n"
1933 "file, not one in the system or user directory. Your\n"
1934 "document may not work with this layout if you do not\n"
1935 "keep the layout file in the document directory."),
1936 1, 1, _("&Set Layout"), _("&Cancel"));
1940 // load the layout file
1941 LayoutFileList & bcl = LayoutFileList::get();
1942 string classname = layoutFile.onlyFileName();
1943 // this will update an existing layout if that layout has been loaded before.
1944 LayoutFileIndex name = bcl.addLocalLayout(
1945 classname.substr(0, classname.size() - 7),
1946 layoutFile.onlyPath().absFileName());
1949 Alert::error(_("Error"),
1950 _("Unable to read local layout file."));
1954 // do not trigger classChanged if there is no change.
1955 if (latexModule->classCO->currentText() == toqstr(name))
1959 int idx = latexModule->classCO->findText(toqstr(name));
1961 classes_model_.insertRow(0, toqstr(name), name);
1962 latexModule->classCO->setCurrentIndex(0);
1964 latexModule->classCO->setCurrentIndex(idx);
1970 void GuiDocument::browseMaster()
1972 QString const title = qt_("Select master document");
1973 QString const dir1 = toqstr(lyxrc.document_path);
1974 QString const old = latexModule->childDocLE->text();
1975 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1976 QStringList const filter(qt_("LyX Files (*.lyx)"));
1977 QString file = browseRelToSub(old, docpath, title, filter, false,
1978 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1980 if (!file.isEmpty())
1981 latexModule->childDocLE->setText(file);
1985 void GuiDocument::classChanged()
1987 int idx = latexModule->classCO->currentIndex();
1990 string const classname = classes_model_.getIDString(idx);
1992 // check whether the selected modules have changed.
1993 bool modules_changed = false;
1994 unsigned int const srows = selectedModel()->rowCount();
1995 if (srows != bp_.getModules().size())
1996 modules_changed = true;
1998 list<string>::const_iterator mit = bp_.getModules().begin();
1999 list<string>::const_iterator men = bp_.getModules().end();
2000 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
2001 if (selectedModel()->getIDString(i) != *mit) {
2002 modules_changed = true;
2007 if (modules_changed || lyxrc.auto_reset_options) {
2008 if (applyPB->isEnabled()) {
2009 int const ret = Alert::prompt(_("Unapplied changes"),
2010 _("Some changes in the dialog were not yet applied.\n"
2011 "If you do not apply now, they will be lost after this action."),
2012 1, 1, _("&Apply"), _("&Dismiss"));
2018 // We load the TextClass as soon as it is selected. This is
2019 // necessary so that other options in the dialog can be updated
2020 // according to the new class. Note, however, that, if you use
2021 // the scroll wheel when sitting on the combo box, we'll load a
2022 // lot of TextClass objects very quickly....
2023 if (!bp_.setBaseClass(classname)) {
2024 Alert::error(_("Error"), _("Unable to set document class."));
2027 if (lyxrc.auto_reset_options)
2028 bp_.useClassDefaults();
2030 // With the introduction of modules came a distinction between the base
2031 // class and the document class. The former corresponds to the main layout
2032 // file; the latter is that plus the modules (or the document-specific layout,
2033 // or whatever else there could be). Our parameters come from the document
2034 // class. So when we set the base class, we also need to recreate the document
2035 // class. Otherwise, we still have the old one.
2036 bp_.makeDocumentClass();
2041 void GuiDocument::languagePackageChanged(int i)
2043 langModule->languagePackageLE->setEnabled(
2044 langModule->languagePackageCO->itemData(i).toString() == "custom");
2048 void GuiDocument::biblioChanged()
2050 biblioChanged_ = true;
2055 void GuiDocument::bibtexChanged(int n)
2057 biblioModule->bibtexOptionsLE->setEnabled(
2058 biblioModule->bibtexCO->itemData(n).toString() != "default");
2063 void GuiDocument::setAuthorYear(bool authoryear)
2066 biblioModule->citeStyleCO->setCurrentIndex(0);
2071 void GuiDocument::setNumerical(bool numerical)
2074 biblioModule->citeStyleCO->setCurrentIndex(1);
2079 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2081 engine_types_.clear();
2085 for (int n = 0; !token(items, '|', n).empty(); ++n) {
2087 string style = token(items, '|', n);
2088 engine_types_.push_back(style);
2092 case ENGINE_TYPE_AUTHORYEAR:
2093 biblioModule->citeStyleCO->setCurrentIndex(0);
2095 case ENGINE_TYPE_NUMERICAL:
2096 biblioModule->citeStyleCO->setCurrentIndex(1);
2100 biblioModule->citationStyleL->setEnabled(nn > 1);
2101 biblioModule->citeStyleCO->setEnabled(nn > 1);
2106 // If the textclass allows only one of authoryear or numerical,
2107 // we have no choice but to force that engine type.
2108 if (engine_types_[0] == "authoryear")
2109 biblioModule->citeStyleCO->setCurrentIndex(0);
2111 biblioModule->citeStyleCO->setCurrentIndex(1);
2117 // both of these should take a vector<docstring>
2119 // This is an insanely complicated attempt to make this sort of thing
2120 // work with RTL languages.
2121 docstring formatStrVec(vector<string> const & v, docstring const & s)
2123 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2127 return translateIfPossible(from_utf8(v[0]));
2128 if (v.size() == 2) {
2129 docstring retval = _("%1$s and %2$s");
2130 retval = subst(retval, _("and"), s);
2131 return bformat(retval, translateIfPossible(from_utf8(v[0])),
2132 translateIfPossible(from_utf8(v[1])));
2134 // The idea here is to format all but the last two items...
2135 int const vSize = v.size();
2136 docstring t2 = _("%1$s, %2$s");
2137 docstring retval = translateIfPossible(from_utf8(v[0]));
2138 for (int i = 1; i < vSize - 2; ++i)
2139 retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2140 //...and then to plug them, and the last two, into this schema
2141 docstring t = _("%1$s, %2$s, and %3$s");
2142 t = subst(t, _("and"), s);
2143 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2144 translateIfPossible(from_utf8(v[vSize - 1])));
2147 vector<string> idsToNames(vector<string> const & idList)
2149 vector<string> retval;
2150 vector<string>::const_iterator it = idList.begin();
2151 vector<string>::const_iterator end = idList.end();
2152 for (; it != end; ++it) {
2153 LyXModule const * const mod = theModuleList[*it];
2155 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2156 translateIfPossible(from_utf8(*it)))));
2158 retval.push_back(mod->getName());
2162 } // end anonymous namespace
2165 void GuiDocument::modulesToParams(BufferParams & bp)
2167 // update list of loaded modules
2168 bp.clearLayoutModules();
2169 int const srows = modules_sel_model_.rowCount();
2170 for (int i = 0; i < srows; ++i)
2171 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2173 // update the list of removed modules
2174 bp.clearRemovedModules();
2175 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2176 list<string>::const_iterator rit = reqmods.begin();
2177 list<string>::const_iterator ren = reqmods.end();
2179 // check each of the default modules
2180 for (; rit != ren; rit++) {
2181 list<string>::const_iterator mit = bp.getModules().begin();
2182 list<string>::const_iterator men = bp.getModules().end();
2184 for (; mit != men; mit++) {
2191 // the module isn't present so must have been removed by the user
2192 bp.addRemovedModule(*rit);
2197 void GuiDocument::modulesChanged()
2199 modulesToParams(bp_);
2200 bp_.makeDocumentClass();
2205 void GuiDocument::updateModuleInfo()
2207 selectionManager->update();
2209 //Module description
2210 bool const focus_on_selected = selectionManager->selectedFocused();
2211 QAbstractItemView * lv;
2212 if (focus_on_selected)
2213 lv = modulesModule->selectedLV;
2215 lv = modulesModule->availableLV;
2216 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2217 modulesModule->infoML->document()->clear();
2220 QModelIndex const & idx = lv->selectionModel()->currentIndex();
2221 GuiIdListModel const & id_model =
2222 focus_on_selected ? modules_sel_model_ : modules_av_model_;
2223 string const modName = id_model.getIDString(idx.row());
2224 docstring desc = getModuleDescription(modName);
2226 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2227 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2230 desc += _("Module provided by document class.");
2233 docstring cat = getModuleCategory(modName);
2237 desc += bformat(_("Category: %1$s."), cat);
2240 vector<string> pkglist = getPackageList(modName);
2241 docstring pkgdesc = formatStrVec(pkglist, _("and"));
2242 if (!pkgdesc.empty()) {
2245 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2248 pkglist = getRequiredList(modName);
2249 if (!pkglist.empty()) {
2250 vector<string> const reqdescs = idsToNames(pkglist);
2251 pkgdesc = formatStrVec(reqdescs, _("or"));
2254 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2257 pkglist = getExcludedList(modName);
2258 if (!pkglist.empty()) {
2259 vector<string> const reqdescs = idsToNames(pkglist);
2260 pkgdesc = formatStrVec(reqdescs, _( "and"));
2263 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2266 if (!isModuleAvailable(modName)) {
2269 desc += _("WARNING: Some required packages are unavailable!");
2272 modulesModule->infoML->document()->setPlainText(toqstr(desc));
2276 void GuiDocument::updateNumbering()
2278 DocumentClass const & tclass = documentClass();
2280 numberingModule->tocTW->setUpdatesEnabled(false);
2281 numberingModule->tocTW->clear();
2283 int const depth = numberingModule->depthSL->value();
2284 int const toc = numberingModule->tocSL->value();
2285 QString const no = qt_("No");
2286 QString const yes = qt_("Yes");
2287 QTreeWidgetItem * item = 0;
2289 DocumentClass::const_iterator lit = tclass.begin();
2290 DocumentClass::const_iterator len = tclass.end();
2291 for (; lit != len; ++lit) {
2292 int const toclevel = lit->toclevel;
2293 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
2294 item = new QTreeWidgetItem(numberingModule->tocTW);
2295 item->setText(0, toqstr(translateIfPossible(lit->name())));
2296 item->setText(1, (toclevel <= depth) ? yes : no);
2297 item->setText(2, (toclevel <= toc) ? yes : no);
2301 numberingModule->tocTW->setUpdatesEnabled(true);
2302 numberingModule->tocTW->update();
2306 void GuiDocument::updateDefaultFormat()
2310 // make a copy in order to consider unapplied changes
2311 BufferParams param_copy = buffer().params();
2312 param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2313 int const idx = latexModule->classCO->currentIndex();
2315 string const classname = classes_model_.getIDString(idx);
2316 param_copy.setBaseClass(classname);
2317 param_copy.makeDocumentClass();
2319 outputModule->defaultFormatCO->blockSignals(true);
2320 outputModule->defaultFormatCO->clear();
2321 outputModule->defaultFormatCO->addItem(qt_("Default"),
2322 QVariant(QString("default")));
2323 typedef vector<Format const *> Formats;
2324 Formats formats = param_copy.exportableFormats(true);
2325 Formats::const_iterator cit = formats.begin();
2326 Formats::const_iterator end = formats.end();
2327 for (; cit != end; ++cit)
2328 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2329 QVariant(toqstr((*cit)->name())));
2330 outputModule->defaultFormatCO->blockSignals(false);
2334 bool GuiDocument::isChildIncluded(string const & child)
2336 if (includeonlys_.empty())
2338 return (std::find(includeonlys_.begin(),
2339 includeonlys_.end(), child) != includeonlys_.end());
2343 void GuiDocument::applyView()
2346 preambleModule->apply(bp_);
2347 localLayout->apply(bp_);
2350 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2351 bp_.use_refstyle = latexModule->refstyleCB->isChecked();
2354 if (biblioModule->citeNatbibRB->isChecked())
2355 bp_.setCiteEngine("natbib");
2356 else if (biblioModule->citeJurabibRB->isChecked())
2357 bp_.setCiteEngine("jurabib");
2359 bp_.setCiteEngine("basic");
2361 if (biblioModule->citeStyleCO->currentIndex())
2362 bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
2364 bp_.setCiteEngineType(ENGINE_TYPE_AUTHORYEAR);
2367 biblioModule->bibtopicCB->isChecked();
2369 bp_.biblio_style = fromqstr(biblioModule->bibtexStyleLE->text());
2371 string const bibtex_command =
2372 fromqstr(biblioModule->bibtexCO->itemData(
2373 biblioModule->bibtexCO->currentIndex()).toString());
2374 string const bibtex_options =
2375 fromqstr(biblioModule->bibtexOptionsLE->text());
2376 if (bibtex_command == "default" || bibtex_options.empty())
2377 bp_.bibtex_command = bibtex_command;
2379 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2381 if (biblioChanged_) {
2382 buffer().invalidateBibinfoCache();
2383 buffer().removeBiblioTempFiles();
2387 indicesModule->apply(bp_);
2389 // language & quotes
2390 if (langModule->defaultencodingRB->isChecked()) {
2391 bp_.inputenc = "auto";
2393 int i = langModule->encodingCO->currentIndex();
2395 bp_.inputenc = "default";
2397 QString const enc_gui =
2398 langModule->encodingCO->currentText();
2399 Encodings::const_iterator it = encodings.begin();
2400 Encodings::const_iterator const end = encodings.end();
2402 for (; it != end; ++it) {
2403 if (qt_(it->guiName()) == enc_gui) {
2404 bp_.inputenc = it->latexName();
2410 // should not happen
2411 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2412 bp_.inputenc = "default";
2417 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2418 switch (langModule->quoteStyleCO->currentIndex()) {
2420 lga = InsetQuotes::EnglishQuotes;
2423 lga = InsetQuotes::SwedishQuotes;
2426 lga = InsetQuotes::GermanQuotes;
2429 lga = InsetQuotes::PolishQuotes;
2432 lga = InsetQuotes::FrenchQuotes;
2435 lga = InsetQuotes::DanishQuotes;
2438 bp_.quotes_language = lga;
2440 QString const lang = langModule->languageCO->itemData(
2441 langModule->languageCO->currentIndex()).toString();
2442 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2444 QString const pack = langModule->languagePackageCO->itemData(
2445 langModule->languagePackageCO->currentIndex()).toString();
2446 if (pack == "custom")
2448 fromqstr(langModule->languagePackageLE->text());
2450 bp_.lang_package = fromqstr(pack);
2453 bp_.backgroundcolor = set_backgroundcolor;
2454 bp_.isbackgroundcolor = is_backgroundcolor;
2455 bp_.fontcolor = set_fontcolor;
2456 bp_.isfontcolor = is_fontcolor;
2457 bp_.notefontcolor = set_notefontcolor;
2458 bp_.boxbgcolor = set_boxbgcolor;
2461 if (bp_.documentClass().hasTocLevels()) {
2462 bp_.tocdepth = numberingModule->tocSL->value();
2463 bp_.secnumdepth = numberingModule->depthSL->value();
2467 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2468 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2469 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2470 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2473 bp_.graphics_driver =
2474 tex_graphics[latexModule->psdriverCO->currentIndex()];
2477 int idx = latexModule->classCO->currentIndex();
2479 string const classname = classes_model_.getIDString(idx);
2480 bp_.setBaseClass(classname);
2484 modulesToParams(bp_);
2487 vector<string> const & packages = BufferParams::auto_packages();
2488 for (size_t n = 0; n < packages.size(); ++n) {
2489 QCheckBox * autoCB = static_cast<QCheckBox *>(
2490 mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget());
2491 if (autoCB->isChecked())
2492 bp_.use_package(packages[n], BufferParams::package_auto);
2494 QCheckBox * alwaysCB = static_cast<QCheckBox *>(
2495 mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget());
2496 if (alwaysCB->isChecked())
2497 bp_.use_package(packages[n], BufferParams::package_on);
2499 bp_.use_package(packages[n], BufferParams::package_off);
2504 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2505 bp_.pagestyle = "default";
2507 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2508 for (size_t i = 0; i != pagestyles.size(); ++i)
2509 if (pagestyles[i].second == style_gui)
2510 bp_.pagestyle = pagestyles[i].first;
2514 switch (textLayoutModule->lspacingCO->currentIndex()) {
2516 bp_.spacing().set(Spacing::Single);
2519 bp_.spacing().set(Spacing::Onehalf);
2522 bp_.spacing().set(Spacing::Double);
2525 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2527 bp_.spacing().set(Spacing::Single);
2529 bp_.spacing().set(Spacing::Other, s);
2534 if (textLayoutModule->twoColumnCB->isChecked())
2539 bp_.justification = textLayoutModule->justCB->isChecked();
2541 if (textLayoutModule->indentRB->isChecked()) {
2542 // if paragraphs are separated by an indentation
2543 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2544 switch (textLayoutModule->indentCO->currentIndex()) {
2546 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2549 HSpace indent = HSpace(
2550 widgetsToLength(textLayoutModule->indentLE,
2551 textLayoutModule->indentLengthCO)
2553 bp_.setIndentation(indent);
2557 // this should never happen
2558 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2562 // if paragraphs are separated by a skip
2563 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2564 switch (textLayoutModule->skipCO->currentIndex()) {
2566 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2569 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2572 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2577 widgetsToLength(textLayoutModule->skipLE,
2578 textLayoutModule->skipLengthCO)
2584 // this should never happen
2585 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2591 fromqstr(latexModule->optionsLE->text());
2593 bp_.use_default_options =
2594 latexModule->defaultOptionsCB->isChecked();
2596 if (latexModule->childDocGB->isChecked())
2598 fromqstr(latexModule->childDocLE->text());
2600 bp_.master = string();
2603 bp_.clearIncludedChildren();
2604 if (masterChildModule->includeonlyRB->isChecked()) {
2605 list<string>::const_iterator it = includeonlys_.begin();
2606 for (; it != includeonlys_.end() ; ++it) {
2607 bp_.addIncludedChildren(*it);
2610 bp_.maintain_unincluded_children =
2611 masterChildModule->maintainAuxCB->isChecked();
2614 bp_.float_placement = floatModule->get();
2617 // text should have passed validation
2618 bp_.listings_params =
2619 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2622 bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
2623 outputModule->defaultFormatCO->currentIndex()).toString());
2625 bool const nontexfonts = fontModule->osFontsCB->isChecked();
2626 bp_.useNonTeXFonts = nontexfonts;
2628 bp_.output_sync = outputModule->outputsyncCB->isChecked();
2630 bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2632 int mathfmt = outputModule->mathoutCB->currentIndex();
2635 BufferParams::MathOutput const mo =
2636 static_cast<BufferParams::MathOutput>(mathfmt);
2637 bp_.html_math_output = mo;
2638 bp_.html_be_strict = outputModule->strictCB->isChecked();
2639 bp_.html_css_as_file = outputModule->cssCB->isChecked();
2640 bp_.html_math_img_scale = outputModule->mathimgSB->value();
2644 fromqstr(fontModule->fontsRomanCO->
2645 itemData(fontModule->fontsRomanCO->currentIndex()).toString());
2648 fromqstr(fontModule->fontsSansCO->
2649 itemData(fontModule->fontsSansCO->currentIndex()).toString());
2651 bp_.fonts_typewriter =
2652 fromqstr(fontModule->fontsTypewriterCO->
2653 itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
2655 if (fontModule->fontencCO->currentIndex() == 0)
2656 bp_.fontenc = "global";
2657 else if (fontModule->fontencCO->currentIndex() == 1)
2658 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2659 else if (fontModule->fontencCO->currentIndex() == 2)
2660 bp_.fontenc = "default";
2663 fromqstr(fontModule->cjkFontLE->text());
2665 bp_.fonts_sans_scale = fontModule->scaleSansSB->value();
2667 bp_.fonts_typewriter_scale = fontModule->scaleTypewriterSB->value();
2669 bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
2671 bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
2674 bp_.fonts_default_family = "default";
2676 bp_.fonts_default_family = GuiDocument::fontfamilies[
2677 fontModule->fontsDefaultCO->currentIndex()];
2679 if (fontModule->fontsizeCO->currentIndex() == 0)
2680 bp_.fontsize = "default";
2683 fromqstr(fontModule->fontsizeCO->currentText());
2686 bp_.papersize = PAPER_SIZE(
2687 pageLayoutModule->papersizeCO->currentIndex());
2689 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2690 pageLayoutModule->paperwidthUnitCO);
2692 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2693 pageLayoutModule->paperheightUnitCO);
2695 if (pageLayoutModule->facingPagesCB->isChecked())
2696 bp_.sides = TwoSides;
2698 bp_.sides = OneSide;
2700 if (pageLayoutModule->landscapeRB->isChecked())
2701 bp_.orientation = ORIENTATION_LANDSCAPE;
2703 bp_.orientation = ORIENTATION_PORTRAIT;
2706 bp_.use_geometry = !marginsModule->marginCB->isChecked();
2708 Ui::MarginsUi const * m = marginsModule;
2710 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2711 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2712 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2713 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2714 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2715 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2716 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2717 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2720 branchesModule->apply(bp_);
2723 PDFOptions & pdf = bp_.pdfoptions();
2724 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2725 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2726 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2727 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2728 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2730 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2731 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2732 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2733 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2735 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2736 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2737 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2738 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2740 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2741 if (pdfSupportModule->fullscreenCB->isChecked())
2742 pdf.pagemode = pdf.pagemode_fullscreen;
2744 pdf.pagemode.clear();
2745 pdf.quoted_options = pdf.quoted_options_check(
2746 fromqstr(pdfSupportModule->optionsLE->text()));
2750 void GuiDocument::paramsToDialog()
2752 // set the default unit
2753 Length::UNIT const default_unit = Length::defaultUnit();
2756 preambleModule->update(bp_, id());
2757 localLayout->update(bp_, id());
2760 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2761 latexModule->refstyleCB->setChecked(bp_.use_refstyle);
2764 string const cite_engine = bp_.citeEngine().list().front();
2766 biblioModule->citeDefaultRB->setChecked(
2767 cite_engine == "basic");
2769 biblioModule->citeJurabibRB->setChecked(
2770 cite_engine == "jurabib");
2772 biblioModule->citeNatbibRB->setChecked(
2773 cite_engine == "natbib");
2775 biblioModule->citeStyleCO->setCurrentIndex(
2776 bp_.citeEngineType() == ENGINE_TYPE_NUMERICAL);
2778 updateEngineType(documentClass().opt_enginetype(),
2779 bp_.citeEngineType());
2781 biblioModule->bibtopicCB->setChecked(
2784 biblioModule->bibtexStyleLE->setText(toqstr(bp_.biblio_style));
2788 split(bp_.bibtex_command, command, ' ');
2790 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2792 biblioModule->bibtexCO->setCurrentIndex(bpos);
2793 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
2795 // We reset to default if we do not know the specified compiler
2796 // This is for security reasons
2797 biblioModule->bibtexCO->setCurrentIndex(
2798 biblioModule->bibtexCO->findData(toqstr("default")));
2799 biblioModule->bibtexOptionsLE->clear();
2801 biblioModule->bibtexOptionsLE->setEnabled(
2802 biblioModule->bibtexCO->currentIndex() != 0);
2804 biblioChanged_ = false;
2807 indicesModule->update(bp_);
2809 // language & quotes
2810 int const pos = langModule->languageCO->findData(toqstr(
2811 bp_.language->lang()));
2812 langModule->languageCO->setCurrentIndex(pos);
2814 langModule->quoteStyleCO->setCurrentIndex(
2815 bp_.quotes_language);
2817 bool default_enc = true;
2818 if (bp_.inputenc != "auto") {
2819 default_enc = false;
2820 if (bp_.inputenc == "default") {
2821 langModule->encodingCO->setCurrentIndex(0);
2824 Encodings::const_iterator it = encodings.begin();
2825 Encodings::const_iterator const end = encodings.end();
2826 for (; it != end; ++it) {
2827 if (it->latexName() == bp_.inputenc) {
2828 enc_gui = it->guiName();
2832 int const i = langModule->encodingCO->findText(
2835 langModule->encodingCO->setCurrentIndex(i);
2837 // unknown encoding. Set to default.
2841 langModule->defaultencodingRB->setChecked(default_enc);
2842 langModule->otherencodingRB->setChecked(!default_enc);
2844 int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
2846 langModule->languagePackageCO->setCurrentIndex(
2847 langModule->languagePackageCO->findData("custom"));
2848 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
2850 langModule->languagePackageCO->setCurrentIndex(p);
2851 langModule->languagePackageLE->clear();
2855 if (bp_.isfontcolor) {
2856 colorModule->fontColorPB->setStyleSheet(
2857 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2859 set_fontcolor = bp_.fontcolor;
2860 is_fontcolor = bp_.isfontcolor;
2862 colorModule->noteFontColorPB->setStyleSheet(
2863 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2864 set_notefontcolor = bp_.notefontcolor;
2866 if (bp_.isbackgroundcolor) {
2867 colorModule->backgroundPB->setStyleSheet(
2868 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2870 set_backgroundcolor = bp_.backgroundcolor;
2871 is_backgroundcolor = bp_.isbackgroundcolor;
2873 colorModule->boxBackgroundPB->setStyleSheet(
2874 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
2875 set_boxbgcolor = bp_.boxbgcolor;
2878 int const min_toclevel = documentClass().min_toclevel();
2879 int const max_toclevel = documentClass().max_toclevel();
2880 if (documentClass().hasTocLevels()) {
2881 numberingModule->setEnabled(true);
2882 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2883 numberingModule->depthSL->setMaximum(max_toclevel);
2884 numberingModule->depthSL->setValue(bp_.secnumdepth);
2885 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2886 numberingModule->tocSL->setMaximum(max_toclevel);
2887 numberingModule->tocSL->setValue(bp_.tocdepth);
2890 numberingModule->setEnabled(false);
2891 numberingModule->tocTW->clear();
2895 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2896 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2897 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2898 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2899 bulletsModule->init();
2902 int nitem = findToken(tex_graphics, bp_.graphics_driver);
2904 latexModule->psdriverCO->setCurrentIndex(nitem);
2907 vector<string> const & packages = BufferParams::auto_packages();
2908 for (size_t n = 0; n < packages.size(); ++n) {
2909 QCheckBox * alwaysCB = static_cast<QCheckBox *>(
2910 mathsModule->gridLayout->itemAtPosition(2 * n + 1, 0)->widget());
2911 alwaysCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_on);
2912 QCheckBox * autoCB = static_cast<QCheckBox *>(
2913 mathsModule->gridLayout->itemAtPosition(2 * n, 0)->widget());
2914 autoCB->setChecked(bp_.use_package(packages[n]) == BufferParams::package_auto);
2917 switch (bp_.spacing().getSpace()) {
2918 case Spacing::Other: nitem = 3; break;
2919 case Spacing::Double: nitem = 2; break;
2920 case Spacing::Onehalf: nitem = 1; break;
2921 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2925 string const & layoutID = bp_.baseClassID();
2926 setLayoutComboByIDString(layoutID);
2928 updatePagestyle(documentClass().opt_pagestyle(),
2931 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2932 if (bp_.spacing().getSpace() == Spacing::Other) {
2933 doubleToWidget(textLayoutModule->lspacingLE,
2934 bp_.spacing().getValueAsString());
2938 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2939 textLayoutModule->indentRB->setChecked(true);
2940 string indentation = bp_.getIndentation().asLyXCommand();
2942 if (indentation != "default") {
2943 lengthToWidgets(textLayoutModule->indentLE,
2944 textLayoutModule->indentLengthCO,
2945 indentation, default_unit);
2948 textLayoutModule->indentCO->setCurrentIndex(indent);
2951 textLayoutModule->skipRB->setChecked(true);
2953 switch (bp_.getDefSkip().kind()) {
2954 case VSpace::SMALLSKIP:
2957 case VSpace::MEDSKIP:
2960 case VSpace::BIGSKIP:
2963 case VSpace::LENGTH:
2966 string const length = bp_.getDefSkip().asLyXCommand();
2967 lengthToWidgets(textLayoutModule->skipLE,
2968 textLayoutModule->skipLengthCO,
2969 length, default_unit);
2976 textLayoutModule->skipCO->setCurrentIndex(skip);
2980 textLayoutModule->twoColumnCB->setChecked(
2982 textLayoutModule->justCB->setChecked(bp_.justification);
2984 if (!bp_.options.empty()) {
2985 latexModule->optionsLE->setText(
2986 toqstr(bp_.options));
2988 latexModule->optionsLE->setText(QString());
2992 latexModule->defaultOptionsCB->setChecked(
2993 bp_.use_default_options);
2994 updateSelectedModules();
2995 selectionManager->updateProvidedModules(
2996 bp_.baseClass()->providedModules());
2997 selectionManager->updateExcludedModules(
2998 bp_.baseClass()->excludedModules());
3000 if (!documentClass().options().empty()) {
3001 latexModule->defaultOptionsLE->setText(
3002 toqstr(documentClass().options()));
3004 latexModule->defaultOptionsLE->setText(
3005 toqstr(_("[No options predefined]")));
3008 latexModule->defaultOptionsLE->setEnabled(
3009 bp_.use_default_options
3010 && !documentClass().options().empty());
3012 latexModule->defaultOptionsCB->setEnabled(
3013 !documentClass().options().empty());
3015 if (!bp_.master.empty()) {
3016 latexModule->childDocGB->setChecked(true);
3017 latexModule->childDocLE->setText(
3018 toqstr(bp_.master));
3020 latexModule->childDocLE->setText(QString());
3021 latexModule->childDocGB->setChecked(false);
3025 if (!bufferview() || !buffer().hasChildren()) {
3026 masterChildModule->childrenTW->clear();
3027 includeonlys_.clear();
3028 docPS->showPanel(qt_("Child Documents"), false);
3029 if (docPS->isCurrentPanel(qt_("Child Documents")))
3030 docPS->setCurrentPanel(qt_("Document Class"));
3032 docPS->showPanel(qt_("Child Documents"), true);
3033 masterChildModule->setEnabled(true);
3034 includeonlys_ = bp_.getIncludedChildren();
3035 updateIncludeonlys();
3037 masterChildModule->maintainAuxCB->setChecked(
3038 bp_.maintain_unincluded_children);
3041 floatModule->set(bp_.float_placement);
3044 // break listings_params to multiple lines
3046 InsetListingsParams(bp_.listings_params).separatedParams();
3047 listingsModule->listingsED->setPlainText(toqstr(lstparams));
3050 bool const os_fonts_available =
3051 bp_.baseClass()->outputType() == lyx::LATEX
3052 && LaTeXFeatures::isAvailable("fontspec");
3053 fontModule->osFontsCB->setEnabled(os_fonts_available);
3054 fontModule->osFontsCB->setChecked(
3055 os_fonts_available && bp_.useNonTeXFonts);
3056 updateFontsize(documentClass().opt_fontsize(),
3059 QString font = toqstr(bp_.fonts_roman);
3060 int rpos = fontModule->fontsRomanCO->findData(font);
3062 rpos = fontModule->fontsRomanCO->count();
3063 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3065 fontModule->fontsRomanCO->setCurrentIndex(rpos);
3067 font = toqstr(bp_.fonts_sans);
3068 int spos = fontModule->fontsSansCO->findData(font);
3070 spos = fontModule->fontsSansCO->count();
3071 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3073 fontModule->fontsSansCO->setCurrentIndex(spos);
3075 font = toqstr(bp_.fonts_typewriter);
3076 int tpos = fontModule->fontsTypewriterCO->findData(font);
3078 tpos = fontModule->fontsTypewriterCO->count();
3079 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3081 fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3083 if (bp_.useNonTeXFonts && os_fonts_available) {
3084 fontModule->fontencLA->setEnabled(false);
3085 fontModule->fontencCO->setEnabled(false);
3086 fontModule->fontencLE->setEnabled(false);
3088 fontModule->fontencLA->setEnabled(true);
3089 fontModule->fontencCO->setEnabled(true);
3090 fontModule->fontencLE->setEnabled(true);
3096 if (!bp_.fonts_cjk.empty())
3097 fontModule->cjkFontLE->setText(
3098 toqstr(bp_.fonts_cjk));
3100 fontModule->cjkFontLE->setText(QString());
3102 fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3103 fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3104 fontModule->scaleSansSB->setValue(bp_.fonts_sans_scale);
3105 fontModule->scaleTypewriterSB->setValue(bp_.fonts_typewriter_scale);
3107 int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3109 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3111 if (bp_.fontenc == "global") {
3112 fontModule->fontencCO->setCurrentIndex(0);
3113 fontModule->fontencLE->setEnabled(false);
3114 } else if (bp_.fontenc == "default") {
3115 fontModule->fontencCO->setCurrentIndex(2);
3116 fontModule->fontencLE->setEnabled(false);
3118 fontModule->fontencCO->setCurrentIndex(1);
3119 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3123 // This must be set _after_ fonts since updateDefaultFormat()
3124 // checks osFontsCB settings.
3125 // update combobox with formats
3126 updateDefaultFormat();
3127 int index = outputModule->defaultFormatCO->findData(toqstr(
3128 bp_.default_output_format));
3129 // set to default if format is not found
3132 outputModule->defaultFormatCO->setCurrentIndex(index);
3134 outputModule->outputsyncCB->setChecked(bp_.output_sync);
3135 outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3137 outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3138 outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3139 outputModule->strictCB->setChecked(bp_.html_be_strict);
3140 outputModule->cssCB->setChecked(bp_.html_css_as_file);
3143 bool const extern_geometry =
3144 documentClass().provides("geometry");
3145 int const psize = bp_.papersize;
3146 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3147 setCustomPapersize(!extern_geometry && psize == 1);
3148 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3150 bool const landscape =
3151 bp_.orientation == ORIENTATION_LANDSCAPE;
3152 pageLayoutModule->landscapeRB->setChecked(landscape);
3153 pageLayoutModule->portraitRB->setChecked(!landscape);
3154 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3155 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3157 pageLayoutModule->facingPagesCB->setChecked(
3158 bp_.sides == TwoSides);
3160 lengthToWidgets(pageLayoutModule->paperwidthLE,
3161 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3162 lengthToWidgets(pageLayoutModule->paperheightLE,
3163 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3166 Ui::MarginsUi * m = marginsModule;
3170 lengthToWidgets(m->topLE, m->topUnit,
3171 bp_.topmargin, default_unit);
3173 lengthToWidgets(m->bottomLE, m->bottomUnit,
3174 bp_.bottommargin, default_unit);
3176 lengthToWidgets(m->innerLE, m->innerUnit,
3177 bp_.leftmargin, default_unit);
3179 lengthToWidgets(m->outerLE, m->outerUnit,
3180 bp_.rightmargin, default_unit);
3182 lengthToWidgets(m->headheightLE, m->headheightUnit,
3183 bp_.headheight, default_unit);
3185 lengthToWidgets(m->headsepLE, m->headsepUnit,
3186 bp_.headsep, default_unit);
3188 lengthToWidgets(m->footskipLE, m->footskipUnit,
3189 bp_.footskip, default_unit);
3191 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3192 bp_.columnsep, default_unit);
3195 updateUnknownBranches();
3196 branchesModule->update(bp_);
3199 PDFOptions const & pdf = bp_.pdfoptions();
3200 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3201 if (bp_.documentClass().provides("hyperref"))
3202 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3204 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3205 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3206 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3207 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3208 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3210 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3211 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3212 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3214 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3216 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3217 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3218 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3219 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3221 nn = findToken(backref_opts, pdf.backref);
3223 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3225 pdfSupportModule->fullscreenCB->setChecked
3226 (pdf.pagemode == pdf.pagemode_fullscreen);
3228 pdfSupportModule->optionsLE->setText(
3229 toqstr(pdf.quoted_options));
3231 // Make sure that the bc is in the INITIAL state
3232 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3235 // clear changed branches cache
3236 changedBranches_.clear();
3240 void GuiDocument::saveDocDefault()
3242 // we have to apply the params first
3248 void GuiDocument::updateAvailableModules()
3250 modules_av_model_.clear();
3251 list<modInfoStruct> const & modInfoList = getModuleInfo();
3252 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3253 list<modInfoStruct>::const_iterator men = modInfoList.end();
3254 for (int i = 0; mit != men; ++mit, ++i)
3255 modules_av_model_.insertRow(i, mit->name, mit->id,
3260 void GuiDocument::updateSelectedModules()
3262 modules_sel_model_.clear();
3263 list<modInfoStruct> const selModList = getSelectedModules();
3264 list<modInfoStruct>::const_iterator mit = selModList.begin();
3265 list<modInfoStruct>::const_iterator men = selModList.end();
3266 for (int i = 0; mit != men; ++mit, ++i)
3267 modules_sel_model_.insertRow(i, mit->name, mit->id,
3272 void GuiDocument::updateIncludeonlys()
3274 masterChildModule->childrenTW->clear();
3275 QString const no = qt_("No");
3276 QString const yes = qt_("Yes");
3278 if (includeonlys_.empty()) {
3279 masterChildModule->includeallRB->setChecked(true);
3280 masterChildModule->childrenTW->setEnabled(false);
3281 masterChildModule->maintainAuxCB->setEnabled(false);
3283 masterChildModule->includeonlyRB->setChecked(true);
3284 masterChildModule->childrenTW->setEnabled(true);
3285 masterChildModule->maintainAuxCB->setEnabled(true);
3287 QTreeWidgetItem * item = 0;
3288 ListOfBuffers children = buffer().getChildren();
3289 ListOfBuffers::const_iterator it = children.begin();
3290 ListOfBuffers::const_iterator end = children.end();
3291 bool has_unincluded = false;
3292 bool all_unincluded = true;
3293 for (; it != end; ++it) {
3294 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3297 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3298 from_utf8(buffer().filePath())));
3299 item->setText(0, toqstr(name));
3300 item->setText(1, isChildIncluded(name) ? yes : no);
3301 if (!isChildIncluded(name))
3302 has_unincluded = true;
3304 all_unincluded = false;
3306 // Both if all childs are included and if none is included
3307 // is equal to "include all" (i.e., ommit \includeonly).
3308 // Thus, reset the GUI.
3309 if (!has_unincluded || all_unincluded) {
3310 masterChildModule->includeallRB->setChecked(true);
3311 masterChildModule->childrenTW->setEnabled(false);
3312 includeonlys_.clear();
3314 // If all are included, we need to update again.
3315 if (!has_unincluded)
3316 updateIncludeonlys();
3320 void GuiDocument::updateContents()
3322 // Nothing to do here as the document settings is not cursor dependant.
3327 void GuiDocument::useClassDefaults()
3329 if (applyPB->isEnabled()) {
3330 int const ret = Alert::prompt(_("Unapplied changes"),
3331 _("Some changes in the dialog were not yet applied.\n"
3332 "If you do not apply now, they will be lost after this action."),
3333 1, 1, _("&Apply"), _("&Dismiss"));
3338 int idx = latexModule->classCO->currentIndex();
3339 string const classname = classes_model_.getIDString(idx);
3340 if (!bp_.setBaseClass(classname)) {
3341 Alert::error(_("Error"), _("Unable to set document class."));
3344 bp_.useClassDefaults();
3349 void GuiDocument::setLayoutComboByIDString(string const & idString)
3351 int idx = classes_model_.findIDString(idString);
3353 Alert::warning(_("Can't set layout!"),
3354 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3356 latexModule->classCO->setCurrentIndex(idx);
3360 bool GuiDocument::isValid()
3363 validateListingsParameters().isEmpty() &&
3364 localLayout->isValid() &&
3366 // if we're asking for skips between paragraphs
3367 !textLayoutModule->skipRB->isChecked() ||
3368 // then either we haven't chosen custom
3369 textLayoutModule->skipCO->currentIndex() != 3 ||
3370 // or else a length has been given
3371 !textLayoutModule->skipLE->text().isEmpty()
3374 // if we're asking for indentation
3375 !textLayoutModule->indentRB->isChecked() ||
3376 // then either we haven't chosen custom
3377 textLayoutModule->indentCO->currentIndex() != 1 ||
3378 // or else a length has been given
3379 !textLayoutModule->indentLE->text().isEmpty()
3384 char const * const GuiDocument::fontfamilies[5] = {
3385 "default", "rmdefault", "sfdefault", "ttdefault", ""
3389 char const * GuiDocument::fontfamilies_gui[5] = {
3390 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3394 bool GuiDocument::initialiseParams(string const &)
3396 BufferView const * view = bufferview();
3398 bp_ = BufferParams();
3402 bp_ = view->buffer().params();
3404 updateAvailableModules();
3405 //FIXME It'd be nice to make sure here that the selected
3406 //modules are consistent: That required modules are actually
3407 //selected, and that we don't have conflicts. If so, we could
3408 //at least pop up a warning.
3414 void GuiDocument::clearParams()
3416 bp_ = BufferParams();
3420 BufferId GuiDocument::id() const
3422 BufferView const * const view = bufferview();
3423 return view? &view->buffer() : 0;
3427 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3429 return moduleNames_;
3433 list<GuiDocument::modInfoStruct> const
3434 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3436 LayoutModuleList::const_iterator it = mods.begin();
3437 LayoutModuleList::const_iterator end = mods.end();
3438 list<modInfoStruct> mInfo;
3439 for (; it != end; ++it) {
3442 LyXModule const * const mod = theModuleList[*it];
3445 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3447 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3454 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3456 return makeModuleInfo(params().getModules());
3460 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3462 return makeModuleInfo(params().baseClass()->providedModules());
3466 DocumentClass const & GuiDocument::documentClass() const
3468 return bp_.documentClass();
3472 static void dispatch_bufferparams(Dialog const & dialog,
3473 BufferParams const & bp, FuncCode lfun)
3476 ss << "\\begin_header\n";
3478 ss << "\\end_header\n";
3479 dialog.dispatch(FuncRequest(lfun, ss.str()));
3483 void GuiDocument::dispatchParams()
3485 // This must come first so that a language change is correctly noticed
3488 // Apply the BufferParams. Note that this will set the base class
3489 // and then update the buffer's layout.
3490 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3492 if (!params().master.empty()) {
3493 FileName const master_file = support::makeAbsPath(params().master,
3494 support::onlyPath(buffer().absFileName()));
3495 if (isLyXFileName(master_file.absFileName())) {
3496 Buffer * master = checkAndLoadLyXFile(master_file);
3498 if (master->isChild(const_cast<Buffer *>(&buffer())))
3499 const_cast<Buffer &>(buffer()).setParent(master);
3501 Alert::warning(_("Assigned master does not include this file"),
3502 bformat(_("You must include this file in the document\n"
3503 "'%1$s' in order to use the master document\n"
3504 "feature."), from_utf8(params().master)));
3506 Alert::warning(_("Could not load master"),
3507 bformat(_("The master document '%1$s'\n"
3508 "could not be loaded."),
3509 from_utf8(params().master)));
3513 // Generate the colours requested by each new branch.
3514 BranchList & branchlist = params().branchlist();
3515 if (!branchlist.empty()) {
3516 BranchList::const_iterator it = branchlist.begin();
3517 BranchList::const_iterator const end = branchlist.end();
3518 for (; it != end; ++it) {
3519 docstring const & current_branch = it->branch();
3520 Branch const * branch = branchlist.find(current_branch);
3521 string const x11hexname = X11hexname(branch->color());
3522 // display the new color
3523 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3524 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3527 // Open insets of selected branches, close deselected ones
3528 dispatch(FuncRequest(LFUN_INSET_FORALL,
3529 "Branch inset-toggle assign"));
3531 // rename branches in the document
3532 executeBranchRenaming();
3533 // and clear changed branches cache
3534 changedBranches_.clear();
3536 // Generate the colours requested by indices.
3537 IndicesList & indiceslist = params().indiceslist();
3538 if (!indiceslist.empty()) {
3539 IndicesList::const_iterator it = indiceslist.begin();
3540 IndicesList::const_iterator const end = indiceslist.end();
3541 for (; it != end; ++it) {
3542 docstring const & current_index = it->shortcut();
3543 Index const * index = indiceslist.findShortcut(current_index);
3544 string const x11hexname = X11hexname(index->color());
3545 // display the new color
3546 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3547 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3551 // If we used an LFUN, we would not need these two lines:
3552 BufferView * bv = const_cast<BufferView *>(bufferview());
3553 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3557 void GuiDocument::setLanguage() const
3559 Language const * const newL = bp_.language;
3560 if (buffer().params().language == newL)
3563 string const & lang_name = newL->lang();
3564 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3568 void GuiDocument::saveAsDefault() const
3570 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3574 bool GuiDocument::isFontAvailable(string const & font) const
3576 if (font == "default" || font == "cmr"
3577 || font == "cmss" || font == "cmtt")
3578 // these are standard
3580 if (font == "lmodern" || font == "lmss" || font == "lmtt")
3581 return LaTeXFeatures::isAvailable("lmodern");
3582 if (font == "times" || font == "palatino"
3583 || font == "helvet" || font == "courier")
3584 return LaTeXFeatures::isAvailable("psnfss");
3585 if (font == "cmbr" || font == "cmtl")
3586 return LaTeXFeatures::isAvailable("cmbright");
3587 if (font == "utopia")
3588 return LaTeXFeatures::isAvailable("utopia")
3589 || LaTeXFeatures::isAvailable("fourier");
3590 if (font == "beraserif" || font == "berasans"
3591 || font == "beramono")
3592 return LaTeXFeatures::isAvailable("bera");
3593 return LaTeXFeatures::isAvailable(font);
3597 bool GuiDocument::providesOSF(string const & font) const
3599 if (fontModule->osFontsCB->isChecked())
3600 // FIXME: we should check if the fonts really
3601 // have OSF support. But how?
3604 return isFontAvailable("eco");
3605 if (font == "palatino")
3606 return isFontAvailable("mathpazo");
3611 bool GuiDocument::providesSC(string const & font) const
3613 if (fontModule->osFontsCB->isChecked())
3615 if (font == "palatino")
3616 return isFontAvailable("mathpazo");
3617 if (font == "utopia")
3618 return isFontAvailable("fourier");
3623 bool GuiDocument::providesScale(string const & font) const
3625 if (fontModule->osFontsCB->isChecked())
3627 return font == "helvet" || font == "luximono"
3628 || font == "berasans" || font == "beramono";
3632 void GuiDocument::loadModuleInfo()
3634 moduleNames_.clear();
3635 LyXModuleList::const_iterator it = theModuleList.begin();
3636 LyXModuleList::const_iterator end = theModuleList.end();
3637 for (; it != end; ++it) {
3641 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3642 // this is supposed to give us the first sentence of the description
3645 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3646 int const pos = desc.indexOf(".");
3648 desc.truncate(pos + 1);
3649 m.description = desc;
3650 if (it->category().substr(0, 8) != "Citation")
3651 moduleNames_.push_back(m);
3656 void GuiDocument::updateUnknownBranches()
3660 list<docstring> used_branches;
3661 buffer().getUsedBranches(used_branches);
3662 list<docstring>::const_iterator it = used_branches.begin();
3663 QStringList unknown_branches;
3664 for (; it != used_branches.end() ; ++it) {
3665 if (!buffer().params().branchlist().find(*it))
3666 unknown_branches.append(toqstr(*it));
3668 branchesModule->setUnknownBranches(unknown_branches);
3672 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3674 map<docstring, docstring>::iterator it = changedBranches_.begin();
3675 for (; it != changedBranches_.end() ; ++it) {
3676 if (it->second == oldname) {
3677 // branch has already been renamed
3678 it->second = newname;
3683 changedBranches_[oldname] = newname;
3687 void GuiDocument::executeBranchRenaming() const
3689 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3690 for (; it != changedBranches_.end() ; ++it) {
3691 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3692 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3697 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3700 } // namespace frontend
3703 #include "moc_GuiDocument.cpp"