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/filetools.h"
47 #include "support/lstrings.h"
49 #include "frontends/alert.h"
51 #include <QCloseEvent>
53 #include <QTextCursor>
63 using namespace lyx::support;
68 char const * const tex_graphics[] =
70 "default", "dvips", "dvitops", "emtex",
71 "ln", "oztex", "textures", "none", ""
75 char const * const tex_graphics_gui[] =
77 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
78 "LN", "OzTeX", "Textures", N_("None"), ""
82 char const * const tex_fonts_roman[] =
84 "default", "cmr", "lmodern", "ae", "times", "palatino",
85 "charter", "newcent", "bookman", "utopia", "beraserif",
86 "ccfonts", "chancery", ""
90 char const * tex_fonts_roman_gui[] =
92 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
93 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
94 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
95 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
100 char const * const tex_fonts_sans[] =
102 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
106 char const * tex_fonts_sans_gui[] =
108 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
109 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
113 char const * const tex_fonts_monospaced[] =
115 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
119 char const * tex_fonts_monospaced_gui[] =
121 N_("Default"), N_("Computer Modern Typewriter"),
122 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
123 N_("LuxiMono"), N_("CM Typewriter Light"), ""
127 vector<pair<string, lyx::docstring> > pagestyles;
130 } // anonymous namespace
135 // used when sorting the textclass list.
136 class less_textclass_avail_desc
137 : public binary_function<string, string, int>
140 int operator()(string const & lhs, string const & rhs) const
142 // Ordering criteria:
143 // 1. Availability of text class
144 // 2. Description (lexicographic)
145 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
146 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
147 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
148 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
149 _(tc1.description()) < _(tc2.description()));
159 QModelIndex getSelectedIndex(QListView * lv)
161 QModelIndex retval = QModelIndex();
162 QModelIndexList selIdx =
163 lv->selectionModel()->selectedIndexes();
165 retval = selIdx.first();
171 vector<string> getRequiredList(string const & modName)
173 LyXModule const * const mod = moduleList[modName];
175 return vector<string>(); //empty such thing
176 return mod->getRequiredModules();
180 vector<string> getExcludedList(string const & modName)
182 LyXModule const * const mod = moduleList[modName];
184 return vector<string>(); //empty such thing
185 return mod->getExcludedModules();
189 docstring getModuleDescription(string const & modName)
191 LyXModule const * const mod = moduleList[modName];
193 return _("Module not found!");
194 return _(mod->getDescription());
198 vector<string> getPackageList(string const & modName)
200 LyXModule const * const mod = moduleList[modName];
202 return vector<string>(); //empty such thing
203 return mod->getPackageList();
207 bool isModuleAvailable(string const & modName)
209 LyXModule * mod = moduleList[modName];
212 return mod->isAvailable();
214 } //anonymous namespace
217 ModuleSelMan::ModuleSelMan(
218 QListView * availableLV,
219 QListView * selectedLV,
223 QPushButton * downPB,
224 GuiIdListModel * availableModel,
225 GuiIdListModel * selectedModel) :
226 GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
227 upPB, downPB, availableModel, selectedModel)
231 void ModuleSelMan::updateAddPB()
233 int const arows = availableModel->rowCount();
234 QModelIndexList const availSels =
235 availableLV->selectionModel()->selectedIndexes();
236 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
237 addPB->setEnabled(false);
241 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
242 string const modName = getAvailableModel()->getIDString(idx.row());
243 vector<string> reqs = getRequiredList(modName);
244 vector<string> excl = getExcludedList(modName);
246 if (reqs.empty() && excl.empty()) {
247 addPB->setEnabled(true);
251 int const srows = selectedModel->rowCount();
252 vector<string> selModList;
253 for (int i = 0; i < srows; ++i)
254 selModList.push_back(getSelectedModel()->getIDString(i));
256 vector<string>::const_iterator selModStart = selModList.begin();
257 vector<string>::const_iterator selModEnd = selModList.end();
259 //Check whether some required module is available
261 bool foundOne = false;
262 vector<string>::const_iterator it = reqs.begin();
263 vector<string>::const_iterator end = reqs.end();
264 for (; it != end; ++it) {
265 if (find(selModStart, selModEnd, *it) != selModEnd) {
271 addPB->setEnabled(false);
276 //Check whether any excluded module is being used
278 vector<string>::const_iterator it = excl.begin();
279 vector<string>::const_iterator end = excl.end();
280 for (; it != end; ++it) {
281 if (find(selModStart, selModEnd, *it) != selModEnd) {
282 addPB->setEnabled(false);
288 addPB->setEnabled(true);
292 void ModuleSelMan::updateDownPB()
294 int const srows = selectedModel->rowCount();
296 downPB->setEnabled(false);
299 QModelIndexList const selSels =
300 selectedLV->selectionModel()->selectedIndexes();
301 //disable if empty or last item is selected
302 if (selSels.empty() || selSels.first().row() == srows - 1) {
303 downPB->setEnabled(false);
306 //determine whether immediately succeding element requires this one
307 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
308 int curRow = curIdx.row();
309 if (curRow < 0 || curRow >= srows - 1) { //this shouldn't happen...
310 downPB->setEnabled(false);
313 string const curModName = getSelectedModel()->getIDString(curRow);
314 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
316 vector<string> reqs = getRequiredList(nextModName);
318 //if it doesn't require anything....
320 downPB->setEnabled(true);
324 //FIXME This should perhaps be more flexible and check whether, even
325 //if this one is required, there is also an earlier one that is required.
326 //enable it if this module isn't required
328 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
331 void ModuleSelMan::updateUpPB()
333 int const srows = selectedModel->rowCount();
335 upPB->setEnabled(false);
338 QModelIndexList const selSels =
339 selectedLV->selectionModel()->selectedIndexes();
340 //disable if empty or first item is selected
341 if (selSels.empty() || selSels.first().row() == 0) {
342 upPB->setEnabled(false);
346 //determine whether immediately preceding element is required by this one
347 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
348 int curRow = curIdx.row();
349 if (curRow <= -1 || curRow > srows - 1) { //sanity check
350 downPB->setEnabled(false);
353 string const curModName = getSelectedModel()->getIDString(curRow);
354 vector<string> reqs = getRequiredList(curModName);
356 //if this one doesn't require anything....
358 upPB->setEnabled(true);
362 string preModName = getSelectedModel()->getIDString(curRow - 1);
364 //NOTE This is less flexible than it might be. You could check whether, even
365 //if this one is required, there is also an earlier one that is required.
366 //enable it if the preceding module isn't required
367 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
370 void ModuleSelMan::updateDelPB()
372 int const srows = selectedModel->rowCount();
374 deletePB->setEnabled(false);
377 QModelIndexList const selSels =
378 selectedLV->selectionModel()->selectedIndexes();
379 if (selSels.empty() || selSels.first().row() < 0) {
380 deletePB->setEnabled(false);
384 //determine whether some LATER module requires this one
385 //NOTE Things are arranged so that this is the only way there
386 //can be a problem. At least, we hope so.
387 QModelIndex const & curIdx =
388 selectedLV->selectionModel()->currentIndex();
389 int const curRow = curIdx.row();
390 if (curRow < 0 || curRow >= srows) { //this shouldn't happen
391 deletePB->setEnabled(false);
395 QString const curModName = curIdx.data().toString();
397 //We're looking here for a reason NOT to enable the button. If we
398 //find one, we disable it and return. If we don't, we'll end up at
399 //the end of the function, and then we enable it.
400 for (int i = curRow + 1; i < srows; ++i) {
401 string const thisMod = getSelectedModel()->getIDString(i);
402 vector<string> reqs = getRequiredList(thisMod);
403 //does this one require us?
404 if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
408 //OK, so this module requires us
409 //is there an EARLIER module that also satisfies the require?
410 //NOTE We demand that it be earlier to keep the list of modules
411 //consistent with the rule that a module must be proceeded by a
412 //required module. There would be more flexible ways to proceed,
413 //but that would be a lot more complicated, and the logic here is
414 //already complicated. (That's why I've left the debugging code.)
415 //lyxerr << "Testing " << thisMod << std::endl;
416 bool foundOne = false;
417 for (int j = 0; j < curRow; ++j) {
418 string const mod = getSelectedModel()->getIDString(j);
419 //lyxerr << "In loop: Testing " << mod << std::endl;
420 //do we satisfy the require?
421 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
422 //lyxerr << mod << " does the trick." << std::endl;
427 //did we find a module to satisfy the require?
429 //lyxerr << "No matching module found." << std::endl;
430 deletePB->setEnabled(false);
434 //lyxerr << "All's well that ends well." << std::endl;
435 deletePB->setEnabled(true);
439 /////////////////////////////////////////////////////////////////////
443 /////////////////////////////////////////////////////////////////////
445 PreambleModule::PreambleModule(): current_id_(0)
447 // This is not a memory leak. The object will be destroyed
449 (void) new LaTeXHighlighter(preambleTE->document());
450 setFocusProxy(preambleTE);
451 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
455 void PreambleModule::update(BufferParams const & params, BufferId id)
457 QString preamble = toqstr(params.preamble);
458 // Nothing to do if the params and preamble are unchanged.
459 if (id == current_id_
460 && preamble == preambleTE->document()->toPlainText())
463 QTextCursor cur = preambleTE->textCursor();
464 // Save the coords before switching to the new one.
465 preamble_coords_[current_id_] =
466 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
468 // Save the params address for further use.
470 preambleTE->document()->setPlainText(preamble);
471 Coords::const_iterator it = preamble_coords_.find(current_id_);
472 if (it == preamble_coords_.end())
473 // First time we open this one.
474 preamble_coords_[current_id_] = make_pair(0,0);
476 // Restore saved coords.
477 QTextCursor cur = preambleTE->textCursor();
478 cur.setPosition(it->second.first);
479 preambleTE->setTextCursor(cur);
480 preambleTE->verticalScrollBar()->setValue(it->second.second);
485 void PreambleModule::apply(BufferParams & params)
487 params.preamble = fromqstr(preambleTE->document()->toPlainText());
491 void PreambleModule::closeEvent(QCloseEvent * e)
493 // Save the coords before closing.
494 QTextCursor cur = preambleTE->textCursor();
495 preamble_coords_[current_id_] =
496 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
501 /////////////////////////////////////////////////////////////////////
505 /////////////////////////////////////////////////////////////////////
508 GuiDocument::GuiDocument(GuiView & lv)
509 : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
513 QList<LanguagePair> langs = languageData();
514 for (int i = 0; i != langs.size(); ++i)
515 lang_.append(langs[i].second);
517 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
518 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
519 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
520 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
522 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
523 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
525 // Manage the restore, ok, apply, restore and cancel/close buttons
526 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
528 bc().setApply(applyPB);
529 bc().setCancel(closePB);
530 bc().setRestore(restorePB);
532 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
534 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
535 this, SLOT(change_adaptor()));
536 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
537 this, SLOT(setLSpacing(int)));
538 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
539 this, SLOT(change_adaptor()));
540 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
541 this, SLOT(change_adaptor()));
542 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
543 this, SLOT(change_adaptor()));
544 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
545 this, SLOT(change_adaptor()));
546 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
547 this, SLOT(change_adaptor()));
548 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
549 this, SLOT(change_adaptor()));
550 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
551 this, SLOT(setSkip(int)));
552 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
553 this, SLOT(enableSkip(bool)));
554 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
555 this, SLOT(change_adaptor()));
556 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
557 this, SLOT(setColSep()));
558 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
559 this, SLOT(change_adaptor()));
560 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
561 this, SLOT(change_adaptor()));
562 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
563 this, SLOT(set_listings_msg()));
564 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
565 this, SLOT(set_listings_msg()));
566 textLayoutModule->listingsTB->setPlainText(
567 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
568 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
569 textLayoutModule->lspacingLE));
570 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
571 textLayoutModule->skipLE));
573 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
574 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
575 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
576 textLayoutModule->skipCO->addItem(qt_("Length"));
577 // remove the %-items from the unit choice
578 textLayoutModule->skipLengthCO->noPercents();
579 textLayoutModule->lspacingCO->insertItem(
580 Spacing::Single, qt_("Single"));
581 textLayoutModule->lspacingCO->insertItem(
582 Spacing::Onehalf, qt_("OneHalf"));
583 textLayoutModule->lspacingCO->insertItem(
584 Spacing::Double, qt_("Double"));
585 textLayoutModule->lspacingCO->insertItem(
586 Spacing::Other, qt_("Custom"));
588 // initialize the length validator
589 bc().addCheckedLineEdit(textLayoutModule->skipLE);
591 fontModule = new UiWidget<Ui::FontUi>;
593 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
594 this, SLOT(change_adaptor()));
595 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
596 this, SLOT(romanChanged(int)));
597 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
598 this, SLOT(change_adaptor()));
599 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
600 this, SLOT(sansChanged(int)));
601 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
602 this, SLOT(change_adaptor()));
603 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
604 this, SLOT(ttChanged(int)));
605 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
606 this, SLOT(change_adaptor()));
607 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
608 this, SLOT(change_adaptor()));
609 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
610 this, SLOT(change_adaptor()));
611 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
612 this, SLOT(change_adaptor()));
613 connect(fontModule->fontScCB, SIGNAL(clicked()),
614 this, SLOT(change_adaptor()));
615 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
616 this, SLOT(change_adaptor()));
618 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
619 QString font = qt_(tex_fonts_roman_gui[n]);
620 if (!isFontAvailable(tex_fonts_roman[n]))
621 font += qt_(" (not installed)");
622 fontModule->fontsRomanCO->addItem(font);
624 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
625 QString font = qt_(tex_fonts_sans_gui[n]);
626 if (!isFontAvailable(tex_fonts_sans[n]))
627 font += qt_(" (not installed)");
628 fontModule->fontsSansCO->addItem(font);
630 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
631 QString font = qt_(tex_fonts_monospaced_gui[n]);
632 if (!isFontAvailable(tex_fonts_monospaced[n]))
633 font += qt_(" (not installed)");
634 fontModule->fontsTypewriterCO->addItem(font);
637 fontModule->fontsizeCO->addItem(qt_("Default"));
638 fontModule->fontsizeCO->addItem(qt_("10"));
639 fontModule->fontsizeCO->addItem(qt_("11"));
640 fontModule->fontsizeCO->addItem(qt_("12"));
642 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
643 fontModule->fontsDefaultCO->addItem(
644 qt_(GuiDocument::fontfamilies_gui[n]));
647 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
649 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
650 this, SLOT(setCustomPapersize(int)));
651 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
652 this, SLOT(setCustomPapersize(int)));
653 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
654 this, SLOT(portraitChanged()));
655 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
656 this, SLOT(change_adaptor()));
657 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
658 this, SLOT(change_adaptor()));
659 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
660 this, SLOT(change_adaptor()));
661 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
662 this, SLOT(change_adaptor()));
663 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
664 this, SLOT(change_adaptor()));
665 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
666 this, SLOT(change_adaptor()));
667 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
668 this, SLOT(change_adaptor()));
669 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
670 this, SLOT(change_adaptor()));
671 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
672 this, SLOT(change_adaptor()));
674 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
675 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
676 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
677 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
678 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
679 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
680 pageLayoutModule->paperheightL);
681 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
682 pageLayoutModule->paperwidthL);
685 QComboBox * cb = pageLayoutModule->papersizeCO;
686 cb->addItem(qt_("Default"));
687 cb->addItem(qt_("Custom"));
688 cb->addItem(qt_("US letter"));
689 cb->addItem(qt_("US legal"));
690 cb->addItem(qt_("US executive"));
691 cb->addItem(qt_("A3"));
692 cb->addItem(qt_("A4"));
693 cb->addItem(qt_("A5"));
694 cb->addItem(qt_("B3"));
695 cb->addItem(qt_("B4"));
696 cb->addItem(qt_("B5"));
697 // remove the %-items from the unit choice
698 pageLayoutModule->paperwidthUnitCO->noPercents();
699 pageLayoutModule->paperheightUnitCO->noPercents();
700 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
701 pageLayoutModule->paperheightLE));
702 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
703 pageLayoutModule->paperwidthLE));
706 marginsModule = new UiWidget<Ui::MarginsUi>;
708 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
709 this, SLOT(setCustomMargins(bool)));
710 connect(marginsModule->marginCB, SIGNAL(clicked()),
711 this, SLOT(change_adaptor()));
712 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
713 this, SLOT(change_adaptor()));
714 connect(marginsModule->topUnit, SIGNAL(activated(int)),
715 this, SLOT(change_adaptor()));
716 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
717 this, SLOT(change_adaptor()));
718 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
719 this, SLOT(change_adaptor()));
720 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
721 this, SLOT(change_adaptor()));
722 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
723 this, SLOT(change_adaptor()));
724 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
725 this, SLOT(change_adaptor()));
726 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
727 this, SLOT(change_adaptor()));
728 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
729 this, SLOT(change_adaptor()));
730 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
731 this, SLOT(change_adaptor()));
732 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
733 this, SLOT(change_adaptor()));
734 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
735 this, SLOT(change_adaptor()));
736 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
737 this, SLOT(change_adaptor()));
738 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
739 this, SLOT(change_adaptor()));
740 connect(marginsModule->columnsepLE, SIGNAL(textChanged(const QString&)),
741 this, SLOT(change_adaptor()));
742 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
743 this, SLOT(change_adaptor()));
744 marginsModule->topLE->setValidator(unsignedLengthValidator(
745 marginsModule->topLE));
746 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
747 marginsModule->bottomLE));
748 marginsModule->innerLE->setValidator(unsignedLengthValidator(
749 marginsModule->innerLE));
750 marginsModule->outerLE->setValidator(unsignedLengthValidator(
751 marginsModule->outerLE));
752 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
753 marginsModule->headsepLE));
754 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
755 marginsModule->headheightLE));
756 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
757 marginsModule->footskipLE));
758 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
759 marginsModule->columnsepLE));
761 bc().addCheckedLineEdit(marginsModule->topLE,
762 marginsModule->topL);
763 bc().addCheckedLineEdit(marginsModule->bottomLE,
764 marginsModule->bottomL);
765 bc().addCheckedLineEdit(marginsModule->innerLE,
766 marginsModule->innerL);
767 bc().addCheckedLineEdit(marginsModule->outerLE,
768 marginsModule->outerL);
769 bc().addCheckedLineEdit(marginsModule->headsepLE,
770 marginsModule->headsepL);
771 bc().addCheckedLineEdit(marginsModule->headheightLE,
772 marginsModule->headheightL);
773 bc().addCheckedLineEdit(marginsModule->footskipLE,
774 marginsModule->footskipL);
775 bc().addCheckedLineEdit(marginsModule->columnsepLE,
776 marginsModule->columnsepL);
779 langModule = new UiWidget<Ui::LanguageUi>;
781 connect(langModule->languageCO, SIGNAL(activated(int)),
782 this, SLOT(change_adaptor()));
783 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
784 this, SLOT(change_adaptor()));
785 connect(langModule->otherencodingRB, SIGNAL(clicked()),
786 this, SLOT(change_adaptor()));
787 connect(langModule->encodingCO, SIGNAL(activated(int)),
788 this, SLOT(change_adaptor()));
789 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
790 this, SLOT(change_adaptor()));
793 QList<LanguagePair>::const_iterator lit = langs.begin();
794 QList<LanguagePair>::const_iterator lend = langs.end();
795 for (; lit != lend; ++lit)
796 langModule->languageCO->addItem(lit->first);
798 // Always put the default encoding in the first position.
799 // It is special because the displayed text is translated.
800 langModule->encodingCO->addItem(qt_("LaTeX default"));
801 Encodings::const_iterator it = encodings.begin();
802 Encodings::const_iterator const end = encodings.end();
803 for (; it != end; ++it)
804 langModule->encodingCO->addItem(toqstr(it->latexName()));
806 langModule->quoteStyleCO->addItem(qt_("``text''"));
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<<"));
814 numberingModule = new UiWidget<Ui::NumberingUi>;
816 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
817 this, SLOT(change_adaptor()));
818 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
819 this, SLOT(change_adaptor()));
820 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
821 this, SLOT(updateNumbering()));
822 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
823 this, SLOT(updateNumbering()));
824 numberingModule->tocTW->setColumnCount(3);
825 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
826 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
827 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
830 biblioModule = new UiWidget<Ui::BiblioUi>;
831 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
832 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
833 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
834 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
836 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
837 this, SLOT(change_adaptor()));
838 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
839 this, SLOT(change_adaptor()));
840 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
841 this, SLOT(change_adaptor()));
842 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
843 this, SLOT(change_adaptor()));
844 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
845 this, SLOT(change_adaptor()));
847 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
848 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
849 biblioModule->citeStyleCO->setCurrentIndex(0);
852 mathsModule = new UiWidget<Ui::MathsUi>;
853 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
854 mathsModule->amsCB, SLOT(setDisabled(bool)));
855 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
856 mathsModule->esintCB, SLOT(setDisabled(bool)));
858 connect(mathsModule->amsCB, SIGNAL(clicked()),
859 this, SLOT(change_adaptor()));
860 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
861 this, SLOT(change_adaptor()));
862 connect(mathsModule->esintCB, SIGNAL(clicked()),
863 this, SLOT(change_adaptor()));
864 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
865 this, SLOT(change_adaptor()));
867 latexModule = new UiWidget<Ui::LaTeXUi>;
869 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
870 this, SLOT(change_adaptor()));
871 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
872 this, SLOT(change_adaptor()));
873 connect(latexModule->classCO, SIGNAL(activated(int)),
874 this, SLOT(classChanged()));
875 connect(latexModule->classCO, SIGNAL(activated(int)),
876 this, SLOT(change_adaptor()));
877 connect(latexModule->layoutPB, SIGNAL(clicked()),
878 this, SLOT(browseLayout()));
879 connect(latexModule->childDocGB, SIGNAL(clicked()),
880 this, SLOT(change_adaptor()));
881 connect(latexModule->childDocLE, SIGNAL(textChanged(const QString &)),
882 this, SLOT(change_adaptor()));
883 connect(latexModule->childDocPB, SIGNAL(clicked()),
884 this, SLOT(browseMaster()));
887 new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
888 latexModule->addPB, latexModule->deletePB,
889 latexModule->upPB, latexModule->downPB,
890 availableModel(), selectedModel());
891 connect(selectionManager, SIGNAL(updateHook()),
892 this, SLOT(updateModuleInfo()));
893 connect(selectionManager, SIGNAL(updateHook()),
894 this, SLOT(change_adaptor()));
896 // postscript drivers
897 for (int n = 0; tex_graphics[n][0]; ++n) {
898 QString enc = qt_(tex_graphics_gui[n]);
899 latexModule->psdriverCO->addItem(enc);
902 latexModule->classCO->setModel(&classes_model_);
903 LayoutFileList const & bcl = LayoutFileList::get();
904 vector<LayoutFileIndex> classList = bcl.classList();
905 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
907 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
908 vector<LayoutFileIndex>::const_iterator cen = classList.end();
909 for (int i = 0; cit != cen; ++cit, ++i) {
910 LayoutFile const & tc = bcl[*cit];
911 docstring item = (tc.isTeXClassAvailable()) ?
912 from_utf8(tc.description()) :
913 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
914 classes_model_.insertRow(i, toqstr(item), *cit);
918 branchesModule = new GuiBranches;
919 connect(branchesModule, SIGNAL(changed()),
920 this, SLOT(change_adaptor()));
923 preambleModule = new PreambleModule;
924 connect(preambleModule, SIGNAL(changed()),
925 this, SLOT(change_adaptor()));
928 bulletsModule = new BulletsModule;
929 connect(bulletsModule, SIGNAL(changed()),
930 this, SLOT(change_adaptor()));
933 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
935 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
936 this, SLOT(change_adaptor()));
937 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
938 this, SLOT(change_adaptor()));
939 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
940 this, SLOT(change_adaptor()));
941 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
942 this, SLOT(change_adaptor()));
943 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
944 this, SLOT(change_adaptor()));
945 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
946 this, SLOT(change_adaptor()));
947 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
948 this, SLOT(change_adaptor()));
949 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
950 this, SLOT(change_adaptor()));
951 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
952 this, SLOT(change_adaptor()));
953 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
954 this, SLOT(change_adaptor()));
955 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
956 this, SLOT(change_adaptor()));
957 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
958 this, SLOT(change_adaptor()));
959 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
960 this, SLOT(change_adaptor()));
961 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
962 this, SLOT(change_adaptor()));
963 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
964 this, SLOT(change_adaptor()));
965 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
966 this, SLOT(change_adaptor()));
967 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
968 this, SLOT(change_adaptor()));
971 floatModule = new FloatPlacement;
972 connect(floatModule, SIGNAL(changed()),
973 this, SLOT(change_adaptor()));
975 docPS->addPanel(latexModule, qt_("Document Class"));
976 docPS->addPanel(fontModule, qt_("Fonts"));
977 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
978 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
979 docPS->addPanel(marginsModule, qt_("Page Margins"));
980 docPS->addPanel(langModule, qt_("Language"));
981 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
982 docPS->addPanel(biblioModule, qt_("Bibliography"));
983 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
984 docPS->addPanel(mathsModule, qt_("Math Options"));
985 docPS->addPanel(floatModule, qt_("Float Placement"));
986 docPS->addPanel(bulletsModule, qt_("Bullets"));
987 docPS->addPanel(branchesModule, qt_("Branches"));
988 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
989 docPS->setCurrentPanel(qt_("Document Class"));
990 // FIXME: hack to work around resizing bug in Qt >= 4.2
991 // bug verified with Qt 4.2.{0-3} (JSpitzm)
992 #if QT_VERSION >= 0x040200
993 docPS->updateGeometry();
998 void GuiDocument::showPreamble()
1000 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
1004 void GuiDocument::saveDefaultClicked()
1010 void GuiDocument::useDefaultsClicked()
1016 void GuiDocument::change_adaptor()
1022 docstring GuiDocument::validate_listings_params()
1024 // use a cache here to avoid repeated validation
1025 // of the same parameters
1026 static string param_cache = string();
1027 static docstring msg_cache = docstring();
1029 if (textLayoutModule->bypassCB->isChecked())
1032 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1033 if (params != param_cache) {
1034 param_cache = params;
1035 msg_cache = InsetListingsParams(params).validate();
1041 void GuiDocument::set_listings_msg()
1043 static bool isOK = true;
1044 docstring msg = validate_listings_params();
1049 // listingsTB->setTextColor("black");
1050 textLayoutModule->listingsTB->setPlainText(
1051 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
1054 // listingsTB->setTextColor("red");
1055 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
1060 void GuiDocument::setLSpacing(int item)
1062 textLayoutModule->lspacingLE->setEnabled(item == 3);
1066 void GuiDocument::setSkip(int item)
1068 bool const enable = (item == 3);
1069 textLayoutModule->skipLE->setEnabled(enable);
1070 textLayoutModule->skipLengthCO->setEnabled(enable);
1074 void GuiDocument::enableSkip(bool skip)
1076 textLayoutModule->skipCO->setEnabled(skip);
1077 textLayoutModule->skipLE->setEnabled(skip);
1078 textLayoutModule->skipLengthCO->setEnabled(skip);
1080 setSkip(textLayoutModule->skipCO->currentIndex());
1083 void GuiDocument::portraitChanged()
1085 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1088 void GuiDocument::setMargins(bool custom)
1090 marginsModule->marginCB->setChecked(custom);
1091 setCustomMargins(custom);
1095 void GuiDocument::setCustomPapersize(int papersize)
1097 bool const custom = (papersize == 1);
1099 pageLayoutModule->paperwidthL->setEnabled(custom);
1100 pageLayoutModule->paperwidthLE->setEnabled(custom);
1101 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1102 pageLayoutModule->paperheightL->setEnabled(custom);
1103 pageLayoutModule->paperheightLE->setEnabled(custom);
1104 pageLayoutModule->paperheightLE->setFocus();
1105 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1109 void GuiDocument::setColSep()
1111 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1115 void GuiDocument::setCustomMargins(bool custom)
1117 marginsModule->topL->setEnabled(!custom);
1118 marginsModule->topLE->setEnabled(!custom);
1119 marginsModule->topUnit->setEnabled(!custom);
1121 marginsModule->bottomL->setEnabled(!custom);
1122 marginsModule->bottomLE->setEnabled(!custom);
1123 marginsModule->bottomUnit->setEnabled(!custom);
1125 marginsModule->innerL->setEnabled(!custom);
1126 marginsModule->innerLE->setEnabled(!custom);
1127 marginsModule->innerUnit->setEnabled(!custom);
1129 marginsModule->outerL->setEnabled(!custom);
1130 marginsModule->outerLE->setEnabled(!custom);
1131 marginsModule->outerUnit->setEnabled(!custom);
1133 marginsModule->headheightL->setEnabled(!custom);
1134 marginsModule->headheightLE->setEnabled(!custom);
1135 marginsModule->headheightUnit->setEnabled(!custom);
1137 marginsModule->headsepL->setEnabled(!custom);
1138 marginsModule->headsepLE->setEnabled(!custom);
1139 marginsModule->headsepUnit->setEnabled(!custom);
1141 marginsModule->footskipL->setEnabled(!custom);
1142 marginsModule->footskipLE->setEnabled(!custom);
1143 marginsModule->footskipUnit->setEnabled(!custom);
1145 bool const enableColSep = !custom &&
1146 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1147 marginsModule->columnsepL->setEnabled(enableColSep);
1148 marginsModule->columnsepLE->setEnabled(enableColSep);
1149 marginsModule->columnsepUnit->setEnabled(enableColSep);
1153 void GuiDocument::updateFontsize(string const & items, string const & sel)
1155 fontModule->fontsizeCO->clear();
1156 fontModule->fontsizeCO->addItem(qt_("Default"));
1158 for (int n = 0; !token(items,'|',n).empty(); ++n)
1159 fontModule->fontsizeCO->
1160 addItem(toqstr(token(items,'|',n)));
1162 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1163 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1164 fontModule->fontsizeCO->setCurrentIndex(n);
1171 void GuiDocument::romanChanged(int item)
1173 string const font = tex_fonts_roman[item];
1174 fontModule->fontScCB->setEnabled(providesSC(font));
1175 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1179 void GuiDocument::sansChanged(int item)
1181 string const font = tex_fonts_sans[item];
1182 bool scaleable = providesScale(font);
1183 fontModule->scaleSansSB->setEnabled(scaleable);
1184 fontModule->scaleSansLA->setEnabled(scaleable);
1188 void GuiDocument::ttChanged(int item)
1190 string const font = tex_fonts_monospaced[item];
1191 bool scaleable = providesScale(font);
1192 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1193 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1197 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1200 pageLayoutModule->pagestyleCO->clear();
1201 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1203 for (int n = 0; !token(items,'|',n).empty(); ++n) {
1204 string style = token(items, '|', n);
1205 docstring style_gui = _(style);
1206 pagestyles.push_back(pair<string, docstring>(style, style_gui));
1207 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
1210 if (sel == "default") {
1211 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1217 for (size_t i = 0; i < pagestyles.size(); ++i)
1218 if (pagestyles[i].first == sel)
1219 nn = pageLayoutModule->pagestyleCO->findText(
1220 toqstr(pagestyles[i].second));
1223 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1227 void GuiDocument::browseLayout()
1229 QString const label1 = qt_("Layouts|#o#O");
1230 QString const dir1 = toqstr(lyxrc.document_path);
1231 QStringList const filter(qt_("LyX Layout (*.layout)"));
1232 QString file = browseRelFile(QString(), bufferFilepath(),
1233 qt_("Local layout file"), filter, false,
1236 if (!file.endsWith(".layout"))
1239 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1240 fromqstr(bufferFilepath()));
1242 // load the layout file
1243 LayoutFileList & bcl = LayoutFileList::get();
1244 string classname = layoutFile.onlyFileName();
1245 LayoutFileIndex name = bcl.addLayoutFile(
1246 classname.substr(0, classname.size() - 7),
1247 layoutFile.onlyPath().absFilename(),
1248 LayoutFileList::Local);
1251 Alert::error(_("Error"),
1252 _("Unable to read local layout file."));
1256 // do not trigger classChanged if there is no change.
1257 if (latexModule->classCO->currentText() == toqstr(name))
1261 int idx = latexModule->classCO->findText(toqstr(name));
1263 classes_model_.insertRow(0, toqstr(name), name);
1264 latexModule->classCO->setCurrentIndex(0);
1266 latexModule->classCO->setCurrentIndex(idx);
1271 void GuiDocument::browseMaster()
1273 QString const title = qt_("Select master document");
1274 QString const dir1 = toqstr(lyxrc.document_path);
1275 QString const old = latexModule->childDocLE->text();
1276 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1277 QStringList const filter(qt_("LyX Files (*.lyx)"));
1278 QString file = browseRelFile(old, docpath, title, filter, false,
1279 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1281 latexModule->childDocLE->setText(file);
1285 void GuiDocument::classChanged()
1287 int idx = latexModule->classCO->currentIndex();
1290 string const classname = classes_model_.getIDString(idx);
1291 // check if this is a local layout file
1292 if (prefixIs(classname, LayoutFileList::localPrefix)) {
1293 int const ret = Alert::prompt(_("Local layout file"),
1294 _("The layout file you have selected is a local layout\n"
1295 "file, not one in the system or user directory. Your\n"
1296 "document may not work with this layout if you do not\n"
1297 "keep the layout file in the same directory."),
1298 1, 1, _("&Set Layout"), _("&Cancel"));
1300 // try to reset the layout combo
1301 setLayoutComboByIDString(bp_.baseClassID());
1305 // FIXME Note that by doing things this way, we load the TextClass
1306 // as soon as it is selected. So, if you use the scroll wheel when
1307 // sitting on the combo box, we'll load a lot of TextClass objects
1308 // very quickly. This could be changed.
1309 if (!bp_.setBaseClass(classname)) {
1310 Alert::error(_("Error"), _("Unable to set document class."));
1313 if (lyxrc.auto_reset_options) {
1314 if (applyPB->isEnabled()) {
1315 int const ret = Alert::prompt(_("Unapplied changes"),
1316 _("Some changes in the dialog were not yet applied.\n"
1317 "If you do not apply now, they will be lost after this action."),
1318 1, 1, _("&Apply"), _("&Dismiss"));
1322 bp_.useClassDefaults();
1329 // This is an insanely complicated attempt to make this sort of thing
1330 // work with RTL languages.
1331 docstring formatStrVec(vector<string> const & v, docstring const & s)
1333 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1334 int const vSize = v.size();
1337 else if (v.size() == 1)
1338 return from_ascii(v[0]);
1339 else if (v.size() == 2) {
1340 docstring retval = _("%1$s and %2$s");
1341 retval = subst(retval, _("and"), s);
1342 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1344 //The idea here is to format all but the last two items...
1345 docstring t2 = _("%1$s, %2$s");
1346 docstring retval = from_ascii(v[0]);
1347 for (int i = 1; i < vSize - 2; ++i)
1348 retval = bformat(t2, retval, from_ascii(v[i]));
1349 //...and then to plug them, and the last two, into this schema
1350 docstring t = _("%1$s, %2$s, and %3$s");
1351 t = subst(t, _("and"), s);
1352 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1355 vector<string> idsToNames(vector<string> const & idList)
1357 vector<string> retval;
1358 vector<string>::const_iterator it = idList.begin();
1359 vector<string>::const_iterator end = idList.end();
1360 for (; it != end; ++it) {
1361 LyXModule const * const mod = moduleList[*it];
1363 retval.push_back(*it + " (Unavailable)");
1365 retval.push_back(mod->getName());
1372 void GuiDocument::updateModuleInfo()
1374 selectionManager->update();
1376 //Module description
1377 bool const focusOnSelected = selectionManager->selectedFocused();
1378 QListView const * const lv =
1379 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1380 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1381 latexModule->infoML->document()->clear();
1384 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1385 GuiIdListModel const & idModel =
1386 focusOnSelected ? modules_sel_model_ : modules_av_model_;
1387 string const modName = idModel.getIDString(idx.row());
1388 docstring desc = getModuleDescription(modName);
1390 vector<string> pkgList = getPackageList(modName);
1391 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1392 if (!pkgdesc.empty()) {
1395 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1398 pkgList = getRequiredList(modName);
1399 if (!pkgList.empty()) {
1400 vector<string> const reqDescs = idsToNames(pkgList);
1401 pkgdesc = formatStrVec(reqDescs, _("or"));
1404 desc += bformat(_("Module required: %1$s."), pkgdesc);
1407 pkgList = getExcludedList(modName);
1408 if (!pkgList.empty()) {
1409 vector<string> const reqDescs = idsToNames(pkgList);
1410 pkgdesc = formatStrVec(reqDescs, _( "and"));
1413 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1416 if (!isModuleAvailable(modName)) {
1419 desc += _("WARNING: Some packages are unavailable!");
1422 latexModule->infoML->document()->setPlainText(toqstr(desc));
1426 void GuiDocument::updateNumbering()
1428 DocumentClass const & tclass = bp_.documentClass();
1430 numberingModule->tocTW->setUpdatesEnabled(false);
1431 numberingModule->tocTW->clear();
1433 int const depth = numberingModule->depthSL->value();
1434 int const toc = numberingModule->tocSL->value();
1435 QString const no = qt_("No");
1436 QString const yes = qt_("Yes");
1437 QTreeWidgetItem * item = 0;
1439 DocumentClass::const_iterator lit = tclass.begin();
1440 DocumentClass::const_iterator len = tclass.end();
1441 for (; lit != len; ++lit) {
1442 int const toclevel = lit->toclevel;
1443 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1444 item = new QTreeWidgetItem(numberingModule->tocTW);
1445 item->setText(0, toqstr(translateIfPossible(lit->name())));
1446 item->setText(1, (toclevel <= depth) ? yes : no);
1447 item->setText(2, (toclevel <= toc) ? yes : no);
1451 numberingModule->tocTW->setUpdatesEnabled(true);
1452 numberingModule->tocTW->update();
1456 void GuiDocument::apply(BufferParams & params)
1459 preambleModule->apply(params);
1462 params.setCiteEngine(ENGINE_BASIC);
1464 if (biblioModule->citeNatbibRB->isChecked()) {
1465 bool const use_numerical_citations =
1466 biblioModule->citeStyleCO->currentIndex();
1467 if (use_numerical_citations)
1468 params.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
1470 params.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
1472 } else if (biblioModule->citeJurabibRB->isChecked())
1473 params.setCiteEngine(ENGINE_JURABIB);
1475 params.use_bibtopic =
1476 biblioModule->bibtopicCB->isChecked();
1478 // language & quotes
1479 if (langModule->defaultencodingRB->isChecked()) {
1480 params.inputenc = "auto";
1482 int i = langModule->encodingCO->currentIndex();
1484 params.inputenc = "default";
1487 fromqstr(langModule->encodingCO->currentText());
1490 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
1491 switch (langModule->quoteStyleCO->currentIndex()) {
1493 lga = InsetQuotes::EnglishQuotes;
1496 lga = InsetQuotes::SwedishQuotes;
1499 lga = InsetQuotes::GermanQuotes;
1502 lga = InsetQuotes::PolishQuotes;
1505 lga = InsetQuotes::FrenchQuotes;
1508 lga = InsetQuotes::DanishQuotes;
1511 params.quotes_language = lga;
1513 int const pos = langModule->languageCO->currentIndex();
1514 params.language = lyx::languages.getLanguage(fromqstr(lang_[pos]));
1517 if (params.documentClass().hasTocLevels()) {
1518 params.tocdepth = numberingModule->tocSL->value();
1519 params.secnumdepth = numberingModule->depthSL->value();
1523 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1524 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1525 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1526 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1529 params.graphicsDriver =
1530 tex_graphics[latexModule->psdriverCO->currentIndex()];
1533 int idx = latexModule->classCO->currentIndex();
1535 string const classname = classes_model_.getIDString(idx);
1536 params.setBaseClass(classname);
1540 params.clearLayoutModules();
1541 int const srows = modules_sel_model_.rowCount();
1542 vector<string> selModList;
1543 for (int i = 0; i < srows; ++i)
1544 params.addLayoutModule(modules_sel_model_.getIDString(i));
1546 if (mathsModule->amsautoCB->isChecked()) {
1547 params.use_amsmath = BufferParams::package_auto;
1549 if (mathsModule->amsCB->isChecked())
1550 params.use_amsmath = BufferParams::package_on;
1552 params.use_amsmath = BufferParams::package_off;
1555 if (mathsModule->esintautoCB->isChecked())
1556 params.use_esint = BufferParams::package_auto;
1558 if (mathsModule->esintCB->isChecked())
1559 params.use_esint = BufferParams::package_on;
1561 params.use_esint = BufferParams::package_off;
1564 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1565 params.pagestyle = "default";
1567 docstring style_gui =
1568 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1569 for (size_t i = 0; i < pagestyles.size(); ++i)
1570 if (pagestyles[i].second == style_gui)
1571 params.pagestyle = pagestyles[i].first;
1574 switch (textLayoutModule->lspacingCO->currentIndex()) {
1576 params.spacing().set(Spacing::Single);
1579 params.spacing().set(Spacing::Onehalf);
1582 params.spacing().set(Spacing::Double);
1585 params.spacing().set(Spacing::Other,
1586 fromqstr(textLayoutModule->lspacingLE->text()));
1590 if (textLayoutModule->twoColumnCB->isChecked())
1595 // text should have passed validation
1596 params.listings_params =
1597 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1599 if (textLayoutModule->indentRB->isChecked())
1600 params.paragraph_separation = BufferParams::ParagraphIndentSeparation;
1602 params.paragraph_separation = BufferParams::ParagraphSkipSeparation;
1604 switch (textLayoutModule->skipCO->currentIndex()) {
1606 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1609 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1612 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1617 widgetsToLength(textLayoutModule->skipLE,
1618 textLayoutModule->skipLengthCO)
1620 params.setDefSkip(vs);
1624 // DocumentDefskipCB assures that this never happens
1625 // so Assert then !!! - jbl
1626 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1631 fromqstr(latexModule->optionsLE->text());
1633 if (latexModule->childDocGB->isChecked())
1635 fromqstr(latexModule->childDocLE->text());
1637 params.master = string();
1639 params.float_placement = floatModule->get();
1643 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1646 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1648 params.fontsTypewriter =
1649 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1651 params.fontsSansScale = fontModule->scaleSansSB->value();
1653 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1655 params.fontsSC = fontModule->fontScCB->isChecked();
1657 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1659 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1660 fontModule->fontsDefaultCO->currentIndex()];
1662 if (fontModule->fontsizeCO->currentIndex() == 0)
1663 params.fontsize = "default";
1666 fromqstr(fontModule->fontsizeCO->currentText());
1669 params.papersize = PAPER_SIZE(
1670 pageLayoutModule->papersizeCO->currentIndex());
1672 // custom, A3, B3 and B4 paper sizes need geometry
1673 int psize = pageLayoutModule->papersizeCO->currentIndex();
1674 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1676 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1677 pageLayoutModule->paperwidthUnitCO);
1679 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1680 pageLayoutModule->paperheightUnitCO);
1682 if (pageLayoutModule->facingPagesCB->isChecked())
1683 params.sides = TwoSides;
1685 params.sides = OneSide;
1687 if (pageLayoutModule->landscapeRB->isChecked())
1688 params.orientation = ORIENTATION_LANDSCAPE;
1690 params.orientation = ORIENTATION_PORTRAIT;
1693 params.use_geometry = !marginsModule->marginCB->isChecked()
1696 Ui::MarginsUi const * m = marginsModule;
1698 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1699 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1700 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1701 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1702 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1703 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1704 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1705 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1707 branchesModule->apply(params);
1710 PDFOptions & pdf = params.pdfoptions();
1711 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1712 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1713 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1714 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1715 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1717 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1718 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1719 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1720 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1722 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1723 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1724 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1725 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1726 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1727 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1728 if (pdfSupportModule->fullscreenCB->isChecked())
1729 pdf.pagemode = pdf.pagemode_fullscreen;
1731 pdf.pagemode.clear();
1732 pdf.quoted_options = pdf.quoted_options_check(
1733 fromqstr(pdfSupportModule->optionsLE->text()));
1737 static int findPos(QStringList const & vec, QString const & val)
1739 for (int i = 0; i != vec.size(); ++i)
1746 void GuiDocument::updateParams()
1752 void GuiDocument::updateParams(BufferParams const & params)
1754 // set the default unit
1755 Length::UNIT defaultUnit = Length::CM;
1756 switch (lyxrc.default_papersize) {
1757 case PAPER_DEFAULT: break;
1759 case PAPER_USLETTER:
1761 case PAPER_USEXECUTIVE:
1762 defaultUnit = Length::IN;
1771 defaultUnit = Length::CM;
1778 preambleModule->update(params, id());
1781 biblioModule->citeDefaultRB->setChecked(
1782 params.citeEngine() == ENGINE_BASIC);
1784 biblioModule->citeNatbibRB->setChecked(
1785 params.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
1786 params.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
1788 biblioModule->citeStyleCO->setCurrentIndex(
1789 params.citeEngine() == ENGINE_NATBIB_NUMERICAL);
1791 biblioModule->citeJurabibRB->setChecked(
1792 params.citeEngine() == ENGINE_JURABIB);
1794 biblioModule->bibtopicCB->setChecked(
1795 params.use_bibtopic);
1797 // language & quotes
1798 int const pos = findPos(lang_, toqstr(params.language->lang()));
1799 langModule->languageCO->setCurrentIndex(pos);
1801 langModule->quoteStyleCO->setCurrentIndex(
1802 params.quotes_language);
1804 bool default_enc = true;
1805 if (params.inputenc != "auto") {
1806 default_enc = false;
1807 if (params.inputenc == "default") {
1808 langModule->encodingCO->setCurrentIndex(0);
1810 int const i = langModule->encodingCO->findText(
1811 toqstr(params.inputenc));
1813 langModule->encodingCO->setCurrentIndex(i);
1815 // unknown encoding. Set to default.
1819 langModule->defaultencodingRB->setChecked(default_enc);
1820 langModule->otherencodingRB->setChecked(!default_enc);
1823 int const min_toclevel = documentClass().min_toclevel();
1824 int const max_toclevel = documentClass().max_toclevel();
1825 if (documentClass().hasTocLevels()) {
1826 numberingModule->setEnabled(true);
1827 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1828 numberingModule->depthSL->setMaximum(max_toclevel);
1829 numberingModule->depthSL->setValue(params.secnumdepth);
1830 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1831 numberingModule->tocSL->setMaximum(max_toclevel);
1832 numberingModule->tocSL->setValue(params.tocdepth);
1835 numberingModule->setEnabled(false);
1836 numberingModule->tocTW->clear();
1840 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1841 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1842 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1843 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1844 bulletsModule->init();
1847 int nitem = findToken(tex_graphics, params.graphicsDriver);
1849 latexModule->psdriverCO->setCurrentIndex(nitem);
1852 mathsModule->amsCB->setChecked(
1853 params.use_amsmath == BufferParams::package_on);
1854 mathsModule->amsautoCB->setChecked(
1855 params.use_amsmath == BufferParams::package_auto);
1857 mathsModule->esintCB->setChecked(
1858 params.use_esint == BufferParams::package_on);
1859 mathsModule->esintautoCB->setChecked(
1860 params.use_esint == BufferParams::package_auto);
1862 switch (params.spacing().getSpace()) {
1863 case Spacing::Other: nitem = 3; break;
1864 case Spacing::Double: nitem = 2; break;
1865 case Spacing::Onehalf: nitem = 1; break;
1866 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1870 string const & layoutID = params.baseClassID();
1871 setLayoutComboByIDString(layoutID);
1873 updatePagestyle(documentClass().opt_pagestyle(),
1876 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1877 if (params.spacing().getSpace() == Spacing::Other) {
1878 textLayoutModule->lspacingLE->setText(
1879 toqstr(params.spacing().getValueAsString()));
1883 if (params.paragraph_separation == BufferParams::ParagraphIndentSeparation)
1884 textLayoutModule->indentRB->setChecked(true);
1886 textLayoutModule->skipRB->setChecked(true);
1889 switch (params.getDefSkip().kind()) {
1890 case VSpace::SMALLSKIP:
1893 case VSpace::MEDSKIP:
1896 case VSpace::BIGSKIP:
1899 case VSpace::LENGTH:
1902 string const length = params.getDefSkip().asLyXCommand();
1903 lengthToWidgets(textLayoutModule->skipLE,
1904 textLayoutModule->skipLengthCO,
1905 length, defaultUnit);
1912 textLayoutModule->skipCO->setCurrentIndex(skip);
1915 textLayoutModule->twoColumnCB->setChecked(
1916 params.columns == 2);
1918 // break listings_params to multiple lines
1920 InsetListingsParams(params.listings_params).separatedParams();
1921 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1923 if (!params.options.empty()) {
1924 latexModule->optionsLE->setText(
1925 toqstr(params.options));
1927 latexModule->optionsLE->setText(QString());
1930 if (!params.master.empty()) {
1931 latexModule->childDocGB->setChecked(true);
1932 latexModule->childDocLE->setText(
1933 toqstr(params.master));
1935 latexModule->childDocLE->setText(QString());
1936 latexModule->childDocGB->setChecked(false);
1939 floatModule->set(params.float_placement);
1942 updateFontsize(documentClass().opt_fontsize(),
1945 int n = findToken(tex_fonts_roman, params.fontsRoman);
1947 fontModule->fontsRomanCO->setCurrentIndex(n);
1951 n = findToken(tex_fonts_sans, params.fontsSans);
1953 fontModule->fontsSansCO->setCurrentIndex(n);
1957 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1959 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1963 fontModule->fontScCB->setChecked(params.fontsSC);
1964 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1965 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1966 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1967 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1969 fontModule->fontsDefaultCO->setCurrentIndex(n);
1972 int const psize = params.papersize;
1973 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1974 setCustomPapersize(psize);
1976 bool const landscape =
1977 params.orientation == ORIENTATION_LANDSCAPE;
1978 pageLayoutModule->landscapeRB->setChecked(landscape);
1979 pageLayoutModule->portraitRB->setChecked(!landscape);
1981 pageLayoutModule->facingPagesCB->setChecked(
1982 params.sides == TwoSides);
1985 lengthToWidgets(pageLayoutModule->paperwidthLE,
1986 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1988 lengthToWidgets(pageLayoutModule->paperheightLE,
1989 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1992 Ui::MarginsUi * m = marginsModule;
1994 setMargins(!params.use_geometry);
1996 lengthToWidgets(m->topLE, m->topUnit,
1997 params.topmargin, defaultUnit);
1999 lengthToWidgets(m->bottomLE, m->bottomUnit,
2000 params.bottommargin, defaultUnit);
2002 lengthToWidgets(m->innerLE, m->innerUnit,
2003 params.leftmargin, defaultUnit);
2005 lengthToWidgets(m->outerLE, m->outerUnit,
2006 params.rightmargin, defaultUnit);
2008 lengthToWidgets(m->headheightLE, m->headheightUnit,
2009 params.headheight, defaultUnit);
2011 lengthToWidgets(m->headsepLE, m->headsepUnit,
2012 params.headsep, defaultUnit);
2014 lengthToWidgets(m->footskipLE, m->footskipUnit,
2015 params.footskip, defaultUnit);
2017 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2018 params.columnsep, defaultUnit);
2020 branchesModule->update(params);
2023 PDFOptions const & pdf = params.pdfoptions();
2024 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2025 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2026 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2027 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2028 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2030 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2031 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2032 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2034 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2036 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2037 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2038 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2039 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2040 pdfSupportModule->backrefCB->setChecked(pdf.backref);
2041 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
2042 pdfSupportModule->fullscreenCB->setChecked
2043 (pdf.pagemode == pdf.pagemode_fullscreen);
2045 pdfSupportModule->optionsLE->setText(
2046 toqstr(pdf.quoted_options));
2050 void GuiDocument::applyView()
2056 void GuiDocument::saveDocDefault()
2058 // we have to apply the params first
2064 void GuiDocument::updateAvailableModules()
2066 modules_av_model_.clear();
2067 vector<modInfoStruct> const & modInfoList = getModuleInfo();
2068 int const mSize = modInfoList.size();
2069 for (int i = 0; i != mSize; ++i) {
2070 modInfoStruct const & modInfo = modInfoList[i];
2071 modules_av_model_.insertRow(i, modInfo.name, modInfo.id,
2072 modInfo.description);
2077 void GuiDocument::updateSelectedModules()
2079 // and selected ones, too
2080 modules_sel_model_.clear();
2081 vector<modInfoStruct> const selModList = getSelectedModules();
2082 int const sSize = selModList.size();
2083 for (int i = 0; i != sSize; ++i) {
2084 modInfoStruct const & modInfo = selModList[i];
2085 modules_sel_model_.insertRow(i, modInfo.name, modInfo.id,
2086 modInfo.description);
2091 void GuiDocument::updateContents()
2093 if (id() == current_id_)
2096 updateAvailableModules();
2097 updateSelectedModules();
2099 //FIXME It'd be nice to make sure here that the selected
2100 //modules are consistent: That required modules are actually
2101 //selected, and that we don't have conflicts. If so, we could
2102 //at least pop up a warning.
2108 void GuiDocument::forceUpdate()
2110 // reset to force dialog update
2116 void GuiDocument::useClassDefaults()
2118 if (applyPB->isEnabled()) {
2119 int const ret = Alert::prompt(_("Unapplied changes"),
2120 _("Some changes in the dialog were not yet applied.\n"
2121 "If you do not apply now, they will be lost after this action."),
2122 1, 1, _("&Apply"), _("&Dismiss"));
2127 int idx = latexModule->classCO->currentIndex();
2128 string const classname = classes_model_.getIDString(idx);
2129 if (!bp_.setBaseClass(classname)) {
2130 Alert::error(_("Error"), _("Unable to set document class."));
2133 bp_.useClassDefaults();
2138 void GuiDocument::setLayoutComboByIDString(std::string const & idString)
2140 int idx = classes_model_.findIDString(idString);
2142 Alert::warning(_("Can't set layout!"),
2143 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2145 latexModule->classCO->setCurrentIndex(idx);
2149 bool GuiDocument::isValid()
2151 return validate_listings_params().empty()
2152 && (textLayoutModule->skipCO->currentIndex() != 3
2153 || !textLayoutModule->skipLE->text().isEmpty());
2157 char const * const GuiDocument::fontfamilies[5] = {
2158 "default", "rmdefault", "sfdefault", "ttdefault", ""
2162 char const * GuiDocument::fontfamilies_gui[5] = {
2163 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2167 bool GuiDocument::initialiseParams(string const &)
2169 bp_ = buffer().params();
2170 // Force update on next updateContent() round.
2177 void GuiDocument::clearParams()
2179 bp_ = BufferParams();
2183 BufferId GuiDocument::id() const
2189 vector<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2191 return moduleNames_;
2195 vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2197 vector<string> const & mods = params().getModules();
2198 vector<string>::const_iterator it = mods.begin();
2199 vector<string>::const_iterator end = mods.end();
2200 vector<modInfoStruct> mInfo;
2201 for (; it != end; ++it) {
2204 LyXModule * mod = moduleList[*it];
2206 m.name = qt_(mod->getName());
2208 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
2215 DocumentClass const & GuiDocument::documentClass() const
2217 return bp_.documentClass();
2221 static void dispatch_bufferparams(Dialog const & dialog,
2222 BufferParams const & bp, FuncCode lfun)
2225 ss << "\\begin_header\n";
2227 ss << "\\end_header\n";
2228 dialog.dispatch(FuncRequest(lfun, ss.str()));
2232 void GuiDocument::dispatchParams()
2234 // This must come first so that a language change is correctly noticed
2237 // Apply the BufferParams. Note that this will set the base class
2238 // and then update the buffer's layout.
2239 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2241 if (!params().master.empty()) {
2242 FileName const master_file = support::makeAbsPath(params().master,
2243 support::onlyPath(buffer().absFileName()));
2244 if (isLyXFilename(master_file.absFilename())) {
2245 Buffer * master = checkAndLoadLyXFile(master_file);
2246 buffer().setParent(master);
2250 // Generate the colours requested by each new branch.
2251 BranchList & branchlist = params().branchlist();
2252 if (!branchlist.empty()) {
2253 BranchList::const_iterator it = branchlist.begin();
2254 BranchList::const_iterator const end = branchlist.end();
2255 for (; it != end; ++it) {
2256 docstring const & current_branch = it->getBranch();
2257 Branch const * branch = branchlist.find(current_branch);
2258 string const x11hexname = X11hexname(branch->getColor());
2259 // display the new color
2260 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2261 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2264 // Open insets of selected branches, close deselected ones
2265 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2268 // FIXME: If we used an LFUN, we would not need those two lines:
2269 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
2273 void GuiDocument::setLanguage() const
2275 Language const * const newL = bp_.language;
2276 if (buffer().params().language == newL)
2279 string const & lang_name = newL->lang();
2280 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2284 void GuiDocument::saveAsDefault() const
2286 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2290 bool GuiDocument::isFontAvailable(string const & font) const
2292 if (font == "default" || font == "cmr"
2293 || font == "cmss" || font == "cmtt")
2294 // these are standard
2296 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2297 return LaTeXFeatures::isAvailable("lmodern");
2298 if (font == "times" || font == "palatino"
2299 || font == "helvet" || font == "courier")
2300 return LaTeXFeatures::isAvailable("psnfss");
2301 if (font == "cmbr" || font == "cmtl")
2302 return LaTeXFeatures::isAvailable("cmbright");
2303 if (font == "utopia")
2304 return LaTeXFeatures::isAvailable("utopia")
2305 || LaTeXFeatures::isAvailable("fourier");
2306 if (font == "beraserif" || font == "berasans"
2307 || font == "beramono")
2308 return LaTeXFeatures::isAvailable("bera");
2309 return LaTeXFeatures::isAvailable(font);
2313 bool GuiDocument::providesOSF(string const & font) const
2316 return isFontAvailable("eco");
2317 if (font == "palatino")
2318 return isFontAvailable("mathpazo");
2323 bool GuiDocument::providesSC(string const & font) const
2325 if (font == "palatino")
2326 return isFontAvailable("mathpazo");
2327 if (font == "utopia")
2328 return isFontAvailable("fourier");
2333 bool GuiDocument::providesScale(string const & font) const
2335 return font == "helvet" || font == "luximono"
2336 || font == "berasans" || font == "beramono";
2340 void GuiDocument::loadModuleInfo()
2342 moduleNames_.clear();
2343 LyXModuleList::const_iterator it = moduleList.begin();
2344 LyXModuleList::const_iterator end = moduleList.end();
2345 for (; it != end; ++it) {
2348 m.name = qt_(it->getName());
2349 // this is supposed to give us the first sentence of the description
2350 QString desc = qt_(it->getDescription());
2351 int const pos = desc.indexOf(".");
2353 desc.truncate(pos + 1);
2354 m.description = desc;
2355 moduleNames_.push_back(m);
2360 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2363 } // namespace frontend
2366 #include "GuiDocument_moc.cpp"