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
238 ModuleSelectionManager(
239 QListView * availableLV,
240 QListView * selectedLV,
244 QPushButton * downPB,
245 GuiIdListModel * availableModel,
246 GuiIdListModel * selectedModel)
247 : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
248 upPB, downPB, availableModel, selectedModel)
252 virtual void updateAddPB();
254 virtual void updateUpPB();
256 virtual void updateDownPB();
258 virtual void updateDelPB();
259 /// returns availableModel as a GuiIdListModel
260 GuiIdListModel * getAvailableModel()
262 return dynamic_cast<GuiIdListModel *>(availableModel);
264 /// returns selectedModel as a GuiIdListModel
265 GuiIdListModel * getSelectedModel()
267 return dynamic_cast<GuiIdListModel *>(selectedModel);
271 void ModuleSelectionManager::updateAddPB()
273 int const arows = availableModel->rowCount();
274 QModelIndexList const availSels =
275 availableLV->selectionModel()->selectedIndexes();
276 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
277 addPB->setEnabled(false);
281 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
282 string const modName = getAvailableModel()->getIDString(idx.row());
283 vector<string> reqs = getRequiredList(modName);
284 vector<string> excl = getExcludedList(modName);
286 if (reqs.empty() && excl.empty()) {
287 addPB->setEnabled(true);
291 int const srows = selectedModel->rowCount();
292 vector<string> selModList;
293 for (int i = 0; i < srows; ++i)
294 selModList.push_back(getSelectedModel()->getIDString(i));
296 vector<string>::const_iterator selModStart = selModList.begin();
297 vector<string>::const_iterator selModEnd = selModList.end();
299 // Check whether some required module is available
301 bool foundOne = false;
302 vector<string>::const_iterator it = reqs.begin();
303 vector<string>::const_iterator end = reqs.end();
304 for (; it != end; ++it) {
305 if (find(selModStart, selModEnd, *it) != selModEnd) {
311 addPB->setEnabled(false);
316 // Check whether any excluded module is being used
318 vector<string>::const_iterator it = excl.begin();
319 vector<string>::const_iterator end = excl.end();
320 for (; it != end; ++it) {
321 if (find(selModStart, selModEnd, *it) != selModEnd) {
322 addPB->setEnabled(false);
328 addPB->setEnabled(true);
332 void ModuleSelectionManager::updateDownPB()
334 int const srows = selectedModel->rowCount();
336 downPB->setEnabled(false);
339 QModelIndexList const selSels =
340 selectedLV->selectionModel()->selectedIndexes();
341 // disable if empty or last item is selected
342 if (selSels.empty() || selSels.first().row() == srows - 1) {
343 downPB->setEnabled(false);
346 // determine whether immediately succeding element requires this one
347 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
348 int curRow = curIdx.row();
349 if (curRow < 0 || curRow >= srows - 1) { //this shouldn't happen...
350 downPB->setEnabled(false);
353 string const curModName = getSelectedModel()->getIDString(curRow);
354 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
356 vector<string> reqs = getRequiredList(nextModName);
358 // if it doesn't require anything....
360 downPB->setEnabled(true);
364 // Enable it if this module isn't required.
365 // FIXME This should perhaps be more flexible and check whether, even
366 // if this one is required, there is also an earlier one that is required.
368 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
371 void ModuleSelectionManager::updateUpPB()
373 int const srows = selectedModel->rowCount();
375 upPB->setEnabled(false);
378 QModelIndexList const selSels =
379 selectedLV->selectionModel()->selectedIndexes();
380 //disable if empty or first item is selected
381 if (selSels.empty() || selSels.first().row() == 0) {
382 upPB->setEnabled(false);
386 // determine whether immediately preceding element is required by this one
387 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
388 int curRow = curIdx.row();
389 if (curRow <= -1 || curRow > srows - 1) { //sanity check
390 downPB->setEnabled(false);
393 string const curModName = getSelectedModel()->getIDString(curRow);
394 vector<string> reqs = getRequiredList(curModName);
396 // if this one doesn't require anything....
398 upPB->setEnabled(true);
402 string preModName = getSelectedModel()->getIDString(curRow - 1);
404 // Enable it if the preceding module isn't required.
405 // NOTE This is less flexible than it might be. You could check whether, even
406 // if this one is required, there is also an earlier one that is required.
407 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
410 void ModuleSelectionManager::updateDelPB()
412 int const srows = selectedModel->rowCount();
414 deletePB->setEnabled(false);
417 QModelIndexList const selSels =
418 selectedLV->selectionModel()->selectedIndexes();
419 if (selSels.empty() || selSels.first().row() < 0) {
420 deletePB->setEnabled(false);
424 // determine whether some LATER module requires this one
425 // NOTE Things are arranged so that this is the only way there
426 // can be a problem. At least, we hope so.
427 QModelIndex const & curIdx =
428 selectedLV->selectionModel()->currentIndex();
429 int const curRow = curIdx.row();
430 if (curRow < 0 || curRow >= srows) { // this shouldn't happen
431 deletePB->setEnabled(false);
435 QString const curModName = curIdx.data().toString();
437 // We're looking here for a reason NOT to enable the button. If we
438 // find one, we disable it and return. If we don't, we'll end up at
439 // the end of the function, and then we enable it.
440 for (int i = curRow + 1; i < srows; ++i) {
441 string const thisMod = getSelectedModel()->getIDString(i);
442 vector<string> reqs = getRequiredList(thisMod);
443 //does this one require us?
444 if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
448 // OK, so this module requires us
449 // is there an EARLIER module that also satisfies the require?
450 // NOTE We demand that it be earlier to keep the list of modules
451 // consistent with the rule that a module must be proceeded by a
452 // required module. There would be more flexible ways to proceed,
453 // but that would be a lot more complicated, and the logic here is
454 // already complicated. (That's why I've left the debugging code.)
455 // lyxerr << "Testing " << thisMod << std::endl;
456 bool foundOne = false;
457 for (int j = 0; j < curRow; ++j) {
458 string const mod = getSelectedModel()->getIDString(j);
459 // lyxerr << "In loop: Testing " << mod << std::endl;
460 // do we satisfy the require?
461 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
462 // lyxerr << mod << " does the trick." << std::endl;
467 // did we find a module to satisfy the require?
469 // lyxerr << "No matching module found." << std::endl;
470 deletePB->setEnabled(false);
474 // lyxerr << "All's well that ends well." << std::endl;
475 deletePB->setEnabled(true);
479 /////////////////////////////////////////////////////////////////////
483 /////////////////////////////////////////////////////////////////////
485 PreambleModule::PreambleModule() : current_id_(0)
487 // This is not a memory leak. The object will be destroyed
489 (void) new LaTeXHighlighter(preambleTE->document());
490 setFocusProxy(preambleTE);
491 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
495 void PreambleModule::update(BufferParams const & params, BufferId id)
497 QString preamble = toqstr(params.preamble);
498 // Nothing to do if the params and preamble are unchanged.
499 if (id == current_id_
500 && preamble == preambleTE->document()->toPlainText())
503 QTextCursor cur = preambleTE->textCursor();
504 // Save the coords before switching to the new one.
505 preamble_coords_[current_id_] =
506 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
508 // Save the params address for further use.
510 preambleTE->document()->setPlainText(preamble);
511 Coords::const_iterator it = preamble_coords_.find(current_id_);
512 if (it == preamble_coords_.end())
513 // First time we open this one.
514 preamble_coords_[current_id_] = make_pair(0, 0);
516 // Restore saved coords.
517 QTextCursor cur = preambleTE->textCursor();
518 cur.setPosition(it->second.first);
519 preambleTE->setTextCursor(cur);
520 preambleTE->verticalScrollBar()->setValue(it->second.second);
525 void PreambleModule::apply(BufferParams & params)
527 params.preamble = fromqstr(preambleTE->document()->toPlainText());
531 void PreambleModule::closeEvent(QCloseEvent * e)
533 // Save the coords before closing.
534 QTextCursor cur = preambleTE->textCursor();
535 preamble_coords_[current_id_] =
536 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
541 /////////////////////////////////////////////////////////////////////
545 /////////////////////////////////////////////////////////////////////
548 GuiDocument::GuiDocument(GuiView & lv)
549 : GuiDialog(lv, "document", qt_("Document Settings"))
553 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
554 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
555 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
556 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
558 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
559 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
561 // Manage the restore, ok, apply, restore and cancel/close buttons
562 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
564 bc().setApply(applyPB);
565 bc().setCancel(closePB);
566 bc().setRestore(restorePB);
568 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
570 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
571 this, SLOT(change_adaptor()));
572 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
573 this, SLOT(setLSpacing(int)));
574 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
575 this, SLOT(change_adaptor()));
576 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
577 this, SLOT(change_adaptor()));
578 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
579 this, SLOT(change_adaptor()));
580 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
581 this, SLOT(change_adaptor()));
582 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
583 this, SLOT(change_adaptor()));
584 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
585 this, SLOT(change_adaptor()));
586 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
587 this, SLOT(setSkip(int)));
588 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
589 this, SLOT(enableSkip(bool)));
590 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
591 this, SLOT(change_adaptor()));
592 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
593 this, SLOT(setColSep()));
594 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
595 this, SLOT(change_adaptor()));
596 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
597 this, SLOT(change_adaptor()));
598 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
599 this, SLOT(setListingsMessage()));
600 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
601 this, SLOT(setListingsMessage()));
602 textLayoutModule->listingsTB->setPlainText(
603 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
604 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
605 textLayoutModule->lspacingLE));
606 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
607 textLayoutModule->skipLE));
609 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
610 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
611 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
612 textLayoutModule->skipCO->addItem(qt_("Length"));
613 // remove the %-items from the unit choice
614 textLayoutModule->skipLengthCO->noPercents();
615 textLayoutModule->lspacingCO->insertItem(
616 Spacing::Single, qt_("Single"));
617 textLayoutModule->lspacingCO->insertItem(
618 Spacing::Onehalf, qt_("OneHalf"));
619 textLayoutModule->lspacingCO->insertItem(
620 Spacing::Double, qt_("Double"));
621 textLayoutModule->lspacingCO->insertItem(
622 Spacing::Other, qt_("Custom"));
624 // initialize the length validator
625 bc().addCheckedLineEdit(textLayoutModule->skipLE);
627 fontModule = new UiWidget<Ui::FontUi>;
629 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
630 this, SLOT(change_adaptor()));
631 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
632 this, SLOT(romanChanged(int)));
633 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
634 this, SLOT(change_adaptor()));
635 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
636 this, SLOT(sansChanged(int)));
637 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
638 this, SLOT(change_adaptor()));
639 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
640 this, SLOT(ttChanged(int)));
641 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
642 this, SLOT(change_adaptor()));
643 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
644 this, SLOT(change_adaptor()));
645 connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
646 this, SLOT(change_adaptor()));
647 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
648 this, SLOT(change_adaptor()));
649 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
650 this, SLOT(change_adaptor()));
651 connect(fontModule->fontScCB, SIGNAL(clicked()),
652 this, SLOT(change_adaptor()));
653 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
654 this, SLOT(change_adaptor()));
656 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
657 QString font = qt_(tex_fonts_roman_gui[n]);
658 if (!isFontAvailable(tex_fonts_roman[n]))
659 font += qt_(" (not installed)");
660 fontModule->fontsRomanCO->addItem(font);
662 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
663 QString font = qt_(tex_fonts_sans_gui[n]);
664 if (!isFontAvailable(tex_fonts_sans[n]))
665 font += qt_(" (not installed)");
666 fontModule->fontsSansCO->addItem(font);
668 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
669 QString font = qt_(tex_fonts_monospaced_gui[n]);
670 if (!isFontAvailable(tex_fonts_monospaced[n]))
671 font += qt_(" (not installed)");
672 fontModule->fontsTypewriterCO->addItem(font);
675 fontModule->fontsizeCO->addItem(qt_("Default"));
676 fontModule->fontsizeCO->addItem(qt_("10"));
677 fontModule->fontsizeCO->addItem(qt_("11"));
678 fontModule->fontsizeCO->addItem(qt_("12"));
680 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
681 fontModule->fontsDefaultCO->addItem(
682 qt_(GuiDocument::fontfamilies_gui[n]));
685 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
687 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
688 this, SLOT(setCustomPapersize(int)));
689 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
690 this, SLOT(setCustomPapersize(int)));
691 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
692 this, SLOT(portraitChanged()));
693 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
694 this, SLOT(change_adaptor()));
695 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
696 this, SLOT(change_adaptor()));
697 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
698 this, SLOT(change_adaptor()));
699 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
700 this, SLOT(change_adaptor()));
701 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
702 this, SLOT(change_adaptor()));
703 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
704 this, SLOT(change_adaptor()));
705 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
706 this, SLOT(change_adaptor()));
707 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
708 this, SLOT(change_adaptor()));
709 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
710 this, SLOT(change_adaptor()));
712 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
713 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
714 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
715 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
716 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
717 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
718 pageLayoutModule->paperheightL);
719 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
720 pageLayoutModule->paperwidthL);
723 QComboBox * cb = pageLayoutModule->papersizeCO;
724 cb->addItem(qt_("Default"));
725 cb->addItem(qt_("Custom"));
726 cb->addItem(qt_("US letter"));
727 cb->addItem(qt_("US legal"));
728 cb->addItem(qt_("US executive"));
729 cb->addItem(qt_("A3"));
730 cb->addItem(qt_("A4"));
731 cb->addItem(qt_("A5"));
732 cb->addItem(qt_("B3"));
733 cb->addItem(qt_("B4"));
734 cb->addItem(qt_("B5"));
735 // remove the %-items from the unit choice
736 pageLayoutModule->paperwidthUnitCO->noPercents();
737 pageLayoutModule->paperheightUnitCO->noPercents();
738 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
739 pageLayoutModule->paperheightLE));
740 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
741 pageLayoutModule->paperwidthLE));
744 marginsModule = new UiWidget<Ui::MarginsUi>;
746 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
747 this, SLOT(setCustomMargins(bool)));
748 connect(marginsModule->marginCB, SIGNAL(clicked()),
749 this, SLOT(change_adaptor()));
750 connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
751 this, SLOT(change_adaptor()));
752 connect(marginsModule->topUnit, SIGNAL(activated(int)),
753 this, SLOT(change_adaptor()));
754 connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
755 this, SLOT(change_adaptor()));
756 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
757 this, SLOT(change_adaptor()));
758 connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
759 this, SLOT(change_adaptor()));
760 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
761 this, SLOT(change_adaptor()));
762 connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
763 this, SLOT(change_adaptor()));
764 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
765 this, SLOT(change_adaptor()));
766 connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
767 this, SLOT(change_adaptor()));
768 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
769 this, SLOT(change_adaptor()));
770 connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
771 this, SLOT(change_adaptor()));
772 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
773 this, SLOT(change_adaptor()));
774 connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
775 this, SLOT(change_adaptor()));
776 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
777 this, SLOT(change_adaptor()));
778 connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
779 this, SLOT(change_adaptor()));
780 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
781 this, SLOT(change_adaptor()));
782 marginsModule->topLE->setValidator(unsignedLengthValidator(
783 marginsModule->topLE));
784 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
785 marginsModule->bottomLE));
786 marginsModule->innerLE->setValidator(unsignedLengthValidator(
787 marginsModule->innerLE));
788 marginsModule->outerLE->setValidator(unsignedLengthValidator(
789 marginsModule->outerLE));
790 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
791 marginsModule->headsepLE));
792 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
793 marginsModule->headheightLE));
794 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
795 marginsModule->footskipLE));
796 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
797 marginsModule->columnsepLE));
799 bc().addCheckedLineEdit(marginsModule->topLE,
800 marginsModule->topL);
801 bc().addCheckedLineEdit(marginsModule->bottomLE,
802 marginsModule->bottomL);
803 bc().addCheckedLineEdit(marginsModule->innerLE,
804 marginsModule->innerL);
805 bc().addCheckedLineEdit(marginsModule->outerLE,
806 marginsModule->outerL);
807 bc().addCheckedLineEdit(marginsModule->headsepLE,
808 marginsModule->headsepL);
809 bc().addCheckedLineEdit(marginsModule->headheightLE,
810 marginsModule->headheightL);
811 bc().addCheckedLineEdit(marginsModule->footskipLE,
812 marginsModule->footskipL);
813 bc().addCheckedLineEdit(marginsModule->columnsepLE,
814 marginsModule->columnsepL);
817 langModule = new UiWidget<Ui::LanguageUi>;
819 connect(langModule->languageCO, SIGNAL(activated(int)),
820 this, SLOT(change_adaptor()));
821 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
822 this, SLOT(change_adaptor()));
823 connect(langModule->otherencodingRB, SIGNAL(clicked()),
824 this, SLOT(change_adaptor()));
825 connect(langModule->encodingCO, SIGNAL(activated(int)),
826 this, SLOT(change_adaptor()));
827 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
828 this, SLOT(change_adaptor()));
830 QAbstractItemModel * language_model = guiApp->languageModel();
831 // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
832 language_model->sort(0);
833 langModule->languageCO->setModel(language_model);
835 // Always put the default encoding in the first position.
836 langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
837 QStringList encodinglist;
838 Encodings::const_iterator it = encodings.begin();
839 Encodings::const_iterator const end = encodings.end();
840 for (; it != end; ++it)
841 encodinglist.append(qt_(it->guiName()));
843 langModule->encodingCO->addItems(encodinglist);
845 langModule->quoteStyleCO->addItem(qt_("``text''"));
846 langModule->quoteStyleCO->addItem(qt_("''text''"));
847 langModule->quoteStyleCO->addItem(qt_(",,text``"));
848 langModule->quoteStyleCO->addItem(qt_(",,text''"));
849 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
850 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
853 numberingModule = new UiWidget<Ui::NumberingUi>;
855 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
856 this, SLOT(change_adaptor()));
857 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
858 this, SLOT(change_adaptor()));
859 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
860 this, SLOT(updateNumbering()));
861 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
862 this, SLOT(updateNumbering()));
863 numberingModule->tocTW->setColumnCount(3);
864 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
865 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
866 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
869 biblioModule = new UiWidget<Ui::BiblioUi>;
870 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
871 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
872 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
873 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
875 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
876 this, SLOT(change_adaptor()));
877 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
878 this, SLOT(change_adaptor()));
879 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
880 this, SLOT(change_adaptor()));
881 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
882 this, SLOT(change_adaptor()));
883 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
884 this, SLOT(change_adaptor()));
886 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
887 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
888 biblioModule->citeStyleCO->setCurrentIndex(0);
891 mathsModule = new UiWidget<Ui::MathsUi>;
892 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
893 mathsModule->amsCB, SLOT(setDisabled(bool)));
894 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
895 mathsModule->esintCB, SLOT(setDisabled(bool)));
897 connect(mathsModule->amsCB, SIGNAL(clicked()),
898 this, SLOT(change_adaptor()));
899 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
900 this, SLOT(change_adaptor()));
901 connect(mathsModule->esintCB, SIGNAL(clicked()),
902 this, SLOT(change_adaptor()));
903 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
904 this, SLOT(change_adaptor()));
906 latexModule = new UiWidget<Ui::LaTeXUi>;
908 connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
909 this, SLOT(change_adaptor()));
910 connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
911 this, SLOT(change_adaptor()));
912 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
913 this, SLOT(change_adaptor()));
914 connect(latexModule->classCO, SIGNAL(activated(int)),
915 this, SLOT(classChanged()));
916 connect(latexModule->classCO, SIGNAL(activated(int)),
917 this, SLOT(change_adaptor()));
918 connect(latexModule->layoutPB, SIGNAL(clicked()),
919 this, SLOT(browseLayout()));
920 connect(latexModule->layoutPB, SIGNAL(clicked()),
921 this, SLOT(change_adaptor()));
922 connect(latexModule->childDocGB, SIGNAL(clicked()),
923 this, SLOT(change_adaptor()));
924 connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
925 this, SLOT(change_adaptor()));
926 connect(latexModule->childDocPB, SIGNAL(clicked()),
927 this, SLOT(browseMaster()));
930 new ModuleSelectionManager(latexModule->availableLV,
931 latexModule->selectedLV,
932 latexModule->addPB, latexModule->deletePB,
933 latexModule->upPB, latexModule->downPB,
934 availableModel(), selectedModel());
935 connect(selectionManager, SIGNAL(updateHook()),
936 this, SLOT(updateModuleInfo()));
937 connect(selectionManager, SIGNAL(updateHook()),
938 this, SLOT(change_adaptor()));
940 // postscript drivers
941 for (int n = 0; tex_graphics[n][0]; ++n) {
942 QString enc = qt_(tex_graphics_gui[n]);
943 latexModule->psdriverCO->addItem(enc);
946 latexModule->classCO->setModel(&classes_model_);
947 LayoutFileList const & bcl = LayoutFileList::get();
948 vector<LayoutFileIndex> classList = bcl.classList();
949 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
951 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
952 vector<LayoutFileIndex>::const_iterator cen = classList.end();
953 for (int i = 0; cit != cen; ++cit, ++i) {
954 LayoutFile const & tc = bcl[*cit];
955 docstring item = (tc.isTeXClassAvailable()) ?
956 from_utf8(tc.description()) :
957 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
958 classes_model_.insertRow(i, toqstr(item), *cit);
962 branchesModule = new GuiBranches;
963 connect(branchesModule, SIGNAL(changed()),
964 this, SLOT(change_adaptor()));
967 preambleModule = new PreambleModule;
968 connect(preambleModule, SIGNAL(changed()),
969 this, SLOT(change_adaptor()));
972 bulletsModule = new BulletsModule;
973 connect(bulletsModule, SIGNAL(changed()),
974 this, SLOT(change_adaptor()));
977 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
979 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
980 this, SLOT(change_adaptor()));
981 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
982 this, SLOT(change_adaptor()));
983 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
984 this, SLOT(change_adaptor()));
985 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
986 this, SLOT(change_adaptor()));
987 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
988 this, SLOT(change_adaptor()));
989 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
990 this, SLOT(change_adaptor()));
991 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
992 this, SLOT(change_adaptor()));
993 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
994 this, SLOT(change_adaptor()));
995 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
996 this, SLOT(change_adaptor()));
997 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
998 this, SLOT(change_adaptor()));
999 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1000 this, SLOT(change_adaptor()));
1001 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1002 this, SLOT(change_adaptor()));
1003 connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1004 this, SLOT(change_adaptor()));
1005 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1006 this, SLOT(change_adaptor()));
1007 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1008 this, SLOT(change_adaptor()));
1009 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1010 this, SLOT(change_adaptor()));
1012 for (int i = 0; backref_opts[i][0]; ++i)
1013 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1016 floatModule = new FloatPlacement;
1017 connect(floatModule, SIGNAL(changed()),
1018 this, SLOT(change_adaptor()));
1020 docPS->addPanel(latexModule, qt_("Document Class"));
1021 docPS->addPanel(fontModule, qt_("Fonts"));
1022 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1023 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1024 docPS->addPanel(marginsModule, qt_("Page Margins"));
1025 docPS->addPanel(langModule, qt_("Language"));
1026 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1027 docPS->addPanel(biblioModule, qt_("Bibliography"));
1028 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1029 docPS->addPanel(mathsModule, qt_("Math Options"));
1030 docPS->addPanel(floatModule, qt_("Float Placement"));
1031 docPS->addPanel(bulletsModule, qt_("Bullets"));
1032 docPS->addPanel(branchesModule, qt_("Branches"));
1033 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1034 docPS->setCurrentPanel(qt_("Document Class"));
1035 // FIXME: hack to work around resizing bug in Qt >= 4.2
1036 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1037 #if QT_VERSION >= 0x040200
1038 docPS->updateGeometry();
1043 void GuiDocument::showPreamble()
1045 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
1049 void GuiDocument::saveDefaultClicked()
1055 void GuiDocument::useDefaultsClicked()
1061 void GuiDocument::change_adaptor()
1067 QString GuiDocument::validateListingsParameters()
1069 // use a cache here to avoid repeated validation
1070 // of the same parameters
1071 static string param_cache;
1072 static QString msg_cache;
1074 if (textLayoutModule->bypassCB->isChecked())
1077 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1078 if (params != param_cache) {
1079 param_cache = params;
1080 msg_cache = toqstr(InsetListingsParams(params).validate());
1086 void GuiDocument::setListingsMessage()
1088 static bool isOK = true;
1089 QString msg = validateListingsParameters();
1090 if (msg.isEmpty()) {
1094 // listingsTB->setTextColor("black");
1095 textLayoutModule->listingsTB->setPlainText(
1096 qt_("Input listings parameters on the right. "
1097 "Enter ? for a list of parameters."));
1100 // listingsTB->setTextColor("red");
1101 textLayoutModule->listingsTB->setPlainText(msg);
1106 void GuiDocument::setLSpacing(int item)
1108 textLayoutModule->lspacingLE->setEnabled(item == 3);
1112 void GuiDocument::setSkip(int item)
1114 bool const enable = (item == 3);
1115 textLayoutModule->skipLE->setEnabled(enable);
1116 textLayoutModule->skipLengthCO->setEnabled(enable);
1120 void GuiDocument::enableSkip(bool skip)
1122 textLayoutModule->skipCO->setEnabled(skip);
1123 textLayoutModule->skipLE->setEnabled(skip);
1124 textLayoutModule->skipLengthCO->setEnabled(skip);
1126 setSkip(textLayoutModule->skipCO->currentIndex());
1129 void GuiDocument::portraitChanged()
1131 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1134 void GuiDocument::setMargins(bool custom)
1136 marginsModule->marginCB->setChecked(custom);
1137 setCustomMargins(custom);
1141 void GuiDocument::setCustomPapersize(int papersize)
1143 bool const custom = (papersize == 1);
1145 pageLayoutModule->paperwidthL->setEnabled(custom);
1146 pageLayoutModule->paperwidthLE->setEnabled(custom);
1147 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1148 pageLayoutModule->paperheightL->setEnabled(custom);
1149 pageLayoutModule->paperheightLE->setEnabled(custom);
1150 pageLayoutModule->paperheightLE->setFocus();
1151 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1155 void GuiDocument::setColSep()
1157 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1161 void GuiDocument::setCustomMargins(bool custom)
1163 marginsModule->topL->setEnabled(!custom);
1164 marginsModule->topLE->setEnabled(!custom);
1165 marginsModule->topUnit->setEnabled(!custom);
1167 marginsModule->bottomL->setEnabled(!custom);
1168 marginsModule->bottomLE->setEnabled(!custom);
1169 marginsModule->bottomUnit->setEnabled(!custom);
1171 marginsModule->innerL->setEnabled(!custom);
1172 marginsModule->innerLE->setEnabled(!custom);
1173 marginsModule->innerUnit->setEnabled(!custom);
1175 marginsModule->outerL->setEnabled(!custom);
1176 marginsModule->outerLE->setEnabled(!custom);
1177 marginsModule->outerUnit->setEnabled(!custom);
1179 marginsModule->headheightL->setEnabled(!custom);
1180 marginsModule->headheightLE->setEnabled(!custom);
1181 marginsModule->headheightUnit->setEnabled(!custom);
1183 marginsModule->headsepL->setEnabled(!custom);
1184 marginsModule->headsepLE->setEnabled(!custom);
1185 marginsModule->headsepUnit->setEnabled(!custom);
1187 marginsModule->footskipL->setEnabled(!custom);
1188 marginsModule->footskipLE->setEnabled(!custom);
1189 marginsModule->footskipUnit->setEnabled(!custom);
1191 bool const enableColSep = !custom &&
1192 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1193 marginsModule->columnsepL->setEnabled(enableColSep);
1194 marginsModule->columnsepLE->setEnabled(enableColSep);
1195 marginsModule->columnsepUnit->setEnabled(enableColSep);
1199 void GuiDocument::updateFontsize(string const & items, string const & sel)
1201 fontModule->fontsizeCO->clear();
1202 fontModule->fontsizeCO->addItem(qt_("Default"));
1204 for (int n = 0; !token(items,'|',n).empty(); ++n)
1205 fontModule->fontsizeCO->
1206 addItem(toqstr(token(items,'|',n)));
1208 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1209 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1210 fontModule->fontsizeCO->setCurrentIndex(n);
1217 void GuiDocument::romanChanged(int item)
1219 string const font = tex_fonts_roman[item];
1220 fontModule->fontScCB->setEnabled(providesSC(font));
1221 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1225 void GuiDocument::sansChanged(int item)
1227 string const font = tex_fonts_sans[item];
1228 bool scaleable = providesScale(font);
1229 fontModule->scaleSansSB->setEnabled(scaleable);
1230 fontModule->scaleSansLA->setEnabled(scaleable);
1234 void GuiDocument::ttChanged(int item)
1236 string const font = tex_fonts_monospaced[item];
1237 bool scaleable = providesScale(font);
1238 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1239 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1243 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1246 pageLayoutModule->pagestyleCO->clear();
1247 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1249 for (int n = 0; !token(items, '|', n).empty(); ++n) {
1250 string style = token(items, '|', n);
1251 QString style_gui = qt_(style);
1252 pagestyles.push_back(pair<string, QString>(style, style_gui));
1253 pageLayoutModule->pagestyleCO->addItem(style_gui);
1256 if (sel == "default") {
1257 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1263 for (size_t i = 0; i < pagestyles.size(); ++i)
1264 if (pagestyles[i].first == sel)
1265 nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1268 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1272 void GuiDocument::browseLayout()
1274 QString const label1 = qt_("Layouts|#o#O");
1275 QString const dir1 = toqstr(lyxrc.document_path);
1276 QStringList const filter(qt_("LyX Layout (*.layout)"));
1277 QString file = browseRelFile(QString(), bufferFilepath(),
1278 qt_("Local layout file"), filter, false,
1281 if (!file.endsWith(".layout"))
1284 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1285 fromqstr(bufferFilepath()));
1287 int const ret = Alert::prompt(_("Local layout file"),
1288 _("The layout file you have selected is a local layout\n"
1289 "file, not one in the system or user directory. Your\n"
1290 "document may not work with this layout if you do not\n"
1291 "keep the layout file in the document directory."),
1292 1, 1, _("&Set Layout"), _("&Cancel"));
1296 // load the layout file
1297 LayoutFileList & bcl = LayoutFileList::get();
1298 string classname = layoutFile.onlyFileName();
1299 // this will update an existing layout if that layout has been loaded before.
1300 LayoutFileIndex name = bcl.addLocalLayout(
1301 classname.substr(0, classname.size() - 7),
1302 layoutFile.onlyPath().absFilename());
1305 Alert::error(_("Error"),
1306 _("Unable to read local layout file."));
1310 // do not trigger classChanged if there is no change.
1311 if (latexModule->classCO->currentText() == toqstr(name))
1315 int idx = latexModule->classCO->findText(toqstr(name));
1317 classes_model_.insertRow(0, toqstr(name), name);
1318 latexModule->classCO->setCurrentIndex(0);
1320 latexModule->classCO->setCurrentIndex(idx);
1326 void GuiDocument::browseMaster()
1328 QString const title = qt_("Select master document");
1329 QString const dir1 = toqstr(lyxrc.document_path);
1330 QString const old = latexModule->childDocLE->text();
1331 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1332 QStringList const filter(qt_("LyX Files (*.lyx)"));
1333 QString file = browseRelFile(old, docpath, title, filter, false,
1334 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1336 latexModule->childDocLE->setText(file);
1340 void GuiDocument::classChanged()
1342 int idx = latexModule->classCO->currentIndex();
1345 string const classname = classes_model_.getIDString(idx);
1347 // We load the TextClass as soon as it is selected. This is
1348 // necessary so that other options in the dialog can be updated
1349 // according to the new class. Note, however, that, if you use
1350 // the scroll wheel when sitting on the combo box, we'll load a
1351 // lot of TextClass objects very quickly....
1352 if (!bp_.setBaseClass(classname)) {
1353 Alert::error(_("Error"), _("Unable to set document class."));
1357 // FIXME We should really check here whether the modules have been
1358 // changed, I think, even if auto_reset_options is false. And, if so,
1359 // pop the same dialog. So we would need to compare what is in
1360 // modules_sel_model with what is in the OLD bp_.getModules() and
1361 // so do that before we reset things.
1362 if (lyxrc.auto_reset_options) {
1363 if (applyPB->isEnabled()) {
1364 int const ret = Alert::prompt(_("Unapplied changes"),
1365 _("Some changes in the dialog were not yet applied.\n"
1366 "If you do not apply now, they will be lost after this action."),
1367 1, 1, _("&Apply"), _("&Dismiss"));
1371 bp_.useClassDefaults();
1373 // With the introduction of modules came a distinction between the base
1374 // class and the document class. The former corresponds to the main layout
1375 // file; the latter is that plus the modules (or the document-specific layout,
1376 // or whatever else there could be). Our parameters come from the document
1377 // class. So when we set the base class, we also need to recreate the document
1378 // class. Otherwise, we still have the old one.
1379 bp_.makeDocumentClass();
1380 // the new class may require some default modules.
1381 updateSelectedModules();
1382 paramsToDialog(bp_);
1387 // This is an insanely complicated attempt to make this sort of thing
1388 // work with RTL languages.
1389 docstring formatStrVec(vector<string> const & v, docstring const & s)
1391 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1395 return from_ascii(v[0]);
1396 if (v.size() == 2) {
1397 docstring retval = _("%1$s and %2$s");
1398 retval = subst(retval, _("and"), s);
1399 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1401 // The idea here is to format all but the last two items...
1402 int const vSize = v.size();
1403 docstring t2 = _("%1$s, %2$s");
1404 docstring retval = from_ascii(v[0]);
1405 for (int i = 1; i < vSize - 2; ++i)
1406 retval = bformat(t2, retval, from_ascii(v[i]));
1407 //...and then to plug them, and the last two, into this schema
1408 docstring t = _("%1$s, %2$s, and %3$s");
1409 t = subst(t, _("and"), s);
1410 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1413 vector<string> idsToNames(vector<string> const & idList)
1415 vector<string> retval;
1416 vector<string>::const_iterator it = idList.begin();
1417 vector<string>::const_iterator end = idList.end();
1418 for (; it != end; ++it) {
1419 LyXModule const * const mod = moduleList[*it];
1421 retval.push_back(*it + " (Unavailable)");
1423 retval.push_back(mod->getName());
1430 void GuiDocument::updateModuleInfo()
1432 selectionManager->update();
1434 //Module description
1435 bool const focusOnSelected = selectionManager->selectedFocused();
1436 QListView const * const lv =
1437 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1438 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1439 latexModule->infoML->document()->clear();
1442 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1443 GuiIdListModel const & idModel =
1444 focusOnSelected ? modules_sel_model_ : modules_av_model_;
1445 string const modName = idModel.getIDString(idx.row());
1446 docstring desc = getModuleDescription(modName);
1448 vector<string> pkgList = getPackageList(modName);
1449 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1450 if (!pkgdesc.empty()) {
1453 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1456 pkgList = getRequiredList(modName);
1457 if (!pkgList.empty()) {
1458 vector<string> const reqDescs = idsToNames(pkgList);
1459 pkgdesc = formatStrVec(reqDescs, _("or"));
1462 desc += bformat(_("Module required: %1$s."), pkgdesc);
1465 pkgList = getExcludedList(modName);
1466 if (!pkgList.empty()) {
1467 vector<string> const reqDescs = idsToNames(pkgList);
1468 pkgdesc = formatStrVec(reqDescs, _( "and"));
1471 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1474 if (!isModuleAvailable(modName)) {
1477 desc += _("WARNING: Some packages are unavailable!");
1480 latexModule->infoML->document()->setPlainText(toqstr(desc));
1484 void GuiDocument::updateNumbering()
1486 DocumentClass const & tclass = documentClass();
1488 numberingModule->tocTW->setUpdatesEnabled(false);
1489 numberingModule->tocTW->clear();
1491 int const depth = numberingModule->depthSL->value();
1492 int const toc = numberingModule->tocSL->value();
1493 QString const no = qt_("No");
1494 QString const yes = qt_("Yes");
1495 QTreeWidgetItem * item = 0;
1497 DocumentClass::const_iterator lit = tclass.begin();
1498 DocumentClass::const_iterator len = tclass.end();
1499 for (; lit != len; ++lit) {
1500 int const toclevel = lit->toclevel;
1501 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1502 item = new QTreeWidgetItem(numberingModule->tocTW);
1503 item->setText(0, toqstr(translateIfPossible(lit->name())));
1504 item->setText(1, (toclevel <= depth) ? yes : no);
1505 item->setText(2, (toclevel <= toc) ? yes : no);
1509 numberingModule->tocTW->setUpdatesEnabled(true);
1510 numberingModule->tocTW->update();
1514 void GuiDocument::apply(BufferParams & params)
1517 preambleModule->apply(params);
1520 params.setCiteEngine(ENGINE_BASIC);
1522 if (biblioModule->citeNatbibRB->isChecked()) {
1523 bool const use_numerical_citations =
1524 biblioModule->citeStyleCO->currentIndex();
1525 if (use_numerical_citations)
1526 params.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
1528 params.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
1530 } else if (biblioModule->citeJurabibRB->isChecked())
1531 params.setCiteEngine(ENGINE_JURABIB);
1533 params.use_bibtopic =
1534 biblioModule->bibtopicCB->isChecked();
1536 // language & quotes
1537 if (langModule->defaultencodingRB->isChecked()) {
1538 params.inputenc = "auto";
1540 int i = langModule->encodingCO->currentIndex();
1542 params.inputenc = "default";
1544 QString const enc_gui =
1545 langModule->encodingCO->currentText();
1546 Encodings::const_iterator it = encodings.begin();
1547 Encodings::const_iterator const end = encodings.end();
1549 for (; it != end; ++it) {
1550 if (qt_(it->guiName()) == enc_gui) {
1551 params.inputenc = it->latexName();
1557 // should not happen
1558 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
1559 params.inputenc = "default";
1564 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
1565 switch (langModule->quoteStyleCO->currentIndex()) {
1567 lga = InsetQuotes::EnglishQuotes;
1570 lga = InsetQuotes::SwedishQuotes;
1573 lga = InsetQuotes::GermanQuotes;
1576 lga = InsetQuotes::PolishQuotes;
1579 lga = InsetQuotes::FrenchQuotes;
1582 lga = InsetQuotes::DanishQuotes;
1585 params.quotes_language = lga;
1587 QString const lang = langModule->languageCO->itemData(
1588 langModule->languageCO->currentIndex()).toString();
1589 params.language = lyx::languages.getLanguage(fromqstr(lang));
1592 if (params.documentClass().hasTocLevels()) {
1593 params.tocdepth = numberingModule->tocSL->value();
1594 params.secnumdepth = numberingModule->depthSL->value();
1598 params.user_defined_bullet(0) = bulletsModule->bullet(0);
1599 params.user_defined_bullet(1) = bulletsModule->bullet(1);
1600 params.user_defined_bullet(2) = bulletsModule->bullet(2);
1601 params.user_defined_bullet(3) = bulletsModule->bullet(3);
1604 params.graphicsDriver =
1605 tex_graphics[latexModule->psdriverCO->currentIndex()];
1608 int idx = latexModule->classCO->currentIndex();
1610 string const classname = classes_model_.getIDString(idx);
1611 params.setBaseClass(classname);
1615 params.clearLayoutModules();
1616 int const srows = modules_sel_model_.rowCount();
1617 vector<string> selModList;
1618 for (int i = 0; i < srows; ++i)
1619 params.addLayoutModule(modules_sel_model_.getIDString(i));
1620 // update the list of removed modules
1621 params.clearRemovedModules();
1622 list<string> const & reqmods = params.baseClass()->defaultModules();
1623 list<string>::const_iterator rit = reqmods.begin();
1624 list<string>::const_iterator ren = reqmods.end();
1625 // check each of the required modules
1626 for (; rit != ren; rit++) {
1627 list<string>::const_iterator mit = params.getModules().begin();
1628 list<string>::const_iterator men = params.getModules().end();
1630 for (; mit != men; mit++) {
1637 // the module isn't present so must have been removed by the user
1638 params.addRemovedModule(*rit);
1642 if (mathsModule->amsautoCB->isChecked()) {
1643 params.use_amsmath = BufferParams::package_auto;
1645 if (mathsModule->amsCB->isChecked())
1646 params.use_amsmath = BufferParams::package_on;
1648 params.use_amsmath = BufferParams::package_off;
1651 if (mathsModule->esintautoCB->isChecked())
1652 params.use_esint = BufferParams::package_auto;
1654 if (mathsModule->esintCB->isChecked())
1655 params.use_esint = BufferParams::package_on;
1657 params.use_esint = BufferParams::package_off;
1660 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1661 params.pagestyle = "default";
1663 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
1664 for (size_t i = 0; i != pagestyles.size(); ++i)
1665 if (pagestyles[i].second == style_gui)
1666 params.pagestyle = pagestyles[i].first;
1669 switch (textLayoutModule->lspacingCO->currentIndex()) {
1671 params.spacing().set(Spacing::Single);
1674 params.spacing().set(Spacing::Onehalf);
1677 params.spacing().set(Spacing::Double);
1680 params.spacing().set(Spacing::Other,
1681 fromqstr(textLayoutModule->lspacingLE->text()));
1685 if (textLayoutModule->twoColumnCB->isChecked())
1690 // text should have passed validation
1691 params.listings_params =
1692 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1694 if (textLayoutModule->indentRB->isChecked())
1695 params.paragraph_separation = BufferParams::ParagraphIndentSeparation;
1697 params.paragraph_separation = BufferParams::ParagraphSkipSeparation;
1699 switch (textLayoutModule->skipCO->currentIndex()) {
1701 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1704 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1707 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1712 widgetsToLength(textLayoutModule->skipLE,
1713 textLayoutModule->skipLengthCO)
1715 params.setDefSkip(vs);
1719 // DocumentDefskipCB assures that this never happens
1720 // so Assert then !!! - jbl
1721 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1726 fromqstr(latexModule->optionsLE->text());
1728 params.use_default_options =
1729 latexModule->defaultOptionsCB->isChecked();
1731 if (latexModule->childDocGB->isChecked())
1733 fromqstr(latexModule->childDocLE->text());
1735 params.master = string();
1737 params.float_placement = floatModule->get();
1741 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1744 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1746 params.fontsTypewriter =
1747 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1750 fromqstr(fontModule->cjkFontLE->text());
1752 params.fontsSansScale = fontModule->scaleSansSB->value();
1754 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1756 params.fontsSC = fontModule->fontScCB->isChecked();
1758 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1760 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1761 fontModule->fontsDefaultCO->currentIndex()];
1763 if (fontModule->fontsizeCO->currentIndex() == 0)
1764 params.fontsize = "default";
1767 fromqstr(fontModule->fontsizeCO->currentText());
1770 params.papersize = PAPER_SIZE(
1771 pageLayoutModule->papersizeCO->currentIndex());
1773 // custom, A3, B3 and B4 paper sizes need geometry
1774 int psize = pageLayoutModule->papersizeCO->currentIndex();
1775 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1777 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1778 pageLayoutModule->paperwidthUnitCO);
1780 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1781 pageLayoutModule->paperheightUnitCO);
1783 if (pageLayoutModule->facingPagesCB->isChecked())
1784 params.sides = TwoSides;
1786 params.sides = OneSide;
1788 if (pageLayoutModule->landscapeRB->isChecked())
1789 params.orientation = ORIENTATION_LANDSCAPE;
1791 params.orientation = ORIENTATION_PORTRAIT;
1794 params.use_geometry = !marginsModule->marginCB->isChecked()
1797 Ui::MarginsUi const * m = marginsModule;
1799 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1800 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1801 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1802 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1803 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1804 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1805 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1806 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1808 branchesModule->apply(params);
1811 PDFOptions & pdf = params.pdfoptions();
1812 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1813 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1814 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1815 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1816 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1818 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1819 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1820 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1821 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1823 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1824 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1825 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1826 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1828 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
1829 if (pdfSupportModule->fullscreenCB->isChecked())
1830 pdf.pagemode = pdf.pagemode_fullscreen;
1832 pdf.pagemode.clear();
1833 pdf.quoted_options = pdf.quoted_options_check(
1834 fromqstr(pdfSupportModule->optionsLE->text()));
1838 void GuiDocument::paramsToDialog(BufferParams const & params)
1840 // set the default unit
1841 Length::UNIT defaultUnit = Length::CM;
1842 switch (lyxrc.default_papersize) {
1843 case PAPER_DEFAULT: break;
1845 case PAPER_USLETTER:
1847 case PAPER_USEXECUTIVE:
1848 defaultUnit = Length::IN;
1857 defaultUnit = Length::CM;
1864 preambleModule->update(params, id());
1867 biblioModule->citeDefaultRB->setChecked(
1868 params.citeEngine() == ENGINE_BASIC);
1870 biblioModule->citeNatbibRB->setChecked(
1871 params.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
1872 params.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
1874 biblioModule->citeStyleCO->setCurrentIndex(
1875 params.citeEngine() == ENGINE_NATBIB_NUMERICAL);
1877 biblioModule->citeJurabibRB->setChecked(
1878 params.citeEngine() == ENGINE_JURABIB);
1880 biblioModule->bibtopicCB->setChecked(
1881 params.use_bibtopic);
1883 // language & quotes
1884 int const pos = langModule->languageCO->findData(toqstr(
1885 params.language->lang()));
1886 langModule->languageCO->setCurrentIndex(pos);
1888 langModule->quoteStyleCO->setCurrentIndex(
1889 params.quotes_language);
1891 bool default_enc = true;
1892 if (params.inputenc != "auto") {
1893 default_enc = false;
1894 if (params.inputenc == "default") {
1895 langModule->encodingCO->setCurrentIndex(0);
1898 Encodings::const_iterator it = encodings.begin();
1899 Encodings::const_iterator const end = encodings.end();
1900 for (; it != end; ++it) {
1901 if (it->latexName() == params.inputenc) {
1902 enc_gui = it->guiName();
1906 int const i = langModule->encodingCO->findText(
1909 langModule->encodingCO->setCurrentIndex(i);
1911 // unknown encoding. Set to default.
1915 langModule->defaultencodingRB->setChecked(default_enc);
1916 langModule->otherencodingRB->setChecked(!default_enc);
1919 int const min_toclevel = documentClass().min_toclevel();
1920 int const max_toclevel = documentClass().max_toclevel();
1921 if (documentClass().hasTocLevels()) {
1922 numberingModule->setEnabled(true);
1923 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1924 numberingModule->depthSL->setMaximum(max_toclevel);
1925 numberingModule->depthSL->setValue(params.secnumdepth);
1926 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1927 numberingModule->tocSL->setMaximum(max_toclevel);
1928 numberingModule->tocSL->setValue(params.tocdepth);
1931 numberingModule->setEnabled(false);
1932 numberingModule->tocTW->clear();
1936 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1937 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1938 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1939 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1940 bulletsModule->init();
1943 int nitem = findToken(tex_graphics, params.graphicsDriver);
1945 latexModule->psdriverCO->setCurrentIndex(nitem);
1948 mathsModule->amsCB->setChecked(
1949 params.use_amsmath == BufferParams::package_on);
1950 mathsModule->amsautoCB->setChecked(
1951 params.use_amsmath == BufferParams::package_auto);
1953 mathsModule->esintCB->setChecked(
1954 params.use_esint == BufferParams::package_on);
1955 mathsModule->esintautoCB->setChecked(
1956 params.use_esint == BufferParams::package_auto);
1958 switch (params.spacing().getSpace()) {
1959 case Spacing::Other: nitem = 3; break;
1960 case Spacing::Double: nitem = 2; break;
1961 case Spacing::Onehalf: nitem = 1; break;
1962 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1966 string const & layoutID = params.baseClassID();
1967 setLayoutComboByIDString(layoutID);
1969 updatePagestyle(documentClass().opt_pagestyle(),
1972 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1973 if (params.spacing().getSpace() == Spacing::Other) {
1974 textLayoutModule->lspacingLE->setText(
1975 toqstr(params.spacing().getValueAsString()));
1979 if (params.paragraph_separation == BufferParams::ParagraphIndentSeparation)
1980 textLayoutModule->indentRB->setChecked(true);
1982 textLayoutModule->skipRB->setChecked(true);
1985 switch (params.getDefSkip().kind()) {
1986 case VSpace::SMALLSKIP:
1989 case VSpace::MEDSKIP:
1992 case VSpace::BIGSKIP:
1995 case VSpace::LENGTH:
1998 string const length = params.getDefSkip().asLyXCommand();
1999 lengthToWidgets(textLayoutModule->skipLE,
2000 textLayoutModule->skipLengthCO,
2001 length, defaultUnit);
2008 textLayoutModule->skipCO->setCurrentIndex(skip);
2011 textLayoutModule->twoColumnCB->setChecked(
2012 params.columns == 2);
2014 // break listings_params to multiple lines
2016 InsetListingsParams(params.listings_params).separatedParams();
2017 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
2019 if (!params.options.empty()) {
2020 latexModule->optionsLE->setText(
2021 toqstr(params.options));
2023 latexModule->optionsLE->setText(QString());
2026 latexModule->defaultOptionsCB->setChecked(
2027 params.use_default_options);
2029 if (!documentClass().options().empty()) {
2030 latexModule->defaultOptionsLE->setText(
2031 toqstr(documentClass().options()));
2033 latexModule->defaultOptionsLE->setText(
2034 toqstr(_("[No options predefined]")));
2037 latexModule->defaultOptionsLE->setEnabled(
2038 params.use_default_options
2039 && !documentClass().options().empty());
2041 latexModule->defaultOptionsCB->setEnabled(
2042 !documentClass().options().empty());
2044 if (!params.master.empty()) {
2045 latexModule->childDocGB->setChecked(true);
2046 latexModule->childDocLE->setText(
2047 toqstr(params.master));
2049 latexModule->childDocLE->setText(QString());
2050 latexModule->childDocGB->setChecked(false);
2053 floatModule->set(params.float_placement);
2056 updateFontsize(documentClass().opt_fontsize(),
2059 int n = findToken(tex_fonts_roman, params.fontsRoman);
2061 fontModule->fontsRomanCO->setCurrentIndex(n);
2065 n = findToken(tex_fonts_sans, params.fontsSans);
2067 fontModule->fontsSansCO->setCurrentIndex(n);
2071 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
2073 fontModule->fontsTypewriterCO->setCurrentIndex(n);
2077 if (!params.fontsCJK.empty())
2078 fontModule->cjkFontLE->setText(
2079 toqstr(params.fontsCJK));
2081 fontModule->cjkFontLE->setText(QString());
2083 fontModule->fontScCB->setChecked(params.fontsSC);
2084 fontModule->fontOsfCB->setChecked(params.fontsOSF);
2085 fontModule->scaleSansSB->setValue(params.fontsSansScale);
2086 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
2087 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
2089 fontModule->fontsDefaultCO->setCurrentIndex(n);
2092 int const psize = params.papersize;
2093 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
2094 setCustomPapersize(psize);
2096 bool const landscape =
2097 params.orientation == ORIENTATION_LANDSCAPE;
2098 pageLayoutModule->landscapeRB->setChecked(landscape);
2099 pageLayoutModule->portraitRB->setChecked(!landscape);
2101 pageLayoutModule->facingPagesCB->setChecked(
2102 params.sides == TwoSides);
2105 lengthToWidgets(pageLayoutModule->paperwidthLE,
2106 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
2108 lengthToWidgets(pageLayoutModule->paperheightLE,
2109 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
2112 Ui::MarginsUi * m = marginsModule;
2114 setMargins(!params.use_geometry);
2116 lengthToWidgets(m->topLE, m->topUnit,
2117 params.topmargin, defaultUnit);
2119 lengthToWidgets(m->bottomLE, m->bottomUnit,
2120 params.bottommargin, defaultUnit);
2122 lengthToWidgets(m->innerLE, m->innerUnit,
2123 params.leftmargin, defaultUnit);
2125 lengthToWidgets(m->outerLE, m->outerUnit,
2126 params.rightmargin, defaultUnit);
2128 lengthToWidgets(m->headheightLE, m->headheightUnit,
2129 params.headheight, defaultUnit);
2131 lengthToWidgets(m->headsepLE, m->headsepUnit,
2132 params.headsep, defaultUnit);
2134 lengthToWidgets(m->footskipLE, m->footskipUnit,
2135 params.footskip, defaultUnit);
2137 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2138 params.columnsep, defaultUnit);
2140 branchesModule->update(params);
2143 PDFOptions const & pdf = params.pdfoptions();
2144 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2145 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2146 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2147 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2148 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2150 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2151 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2152 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2154 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2156 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2157 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2158 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2159 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2161 n = findToken(backref_opts, pdf.backref);
2163 pdfSupportModule->backrefCO->setCurrentIndex(n);
2165 pdfSupportModule->fullscreenCB->setChecked
2166 (pdf.pagemode == pdf.pagemode_fullscreen);
2168 pdfSupportModule->optionsLE->setText(
2169 toqstr(pdf.quoted_options));
2173 void GuiDocument::applyView()
2179 void GuiDocument::saveDocDefault()
2181 // we have to apply the params first
2187 void GuiDocument::updateAvailableModules()
2189 modules_av_model_.clear();
2190 list<modInfoStruct> const & modInfoList = getModuleInfo();
2191 list<modInfoStruct>::const_iterator mit = modInfoList.begin();
2192 list<modInfoStruct>::const_iterator men = modInfoList.end();
2193 for (int i = 0; mit != men; ++mit, ++i)
2194 modules_av_model_.insertRow(i, mit->name, mit->id,
2199 void GuiDocument::updateSelectedModules()
2201 modules_sel_model_.clear();
2202 list<modInfoStruct> const selModList = getSelectedModules();
2203 list<modInfoStruct>::const_iterator mit = selModList.begin();
2204 list<modInfoStruct>::const_iterator men = selModList.end();
2205 for (int i = 0; mit != men; ++mit, ++i)
2206 modules_sel_model_.insertRow(i, mit->name, mit->id,
2211 void GuiDocument::updateContents()
2213 // Nothing to do here as the document settings is not cursor dependant.
2218 void GuiDocument::useClassDefaults()
2220 if (applyPB->isEnabled()) {
2221 int const ret = Alert::prompt(_("Unapplied changes"),
2222 _("Some changes in the dialog were not yet applied.\n"
2223 "If you do not apply now, they will be lost after this action."),
2224 1, 1, _("&Apply"), _("&Dismiss"));
2229 int idx = latexModule->classCO->currentIndex();
2230 string const classname = classes_model_.getIDString(idx);
2231 if (!bp_.setBaseClass(classname)) {
2232 Alert::error(_("Error"), _("Unable to set document class."));
2235 bp_.useClassDefaults();
2236 paramsToDialog(bp_);
2240 void GuiDocument::setLayoutComboByIDString(string const & idString)
2242 int idx = classes_model_.findIDString(idString);
2244 Alert::warning(_("Can't set layout!"),
2245 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2247 latexModule->classCO->setCurrentIndex(idx);
2251 bool GuiDocument::isValid()
2253 return validateListingsParameters().isEmpty()
2254 && (textLayoutModule->skipCO->currentIndex() != 3
2255 || !textLayoutModule->skipLE->text().isEmpty());
2259 char const * const GuiDocument::fontfamilies[5] = {
2260 "default", "rmdefault", "sfdefault", "ttdefault", ""
2264 char const * GuiDocument::fontfamilies_gui[5] = {
2265 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2269 bool GuiDocument::initialiseParams(string const &)
2271 BufferView const * view = bufferview();
2273 bp_ = BufferParams();
2274 paramsToDialog(bp_);
2277 bp_ = view->buffer().params();
2279 updateAvailableModules();
2280 updateSelectedModules();
2281 //FIXME It'd be nice to make sure here that the selected
2282 //modules are consistent: That required modules are actually
2283 //selected, and that we don't have conflicts. If so, we could
2284 //at least pop up a warning.
2285 paramsToDialog(bp_);
2290 void GuiDocument::clearParams()
2292 bp_ = BufferParams();
2296 BufferId GuiDocument::id() const
2298 BufferView const * const view = bufferview();
2299 return view? &view->buffer() : 0;
2303 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2305 return moduleNames_;
2309 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2311 list<string> const & mods = params().getModules();
2312 list<string>::const_iterator it = mods.begin();
2313 list<string>::const_iterator end = mods.end();
2314 list<modInfoStruct> mInfo;
2315 for (; it != end; ++it) {
2318 LyXModule * mod = moduleList[*it];
2320 m.name = qt_(mod->getName());
2322 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
2329 DocumentClass const & GuiDocument::documentClass() const
2331 return bp_.documentClass();
2335 static void dispatch_bufferparams(Dialog const & dialog,
2336 BufferParams const & bp, FuncCode lfun)
2339 ss << "\\begin_header\n";
2341 ss << "\\end_header\n";
2342 dialog.dispatch(FuncRequest(lfun, ss.str()));
2346 void GuiDocument::dispatchParams()
2348 // This must come first so that a language change is correctly noticed
2351 // Apply the BufferParams. Note that this will set the base class
2352 // and then update the buffer's layout.
2353 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2355 if (!params().master.empty()) {
2356 FileName const master_file = support::makeAbsPath(params().master,
2357 support::onlyPath(buffer().absFileName()));
2358 if (isLyXFilename(master_file.absFilename())) {
2359 Buffer * master = checkAndLoadLyXFile(master_file);
2360 const_cast<Buffer &>(buffer()).setParent(master);
2364 // Generate the colours requested by each new branch.
2365 BranchList & branchlist = params().branchlist();
2366 if (!branchlist.empty()) {
2367 BranchList::const_iterator it = branchlist.begin();
2368 BranchList::const_iterator const end = branchlist.end();
2369 for (; it != end; ++it) {
2370 docstring const & current_branch = it->branch();
2371 Branch const * branch = branchlist.find(current_branch);
2372 string const x11hexname = X11hexname(branch->color());
2373 // display the new color
2374 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2375 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2378 // Open insets of selected branches, close deselected ones
2379 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2382 // FIXME: If we used an LFUN, we would not need those two lines:
2383 BufferView * bv = const_cast<BufferView *>(bufferview());
2384 bv->processUpdateFlags(Update::Force | Update::FitCursor);
2388 void GuiDocument::setLanguage() const
2390 Language const * const newL = bp_.language;
2391 if (buffer().params().language == newL)
2394 string const & lang_name = newL->lang();
2395 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2399 void GuiDocument::saveAsDefault() const
2401 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2405 bool GuiDocument::isFontAvailable(string const & font) const
2407 if (font == "default" || font == "cmr"
2408 || font == "cmss" || font == "cmtt")
2409 // these are standard
2411 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2412 return LaTeXFeatures::isAvailable("lmodern");
2413 if (font == "times" || font == "palatino"
2414 || font == "helvet" || font == "courier")
2415 return LaTeXFeatures::isAvailable("psnfss");
2416 if (font == "cmbr" || font == "cmtl")
2417 return LaTeXFeatures::isAvailable("cmbright");
2418 if (font == "utopia")
2419 return LaTeXFeatures::isAvailable("utopia")
2420 || LaTeXFeatures::isAvailable("fourier");
2421 if (font == "beraserif" || font == "berasans"
2422 || font == "beramono")
2423 return LaTeXFeatures::isAvailable("bera");
2424 return LaTeXFeatures::isAvailable(font);
2428 bool GuiDocument::providesOSF(string const & font) const
2431 return isFontAvailable("eco");
2432 if (font == "palatino")
2433 return isFontAvailable("mathpazo");
2438 bool GuiDocument::providesSC(string const & font) const
2440 if (font == "palatino")
2441 return isFontAvailable("mathpazo");
2442 if (font == "utopia")
2443 return isFontAvailable("fourier");
2448 bool GuiDocument::providesScale(string const & font) const
2450 return font == "helvet" || font == "luximono"
2451 || font == "berasans" || font == "beramono";
2455 void GuiDocument::loadModuleInfo()
2457 moduleNames_.clear();
2458 LyXModuleList::const_iterator it = moduleList.begin();
2459 LyXModuleList::const_iterator end = moduleList.end();
2460 for (; it != end; ++it) {
2463 m.name = qt_(it->getName());
2464 // this is supposed to give us the first sentence of the description
2465 QString desc = qt_(it->getDescription());
2466 int const pos = desc.indexOf(".");
2468 desc.truncate(pos + 1);
2469 m.description = desc;
2470 moduleNames_.push_back(m);
2475 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2478 } // namespace frontend
2481 #include "GuiDocument_moc.cpp"