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 "LayoutFile.h"
17 #include "BranchList.h"
18 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
24 #include "FloatPlacement.h"
25 #include "FuncRequest.h"
26 #include "support/gettext.h"
27 #include "GuiBranches.h"
29 #include "LaTeXFeatures.h"
30 #include "LaTeXHighlighter.h"
32 #include "LengthCombo.h"
33 #include "LyXRC.h" // defaultUnit
34 #include "ModuleList.h"
35 #include "OutputParams.h"
36 #include "PanelStack.h"
37 #include "PDFOptions.h"
38 #include "qt_helpers.h"
40 #include "Validator.h"
42 #include "insets/InsetListingsParams.h"
44 #include "support/debug.h"
45 #include "support/FileName.h"
46 #include "support/FileFilterList.h"
47 #include "support/filetools.h"
48 #include "support/lstrings.h"
50 #include "frontends/alert.h"
52 #include <QCloseEvent>
54 #include <QTextCursor>
64 using namespace lyx::support;
69 char const * const tex_graphics[] =
71 "default", "dvips", "dvitops", "emtex",
72 "ln", "oztex", "textures", "none", ""
76 char const * const tex_graphics_gui[] =
78 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
79 "LN", "OzTeX", "Textures", N_("None"), ""
83 char const * const tex_fonts_roman[] =
85 "default", "cmr", "lmodern", "ae", "times", "palatino",
86 "charter", "newcent", "bookman", "utopia", "beraserif",
87 "ccfonts", "chancery", ""
91 char const * tex_fonts_roman_gui[] =
93 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
94 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
95 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
96 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
101 char const * const tex_fonts_sans[] =
103 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
107 char const * tex_fonts_sans_gui[] =
109 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
110 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
114 char const * const tex_fonts_monospaced[] =
116 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
120 char const * tex_fonts_monospaced_gui[] =
122 N_("Default"), N_("Computer Modern Typewriter"),
123 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
124 N_("LuxiMono"), N_("CM Typewriter Light"), ""
128 vector<pair<string, lyx::docstring> > pagestyles;
131 } // anonymous namespace
136 // used when sorting the textclass list.
137 class less_textclass_avail_desc
138 : public binary_function<string, string, int>
141 int operator()(string const & lhs, string const & rhs) const
143 // Ordering criteria:
144 // 1. Availability of text class
145 // 2. Description (lexicographic)
146 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
147 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
148 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
149 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
150 _(tc1.description()) < _(tc2.description()));
160 QModelIndex getSelectedIndex(QListView * lv)
162 QModelIndex retval = QModelIndex();
163 QModelIndexList selIdx =
164 lv->selectionModel()->selectedIndexes();
166 retval = selIdx.first();
172 vector<string> getRequiredList(string const & modName)
174 LyXModule const * const mod = moduleList[modName];
176 return vector<string>(); //empty such thing
177 return mod->getRequiredModules();
181 vector<string> getExcludedList(string const & modName)
183 LyXModule const * const mod = moduleList[modName];
185 return vector<string>(); //empty such thing
186 return mod->getExcludedModules();
190 docstring getModuleDescription(string const & modName)
192 LyXModule const * const mod = moduleList[modName];
194 return _("Module not found!");
195 return _(mod->getDescription());
199 vector<string> getPackageList(string const & modName)
201 LyXModule const * const mod = moduleList[modName];
203 return vector<string>(); //empty such thing
204 return mod->getPackageList();
208 bool isModuleAvailable(string const & modName)
210 LyXModule * mod = moduleList[modName];
213 return mod->isAvailable();
215 } //anonymous namespace
218 ModuleSelMan::ModuleSelMan(
219 QListView * availableLV,
220 QListView * selectedLV,
224 QPushButton * downPB,
225 GuiIdListModel * availableModel,
226 GuiIdListModel * selectedModel) :
227 GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
228 upPB, downPB, availableModel, selectedModel)
232 void ModuleSelMan::updateAddPB()
234 int const arows = availableModel->rowCount();
235 QModelIndexList const availSels =
236 availableLV->selectionModel()->selectedIndexes();
237 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
238 addPB->setEnabled(false);
242 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
243 string const modName = getAvailableModel()->getIDString(idx.row());
244 vector<string> reqs = getRequiredList(modName);
245 vector<string> excl = getExcludedList(modName);
247 if (reqs.empty() && excl.empty()) {
248 addPB->setEnabled(true);
252 int const srows = selectedModel->rowCount();
253 vector<string> selModList;
254 for (int i = 0; i < srows; ++i)
255 selModList.push_back(getSelectedModel()->getIDString(i));
257 vector<string>::const_iterator selModStart = selModList.begin();
258 vector<string>::const_iterator selModEnd = selModList.end();
260 //Check whether some required module is available
262 bool foundOne = false;
263 vector<string>::const_iterator it = reqs.begin();
264 vector<string>::const_iterator end = reqs.end();
265 for (; it != end; ++it) {
266 if (find(selModStart, selModEnd, *it) != selModEnd) {
272 addPB->setEnabled(false);
277 //Check whether any excluded module is being used
279 vector<string>::const_iterator it = excl.begin();
280 vector<string>::const_iterator end = excl.end();
281 for (; it != end; ++it) {
282 if (find(selModStart, selModEnd, *it) != selModEnd) {
283 addPB->setEnabled(false);
289 addPB->setEnabled(true);
293 void ModuleSelMan::updateDownPB()
295 int const srows = selectedModel->rowCount();
297 downPB->setEnabled(false);
300 QModelIndexList const selSels =
301 selectedLV->selectionModel()->selectedIndexes();
302 //disable if empty or last item is selected
303 if (selSels.empty() || selSels.first().row() == srows - 1) {
304 downPB->setEnabled(false);
307 //determine whether immediately succeding element requires this one
308 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
309 int curRow = curIdx.row();
310 if (curRow < 0 || curRow >= srows - 1) { //this shouldn't happen...
311 downPB->setEnabled(false);
314 string const curModName = getSelectedModel()->getIDString(curRow);
315 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
317 vector<string> reqs = getRequiredList(nextModName);
319 //if it doesn't require anything....
321 downPB->setEnabled(true);
325 //FIXME This should perhaps be more flexible and check whether, even
326 //if this one is required, there is also an earlier one that is required.
327 //enable it if this module isn't required
329 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
332 void ModuleSelMan::updateUpPB()
334 int const srows = selectedModel->rowCount();
336 upPB->setEnabled(false);
339 QModelIndexList const selSels =
340 selectedLV->selectionModel()->selectedIndexes();
341 //disable if empty or first item is selected
342 if (selSels.empty() || selSels.first().row() == 0) {
343 upPB->setEnabled(false);
347 //determine whether immediately preceding element is required by this one
348 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
349 int curRow = curIdx.row();
350 if (curRow <= -1 || curRow > srows - 1) { //sanity check
351 downPB->setEnabled(false);
354 string const curModName = getSelectedModel()->getIDString(curRow);
355 vector<string> reqs = getRequiredList(curModName);
357 //if this one doesn't require anything....
359 upPB->setEnabled(true);
363 string preModName = getSelectedModel()->getIDString(curRow - 1);
365 //NOTE This is less flexible than it might be. You could check whether, even
366 //if this one is required, there is also an earlier one that is required.
367 //enable it if the preceding module isn't required
368 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
371 void ModuleSelMan::updateDelPB()
373 int const srows = selectedModel->rowCount();
375 deletePB->setEnabled(false);
378 QModelIndexList const selSels =
379 selectedLV->selectionModel()->selectedIndexes();
380 if (selSels.empty() || selSels.first().row() < 0) {
381 deletePB->setEnabled(false);
385 //determine whether some LATER module requires this one
386 //NOTE Things are arranged so that this is the only way there
387 //can be a problem. At least, we hope so.
388 QModelIndex const & curIdx =
389 selectedLV->selectionModel()->currentIndex();
390 int const curRow = curIdx.row();
391 if (curRow < 0 || curRow >= srows) { //this shouldn't happen
392 deletePB->setEnabled(false);
396 QString const curModName = curIdx.data().toString();
398 //We're looking here for a reason NOT to enable the button. If we
399 //find one, we disable it and return. If we don't, we'll end up at
400 //the end of the function, and then we enable it.
401 for (int i = curRow + 1; i < srows; ++i) {
402 string const thisMod = getSelectedModel()->getIDString(i);
403 vector<string> reqs = getRequiredList(thisMod);
404 //does this one require us?
405 if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
409 //OK, so this module requires us
410 //is there an EARLIER module that also satisfies the require?
411 //NOTE We demand that it be earlier to keep the list of modules
412 //consistent with the rule that a module must be proceeded by a
413 //required module. There would be more flexible ways to proceed,
414 //but that would be a lot more complicated, and the logic here is
415 //already complicated. (That's why I've left the debugging code.)
416 //lyxerr << "Testing " << thisMod << std::endl;
417 bool foundOne = false;
418 for (int j = 0; j < curRow; ++j) {
419 string const mod = getSelectedModel()->getIDString(j);
420 //lyxerr << "In loop: Testing " << mod << std::endl;
421 //do we satisfy the require?
422 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
423 //lyxerr << mod << " does the trick." << std::endl;
428 //did we find a module to satisfy the require?
430 //lyxerr << "No matching module found." << std::endl;
431 deletePB->setEnabled(false);
435 //lyxerr << "All's well that ends well." << std::endl;
436 deletePB->setEnabled(true);
440 /////////////////////////////////////////////////////////////////////
444 /////////////////////////////////////////////////////////////////////
446 PreambleModule::PreambleModule(): current_id_(0)
448 // This is not a memory leak. The object will be destroyed
450 (void) new LaTeXHighlighter(preambleTE->document());
451 setFocusProxy(preambleTE);
452 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
456 void PreambleModule::update(BufferParams const & params, BufferId id)
458 QString preamble = toqstr(params.preamble);
459 // Nothing to do if the params and preamble are unchanged.
460 if (id == current_id_
461 && preamble == preambleTE->document()->toPlainText())
464 QTextCursor cur = preambleTE->textCursor();
465 // Save the coords before switching to the new one.
466 preamble_coords_[current_id_] =
467 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
469 // Save the params address for further use.
471 preambleTE->document()->setPlainText(preamble);
472 Coords::const_iterator it = preamble_coords_.find(current_id_);
473 if (it == preamble_coords_.end())
474 // First time we open this one.
475 preamble_coords_[current_id_] = make_pair(0,0);
477 // Restore saved coords.
478 QTextCursor cur = preambleTE->textCursor();
479 cur.setPosition(it->second.first);
480 preambleTE->setTextCursor(cur);
481 preambleTE->verticalScrollBar()->setValue(it->second.second);
486 void PreambleModule::apply(BufferParams & params)
488 params.preamble = fromqstr(preambleTE->document()->toPlainText());
492 void PreambleModule::closeEvent(QCloseEvent * e)
494 // Save the coords before closing.
495 QTextCursor cur = preambleTE->textCursor();
496 preamble_coords_[current_id_] =
497 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
502 /////////////////////////////////////////////////////////////////////
506 /////////////////////////////////////////////////////////////////////
509 GuiDocument::GuiDocument(GuiView & lv)
510 : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
514 QList<LanguagePair> langs = languageData(false);
515 for (int i = 0; i != langs.size(); ++i)
516 lang_.append(langs[i].second);
518 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
519 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
520 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
521 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
523 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
524 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
526 // Manage the restore, ok, apply, restore and cancel/close buttons
527 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
529 bc().setApply(applyPB);
530 bc().setCancel(closePB);
531 bc().setRestore(restorePB);
533 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
535 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
536 this, SLOT(change_adaptor()));
537 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
538 this, SLOT(setLSpacing(int)));
539 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
540 this, SLOT(change_adaptor()));
541 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
542 this, SLOT(change_adaptor()));
543 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
544 this, SLOT(change_adaptor()));
545 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
546 this, SLOT(change_adaptor()));
547 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
548 this, SLOT(change_adaptor()));
549 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
550 this, SLOT(change_adaptor()));
551 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
552 this, SLOT(setSkip(int)));
553 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
554 this, SLOT(enableSkip(bool)));
555 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
556 this, SLOT(change_adaptor()));
557 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
558 this, SLOT(setColSep()));
559 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
560 this, SLOT(change_adaptor()));
561 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
562 this, SLOT(change_adaptor()));
563 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
564 this, SLOT(set_listings_msg()));
565 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
566 this, SLOT(set_listings_msg()));
567 textLayoutModule->listingsTB->setPlainText(
568 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
569 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
570 textLayoutModule->lspacingLE));
571 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
572 textLayoutModule->skipLE));
574 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
575 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
576 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
577 textLayoutModule->skipCO->addItem(qt_("Length"));
578 // remove the %-items from the unit choice
579 textLayoutModule->skipLengthCO->noPercents();
580 textLayoutModule->lspacingCO->insertItem(
581 Spacing::Single, qt_("Single"));
582 textLayoutModule->lspacingCO->insertItem(
583 Spacing::Onehalf, qt_("OneHalf"));
584 textLayoutModule->lspacingCO->insertItem(
585 Spacing::Double, qt_("Double"));
586 textLayoutModule->lspacingCO->insertItem(
587 Spacing::Other, qt_("Custom"));
589 // initialize the length validator
590 bc().addCheckedLineEdit(textLayoutModule->skipLE);
592 fontModule = new UiWidget<Ui::FontUi>;
594 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
595 this, SLOT(change_adaptor()));
596 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
597 this, SLOT(romanChanged(int)));
598 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
599 this, SLOT(change_adaptor()));
600 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
601 this, SLOT(sansChanged(int)));
602 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
603 this, SLOT(change_adaptor()));
604 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
605 this, SLOT(ttChanged(int)));
606 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
607 this, SLOT(change_adaptor()));
608 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
609 this, SLOT(change_adaptor()));
610 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
611 this, SLOT(change_adaptor()));
612 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
613 this, SLOT(change_adaptor()));
614 connect(fontModule->fontScCB, SIGNAL(clicked()),
615 this, SLOT(change_adaptor()));
616 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
617 this, SLOT(change_adaptor()));
619 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
620 QString font = qt_(tex_fonts_roman_gui[n]);
621 if (!isFontAvailable(tex_fonts_roman[n]))
622 font += qt_(" (not installed)");
623 fontModule->fontsRomanCO->addItem(font);
625 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
626 QString font = qt_(tex_fonts_sans_gui[n]);
627 if (!isFontAvailable(tex_fonts_sans[n]))
628 font += qt_(" (not installed)");
629 fontModule->fontsSansCO->addItem(font);
631 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
632 QString font = qt_(tex_fonts_monospaced_gui[n]);
633 if (!isFontAvailable(tex_fonts_monospaced[n]))
634 font += qt_(" (not installed)");
635 fontModule->fontsTypewriterCO->addItem(font);
638 fontModule->fontsizeCO->addItem(qt_("Default"));
639 fontModule->fontsizeCO->addItem(qt_("10"));
640 fontModule->fontsizeCO->addItem(qt_("11"));
641 fontModule->fontsizeCO->addItem(qt_("12"));
643 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
644 fontModule->fontsDefaultCO->addItem(
645 qt_(GuiDocument::fontfamilies_gui[n]));
648 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
650 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
651 this, SLOT(setCustomPapersize(int)));
652 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
653 this, SLOT(setCustomPapersize(int)));
654 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
655 this, SLOT(portraitChanged()));
656 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
657 this, SLOT(change_adaptor()));
658 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
659 this, SLOT(change_adaptor()));
660 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
661 this, SLOT(change_adaptor()));
662 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
663 this, SLOT(change_adaptor()));
664 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
665 this, SLOT(change_adaptor()));
666 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
667 this, SLOT(change_adaptor()));
668 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
669 this, SLOT(change_adaptor()));
670 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
671 this, SLOT(change_adaptor()));
672 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
673 this, SLOT(change_adaptor()));
675 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
676 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
677 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
678 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
679 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
680 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
681 pageLayoutModule->paperheightL);
682 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
683 pageLayoutModule->paperwidthL);
686 QComboBox * cb = pageLayoutModule->papersizeCO;
687 cb->addItem(qt_("Default"));
688 cb->addItem(qt_("Custom"));
689 cb->addItem(qt_("US letter"));
690 cb->addItem(qt_("US legal"));
691 cb->addItem(qt_("US executive"));
692 cb->addItem(qt_("A3"));
693 cb->addItem(qt_("A4"));
694 cb->addItem(qt_("A5"));
695 cb->addItem(qt_("B3"));
696 cb->addItem(qt_("B4"));
697 cb->addItem(qt_("B5"));
698 // remove the %-items from the unit choice
699 pageLayoutModule->paperwidthUnitCO->noPercents();
700 pageLayoutModule->paperheightUnitCO->noPercents();
701 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
702 pageLayoutModule->paperheightLE));
703 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
704 pageLayoutModule->paperwidthLE));
707 marginsModule = new UiWidget<Ui::MarginsUi>;
709 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
710 this, SLOT(setCustomMargins(bool)));
711 connect(marginsModule->marginCB, SIGNAL(clicked()),
712 this, SLOT(change_adaptor()));
713 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
714 this, SLOT(change_adaptor()));
715 connect(marginsModule->topUnit, SIGNAL(activated(int)),
716 this, SLOT(change_adaptor()));
717 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
718 this, SLOT(change_adaptor()));
719 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
720 this, SLOT(change_adaptor()));
721 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
722 this, SLOT(change_adaptor()));
723 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
724 this, SLOT(change_adaptor()));
725 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
726 this, SLOT(change_adaptor()));
727 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
728 this, SLOT(change_adaptor()));
729 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
730 this, SLOT(change_adaptor()));
731 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
732 this, SLOT(change_adaptor()));
733 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
734 this, SLOT(change_adaptor()));
735 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
736 this, SLOT(change_adaptor()));
737 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
738 this, SLOT(change_adaptor()));
739 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
740 this, SLOT(change_adaptor()));
741 connect(marginsModule->columnsepLE, SIGNAL(textChanged(const QString&)),
742 this, SLOT(change_adaptor()));
743 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
744 this, SLOT(change_adaptor()));
745 marginsModule->topLE->setValidator(unsignedLengthValidator(
746 marginsModule->topLE));
747 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
748 marginsModule->bottomLE));
749 marginsModule->innerLE->setValidator(unsignedLengthValidator(
750 marginsModule->innerLE));
751 marginsModule->outerLE->setValidator(unsignedLengthValidator(
752 marginsModule->outerLE));
753 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
754 marginsModule->headsepLE));
755 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
756 marginsModule->headheightLE));
757 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
758 marginsModule->footskipLE));
759 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
760 marginsModule->columnsepLE));
762 bc().addCheckedLineEdit(marginsModule->topLE,
763 marginsModule->topL);
764 bc().addCheckedLineEdit(marginsModule->bottomLE,
765 marginsModule->bottomL);
766 bc().addCheckedLineEdit(marginsModule->innerLE,
767 marginsModule->innerL);
768 bc().addCheckedLineEdit(marginsModule->outerLE,
769 marginsModule->outerL);
770 bc().addCheckedLineEdit(marginsModule->headsepLE,
771 marginsModule->headsepL);
772 bc().addCheckedLineEdit(marginsModule->headheightLE,
773 marginsModule->headheightL);
774 bc().addCheckedLineEdit(marginsModule->footskipLE,
775 marginsModule->footskipL);
776 bc().addCheckedLineEdit(marginsModule->columnsepLE,
777 marginsModule->columnsepL);
780 langModule = new UiWidget<Ui::LanguageUi>;
782 connect(langModule->languageCO, SIGNAL(activated(int)),
783 this, SLOT(change_adaptor()));
784 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
785 this, SLOT(change_adaptor()));
786 connect(langModule->otherencodingRB, SIGNAL(clicked()),
787 this, SLOT(change_adaptor()));
788 connect(langModule->encodingCO, SIGNAL(activated(int)),
789 this, SLOT(change_adaptor()));
790 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
791 this, SLOT(change_adaptor()));
794 QList<LanguagePair>::const_iterator lit = langs.begin();
795 QList<LanguagePair>::const_iterator lend = langs.end();
796 for (; lit != lend; ++lit)
797 langModule->languageCO->addItem(lit->first);
799 // Always put the default encoding in the first position.
800 // It is special because the displayed text is translated.
801 langModule->encodingCO->addItem(qt_("LaTeX default"));
802 Encodings::const_iterator it = encodings.begin();
803 Encodings::const_iterator const end = encodings.end();
804 for (; it != end; ++it)
805 langModule->encodingCO->addItem(toqstr(it->latexName()));
807 langModule->quoteStyleCO->addItem(qt_("``text''"));
808 langModule->quoteStyleCO->addItem(qt_("''text''"));
809 langModule->quoteStyleCO->addItem(qt_(",,text``"));
810 langModule->quoteStyleCO->addItem(qt_(",,text''"));
811 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
812 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
815 numberingModule = new UiWidget<Ui::NumberingUi>;
817 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
818 this, SLOT(change_adaptor()));
819 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
820 this, SLOT(change_adaptor()));
821 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
822 this, SLOT(updateNumbering()));
823 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
824 this, SLOT(updateNumbering()));
825 numberingModule->tocTW->setColumnCount(3);
826 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
827 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
828 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
831 biblioModule = new UiWidget<Ui::BiblioUi>;
832 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
833 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
834 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
835 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
837 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
838 this, SLOT(change_adaptor()));
839 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
840 this, SLOT(change_adaptor()));
841 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
842 this, SLOT(change_adaptor()));
843 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
844 this, SLOT(change_adaptor()));
845 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
846 this, SLOT(change_adaptor()));
848 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
849 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
850 biblioModule->citeStyleCO->setCurrentIndex(0);
853 mathsModule = new UiWidget<Ui::MathsUi>;
854 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
855 mathsModule->amsCB, SLOT(setDisabled(bool)));
856 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
857 mathsModule->esintCB, SLOT(setDisabled(bool)));
859 connect(mathsModule->amsCB, SIGNAL(clicked()),
860 this, SLOT(change_adaptor()));
861 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
862 this, SLOT(change_adaptor()));
863 connect(mathsModule->esintCB, SIGNAL(clicked()),
864 this, SLOT(change_adaptor()));
865 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
866 this, SLOT(change_adaptor()));
868 latexModule = new UiWidget<Ui::LaTeXUi>;
870 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
871 this, SLOT(change_adaptor()));
872 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
873 this, SLOT(change_adaptor()));
874 connect(latexModule->classCO, SIGNAL(activated(int)),
875 this, SLOT(classChanged()));
876 connect(latexModule->classCO, SIGNAL(activated(int)),
877 this, SLOT(change_adaptor()));
878 connect(latexModule->layoutPB, SIGNAL(clicked()),
879 this, SLOT(browseLayout()));
882 new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
883 latexModule->addPB, latexModule->deletePB,
884 latexModule->upPB, latexModule->downPB,
885 availableModel(), selectedModel());
886 connect(selectionManager, SIGNAL(updateHook()),
887 this, SLOT(updateModuleInfo()));
888 connect(selectionManager, SIGNAL(updateHook()),
889 this, SLOT(change_adaptor()));
891 // postscript drivers
892 for (int n = 0; tex_graphics[n][0]; ++n) {
893 QString enc = qt_(tex_graphics_gui[n]);
894 latexModule->psdriverCO->addItem(enc);
897 latexModule->classCO->setModel(&classes_model_);
898 LayoutFileList const & bcl = LayoutFileList::get();
899 vector<LayoutFileIndex> classList = bcl.classList();
900 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
902 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
903 vector<LayoutFileIndex>::const_iterator cen = classList.end();
904 for (int i = 0; cit != cen; ++cit, ++i) {
905 LayoutFile const & tc = bcl[*cit];
906 docstring item = (tc.isTeXClassAvailable()) ?
907 from_utf8(tc.description()) :
908 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
909 classes_model_.insertRow(i, toqstr(item), *cit);
913 branchesModule = new GuiBranches;
914 connect(branchesModule, SIGNAL(changed()),
915 this, SLOT(change_adaptor()));
918 preambleModule = new PreambleModule;
919 connect(preambleModule, SIGNAL(changed()),
920 this, SLOT(change_adaptor()));
923 bulletsModule = new BulletsModule;
924 connect(bulletsModule, SIGNAL(changed()),
925 this, SLOT(change_adaptor()));
928 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
930 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
931 this, SLOT(change_adaptor()));
932 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
933 this, SLOT(change_adaptor()));
934 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
935 this, SLOT(change_adaptor()));
936 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
937 this, SLOT(change_adaptor()));
938 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
939 this, SLOT(change_adaptor()));
940 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
941 this, SLOT(change_adaptor()));
942 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
943 this, SLOT(change_adaptor()));
944 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
945 this, SLOT(change_adaptor()));
946 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
947 this, SLOT(change_adaptor()));
948 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
949 this, SLOT(change_adaptor()));
950 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
951 this, SLOT(change_adaptor()));
952 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
953 this, SLOT(change_adaptor()));
954 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
955 this, SLOT(change_adaptor()));
956 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
957 this, SLOT(change_adaptor()));
958 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
959 this, SLOT(change_adaptor()));
960 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
961 this, SLOT(change_adaptor()));
962 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
963 this, SLOT(change_adaptor()));
966 floatModule = new FloatPlacement;
967 connect(floatModule, SIGNAL(changed()),
968 this, SLOT(change_adaptor()));
970 docPS->addPanel(latexModule, qt_("Document Class"));
971 docPS->addPanel(fontModule, qt_("Fonts"));
972 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
973 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
974 docPS->addPanel(marginsModule, qt_("Page Margins"));
975 docPS->addPanel(langModule, qt_("Language"));
976 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
977 docPS->addPanel(biblioModule, qt_("Bibliography"));
978 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
979 docPS->addPanel(mathsModule, qt_("Math Options"));
980 docPS->addPanel(floatModule, qt_("Float Placement"));
981 docPS->addPanel(bulletsModule, qt_("Bullets"));
982 docPS->addPanel(branchesModule, qt_("Branches"));
983 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
984 docPS->setCurrentPanel(qt_("Document Class"));
985 // FIXME: hack to work around resizing bug in Qt >= 4.2
986 // bug verified with Qt 4.2.{0-3} (JSpitzm)
987 #if QT_VERSION >= 0x040200
988 docPS->updateGeometry();
993 void GuiDocument::showPreamble()
995 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
999 void GuiDocument::saveDefaultClicked()
1005 void GuiDocument::useDefaultsClicked()
1011 void GuiDocument::change_adaptor()
1017 docstring GuiDocument::validate_listings_params()
1019 // use a cache here to avoid repeated validation
1020 // of the same parameters
1021 static string param_cache = string();
1022 static docstring msg_cache = docstring();
1024 if (textLayoutModule->bypassCB->isChecked())
1027 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1028 if (params != param_cache) {
1029 param_cache = params;
1030 msg_cache = InsetListingsParams(params).validate();
1036 void GuiDocument::set_listings_msg()
1038 static bool isOK = true;
1039 docstring msg = validate_listings_params();
1044 // listingsTB->setTextColor("black");
1045 textLayoutModule->listingsTB->setPlainText(
1046 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
1049 // listingsTB->setTextColor("red");
1050 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
1055 void GuiDocument::setLSpacing(int item)
1057 textLayoutModule->lspacingLE->setEnabled(item == 3);
1061 void GuiDocument::setSkip(int item)
1063 bool const enable = (item == 3);
1064 textLayoutModule->skipLE->setEnabled(enable);
1065 textLayoutModule->skipLengthCO->setEnabled(enable);
1069 void GuiDocument::enableSkip(bool skip)
1071 textLayoutModule->skipCO->setEnabled(skip);
1072 textLayoutModule->skipLE->setEnabled(skip);
1073 textLayoutModule->skipLengthCO->setEnabled(skip);
1075 setSkip(textLayoutModule->skipCO->currentIndex());
1078 void GuiDocument::portraitChanged()
1080 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1083 void GuiDocument::setMargins(bool custom)
1085 marginsModule->marginCB->setChecked(custom);
1086 setCustomMargins(custom);
1090 void GuiDocument::setCustomPapersize(int papersize)
1092 bool const custom = (papersize == 1);
1094 pageLayoutModule->paperwidthL->setEnabled(custom);
1095 pageLayoutModule->paperwidthLE->setEnabled(custom);
1096 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1097 pageLayoutModule->paperheightL->setEnabled(custom);
1098 pageLayoutModule->paperheightLE->setEnabled(custom);
1099 pageLayoutModule->paperheightLE->setFocus();
1100 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1104 void GuiDocument::setColSep()
1106 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1110 void GuiDocument::setCustomMargins(bool custom)
1112 marginsModule->topL->setEnabled(!custom);
1113 marginsModule->topLE->setEnabled(!custom);
1114 marginsModule->topUnit->setEnabled(!custom);
1116 marginsModule->bottomL->setEnabled(!custom);
1117 marginsModule->bottomLE->setEnabled(!custom);
1118 marginsModule->bottomUnit->setEnabled(!custom);
1120 marginsModule->innerL->setEnabled(!custom);
1121 marginsModule->innerLE->setEnabled(!custom);
1122 marginsModule->innerUnit->setEnabled(!custom);
1124 marginsModule->outerL->setEnabled(!custom);
1125 marginsModule->outerLE->setEnabled(!custom);
1126 marginsModule->outerUnit->setEnabled(!custom);
1128 marginsModule->headheightL->setEnabled(!custom);
1129 marginsModule->headheightLE->setEnabled(!custom);
1130 marginsModule->headheightUnit->setEnabled(!custom);
1132 marginsModule->headsepL->setEnabled(!custom);
1133 marginsModule->headsepLE->setEnabled(!custom);
1134 marginsModule->headsepUnit->setEnabled(!custom);
1136 marginsModule->footskipL->setEnabled(!custom);
1137 marginsModule->footskipLE->setEnabled(!custom);
1138 marginsModule->footskipUnit->setEnabled(!custom);
1140 bool const enableColSep = !custom &&
1141 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1142 marginsModule->columnsepL->setEnabled(enableColSep);
1143 marginsModule->columnsepLE->setEnabled(enableColSep);
1144 marginsModule->columnsepUnit->setEnabled(enableColSep);
1148 void GuiDocument::updateFontsize(string const & items, string const & sel)
1150 fontModule->fontsizeCO->clear();
1151 fontModule->fontsizeCO->addItem(qt_("Default"));
1153 for (int n = 0; !token(items,'|',n).empty(); ++n)
1154 fontModule->fontsizeCO->
1155 addItem(toqstr(token(items,'|',n)));
1157 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1158 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1159 fontModule->fontsizeCO->setCurrentIndex(n);
1166 void GuiDocument::romanChanged(int item)
1168 string const font = tex_fonts_roman[item];
1169 fontModule->fontScCB->setEnabled(providesSC(font));
1170 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1174 void GuiDocument::sansChanged(int item)
1176 string const font = tex_fonts_sans[item];
1177 bool scaleable = providesScale(font);
1178 fontModule->scaleSansSB->setEnabled(scaleable);
1179 fontModule->scaleSansLA->setEnabled(scaleable);
1183 void GuiDocument::ttChanged(int item)
1185 string const font = tex_fonts_monospaced[item];
1186 bool scaleable = providesScale(font);
1187 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1188 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1192 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1195 pageLayoutModule->pagestyleCO->clear();
1196 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1198 for (int n = 0; !token(items,'|',n).empty(); ++n) {
1199 string style = token(items, '|', n);
1200 docstring style_gui = _(style);
1201 pagestyles.push_back(pair<string, docstring>(style, style_gui));
1202 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
1205 if (sel == "default") {
1206 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1212 for (size_t i = 0; i < pagestyles.size(); ++i)
1213 if (pagestyles[i].first == sel)
1214 nn = pageLayoutModule->pagestyleCO->findText(
1215 toqstr(pagestyles[i].second));
1218 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1222 void GuiDocument::browseLayout()
1224 QString const label1 = qt_("Layouts|#o#O");
1225 QString const dir1 = toqstr(lyxrc.document_path);
1226 FileFilterList const filter(_("LyX Layout (*.layout)"));
1227 QString file = browseRelFile(QString(), bufferFilepath(),
1228 qt_("Local layout file"), filter, false,
1231 if (!suffixIs(fromqstr(file), ".layout"))
1234 FileName layoutFile = makeAbsPath(fromqstr(file),
1235 fromqstr(bufferFilepath()));
1237 // load the layout file
1238 LayoutFileList & bcl = LayoutFileList::get();
1239 string classname = layoutFile.onlyFileName();
1240 LayoutFileIndex name = bcl.addLayoutFile(
1241 classname.substr(0, classname.size() - 7),
1242 layoutFile.onlyPath().absFilename(),
1243 LayoutFileList::Local);
1246 Alert::error(_("Error"),
1247 _("Unable to read local layout file."));
1251 // do not trigger classChanged if there is no change.
1252 if (latexModule->classCO->currentText() == toqstr(name))
1256 int idx = latexModule->classCO->findText(toqstr(name));
1258 classes_model_.insertRow(0, toqstr(name), name);
1259 latexModule->classCO->setCurrentIndex(0);
1261 latexModule->classCO->setCurrentIndex(idx);
1266 void GuiDocument::classChanged()
1268 int idx = latexModule->classCO->currentIndex();
1271 string const classname = classes_model_.getIDString(idx);
1272 // check if this is a local layout file
1273 if (prefixIs(classname, LayoutFileList::localPrefix)) {
1274 int const ret = Alert::prompt(_("Local layout file"),
1275 _("The layout file you have selected is a local layout\n"
1276 "file, not one in the system or user directory. Your\n"
1277 "document may not work with this layout if you do not\n"
1278 "keep the layout file in the same directory."),
1279 1, 1, _("&Set Layout"), _("&Cancel"));
1281 // try to reset the layout combo
1282 setLayoutComboByIDString(bp_.baseClassID());
1285 } else if (prefixIs(classname, LayoutFileList::embeddedPrefix)) {
1286 int const ret = Alert::prompt(_("Embedded layout"),
1287 _("The layout file you have selected is an embedded layout that\n"
1288 "is embedded to a buffer. You cannot make use of it unless\n"
1289 "it is already embedded to this buffer.\n"),
1290 1, 1, _("&Set Layout"), _("&Cancel"));
1292 setLayoutComboByIDString(bp_.baseClassID());
1296 // FIXME Note that by doing things this way, we load the TextClass
1297 // as soon as it is selected. So, if you use the scroll wheel when
1298 // sitting on the combo box, we'll load a lot of TextClass objects
1299 // very quickly. This could be changed.
1300 if (!bp_.setBaseClass(classname)) {
1301 Alert::error(_("Error"), _("Unable to set document class."));
1304 if (lyxrc.auto_reset_options) {
1305 if (applyPB->isEnabled()) {
1306 int const ret = Alert::prompt(_("Unapplied changes"),
1307 _("Some changes in the dialog were not yet applied.\n"
1308 "If you do not apply now, they will be lost after this action."),
1309 1, 1, _("&Apply"), _("&Dismiss"));
1313 bp_.useClassDefaults();
1320 // This is an insanely complicated attempt to make this sort of thing
1321 // work with RTL languages.
1322 docstring formatStrVec(vector<string> const & v, docstring const & s)
1324 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1325 int const vSize = v.size();
1328 else if (v.size() == 1)
1329 return from_ascii(v[0]);
1330 else if (v.size() == 2) {
1331 docstring retval = _("%1$s and %2$s");
1332 retval = subst(retval, _("and"), s);
1333 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1335 //The idea here is to format all but the last two items...
1336 docstring t2 = _("%1$s, %2$s");
1337 docstring retval = from_ascii(v[0]);
1338 for (int i = 1; i < vSize - 2; ++i)
1339 retval = bformat(t2, retval, from_ascii(v[i]));
1340 //...and then to plug them, and the last two, into this schema
1341 docstring t = _("%1$s, %2$s, and %3$s");
1342 t = subst(t, _("and"), s);
1343 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1346 vector<string> idsToNames(vector<string> const & idList)
1348 vector<string> retval;
1349 vector<string>::const_iterator it = idList.begin();
1350 vector<string>::const_iterator end = idList.end();
1351 for (; it != end; ++it) {
1352 LyXModule const * const mod = moduleList[*it];
1354 retval.push_back(*it + " (Unavailable)");
1356 retval.push_back(mod->getName());
1363 void GuiDocument::updateModuleInfo()
1365 selectionManager->update();
1367 //Module description
1368 bool const focusOnSelected = selectionManager->selectedFocused();
1369 QListView const * const lv =
1370 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1371 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1372 latexModule->infoML->document()->clear();
1375 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1376 GuiIdListModel const & idModel =
1377 focusOnSelected ? modules_sel_model_ : modules_av_model_;
1378 string const modName = idModel.getIDString(idx.row());
1379 docstring desc = getModuleDescription(modName);
1381 vector<string> pkgList = getPackageList(modName);
1382 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1383 if (!pkgdesc.empty()) {
1386 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1389 pkgList = getRequiredList(modName);
1390 if (!pkgList.empty()) {
1391 vector<string> const reqDescs = idsToNames(pkgList);
1392 pkgdesc = formatStrVec(reqDescs, _("or"));
1395 desc += bformat(_("Module required: %1$s."), pkgdesc);
1398 pkgList = getExcludedList(modName);
1399 if (!pkgList.empty()) {
1400 vector<string> const reqDescs = idsToNames(pkgList);
1401 pkgdesc = formatStrVec(reqDescs, _( "and"));
1404 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1407 if (!isModuleAvailable(modName)) {
1410 desc += _("WARNING: Some packages are unavailable!");
1413 latexModule->infoML->document()->setPlainText(toqstr(desc));
1417 void GuiDocument::updateNumbering()
1419 DocumentClass const & tclass = bp_.documentClass();
1421 numberingModule->tocTW->setUpdatesEnabled(false);
1422 numberingModule->tocTW->clear();
1424 int const depth = numberingModule->depthSL->value();
1425 int const toc = numberingModule->tocSL->value();
1426 QString const no = qt_("No");
1427 QString const yes = qt_("Yes");
1428 QTreeWidgetItem * item = 0;
1430 DocumentClass::const_iterator lit = tclass.begin();
1431 DocumentClass::const_iterator len = tclass.end();
1432 for (; lit != len; ++lit) {
1433 int const toclevel = lit->toclevel;
1434 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1435 item = new QTreeWidgetItem(numberingModule->tocTW);
1436 item->setText(0, toqstr(translateIfPossible(lit->name())));
1437 item->setText(1, (toclevel <= depth) ? yes : no);
1438 item->setText(2, (toclevel <= toc) ? yes : no);
1442 numberingModule->tocTW->setUpdatesEnabled(true);
1443 numberingModule->tocTW->update();
1447 void GuiDocument::apply(BufferParams & params)
1450 preambleModule->apply(params);
1453 params.setCiteEngine(biblio::ENGINE_BASIC);
1455 if (biblioModule->citeNatbibRB->isChecked()) {
1456 bool const use_numerical_citations =
1457 biblioModule->citeStyleCO->currentIndex();
1458 if (use_numerical_citations)
1459 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1461 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1463 } else if (biblioModule->citeJurabibRB->isChecked())
1464 params.setCiteEngine(biblio::ENGINE_JURABIB);
1466 params.use_bibtopic =
1467 biblioModule->bibtopicCB->isChecked();
1469 // language & quotes
1470 if (langModule->defaultencodingRB->isChecked()) {
1471 params.inputenc = "auto";
1473 int i = langModule->encodingCO->currentIndex();
1475 params.inputenc = "default";
1478 fromqstr(langModule->encodingCO->currentText());
1481 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
1482 switch (langModule->quoteStyleCO->currentIndex()) {
1484 lga = InsetQuotes::EnglishQuotes;
1487 lga = InsetQuotes::SwedishQuotes;
1490 lga = InsetQuotes::GermanQuotes;
1493 lga = InsetQuotes::PolishQuotes;
1496 lga = InsetQuotes::FrenchQuotes;
1499 lga = InsetQuotes::DanishQuotes;
1502 params.quotes_language = lga;
1504 int const pos = langModule->languageCO->currentIndex();
1505 params.language = lyx::languages.getLanguage(fromqstr(lang_[pos]));
1508 if (params.documentClass().hasTocLevels()) {
1509 params.tocdepth = numberingModule->tocSL->value();
1510 params.secnumdepth = numberingModule->depthSL->value();
1514 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1515 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1516 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1517 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1520 params.graphicsDriver =
1521 tex_graphics[latexModule->psdriverCO->currentIndex()];
1524 int idx = latexModule->classCO->currentIndex();
1526 string const classname = classes_model_.getIDString(idx);
1527 params.setBaseClass(classname);
1531 params.clearLayoutModules();
1532 int const srows = modules_sel_model_.rowCount();
1533 vector<string> selModList;
1534 for (int i = 0; i < srows; ++i)
1535 params.addLayoutModule(modules_sel_model_.getIDString(i));
1537 if (mathsModule->amsautoCB->isChecked()) {
1538 params.use_amsmath = BufferParams::package_auto;
1540 if (mathsModule->amsCB->isChecked())
1541 params.use_amsmath = BufferParams::package_on;
1543 params.use_amsmath = BufferParams::package_off;
1546 if (mathsModule->esintautoCB->isChecked())
1547 params.use_esint = BufferParams::package_auto;
1549 if (mathsModule->esintCB->isChecked())
1550 params.use_esint = BufferParams::package_on;
1552 params.use_esint = BufferParams::package_off;
1555 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1556 params.pagestyle = "default";
1558 docstring style_gui =
1559 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1560 for (size_t i = 0; i < pagestyles.size(); ++i)
1561 if (pagestyles[i].second == style_gui)
1562 params.pagestyle = pagestyles[i].first;
1565 switch (textLayoutModule->lspacingCO->currentIndex()) {
1567 params.spacing().set(Spacing::Single);
1570 params.spacing().set(Spacing::Onehalf);
1573 params.spacing().set(Spacing::Double);
1576 params.spacing().set(Spacing::Other,
1577 fromqstr(textLayoutModule->lspacingLE->text()));
1581 if (textLayoutModule->twoColumnCB->isChecked())
1586 // text should have passed validation
1587 params.listings_params =
1588 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1590 if (textLayoutModule->indentRB->isChecked())
1591 params.paragraph_separation = BufferParams::ParagraphIndentSeparation;
1593 params.paragraph_separation = BufferParams::ParagraphSkipSeparation;
1595 switch (textLayoutModule->skipCO->currentIndex()) {
1597 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1600 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1603 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1608 widgetsToLength(textLayoutModule->skipLE,
1609 textLayoutModule->skipLengthCO)
1611 params.setDefSkip(vs);
1615 // DocumentDefskipCB assures that this never happens
1616 // so Assert then !!! - jbl
1617 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1622 fromqstr(latexModule->optionsLE->text());
1624 params.float_placement = floatModule->get();
1628 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1631 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1633 params.fontsTypewriter =
1634 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1636 params.fontsSansScale = fontModule->scaleSansSB->value();
1638 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1640 params.fontsSC = fontModule->fontScCB->isChecked();
1642 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1644 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1645 fontModule->fontsDefaultCO->currentIndex()];
1647 if (fontModule->fontsizeCO->currentIndex() == 0)
1648 params.fontsize = "default";
1651 fromqstr(fontModule->fontsizeCO->currentText());
1654 params.papersize = PAPER_SIZE(
1655 pageLayoutModule->papersizeCO->currentIndex());
1657 // custom, A3, B3 and B4 paper sizes need geometry
1658 int psize = pageLayoutModule->papersizeCO->currentIndex();
1659 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1661 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1662 pageLayoutModule->paperwidthUnitCO);
1664 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1665 pageLayoutModule->paperheightUnitCO);
1667 if (pageLayoutModule->facingPagesCB->isChecked())
1668 params.sides = TwoSides;
1670 params.sides = OneSide;
1672 if (pageLayoutModule->landscapeRB->isChecked())
1673 params.orientation = ORIENTATION_LANDSCAPE;
1675 params.orientation = ORIENTATION_PORTRAIT;
1678 params.use_geometry = !marginsModule->marginCB->isChecked()
1681 Ui::MarginsUi const * m = marginsModule;
1683 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1684 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1685 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1686 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1687 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1688 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1689 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1690 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1692 branchesModule->apply(params);
1695 PDFOptions & pdf = params.pdfoptions();
1696 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1697 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1698 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1699 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1700 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1702 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1703 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1704 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1705 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1707 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1708 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1709 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1710 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1711 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1712 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1713 if (pdfSupportModule->fullscreenCB->isChecked())
1714 pdf.pagemode = pdf.pagemode_fullscreen;
1716 pdf.pagemode.clear();
1717 pdf.quoted_options = pdf.quoted_options_check(
1718 fromqstr(pdfSupportModule->optionsLE->text()));
1722 static int findPos(QStringList const & vec, QString const & val)
1724 for (int i = 0; i != vec.size(); ++i)
1731 void GuiDocument::updateParams()
1737 void GuiDocument::updateParams(BufferParams const & params)
1739 // set the default unit
1740 Length::UNIT defaultUnit = Length::CM;
1741 switch (lyxrc.default_papersize) {
1742 case PAPER_DEFAULT: break;
1744 case PAPER_USLETTER:
1746 case PAPER_USEXECUTIVE:
1747 defaultUnit = Length::IN;
1756 defaultUnit = Length::CM;
1763 preambleModule->update(params, id());
1766 biblioModule->citeDefaultRB->setChecked(
1767 params.citeEngine() == biblio::ENGINE_BASIC);
1769 biblioModule->citeNatbibRB->setChecked(
1770 params.citeEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1771 params.citeEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1773 biblioModule->citeStyleCO->setCurrentIndex(
1774 params.citeEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1776 biblioModule->citeJurabibRB->setChecked(
1777 params.citeEngine() == biblio::ENGINE_JURABIB);
1779 biblioModule->bibtopicCB->setChecked(
1780 params.use_bibtopic);
1782 // language & quotes
1783 int const pos = findPos(lang_, toqstr(params.language->lang()));
1784 langModule->languageCO->setCurrentIndex(pos);
1786 langModule->quoteStyleCO->setCurrentIndex(
1787 params.quotes_language);
1789 bool default_enc = true;
1790 if (params.inputenc != "auto") {
1791 default_enc = false;
1792 if (params.inputenc == "default") {
1793 langModule->encodingCO->setCurrentIndex(0);
1795 int const i = langModule->encodingCO->findText(
1796 toqstr(params.inputenc));
1798 langModule->encodingCO->setCurrentIndex(i);
1800 // unknown encoding. Set to default.
1804 langModule->defaultencodingRB->setChecked(default_enc);
1805 langModule->otherencodingRB->setChecked(!default_enc);
1808 int const min_toclevel = documentClass().min_toclevel();
1809 int const max_toclevel = documentClass().max_toclevel();
1810 if (documentClass().hasTocLevels()) {
1811 numberingModule->setEnabled(true);
1812 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1813 numberingModule->depthSL->setMaximum(max_toclevel);
1814 numberingModule->depthSL->setValue(params.secnumdepth);
1815 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1816 numberingModule->tocSL->setMaximum(max_toclevel);
1817 numberingModule->tocSL->setValue(params.tocdepth);
1820 numberingModule->setEnabled(false);
1821 numberingModule->tocTW->clear();
1825 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1826 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1827 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1828 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1829 bulletsModule->init();
1832 int nitem = findToken(tex_graphics, params.graphicsDriver);
1834 latexModule->psdriverCO->setCurrentIndex(nitem);
1837 mathsModule->amsCB->setChecked(
1838 params.use_amsmath == BufferParams::package_on);
1839 mathsModule->amsautoCB->setChecked(
1840 params.use_amsmath == BufferParams::package_auto);
1842 mathsModule->esintCB->setChecked(
1843 params.use_esint == BufferParams::package_on);
1844 mathsModule->esintautoCB->setChecked(
1845 params.use_esint == BufferParams::package_auto);
1847 switch (params.spacing().getSpace()) {
1848 case Spacing::Other: nitem = 3; break;
1849 case Spacing::Double: nitem = 2; break;
1850 case Spacing::Onehalf: nitem = 1; break;
1851 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1855 string const & layoutID = params.baseClassID();
1856 setLayoutComboByIDString(layoutID);
1858 updatePagestyle(documentClass().opt_pagestyle(),
1861 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1862 if (params.spacing().getSpace() == Spacing::Other) {
1863 textLayoutModule->lspacingLE->setText(
1864 toqstr(params.spacing().getValueAsString()));
1868 if (params.paragraph_separation == BufferParams::ParagraphIndentSeparation)
1869 textLayoutModule->indentRB->setChecked(true);
1871 textLayoutModule->skipRB->setChecked(true);
1874 switch (params.getDefSkip().kind()) {
1875 case VSpace::SMALLSKIP:
1878 case VSpace::MEDSKIP:
1881 case VSpace::BIGSKIP:
1884 case VSpace::LENGTH:
1887 string const length = params.getDefSkip().asLyXCommand();
1888 lengthToWidgets(textLayoutModule->skipLE,
1889 textLayoutModule->skipLengthCO,
1890 length, defaultUnit);
1897 textLayoutModule->skipCO->setCurrentIndex(skip);
1900 textLayoutModule->twoColumnCB->setChecked(
1901 params.columns == 2);
1903 // break listings_params to multiple lines
1905 InsetListingsParams(params.listings_params).separatedParams();
1906 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1908 if (!params.options.empty()) {
1909 latexModule->optionsLE->setText(
1910 toqstr(params.options));
1912 latexModule->optionsLE->setText(QString());
1915 floatModule->set(params.float_placement);
1918 updateFontsize(documentClass().opt_fontsize(),
1921 int n = findToken(tex_fonts_roman, params.fontsRoman);
1923 fontModule->fontsRomanCO->setCurrentIndex(n);
1927 n = findToken(tex_fonts_sans, params.fontsSans);
1929 fontModule->fontsSansCO->setCurrentIndex(n);
1933 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1935 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1939 fontModule->fontScCB->setChecked(params.fontsSC);
1940 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1941 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1942 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1943 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1945 fontModule->fontsDefaultCO->setCurrentIndex(n);
1948 int const psize = params.papersize;
1949 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1950 setCustomPapersize(psize);
1952 bool const landscape =
1953 params.orientation == ORIENTATION_LANDSCAPE;
1954 pageLayoutModule->landscapeRB->setChecked(landscape);
1955 pageLayoutModule->portraitRB->setChecked(!landscape);
1957 pageLayoutModule->facingPagesCB->setChecked(
1958 params.sides == TwoSides);
1961 lengthToWidgets(pageLayoutModule->paperwidthLE,
1962 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1964 lengthToWidgets(pageLayoutModule->paperheightLE,
1965 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1968 Ui::MarginsUi * m = marginsModule;
1970 setMargins(!params.use_geometry);
1972 lengthToWidgets(m->topLE, m->topUnit,
1973 params.topmargin, defaultUnit);
1975 lengthToWidgets(m->bottomLE, m->bottomUnit,
1976 params.bottommargin, defaultUnit);
1978 lengthToWidgets(m->innerLE, m->innerUnit,
1979 params.leftmargin, defaultUnit);
1981 lengthToWidgets(m->outerLE, m->outerUnit,
1982 params.rightmargin, defaultUnit);
1984 lengthToWidgets(m->headheightLE, m->headheightUnit,
1985 params.headheight, defaultUnit);
1987 lengthToWidgets(m->headsepLE, m->headsepUnit,
1988 params.headsep, defaultUnit);
1990 lengthToWidgets(m->footskipLE, m->footskipUnit,
1991 params.footskip, defaultUnit);
1993 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
1994 params.columnsep, defaultUnit);
1996 branchesModule->update(params);
1999 PDFOptions const & pdf = params.pdfoptions();
2000 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2001 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2002 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2003 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2004 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2006 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2007 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2008 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2010 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2012 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2013 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2014 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2015 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2016 pdfSupportModule->backrefCB->setChecked(pdf.backref);
2017 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
2018 pdfSupportModule->fullscreenCB->setChecked
2019 (pdf.pagemode == pdf.pagemode_fullscreen);
2021 pdfSupportModule->optionsLE->setText(
2022 toqstr(pdf.quoted_options));
2026 void GuiDocument::applyView()
2032 void GuiDocument::saveDocDefault()
2034 // we have to apply the params first
2040 void GuiDocument::updateAvailableModules()
2042 modules_av_model_.clear();
2043 vector<modInfoStruct> const & modInfoList = getModuleInfo();
2044 int const mSize = modInfoList.size();
2045 for (int i = 0; i != mSize; ++i) {
2046 modInfoStruct const & modInfo = modInfoList[i];
2047 modules_av_model_.insertRow(i, modInfo.name, modInfo.id,
2048 modInfo.description);
2053 void GuiDocument::updateSelectedModules()
2055 // and selected ones, too
2056 modules_sel_model_.clear();
2057 vector<modInfoStruct> const selModList = getSelectedModules();
2058 int const sSize = selModList.size();
2059 for (int i = 0; i != sSize; ++i) {
2060 modInfoStruct const & modInfo = selModList[i];
2061 modules_sel_model_.insertRow(i, modInfo.name, modInfo.id,
2062 modInfo.description);
2067 void GuiDocument::updateContents()
2069 if (id() == current_id_)
2072 updateAvailableModules();
2073 updateSelectedModules();
2075 //FIXME It'd be nice to make sure here that the selected
2076 //modules are consistent: That required modules are actually
2077 //selected, and that we don't have conflicts. If so, we could
2078 //at least pop up a warning.
2084 void GuiDocument::forceUpdate()
2086 // reset to force dialog update
2092 void GuiDocument::useClassDefaults()
2094 if (applyPB->isEnabled()) {
2095 int const ret = Alert::prompt(_("Unapplied changes"),
2096 _("Some changes in the dialog were not yet applied.\n"
2097 "If you do not apply now, they will be lost after this action."),
2098 1, 1, _("&Apply"), _("&Dismiss"));
2103 int idx = latexModule->classCO->currentIndex();
2104 string const classname = classes_model_.getIDString(idx);
2105 if (!bp_.setBaseClass(classname)) {
2106 Alert::error(_("Error"), _("Unable to set document class."));
2109 bp_.useClassDefaults();
2114 void GuiDocument::setLayoutComboByIDString(std::string const & idString)
2116 int idx = classes_model_.findIDString(idString);
2118 Alert::warning(_("Can't set layout!"),
2119 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2121 latexModule->classCO->setCurrentIndex(idx);
2125 bool GuiDocument::isValid()
2127 return validate_listings_params().empty()
2128 && (textLayoutModule->skipCO->currentIndex() != 3
2129 || !textLayoutModule->skipLE->text().isEmpty());
2133 char const * const GuiDocument::fontfamilies[5] = {
2134 "default", "rmdefault", "sfdefault", "ttdefault", ""
2138 char const * GuiDocument::fontfamilies_gui[5] = {
2139 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2143 bool GuiDocument::initialiseParams(string const &)
2145 bp_ = buffer().params();
2151 void GuiDocument::clearParams()
2153 bp_ = BufferParams();
2157 BufferId GuiDocument::id() const
2163 vector<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2165 return moduleNames_;
2169 vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2171 vector<string> const & mods = params().getModules();
2172 vector<string>::const_iterator it = mods.begin();
2173 vector<string>::const_iterator end = mods.end();
2174 vector<modInfoStruct> mInfo;
2175 for (; it != end; ++it) {
2178 LyXModule * mod = moduleList[*it];
2180 m.name = qt_(mod->getName());
2182 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
2189 DocumentClass const & GuiDocument::documentClass() const
2191 return bp_.documentClass();
2195 static void dispatch_bufferparams(Dialog const & dialog,
2196 BufferParams const & bp, FuncCode lfun)
2199 ss << "\\begin_header\n";
2201 ss << "\\end_header\n";
2202 dialog.dispatch(FuncRequest(lfun, ss.str()));
2206 void GuiDocument::dispatchParams()
2208 // This must come first so that a language change is correctly noticed
2211 // Apply the BufferParams. Note that this will set the base class
2212 // and then update the buffer's layout.
2213 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2215 // Generate the colours requested by each new branch.
2216 BranchList & branchlist = params().branchlist();
2217 if (!branchlist.empty()) {
2218 BranchList::const_iterator it = branchlist.begin();
2219 BranchList::const_iterator const end = branchlist.end();
2220 for (; it != end; ++it) {
2221 docstring const & current_branch = it->getBranch();
2222 Branch const * branch = branchlist.find(current_branch);
2223 string const x11hexname = X11hexname(branch->getColor());
2224 // display the new color
2225 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2226 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2229 // Open insets of selected branches, close deselected ones
2230 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2233 // FIXME: If we used an LFUN, we would not need those two lines:
2234 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
2238 void GuiDocument::setLanguage() const
2240 Language const * const newL = bp_.language;
2241 if (buffer().params().language == newL)
2244 string const & lang_name = newL->lang();
2245 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2249 void GuiDocument::saveAsDefault() const
2251 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2255 bool GuiDocument::isFontAvailable(string const & font) const
2257 if (font == "default" || font == "cmr"
2258 || font == "cmss" || font == "cmtt")
2259 // these are standard
2261 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2262 return LaTeXFeatures::isAvailable("lmodern");
2263 if (font == "times" || font == "palatino"
2264 || font == "helvet" || font == "courier")
2265 return LaTeXFeatures::isAvailable("psnfss");
2266 if (font == "cmbr" || font == "cmtl")
2267 return LaTeXFeatures::isAvailable("cmbright");
2268 if (font == "utopia")
2269 return LaTeXFeatures::isAvailable("utopia")
2270 || LaTeXFeatures::isAvailable("fourier");
2271 if (font == "beraserif" || font == "berasans"
2272 || font == "beramono")
2273 return LaTeXFeatures::isAvailable("bera");
2274 return LaTeXFeatures::isAvailable(font);
2278 bool GuiDocument::providesOSF(string const & font) const
2281 return isFontAvailable("eco");
2282 if (font == "palatino")
2283 return isFontAvailable("mathpazo");
2288 bool GuiDocument::providesSC(string const & font) const
2290 if (font == "palatino")
2291 return isFontAvailable("mathpazo");
2292 if (font == "utopia")
2293 return isFontAvailable("fourier");
2298 bool GuiDocument::providesScale(string const & font) const
2300 return font == "helvet" || font == "luximono"
2301 || font == "berasans" || font == "beramono";
2305 void GuiDocument::loadModuleInfo()
2307 moduleNames_.clear();
2308 LyXModuleList::const_iterator it = moduleList.begin();
2309 LyXModuleList::const_iterator end = moduleList.end();
2310 for (; it != end; ++it) {
2313 m.name = qt_(it->getName());
2314 // this is supposed to give us the first sentence of the description
2315 QString desc = qt_(it->getDescription());
2316 int const pos = desc.indexOf(".");
2318 desc.truncate(pos + 1);
2319 m.description = desc;
2320 moduleNames_.push_back(m);
2325 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2328 } // namespace frontend
2331 #include "GuiDocument_moc.cpp"