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 "GuiSelectionManager.h"
19 #include "LaTeXHighlighter.h"
20 #include "LengthCombo.h"
21 #include "PanelStack.h"
22 #include "Validator.h"
24 #include "LayoutFile.h"
25 #include "BranchList.h"
26 #include "buffer_funcs.h"
28 #include "BufferParams.h"
29 #include "BufferView.h"
32 #include "FloatPlacement.h"
33 #include "FuncRequest.h"
35 #include "LaTeXFeatures.h"
37 #include "LyXRC.h" // defaultUnit
38 #include "ModuleList.h"
39 #include "OutputParams.h"
40 #include "PDFOptions.h"
41 #include "qt_helpers.h"
44 #include "insets/InsetListingsParams.h"
46 #include "support/debug.h"
47 #include "support/FileName.h"
48 #include "support/filetools.h"
49 #include "support/gettext.h"
50 #include "support/lstrings.h"
52 #include "frontends/alert.h"
54 #include <QAbstractItemModel>
55 #include <QCloseEvent>
57 #include <QTextCursor>
68 using namespace lyx::support;
73 char const * const tex_graphics[] =
75 "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
76 "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
77 "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
78 "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
83 char const * const tex_graphics_gui[] =
85 N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
86 "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
87 "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
88 "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
89 "XeTeX", N_("None"), ""
93 char const * const tex_fonts_roman[] =
95 "default", "cmr", "lmodern", "ae", "times", "palatino",
96 "charter", "newcent", "bookman", "utopia", "beraserif",
97 "ccfonts", "chancery", ""
101 char const * tex_fonts_roman_gui[] =
103 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
104 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
105 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
106 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
111 char const * const tex_fonts_sans[] =
113 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
117 char const * tex_fonts_sans_gui[] =
119 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
120 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
124 char const * const tex_fonts_monospaced[] =
126 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
130 char const * tex_fonts_monospaced_gui[] =
132 N_("Default"), N_("Computer Modern Typewriter"),
133 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
134 N_("LuxiMono"), N_("CM Typewriter Light"), ""
138 char const * backref_opts[] =
140 "false", "section", "slide", "page", ""
144 char const * backref_opts_gui[] =
146 N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
150 vector<pair<string, QString> > pagestyles;
153 } // anonymous namespace
158 // used when sorting the textclass list.
159 class less_textclass_avail_desc
160 : public binary_function<string, string, int>
163 bool operator()(string const & lhs, string const & rhs) const
165 // Ordering criteria:
166 // 1. Availability of text class
167 // 2. Description (lexicographic)
168 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
169 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
170 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
171 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
172 _(tc1.description()) < _(tc2.description()));
181 vector<string> getRequiredList(string const & modName)
183 LyXModule const * const mod = moduleList[modName];
185 return vector<string>(); //empty such thing
186 return mod->getRequiredModules();
190 vector<string> getExcludedList(string const & modName)
192 LyXModule const * const mod = moduleList[modName];
194 return vector<string>(); //empty such thing
195 return mod->getExcludedModules();
199 docstring getModuleDescription(string const & modName)
201 LyXModule const * const mod = moduleList[modName];
203 return _("Module not found!");
204 return _(mod->getDescription());
208 vector<string> getPackageList(string const & modName)
210 LyXModule const * const mod = moduleList[modName];
212 return vector<string>(); //empty such thing
213 return mod->getPackageList();
217 bool isModuleAvailable(string const & modName)
219 LyXModule * mod = moduleList[modName];
222 return mod->isAvailable();
225 } // anonymous namespace
228 /////////////////////////////////////////////////////////////////////
230 // ModuleSelectionManager
232 /////////////////////////////////////////////////////////////////////
234 /// SelectionManager for use with modules
235 class ModuleSelectionManager : public GuiSelectionManager
239 ModuleSelectionManager(
240 QListView * availableLV,
241 QListView * selectedLV,
245 QPushButton * downPB,
246 GuiIdListModel * availableModel,
247 GuiIdListModel * selectedModel)
248 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
249 upPB, downPB, availableModel, selectedModel)
253 virtual void updateAddPB();
255 virtual void updateUpPB();
257 virtual void updateDownPB();
259 virtual void updateDelPB();
260 /// returns availableModel as a GuiIdListModel
261 GuiIdListModel * getAvailableModel()
263 return dynamic_cast<GuiIdListModel *>(availableModel);
265 /// returns selectedModel as a GuiIdListModel
266 GuiIdListModel * getSelectedModel()
268 return dynamic_cast<GuiIdListModel *>(selectedModel);
272 void ModuleSelectionManager::updateAddPB()
274 int const arows = availableModel->rowCount();
275 QModelIndexList const availSels =
276 availableLV->selectionModel()->selectedIndexes();
277 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
278 addPB->setEnabled(false);
282 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
283 string const modName = getAvailableModel()->getIDString(idx.row());
284 vector<string> const reqs = getRequiredList(modName);
285 vector<string> const excl = getExcludedList(modName);
287 if (reqs.empty() && excl.empty()) {
288 addPB->setEnabled(true);
292 int const srows = selectedModel->rowCount();
293 vector<string> selModList;
294 for (int i = 0; i < srows; ++i)
295 selModList.push_back(getSelectedModel()->getIDString(i));
297 vector<string>::const_iterator const selModStart = selModList.begin();
298 vector<string>::const_iterator const selModEnd = selModList.end();
300 // Check whether some required module is available
302 bool foundOne = false;
303 vector<string>::const_iterator it = reqs.begin();
304 vector<string>::const_iterator en = reqs.end();
305 for (; it != en; ++it) {
306 if (find(selModStart, selModEnd, *it) != selModEnd) {
312 addPB->setEnabled(false);
317 // Check whether any excluded module is being used
319 vector<string>::const_iterator it = excl.begin();
320 vector<string>::const_iterator en = excl.end();
321 for (; it != en; ++it) {
322 if (find(selModStart, selModEnd, *it) != selModEnd) {
323 addPB->setEnabled(false);
329 addPB->setEnabled(true);
333 void ModuleSelectionManager::updateDownPB()
335 int const srows = selectedModel->rowCount();
337 downPB->setEnabled(false);
340 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
341 int const curRow = curIdx.row();
342 if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
343 downPB->setEnabled(false);
347 // determine whether immediately succeding element requires this one
348 string const curModName = getSelectedModel()->getIDString(curRow);
349 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
351 vector<string> reqs = getRequiredList(nextModName);
353 // if it doesn't require anything....
355 downPB->setEnabled(true);
359 // Enable it if this module isn't required.
360 // FIXME This should perhaps be more flexible and check whether, even
361 // if the next one is required, there is also an earlier one that will do.
363 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
366 void ModuleSelectionManager::updateUpPB()
368 int const srows = selectedModel->rowCount();
370 upPB->setEnabled(false);
374 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
375 int curRow = curIdx.row();
376 if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
377 upPB->setEnabled(false);
380 string const curModName = getSelectedModel()->getIDString(curRow);
382 // determine whether immediately preceding element is required by this one
383 vector<string> reqs = getRequiredList(curModName);
385 // if this one doesn't require anything....
387 upPB->setEnabled(true);
392 // Enable it if the preceding module isn't required.
393 // NOTE This is less flexible than it might be. We could check whether, even
394 // if the previous one is required, there is an earlier one that would do.
395 string const preModName = getSelectedModel()->getIDString(curRow - 1);
396 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
399 void ModuleSelectionManager::updateDelPB()
401 int const srows = selectedModel->rowCount();
403 deletePB->setEnabled(false);
407 QModelIndex const & curIdx =
408 selectedLV->selectionModel()->currentIndex();
409 int const curRow = curIdx.row();
410 if (curRow < 0 || curRow >= srows) { // invalid index?
411 deletePB->setEnabled(false);
415 string const curModName = getSelectedModel()->getIDString(curRow);
417 // We're looking here for a reason NOT to enable the button. If we
418 // find one, we disable it and return. If we don't, we'll end up at
419 // the end of the function, and then we enable it.
420 for (int i = curRow + 1; i < srows; ++i) {
421 string const thisMod = getSelectedModel()->getIDString(i);
422 vector<string> reqs = getRequiredList(thisMod);
423 //does this one require us?
424 if (find(reqs.begin(), reqs.end(), curModName) == reqs.end())
428 // OK, so this module requires us
429 // is there an EARLIER module that also satisfies the require?
430 // NOTE We demand that it be earlier to keep the list of modules
431 // consistent with the rule that a module must be proceeded by a
432 // required module. There would be more flexible ways to proceed,
433 // but that would be a lot more complicated, and the logic here is
434 // already complicated. (That's why I've left the debugging code.)
435 // lyxerr << "Testing " << thisMod << std::endl;
436 bool foundOne = false;
437 for (int j = 0; j < curRow; ++j) {
438 string const mod = getSelectedModel()->getIDString(j);
439 // lyxerr << "In loop: Testing " << mod << std::endl;
440 // do we satisfy the require?
441 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
442 // lyxerr << mod << " does the trick." << std::endl;
447 // did we find a module to satisfy the require?
449 // lyxerr << "No matching module found." << std::endl;
450 deletePB->setEnabled(false);
454 // lyxerr << "All's well that ends well." << std::endl;
455 deletePB->setEnabled(true);
459 /////////////////////////////////////////////////////////////////////
463 /////////////////////////////////////////////////////////////////////
465 PreambleModule::PreambleModule() : current_id_(0)
467 // This is not a memory leak. The object will be destroyed
469 (void) new LaTeXHighlighter(preambleTE->document());
470 setFocusProxy(preambleTE);
471 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
475 void PreambleModule::update(BufferParams const & params, BufferId id)
477 QString preamble = toqstr(params.preamble);
478 // Nothing to do if the params and preamble are unchanged.
479 if (id == current_id_
480 && preamble == preambleTE->document()->toPlainText())
483 QTextCursor cur = preambleTE->textCursor();
484 // Save the coords before switching to the new one.
485 preamble_coords_[current_id_] =
486 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
488 // Save the params address for further use.
490 preambleTE->document()->setPlainText(preamble);
491 Coords::const_iterator it = preamble_coords_.find(current_id_);
492 if (it == preamble_coords_.end())
493 // First time we open this one.
494 preamble_coords_[current_id_] = make_pair(0, 0);
496 // Restore saved coords.
497 QTextCursor cur = preambleTE->textCursor();
498 cur.setPosition(it->second.first);
499 preambleTE->setTextCursor(cur);
500 preambleTE->verticalScrollBar()->setValue(it->second.second);
505 void PreambleModule::apply(BufferParams & params)
507 params.preamble = fromqstr(preambleTE->document()->toPlainText());
511 void PreambleModule::closeEvent(QCloseEvent * e)
513 // Save the coords before closing.
514 QTextCursor cur = preambleTE->textCursor();
515 preamble_coords_[current_id_] =
516 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
521 /////////////////////////////////////////////////////////////////////
525 /////////////////////////////////////////////////////////////////////
528 GuiDocument::GuiDocument(GuiView & lv)
529 : GuiDialog(lv, "document", qt_("Document Settings"))
533 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
534 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
535 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
536 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
538 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
539 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
541 // Manage the restore, ok, apply, restore and cancel/close buttons
542 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
544 bc().setApply(applyPB);
545 bc().setCancel(closePB);
546 bc().setRestore(restorePB);
548 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
550 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
551 this, SLOT(change_adaptor()));
552 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
553 this, SLOT(setLSpacing(int)));
554 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
555 this, SLOT(change_adaptor()));
556 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
557 this, SLOT(change_adaptor()));
558 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
559 this, SLOT(change_adaptor()));
560 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
561 this, SLOT(change_adaptor()));
562 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
563 this, SLOT(change_adaptor()));
564 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
565 this, SLOT(change_adaptor()));
566 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
567 this, SLOT(setSkip(int)));
568 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
569 this, SLOT(enableSkip(bool)));
570 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
571 this, SLOT(change_adaptor()));
572 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
573 this, SLOT(setColSep()));
574 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
575 this, SLOT(change_adaptor()));
576 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
577 this, SLOT(change_adaptor()));
578 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
579 this, SLOT(setListingsMessage()));
580 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
581 this, SLOT(setListingsMessage()));
582 textLayoutModule->listingsTB->setPlainText(
583 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
584 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
585 textLayoutModule->lspacingLE));
586 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
587 textLayoutModule->skipLE));
589 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
590 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
591 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
592 textLayoutModule->skipCO->addItem(qt_("Length"));
593 // remove the %-items from the unit choice
594 textLayoutModule->skipLengthCO->noPercents();
595 textLayoutModule->lspacingCO->insertItem(
596 Spacing::Single, qt_("Single"));
597 textLayoutModule->lspacingCO->insertItem(
598 Spacing::Onehalf, qt_("OneHalf"));
599 textLayoutModule->lspacingCO->insertItem(
600 Spacing::Double, qt_("Double"));
601 textLayoutModule->lspacingCO->insertItem(
602 Spacing::Other, qt_("Custom"));
604 // initialize the length validator
605 bc().addCheckedLineEdit(textLayoutModule->skipLE);
607 fontModule = new UiWidget<Ui::FontUi>;
609 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
610 this, SLOT(change_adaptor()));
611 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
612 this, SLOT(romanChanged(int)));
613 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
614 this, SLOT(change_adaptor()));
615 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
616 this, SLOT(sansChanged(int)));
617 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
618 this, SLOT(change_adaptor()));
619 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
620 this, SLOT(ttChanged(int)));
621 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
622 this, SLOT(change_adaptor()));
623 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
624 this, SLOT(change_adaptor()));
625 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
626 this, SLOT(change_adaptor()));
627 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
628 this, SLOT(change_adaptor()));
629 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
630 this, SLOT(change_adaptor()));
631 connect(fontModule->fontScCB, SIGNAL(clicked()),
632 this, SLOT(change_adaptor()));
633 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
634 this, SLOT(change_adaptor()));
636 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
637 QString font = qt_(tex_fonts_roman_gui[n]);
638 if (!isFontAvailable(tex_fonts_roman[n]))
639 font += qt_(" (not installed)");
640 fontModule->fontsRomanCO->addItem(font);
642 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
643 QString font = qt_(tex_fonts_sans_gui[n]);
644 if (!isFontAvailable(tex_fonts_sans[n]))
645 font += qt_(" (not installed)");
646 fontModule->fontsSansCO->addItem(font);
648 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
649 QString font = qt_(tex_fonts_monospaced_gui[n]);
650 if (!isFontAvailable(tex_fonts_monospaced[n]))
651 font += qt_(" (not installed)");
652 fontModule->fontsTypewriterCO->addItem(font);
655 fontModule->fontsizeCO->addItem(qt_("Default"));
656 fontModule->fontsizeCO->addItem(qt_("10"));
657 fontModule->fontsizeCO->addItem(qt_("11"));
658 fontModule->fontsizeCO->addItem(qt_("12"));
660 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
661 fontModule->fontsDefaultCO->addItem(
662 qt_(GuiDocument::fontfamilies_gui[n]));
665 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
667 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
668 this, SLOT(setCustomPapersize(int)));
669 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
670 this, SLOT(setCustomPapersize(int)));
671 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
672 this, SLOT(portraitChanged()));
673 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
674 this, SLOT(change_adaptor()));
675 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
676 this, SLOT(change_adaptor()));
677 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
678 this, SLOT(change_adaptor()));
679 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
680 this, SLOT(change_adaptor()));
681 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
682 this, SLOT(change_adaptor()));
683 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
684 this, SLOT(change_adaptor()));
685 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
686 this, SLOT(change_adaptor()));
687 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
688 this, SLOT(change_adaptor()));
689 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
690 this, SLOT(change_adaptor()));
692 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
693 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
694 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
695 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
696 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
697 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
698 pageLayoutModule->paperheightL);
699 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
700 pageLayoutModule->paperwidthL);
703 QComboBox * cb = pageLayoutModule->papersizeCO;
704 cb->addItem(qt_("Default"));
705 cb->addItem(qt_("Custom"));
706 cb->addItem(qt_("US letter"));
707 cb->addItem(qt_("US legal"));
708 cb->addItem(qt_("US executive"));
709 cb->addItem(qt_("A3"));
710 cb->addItem(qt_("A4"));
711 cb->addItem(qt_("A5"));
712 cb->addItem(qt_("B3"));
713 cb->addItem(qt_("B4"));
714 cb->addItem(qt_("B5"));
715 // remove the %-items from the unit choice
716 pageLayoutModule->paperwidthUnitCO->noPercents();
717 pageLayoutModule->paperheightUnitCO->noPercents();
718 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
719 pageLayoutModule->paperheightLE));
720 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
721 pageLayoutModule->paperwidthLE));
724 marginsModule = new UiWidget<Ui::MarginsUi>;
726 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
727 this, SLOT(setCustomMargins(bool)));
728 connect(marginsModule->marginCB, SIGNAL(clicked()),
729 this, SLOT(change_adaptor()));
730 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
731 this, SLOT(change_adaptor()));
732 connect(marginsModule->topUnit, SIGNAL(activated(int)),
733 this, SLOT(change_adaptor()));
734 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
735 this, SLOT(change_adaptor()));
736 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
737 this, SLOT(change_adaptor()));
738 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
739 this, SLOT(change_adaptor()));
740 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
741 this, SLOT(change_adaptor()));
742 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
743 this, SLOT(change_adaptor()));
744 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
745 this, SLOT(change_adaptor()));
746 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
747 this, SLOT(change_adaptor()));
748 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
749 this, SLOT(change_adaptor()));
750 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
751 this, SLOT(change_adaptor()));
752 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
753 this, SLOT(change_adaptor()));
754 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
755 this, SLOT(change_adaptor()));
756 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
757 this, SLOT(change_adaptor()));
758 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
759 this, SLOT(change_adaptor()));
760 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
761 this, SLOT(change_adaptor()));
762 marginsModule->topLE->setValidator(unsignedLengthValidator(
763 marginsModule->topLE));
764 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
765 marginsModule->bottomLE));
766 marginsModule->innerLE->setValidator(unsignedLengthValidator(
767 marginsModule->innerLE));
768 marginsModule->outerLE->setValidator(unsignedLengthValidator(
769 marginsModule->outerLE));
770 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
771 marginsModule->headsepLE));
772 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
773 marginsModule->headheightLE));
774 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
775 marginsModule->footskipLE));
776 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
777 marginsModule->columnsepLE));
779 bc().addCheckedLineEdit(marginsModule->topLE,
780 marginsModule->topL);
781 bc().addCheckedLineEdit(marginsModule->bottomLE,
782 marginsModule->bottomL);
783 bc().addCheckedLineEdit(marginsModule->innerLE,
784 marginsModule->innerL);
785 bc().addCheckedLineEdit(marginsModule->outerLE,
786 marginsModule->outerL);
787 bc().addCheckedLineEdit(marginsModule->headsepLE,
788 marginsModule->headsepL);
789 bc().addCheckedLineEdit(marginsModule->headheightLE,
790 marginsModule->headheightL);
791 bc().addCheckedLineEdit(marginsModule->footskipLE,
792 marginsModule->footskipL);
793 bc().addCheckedLineEdit(marginsModule->columnsepLE,
794 marginsModule->columnsepL);
797 langModule = new UiWidget<Ui::LanguageUi>;
799 connect(langModule->languageCO, SIGNAL(activated(int)),
800 this, SLOT(change_adaptor()));
801 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
802 this, SLOT(change_adaptor()));
803 connect(langModule->otherencodingRB, SIGNAL(clicked()),
804 this, SLOT(change_adaptor()));
805 connect(langModule->encodingCO, SIGNAL(activated(int)),
806 this, SLOT(change_adaptor()));
807 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
808 this, SLOT(change_adaptor()));
810 QAbstractItemModel * language_model = guiApp->languageModel();
811 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
812 language_model->sort(0);
813 langModule->languageCO->setModel(language_model);
815 // Always put the default encoding in the first position.
816 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
817 QStringList encodinglist;
818 Encodings::const_iterator it = encodings.begin();
819 Encodings::const_iterator const end = encodings.end();
820 for (; it != end; ++it)
821 encodinglist.append(qt_(it->guiName()));
823 langModule->encodingCO->addItems(encodinglist);
825 langModule->quoteStyleCO->addItem(qt_("``text''"));
826 langModule->quoteStyleCO->addItem(qt_("''text''"));
827 langModule->quoteStyleCO->addItem(qt_(",,text``"));
828 langModule->quoteStyleCO->addItem(qt_(",,text''"));
829 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
830 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
833 numberingModule = new UiWidget<Ui::NumberingUi>;
835 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
836 this, SLOT(change_adaptor()));
837 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
838 this, SLOT(change_adaptor()));
839 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
840 this, SLOT(updateNumbering()));
841 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
842 this, SLOT(updateNumbering()));
843 numberingModule->tocTW->setColumnCount(3);
844 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
845 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
846 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
849 biblioModule = new UiWidget<Ui::BiblioUi>;
850 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
851 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
852 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
853 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
855 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
856 this, SLOT(change_adaptor()));
857 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
858 this, SLOT(change_adaptor()));
859 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
860 this, SLOT(change_adaptor()));
861 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
862 this, SLOT(change_adaptor()));
863 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
864 this, SLOT(change_adaptor()));
866 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
867 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
868 biblioModule->citeStyleCO->setCurrentIndex(0);
871 mathsModule = new UiWidget<Ui::MathsUi>;
872 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
873 mathsModule->amsCB, SLOT(setDisabled(bool)));
874 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
875 mathsModule->esintCB, SLOT(setDisabled(bool)));
877 connect(mathsModule->amsCB, SIGNAL(clicked()),
878 this, SLOT(change_adaptor()));
879 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
880 this, SLOT(change_adaptor()));
881 connect(mathsModule->esintCB, SIGNAL(clicked()),
882 this, SLOT(change_adaptor()));
883 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
884 this, SLOT(change_adaptor()));
886 latexModule = new UiWidget<Ui::LaTeXUi>;
888 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
889 this, SLOT(change_adaptor()));
890 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
891 this, SLOT(change_adaptor()));
892 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
893 this, SLOT(change_adaptor()));
894 connect(latexModule->classCO, SIGNAL(activated(int)),
895 this, SLOT(classChanged()));
896 connect(latexModule->classCO, SIGNAL(activated(int)),
897 this, SLOT(change_adaptor()));
898 connect(latexModule->layoutPB, SIGNAL(clicked()),
899 this, SLOT(browseLayout()));
900 connect(latexModule->layoutPB, SIGNAL(clicked()),
901 this, SLOT(change_adaptor()));
902 connect(latexModule->childDocGB, SIGNAL(clicked()),
903 this, SLOT(change_adaptor()));
904 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
905 this, SLOT(change_adaptor()));
906 connect(latexModule->childDocPB, SIGNAL(clicked()),
907 this, SLOT(browseMaster()));
910 new ModuleSelectionManager(latexModule->availableLV,
911 latexModule->selectedLV,
912 latexModule->addPB, latexModule->deletePB,
913 latexModule->upPB, latexModule->downPB,
914 availableModel(), selectedModel());
915 connect(selectionManager, SIGNAL(updateHook()),
916 this, SLOT(updateModuleInfo()));
917 connect(selectionManager, SIGNAL(updateHook()),
918 this, SLOT(change_adaptor()));
920 // postscript drivers
921 for (int n = 0; tex_graphics[n][0]; ++n) {
922 QString enc = qt_(tex_graphics_gui[n]);
923 latexModule->psdriverCO->addItem(enc);
926 latexModule->classCO->setModel(&classes_model_);
927 LayoutFileList const & bcl = LayoutFileList::get();
928 vector<LayoutFileIndex> classList = bcl.classList();
929 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
931 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
932 vector<LayoutFileIndex>::const_iterator cen = classList.end();
933 for (int i = 0; cit != cen; ++cit, ++i) {
934 LayoutFile const & tc = bcl[*cit];
935 docstring item = (tc.isTeXClassAvailable()) ?
936 from_utf8(tc.description()) :
937 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
938 classes_model_.insertRow(i, toqstr(item), *cit);
942 branchesModule = new GuiBranches;
943 connect(branchesModule, SIGNAL(changed()),
944 this, SLOT(change_adaptor()));
947 preambleModule = new PreambleModule;
948 connect(preambleModule, SIGNAL(changed()),
949 this, SLOT(change_adaptor()));
952 bulletsModule = new BulletsModule;
953 connect(bulletsModule, SIGNAL(changed()),
954 this, SLOT(change_adaptor()));
957 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
959 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
960 this, SLOT(change_adaptor()));
961 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
962 this, SLOT(change_adaptor()));
963 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
964 this, SLOT(change_adaptor()));
965 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
966 this, SLOT(change_adaptor()));
967 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
968 this, SLOT(change_adaptor()));
969 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
970 this, SLOT(change_adaptor()));
971 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
972 this, SLOT(change_adaptor()));
973 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
974 this, SLOT(change_adaptor()));
975 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
976 this, SLOT(change_adaptor()));
977 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
978 this, SLOT(change_adaptor()));
979 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
980 this, SLOT(change_adaptor()));
981 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
982 this, SLOT(change_adaptor()));
983 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
984 this, SLOT(change_adaptor()));
985 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
986 this, SLOT(change_adaptor()));
987 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
988 this, SLOT(change_adaptor()));
989 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
990 this, SLOT(change_adaptor()));
992 for (int i = 0; backref_opts[i][0]; ++i)
993 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
996 floatModule = new FloatPlacement;
997 connect(floatModule, SIGNAL(changed()),
998 this, SLOT(change_adaptor()));
1000 docPS->addPanel(latexModule, qt_("Document Class"));
1001 docPS->addPanel(fontModule, qt_("Fonts"));
1002 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1003 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1004 docPS->addPanel(marginsModule, qt_("Page Margins"));
1005 docPS->addPanel(langModule, qt_("Language"));
1006 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1007 docPS->addPanel(biblioModule, qt_("Bibliography"));
1008 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1009 docPS->addPanel(mathsModule, qt_("Math Options"));
1010 docPS->addPanel(floatModule, qt_("Float Placement"));
1011 docPS->addPanel(bulletsModule, qt_("Bullets"));
1012 docPS->addPanel(branchesModule, qt_("Branches"));
1013 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1014 docPS->setCurrentPanel(qt_("Document Class"));
1015 // FIXME: hack to work around resizing bug in Qt >= 4.2
1016 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1017 #if QT_VERSION >= 0x040200
1018 docPS->updateGeometry();
1023 void GuiDocument::showPreamble()
1025 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
1029 void GuiDocument::saveDefaultClicked()
1035 void GuiDocument::useDefaultsClicked()
1041 void GuiDocument::change_adaptor()
1047 QString GuiDocument::validateListingsParameters()
1049 // use a cache here to avoid repeated validation
1050 // of the same parameters
1051 static string param_cache;
1052 static QString msg_cache;
1054 if (textLayoutModule->bypassCB->isChecked())
1057 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1058 if (params != param_cache) {
1059 param_cache = params;
1060 msg_cache = toqstr(InsetListingsParams(params).validate());
1066 void GuiDocument::setListingsMessage()
1068 static bool isOK = true;
1069 QString msg = validateListingsParameters();
1070 if (msg.isEmpty()) {
1074 // listingsTB->setTextColor("black");
1075 textLayoutModule->listingsTB->setPlainText(
1076 qt_("Input listings parameters on the right. "
1077 "Enter ? for a list of parameters."));
1080 // listingsTB->setTextColor("red");
1081 textLayoutModule->listingsTB->setPlainText(msg);
1086 void GuiDocument::setLSpacing(int item)
1088 textLayoutModule->lspacingLE->setEnabled(item == 3);
1092 void GuiDocument::setSkip(int item)
1094 bool const enable = (item == 3);
1095 textLayoutModule->skipLE->setEnabled(enable);
1096 textLayoutModule->skipLengthCO->setEnabled(enable);
1100 void GuiDocument::enableSkip(bool skip)
1102 textLayoutModule->skipCO->setEnabled(skip);
1103 textLayoutModule->skipLE->setEnabled(skip);
1104 textLayoutModule->skipLengthCO->setEnabled(skip);
1106 setSkip(textLayoutModule->skipCO->currentIndex());
1109 void GuiDocument::portraitChanged()
1111 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1114 void GuiDocument::setMargins(bool custom)
1116 marginsModule->marginCB->setChecked(custom);
1117 setCustomMargins(custom);
1121 void GuiDocument::setCustomPapersize(int papersize)
1123 bool const custom = (papersize == 1);
1125 pageLayoutModule->paperwidthL->setEnabled(custom);
1126 pageLayoutModule->paperwidthLE->setEnabled(custom);
1127 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1128 pageLayoutModule->paperheightL->setEnabled(custom);
1129 pageLayoutModule->paperheightLE->setEnabled(custom);
1130 pageLayoutModule->paperheightLE->setFocus();
1131 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1135 void GuiDocument::setColSep()
1137 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1141 void GuiDocument::setCustomMargins(bool custom)
1143 marginsModule->topL->setEnabled(!custom);
1144 marginsModule->topLE->setEnabled(!custom);
1145 marginsModule->topUnit->setEnabled(!custom);
1147 marginsModule->bottomL->setEnabled(!custom);
1148 marginsModule->bottomLE->setEnabled(!custom);
1149 marginsModule->bottomUnit->setEnabled(!custom);
1151 marginsModule->innerL->setEnabled(!custom);
1152 marginsModule->innerLE->setEnabled(!custom);
1153 marginsModule->innerUnit->setEnabled(!custom);
1155 marginsModule->outerL->setEnabled(!custom);
1156 marginsModule->outerLE->setEnabled(!custom);
1157 marginsModule->outerUnit->setEnabled(!custom);
1159 marginsModule->headheightL->setEnabled(!custom);
1160 marginsModule->headheightLE->setEnabled(!custom);
1161 marginsModule->headheightUnit->setEnabled(!custom);
1163 marginsModule->headsepL->setEnabled(!custom);
1164 marginsModule->headsepLE->setEnabled(!custom);
1165 marginsModule->headsepUnit->setEnabled(!custom);
1167 marginsModule->footskipL->setEnabled(!custom);
1168 marginsModule->footskipLE->setEnabled(!custom);
1169 marginsModule->footskipUnit->setEnabled(!custom);
1171 bool const enableColSep = !custom &&
1172 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1173 marginsModule->columnsepL->setEnabled(enableColSep);
1174 marginsModule->columnsepLE->setEnabled(enableColSep);
1175 marginsModule->columnsepUnit->setEnabled(enableColSep);
1179 void GuiDocument::updateFontsize(string const & items, string const & sel)
1181 fontModule->fontsizeCO->clear();
1182 fontModule->fontsizeCO->addItem(qt_("Default"));
1184 for (int n = 0; !token(items,'|',n).empty(); ++n)
1185 fontModule->fontsizeCO->
1186 addItem(toqstr(token(items,'|',n)));
1188 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1189 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1190 fontModule->fontsizeCO->setCurrentIndex(n);
1197 void GuiDocument::romanChanged(int item)
1199 string const font = tex_fonts_roman[item];
1200 fontModule->fontScCB->setEnabled(providesSC(font));
1201 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1205 void GuiDocument::sansChanged(int item)
1207 string const font = tex_fonts_sans[item];
1208 bool scaleable = providesScale(font);
1209 fontModule->scaleSansSB->setEnabled(scaleable);
1210 fontModule->scaleSansLA->setEnabled(scaleable);
1214 void GuiDocument::ttChanged(int item)
1216 string const font = tex_fonts_monospaced[item];
1217 bool scaleable = providesScale(font);
1218 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1219 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1223 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1226 pageLayoutModule->pagestyleCO->clear();
1227 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1229 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1230 string style = token(items, '|', n);
1231 QString style_gui = qt_(style);
1232 pagestyles.push_back(pair<string, QString>(style, style_gui));
1233 pageLayoutModule->pagestyleCO->addItem(style_gui);
1236 if (sel == "default") {
1237 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1243 for (size_t i = 0; i < pagestyles.size(); ++i)
1244 if (pagestyles[i].first == sel)
1245 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1248 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1252 void GuiDocument::browseLayout()
1254 QString const label1 = qt_("Layouts|#o#O");
1255 QString const dir1 = toqstr(lyxrc.document_path);
1256 QStringList const filter(qt_("LyX Layout (*.layout)"));
1257 QString file = browseRelFile(QString(), bufferFilepath(),
1258 qt_("Local layout file"), filter, false,
1261 if (!file.endsWith(".layout"))
1264 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1265 fromqstr(bufferFilepath()));
1267 int const ret = Alert::prompt(_("Local layout file"),
1268 _("The layout file you have selected is a local layout\n"
1269 "file, not one in the system or user directory. Your\n"
1270 "document may not work with this layout if you do not\n"
1271 "keep the layout file in the document directory."),
1272 1, 1, _("&Set Layout"), _("&Cancel"));
1276 // load the layout file
1277 LayoutFileList & bcl = LayoutFileList::get();
1278 string classname = layoutFile.onlyFileName();
1279 // this will update an existing layout if that layout has been loaded before.
1280 LayoutFileIndex name = bcl.addLocalLayout(
1281 classname.substr(0, classname.size() - 7),
1282 layoutFile.onlyPath().absFilename());
1285 Alert::error(_("Error"),
1286 _("Unable to read local layout file."));
1290 // do not trigger classChanged if there is no change.
1291 if (latexModule->classCO->currentText() == toqstr(name))
1295 int idx = latexModule->classCO->findText(toqstr(name));
1297 classes_model_.insertRow(0, toqstr(name), name);
1298 latexModule->classCO->setCurrentIndex(0);
1300 latexModule->classCO->setCurrentIndex(idx);
1306 void GuiDocument::browseMaster()
1308 QString const title = qt_("Select master document");
1309 QString const dir1 = toqstr(lyxrc.document_path);
1310 QString const old = latexModule->childDocLE->text();
1311 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1312 QStringList const filter(qt_("LyX Files (*.lyx)"));
1313 QString file = browseRelFile(old, docpath, title, filter, false,
1314 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1316 latexModule->childDocLE->setText(file);
1320 void GuiDocument::classChanged()
1322 int idx = latexModule->classCO->currentIndex();
1325 string const classname = classes_model_.getIDString(idx);
1327 // check whether the selected modules have changed.
1328 bool modulesChanged = false;
1329 unsigned int const srows = selectedModel()->rowCount();
1330 if (srows != bp_.getModules().size())
1331 modulesChanged = true;
1333 list<string>::const_iterator mit = bp_.getModules().begin();
1334 list<string>::const_iterator men = bp_.getModules().end();
1335 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1336 if (selectedModel()->getIDString(i) != *mit) {
1337 modulesChanged = true;
1342 if (modulesChanged || lyxrc.auto_reset_options) {
1343 if (applyPB->isEnabled()) {
1344 int const ret = Alert::prompt(_("Unapplied changes"),
1345 _("Some changes in the dialog were not yet applied.\n"
1346 "If you do not apply now, they will be lost after this action."),
1347 1, 1, _("&Apply"), _("&Dismiss"));
1353 // We load the TextClass as soon as it is selected. This is
1354 // necessary so that other options in the dialog can be updated
1355 // according to the new class. Note, however, that, if you use
1356 // the scroll wheel when sitting on the combo box, we'll load a
1357 // lot of TextClass objects very quickly....
1358 if (!bp_.setBaseClass(classname)) {
1359 Alert::error(_("Error"), _("Unable to set document class."));
1362 if (lyxrc.auto_reset_options)
1363 bp_.useClassDefaults();
1365 // With the introduction of modules came a distinction between the base
1366 // class and the document class. The former corresponds to the main layout
1367 // file; the latter is that plus the modules (or the document-specific layout,
1368 // or whatever else there could be). Our parameters come from the document
1369 // class. So when we set the base class, we also need to recreate the document
1370 // class. Otherwise, we still have the old one.
1371 bp_.makeDocumentClass();
1372 // the new class may require some default modules.
1373 updateSelectedModules();
1379 // This is an insanely complicated attempt to make this sort of thing
1380 // work with RTL languages.
1381 docstring formatStrVec(vector<string> const & v, docstring const & s)
1383 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1387 return from_ascii(v[0]);
1388 if (v.size() == 2) {
1389 docstring retval = _("%1$s and %2$s");
1390 retval = subst(retval, _("and"), s);
1391 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1393 // The idea here is to format all but the last two items...
1394 int const vSize = v.size();
1395 docstring t2 = _("%1$s, %2$s");
1396 docstring retval = from_ascii(v[0]);
1397 for (int i = 1; i < vSize - 2; ++i)
1398 retval = bformat(t2, retval, from_ascii(v[i]));
1399 //...and then to plug them, and the last two, into this schema
1400 docstring t = _("%1$s, %2$s, and %3$s");
1401 t = subst(t, _("and"), s);
1402 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1405 vector<string> idsToNames(vector<string> const & idList)
1407 vector<string> retval;
1408 vector<string>::const_iterator it = idList.begin();
1409 vector<string>::const_iterator end = idList.end();
1410 for (; it != end; ++it) {
1411 LyXModule const * const mod = moduleList[*it];
1413 retval.push_back(*it + " (Unavailable)");
1415 retval.push_back(mod->getName());
1422 void GuiDocument::updateModuleInfo()
1424 selectionManager->update();
1426 //Module description
1427 bool const focusOnSelected = selectionManager->selectedFocused();
1428 QListView const * const lv =
1429 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1430 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1431 latexModule->infoML->document()->clear();
1434 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1435 GuiIdListModel const & idModel =
1436 focusOnSelected ? modules_sel_model_ : modules_av_model_;
1437 string const modName = idModel.getIDString(idx.row());
1438 docstring desc = getModuleDescription(modName);
1440 vector<string> pkgList = getPackageList(modName);
1441 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1442 if (!pkgdesc.empty()) {
1445 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1448 pkgList = getRequiredList(modName);
1449 if (!pkgList.empty()) {
1450 vector<string> const reqDescs = idsToNames(pkgList);
1451 pkgdesc = formatStrVec(reqDescs, _("or"));
1454 desc += bformat(_("Module required: %1$s."), pkgdesc);
1457 pkgList = getExcludedList(modName);
1458 if (!pkgList.empty()) {
1459 vector<string> const reqDescs = idsToNames(pkgList);
1460 pkgdesc = formatStrVec(reqDescs, _( "and"));
1463 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1466 if (!isModuleAvailable(modName)) {
1469 desc += _("WARNING: Some packages are unavailable!");
1472 latexModule->infoML->document()->setPlainText(toqstr(desc));
1476 void GuiDocument::updateNumbering()
1478 DocumentClass const & tclass = documentClass();
1480 numberingModule->tocTW->setUpdatesEnabled(false);
1481 numberingModule->tocTW->clear();
1483 int const depth = numberingModule->depthSL->value();
1484 int const toc = numberingModule->tocSL->value();
1485 QString const no = qt_("No");
1486 QString const yes = qt_("Yes");
1487 QTreeWidgetItem * item = 0;
1489 DocumentClass::const_iterator lit = tclass.begin();
1490 DocumentClass::const_iterator len = tclass.end();
1491 for (; lit != len; ++lit) {
1492 int const toclevel = lit->toclevel;
1493 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1494 item = new QTreeWidgetItem(numberingModule->tocTW);
1495 item->setText(0, toqstr(translateIfPossible(lit->name())));
1496 item->setText(1, (toclevel <= depth) ? yes : no);
1497 item->setText(2, (toclevel <= toc) ? yes : no);
1501 numberingModule->tocTW->setUpdatesEnabled(true);
1502 numberingModule->tocTW->update();
1506 void GuiDocument::apply(BufferParams & params)
1509 preambleModule->apply(params);
1512 params.setCiteEngine(ENGINE_BASIC);
1514 if (biblioModule->citeNatbibRB->isChecked()) {
1515 bool const use_numerical_citations =
1516 biblioModule->citeStyleCO->currentIndex();
1517 if (use_numerical_citations)
1518 params.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
1520 params.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
1522 } else if (biblioModule->citeJurabibRB->isChecked())
1523 params.setCiteEngine(ENGINE_JURABIB);
1525 params.use_bibtopic =
1526 biblioModule->bibtopicCB->isChecked();
1528 // language & quotes
1529 if (langModule->defaultencodingRB->isChecked()) {
1530 params.inputenc = "auto";
1532 int i = langModule->encodingCO->currentIndex();
1534 params.inputenc = "default";
1536 QString const enc_gui =
1537 langModule->encodingCO->currentText();
1538 Encodings::const_iterator it = encodings.begin();
1539 Encodings::const_iterator const end = encodings.end();
1541 for (; it != end; ++it) {
1542 if (qt_(it->guiName()) == enc_gui) {
1543 params.inputenc = it->latexName();
1549 // should not happen
1550 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
1551 params.inputenc = "default";
1556 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
1557 switch (langModule->quoteStyleCO->currentIndex()) {
1559 lga = InsetQuotes::EnglishQuotes;
1562 lga = InsetQuotes::SwedishQuotes;
1565 lga = InsetQuotes::GermanQuotes;
1568 lga = InsetQuotes::PolishQuotes;
1571 lga = InsetQuotes::FrenchQuotes;
1574 lga = InsetQuotes::DanishQuotes;
1577 params.quotes_language = lga;
1579 QString const lang = langModule->languageCO->itemData(
1580 langModule->languageCO->currentIndex()).toString();
1581 params.language = lyx::languages.getLanguage(fromqstr(lang));
1584 if (params.documentClass().hasTocLevels()) {
1585 params.tocdepth = numberingModule->tocSL->value();
1586 params.secnumdepth = numberingModule->depthSL->value();
1590 params.user_defined_bullet(0) = bulletsModule->bullet(0);
1591 params.user_defined_bullet(1) = bulletsModule->bullet(1);
1592 params.user_defined_bullet(2) = bulletsModule->bullet(2);
1593 params.user_defined_bullet(3) = bulletsModule->bullet(3);
1596 params.graphicsDriver =
1597 tex_graphics[latexModule->psdriverCO->currentIndex()];
1600 int idx = latexModule->classCO->currentIndex();
1602 string const classname = classes_model_.getIDString(idx);
1603 params.setBaseClass(classname);
1607 params.clearLayoutModules();
1608 int const srows = modules_sel_model_.rowCount();
1609 vector<string> selModList;
1610 for (int i = 0; i < srows; ++i)
1611 params.addLayoutModule(modules_sel_model_.getIDString(i));
1612 // update the list of removed modules
1613 params.clearRemovedModules();
1614 list<string> const & reqmods = params.baseClass()->defaultModules();
1615 list<string>::const_iterator rit = reqmods.begin();
1616 list<string>::const_iterator ren = reqmods.end();
1617 // check each of the required modules
1618 for (; rit != ren; rit++) {
1619 list<string>::const_iterator mit = params.getModules().begin();
1620 list<string>::const_iterator men = params.getModules().end();
1622 for (; mit != men; mit++) {
1629 // the module isn't present so must have been removed by the user
1630 params.addRemovedModule(*rit);
1634 if (mathsModule->amsautoCB->isChecked()) {
1635 params.use_amsmath = BufferParams::package_auto;
1637 if (mathsModule->amsCB->isChecked())
1638 params.use_amsmath = BufferParams::package_on;
1640 params.use_amsmath = BufferParams::package_off;
1643 if (mathsModule->esintautoCB->isChecked())
1644 params.use_esint = BufferParams::package_auto;
1646 if (mathsModule->esintCB->isChecked())
1647 params.use_esint = BufferParams::package_on;
1649 params.use_esint = BufferParams::package_off;
1652 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1653 params.pagestyle = "default";
1655 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
1656 for (size_t i = 0; i != pagestyles.size(); ++i)
1657 if (pagestyles[i].second == style_gui)
1658 params.pagestyle = pagestyles[i].first;
1661 switch (textLayoutModule->lspacingCO->currentIndex()) {
1663 params.spacing().set(Spacing::Single);
1666 params.spacing().set(Spacing::Onehalf);
1669 params.spacing().set(Spacing::Double);
1672 params.spacing().set(Spacing::Other,
1673 fromqstr(textLayoutModule->lspacingLE->text()));
1677 if (textLayoutModule->twoColumnCB->isChecked())
1682 // text should have passed validation
1683 params.listings_params =
1684 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1686 if (textLayoutModule->indentRB->isChecked())
1687 params.paragraph_separation = BufferParams::ParagraphIndentSeparation;
1689 params.paragraph_separation = BufferParams::ParagraphSkipSeparation;
1691 switch (textLayoutModule->skipCO->currentIndex()) {
1693 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1696 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1699 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1704 widgetsToLength(textLayoutModule->skipLE,
1705 textLayoutModule->skipLengthCO)
1707 params.setDefSkip(vs);
1711 // DocumentDefskipCB assures that this never happens
1712 // so Assert then !!! - jbl
1713 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1718 fromqstr(latexModule->optionsLE->text());
1720 params.use_default_options =
1721 latexModule->defaultOptionsCB->isChecked();
1723 if (latexModule->childDocGB->isChecked())
1725 fromqstr(latexModule->childDocLE->text());
1727 params.master = string();
1729 params.float_placement = floatModule->get();
1733 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1736 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1738 params.fontsTypewriter =
1739 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1742 fromqstr(fontModule->cjkFontLE->text());
1744 params.fontsSansScale = fontModule->scaleSansSB->value();
1746 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1748 params.fontsSC = fontModule->fontScCB->isChecked();
1750 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1752 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1753 fontModule->fontsDefaultCO->currentIndex()];
1755 if (fontModule->fontsizeCO->currentIndex() == 0)
1756 params.fontsize = "default";
1759 fromqstr(fontModule->fontsizeCO->currentText());
1762 params.papersize = PAPER_SIZE(
1763 pageLayoutModule->papersizeCO->currentIndex());
1765 // custom, A3, B3 and B4 paper sizes need geometry
1766 int psize = pageLayoutModule->papersizeCO->currentIndex();
1767 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1769 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1770 pageLayoutModule->paperwidthUnitCO);
1772 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1773 pageLayoutModule->paperheightUnitCO);
1775 if (pageLayoutModule->facingPagesCB->isChecked())
1776 params.sides = TwoSides;
1778 params.sides = OneSide;
1780 if (pageLayoutModule->landscapeRB->isChecked())
1781 params.orientation = ORIENTATION_LANDSCAPE;
1783 params.orientation = ORIENTATION_PORTRAIT;
1786 params.use_geometry = !marginsModule->marginCB->isChecked()
1789 Ui::MarginsUi const * m = marginsModule;
1791 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1792 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1793 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1794 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1795 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1796 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1797 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1798 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1800 branchesModule->apply(params);
1803 PDFOptions & pdf = params.pdfoptions();
1804 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1805 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1806 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1807 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1808 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1810 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1811 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1812 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1813 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1815 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1816 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1817 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1818 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1820 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
1821 if (pdfSupportModule->fullscreenCB->isChecked())
1822 pdf.pagemode = pdf.pagemode_fullscreen;
1824 pdf.pagemode.clear();
1825 pdf.quoted_options = pdf.quoted_options_check(
1826 fromqstr(pdfSupportModule->optionsLE->text()));
1830 void GuiDocument::paramsToDialog()
1832 // set the default unit
1833 Length::UNIT defaultUnit = Length::CM;
1834 switch (lyxrc.default_papersize) {
1835 case PAPER_DEFAULT: break;
1837 case PAPER_USLETTER:
1839 case PAPER_USEXECUTIVE:
1840 defaultUnit = Length::IN;
1849 defaultUnit = Length::CM;
1856 preambleModule->update(bp_, id());
1859 biblioModule->citeDefaultRB->setChecked(
1860 bp_.citeEngine() == ENGINE_BASIC);
1862 biblioModule->citeNatbibRB->setChecked(
1863 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
1864 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
1866 biblioModule->citeStyleCO->setCurrentIndex(
1867 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
1869 biblioModule->citeJurabibRB->setChecked(
1870 bp_.citeEngine() == ENGINE_JURABIB);
1872 biblioModule->bibtopicCB->setChecked(
1875 // language & quotes
1876 int const pos = langModule->languageCO->findData(toqstr(
1877 bp_.language->lang()));
1878 langModule->languageCO->setCurrentIndex(pos);
1880 langModule->quoteStyleCO->setCurrentIndex(
1881 bp_.quotes_language);
1883 bool default_enc = true;
1884 if (bp_.inputenc != "auto") {
1885 default_enc = false;
1886 if (bp_.inputenc == "default") {
1887 langModule->encodingCO->setCurrentIndex(0);
1890 Encodings::const_iterator it = encodings.begin();
1891 Encodings::const_iterator const end = encodings.end();
1892 for (; it != end; ++it) {
1893 if (it->latexName() == bp_.inputenc) {
1894 enc_gui = it->guiName();
1898 int const i = langModule->encodingCO->findText(
1901 langModule->encodingCO->setCurrentIndex(i);
1903 // unknown encoding. Set to default.
1907 langModule->defaultencodingRB->setChecked(default_enc);
1908 langModule->otherencodingRB->setChecked(!default_enc);
1911 int const min_toclevel = documentClass().min_toclevel();
1912 int const max_toclevel = documentClass().max_toclevel();
1913 if (documentClass().hasTocLevels()) {
1914 numberingModule->setEnabled(true);
1915 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1916 numberingModule->depthSL->setMaximum(max_toclevel);
1917 numberingModule->depthSL->setValue(bp_.secnumdepth);
1918 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1919 numberingModule->tocSL->setMaximum(max_toclevel);
1920 numberingModule->tocSL->setValue(bp_.tocdepth);
1923 numberingModule->setEnabled(false);
1924 numberingModule->tocTW->clear();
1928 bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
1929 bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
1930 bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
1931 bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
1932 bulletsModule->init();
1935 int nitem = findToken(tex_graphics, bp_.graphicsDriver);
1937 latexModule->psdriverCO->setCurrentIndex(nitem);
1940 mathsModule->amsCB->setChecked(
1941 bp_.use_amsmath == BufferParams::package_on);
1942 mathsModule->amsautoCB->setChecked(
1943 bp_.use_amsmath == BufferParams::package_auto);
1945 mathsModule->esintCB->setChecked(
1946 bp_.use_esint == BufferParams::package_on);
1947 mathsModule->esintautoCB->setChecked(
1948 bp_.use_esint == BufferParams::package_auto);
1950 switch (bp_.spacing().getSpace()) {
1951 case Spacing::Other: nitem = 3; break;
1952 case Spacing::Double: nitem = 2; break;
1953 case Spacing::Onehalf: nitem = 1; break;
1954 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1958 string const & layoutID = bp_.baseClassID();
1959 setLayoutComboByIDString(layoutID);
1961 updatePagestyle(documentClass().opt_pagestyle(),
1964 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1965 if (bp_.spacing().getSpace() == Spacing::Other) {
1966 textLayoutModule->lspacingLE->setText(
1967 toqstr(bp_.spacing().getValueAsString()));
1971 if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation)
1972 textLayoutModule->indentRB->setChecked(true);
1974 textLayoutModule->skipRB->setChecked(true);
1977 switch (bp_.getDefSkip().kind()) {
1978 case VSpace::SMALLSKIP:
1981 case VSpace::MEDSKIP:
1984 case VSpace::BIGSKIP:
1987 case VSpace::LENGTH:
1990 string const length = bp_.getDefSkip().asLyXCommand();
1991 lengthToWidgets(textLayoutModule->skipLE,
1992 textLayoutModule->skipLengthCO,
1993 length, defaultUnit);
2000 textLayoutModule->skipCO->setCurrentIndex(skip);
2003 textLayoutModule->twoColumnCB->setChecked(
2006 // break listings_params to multiple lines
2008 InsetListingsParams(bp_.listings_params).separatedParams();
2009 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
2011 if (!bp_.options.empty()) {
2012 latexModule->optionsLE->setText(
2013 toqstr(bp_.options));
2015 latexModule->optionsLE->setText(QString());
2019 latexModule->defaultOptionsCB->setChecked(
2020 bp_.use_default_options);
2022 if (!documentClass().options().empty()) {
2023 latexModule->defaultOptionsLE->setText(
2024 toqstr(documentClass().options()));
2026 latexModule->defaultOptionsLE->setText(
2027 toqstr(_("[No options predefined]")));
2030 latexModule->defaultOptionsLE->setEnabled(
2031 bp_.use_default_options
2032 && !documentClass().options().empty());
2034 latexModule->defaultOptionsCB->setEnabled(
2035 !documentClass().options().empty());
2037 if (!bp_.master.empty()) {
2038 latexModule->childDocGB->setChecked(true);
2039 latexModule->childDocLE->setText(
2040 toqstr(bp_.master));
2042 latexModule->childDocLE->setText(QString());
2043 latexModule->childDocGB->setChecked(false);
2046 floatModule->set(bp_.float_placement);
2049 updateFontsize(documentClass().opt_fontsize(),
2052 int n = findToken(tex_fonts_roman, bp_.fontsRoman);
2054 fontModule->fontsRomanCO->setCurrentIndex(n);
2058 n = findToken(tex_fonts_sans, bp_.fontsSans);
2060 fontModule->fontsSansCO->setCurrentIndex(n);
2064 n = findToken(tex_fonts_monospaced, bp_.fontsTypewriter);
2066 fontModule->fontsTypewriterCO->setCurrentIndex(n);
2070 if (!bp_.fontsCJK.empty())
2071 fontModule->cjkFontLE->setText(
2072 toqstr(bp_.fontsCJK));
2074 fontModule->cjkFontLE->setText(QString());
2076 fontModule->fontScCB->setChecked(bp_.fontsSC);
2077 fontModule->fontOsfCB->setChecked(bp_.fontsOSF);
2078 fontModule->scaleSansSB->setValue(bp_.fontsSansScale);
2079 fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale);
2080 n = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily);
2082 fontModule->fontsDefaultCO->setCurrentIndex(n);
2085 int const psize = bp_.papersize;
2086 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
2087 setCustomPapersize(psize);
2089 bool const landscape =
2090 bp_.orientation == ORIENTATION_LANDSCAPE;
2091 pageLayoutModule->landscapeRB->setChecked(landscape);
2092 pageLayoutModule->portraitRB->setChecked(!landscape);
2094 pageLayoutModule->facingPagesCB->setChecked(
2095 bp_.sides == TwoSides);
2098 lengthToWidgets(pageLayoutModule->paperwidthLE,
2099 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, defaultUnit);
2101 lengthToWidgets(pageLayoutModule->paperheightLE,
2102 pageLayoutModule->paperheightUnitCO, bp_.paperheight, defaultUnit);
2105 Ui::MarginsUi * m = marginsModule;
2107 setMargins(!bp_.use_geometry);
2109 lengthToWidgets(m->topLE, m->topUnit,
2110 bp_.topmargin, defaultUnit);
2112 lengthToWidgets(m->bottomLE, m->bottomUnit,
2113 bp_.bottommargin, defaultUnit);
2115 lengthToWidgets(m->innerLE, m->innerUnit,
2116 bp_.leftmargin, defaultUnit);
2118 lengthToWidgets(m->outerLE, m->outerUnit,
2119 bp_.rightmargin, defaultUnit);
2121 lengthToWidgets(m->headheightLE, m->headheightUnit,
2122 bp_.headheight, defaultUnit);
2124 lengthToWidgets(m->headsepLE, m->headsepUnit,
2125 bp_.headsep, defaultUnit);
2127 lengthToWidgets(m->footskipLE, m->footskipUnit,
2128 bp_.footskip, defaultUnit);
2130 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2131 bp_.columnsep, defaultUnit);
2133 branchesModule->update(bp_);
2136 PDFOptions const & pdf = bp_.pdfoptions();
2137 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2138 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2139 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2140 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2141 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2143 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2144 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2145 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2147 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2149 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2150 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2151 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2152 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2154 n = findToken(backref_opts, pdf.backref);
2156 pdfSupportModule->backrefCO->setCurrentIndex(n);
2158 pdfSupportModule->fullscreenCB->setChecked
2159 (pdf.pagemode == pdf.pagemode_fullscreen);
2161 pdfSupportModule->optionsLE->setText(
2162 toqstr(pdf.quoted_options));
2166 void GuiDocument::applyView()
2172 void GuiDocument::saveDocDefault()
2174 // we have to apply the params first
2180 void GuiDocument::updateAvailableModules()
2182 modules_av_model_.clear();
2183 list<modInfoStruct> const & modInfoList = getModuleInfo();
2184 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
2185 list<modInfoStruct>::const_iterator men = modInfoList.end();
2186 for (int i = 0; mit != men; ++mit, ++i)
2187 modules_av_model_.insertRow(i, mit->name, mit->id,
2192 void GuiDocument::updateSelectedModules()
2194 modules_sel_model_.clear();
2195 list<modInfoStruct> const selModList = getSelectedModules();
2196 list<modInfoStruct>::const_iterator mit = selModList.begin();
2197 list<modInfoStruct>::const_iterator men = selModList.end();
2198 for (int i = 0; mit != men; ++mit, ++i)
2199 modules_sel_model_.insertRow(i, mit->name, mit->id,
2204 void GuiDocument::updateContents()
2206 // Nothing to do here as the document settings is not cursor dependant.
2211 void GuiDocument::useClassDefaults()
2213 if (applyPB->isEnabled()) {
2214 int const ret = Alert::prompt(_("Unapplied changes"),
2215 _("Some changes in the dialog were not yet applied.\n"
2216 "If you do not apply now, they will be lost after this action."),
2217 1, 1, _("&Apply"), _("&Dismiss"));
2222 int idx = latexModule->classCO->currentIndex();
2223 string const classname = classes_model_.getIDString(idx);
2224 if (!bp_.setBaseClass(classname)) {
2225 Alert::error(_("Error"), _("Unable to set document class."));
2228 bp_.useClassDefaults();
2233 void GuiDocument::setLayoutComboByIDString(string const & idString)
2235 int idx = classes_model_.findIDString(idString);
2237 Alert::warning(_("Can't set layout!"),
2238 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2240 latexModule->classCO->setCurrentIndex(idx);
2244 bool GuiDocument::isValid()
2246 return validateListingsParameters().isEmpty()
2247 && (textLayoutModule->skipCO->currentIndex() != 3
2248 || !textLayoutModule->skipLE->text().isEmpty());
2252 char const * const GuiDocument::fontfamilies[5] = {
2253 "default", "rmdefault", "sfdefault", "ttdefault", ""
2257 char const * GuiDocument::fontfamilies_gui[5] = {
2258 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2262 bool GuiDocument::initialiseParams(string const &)
2264 BufferView const * view = bufferview();
2266 bp_ = BufferParams();
2270 bp_ = view->buffer().params();
2272 updateAvailableModules();
2273 updateSelectedModules();
2274 //FIXME It'd be nice to make sure here that the selected
2275 //modules are consistent: That required modules are actually
2276 //selected, and that we don't have conflicts. If so, we could
2277 //at least pop up a warning.
2283 void GuiDocument::clearParams()
2285 bp_ = BufferParams();
2289 BufferId GuiDocument::id() const
2291 BufferView const * const view = bufferview();
2292 return view? &view->buffer() : 0;
2296 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2298 return moduleNames_;
2302 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2304 list<string> const & mods = params().getModules();
2305 list<string>::const_iterator it = mods.begin();
2306 list<string>::const_iterator end = mods.end();
2307 list<modInfoStruct> mInfo;
2308 for (; it != end; ++it) {
2311 LyXModule * mod = moduleList[*it];
2313 m.name = qt_(mod->getName());
2315 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
2322 DocumentClass const & GuiDocument::documentClass() const
2324 return bp_.documentClass();
2328 static void dispatch_bufferparams(Dialog const & dialog,
2329 BufferParams const & bp, FuncCode lfun)
2332 ss << "\\begin_header\n";
2334 ss << "\\end_header\n";
2335 dialog.dispatch(FuncRequest(lfun, ss.str()));
2339 void GuiDocument::dispatchParams()
2341 // This must come first so that a language change is correctly noticed
2344 // Apply the BufferParams. Note that this will set the base class
2345 // and then update the buffer's layout.
2346 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2348 if (!params().master.empty()) {
2349 FileName const master_file = support::makeAbsPath(params().master,
2350 support::onlyPath(buffer().absFileName()));
2351 if (isLyXFilename(master_file.absFilename())) {
2352 Buffer * master = checkAndLoadLyXFile(master_file);
2353 const_cast<Buffer &>(buffer()).setParent(master);
2357 // Generate the colours requested by each new branch.
2358 BranchList & branchlist = params().branchlist();
2359 if (!branchlist.empty()) {
2360 BranchList::const_iterator it = branchlist.begin();
2361 BranchList::const_iterator const end = branchlist.end();
2362 for (; it != end; ++it) {
2363 docstring const & current_branch = it->branch();
2364 Branch const * branch = branchlist.find(current_branch);
2365 string const x11hexname = X11hexname(branch->color());
2366 // display the new color
2367 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2368 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2371 // Open insets of selected branches, close deselected ones
2372 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2375 // FIXME: If we used an LFUN, we would not need those two lines:
2376 BufferView * bv = const_cast<BufferView *>(bufferview());
2377 bv->processUpdateFlags(Update::Force | Update::FitCursor);
2381 void GuiDocument::setLanguage() const
2383 Language const * const newL = bp_.language;
2384 if (buffer().params().language == newL)
2387 string const & lang_name = newL->lang();
2388 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2392 void GuiDocument::saveAsDefault() const
2394 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2398 bool GuiDocument::isFontAvailable(string const & font) const
2400 if (font == "default" || font == "cmr"
2401 || font == "cmss" || font == "cmtt")
2402 // these are standard
2404 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2405 return LaTeXFeatures::isAvailable("lmodern");
2406 if (font == "times" || font == "palatino"
2407 || font == "helvet" || font == "courier")
2408 return LaTeXFeatures::isAvailable("psnfss");
2409 if (font == "cmbr" || font == "cmtl")
2410 return LaTeXFeatures::isAvailable("cmbright");
2411 if (font == "utopia")
2412 return LaTeXFeatures::isAvailable("utopia")
2413 || LaTeXFeatures::isAvailable("fourier");
2414 if (font == "beraserif" || font == "berasans"
2415 || font == "beramono")
2416 return LaTeXFeatures::isAvailable("bera");
2417 return LaTeXFeatures::isAvailable(font);
2421 bool GuiDocument::providesOSF(string const & font) const
2424 return isFontAvailable("eco");
2425 if (font == "palatino")
2426 return isFontAvailable("mathpazo");
2431 bool GuiDocument::providesSC(string const & font) const
2433 if (font == "palatino")
2434 return isFontAvailable("mathpazo");
2435 if (font == "utopia")
2436 return isFontAvailable("fourier");
2441 bool GuiDocument::providesScale(string const & font) const
2443 return font == "helvet" || font == "luximono"
2444 || font == "berasans" || font == "beramono";
2448 void GuiDocument::loadModuleInfo()
2450 moduleNames_.clear();
2451 LyXModuleList::const_iterator it = moduleList.begin();
2452 LyXModuleList::const_iterator end = moduleList.end();
2453 for (; it != end; ++it) {
2456 m.name = qt_(it->getName());
2457 // this is supposed to give us the first sentence of the description
2458 QString desc = qt_(it->getDescription());
2459 int const pos = desc.indexOf(".");
2461 desc.truncate(pos + 1);
2462 m.description = desc;
2463 moduleNames_.push_back(m);
2468 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2471 } // namespace frontend
2474 #include "GuiDocument_moc.cpp"