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"
50 #include "insets/InsetListingsParams.h"
52 #include "support/debug.h"
53 #include "support/FileName.h"
54 #include "support/filetools.h"
55 #include "support/gettext.h"
56 #include "support/lstrings.h"
58 #include "frontends/alert.h"
60 #include <QAbstractItemModel>
61 #include <QHeaderView>
63 #include <QColorDialog>
64 #include <QCloseEvent>
65 #include <QFontDatabase>
67 #include <QTextCursor>
77 // a style sheet for buttons
78 // this is for example used for the background color setting button
79 static inline QString colorButtonStyleSheet(QColor const & bgColor)
81 if (bgColor.isValid()) {
82 QString rc = QLatin1String("background-color:");
91 using namespace lyx::support;
96 char const * const tex_graphics[] =
98 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
99 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
100 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
101 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
106 char const * const tex_graphics_gui[] =
108 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
109 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
110 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
111 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
112 "XeTeX", N_("None"), ""
116 char const * const tex_fonts_roman[] =
118 "default", "cmr", "lmodern", "ae", "times", "palatino",
119 "charter", "newcent", "bookman", "utopia", "beraserif",
120 "ccfonts", "chancery", ""
124 char const * tex_fonts_roman_gui[] =
126 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
127 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
128 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
129 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
134 char const * const tex_fonts_sans[] =
136 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
140 char const * tex_fonts_sans_gui[] =
142 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
143 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
147 char const * const tex_fonts_monospaced[] =
149 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
153 char const * tex_fonts_monospaced_gui[] =
155 N_("Default"), N_("Computer Modern Typewriter"),
156 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
157 N_("LuxiMono"), N_("CM Typewriter Light"), ""
161 char const * backref_opts[] =
163 "false", "section", "slide", "page", ""
167 char const * backref_opts_gui[] =
169 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
173 vector<pair<string, QString> > pagestyles;
176 } // anonymous namespace
180 RGBColor set_backgroundcolor;
181 bool is_backgroundcolor;
182 RGBColor set_fontcolor;
184 RGBColor set_notefontcolor;
187 // used when sorting the textclass list.
188 class less_textclass_avail_desc
189 : public binary_function<string, string, int>
192 bool operator()(string const & lhs, string const & rhs) const
194 // Ordering criteria:
195 // 1. Availability of text class
196 // 2. Description (lexicographic)
197 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
198 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
199 int const order = compare_no_case(
200 translateIfPossible(from_utf8(tc1.description())),
201 translateIfPossible(from_utf8(tc2.description())));
202 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
203 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
212 vector<string> getRequiredList(string const & modName)
214 LyXModule const * const mod = theModuleList[modName];
216 return vector<string>(); //empty such thing
217 return mod->getRequiredModules();
221 vector<string> getExcludedList(string const & modName)
223 LyXModule const * const mod = theModuleList[modName];
225 return vector<string>(); //empty such thing
226 return mod->getExcludedModules();
230 docstring getModuleDescription(string const & modName)
232 LyXModule const * const mod = theModuleList[modName];
234 return _("Module not found!");
236 return translateIfPossible(from_utf8(mod->getDescription()));
240 vector<string> getPackageList(string const & modName)
242 LyXModule const * const mod = theModuleList[modName];
244 return vector<string>(); //empty such thing
245 return mod->getPackageList();
249 bool isModuleAvailable(string const & modName)
251 LyXModule const * const mod = theModuleList[modName];
254 return mod->isAvailable();
257 } // anonymous namespace
260 /////////////////////////////////////////////////////////////////////
262 // ModuleSelectionManager
264 /////////////////////////////////////////////////////////////////////
266 /// SelectionManager for use with modules
267 class ModuleSelectionManager : public GuiSelectionManager
271 ModuleSelectionManager(
272 QTreeView * availableLV,
273 QListView * selectedLV,
277 QPushButton * downPB,
278 GuiIdListModel * availableModel,
279 GuiIdListModel * selectedModel,
280 GuiDocument const * container)
281 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
282 upPB, downPB, availableModel, selectedModel), container_(container)
285 void updateProvidedModules(LayoutModuleList const & pm)
286 { provided_modules_ = pm.list(); }
288 void updateExcludedModules(LayoutModuleList const & em)
289 { excluded_modules_ = em.list(); }
292 virtual void updateAddPB();
294 virtual void updateUpPB();
296 virtual void updateDownPB();
298 virtual void updateDelPB();
299 /// returns availableModel as a GuiIdListModel
300 GuiIdListModel * getAvailableModel()
302 return dynamic_cast<GuiIdListModel *>(availableModel);
304 /// returns selectedModel as a GuiIdListModel
305 GuiIdListModel * getSelectedModel()
307 return dynamic_cast<GuiIdListModel *>(selectedModel);
309 /// keeps a list of the modules the text class provides
310 list<string> provided_modules_;
312 list<string> excluded_modules_;
314 GuiDocument const * container_;
317 void ModuleSelectionManager::updateAddPB()
319 int const arows = availableModel->rowCount();
320 QModelIndexList const avail_sels =
321 availableLV->selectionModel()->selectedIndexes();
323 // disable if there aren't any modules (?), if none of them is chosen
324 // in the dialog, or if the chosen one is already selected for use.
325 if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
326 addPB->setEnabled(false);
330 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
331 string const modname = getAvailableModel()->getIDString(idx.row());
334 container_->params().moduleCanBeAdded(modname);
335 addPB->setEnabled(enable);
339 void ModuleSelectionManager::updateDownPB()
341 int const srows = selectedModel->rowCount();
343 downPB->setEnabled(false);
346 QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
347 int const curRow = curidx.row();
348 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
349 downPB->setEnabled(false);
353 // determine whether immediately succeding element requires this one
354 string const curmodname = getSelectedModel()->getIDString(curRow);
355 string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
357 vector<string> reqs = getRequiredList(nextmodname);
359 // if it doesn't require anything....
361 downPB->setEnabled(true);
365 // Enable it if this module isn't required.
366 // FIXME This should perhaps be more flexible and check whether, even
367 // if the next one is required, there is also an earlier one that will do.
369 find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
372 void ModuleSelectionManager::updateUpPB()
374 int const srows = selectedModel->rowCount();
376 upPB->setEnabled(false);
380 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
381 int curRow = curIdx.row();
382 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
383 upPB->setEnabled(false);
386 string const curmodname = getSelectedModel()->getIDString(curRow);
388 // determine whether immediately preceding element is required by this one
389 vector<string> reqs = getRequiredList(curmodname);
391 // if this one doesn't require anything....
393 upPB->setEnabled(true);
398 // Enable it if the preceding module isn't required.
399 // NOTE This is less flexible than it might be. We could check whether, even
400 // if the previous one is required, there is an earlier one that would do.
401 string const premod = getSelectedModel()->getIDString(curRow - 1);
402 upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
405 void ModuleSelectionManager::updateDelPB()
407 int const srows = selectedModel->rowCount();
409 deletePB->setEnabled(false);
413 QModelIndex const & curidx =
414 selectedLV->selectionModel()->currentIndex();
415 int const curRow = curidx.row();
416 if (curRow < 0 || curRow >= srows) { // invalid index?
417 deletePB->setEnabled(false);
421 string const curmodname = getSelectedModel()->getIDString(curRow);
423 // We're looking here for a reason NOT to enable the button. If we
424 // find one, we disable it and return. If we don't, we'll end up at
425 // the end of the function, and then we enable it.
426 for (int i = curRow + 1; i < srows; ++i) {
427 string const thisMod = getSelectedModel()->getIDString(i);
428 vector<string> reqs = getRequiredList(thisMod);
429 //does this one require us?
430 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
434 // OK, so this module requires us
435 // is there an EARLIER module that also satisfies the require?
436 // NOTE We demand that it be earlier to keep the list of modules
437 // consistent with the rule that a module must be proceeded by a
438 // required module. There would be more flexible ways to proceed,
439 // but that would be a lot more complicated, and the logic here is
440 // already complicated. (That's why I've left the debugging code.)
441 // lyxerr << "Testing " << thisMod << endl;
442 bool foundone = false;
443 for (int j = 0; j < curRow; ++j) {
444 string const mod = getSelectedModel()->getIDString(j);
445 // lyxerr << "In loop: Testing " << mod << endl;
446 // do we satisfy the require?
447 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
448 // lyxerr << mod << " does the trick." << endl;
453 // did we find a module to satisfy the require?
455 // lyxerr << "No matching module found." << endl;
456 deletePB->setEnabled(false);
460 // lyxerr << "All's well that ends well." << endl;
461 deletePB->setEnabled(true);
465 /////////////////////////////////////////////////////////////////////
469 /////////////////////////////////////////////////////////////////////
471 PreambleModule::PreambleModule() : current_id_(0)
473 // This is not a memory leak. The object will be destroyed
475 (void) new LaTeXHighlighter(preambleTE->document());
476 setFocusProxy(preambleTE);
477 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
481 void PreambleModule::update(BufferParams const & params, BufferId id)
483 QString preamble = toqstr(params.preamble);
484 // Nothing to do if the params and preamble are unchanged.
485 if (id == current_id_
486 && preamble == preambleTE->document()->toPlainText())
489 QTextCursor cur = preambleTE->textCursor();
490 // Save the coords before switching to the new one.
491 preamble_coords_[current_id_] =
492 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
494 // Save the params address for further use.
496 preambleTE->document()->setPlainText(preamble);
497 Coords::const_iterator it = preamble_coords_.find(current_id_);
498 if (it == preamble_coords_.end())
499 // First time we open this one.
500 preamble_coords_[current_id_] = make_pair(0, 0);
502 // Restore saved coords.
503 QTextCursor cur = preambleTE->textCursor();
504 cur.setPosition(it->second.first);
505 preambleTE->setTextCursor(cur);
506 preambleTE->verticalScrollBar()->setValue(it->second.second);
511 void PreambleModule::apply(BufferParams & params)
513 params.preamble = fromqstr(preambleTE->document()->toPlainText());
517 void PreambleModule::closeEvent(QCloseEvent * e)
519 // Save the coords before closing.
520 QTextCursor cur = preambleTE->textCursor();
521 preamble_coords_[current_id_] =
522 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
527 /////////////////////////////////////////////////////////////////////
531 /////////////////////////////////////////////////////////////////////
534 GuiDocument::GuiDocument(GuiView & lv)
535 : GuiDialog(lv, "document", qt_("Document Settings"))
539 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
540 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
541 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
542 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
544 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
545 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
547 // Manage the restore, ok, apply, restore and cancel/close buttons
548 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
550 bc().setApply(applyPB);
551 bc().setCancel(closePB);
552 bc().setRestore(restorePB);
556 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
557 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
558 this, SLOT(change_adaptor()));
559 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
560 this, SLOT(setLSpacing(int)));
561 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
562 this, SLOT(change_adaptor()));
564 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
565 this, SLOT(change_adaptor()));
566 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
567 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
568 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
569 this, SLOT(change_adaptor()));
570 connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
571 this, SLOT(setIndent(int)));
572 connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
573 this, SLOT(change_adaptor()));
574 connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
575 this, SLOT(change_adaptor()));
577 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
578 this, SLOT(change_adaptor()));
579 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
580 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
581 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
582 this, SLOT(change_adaptor()));
583 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
584 this, SLOT(setSkip(int)));
585 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
586 this, SLOT(change_adaptor()));
587 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
588 this, SLOT(change_adaptor()));
590 connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
591 this, SLOT(enableIndent(bool)));
592 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
593 this, SLOT(enableSkip(bool)));
595 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
596 this, SLOT(change_adaptor()));
597 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
598 this, SLOT(setColSep()));
600 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
601 textLayoutModule->lspacingLE));
602 textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
603 textLayoutModule->indentLE));
604 textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
605 textLayoutModule->skipLE));
607 textLayoutModule->indentCO->addItem(qt_("Default"));
608 textLayoutModule->indentCO->addItem(qt_("Custom"));
609 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
610 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
611 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
612 textLayoutModule->skipCO->addItem(qt_("Custom"));
613 textLayoutModule->lspacingCO->insertItem(
614 Spacing::Single, qt_("Single"));
615 textLayoutModule->lspacingCO->insertItem(
616 Spacing::Onehalf, qt_("OneHalf"));
617 textLayoutModule->lspacingCO->insertItem(
618 Spacing::Double, qt_("Double"));
619 textLayoutModule->lspacingCO->insertItem(
620 Spacing::Other, qt_("Custom"));
621 // initialize the length validator
622 bc().addCheckedLineEdit(textLayoutModule->indentLE);
623 bc().addCheckedLineEdit(textLayoutModule->skipLE);
626 // master/child handling
627 masterChildModule = new UiWidget<Ui::MasterChildUi>;
629 connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
630 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
631 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
632 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
633 connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
634 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
635 connect(masterChildModule->includeallRB, SIGNAL(clicked()),
636 this, SLOT(change_adaptor()));
637 connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
638 this, SLOT(change_adaptor()));
639 connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
640 this, SLOT(change_adaptor()));
641 masterChildModule->childrenTW->setColumnCount(2);
642 masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
643 masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
644 masterChildModule->childrenTW->resizeColumnToContents(1);
645 masterChildModule->childrenTW->resizeColumnToContents(2);
649 outputModule = new UiWidget<Ui::OutputUi>;
651 connect(outputModule->xetexCB, SIGNAL(clicked()),
652 this, SLOT(change_adaptor()));
653 connect(outputModule->xetexCB, SIGNAL(toggled(bool)),
654 this, SLOT(xetexChanged(bool)));
655 connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
656 this, SLOT(change_adaptor()));
660 fontModule = new UiWidget<Ui::FontUi>;
661 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
662 this, SLOT(change_adaptor()));
663 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
664 this, SLOT(romanChanged(int)));
665 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
666 this, SLOT(change_adaptor()));
667 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
668 this, SLOT(sansChanged(int)));
669 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
670 this, SLOT(change_adaptor()));
671 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
672 this, SLOT(ttChanged(int)));
673 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
674 this, SLOT(change_adaptor()));
675 connect(fontModule->fontencCO, SIGNAL(activated(int)),
676 this, SLOT(change_adaptor()));
677 connect(fontModule->fontencCO, SIGNAL(activated(int)),
678 this, SLOT(fontencChanged(int)));
679 connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
680 this, SLOT(change_adaptor()));
681 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
682 this, SLOT(change_adaptor()));
683 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
684 this, SLOT(change_adaptor()));
685 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
686 this, SLOT(change_adaptor()));
687 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
688 this, SLOT(change_adaptor()));
689 connect(fontModule->fontScCB, SIGNAL(clicked()),
690 this, SLOT(change_adaptor()));
691 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
692 this, SLOT(change_adaptor()));
696 fontModule->fontsizeCO->addItem(qt_("Default"));
697 fontModule->fontsizeCO->addItem(qt_("10"));
698 fontModule->fontsizeCO->addItem(qt_("11"));
699 fontModule->fontsizeCO->addItem(qt_("12"));
701 fontModule->fontencCO->addItem(qt_("Default"));
702 fontModule->fontencCO->addItem(qt_("Custom"));
703 fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
705 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
706 fontModule->fontsDefaultCO->addItem(
707 qt_(GuiDocument::fontfamilies_gui[n]));
711 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
712 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
713 this, SLOT(papersizeChanged(int)));
714 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
715 this, SLOT(papersizeChanged(int)));
716 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
717 this, SLOT(portraitChanged()));
718 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
719 this, SLOT(change_adaptor()));
720 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
721 this, SLOT(change_adaptor()));
722 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
723 this, SLOT(change_adaptor()));
724 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
725 this, SLOT(change_adaptor()));
726 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
727 this, SLOT(change_adaptor()));
728 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
729 this, SLOT(change_adaptor()));
730 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
731 this, SLOT(change_adaptor()));
732 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
733 this, SLOT(change_adaptor()));
734 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
735 this, SLOT(change_adaptor()));
737 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
738 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
739 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
740 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
741 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
742 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
743 pageLayoutModule->paperheightL);
744 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
745 pageLayoutModule->paperwidthL);
747 QComboBox * cb = pageLayoutModule->papersizeCO;
748 cb->addItem(qt_("Default"));
749 cb->addItem(qt_("Custom"));
750 cb->addItem(qt_("US letter"));
751 cb->addItem(qt_("US legal"));
752 cb->addItem(qt_("US executive"));
753 cb->addItem(qt_("A3"));
754 cb->addItem(qt_("A4"));
755 cb->addItem(qt_("A5"));
756 cb->addItem(qt_("B3"));
757 cb->addItem(qt_("B4"));
758 cb->addItem(qt_("B5"));
759 // remove the %-items from the unit choice
760 pageLayoutModule->paperwidthUnitCO->noPercents();
761 pageLayoutModule->paperheightUnitCO->noPercents();
762 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
763 pageLayoutModule->paperheightLE));
764 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
765 pageLayoutModule->paperwidthLE));
769 marginsModule = new UiWidget<Ui::MarginsUi>;
770 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
771 this, SLOT(setCustomMargins(bool)));
772 connect(marginsModule->marginCB, SIGNAL(clicked()),
773 this, SLOT(change_adaptor()));
774 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
775 this, SLOT(change_adaptor()));
776 connect(marginsModule->topUnit, SIGNAL(activated(int)),
777 this, SLOT(change_adaptor()));
778 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
779 this, SLOT(change_adaptor()));
780 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
781 this, SLOT(change_adaptor()));
782 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
783 this, SLOT(change_adaptor()));
784 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
785 this, SLOT(change_adaptor()));
786 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
787 this, SLOT(change_adaptor()));
788 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
789 this, SLOT(change_adaptor()));
790 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
791 this, SLOT(change_adaptor()));
792 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
793 this, SLOT(change_adaptor()));
794 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
795 this, SLOT(change_adaptor()));
796 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
797 this, SLOT(change_adaptor()));
798 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
799 this, SLOT(change_adaptor()));
800 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
801 this, SLOT(change_adaptor()));
802 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
803 this, SLOT(change_adaptor()));
804 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
805 this, SLOT(change_adaptor()));
806 marginsModule->topLE->setValidator(unsignedLengthValidator(
807 marginsModule->topLE));
808 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
809 marginsModule->bottomLE));
810 marginsModule->innerLE->setValidator(unsignedLengthValidator(
811 marginsModule->innerLE));
812 marginsModule->outerLE->setValidator(unsignedLengthValidator(
813 marginsModule->outerLE));
814 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
815 marginsModule->headsepLE));
816 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
817 marginsModule->headheightLE));
818 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
819 marginsModule->footskipLE));
820 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
821 marginsModule->columnsepLE));
823 bc().addCheckedLineEdit(marginsModule->topLE,
824 marginsModule->topL);
825 bc().addCheckedLineEdit(marginsModule->bottomLE,
826 marginsModule->bottomL);
827 bc().addCheckedLineEdit(marginsModule->innerLE,
828 marginsModule->innerL);
829 bc().addCheckedLineEdit(marginsModule->outerLE,
830 marginsModule->outerL);
831 bc().addCheckedLineEdit(marginsModule->headsepLE,
832 marginsModule->headsepL);
833 bc().addCheckedLineEdit(marginsModule->headheightLE,
834 marginsModule->headheightL);
835 bc().addCheckedLineEdit(marginsModule->footskipLE,
836 marginsModule->footskipL);
837 bc().addCheckedLineEdit(marginsModule->columnsepLE,
838 marginsModule->columnsepL);
842 langModule = new UiWidget<Ui::LanguageUi>;
843 connect(langModule->languageCO, SIGNAL(activated(int)),
844 this, SLOT(change_adaptor()));
845 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
846 this, SLOT(change_adaptor()));
847 connect(langModule->otherencodingRB, SIGNAL(clicked()),
848 this, SLOT(change_adaptor()));
849 connect(langModule->encodingCO, SIGNAL(activated(int)),
850 this, SLOT(change_adaptor()));
851 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
852 this, SLOT(change_adaptor()));
854 QAbstractItemModel * language_model = guiApp->languageModel();
855 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
856 language_model->sort(0);
857 langModule->languageCO->setModel(language_model);
858 langModule->languageCO->setModelColumn(0);
860 // Always put the default encoding in the first position.
861 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
862 QStringList encodinglist;
863 Encodings::const_iterator it = encodings.begin();
864 Encodings::const_iterator const end = encodings.end();
865 for (; it != end; ++it)
866 encodinglist.append(qt_(it->guiName()));
868 langModule->encodingCO->addItems(encodinglist);
870 langModule->quoteStyleCO->addItem(qt_("``text''"));
871 langModule->quoteStyleCO->addItem(qt_("''text''"));
872 langModule->quoteStyleCO->addItem(qt_(",,text``"));
873 langModule->quoteStyleCO->addItem(qt_(",,text''"));
874 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
875 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
879 colorModule = new UiWidget<Ui::ColorUi>;
880 connect(colorModule->fontColorPB, SIGNAL(clicked()),
881 this, SLOT(changeFontColor()));
882 connect(colorModule->delFontColorTB, SIGNAL(clicked()),
883 this, SLOT(deleteFontColor()));
884 connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
885 this, SLOT(changeNoteFontColor()));
886 connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
887 this, SLOT(deleteNoteFontColor()));
888 connect(colorModule->backgroundPB, SIGNAL(clicked()),
889 this, SLOT(changeBackgroundColor()));
890 connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
891 this, SLOT(deleteBackgroundColor()));
895 numberingModule = new UiWidget<Ui::NumberingUi>;
896 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
897 this, SLOT(change_adaptor()));
898 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
899 this, SLOT(change_adaptor()));
900 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
901 this, SLOT(updateNumbering()));
902 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
903 this, SLOT(updateNumbering()));
904 numberingModule->tocTW->setColumnCount(3);
905 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
906 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
907 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
911 biblioModule = new UiWidget<Ui::BiblioUi>;
912 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
913 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
914 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
915 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
916 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
917 this, SLOT(change_adaptor()));
918 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
919 this, SLOT(change_adaptor()));
920 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
921 this, SLOT(change_adaptor()));
922 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
923 this, SLOT(change_adaptor()));
924 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
925 this, SLOT(change_adaptor()));
926 connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
927 this, SLOT(bibtexChanged(int)));
928 connect(biblioModule->bibtexOptionsED, SIGNAL(textChanged(QString)),
929 this, SLOT(change_adaptor()));
931 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
932 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
933 biblioModule->citeStyleCO->setCurrentIndex(0);
935 biblioModule->bibtexCO->clear();
936 biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
937 for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
938 it != lyxrc.bibtex_alternatives.end(); ++it) {
939 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
940 biblioModule->bibtexCO->addItem(command, command);
945 indicesModule = new GuiIndices;
946 connect(indicesModule, SIGNAL(changed()),
947 this, SLOT(change_adaptor()));
951 mathsModule = new UiWidget<Ui::MathsUi>;
952 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
953 mathsModule->amsCB, SLOT(setDisabled(bool)));
954 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
955 mathsModule->esintCB, SLOT(setDisabled(bool)));
956 connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)),
957 mathsModule->mhchemCB, SLOT(setDisabled(bool)));
959 connect(mathsModule->amsCB, SIGNAL(clicked()),
960 this, SLOT(change_adaptor()));
961 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
962 this, SLOT(change_adaptor()));
963 connect(mathsModule->esintCB, SIGNAL(clicked()),
964 this, SLOT(change_adaptor()));
965 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
966 this, SLOT(change_adaptor()));
967 connect(mathsModule->mhchemCB, SIGNAL(clicked()),
968 this, SLOT(change_adaptor()));
969 connect(mathsModule->mhchemautoCB, SIGNAL(clicked()),
970 this, SLOT(change_adaptor()));
974 latexModule = new UiWidget<Ui::LaTeXUi>;
975 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
976 this, SLOT(change_adaptor()));
977 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
978 this, SLOT(change_adaptor()));
979 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
980 this, SLOT(change_adaptor()));
981 connect(latexModule->classCO, SIGNAL(activated(int)),
982 this, SLOT(classChanged()));
983 connect(latexModule->classCO, SIGNAL(activated(int)),
984 this, SLOT(change_adaptor()));
985 connect(latexModule->layoutPB, SIGNAL(clicked()),
986 this, SLOT(browseLayout()));
987 connect(latexModule->layoutPB, SIGNAL(clicked()),
988 this, SLOT(change_adaptor()));
989 connect(latexModule->childDocGB, SIGNAL(clicked()),
990 this, SLOT(change_adaptor()));
991 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
992 this, SLOT(change_adaptor()));
993 connect(latexModule->childDocPB, SIGNAL(clicked()),
994 this, SLOT(browseMaster()));
995 connect(latexModule->suppressDateCB, SIGNAL(clicked()),
996 this, SLOT(change_adaptor()));
998 // postscript drivers
999 for (int n = 0; tex_graphics[n][0]; ++n) {
1000 QString enc = qt_(tex_graphics_gui[n]);
1001 latexModule->psdriverCO->addItem(enc);
1004 latexModule->classCO->setModel(&classes_model_);
1005 LayoutFileList const & bcl = LayoutFileList::get();
1006 vector<LayoutFileIndex> classList = bcl.classList();
1007 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1009 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
1010 vector<LayoutFileIndex>::const_iterator cen = classList.end();
1011 for (int i = 0; cit != cen; ++cit, ++i) {
1012 LayoutFile const & tc = bcl[*cit];
1013 docstring item = (tc.isTeXClassAvailable()) ?
1014 from_utf8(tc.description()) :
1015 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1016 classes_model_.insertRow(i, toqstr(item), *cit);
1021 branchesModule = new GuiBranches;
1022 connect(branchesModule, SIGNAL(changed()),
1023 this, SLOT(change_adaptor()));
1024 connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1025 this, SLOT(branchesRename(docstring const &, docstring const &)));
1026 updateUnknownBranches();
1030 preambleModule = new PreambleModule;
1031 connect(preambleModule, SIGNAL(changed()),
1032 this, SLOT(change_adaptor()));
1036 bulletsModule = new BulletsModule;
1037 connect(bulletsModule, SIGNAL(changed()),
1038 this, SLOT(change_adaptor()));
1042 modulesModule = new UiWidget<Ui::ModulesUi>;
1043 modulesModule->availableLV->header()->setVisible(false);
1045 new ModuleSelectionManager(modulesModule->availableLV,
1046 modulesModule->selectedLV,
1047 modulesModule->addPB, modulesModule->deletePB,
1048 modulesModule->upPB, modulesModule->downPB,
1049 availableModel(), selectedModel(), this);
1050 connect(selectionManager, SIGNAL(updateHook()),
1051 this, SLOT(updateModuleInfo()));
1052 connect(selectionManager, SIGNAL(updateHook()),
1053 this, SLOT(change_adaptor()));
1054 connect(selectionManager, SIGNAL(selectionChanged()),
1055 this, SLOT(modulesChanged()));
1059 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1060 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1061 this, SLOT(change_adaptor()));
1062 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1063 this, SLOT(change_adaptor()));
1064 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1065 this, SLOT(change_adaptor()));
1066 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1067 this, SLOT(change_adaptor()));
1068 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1069 this, SLOT(change_adaptor()));
1070 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1071 this, SLOT(change_adaptor()));
1072 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1073 this, SLOT(change_adaptor()));
1074 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1075 this, SLOT(change_adaptor()));
1076 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1077 this, SLOT(change_adaptor()));
1078 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1079 this, SLOT(change_adaptor()));
1080 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1081 this, SLOT(change_adaptor()));
1082 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1083 this, SLOT(change_adaptor()));
1084 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1085 this, SLOT(change_adaptor()));
1086 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1087 this, SLOT(change_adaptor()));
1088 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1089 this, SLOT(change_adaptor()));
1090 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1091 this, SLOT(change_adaptor()));
1093 for (int i = 0; backref_opts[i][0]; ++i)
1094 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1098 floatModule = new FloatPlacement;
1099 connect(floatModule, SIGNAL(changed()),
1100 this, SLOT(change_adaptor()));
1104 listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1105 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1106 this, SLOT(change_adaptor()));
1107 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1108 this, SLOT(change_adaptor()));
1109 connect(listingsModule->bypassCB, SIGNAL(clicked()),
1110 this, SLOT(setListingsMessage()));
1111 connect(listingsModule->listingsED, SIGNAL(textChanged()),
1112 this, SLOT(setListingsMessage()));
1113 listingsModule->listingsTB->setPlainText(
1114 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1118 docPS->addPanel(latexModule, qt_("Document Class"));
1119 docPS->addPanel(masterChildModule, qt_("Child Documents"));
1120 docPS->addPanel(modulesModule, qt_("Modules"));
1121 docPS->addPanel(fontModule, qt_("Fonts"));
1122 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1123 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1124 docPS->addPanel(marginsModule, qt_("Page Margins"));
1125 docPS->addPanel(langModule, qt_("Language"));
1126 docPS->addPanel(colorModule, qt_("Colors"));
1127 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1128 docPS->addPanel(biblioModule, qt_("Bibliography"));
1129 docPS->addPanel(indicesModule, qt_("Indexes"));
1130 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1131 docPS->addPanel(mathsModule, qt_("Math Options"));
1132 docPS->addPanel(floatModule, qt_("Float Placement"));
1133 docPS->addPanel(listingsModule, qt_("Listings"));
1134 docPS->addPanel(bulletsModule, qt_("Bullets"));
1135 docPS->addPanel(branchesModule, qt_("Branches"));
1136 docPS->addPanel(outputModule, qt_("Output"));
1137 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1138 docPS->setCurrentPanel(qt_("Document Class"));
1139 // FIXME: hack to work around resizing bug in Qt >= 4.2
1140 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1141 #if QT_VERSION >= 0x040200
1142 docPS->updateGeometry();
1147 void GuiDocument::showPreamble()
1149 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
1153 void GuiDocument::saveDefaultClicked()
1159 void GuiDocument::useDefaultsClicked()
1165 void GuiDocument::change_adaptor()
1171 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1176 string child = fromqstr(item->text(0));
1180 if (std::find(includeonlys_.begin(),
1181 includeonlys_.end(), child) != includeonlys_.end())
1182 includeonlys_.remove(child);
1184 includeonlys_.push_back(child);
1186 updateIncludeonlys();
1191 QString GuiDocument::validateListingsParameters()
1193 // use a cache here to avoid repeated validation
1194 // of the same parameters
1195 static string param_cache;
1196 static QString msg_cache;
1198 if (listingsModule->bypassCB->isChecked())
1201 string params = fromqstr(listingsModule->listingsED->toPlainText());
1202 if (params != param_cache) {
1203 param_cache = params;
1204 msg_cache = toqstr(InsetListingsParams(params).validate());
1210 void GuiDocument::setListingsMessage()
1212 static bool isOK = true;
1213 QString msg = validateListingsParameters();
1214 if (msg.isEmpty()) {
1218 // listingsTB->setTextColor("black");
1219 listingsModule->listingsTB->setPlainText(
1220 qt_("Input listings parameters below. "
1221 "Enter ? for a list of parameters."));
1224 // listingsTB->setTextColor("red");
1225 listingsModule->listingsTB->setPlainText(msg);
1230 void GuiDocument::setLSpacing(int item)
1232 textLayoutModule->lspacingLE->setEnabled(item == 3);
1236 void GuiDocument::setIndent(int item)
1238 bool const enable = (item == 1);
1239 textLayoutModule->indentLE->setEnabled(enable);
1240 textLayoutModule->indentLengthCO->setEnabled(enable);
1241 textLayoutModule->skipLE->setEnabled(false);
1242 textLayoutModule->skipLengthCO->setEnabled(false);
1247 void GuiDocument::enableIndent(bool indent)
1249 textLayoutModule->skipLE->setEnabled(!indent);
1250 textLayoutModule->skipLengthCO->setEnabled(!indent);
1252 setIndent(textLayoutModule->indentCO->currentIndex());
1256 void GuiDocument::setSkip(int item)
1258 bool const enable = (item == 3);
1259 textLayoutModule->skipLE->setEnabled(enable);
1260 textLayoutModule->skipLengthCO->setEnabled(enable);
1265 void GuiDocument::enableSkip(bool skip)
1267 textLayoutModule->indentLE->setEnabled(!skip);
1268 textLayoutModule->indentLengthCO->setEnabled(!skip);
1270 setSkip(textLayoutModule->skipCO->currentIndex());
1274 void GuiDocument::portraitChanged()
1276 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1280 void GuiDocument::setMargins(bool custom)
1282 bool const extern_geometry =
1283 documentClass().provides("geometry");
1284 marginsModule->marginCB->setEnabled(!extern_geometry);
1285 if (extern_geometry) {
1286 marginsModule->marginCB->setChecked(false);
1287 setCustomMargins(true);
1290 marginsModule->marginCB->setChecked(custom);
1291 setCustomMargins(custom);
1295 void GuiDocument::papersizeChanged(int paper_size)
1297 setCustomPapersize(paper_size == 1);
1301 void GuiDocument::setCustomPapersize(bool custom)
1303 pageLayoutModule->paperwidthL->setEnabled(custom);
1304 pageLayoutModule->paperwidthLE->setEnabled(custom);
1305 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1306 pageLayoutModule->paperheightL->setEnabled(custom);
1307 pageLayoutModule->paperheightLE->setEnabled(custom);
1308 pageLayoutModule->paperheightLE->setFocus();
1309 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1313 void GuiDocument::setColSep()
1315 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1319 void GuiDocument::setCustomMargins(bool custom)
1321 marginsModule->topL->setEnabled(!custom);
1322 marginsModule->topLE->setEnabled(!custom);
1323 marginsModule->topUnit->setEnabled(!custom);
1325 marginsModule->bottomL->setEnabled(!custom);
1326 marginsModule->bottomLE->setEnabled(!custom);
1327 marginsModule->bottomUnit->setEnabled(!custom);
1329 marginsModule->innerL->setEnabled(!custom);
1330 marginsModule->innerLE->setEnabled(!custom);
1331 marginsModule->innerUnit->setEnabled(!custom);
1333 marginsModule->outerL->setEnabled(!custom);
1334 marginsModule->outerLE->setEnabled(!custom);
1335 marginsModule->outerUnit->setEnabled(!custom);
1337 marginsModule->headheightL->setEnabled(!custom);
1338 marginsModule->headheightLE->setEnabled(!custom);
1339 marginsModule->headheightUnit->setEnabled(!custom);
1341 marginsModule->headsepL->setEnabled(!custom);
1342 marginsModule->headsepLE->setEnabled(!custom);
1343 marginsModule->headsepUnit->setEnabled(!custom);
1345 marginsModule->footskipL->setEnabled(!custom);
1346 marginsModule->footskipLE->setEnabled(!custom);
1347 marginsModule->footskipUnit->setEnabled(!custom);
1349 bool const enableColSep = !custom &&
1350 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1351 marginsModule->columnsepL->setEnabled(enableColSep);
1352 marginsModule->columnsepLE->setEnabled(enableColSep);
1353 marginsModule->columnsepUnit->setEnabled(enableColSep);
1357 void GuiDocument::changeBackgroundColor()
1359 QColor const & newColor = QColorDialog::getColor(
1360 rgb2qcolor(set_backgroundcolor), asQWidget());
1361 if (!newColor.isValid())
1363 // set the button color and text
1364 colorModule->backgroundPB->setStyleSheet(
1365 colorButtonStyleSheet(newColor));
1366 colorModule->backgroundPB->setText(toqstr("Change..."));
1368 set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1369 is_backgroundcolor = true;
1374 void GuiDocument::deleteBackgroundColor()
1376 // set the button color back to default by setting an epmty StyleSheet
1377 colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1378 // change button text
1379 colorModule->backgroundPB->setText(toqstr("Default..."));
1380 // save default color (white)
1381 set_backgroundcolor = rgbFromHexName("#ffffff");
1382 is_backgroundcolor = false;
1387 void GuiDocument::changeFontColor()
1389 QColor const & newColor = QColorDialog::getColor(
1390 rgb2qcolor(set_fontcolor), asQWidget());
1391 if (!newColor.isValid())
1393 // set the button color and text
1394 colorModule->fontColorPB->setStyleSheet(
1395 colorButtonStyleSheet(newColor));
1396 colorModule->fontColorPB->setText(toqstr("Change..."));
1398 set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1399 is_fontcolor = true;
1404 void GuiDocument::deleteFontColor()
1406 // set the button color back to default by setting an epmty StyleSheet
1407 colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1408 // change button text
1409 colorModule->fontColorPB->setText(toqstr("Default..."));
1410 // save default color (black)
1411 set_fontcolor = rgbFromHexName("#000000");
1412 is_fontcolor = false;
1417 void GuiDocument::changeNoteFontColor()
1419 QColor const & newColor = QColorDialog::getColor(
1420 rgb2qcolor(set_notefontcolor), asQWidget());
1421 if (!newColor.isValid())
1423 // set the button color
1424 colorModule->noteFontColorPB->setStyleSheet(
1425 colorButtonStyleSheet(newColor));
1427 set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1432 void GuiDocument::deleteNoteFontColor()
1434 // set the button color back to light gray
1435 colorModule->noteFontColorPB->setStyleSheet(
1436 colorButtonStyleSheet(QColor(204, 204, 204, 255)));
1437 // save light gray as the set color
1438 set_notefontcolor = rgbFromHexName("#cccccc");
1443 void GuiDocument::xetexChanged(bool xetex)
1446 updateDefaultFormat();
1447 langModule->encodingCO->setEnabled(!xetex &&
1448 !langModule->defaultencodingRB->isChecked());
1449 langModule->defaultencodingRB->setEnabled(!xetex);
1450 langModule->otherencodingRB->setEnabled(!xetex);
1452 fontModule->fontsDefaultCO->setEnabled(!xetex);
1453 fontModule->fontsDefaultLA->setEnabled(!xetex);
1454 fontModule->cjkFontLE->setEnabled(!xetex);
1455 fontModule->cjkFontLA->setEnabled(!xetex);
1458 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1459 bool scaleable = providesScale(font);
1460 fontModule->scaleSansSB->setEnabled(scaleable);
1461 fontModule->scaleSansLA->setEnabled(scaleable);
1463 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1464 scaleable = providesScale(font);
1465 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1466 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1468 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1469 fontModule->fontScCB->setEnabled(providesSC(font));
1470 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1472 fontModule->fontencLA->setEnabled(!xetex);
1473 fontModule->fontencCO->setEnabled(!xetex);
1474 fontModule->fontencLE->setEnabled(!xetex);
1478 void GuiDocument::updateFontsize(string const & items, string const & sel)
1480 fontModule->fontsizeCO->clear();
1481 fontModule->fontsizeCO->addItem(qt_("Default"));
1483 for (int n = 0; !token(items,'|',n).empty(); ++n)
1484 fontModule->fontsizeCO->
1485 addItem(toqstr(token(items,'|',n)));
1487 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1488 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1489 fontModule->fontsizeCO->setCurrentIndex(n);
1496 void GuiDocument::updateFontlist()
1498 fontModule->fontsRomanCO->clear();
1499 fontModule->fontsSansCO->clear();
1500 fontModule->fontsTypewriterCO->clear();
1502 // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1503 if (outputModule->xetexCB->isChecked()) {
1504 fontModule->fontsRomanCO->addItem(qt_("Default"));
1505 fontModule->fontsSansCO->addItem(qt_("Default"));
1506 fontModule->fontsTypewriterCO->addItem(qt_("Default"));
1508 QFontDatabase fontdb;
1509 QStringList families(fontdb.families());
1510 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1511 fontModule->fontsRomanCO->addItem(*it);
1512 fontModule->fontsSansCO->addItem(*it);
1513 fontModule->fontsTypewriterCO->addItem(*it);
1518 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1519 QString font = qt_(tex_fonts_roman_gui[n]);
1520 if (!isFontAvailable(tex_fonts_roman[n]))
1521 font += qt_(" (not installed)");
1522 fontModule->fontsRomanCO->addItem(font);
1524 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1525 QString font = qt_(tex_fonts_sans_gui[n]);
1526 if (!isFontAvailable(tex_fonts_sans[n]))
1527 font += qt_(" (not installed)");
1528 fontModule->fontsSansCO->addItem(font);
1530 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1531 QString font = qt_(tex_fonts_monospaced_gui[n]);
1532 if (!isFontAvailable(tex_fonts_monospaced[n]))
1533 font += qt_(" (not installed)");
1534 fontModule->fontsTypewriterCO->addItem(font);
1539 void GuiDocument::fontencChanged(int item)
1541 fontModule->fontencLE->setEnabled(item == 1);
1545 void GuiDocument::romanChanged(int item)
1547 if (outputModule->xetexCB->isChecked())
1549 string const font = tex_fonts_roman[item];
1550 fontModule->fontScCB->setEnabled(providesSC(font));
1551 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1555 void GuiDocument::sansChanged(int item)
1557 if (outputModule->xetexCB->isChecked())
1559 string const font = tex_fonts_sans[item];
1560 bool scaleable = providesScale(font);
1561 fontModule->scaleSansSB->setEnabled(scaleable);
1562 fontModule->scaleSansLA->setEnabled(scaleable);
1566 void GuiDocument::ttChanged(int item)
1568 if (outputModule->xetexCB->isChecked())
1570 string const font = tex_fonts_monospaced[item];
1571 bool scaleable = providesScale(font);
1572 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1573 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1577 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1580 pageLayoutModule->pagestyleCO->clear();
1581 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1583 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1584 string style = token(items, '|', n);
1585 QString style_gui = qt_(style);
1586 pagestyles.push_back(pair<string, QString>(style, style_gui));
1587 pageLayoutModule->pagestyleCO->addItem(style_gui);
1590 if (sel == "default") {
1591 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1597 for (size_t i = 0; i < pagestyles.size(); ++i)
1598 if (pagestyles[i].first == sel)
1599 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1602 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1606 void GuiDocument::browseLayout()
1608 QString const label1 = qt_("Layouts|#o#O");
1609 QString const dir1 = toqstr(lyxrc.document_path);
1610 QStringList const filter(qt_("LyX Layout (*.layout)"));
1611 QString file = browseRelFile(QString(), bufferFilepath(),
1612 qt_("Local layout file"), filter, false,
1615 if (!file.endsWith(".layout"))
1618 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1619 fromqstr(bufferFilepath()));
1621 int const ret = Alert::prompt(_("Local layout file"),
1622 _("The layout file you have selected is a local layout\n"
1623 "file, not one in the system or user directory. Your\n"
1624 "document may not work with this layout if you do not\n"
1625 "keep the layout file in the document directory."),
1626 1, 1, _("&Set Layout"), _("&Cancel"));
1630 // load the layout file
1631 LayoutFileList & bcl = LayoutFileList::get();
1632 string classname = layoutFile.onlyFileName();
1633 // this will update an existing layout if that layout has been loaded before.
1634 LayoutFileIndex name = bcl.addLocalLayout(
1635 classname.substr(0, classname.size() - 7),
1636 layoutFile.onlyPath().absFilename());
1639 Alert::error(_("Error"),
1640 _("Unable to read local layout file."));
1644 // do not trigger classChanged if there is no change.
1645 if (latexModule->classCO->currentText() == toqstr(name))
1649 int idx = latexModule->classCO->findText(toqstr(name));
1651 classes_model_.insertRow(0, toqstr(name), name);
1652 latexModule->classCO->setCurrentIndex(0);
1654 latexModule->classCO->setCurrentIndex(idx);
1660 void GuiDocument::browseMaster()
1662 QString const title = qt_("Select master document");
1663 QString const dir1 = toqstr(lyxrc.document_path);
1664 QString const old = latexModule->childDocLE->text();
1665 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1666 QStringList const filter(qt_("LyX Files (*.lyx)"));
1667 QString file = browseRelFile(old, docpath, title, filter, false,
1668 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1670 if (!file.isEmpty())
1671 latexModule->childDocLE->setText(file);
1675 void GuiDocument::classChanged()
1677 int idx = latexModule->classCO->currentIndex();
1680 string const classname = classes_model_.getIDString(idx);
1682 // check whether the selected modules have changed.
1683 bool modules_changed = false;
1684 unsigned int const srows = selectedModel()->rowCount();
1685 if (srows != bp_.getModules().size())
1686 modules_changed = true;
1688 list<string>::const_iterator mit = bp_.getModules().begin();
1689 list<string>::const_iterator men = bp_.getModules().end();
1690 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1691 if (selectedModel()->getIDString(i) != *mit) {
1692 modules_changed = true;
1697 if (modules_changed || lyxrc.auto_reset_options) {
1698 if (applyPB->isEnabled()) {
1699 int const ret = Alert::prompt(_("Unapplied changes"),
1700 _("Some changes in the dialog were not yet applied.\n"
1701 "If you do not apply now, they will be lost after this action."),
1702 1, 1, _("&Apply"), _("&Dismiss"));
1708 // We load the TextClass as soon as it is selected. This is
1709 // necessary so that other options in the dialog can be updated
1710 // according to the new class. Note, however, that, if you use
1711 // the scroll wheel when sitting on the combo box, we'll load a
1712 // lot of TextClass objects very quickly....
1713 if (!bp_.setBaseClass(classname)) {
1714 Alert::error(_("Error"), _("Unable to set document class."));
1717 if (lyxrc.auto_reset_options)
1718 bp_.useClassDefaults();
1720 // With the introduction of modules came a distinction between the base
1721 // class and the document class. The former corresponds to the main layout
1722 // file; the latter is that plus the modules (or the document-specific layout,
1723 // or whatever else there could be). Our parameters come from the document
1724 // class. So when we set the base class, we also need to recreate the document
1725 // class. Otherwise, we still have the old one.
1726 bp_.makeDocumentClass();
1731 void GuiDocument::bibtexChanged(int n)
1733 biblioModule->bibtexOptionsED->setEnabled(n != 0);
1739 // This is an insanely complicated attempt to make this sort of thing
1740 // work with RTL languages.
1741 docstring formatStrVec(vector<string> const & v, docstring const & s)
1743 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1747 return from_utf8(v[0]);
1748 if (v.size() == 2) {
1749 docstring retval = _("%1$s and %2$s");
1750 retval = subst(retval, _("and"), s);
1751 return bformat(retval, from_utf8(v[0]), from_utf8(v[1]));
1753 // The idea here is to format all but the last two items...
1754 int const vSize = v.size();
1755 docstring t2 = _("%1$s, %2$s");
1756 docstring retval = from_utf8(v[0]);
1757 for (int i = 1; i < vSize - 2; ++i)
1758 retval = bformat(t2, retval, from_utf8(v[i]));
1759 //...and then to plug them, and the last two, into this schema
1760 docstring t = _("%1$s, %2$s, and %3$s");
1761 t = subst(t, _("and"), s);
1762 return bformat(t, retval, from_utf8(v[vSize - 2]), from_utf8(v[vSize - 1]));
1765 vector<string> idsToNames(vector<string> const & idList)
1767 vector<string> retval;
1768 vector<string>::const_iterator it = idList.begin();
1769 vector<string>::const_iterator end = idList.end();
1770 for (; it != end; ++it) {
1771 LyXModule const * const mod = theModuleList[*it];
1773 retval.push_back(*it + " (Unavailable)");
1775 retval.push_back(mod->getName());
1782 void GuiDocument::modulesToParams(BufferParams & bp)
1784 // update list of loaded modules
1785 bp.clearLayoutModules();
1786 int const srows = modules_sel_model_.rowCount();
1787 for (int i = 0; i < srows; ++i)
1788 bp.addLayoutModule(modules_sel_model_.getIDString(i));
1790 // update the list of removed modules
1791 bp.clearRemovedModules();
1792 LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
1793 list<string>::const_iterator rit = reqmods.begin();
1794 list<string>::const_iterator ren = reqmods.end();
1796 // check each of the default modules
1797 for (; rit != ren; rit++) {
1798 list<string>::const_iterator mit = bp.getModules().begin();
1799 list<string>::const_iterator men = bp.getModules().end();
1801 for (; mit != men; mit++) {
1808 // the module isn't present so must have been removed by the user
1809 bp.addRemovedModule(*rit);
1814 void GuiDocument::modulesChanged()
1816 modulesToParams(bp_);
1817 bp_.makeDocumentClass();
1822 void GuiDocument::updateModuleInfo()
1824 selectionManager->update();
1826 //Module description
1827 bool const focus_on_selected = selectionManager->selectedFocused();
1828 QAbstractItemView * lv;
1829 if (focus_on_selected)
1830 lv = modulesModule->selectedLV;
1832 lv= modulesModule->availableLV;
1833 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1834 modulesModule->infoML->document()->clear();
1837 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1838 GuiIdListModel const & id_model =
1839 focus_on_selected ? modules_sel_model_ : modules_av_model_;
1840 string const modName = id_model.getIDString(idx.row());
1841 docstring desc = getModuleDescription(modName);
1843 LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
1844 if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
1847 desc += _("Module provided by document class.");
1850 vector<string> pkglist = getPackageList(modName);
1851 docstring pkgdesc = formatStrVec(pkglist, _("and"));
1852 if (!pkgdesc.empty()) {
1855 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1858 pkglist = getRequiredList(modName);
1859 if (!pkglist.empty()) {
1860 vector<string> const reqdescs = idsToNames(pkglist);
1861 pkgdesc = formatStrVec(reqdescs, _("or"));
1864 desc += bformat(_("Module required: %1$s."), pkgdesc);
1867 pkglist = getExcludedList(modName);
1868 if (!pkglist.empty()) {
1869 vector<string> const reqdescs = idsToNames(pkglist);
1870 pkgdesc = formatStrVec(reqdescs, _( "and"));
1873 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1876 if (!isModuleAvailable(modName)) {
1879 desc += _("WARNING: Some required packages are unavailable!");
1882 modulesModule->infoML->document()->setPlainText(toqstr(desc));
1886 void GuiDocument::updateNumbering()
1888 DocumentClass const & tclass = documentClass();
1890 numberingModule->tocTW->setUpdatesEnabled(false);
1891 numberingModule->tocTW->clear();
1893 int const depth = numberingModule->depthSL->value();
1894 int const toc = numberingModule->tocSL->value();
1895 QString const no = qt_("No");
1896 QString const yes = qt_("Yes");
1897 QTreeWidgetItem * item = 0;
1899 DocumentClass::const_iterator lit = tclass.begin();
1900 DocumentClass::const_iterator len = tclass.end();
1901 for (; lit != len; ++lit) {
1902 int const toclevel = lit->toclevel;
1903 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1904 item = new QTreeWidgetItem(numberingModule->tocTW);
1905 item->setText(0, toqstr(translateIfPossible(lit->name())));
1906 item->setText(1, (toclevel <= depth) ? yes : no);
1907 item->setText(2, (toclevel <= toc) ? yes : no);
1911 numberingModule->tocTW->setUpdatesEnabled(true);
1912 numberingModule->tocTW->update();
1916 void GuiDocument::updateDefaultFormat()
1920 // make a copy in order to consider unapplied changes
1921 Buffer * tmpbuf = buffer().clone();
1922 tmpbuf->params().useXetex = outputModule->xetexCB->isChecked();
1923 int idx = latexModule->classCO->currentIndex();
1925 string const classname = classes_model_.getIDString(idx);
1926 tmpbuf->params().setBaseClass(classname);
1927 tmpbuf->params().makeDocumentClass();
1929 outputModule->defaultFormatCO->blockSignals(true);
1930 outputModule->defaultFormatCO->clear();
1931 outputModule->defaultFormatCO->addItem(qt_("Default"),
1932 QVariant(QString("default")));
1933 typedef vector<Format const *> Formats;
1934 Formats formats = tmpbuf->exportableFormats(true);
1935 Formats::const_iterator cit = formats.begin();
1936 Formats::const_iterator end = formats.end();
1937 for (; cit != end; ++cit)
1938 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
1939 QVariant(toqstr((*cit)->name())));
1940 outputModule->defaultFormatCO->blockSignals(false);
1946 bool GuiDocument::isChildIncluded(string const & child)
1948 if (includeonlys_.empty())
1950 return (std::find(includeonlys_.begin(),
1951 includeonlys_.end(), child) != includeonlys_.end());
1955 void GuiDocument::applyView()
1958 preambleModule->apply(bp_);
1961 bp_.suppress_date = latexModule->suppressDateCB->isChecked();
1964 bp_.setCiteEngine(ENGINE_BASIC);
1966 if (biblioModule->citeNatbibRB->isChecked()) {
1967 bool const use_numerical_citations =
1968 biblioModule->citeStyleCO->currentIndex();
1969 if (use_numerical_citations)
1970 bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
1972 bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
1974 } else if (biblioModule->citeJurabibRB->isChecked())
1975 bp_.setCiteEngine(ENGINE_JURABIB);
1978 biblioModule->bibtopicCB->isChecked();
1980 string const bibtex_command =
1981 fromqstr(biblioModule->bibtexCO->itemData(
1982 biblioModule->bibtexCO->currentIndex()).toString());
1983 string const bibtex_options =
1984 fromqstr(biblioModule->bibtexOptionsED->text());
1985 if (bibtex_command == "default" || bibtex_options.empty())
1986 bp_.bibtex_command = bibtex_command;
1988 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
1991 indicesModule->apply(bp_);
1993 // language & quotes
1994 if (langModule->defaultencodingRB->isChecked()) {
1995 bp_.inputenc = "auto";
1997 int i = langModule->encodingCO->currentIndex();
1999 bp_.inputenc = "default";
2001 QString const enc_gui =
2002 langModule->encodingCO->currentText();
2003 Encodings::const_iterator it = encodings.begin();
2004 Encodings::const_iterator const end = encodings.end();
2006 for (; it != end; ++it) {
2007 if (qt_(it->guiName()) == enc_gui) {
2008 bp_.inputenc = it->latexName();
2014 // should not happen
2015 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2016 bp_.inputenc = "default";
2021 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2022 switch (langModule->quoteStyleCO->currentIndex()) {
2024 lga = InsetQuotes::EnglishQuotes;
2027 lga = InsetQuotes::SwedishQuotes;
2030 lga = InsetQuotes::GermanQuotes;
2033 lga = InsetQuotes::PolishQuotes;
2036 lga = InsetQuotes::FrenchQuotes;
2039 lga = InsetQuotes::DanishQuotes;
2042 bp_.quotes_language = lga;
2044 QString const lang = langModule->languageCO->itemData(
2045 langModule->languageCO->currentIndex()).toString();
2046 bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2049 bp_.backgroundcolor = set_backgroundcolor;
2050 bp_.isbackgroundcolor = is_backgroundcolor;
2051 bp_.fontcolor = set_fontcolor;
2052 bp_.isfontcolor = is_fontcolor;
2053 bp_.notefontcolor = set_notefontcolor;
2056 if (bp_.documentClass().hasTocLevels()) {
2057 bp_.tocdepth = numberingModule->tocSL->value();
2058 bp_.secnumdepth = numberingModule->depthSL->value();
2062 bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2063 bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2064 bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2065 bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2068 bp_.graphicsDriver =
2069 tex_graphics[latexModule->psdriverCO->currentIndex()];
2072 int idx = latexModule->classCO->currentIndex();
2074 string const classname = classes_model_.getIDString(idx);
2075 bp_.setBaseClass(classname);
2079 modulesToParams(bp_);
2082 if (mathsModule->amsautoCB->isChecked()) {
2083 bp_.use_amsmath = BufferParams::package_auto;
2085 if (mathsModule->amsCB->isChecked())
2086 bp_.use_amsmath = BufferParams::package_on;
2088 bp_.use_amsmath = BufferParams::package_off;
2090 if (mathsModule->esintautoCB->isChecked())
2091 bp_.use_esint = BufferParams::package_auto;
2093 if (mathsModule->esintCB->isChecked())
2094 bp_.use_esint = BufferParams::package_on;
2096 bp_.use_esint = BufferParams::package_off;
2098 if (mathsModule->mhchemautoCB->isChecked())
2099 bp_.use_mhchem = BufferParams::package_auto;
2101 if (mathsModule->mhchemCB->isChecked())
2102 bp_.use_mhchem = BufferParams::package_on;
2104 bp_.use_mhchem = BufferParams::package_off;
2108 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2109 bp_.pagestyle = "default";
2111 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2112 for (size_t i = 0; i != pagestyles.size(); ++i)
2113 if (pagestyles[i].second == style_gui)
2114 bp_.pagestyle = pagestyles[i].first;
2118 switch (textLayoutModule->lspacingCO->currentIndex()) {
2120 bp_.spacing().set(Spacing::Single);
2123 bp_.spacing().set(Spacing::Onehalf);
2126 bp_.spacing().set(Spacing::Double);
2129 bp_.spacing().set(Spacing::Other,
2130 widgetToDoubleStr(textLayoutModule->lspacingLE));
2134 if (textLayoutModule->twoColumnCB->isChecked())
2139 if (textLayoutModule->indentRB->isChecked()) {
2140 // if paragraphs are separated by an indentation
2141 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2142 switch (textLayoutModule->indentCO->currentIndex()) {
2144 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2147 HSpace indent = HSpace(
2148 widgetsToLength(textLayoutModule->indentLE,
2149 textLayoutModule->indentLengthCO)
2151 bp_.setIndentation(indent);
2155 // this should never happen
2156 bp_.setIndentation(HSpace(HSpace::DEFAULT));
2160 // if paragraphs are separated by a skip
2161 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2162 switch (textLayoutModule->skipCO->currentIndex()) {
2164 bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2167 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2170 bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2175 widgetsToLength(textLayoutModule->skipLE,
2176 textLayoutModule->skipLengthCO)
2182 // this should never happen
2183 bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2189 fromqstr(latexModule->optionsLE->text());
2191 bp_.use_default_options =
2192 latexModule->defaultOptionsCB->isChecked();
2194 if (latexModule->childDocGB->isChecked())
2196 fromqstr(latexModule->childDocLE->text());
2198 bp_.master = string();
2201 bp_.clearIncludedChildren();
2202 if (masterChildModule->includeonlyRB->isChecked()) {
2203 list<string>::const_iterator it = includeonlys_.begin();
2204 for (; it != includeonlys_.end() ; ++it) {
2205 bp_.addIncludedChildren(*it);
2208 bp_.maintain_unincluded_children =
2209 masterChildModule->maintainAuxCB->isChecked();
2212 bp_.float_placement = floatModule->get();
2215 // text should have passed validation
2216 bp_.listings_params =
2217 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2220 bp_.defaultOutputFormat = fromqstr(outputModule->defaultFormatCO->itemData(
2221 outputModule->defaultFormatCO->currentIndex()).toString());
2223 bool const xetex = outputModule->xetexCB->isChecked();
2224 bp_.useXetex = xetex;
2228 if (fontModule->fontsRomanCO->currentIndex() == 0)
2229 bp_.fontsRoman = "default";
2232 fromqstr(fontModule->fontsRomanCO->currentText());
2234 if (fontModule->fontsSansCO->currentIndex() == 0)
2235 bp_.fontsSans = "default";
2238 fromqstr(fontModule->fontsSansCO->currentText());
2240 if (fontModule->fontsTypewriterCO->currentIndex() == 0)
2241 bp_.fontsTypewriter = "default";
2243 bp_.fontsTypewriter =
2244 fromqstr(fontModule->fontsTypewriterCO->currentText());
2247 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
2250 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
2252 bp_.fontsTypewriter =
2253 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
2256 if (fontModule->fontencCO->currentIndex() == 0)
2257 bp_.fontenc = "global";
2258 else if (fontModule->fontencCO->currentIndex() == 1)
2259 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2260 else if (fontModule->fontencCO->currentIndex() == 2)
2261 bp_.fontenc = "default";
2264 fromqstr(fontModule->cjkFontLE->text());
2266 bp_.fontsSansScale = fontModule->scaleSansSB->value();
2268 bp_.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
2270 bp_.fontsSC = fontModule->fontScCB->isChecked();
2272 bp_.fontsOSF = fontModule->fontOsfCB->isChecked();
2275 bp_.fontsDefaultFamily = "default";
2277 bp_.fontsDefaultFamily = GuiDocument::fontfamilies[
2278 fontModule->fontsDefaultCO->currentIndex()];
2280 if (fontModule->fontsizeCO->currentIndex() == 0)
2281 bp_.fontsize = "default";
2284 fromqstr(fontModule->fontsizeCO->currentText());
2287 bp_.papersize = PAPER_SIZE(
2288 pageLayoutModule->papersizeCO->currentIndex());
2290 // custom, A3, B3 and B4 paper sizes need geometry
2291 int psize = pageLayoutModule->papersizeCO->currentIndex();
2292 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
2294 bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2295 pageLayoutModule->paperwidthUnitCO);
2297 bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2298 pageLayoutModule->paperheightUnitCO);
2300 if (pageLayoutModule->facingPagesCB->isChecked())
2301 bp_.sides = TwoSides;
2303 bp_.sides = OneSide;
2305 if (pageLayoutModule->landscapeRB->isChecked())
2306 bp_.orientation = ORIENTATION_LANDSCAPE;
2308 bp_.orientation = ORIENTATION_PORTRAIT;
2311 bp_.use_geometry = !marginsModule->marginCB->isChecked()
2314 Ui::MarginsUi const * m = marginsModule;
2316 bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2317 bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2318 bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2319 bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2320 bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2321 bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2322 bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2323 bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2326 branchesModule->apply(bp_);
2329 PDFOptions & pdf = bp_.pdfoptions();
2330 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2331 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2332 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2333 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2334 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2336 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2337 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2338 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2339 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2341 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2342 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2343 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2344 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2346 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2347 if (pdfSupportModule->fullscreenCB->isChecked())
2348 pdf.pagemode = pdf.pagemode_fullscreen;
2350 pdf.pagemode.clear();
2351 pdf.quoted_options = pdf.quoted_options_check(
2352 fromqstr(pdfSupportModule->optionsLE->text()));
2356 void GuiDocument::paramsToDialog()
2358 // set the default unit
2359 Length::UNIT const defaultUnit = Length::defaultUnit();
2362 preambleModule->update(bp_, id());
2365 latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2368 biblioModule->citeDefaultRB->setChecked(
2369 bp_.citeEngine() == ENGINE_BASIC);
2371 biblioModule->citeNatbibRB->setChecked(
2372 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
2373 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
2375 biblioModule->citeStyleCO->setCurrentIndex(
2376 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
2378 biblioModule->citeJurabibRB->setChecked(
2379 bp_.citeEngine() == ENGINE_JURABIB);
2381 biblioModule->bibtopicCB->setChecked(
2386 split(bp_.bibtex_command, command, ' ');
2388 int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2390 biblioModule->bibtexCO->setCurrentIndex(bpos);
2391 biblioModule->bibtexOptionsED->setText(toqstr(options).trimmed());
2393 biblioModule->bibtexCO->setCurrentIndex(0);
2394 biblioModule->bibtexOptionsED->clear();
2396 biblioModule->bibtexOptionsED->setEnabled(
2397 biblioModule->bibtexCO->currentIndex() != 0);
2400 indicesModule->update(bp_);
2402 // language & quotes
2403 int const pos = langModule->languageCO->findData(toqstr(
2404 bp_.language->lang()));
2405 langModule->languageCO->setCurrentIndex(pos);
2407 langModule->quoteStyleCO->setCurrentIndex(
2408 bp_.quotes_language);
2410 bool default_enc = true;
2411 if (bp_.inputenc != "auto") {
2412 default_enc = false;
2413 if (bp_.inputenc == "default") {
2414 langModule->encodingCO->setCurrentIndex(0);
2417 Encodings::const_iterator it = encodings.begin();
2418 Encodings::const_iterator const end = encodings.end();
2419 for (; it != end; ++it) {
2420 if (it->latexName() == bp_.inputenc) {
2421 enc_gui = it->guiName();
2425 int const i = langModule->encodingCO->findText(
2428 langModule->encodingCO->setCurrentIndex(i);
2430 // unknown encoding. Set to default.
2434 langModule->defaultencodingRB->setChecked(default_enc);
2435 langModule->otherencodingRB->setChecked(!default_enc);
2438 if (bp_.isfontcolor) {
2439 colorModule->fontColorPB->setStyleSheet(
2440 colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2442 set_fontcolor = bp_.fontcolor;
2443 is_fontcolor = bp_.isfontcolor;
2445 colorModule->noteFontColorPB->setStyleSheet(
2446 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2447 set_notefontcolor = bp_.notefontcolor;
2449 if (bp_.isbackgroundcolor) {
2450 colorModule->backgroundPB->setStyleSheet(
2451 colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2453 set_backgroundcolor = bp_.backgroundcolor;
2454 is_backgroundcolor = bp_.isbackgroundcolor;
2457 int const min_toclevel = documentClass().min_toclevel();
2458 int const max_toclevel = documentClass().max_toclevel();
2459 if (documentClass().hasTocLevels()) {
2460 numberingModule->setEnabled(true);
2461 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2462 numberingModule->depthSL->setMaximum(max_toclevel);
2463 numberingModule->depthSL->setValue(bp_.secnumdepth);
2464 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2465 numberingModule->tocSL->setMaximum(max_toclevel);
2466 numberingModule->tocSL->setValue(bp_.tocdepth);
2469 numberingModule->setEnabled(false);
2470 numberingModule->tocTW->clear();
2474 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2475 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2476 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2477 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2478 bulletsModule->init();
2481 int nitem = findToken(tex_graphics, bp_.graphicsDriver);
2483 latexModule->psdriverCO->setCurrentIndex(nitem);
2486 mathsModule->amsCB->setChecked(
2487 bp_.use_amsmath == BufferParams::package_on);
2488 mathsModule->amsautoCB->setChecked(
2489 bp_.use_amsmath == BufferParams::package_auto);
2491 mathsModule->esintCB->setChecked(
2492 bp_.use_esint == BufferParams::package_on);
2493 mathsModule->esintautoCB->setChecked(
2494 bp_.use_esint == BufferParams::package_auto);
2496 mathsModule->mhchemCB->setChecked(
2497 bp_.use_mhchem == BufferParams::package_on);
2498 mathsModule->mhchemautoCB->setChecked(
2499 bp_.use_mhchem == BufferParams::package_auto);
2501 switch (bp_.spacing().getSpace()) {
2502 case Spacing::Other: nitem = 3; break;
2503 case Spacing::Double: nitem = 2; break;
2504 case Spacing::Onehalf: nitem = 1; break;
2505 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2509 string const & layoutID = bp_.baseClassID();
2510 setLayoutComboByIDString(layoutID);
2512 updatePagestyle(documentClass().opt_pagestyle(),
2515 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2516 if (bp_.spacing().getSpace() == Spacing::Other) {
2517 doubleToWidget(textLayoutModule->lspacingLE,
2518 bp_.spacing().getValueAsString());
2522 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2523 textLayoutModule->indentRB->setChecked(true);
2524 string indentation = bp_.getIndentation().asLyXCommand();
2526 if (indentation != "default") {
2527 lengthToWidgets(textLayoutModule->indentLE,
2528 textLayoutModule->indentLengthCO,
2529 indentation, defaultUnit);
2532 textLayoutModule->indentCO->setCurrentIndex(indent);
2535 textLayoutModule->skipRB->setChecked(true);
2537 switch (bp_.getDefSkip().kind()) {
2538 case VSpace::SMALLSKIP:
2541 case VSpace::MEDSKIP:
2544 case VSpace::BIGSKIP:
2547 case VSpace::LENGTH:
2550 string const length = bp_.getDefSkip().asLyXCommand();
2551 lengthToWidgets(textLayoutModule->skipLE,
2552 textLayoutModule->skipLengthCO,
2553 length, defaultUnit);
2560 textLayoutModule->skipCO->setCurrentIndex(skip);
2564 textLayoutModule->twoColumnCB->setChecked(
2567 if (!bp_.options.empty()) {
2568 latexModule->optionsLE->setText(
2569 toqstr(bp_.options));
2571 latexModule->optionsLE->setText(QString());
2575 latexModule->defaultOptionsCB->setChecked(
2576 bp_.use_default_options);
2577 updateSelectedModules();
2578 selectionManager->updateProvidedModules(
2579 bp_.baseClass()->providedModules());
2580 selectionManager->updateExcludedModules(
2581 bp_.baseClass()->excludedModules());
2583 if (!documentClass().options().empty()) {
2584 latexModule->defaultOptionsLE->setText(
2585 toqstr(documentClass().options()));
2587 latexModule->defaultOptionsLE->setText(
2588 toqstr(_("[No options predefined]")));
2591 latexModule->defaultOptionsLE->setEnabled(
2592 bp_.use_default_options
2593 && !documentClass().options().empty());
2595 latexModule->defaultOptionsCB->setEnabled(
2596 !documentClass().options().empty());
2598 if (!bp_.master.empty()) {
2599 latexModule->childDocGB->setChecked(true);
2600 latexModule->childDocLE->setText(
2601 toqstr(bp_.master));
2603 latexModule->childDocLE->setText(QString());
2604 latexModule->childDocGB->setChecked(false);
2608 std::vector<Buffer *> children;
2610 children = buffer().getChildren(false);
2611 if (children.empty()) {
2612 masterChildModule->childrenTW->clear();
2613 includeonlys_.clear();
2614 docPS->showPanel(qt_("Child Documents"), false);
2615 if (docPS->isCurrentPanel(qt_("Child Documents")))
2616 docPS->setCurrentPanel(qt_("Document Class"));
2618 docPS->showPanel(qt_("Child Documents"), true);
2619 masterChildModule->setEnabled(true);
2620 includeonlys_ = bp_.getIncludedChildren();
2621 updateIncludeonlys();
2623 masterChildModule->maintainAuxCB->setChecked(
2624 bp_.maintain_unincluded_children);
2627 floatModule->set(bp_.float_placement);
2630 // break listings_params to multiple lines
2632 InsetListingsParams(bp_.listings_params).separatedParams();
2633 listingsModule->listingsED->setPlainText(toqstr(lstparams));
2636 // update combobox with formats
2637 updateDefaultFormat();
2638 int index = outputModule->defaultFormatCO->findData(toqstr(
2639 bp_.defaultOutputFormat));
2640 // set to default if format is not found
2643 outputModule->defaultFormatCO->setCurrentIndex(index);
2644 outputModule->xetexCB->setEnabled(bp_.baseClass()->outputType() == lyx::LATEX);
2645 outputModule->xetexCB->setChecked(
2646 bp_.baseClass()->outputType() == lyx::LATEX && bp_.useXetex);
2649 updateFontsize(documentClass().opt_fontsize(),
2653 fontModule->fontencLA->setEnabled(false);
2654 fontModule->fontencCO->setEnabled(false);
2655 fontModule->fontencLE->setEnabled(false);
2656 for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
2657 if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fontsRoman)) {
2658 fontModule->fontsRomanCO->setCurrentIndex(i);
2663 for (int i = 0; i < fontModule->fontsSansCO->count(); ++i) {
2664 if (fontModule->fontsSansCO->itemText(i) == toqstr(bp_.fontsSans)) {
2665 fontModule->fontsSansCO->setCurrentIndex(i);
2669 for (int i = 0; i < fontModule->fontsTypewriterCO->count(); ++i) {
2670 if (fontModule->fontsTypewriterCO->itemText(i) ==
2671 toqstr(bp_.fontsTypewriter)) {
2672 fontModule->fontsTypewriterCO->setCurrentIndex(i);
2677 fontModule->fontencLA->setEnabled(true);
2678 fontModule->fontencCO->setEnabled(true);
2679 fontModule->fontencLE->setEnabled(true);
2680 int n = findToken(tex_fonts_roman, bp_.fontsRoman);
2682 fontModule->fontsRomanCO->setCurrentIndex(n);
2686 n = findToken(tex_fonts_sans, bp_.fontsSans);
2688 fontModule->fontsSansCO->setCurrentIndex(n);
2692 n = findToken(tex_fonts_monospaced, bp_.fontsTypewriter);
2694 fontModule->fontsTypewriterCO->setCurrentIndex(n);
2699 if (!bp_.fontsCJK.empty())
2700 fontModule->cjkFontLE->setText(
2701 toqstr(bp_.fontsCJK));
2703 fontModule->cjkFontLE->setText(QString());
2705 fontModule->fontScCB->setChecked(bp_.fontsSC);
2706 fontModule->fontOsfCB->setChecked(bp_.fontsOSF);
2707 fontModule->scaleSansSB->setValue(bp_.fontsSansScale);
2708 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale);
2710 int nn = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily);
2712 fontModule->fontsDefaultCO->setCurrentIndex(nn);
2714 if (bp_.fontenc == "global")
2715 fontModule->fontencCO->setCurrentIndex(0);
2716 else if (bp_.fontenc == "default")
2717 fontModule->fontencCO->setCurrentIndex(2);
2719 fontModule->fontencCO->setCurrentIndex(1);
2720 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
2724 bool const extern_geometry =
2725 documentClass().provides("geometry");
2726 int const psize = bp_.papersize;
2727 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
2728 setCustomPapersize(!extern_geometry && psize == 1);
2729 pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
2731 bool const landscape =
2732 bp_.orientation == ORIENTATION_LANDSCAPE;
2733 pageLayoutModule->landscapeRB->setChecked(landscape);
2734 pageLayoutModule->portraitRB->setChecked(!landscape);
2735 pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
2736 pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
2738 pageLayoutModule->facingPagesCB->setChecked(
2739 bp_.sides == TwoSides);
2741 lengthToWidgets(pageLayoutModule->paperwidthLE,
2742 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, defaultUnit);
2743 lengthToWidgets(pageLayoutModule->paperheightLE,
2744 pageLayoutModule->paperheightUnitCO, bp_.paperheight, defaultUnit);
2747 Ui::MarginsUi * m = marginsModule;
2749 setMargins(!bp_.use_geometry);
2751 lengthToWidgets(m->topLE, m->topUnit,
2752 bp_.topmargin, defaultUnit);
2754 lengthToWidgets(m->bottomLE, m->bottomUnit,
2755 bp_.bottommargin, defaultUnit);
2757 lengthToWidgets(m->innerLE, m->innerUnit,
2758 bp_.leftmargin, defaultUnit);
2760 lengthToWidgets(m->outerLE, m->outerUnit,
2761 bp_.rightmargin, defaultUnit);
2763 lengthToWidgets(m->headheightLE, m->headheightUnit,
2764 bp_.headheight, defaultUnit);
2766 lengthToWidgets(m->headsepLE, m->headsepUnit,
2767 bp_.headsep, defaultUnit);
2769 lengthToWidgets(m->footskipLE, m->footskipUnit,
2770 bp_.footskip, defaultUnit);
2772 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2773 bp_.columnsep, defaultUnit);
2776 updateUnknownBranches();
2777 branchesModule->update(bp_);
2780 PDFOptions const & pdf = bp_.pdfoptions();
2781 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2782 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2783 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2784 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2785 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2787 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2788 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2789 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2791 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2793 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2794 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2795 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2796 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2798 nn = findToken(backref_opts, pdf.backref);
2800 pdfSupportModule->backrefCO->setCurrentIndex(nn);
2802 pdfSupportModule->fullscreenCB->setChecked
2803 (pdf.pagemode == pdf.pagemode_fullscreen);
2805 pdfSupportModule->optionsLE->setText(
2806 toqstr(pdf.quoted_options));
2808 // Make sure that the bc is in the INITIAL state
2809 if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
2812 // clear changed branches cache
2813 changedBranches_.clear();
2817 void GuiDocument::saveDocDefault()
2819 // we have to apply the params first
2825 void GuiDocument::updateAvailableModules()
2827 modules_av_model_.clear();
2828 list<modInfoStruct> const & modInfoList = getModuleInfo();
2829 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
2830 list<modInfoStruct>::const_iterator men = modInfoList.end();
2831 for (int i = 0; mit != men; ++mit, ++i)
2832 modules_av_model_.insertRow(i, mit->name, mit->id,
2837 void GuiDocument::updateSelectedModules()
2839 modules_sel_model_.clear();
2840 list<modInfoStruct> const selModList = getSelectedModules();
2841 list<modInfoStruct>::const_iterator mit = selModList.begin();
2842 list<modInfoStruct>::const_iterator men = selModList.end();
2843 for (int i = 0; mit != men; ++mit, ++i)
2844 modules_sel_model_.insertRow(i, mit->name, mit->id,
2849 void GuiDocument::updateIncludeonlys()
2851 masterChildModule->childrenTW->clear();
2852 QString const no = qt_("No");
2853 QString const yes = qt_("Yes");
2855 if (includeonlys_.empty()) {
2856 masterChildModule->includeallRB->setChecked(true);
2857 masterChildModule->childrenTW->setEnabled(false);
2858 masterChildModule->maintainAuxCB->setEnabled(false);
2860 masterChildModule->includeonlyRB->setChecked(true);
2861 masterChildModule->childrenTW->setEnabled(true);
2862 masterChildModule->maintainAuxCB->setEnabled(true);
2864 QTreeWidgetItem * item = 0;
2865 std::vector<Buffer *> children = buffer().getChildren(false);
2866 vector<Buffer *>::const_iterator it = children.begin();
2867 vector<Buffer *>::const_iterator end = children.end();
2868 bool has_unincluded = false;
2869 bool all_unincluded = true;
2870 for (; it != end; ++it) {
2871 item = new QTreeWidgetItem(masterChildModule->childrenTW);
2874 to_utf8(makeRelPath(from_utf8((*it)->fileName().absFilename()),
2875 from_utf8(buffer().filePath())));
2876 item->setText(0, toqstr(name));
2877 item->setText(1, isChildIncluded(name) ? yes : no);
2878 if (!isChildIncluded(name))
2879 has_unincluded = true;
2881 all_unincluded = false;
2883 // Both if all childs are included and if none is included
2884 // is equal to "include all" (i.e., ommit \includeonly).
2885 // Thus, reset the GUI.
2886 if (!has_unincluded || all_unincluded) {
2887 masterChildModule->includeallRB->setChecked(true);
2888 masterChildModule->childrenTW->setEnabled(false);
2889 includeonlys_.clear();
2891 // If all are included, we need to update again.
2892 if (!has_unincluded)
2893 updateIncludeonlys();
2897 void GuiDocument::updateContents()
2899 // Nothing to do here as the document settings is not cursor dependant.
2904 void GuiDocument::useClassDefaults()
2906 if (applyPB->isEnabled()) {
2907 int const ret = Alert::prompt(_("Unapplied changes"),
2908 _("Some changes in the dialog were not yet applied.\n"
2909 "If you do not apply now, they will be lost after this action."),
2910 1, 1, _("&Apply"), _("&Dismiss"));
2915 int idx = latexModule->classCO->currentIndex();
2916 string const classname = classes_model_.getIDString(idx);
2917 if (!bp_.setBaseClass(classname)) {
2918 Alert::error(_("Error"), _("Unable to set document class."));
2921 bp_.useClassDefaults();
2926 void GuiDocument::setLayoutComboByIDString(string const & idString)
2928 int idx = classes_model_.findIDString(idString);
2930 Alert::warning(_("Can't set layout!"),
2931 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2933 latexModule->classCO->setCurrentIndex(idx);
2937 bool GuiDocument::isValid()
2939 return validateListingsParameters().isEmpty()
2940 && (textLayoutModule->skipCO->currentIndex() != 3
2941 || !textLayoutModule->skipLE->text().isEmpty()
2942 || textLayoutModule->indentRB->isChecked())
2943 && (textLayoutModule->indentCO->currentIndex() != 1
2944 || !textLayoutModule->indentLE->text().isEmpty()
2945 || textLayoutModule->skipRB->isChecked());
2949 char const * const GuiDocument::fontfamilies[5] = {
2950 "default", "rmdefault", "sfdefault", "ttdefault", ""
2954 char const * GuiDocument::fontfamilies_gui[5] = {
2955 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2959 bool GuiDocument::initialiseParams(string const &)
2961 BufferView const * view = bufferview();
2963 bp_ = BufferParams();
2967 bp_ = view->buffer().params();
2969 updateAvailableModules();
2970 //FIXME It'd be nice to make sure here that the selected
2971 //modules are consistent: That required modules are actually
2972 //selected, and that we don't have conflicts. If so, we could
2973 //at least pop up a warning.
2979 void GuiDocument::clearParams()
2981 bp_ = BufferParams();
2985 BufferId GuiDocument::id() const
2987 BufferView const * const view = bufferview();
2988 return view? &view->buffer() : 0;
2992 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2994 return moduleNames_;
2998 list<GuiDocument::modInfoStruct> const
2999 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3001 LayoutModuleList::const_iterator it = mods.begin();
3002 LayoutModuleList::const_iterator end = mods.end();
3003 list<modInfoStruct> mInfo;
3004 for (; it != end; ++it) {
3007 LyXModule const * const mod = theModuleList[*it];
3010 m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3012 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3019 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3021 return makeModuleInfo(params().getModules());
3025 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3027 return makeModuleInfo(params().baseClass()->providedModules());
3031 DocumentClass const & GuiDocument::documentClass() const
3033 return bp_.documentClass();
3037 static void dispatch_bufferparams(Dialog const & dialog,
3038 BufferParams const & bp, FuncCode lfun)
3041 ss << "\\begin_header\n";
3043 ss << "\\end_header\n";
3044 dialog.dispatch(FuncRequest(lfun, ss.str()));
3048 void GuiDocument::dispatchParams()
3050 // This must come first so that a language change is correctly noticed
3053 // Apply the BufferParams. Note that this will set the base class
3054 // and then update the buffer's layout.
3055 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3057 if (!params().master.empty()) {
3058 FileName const master_file = support::makeAbsPath(params().master,
3059 support::onlyPath(buffer().absFileName()));
3060 if (isLyXFilename(master_file.absFilename())) {
3061 Buffer * master = checkAndLoadLyXFile(master_file);
3063 if (master->isChild(const_cast<Buffer *>(&buffer())))
3064 const_cast<Buffer &>(buffer()).setParent(master);
3066 Alert::warning(_("Assigned master does not include this file"),
3067 bformat(_("You must include this file in the document\n"
3068 "'%1$s' in order to use the master document\n"
3069 "feature."), from_utf8(params().master)));
3071 Alert::warning(_("Could not load master"),
3072 bformat(_("The master document '%1$s'\n"
3073 "could not be loaded."),
3074 from_utf8(params().master)));
3078 // Generate the colours requested by each new branch.
3079 BranchList & branchlist = params().branchlist();
3080 if (!branchlist.empty()) {
3081 BranchList::const_iterator it = branchlist.begin();
3082 BranchList::const_iterator const end = branchlist.end();
3083 for (; it != end; ++it) {
3084 docstring const & current_branch = it->branch();
3085 Branch const * branch = branchlist.find(current_branch);
3086 string const x11hexname = X11hexname(branch->color());
3087 // display the new color
3088 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3089 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3092 // Open insets of selected branches, close deselected ones
3093 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
3096 // rename branches in the document
3097 executeBranchRenaming();
3098 // and clear changed branches cache
3099 changedBranches_.clear();
3101 // Generate the colours requested by indices.
3102 IndicesList & indiceslist = params().indiceslist();
3103 if (!indiceslist.empty()) {
3104 IndicesList::const_iterator it = indiceslist.begin();
3105 IndicesList::const_iterator const end = indiceslist.end();
3106 for (; it != end; ++it) {
3107 docstring const & current_index = it->shortcut();
3108 Index const * index = indiceslist.findShortcut(current_index);
3109 string const x11hexname = X11hexname(index->color());
3110 // display the new color
3111 docstring const str = current_index + ' ' + from_ascii(x11hexname);
3112 dispatch(FuncRequest(LFUN_SET_COLOR, str));
3115 // FIXME: If we used an LFUN, we would not need those two lines:
3116 BufferView * bv = const_cast<BufferView *>(bufferview());
3117 bv->processUpdateFlags(Update::Force | Update::FitCursor);
3121 void GuiDocument::setLanguage() const
3123 Language const * const newL = bp_.language;
3124 if (buffer().params().language == newL)
3127 string const & lang_name = newL->lang();
3128 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3132 void GuiDocument::saveAsDefault() const
3134 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3138 bool GuiDocument::isFontAvailable(string const & font) const
3140 if (font == "default" || font == "cmr"
3141 || font == "cmss" || font == "cmtt")
3142 // these are standard
3144 if (font == "lmodern" || font == "lmss" || font == "lmtt")
3145 return LaTeXFeatures::isAvailable("lmodern");
3146 if (font == "times" || font == "palatino"
3147 || font == "helvet" || font == "courier")
3148 return LaTeXFeatures::isAvailable("psnfss");
3149 if (font == "cmbr" || font == "cmtl")
3150 return LaTeXFeatures::isAvailable("cmbright");
3151 if (font == "utopia")
3152 return LaTeXFeatures::isAvailable("utopia")
3153 || LaTeXFeatures::isAvailable("fourier");
3154 if (font == "beraserif" || font == "berasans"
3155 || font == "beramono")
3156 return LaTeXFeatures::isAvailable("bera");
3157 return LaTeXFeatures::isAvailable(font);
3161 bool GuiDocument::providesOSF(string const & font) const
3163 if (outputModule->xetexCB->isChecked())
3164 // FIXME: we should check if the fonts really
3165 // have OSF support. But how?
3168 return isFontAvailable("eco");
3169 if (font == "palatino")
3170 return isFontAvailable("mathpazo");
3175 bool GuiDocument::providesSC(string const & font) const
3177 if (outputModule->xetexCB->isChecked())
3179 if (font == "palatino")
3180 return isFontAvailable("mathpazo");
3181 if (font == "utopia")
3182 return isFontAvailable("fourier");
3187 bool GuiDocument::providesScale(string const & font) const
3189 if (outputModule->xetexCB->isChecked())
3191 return font == "helvet" || font == "luximono"
3192 || font == "berasans" || font == "beramono";
3196 void GuiDocument::loadModuleInfo()
3198 moduleNames_.clear();
3199 LyXModuleList::const_iterator it = theModuleList.begin();
3200 LyXModuleList::const_iterator end = theModuleList.end();
3201 for (; it != end; ++it) {
3205 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3206 // this is supposed to give us the first sentence of the description
3209 toqstr(translateIfPossible(from_utf8(it->getDescription())));
3210 int const pos = desc.indexOf(".");
3212 desc.truncate(pos + 1);
3213 m.description = desc;
3214 moduleNames_.push_back(m);
3219 void GuiDocument::updateUnknownBranches()
3223 list<docstring> used_branches;
3224 buffer().getUsedBranches(used_branches);
3225 list<docstring>::const_iterator it = used_branches.begin();
3226 QStringList unknown_branches;
3227 for (; it != used_branches.end() ; ++it) {
3228 if (!buffer().params().branchlist().find(*it))
3229 unknown_branches.append(toqstr(*it));
3231 branchesModule->setUnknownBranches(unknown_branches);
3235 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3237 map<docstring, docstring>::iterator it = changedBranches_.begin();
3238 for (; it != changedBranches_.end() ; ++it) {
3239 if (it->second == oldname) {
3240 // branch has already been renamed
3241 it->second = newname;
3246 changedBranches_[oldname] = newname;
3250 void GuiDocument::executeBranchRenaming() const
3252 map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3253 for (; it != changedBranches_.end() ; ++it) {
3254 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3255 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3260 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3263 } // namespace frontend
3266 #include "moc_GuiDocument.cpp"