2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "GuiApplication.h"
17 #include "GuiBranches.h"
18 #include "LaTeXHighlighter.h"
19 #include "LengthCombo.h"
20 #include "PanelStack.h"
21 #include "Validator.h"
23 #include "LayoutFile.h"
24 #include "BranchList.h"
25 #include "buffer_funcs.h"
27 #include "BufferParams.h"
28 #include "BufferView.h"
31 #include "FloatPlacement.h"
32 #include "FuncRequest.h"
34 #include "LaTeXFeatures.h"
36 #include "LyXRC.h" // defaultUnit
37 #include "ModuleList.h"
38 #include "OutputParams.h"
39 #include "PDFOptions.h"
40 #include "qt_helpers.h"
43 #include "insets/InsetListingsParams.h"
45 #include "support/debug.h"
46 #include "support/FileName.h"
47 #include "support/filetools.h"
48 #include "support/gettext.h"
49 #include "support/lstrings.h"
51 #include "frontends/alert.h"
53 #include <QCloseEvent>
55 #include <QTextCursor>
65 using namespace lyx::support;
70 char const * const tex_graphics[] =
72 "default", "dvips", "dvitops", "emtex",
73 "ln", "oztex", "textures", "none", ""
77 char const * const tex_graphics_gui[] =
79 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
80 "LN", "OzTeX", "Textures", N_("None"), ""
84 char const * const tex_fonts_roman[] =
86 "default", "cmr", "lmodern", "ae", "times", "palatino",
87 "charter", "newcent", "bookman", "utopia", "beraserif",
88 "ccfonts", "chancery", ""
92 char const * tex_fonts_roman_gui[] =
94 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
95 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
96 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
97 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
102 char const * const tex_fonts_sans[] =
104 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
108 char const * tex_fonts_sans_gui[] =
110 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
111 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
115 char const * const tex_fonts_monospaced[] =
117 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
121 char const * tex_fonts_monospaced_gui[] =
123 N_("Default"), N_("Computer Modern Typewriter"),
124 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
125 N_("LuxiMono"), N_("CM Typewriter Light"), ""
129 vector<pair<string, lyx::docstring> > pagestyles;
132 } // anonymous namespace
137 // used when sorting the textclass list.
138 class less_textclass_avail_desc
139 : public binary_function<string, string, int>
142 int operator()(string const & lhs, string const & rhs) const
144 // Ordering criteria:
145 // 1. Availability of text class
146 // 2. Description (lexicographic)
147 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
148 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
149 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
150 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
151 _(tc1.description()) < _(tc2.description()));
161 QModelIndex getSelectedIndex(QListView * lv)
163 QModelIndex retval = QModelIndex();
164 QModelIndexList selIdx =
165 lv->selectionModel()->selectedIndexes();
167 retval = selIdx.first();
173 vector<string> getRequiredList(string const & modName)
175 LyXModule const * const mod = moduleList[modName];
177 return vector<string>(); //empty such thing
178 return mod->getRequiredModules();
182 vector<string> getExcludedList(string const & modName)
184 LyXModule const * const mod = moduleList[modName];
186 return vector<string>(); //empty such thing
187 return mod->getExcludedModules();
191 docstring getModuleDescription(string const & modName)
193 LyXModule const * const mod = moduleList[modName];
195 return _("Module not found!");
196 return _(mod->getDescription());
200 vector<string> getPackageList(string const & modName)
202 LyXModule const * const mod = moduleList[modName];
204 return vector<string>(); //empty such thing
205 return mod->getPackageList();
209 bool isModuleAvailable(string const & modName)
211 LyXModule * mod = moduleList[modName];
214 return mod->isAvailable();
216 } //anonymous namespace
219 ModuleSelMan::ModuleSelMan(
220 QListView * availableLV,
221 QListView * selectedLV,
225 QPushButton * downPB,
226 GuiIdListModel * availableModel,
227 GuiIdListModel * selectedModel) :
228 GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
229 upPB, downPB, availableModel, selectedModel)
233 void ModuleSelMan::updateAddPB()
235 int const arows = availableModel->rowCount();
236 QModelIndexList const availSels =
237 availableLV->selectionModel()->selectedIndexes();
238 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
239 addPB->setEnabled(false);
243 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
244 string const modName = getAvailableModel()->getIDString(idx.row());
245 vector<string> reqs = getRequiredList(modName);
246 vector<string> excl = getExcludedList(modName);
248 if (reqs.empty() && excl.empty()) {
249 addPB->setEnabled(true);
253 int const srows = selectedModel->rowCount();
254 vector<string> selModList;
255 for (int i = 0; i < srows; ++i)
256 selModList.push_back(getSelectedModel()->getIDString(i));
258 vector<string>::const_iterator selModStart = selModList.begin();
259 vector<string>::const_iterator selModEnd = selModList.end();
261 //Check whether some required module is available
263 bool foundOne = false;
264 vector<string>::const_iterator it = reqs.begin();
265 vector<string>::const_iterator end = reqs.end();
266 for (; it != end; ++it) {
267 if (find(selModStart, selModEnd, *it) != selModEnd) {
273 addPB->setEnabled(false);
278 //Check whether any excluded module is being used
280 vector<string>::const_iterator it = excl.begin();
281 vector<string>::const_iterator end = excl.end();
282 for (; it != end; ++it) {
283 if (find(selModStart, selModEnd, *it) != selModEnd) {
284 addPB->setEnabled(false);
290 addPB->setEnabled(true);
294 void ModuleSelMan::updateDownPB()
296 int const srows = selectedModel->rowCount();
298 downPB->setEnabled(false);
301 QModelIndexList const selSels =
302 selectedLV->selectionModel()->selectedIndexes();
303 //disable if empty or last item is selected
304 if (selSels.empty() || selSels.first().row() == srows - 1) {
305 downPB->setEnabled(false);
308 //determine whether immediately succeding element requires this one
309 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
310 int curRow = curIdx.row();
311 if (curRow < 0 || curRow >= srows - 1) { //this shouldn't happen...
312 downPB->setEnabled(false);
315 string const curModName = getSelectedModel()->getIDString(curRow);
316 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
318 vector<string> reqs = getRequiredList(nextModName);
320 //if it doesn't require anything....
322 downPB->setEnabled(true);
326 //FIXME This should perhaps be more flexible and check whether, even
327 //if this one is required, there is also an earlier one that is required.
328 //enable it if this module isn't required
330 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
333 void ModuleSelMan::updateUpPB()
335 int const srows = selectedModel->rowCount();
337 upPB->setEnabled(false);
340 QModelIndexList const selSels =
341 selectedLV->selectionModel()->selectedIndexes();
342 //disable if empty or first item is selected
343 if (selSels.empty() || selSels.first().row() == 0) {
344 upPB->setEnabled(false);
348 //determine whether immediately preceding element is required by this one
349 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
350 int curRow = curIdx.row();
351 if (curRow <= -1 || curRow > srows - 1) { //sanity check
352 downPB->setEnabled(false);
355 string const curModName = getSelectedModel()->getIDString(curRow);
356 vector<string> reqs = getRequiredList(curModName);
358 //if this one doesn't require anything....
360 upPB->setEnabled(true);
364 string preModName = getSelectedModel()->getIDString(curRow - 1);
366 //NOTE This is less flexible than it might be. You could check whether, even
367 //if this one is required, there is also an earlier one that is required.
368 //enable it if the preceding module isn't required
369 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
372 void ModuleSelMan::updateDelPB()
374 int const srows = selectedModel->rowCount();
376 deletePB->setEnabled(false);
379 QModelIndexList const selSels =
380 selectedLV->selectionModel()->selectedIndexes();
381 if (selSels.empty() || selSels.first().row() < 0) {
382 deletePB->setEnabled(false);
386 //determine whether some LATER module requires this one
387 //NOTE Things are arranged so that this is the only way there
388 //can be a problem. At least, we hope so.
389 QModelIndex const & curIdx =
390 selectedLV->selectionModel()->currentIndex();
391 int const curRow = curIdx.row();
392 if (curRow < 0 || curRow >= srows) { //this shouldn't happen
393 deletePB->setEnabled(false);
397 QString const curModName = curIdx.data().toString();
399 //We're looking here for a reason NOT to enable the button. If we
400 //find one, we disable it and return. If we don't, we'll end up at
401 //the end of the function, and then we enable it.
402 for (int i = curRow + 1; i < srows; ++i) {
403 string const thisMod = getSelectedModel()->getIDString(i);
404 vector<string> reqs = getRequiredList(thisMod);
405 //does this one require us?
406 if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
410 //OK, so this module requires us
411 //is there an EARLIER module that also satisfies the require?
412 //NOTE We demand that it be earlier to keep the list of modules
413 //consistent with the rule that a module must be proceeded by a
414 //required module. There would be more flexible ways to proceed,
415 //but that would be a lot more complicated, and the logic here is
416 //already complicated. (That's why I've left the debugging code.)
417 //lyxerr << "Testing " << thisMod << std::endl;
418 bool foundOne = false;
419 for (int j = 0; j < curRow; ++j) {
420 string const mod = getSelectedModel()->getIDString(j);
421 //lyxerr << "In loop: Testing " << mod << std::endl;
422 //do we satisfy the require?
423 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
424 //lyxerr << mod << " does the trick." << std::endl;
429 //did we find a module to satisfy the require?
431 //lyxerr << "No matching module found." << std::endl;
432 deletePB->setEnabled(false);
436 //lyxerr << "All's well that ends well." << std::endl;
437 deletePB->setEnabled(true);
441 /////////////////////////////////////////////////////////////////////
445 /////////////////////////////////////////////////////////////////////
447 PreambleModule::PreambleModule(): current_id_(0)
449 // This is not a memory leak. The object will be destroyed
451 (void) new LaTeXHighlighter(preambleTE->document());
452 setFocusProxy(preambleTE);
453 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
457 void PreambleModule::update(BufferParams const & params, BufferId id)
459 QString preamble = toqstr(params.preamble);
460 // Nothing to do if the params and preamble are unchanged.
461 if (id == current_id_
462 && preamble == preambleTE->document()->toPlainText())
465 QTextCursor cur = preambleTE->textCursor();
466 // Save the coords before switching to the new one.
467 preamble_coords_[current_id_] =
468 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
470 // Save the params address for further use.
472 preambleTE->document()->setPlainText(preamble);
473 Coords::const_iterator it = preamble_coords_.find(current_id_);
474 if (it == preamble_coords_.end())
475 // First time we open this one.
476 preamble_coords_[current_id_] = make_pair(0,0);
478 // Restore saved coords.
479 QTextCursor cur = preambleTE->textCursor();
480 cur.setPosition(it->second.first);
481 preambleTE->setTextCursor(cur);
482 preambleTE->verticalScrollBar()->setValue(it->second.second);
487 void PreambleModule::apply(BufferParams & params)
489 params.preamble = fromqstr(preambleTE->document()->toPlainText());
493 void PreambleModule::closeEvent(QCloseEvent * e)
495 // Save the coords before closing.
496 QTextCursor cur = preambleTE->textCursor();
497 preamble_coords_[current_id_] =
498 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
503 /////////////////////////////////////////////////////////////////////
507 /////////////////////////////////////////////////////////////////////
510 GuiDocument::GuiDocument(GuiView & lv)
511 : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
515 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
516 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
517 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
518 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
520 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
521 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
523 // Manage the restore, ok, apply, restore and cancel/close buttons
524 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
526 bc().setApply(applyPB);
527 bc().setCancel(closePB);
528 bc().setRestore(restorePB);
530 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
532 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
533 this, SLOT(change_adaptor()));
534 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
535 this, SLOT(setLSpacing(int)));
536 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
537 this, SLOT(change_adaptor()));
538 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
539 this, SLOT(change_adaptor()));
540 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
541 this, SLOT(change_adaptor()));
542 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
543 this, SLOT(change_adaptor()));
544 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
545 this, SLOT(change_adaptor()));
546 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
547 this, SLOT(change_adaptor()));
548 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
549 this, SLOT(setSkip(int)));
550 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
551 this, SLOT(enableSkip(bool)));
552 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
553 this, SLOT(change_adaptor()));
554 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
555 this, SLOT(setColSep()));
556 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
557 this, SLOT(change_adaptor()));
558 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
559 this, SLOT(change_adaptor()));
560 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
561 this, SLOT(set_listings_msg()));
562 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
563 this, SLOT(set_listings_msg()));
564 textLayoutModule->listingsTB->setPlainText(
565 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
566 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
567 textLayoutModule->lspacingLE));
568 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
569 textLayoutModule->skipLE));
571 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
572 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
573 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
574 textLayoutModule->skipCO->addItem(qt_("Length"));
575 // remove the %-items from the unit choice
576 textLayoutModule->skipLengthCO->noPercents();
577 textLayoutModule->lspacingCO->insertItem(
578 Spacing::Single, qt_("Single"));
579 textLayoutModule->lspacingCO->insertItem(
580 Spacing::Onehalf, qt_("OneHalf"));
581 textLayoutModule->lspacingCO->insertItem(
582 Spacing::Double, qt_("Double"));
583 textLayoutModule->lspacingCO->insertItem(
584 Spacing::Other, qt_("Custom"));
586 // initialize the length validator
587 bc().addCheckedLineEdit(textLayoutModule->skipLE);
589 fontModule = new UiWidget<Ui::FontUi>;
591 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
592 this, SLOT(change_adaptor()));
593 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
594 this, SLOT(romanChanged(int)));
595 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
596 this, SLOT(change_adaptor()));
597 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
598 this, SLOT(sansChanged(int)));
599 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
600 this, SLOT(change_adaptor()));
601 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
602 this, SLOT(ttChanged(int)));
603 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
604 this, SLOT(change_adaptor()));
605 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
606 this, SLOT(change_adaptor()));
607 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
608 this, SLOT(change_adaptor()));
609 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
610 this, SLOT(change_adaptor()));
611 connect(fontModule->fontScCB, SIGNAL(clicked()),
612 this, SLOT(change_adaptor()));
613 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
614 this, SLOT(change_adaptor()));
616 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
617 QString font = qt_(tex_fonts_roman_gui[n]);
618 if (!isFontAvailable(tex_fonts_roman[n]))
619 font += qt_(" (not installed)");
620 fontModule->fontsRomanCO->addItem(font);
622 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
623 QString font = qt_(tex_fonts_sans_gui[n]);
624 if (!isFontAvailable(tex_fonts_sans[n]))
625 font += qt_(" (not installed)");
626 fontModule->fontsSansCO->addItem(font);
628 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
629 QString font = qt_(tex_fonts_monospaced_gui[n]);
630 if (!isFontAvailable(tex_fonts_monospaced[n]))
631 font += qt_(" (not installed)");
632 fontModule->fontsTypewriterCO->addItem(font);
635 fontModule->fontsizeCO->addItem(qt_("Default"));
636 fontModule->fontsizeCO->addItem(qt_("10"));
637 fontModule->fontsizeCO->addItem(qt_("11"));
638 fontModule->fontsizeCO->addItem(qt_("12"));
640 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
641 fontModule->fontsDefaultCO->addItem(
642 qt_(GuiDocument::fontfamilies_gui[n]));
645 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
647 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
648 this, SLOT(setCustomPapersize(int)));
649 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
650 this, SLOT(setCustomPapersize(int)));
651 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
652 this, SLOT(portraitChanged()));
653 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
654 this, SLOT(change_adaptor()));
655 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
656 this, SLOT(change_adaptor()));
657 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
658 this, SLOT(change_adaptor()));
659 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
660 this, SLOT(change_adaptor()));
661 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
662 this, SLOT(change_adaptor()));
663 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
664 this, SLOT(change_adaptor()));
665 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
666 this, SLOT(change_adaptor()));
667 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
668 this, SLOT(change_adaptor()));
669 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
670 this, SLOT(change_adaptor()));
672 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
673 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
674 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
675 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
676 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
677 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
678 pageLayoutModule->paperheightL);
679 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
680 pageLayoutModule->paperwidthL);
683 QComboBox * cb = pageLayoutModule->papersizeCO;
684 cb->addItem(qt_("Default"));
685 cb->addItem(qt_("Custom"));
686 cb->addItem(qt_("US letter"));
687 cb->addItem(qt_("US legal"));
688 cb->addItem(qt_("US executive"));
689 cb->addItem(qt_("A3"));
690 cb->addItem(qt_("A4"));
691 cb->addItem(qt_("A5"));
692 cb->addItem(qt_("B3"));
693 cb->addItem(qt_("B4"));
694 cb->addItem(qt_("B5"));
695 // remove the %-items from the unit choice
696 pageLayoutModule->paperwidthUnitCO->noPercents();
697 pageLayoutModule->paperheightUnitCO->noPercents();
698 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
699 pageLayoutModule->paperheightLE));
700 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
701 pageLayoutModule->paperwidthLE));
704 marginsModule = new UiWidget<Ui::MarginsUi>;
706 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
707 this, SLOT(setCustomMargins(bool)));
708 connect(marginsModule->marginCB, SIGNAL(clicked()),
709 this, SLOT(change_adaptor()));
710 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
711 this, SLOT(change_adaptor()));
712 connect(marginsModule->topUnit, SIGNAL(activated(int)),
713 this, SLOT(change_adaptor()));
714 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
715 this, SLOT(change_adaptor()));
716 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
717 this, SLOT(change_adaptor()));
718 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
719 this, SLOT(change_adaptor()));
720 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
721 this, SLOT(change_adaptor()));
722 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
723 this, SLOT(change_adaptor()));
724 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
725 this, SLOT(change_adaptor()));
726 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
727 this, SLOT(change_adaptor()));
728 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
729 this, SLOT(change_adaptor()));
730 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
731 this, SLOT(change_adaptor()));
732 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
733 this, SLOT(change_adaptor()));
734 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
735 this, SLOT(change_adaptor()));
736 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
737 this, SLOT(change_adaptor()));
738 connect(marginsModule->columnsepLE, SIGNAL(textChanged(const QString&)),
739 this, SLOT(change_adaptor()));
740 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
741 this, SLOT(change_adaptor()));
742 marginsModule->topLE->setValidator(unsignedLengthValidator(
743 marginsModule->topLE));
744 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
745 marginsModule->bottomLE));
746 marginsModule->innerLE->setValidator(unsignedLengthValidator(
747 marginsModule->innerLE));
748 marginsModule->outerLE->setValidator(unsignedLengthValidator(
749 marginsModule->outerLE));
750 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
751 marginsModule->headsepLE));
752 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
753 marginsModule->headheightLE));
754 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
755 marginsModule->footskipLE));
756 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
757 marginsModule->columnsepLE));
759 bc().addCheckedLineEdit(marginsModule->topLE,
760 marginsModule->topL);
761 bc().addCheckedLineEdit(marginsModule->bottomLE,
762 marginsModule->bottomL);
763 bc().addCheckedLineEdit(marginsModule->innerLE,
764 marginsModule->innerL);
765 bc().addCheckedLineEdit(marginsModule->outerLE,
766 marginsModule->outerL);
767 bc().addCheckedLineEdit(marginsModule->headsepLE,
768 marginsModule->headsepL);
769 bc().addCheckedLineEdit(marginsModule->headheightLE,
770 marginsModule->headheightL);
771 bc().addCheckedLineEdit(marginsModule->footskipLE,
772 marginsModule->footskipL);
773 bc().addCheckedLineEdit(marginsModule->columnsepLE,
774 marginsModule->columnsepL);
777 langModule = new UiWidget<Ui::LanguageUi>;
779 connect(langModule->languageCO, SIGNAL(activated(int)),
780 this, SLOT(change_adaptor()));
781 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
782 this, SLOT(change_adaptor()));
783 connect(langModule->otherencodingRB, SIGNAL(clicked()),
784 this, SLOT(change_adaptor()));
785 connect(langModule->encodingCO, SIGNAL(activated(int)),
786 this, SLOT(change_adaptor()));
787 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
788 this, SLOT(change_adaptor()));
790 langModule->languageCO->setModel(guiApp->languageModel());
792 // Always put the default encoding in the first position.
793 // It is special because the displayed text is translated.
794 langModule->encodingCO->addItem(qt_("LaTeX default"));
795 Encodings::const_iterator it = encodings.begin();
796 Encodings::const_iterator const end = encodings.end();
797 for (; it != end; ++it)
798 langModule->encodingCO->addItem(toqstr(it->latexName()));
800 langModule->quoteStyleCO->addItem(qt_("``text''"));
801 langModule->quoteStyleCO->addItem(qt_("''text''"));
802 langModule->quoteStyleCO->addItem(qt_(",,text``"));
803 langModule->quoteStyleCO->addItem(qt_(",,text''"));
804 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
805 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
808 numberingModule = new UiWidget<Ui::NumberingUi>;
810 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
811 this, SLOT(change_adaptor()));
812 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
813 this, SLOT(change_adaptor()));
814 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
815 this, SLOT(updateNumbering()));
816 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
817 this, SLOT(updateNumbering()));
818 numberingModule->tocTW->setColumnCount(3);
819 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
820 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
821 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
824 biblioModule = new UiWidget<Ui::BiblioUi>;
825 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
826 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
827 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
828 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
830 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
831 this, SLOT(change_adaptor()));
832 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
833 this, SLOT(change_adaptor()));
834 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
835 this, SLOT(change_adaptor()));
836 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
837 this, SLOT(change_adaptor()));
838 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
839 this, SLOT(change_adaptor()));
841 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
842 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
843 biblioModule->citeStyleCO->setCurrentIndex(0);
846 mathsModule = new UiWidget<Ui::MathsUi>;
847 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
848 mathsModule->amsCB, SLOT(setDisabled(bool)));
849 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
850 mathsModule->esintCB, SLOT(setDisabled(bool)));
852 connect(mathsModule->amsCB, SIGNAL(clicked()),
853 this, SLOT(change_adaptor()));
854 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
855 this, SLOT(change_adaptor()));
856 connect(mathsModule->esintCB, SIGNAL(clicked()),
857 this, SLOT(change_adaptor()));
858 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
859 this, SLOT(change_adaptor()));
861 latexModule = new UiWidget<Ui::LaTeXUi>;
863 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
864 this, SLOT(change_adaptor()));
865 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
866 this, SLOT(change_adaptor()));
867 connect(latexModule->classCO, SIGNAL(activated(int)),
868 this, SLOT(classChanged()));
869 connect(latexModule->classCO, SIGNAL(activated(int)),
870 this, SLOT(change_adaptor()));
871 connect(latexModule->layoutPB, SIGNAL(clicked()),
872 this, SLOT(browseLayout()));
873 connect(latexModule->childDocGB, SIGNAL(clicked()),
874 this, SLOT(change_adaptor()));
875 connect(latexModule->childDocLE, SIGNAL(textChanged(const QString &)),
876 this, SLOT(change_adaptor()));
877 connect(latexModule->childDocPB, SIGNAL(clicked()),
878 this, SLOT(browseMaster()));
881 new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
882 latexModule->addPB, latexModule->deletePB,
883 latexModule->upPB, latexModule->downPB,
884 availableModel(), selectedModel());
885 connect(selectionManager, SIGNAL(updateHook()),
886 this, SLOT(updateModuleInfo()));
887 connect(selectionManager, SIGNAL(updateHook()),
888 this, SLOT(change_adaptor()));
890 // postscript drivers
891 for (int n = 0; tex_graphics[n][0]; ++n) {
892 QString enc = qt_(tex_graphics_gui[n]);
893 latexModule->psdriverCO->addItem(enc);
896 latexModule->classCO->setModel(&classes_model_);
897 LayoutFileList const & bcl = LayoutFileList::get();
898 vector<LayoutFileIndex> classList = bcl.classList();
899 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
901 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
902 vector<LayoutFileIndex>::const_iterator cen = classList.end();
903 for (int i = 0; cit != cen; ++cit, ++i) {
904 LayoutFile const & tc = bcl[*cit];
905 docstring item = (tc.isTeXClassAvailable()) ?
906 from_utf8(tc.description()) :
907 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
908 classes_model_.insertRow(i, toqstr(item), *cit);
912 branchesModule = new GuiBranches;
913 connect(branchesModule, SIGNAL(changed()),
914 this, SLOT(change_adaptor()));
917 preambleModule = new PreambleModule;
918 connect(preambleModule, SIGNAL(changed()),
919 this, SLOT(change_adaptor()));
922 bulletsModule = new BulletsModule;
923 connect(bulletsModule, SIGNAL(changed()),
924 this, SLOT(change_adaptor()));
927 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
929 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
930 this, SLOT(change_adaptor()));
931 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
932 this, SLOT(change_adaptor()));
933 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
934 this, SLOT(change_adaptor()));
935 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
936 this, SLOT(change_adaptor()));
937 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
938 this, SLOT(change_adaptor()));
939 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
940 this, SLOT(change_adaptor()));
941 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
942 this, SLOT(change_adaptor()));
943 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
944 this, SLOT(change_adaptor()));
945 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
946 this, SLOT(change_adaptor()));
947 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
948 this, SLOT(change_adaptor()));
949 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
950 this, SLOT(change_adaptor()));
951 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
952 this, SLOT(change_adaptor()));
953 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
954 this, SLOT(change_adaptor()));
955 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
956 this, SLOT(change_adaptor()));
957 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
958 this, SLOT(change_adaptor()));
959 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
960 this, SLOT(change_adaptor()));
961 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
962 this, SLOT(change_adaptor()));
965 floatModule = new FloatPlacement;
966 connect(floatModule, SIGNAL(changed()),
967 this, SLOT(change_adaptor()));
969 docPS->addPanel(latexModule, qt_("Document Class"));
970 docPS->addPanel(fontModule, qt_("Fonts"));
971 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
972 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
973 docPS->addPanel(marginsModule, qt_("Page Margins"));
974 docPS->addPanel(langModule, qt_("Language"));
975 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
976 docPS->addPanel(biblioModule, qt_("Bibliography"));
977 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
978 docPS->addPanel(mathsModule, qt_("Math Options"));
979 docPS->addPanel(floatModule, qt_("Float Placement"));
980 docPS->addPanel(bulletsModule, qt_("Bullets"));
981 docPS->addPanel(branchesModule, qt_("Branches"));
982 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
983 docPS->setCurrentPanel(qt_("Document Class"));
984 // FIXME: hack to work around resizing bug in Qt >= 4.2
985 // bug verified with Qt 4.2.{0-3} (JSpitzm)
986 #if QT_VERSION >= 0x040200
987 docPS->updateGeometry();
992 void GuiDocument::showPreamble()
994 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
998 void GuiDocument::saveDefaultClicked()
1004 void GuiDocument::useDefaultsClicked()
1010 void GuiDocument::change_adaptor()
1016 docstring GuiDocument::validate_listings_params()
1018 // use a cache here to avoid repeated validation
1019 // of the same parameters
1020 static string param_cache = string();
1021 static docstring msg_cache = docstring();
1023 if (textLayoutModule->bypassCB->isChecked())
1026 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1027 if (params != param_cache) {
1028 param_cache = params;
1029 msg_cache = InsetListingsParams(params).validate();
1035 void GuiDocument::set_listings_msg()
1037 static bool isOK = true;
1038 docstring msg = validate_listings_params();
1043 // listingsTB->setTextColor("black");
1044 textLayoutModule->listingsTB->setPlainText(
1045 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
1048 // listingsTB->setTextColor("red");
1049 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
1054 void GuiDocument::setLSpacing(int item)
1056 textLayoutModule->lspacingLE->setEnabled(item == 3);
1060 void GuiDocument::setSkip(int item)
1062 bool const enable = (item == 3);
1063 textLayoutModule->skipLE->setEnabled(enable);
1064 textLayoutModule->skipLengthCO->setEnabled(enable);
1068 void GuiDocument::enableSkip(bool skip)
1070 textLayoutModule->skipCO->setEnabled(skip);
1071 textLayoutModule->skipLE->setEnabled(skip);
1072 textLayoutModule->skipLengthCO->setEnabled(skip);
1074 setSkip(textLayoutModule->skipCO->currentIndex());
1077 void GuiDocument::portraitChanged()
1079 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1082 void GuiDocument::setMargins(bool custom)
1084 marginsModule->marginCB->setChecked(custom);
1085 setCustomMargins(custom);
1089 void GuiDocument::setCustomPapersize(int papersize)
1091 bool const custom = (papersize == 1);
1093 pageLayoutModule->paperwidthL->setEnabled(custom);
1094 pageLayoutModule->paperwidthLE->setEnabled(custom);
1095 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1096 pageLayoutModule->paperheightL->setEnabled(custom);
1097 pageLayoutModule->paperheightLE->setEnabled(custom);
1098 pageLayoutModule->paperheightLE->setFocus();
1099 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1103 void GuiDocument::setColSep()
1105 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1109 void GuiDocument::setCustomMargins(bool custom)
1111 marginsModule->topL->setEnabled(!custom);
1112 marginsModule->topLE->setEnabled(!custom);
1113 marginsModule->topUnit->setEnabled(!custom);
1115 marginsModule->bottomL->setEnabled(!custom);
1116 marginsModule->bottomLE->setEnabled(!custom);
1117 marginsModule->bottomUnit->setEnabled(!custom);
1119 marginsModule->innerL->setEnabled(!custom);
1120 marginsModule->innerLE->setEnabled(!custom);
1121 marginsModule->innerUnit->setEnabled(!custom);
1123 marginsModule->outerL->setEnabled(!custom);
1124 marginsModule->outerLE->setEnabled(!custom);
1125 marginsModule->outerUnit->setEnabled(!custom);
1127 marginsModule->headheightL->setEnabled(!custom);
1128 marginsModule->headheightLE->setEnabled(!custom);
1129 marginsModule->headheightUnit->setEnabled(!custom);
1131 marginsModule->headsepL->setEnabled(!custom);
1132 marginsModule->headsepLE->setEnabled(!custom);
1133 marginsModule->headsepUnit->setEnabled(!custom);
1135 marginsModule->footskipL->setEnabled(!custom);
1136 marginsModule->footskipLE->setEnabled(!custom);
1137 marginsModule->footskipUnit->setEnabled(!custom);
1139 bool const enableColSep = !custom &&
1140 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1141 marginsModule->columnsepL->setEnabled(enableColSep);
1142 marginsModule->columnsepLE->setEnabled(enableColSep);
1143 marginsModule->columnsepUnit->setEnabled(enableColSep);
1147 void GuiDocument::updateFontsize(string const & items, string const & sel)
1149 fontModule->fontsizeCO->clear();
1150 fontModule->fontsizeCO->addItem(qt_("Default"));
1152 for (int n = 0; !token(items,'|',n).empty(); ++n)
1153 fontModule->fontsizeCO->
1154 addItem(toqstr(token(items,'|',n)));
1156 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1157 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1158 fontModule->fontsizeCO->setCurrentIndex(n);
1165 void GuiDocument::romanChanged(int item)
1167 string const font = tex_fonts_roman[item];
1168 fontModule->fontScCB->setEnabled(providesSC(font));
1169 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1173 void GuiDocument::sansChanged(int item)
1175 string const font = tex_fonts_sans[item];
1176 bool scaleable = providesScale(font);
1177 fontModule->scaleSansSB->setEnabled(scaleable);
1178 fontModule->scaleSansLA->setEnabled(scaleable);
1182 void GuiDocument::ttChanged(int item)
1184 string const font = tex_fonts_monospaced[item];
1185 bool scaleable = providesScale(font);
1186 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1187 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1191 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1194 pageLayoutModule->pagestyleCO->clear();
1195 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1197 for (int n = 0; !token(items,'|',n).empty(); ++n) {
1198 string style = token(items, '|', n);
1199 docstring style_gui = _(style);
1200 pagestyles.push_back(pair<string, docstring>(style, style_gui));
1201 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
1204 if (sel == "default") {
1205 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1211 for (size_t i = 0; i < pagestyles.size(); ++i)
1212 if (pagestyles[i].first == sel)
1213 nn = pageLayoutModule->pagestyleCO->findText(
1214 toqstr(pagestyles[i].second));
1217 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1221 void GuiDocument::browseLayout()
1223 QString const label1 = qt_("Layouts|#o#O");
1224 QString const dir1 = toqstr(lyxrc.document_path);
1225 QStringList const filter(qt_("LyX Layout (*.layout)"));
1226 QString file = browseRelFile(QString(), bufferFilepath(),
1227 qt_("Local layout file"), filter, false,
1230 if (!file.endsWith(".layout"))
1233 FileName layoutFile = support::makeAbsPath(fromqstr(file),
1234 fromqstr(bufferFilepath()));
1236 // load the layout file
1237 LayoutFileList & bcl = LayoutFileList::get();
1238 string classname = layoutFile.onlyFileName();
1239 LayoutFileIndex name = bcl.addLayoutFile(
1240 classname.substr(0, classname.size() - 7),
1241 layoutFile.onlyPath().absFilename(),
1242 LayoutFileList::Local);
1245 Alert::error(_("Error"),
1246 _("Unable to read local layout file."));
1250 // do not trigger classChanged if there is no change.
1251 if (latexModule->classCO->currentText() == toqstr(name))
1255 int idx = latexModule->classCO->findText(toqstr(name));
1257 classes_model_.insertRow(0, toqstr(name), name);
1258 latexModule->classCO->setCurrentIndex(0);
1260 latexModule->classCO->setCurrentIndex(idx);
1265 void GuiDocument::browseMaster()
1267 QString const title = qt_("Select master document");
1268 QString const dir1 = toqstr(lyxrc.document_path);
1269 QString const old = latexModule->childDocLE->text();
1270 QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1271 QStringList const filter(qt_("LyX Files (*.lyx)"));
1272 QString file = browseRelFile(old, docpath, title, filter, false,
1273 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1275 latexModule->childDocLE->setText(file);
1279 void GuiDocument::classChanged()
1281 int idx = latexModule->classCO->currentIndex();
1284 string const classname = classes_model_.getIDString(idx);
1285 // check if this is a local layout file
1286 if (prefixIs(classname, LayoutFileList::localPrefix)) {
1287 int const ret = Alert::prompt(_("Local layout file"),
1288 _("The layout file you have selected is a local layout\n"
1289 "file, not one in the system or user directory. Your\n"
1290 "document may not work with this layout if you do not\n"
1291 "keep the layout file in the same directory."),
1292 1, 1, _("&Set Layout"), _("&Cancel"));
1294 // try to reset the layout combo
1295 setLayoutComboByIDString(bp_.baseClassID());
1299 // FIXME Note that by doing things this way, we load the TextClass
1300 // as soon as it is selected. So, if you use the scroll wheel when
1301 // sitting on the combo box, we'll load a lot of TextClass objects
1302 // very quickly. This could be changed.
1303 if (!bp_.setBaseClass(classname)) {
1304 Alert::error(_("Error"), _("Unable to set document class."));
1307 if (lyxrc.auto_reset_options) {
1308 if (applyPB->isEnabled()) {
1309 int const ret = Alert::prompt(_("Unapplied changes"),
1310 _("Some changes in the dialog were not yet applied.\n"
1311 "If you do not apply now, they will be lost after this action."),
1312 1, 1, _("&Apply"), _("&Dismiss"));
1316 bp_.useClassDefaults();
1323 // This is an insanely complicated attempt to make this sort of thing
1324 // work with RTL languages.
1325 docstring formatStrVec(vector<string> const & v, docstring const & s)
1327 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1328 int const vSize = v.size();
1331 else if (v.size() == 1)
1332 return from_ascii(v[0]);
1333 else if (v.size() == 2) {
1334 docstring retval = _("%1$s and %2$s");
1335 retval = subst(retval, _("and"), s);
1336 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1338 //The idea here is to format all but the last two items...
1339 docstring t2 = _("%1$s, %2$s");
1340 docstring retval = from_ascii(v[0]);
1341 for (int i = 1; i < vSize - 2; ++i)
1342 retval = bformat(t2, retval, from_ascii(v[i]));
1343 //...and then to plug them, and the last two, into this schema
1344 docstring t = _("%1$s, %2$s, and %3$s");
1345 t = subst(t, _("and"), s);
1346 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1349 vector<string> idsToNames(vector<string> const & idList)
1351 vector<string> retval;
1352 vector<string>::const_iterator it = idList.begin();
1353 vector<string>::const_iterator end = idList.end();
1354 for (; it != end; ++it) {
1355 LyXModule const * const mod = moduleList[*it];
1357 retval.push_back(*it + " (Unavailable)");
1359 retval.push_back(mod->getName());
1366 void GuiDocument::updateModuleInfo()
1368 selectionManager->update();
1370 //Module description
1371 bool const focusOnSelected = selectionManager->selectedFocused();
1372 QListView const * const lv =
1373 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1374 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1375 latexModule->infoML->document()->clear();
1378 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1379 GuiIdListModel const & idModel =
1380 focusOnSelected ? modules_sel_model_ : modules_av_model_;
1381 string const modName = idModel.getIDString(idx.row());
1382 docstring desc = getModuleDescription(modName);
1384 vector<string> pkgList = getPackageList(modName);
1385 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1386 if (!pkgdesc.empty()) {
1389 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1392 pkgList = getRequiredList(modName);
1393 if (!pkgList.empty()) {
1394 vector<string> const reqDescs = idsToNames(pkgList);
1395 pkgdesc = formatStrVec(reqDescs, _("or"));
1398 desc += bformat(_("Module required: %1$s."), pkgdesc);
1401 pkgList = getExcludedList(modName);
1402 if (!pkgList.empty()) {
1403 vector<string> const reqDescs = idsToNames(pkgList);
1404 pkgdesc = formatStrVec(reqDescs, _( "and"));
1407 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1410 if (!isModuleAvailable(modName)) {
1413 desc += _("WARNING: Some packages are unavailable!");
1416 latexModule->infoML->document()->setPlainText(toqstr(desc));
1420 void GuiDocument::updateNumbering()
1422 DocumentClass const & tclass = bp_.documentClass();
1424 numberingModule->tocTW->setUpdatesEnabled(false);
1425 numberingModule->tocTW->clear();
1427 int const depth = numberingModule->depthSL->value();
1428 int const toc = numberingModule->tocSL->value();
1429 QString const no = qt_("No");
1430 QString const yes = qt_("Yes");
1431 QTreeWidgetItem * item = 0;
1433 DocumentClass::const_iterator lit = tclass.begin();
1434 DocumentClass::const_iterator len = tclass.end();
1435 for (; lit != len; ++lit) {
1436 int const toclevel = lit->toclevel;
1437 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1438 item = new QTreeWidgetItem(numberingModule->tocTW);
1439 item->setText(0, toqstr(translateIfPossible(lit->name())));
1440 item->setText(1, (toclevel <= depth) ? yes : no);
1441 item->setText(2, (toclevel <= toc) ? yes : no);
1445 numberingModule->tocTW->setUpdatesEnabled(true);
1446 numberingModule->tocTW->update();
1450 void GuiDocument::apply(BufferParams & params)
1453 preambleModule->apply(params);
1456 params.setCiteEngine(ENGINE_BASIC);
1458 if (biblioModule->citeNatbibRB->isChecked()) {
1459 bool const use_numerical_citations =
1460 biblioModule->citeStyleCO->currentIndex();
1461 if (use_numerical_citations)
1462 params.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
1464 params.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
1466 } else if (biblioModule->citeJurabibRB->isChecked())
1467 params.setCiteEngine(ENGINE_JURABIB);
1469 params.use_bibtopic =
1470 biblioModule->bibtopicCB->isChecked();
1472 // language & quotes
1473 if (langModule->defaultencodingRB->isChecked()) {
1474 params.inputenc = "auto";
1476 int i = langModule->encodingCO->currentIndex();
1478 params.inputenc = "default";
1481 fromqstr(langModule->encodingCO->currentText());
1484 InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
1485 switch (langModule->quoteStyleCO->currentIndex()) {
1487 lga = InsetQuotes::EnglishQuotes;
1490 lga = InsetQuotes::SwedishQuotes;
1493 lga = InsetQuotes::GermanQuotes;
1496 lga = InsetQuotes::PolishQuotes;
1499 lga = InsetQuotes::FrenchQuotes;
1502 lga = InsetQuotes::DanishQuotes;
1505 params.quotes_language = lga;
1507 QString const lang = langModule->languageCO->itemData(
1508 langModule->languageCO->currentIndex()).toString();
1509 params.language = lyx::languages.getLanguage(fromqstr(lang));
1512 if (params.documentClass().hasTocLevels()) {
1513 params.tocdepth = numberingModule->tocSL->value();
1514 params.secnumdepth = numberingModule->depthSL->value();
1518 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1519 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1520 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1521 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1524 params.graphicsDriver =
1525 tex_graphics[latexModule->psdriverCO->currentIndex()];
1528 int idx = latexModule->classCO->currentIndex();
1530 string const classname = classes_model_.getIDString(idx);
1531 params.setBaseClass(classname);
1535 params.clearLayoutModules();
1536 int const srows = modules_sel_model_.rowCount();
1537 vector<string> selModList;
1538 for (int i = 0; i < srows; ++i)
1539 params.addLayoutModule(modules_sel_model_.getIDString(i));
1541 if (mathsModule->amsautoCB->isChecked()) {
1542 params.use_amsmath = BufferParams::package_auto;
1544 if (mathsModule->amsCB->isChecked())
1545 params.use_amsmath = BufferParams::package_on;
1547 params.use_amsmath = BufferParams::package_off;
1550 if (mathsModule->esintautoCB->isChecked())
1551 params.use_esint = BufferParams::package_auto;
1553 if (mathsModule->esintCB->isChecked())
1554 params.use_esint = BufferParams::package_on;
1556 params.use_esint = BufferParams::package_off;
1559 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1560 params.pagestyle = "default";
1562 docstring style_gui =
1563 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1564 for (size_t i = 0; i < pagestyles.size(); ++i)
1565 if (pagestyles[i].second == style_gui)
1566 params.pagestyle = pagestyles[i].first;
1569 switch (textLayoutModule->lspacingCO->currentIndex()) {
1571 params.spacing().set(Spacing::Single);
1574 params.spacing().set(Spacing::Onehalf);
1577 params.spacing().set(Spacing::Double);
1580 params.spacing().set(Spacing::Other,
1581 fromqstr(textLayoutModule->lspacingLE->text()));
1585 if (textLayoutModule->twoColumnCB->isChecked())
1590 // text should have passed validation
1591 params.listings_params =
1592 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1594 if (textLayoutModule->indentRB->isChecked())
1595 params.paragraph_separation = BufferParams::ParagraphIndentSeparation;
1597 params.paragraph_separation = BufferParams::ParagraphSkipSeparation;
1599 switch (textLayoutModule->skipCO->currentIndex()) {
1601 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1604 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1607 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1612 widgetsToLength(textLayoutModule->skipLE,
1613 textLayoutModule->skipLengthCO)
1615 params.setDefSkip(vs);
1619 // DocumentDefskipCB assures that this never happens
1620 // so Assert then !!! - jbl
1621 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1626 fromqstr(latexModule->optionsLE->text());
1628 if (latexModule->childDocGB->isChecked())
1630 fromqstr(latexModule->childDocLE->text());
1632 params.master = string();
1634 params.float_placement = floatModule->get();
1638 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1641 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1643 params.fontsTypewriter =
1644 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1646 params.fontsSansScale = fontModule->scaleSansSB->value();
1648 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1650 params.fontsSC = fontModule->fontScCB->isChecked();
1652 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1654 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1655 fontModule->fontsDefaultCO->currentIndex()];
1657 if (fontModule->fontsizeCO->currentIndex() == 0)
1658 params.fontsize = "default";
1661 fromqstr(fontModule->fontsizeCO->currentText());
1664 params.papersize = PAPER_SIZE(
1665 pageLayoutModule->papersizeCO->currentIndex());
1667 // custom, A3, B3 and B4 paper sizes need geometry
1668 int psize = pageLayoutModule->papersizeCO->currentIndex();
1669 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1671 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1672 pageLayoutModule->paperwidthUnitCO);
1674 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1675 pageLayoutModule->paperheightUnitCO);
1677 if (pageLayoutModule->facingPagesCB->isChecked())
1678 params.sides = TwoSides;
1680 params.sides = OneSide;
1682 if (pageLayoutModule->landscapeRB->isChecked())
1683 params.orientation = ORIENTATION_LANDSCAPE;
1685 params.orientation = ORIENTATION_PORTRAIT;
1688 params.use_geometry = !marginsModule->marginCB->isChecked()
1691 Ui::MarginsUi const * m = marginsModule;
1693 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1694 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1695 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1696 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1697 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1698 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1699 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1700 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1702 branchesModule->apply(params);
1705 PDFOptions & pdf = params.pdfoptions();
1706 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1707 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1708 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1709 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1710 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1712 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1713 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1714 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1715 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1717 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1718 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1719 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1720 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1721 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1722 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1723 if (pdfSupportModule->fullscreenCB->isChecked())
1724 pdf.pagemode = pdf.pagemode_fullscreen;
1726 pdf.pagemode.clear();
1727 pdf.quoted_options = pdf.quoted_options_check(
1728 fromqstr(pdfSupportModule->optionsLE->text()));
1732 void GuiDocument::updateParams()
1738 void GuiDocument::updateParams(BufferParams const & params)
1740 // set the default unit
1741 Length::UNIT defaultUnit = Length::CM;
1742 switch (lyxrc.default_papersize) {
1743 case PAPER_DEFAULT: break;
1745 case PAPER_USLETTER:
1747 case PAPER_USEXECUTIVE:
1748 defaultUnit = Length::IN;
1757 defaultUnit = Length::CM;
1764 preambleModule->update(params, id());
1767 biblioModule->citeDefaultRB->setChecked(
1768 params.citeEngine() == ENGINE_BASIC);
1770 biblioModule->citeNatbibRB->setChecked(
1771 params.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
1772 params.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
1774 biblioModule->citeStyleCO->setCurrentIndex(
1775 params.citeEngine() == ENGINE_NATBIB_NUMERICAL);
1777 biblioModule->citeJurabibRB->setChecked(
1778 params.citeEngine() == ENGINE_JURABIB);
1780 biblioModule->bibtopicCB->setChecked(
1781 params.use_bibtopic);
1783 // language & quotes
1784 int const pos = langModule->languageCO->findData(toqstr(
1785 params.language->lang()));
1786 langModule->languageCO->setCurrentIndex(pos);
1788 langModule->quoteStyleCO->setCurrentIndex(
1789 params.quotes_language);
1791 bool default_enc = true;
1792 if (params.inputenc != "auto") {
1793 default_enc = false;
1794 if (params.inputenc == "default") {
1795 langModule->encodingCO->setCurrentIndex(0);
1797 int const i = langModule->encodingCO->findText(
1798 toqstr(params.inputenc));
1800 langModule->encodingCO->setCurrentIndex(i);
1802 // unknown encoding. Set to default.
1806 langModule->defaultencodingRB->setChecked(default_enc);
1807 langModule->otherencodingRB->setChecked(!default_enc);
1810 int const min_toclevel = documentClass().min_toclevel();
1811 int const max_toclevel = documentClass().max_toclevel();
1812 if (documentClass().hasTocLevels()) {
1813 numberingModule->setEnabled(true);
1814 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1815 numberingModule->depthSL->setMaximum(max_toclevel);
1816 numberingModule->depthSL->setValue(params.secnumdepth);
1817 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1818 numberingModule->tocSL->setMaximum(max_toclevel);
1819 numberingModule->tocSL->setValue(params.tocdepth);
1822 numberingModule->setEnabled(false);
1823 numberingModule->tocTW->clear();
1827 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1828 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1829 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1830 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1831 bulletsModule->init();
1834 int nitem = findToken(tex_graphics, params.graphicsDriver);
1836 latexModule->psdriverCO->setCurrentIndex(nitem);
1839 mathsModule->amsCB->setChecked(
1840 params.use_amsmath == BufferParams::package_on);
1841 mathsModule->amsautoCB->setChecked(
1842 params.use_amsmath == BufferParams::package_auto);
1844 mathsModule->esintCB->setChecked(
1845 params.use_esint == BufferParams::package_on);
1846 mathsModule->esintautoCB->setChecked(
1847 params.use_esint == BufferParams::package_auto);
1849 switch (params.spacing().getSpace()) {
1850 case Spacing::Other: nitem = 3; break;
1851 case Spacing::Double: nitem = 2; break;
1852 case Spacing::Onehalf: nitem = 1; break;
1853 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1857 string const & layoutID = params.baseClassID();
1858 setLayoutComboByIDString(layoutID);
1860 updatePagestyle(documentClass().opt_pagestyle(),
1863 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1864 if (params.spacing().getSpace() == Spacing::Other) {
1865 textLayoutModule->lspacingLE->setText(
1866 toqstr(params.spacing().getValueAsString()));
1870 if (params.paragraph_separation == BufferParams::ParagraphIndentSeparation)
1871 textLayoutModule->indentRB->setChecked(true);
1873 textLayoutModule->skipRB->setChecked(true);
1876 switch (params.getDefSkip().kind()) {
1877 case VSpace::SMALLSKIP:
1880 case VSpace::MEDSKIP:
1883 case VSpace::BIGSKIP:
1886 case VSpace::LENGTH:
1889 string const length = params.getDefSkip().asLyXCommand();
1890 lengthToWidgets(textLayoutModule->skipLE,
1891 textLayoutModule->skipLengthCO,
1892 length, defaultUnit);
1899 textLayoutModule->skipCO->setCurrentIndex(skip);
1902 textLayoutModule->twoColumnCB->setChecked(
1903 params.columns == 2);
1905 // break listings_params to multiple lines
1907 InsetListingsParams(params.listings_params).separatedParams();
1908 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1910 if (!params.options.empty()) {
1911 latexModule->optionsLE->setText(
1912 toqstr(params.options));
1914 latexModule->optionsLE->setText(QString());
1917 if (!params.master.empty()) {
1918 latexModule->childDocGB->setChecked(true);
1919 latexModule->childDocLE->setText(
1920 toqstr(params.master));
1922 latexModule->childDocLE->setText(QString());
1923 latexModule->childDocGB->setChecked(false);
1926 floatModule->set(params.float_placement);
1929 updateFontsize(documentClass().opt_fontsize(),
1932 int n = findToken(tex_fonts_roman, params.fontsRoman);
1934 fontModule->fontsRomanCO->setCurrentIndex(n);
1938 n = findToken(tex_fonts_sans, params.fontsSans);
1940 fontModule->fontsSansCO->setCurrentIndex(n);
1944 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1946 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1950 fontModule->fontScCB->setChecked(params.fontsSC);
1951 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1952 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1953 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1954 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1956 fontModule->fontsDefaultCO->setCurrentIndex(n);
1959 int const psize = params.papersize;
1960 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1961 setCustomPapersize(psize);
1963 bool const landscape =
1964 params.orientation == ORIENTATION_LANDSCAPE;
1965 pageLayoutModule->landscapeRB->setChecked(landscape);
1966 pageLayoutModule->portraitRB->setChecked(!landscape);
1968 pageLayoutModule->facingPagesCB->setChecked(
1969 params.sides == TwoSides);
1972 lengthToWidgets(pageLayoutModule->paperwidthLE,
1973 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1975 lengthToWidgets(pageLayoutModule->paperheightLE,
1976 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1979 Ui::MarginsUi * m = marginsModule;
1981 setMargins(!params.use_geometry);
1983 lengthToWidgets(m->topLE, m->topUnit,
1984 params.topmargin, defaultUnit);
1986 lengthToWidgets(m->bottomLE, m->bottomUnit,
1987 params.bottommargin, defaultUnit);
1989 lengthToWidgets(m->innerLE, m->innerUnit,
1990 params.leftmargin, defaultUnit);
1992 lengthToWidgets(m->outerLE, m->outerUnit,
1993 params.rightmargin, defaultUnit);
1995 lengthToWidgets(m->headheightLE, m->headheightUnit,
1996 params.headheight, defaultUnit);
1998 lengthToWidgets(m->headsepLE, m->headsepUnit,
1999 params.headsep, defaultUnit);
2001 lengthToWidgets(m->footskipLE, m->footskipUnit,
2002 params.footskip, defaultUnit);
2004 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2005 params.columnsep, defaultUnit);
2007 branchesModule->update(params);
2010 PDFOptions const & pdf = params.pdfoptions();
2011 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2012 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2013 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2014 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2015 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2017 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2018 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2019 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2021 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2023 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2024 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2025 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2026 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2027 pdfSupportModule->backrefCB->setChecked(pdf.backref);
2028 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
2029 pdfSupportModule->fullscreenCB->setChecked
2030 (pdf.pagemode == pdf.pagemode_fullscreen);
2032 pdfSupportModule->optionsLE->setText(
2033 toqstr(pdf.quoted_options));
2037 void GuiDocument::applyView()
2043 void GuiDocument::saveDocDefault()
2045 // we have to apply the params first
2051 void GuiDocument::updateAvailableModules()
2053 modules_av_model_.clear();
2054 vector<modInfoStruct> const & modInfoList = getModuleInfo();
2055 int const mSize = modInfoList.size();
2056 for (int i = 0; i != mSize; ++i) {
2057 modInfoStruct const & modInfo = modInfoList[i];
2058 modules_av_model_.insertRow(i, modInfo.name, modInfo.id,
2059 modInfo.description);
2064 void GuiDocument::updateSelectedModules()
2066 // and selected ones, too
2067 modules_sel_model_.clear();
2068 vector<modInfoStruct> const selModList = getSelectedModules();
2069 int const sSize = selModList.size();
2070 for (int i = 0; i != sSize; ++i) {
2071 modInfoStruct const & modInfo = selModList[i];
2072 modules_sel_model_.insertRow(i, modInfo.name, modInfo.id,
2073 modInfo.description);
2078 void GuiDocument::updateContents()
2080 if (id() == current_id_)
2083 updateAvailableModules();
2084 updateSelectedModules();
2086 //FIXME It'd be nice to make sure here that the selected
2087 //modules are consistent: That required modules are actually
2088 //selected, and that we don't have conflicts. If so, we could
2089 //at least pop up a warning.
2095 void GuiDocument::forceUpdate()
2097 // reset to force dialog update
2103 void GuiDocument::useClassDefaults()
2105 if (applyPB->isEnabled()) {
2106 int const ret = Alert::prompt(_("Unapplied changes"),
2107 _("Some changes in the dialog were not yet applied.\n"
2108 "If you do not apply now, they will be lost after this action."),
2109 1, 1, _("&Apply"), _("&Dismiss"));
2114 int idx = latexModule->classCO->currentIndex();
2115 string const classname = classes_model_.getIDString(idx);
2116 if (!bp_.setBaseClass(classname)) {
2117 Alert::error(_("Error"), _("Unable to set document class."));
2120 bp_.useClassDefaults();
2125 void GuiDocument::setLayoutComboByIDString(std::string const & idString)
2127 int idx = classes_model_.findIDString(idString);
2129 Alert::warning(_("Can't set layout!"),
2130 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2132 latexModule->classCO->setCurrentIndex(idx);
2136 bool GuiDocument::isValid()
2138 return validate_listings_params().empty()
2139 && (textLayoutModule->skipCO->currentIndex() != 3
2140 || !textLayoutModule->skipLE->text().isEmpty());
2144 char const * const GuiDocument::fontfamilies[5] = {
2145 "default", "rmdefault", "sfdefault", "ttdefault", ""
2149 char const * GuiDocument::fontfamilies_gui[5] = {
2150 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2154 bool GuiDocument::initialiseParams(string const &)
2156 bp_ = buffer().params();
2157 // Force update on next updateContent() round.
2164 void GuiDocument::clearParams()
2166 bp_ = BufferParams();
2170 BufferId GuiDocument::id() const
2176 vector<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2178 return moduleNames_;
2182 vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2184 vector<string> const & mods = params().getModules();
2185 vector<string>::const_iterator it = mods.begin();
2186 vector<string>::const_iterator end = mods.end();
2187 vector<modInfoStruct> mInfo;
2188 for (; it != end; ++it) {
2191 LyXModule * mod = moduleList[*it];
2193 m.name = qt_(mod->getName());
2195 m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
2202 DocumentClass const & GuiDocument::documentClass() const
2204 return bp_.documentClass();
2208 static void dispatch_bufferparams(Dialog const & dialog,
2209 BufferParams const & bp, FuncCode lfun)
2212 ss << "\\begin_header\n";
2214 ss << "\\end_header\n";
2215 dialog.dispatch(FuncRequest(lfun, ss.str()));
2219 void GuiDocument::dispatchParams()
2221 // This must come first so that a language change is correctly noticed
2224 // Apply the BufferParams. Note that this will set the base class
2225 // and then update the buffer's layout.
2226 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2228 if (!params().master.empty()) {
2229 FileName const master_file = support::makeAbsPath(params().master,
2230 support::onlyPath(buffer().absFileName()));
2231 if (isLyXFilename(master_file.absFilename())) {
2232 Buffer * master = checkAndLoadLyXFile(master_file);
2233 buffer().setParent(master);
2237 // Generate the colours requested by each new branch.
2238 BranchList & branchlist = params().branchlist();
2239 if (!branchlist.empty()) {
2240 BranchList::const_iterator it = branchlist.begin();
2241 BranchList::const_iterator const end = branchlist.end();
2242 for (; it != end; ++it) {
2243 docstring const & current_branch = it->getBranch();
2244 Branch const * branch = branchlist.find(current_branch);
2245 string const x11hexname = X11hexname(branch->getColor());
2246 // display the new color
2247 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2248 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2251 // Open insets of selected branches, close deselected ones
2252 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2255 // FIXME: If we used an LFUN, we would not need those two lines:
2256 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
2260 void GuiDocument::setLanguage() const
2262 Language const * const newL = bp_.language;
2263 if (buffer().params().language == newL)
2266 string const & lang_name = newL->lang();
2267 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2271 void GuiDocument::saveAsDefault() const
2273 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2277 bool GuiDocument::isFontAvailable(string const & font) const
2279 if (font == "default" || font == "cmr"
2280 || font == "cmss" || font == "cmtt")
2281 // these are standard
2283 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2284 return LaTeXFeatures::isAvailable("lmodern");
2285 if (font == "times" || font == "palatino"
2286 || font == "helvet" || font == "courier")
2287 return LaTeXFeatures::isAvailable("psnfss");
2288 if (font == "cmbr" || font == "cmtl")
2289 return LaTeXFeatures::isAvailable("cmbright");
2290 if (font == "utopia")
2291 return LaTeXFeatures::isAvailable("utopia")
2292 || LaTeXFeatures::isAvailable("fourier");
2293 if (font == "beraserif" || font == "berasans"
2294 || font == "beramono")
2295 return LaTeXFeatures::isAvailable("bera");
2296 return LaTeXFeatures::isAvailable(font);
2300 bool GuiDocument::providesOSF(string const & font) const
2303 return isFontAvailable("eco");
2304 if (font == "palatino")
2305 return isFontAvailable("mathpazo");
2310 bool GuiDocument::providesSC(string const & font) const
2312 if (font == "palatino")
2313 return isFontAvailable("mathpazo");
2314 if (font == "utopia")
2315 return isFontAvailable("fourier");
2320 bool GuiDocument::providesScale(string const & font) const
2322 return font == "helvet" || font == "luximono"
2323 || font == "berasans" || font == "beramono";
2327 void GuiDocument::loadModuleInfo()
2329 moduleNames_.clear();
2330 LyXModuleList::const_iterator it = moduleList.begin();
2331 LyXModuleList::const_iterator end = moduleList.end();
2332 for (; it != end; ++it) {
2335 m.name = qt_(it->getName());
2336 // this is supposed to give us the first sentence of the description
2337 QString desc = qt_(it->getDescription());
2338 int const pos = desc.indexOf(".");
2340 desc.truncate(pos + 1);
2341 m.description = desc;
2342 moduleNames_.push_back(m);
2347 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2350 } // namespace frontend
2353 #include "GuiDocument_moc.cpp"