2 * \file GuiDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "GuiDocument.h"
16 #include "LayoutFile.h"
17 #include "BranchList.h"
18 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
24 #include "FloatPlacement.h"
25 #include "FuncRequest.h"
26 #include "support/gettext.h"
27 #include "GuiBranches.h"
29 #include "LaTeXFeatures.h"
30 #include "LaTeXHighlighter.h"
32 #include "LengthCombo.h"
33 #include "LyXRC.h" // defaultUnit
34 #include "ModuleList.h"
35 #include "OutputParams.h"
36 #include "PanelStack.h"
37 #include "PDFOptions.h"
38 #include "qt_helpers.h"
40 #include "Validator.h"
42 #include "insets/InsetListingsParams.h"
44 #include "support/debug.h"
45 #include "support/FileName.h"
46 #include "support/FileFilterList.h"
47 #include "support/filetools.h"
48 #include "support/lstrings.h"
50 #include "frontends/alert.h"
52 #include <QCloseEvent>
54 #include <QTextCursor>
59 using namespace lyx::support;
64 char const * const tex_graphics[] =
66 "default", "dvips", "dvitops", "emtex",
67 "ln", "oztex", "textures", "none", ""
71 char const * const tex_graphics_gui[] =
73 N_("Default"), "Dvips", "DVItoPS", "EmTeX",
74 "LN", "OzTeX", "Textures", N_("None"), ""
78 char const * const tex_fonts_roman[] =
80 "default", "cmr", "lmodern", "ae", "times", "palatino",
81 "charter", "newcent", "bookman", "utopia", "beraserif",
82 "ccfonts", "chancery", ""
86 char const * tex_fonts_roman_gui[] =
88 N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
89 N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
90 N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
91 N_("Utopia"), N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
96 char const * const tex_fonts_sans[] =
98 "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
102 char const * tex_fonts_sans_gui[] =
104 N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
105 N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
109 char const * const tex_fonts_monospaced[] =
111 "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
115 char const * tex_fonts_monospaced_gui[] =
117 N_("Default"), N_("Computer Modern Typewriter"),
118 N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
119 N_("LuxiMono"), N_("CM Typewriter Light"), ""
123 vector<pair<string, lyx::docstring> > pagestyles;
126 } // anonymous namespace
131 // used when sorting the textclass list.
132 class less_textclass_avail_desc
133 : public binary_function<string, string, int>
136 int operator()(string const & lhs, string const & rhs) const
138 // Ordering criteria:
139 // 1. Availability of text class
140 // 2. Description (lexicographic)
141 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
142 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
143 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
144 (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() &&
145 _(tc1.description()) < _(tc2.description()));
155 QModelIndex getSelectedIndex(QListView * lv)
157 QModelIndex retval = QModelIndex();
158 QModelIndexList selIdx =
159 lv->selectionModel()->selectedIndexes();
161 retval = selIdx.first();
167 vector<string> getRequiredList(string const & modName)
169 LyXModule const * const mod = moduleList[modName];
171 return vector<string>(); //empty such thing
172 return mod->getRequiredModules();
176 vector<string> getExcludedList(string const & modName)
178 LyXModule const * const mod = moduleList[modName];
180 return vector<string>(); //empty such thing
181 return mod->getExcludedModules();
185 docstring getModuleDescription(string const & modName)
187 LyXModule const * const mod = moduleList[modName];
189 return _("Module not found!");
190 return _(mod->getDescription());
194 vector<string> getPackageList(string const & modName)
196 LyXModule const * const mod = moduleList[modName];
198 return vector<string>(); //empty such thing
199 return mod->getPackageList();
203 bool isModuleAvailable(string const & modName)
205 LyXModule * mod = moduleList[modName];
208 return mod->isAvailable();
210 } //anonymous namespace
213 ModuleSelMan::ModuleSelMan(
214 QListView * availableLV,
215 QListView * selectedLV,
219 QPushButton * downPB,
220 GuiIdListModel * availableModel,
221 GuiIdListModel * selectedModel) :
222 GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
223 upPB, downPB, availableModel, selectedModel)
227 void ModuleSelMan::updateAddPB()
229 int const arows = availableModel->rowCount();
230 QModelIndexList const availSels =
231 availableLV->selectionModel()->selectedIndexes();
232 if (arows == 0 || availSels.isEmpty() || isSelected(availSels.first())) {
233 addPB->setEnabled(false);
237 QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
238 string const modName = getAvailableModel()->getIDString(idx.row());
239 vector<string> reqs = getRequiredList(modName);
240 vector<string> excl = getExcludedList(modName);
242 if (reqs.empty() && excl.empty()) {
243 addPB->setEnabled(true);
247 int const srows = selectedModel->rowCount();
248 vector<string> selModList;
249 for (int i = 0; i < srows; ++i)
250 selModList.push_back(getSelectedModel()->getIDString(i));
252 vector<string>::const_iterator selModStart = selModList.begin();
253 vector<string>::const_iterator selModEnd = selModList.end();
255 //Check whether some required module is available
257 bool foundOne = false;
258 vector<string>::const_iterator it = reqs.begin();
259 vector<string>::const_iterator end = reqs.end();
260 for (; it != end; ++it) {
261 if (find(selModStart, selModEnd, *it) != selModEnd) {
267 addPB->setEnabled(false);
272 //Check whether any excluded module is being used
274 vector<string>::const_iterator it = excl.begin();
275 vector<string>::const_iterator end = excl.end();
276 for (; it != end; ++it) {
277 if (find(selModStart, selModEnd, *it) != selModEnd) {
278 addPB->setEnabled(false);
284 addPB->setEnabled(true);
288 void ModuleSelMan::updateDownPB()
290 int const srows = selectedModel->rowCount();
292 downPB->setEnabled(false);
295 QModelIndexList const selSels =
296 selectedLV->selectionModel()->selectedIndexes();
297 //disable if empty or last item is selected
298 if (selSels.empty() || selSels.first().row() == srows - 1) {
299 downPB->setEnabled(false);
302 //determine whether immediately succeding element requires this one
303 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
304 int curRow = curIdx.row();
305 if (curRow < 0 || curRow >= srows - 1) { //this shouldn't happen...
306 downPB->setEnabled(false);
309 string const curModName = getSelectedModel()->getIDString(curRow);
310 string const nextModName = getSelectedModel()->getIDString(curRow + 1);
312 vector<string> reqs = getRequiredList(nextModName);
314 //if it doesn't require anything....
316 downPB->setEnabled(true);
320 //FIXME This should perhaps be more flexible and check whether, even
321 //if this one is required, there is also an earlier one that is required.
322 //enable it if this module isn't required
324 find(reqs.begin(), reqs.end(), curModName) == reqs.end());
327 void ModuleSelMan::updateUpPB()
329 int const srows = selectedModel->rowCount();
331 upPB->setEnabled(false);
334 QModelIndexList const selSels =
335 selectedLV->selectionModel()->selectedIndexes();
336 //disable if empty or first item is selected
337 if (selSels.empty() || selSels.first().row() == 0) {
338 upPB->setEnabled(false);
342 //determine whether immediately preceding element is required by this one
343 QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
344 int curRow = curIdx.row();
345 if (curRow <= -1 || curRow > srows - 1) { //sanity check
346 downPB->setEnabled(false);
349 string const curModName = getSelectedModel()->getIDString(curRow);
350 vector<string> reqs = getRequiredList(curModName);
352 //if this one doesn't require anything....
354 upPB->setEnabled(true);
358 string preModName = getSelectedModel()->getIDString(curRow - 1);
360 //NOTE This is less flexible than it might be. You could check whether, even
361 //if this one is required, there is also an earlier one that is required.
362 //enable it if the preceding module isn't required
363 upPB->setEnabled(find(reqs.begin(), reqs.end(), preModName) == reqs.end());
366 void ModuleSelMan::updateDelPB()
368 int const srows = selectedModel->rowCount();
370 deletePB->setEnabled(false);
373 QModelIndexList const selSels =
374 selectedLV->selectionModel()->selectedIndexes();
375 if (selSels.empty() || selSels.first().row() < 0) {
376 deletePB->setEnabled(false);
380 //determine whether some LATER module requires this one
381 //NOTE Things are arranged so that this is the only way there
382 //can be a problem. At least, we hope so.
383 QModelIndex const & curIdx =
384 selectedLV->selectionModel()->currentIndex();
385 int const curRow = curIdx.row();
386 if (curRow < 0 || curRow >= srows) { //this shouldn't happen
387 deletePB->setEnabled(false);
391 QString const curModName = curIdx.data().toString();
393 //We're looking here for a reason NOT to enable the button. If we
394 //find one, we disable it and return. If we don't, we'll end up at
395 //the end of the function, and then we enable it.
396 for (int i = curRow + 1; i < srows; ++i) {
397 string const thisMod = getSelectedModel()->getIDString(i);
398 vector<string> reqs = getRequiredList(thisMod);
399 //does this one require us?
400 if (find(reqs.begin(), reqs.end(), fromqstr(curModName)) == reqs.end())
404 //OK, so this module requires us
405 //is there an EARLIER module that also satisfies the require?
406 //NOTE We demand that it be earlier to keep the list of modules
407 //consistent with the rule that a module must be proceeded by a
408 //required module. There would be more flexible ways to proceed,
409 //but that would be a lot more complicated, and the logic here is
410 //already complicated. (That's why I've left the debugging code.)
411 //lyxerr << "Testing " << thisMod << std::endl;
412 bool foundOne = false;
413 for (int j = 0; j < curRow; ++j) {
414 string const mod = getSelectedModel()->getIDString(j);
415 //lyxerr << "In loop: Testing " << mod << std::endl;
416 //do we satisfy the require?
417 if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
418 //lyxerr << mod << " does the trick." << std::endl;
423 //did we find a module to satisfy the require?
425 //lyxerr << "No matching module found." << std::endl;
426 deletePB->setEnabled(false);
430 //lyxerr << "All's well that ends well." << std::endl;
431 deletePB->setEnabled(true);
435 /////////////////////////////////////////////////////////////////////
439 /////////////////////////////////////////////////////////////////////
441 PreambleModule::PreambleModule(): current_id_(0)
443 // This is not a memory leak. The object will be destroyed
445 (void) new LaTeXHighlighter(preambleTE->document());
446 setFocusProxy(preambleTE);
447 connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
451 void PreambleModule::update(BufferParams const & params, BufferId id)
453 QString preamble = toqstr(params.preamble);
454 // Nothing to do if the params and preamble are unchanged.
455 if (id == current_id_
456 && preamble == preambleTE->document()->toPlainText())
459 QTextCursor cur = preambleTE->textCursor();
460 // Save the coords before switching to the new one.
461 preamble_coords_[current_id_] =
462 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
464 // Save the params address for further use.
466 preambleTE->document()->setPlainText(preamble);
467 Coords::const_iterator it = preamble_coords_.find(current_id_);
468 if (it == preamble_coords_.end())
469 // First time we open this one.
470 preamble_coords_[current_id_] = make_pair(0,0);
472 // Restore saved coords.
473 QTextCursor cur = preambleTE->textCursor();
474 cur.setPosition(it->second.first);
475 preambleTE->setTextCursor(cur);
476 preambleTE->verticalScrollBar()->setValue(it->second.second);
481 void PreambleModule::apply(BufferParams & params)
483 params.preamble = fromqstr(preambleTE->document()->toPlainText());
487 void PreambleModule::closeEvent(QCloseEvent * e)
489 // Save the coords before closing.
490 QTextCursor cur = preambleTE->textCursor();
491 preamble_coords_[current_id_] =
492 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
497 /////////////////////////////////////////////////////////////////////
501 /////////////////////////////////////////////////////////////////////
504 GuiDocument::GuiDocument(GuiView & lv)
505 : GuiDialog(lv, "document", qt_("Document Settings")), current_id_(0)
509 QList<LanguagePair> langs = languageData(false);
510 for (int i = 0; i != langs.size(); ++i)
511 lang_.append(langs[i].second);
513 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
514 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
515 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
516 connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
518 connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
519 connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
521 // Manage the restore, ok, apply, restore and cancel/close buttons
522 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
524 bc().setApply(applyPB);
525 bc().setCancel(closePB);
526 bc().setRestore(restorePB);
528 textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
530 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
531 this, SLOT(change_adaptor()));
532 connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
533 this, SLOT(setLSpacing(int)));
534 connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
535 this, SLOT(change_adaptor()));
536 connect(textLayoutModule->skipRB, SIGNAL(clicked()),
537 this, SLOT(change_adaptor()));
538 connect(textLayoutModule->indentRB, SIGNAL(clicked()),
539 this, SLOT(change_adaptor()));
540 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
541 this, SLOT(change_adaptor()));
542 connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
543 this, SLOT(change_adaptor()));
544 connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
545 this, SLOT(change_adaptor()));
546 connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
547 this, SLOT(setSkip(int)));
548 connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
549 this, SLOT(enableSkip(bool)));
550 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
551 this, SLOT(change_adaptor()));
552 connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
553 this, SLOT(setColSep()));
554 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
555 this, SLOT(change_adaptor()));
556 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
557 this, SLOT(change_adaptor()));
558 connect(textLayoutModule->bypassCB, SIGNAL(clicked()),
559 this, SLOT(set_listings_msg()));
560 connect(textLayoutModule->listingsED, SIGNAL(textChanged()),
561 this, SLOT(set_listings_msg()));
562 textLayoutModule->listingsTB->setPlainText(
563 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
564 textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
565 textLayoutModule->lspacingLE));
566 textLayoutModule->skipLE->setValidator(unsignedLengthValidator(
567 textLayoutModule->skipLE));
569 textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
570 textLayoutModule->skipCO->addItem(qt_("MedSkip"));
571 textLayoutModule->skipCO->addItem(qt_("BigSkip"));
572 textLayoutModule->skipCO->addItem(qt_("Length"));
573 // remove the %-items from the unit choice
574 textLayoutModule->skipLengthCO->noPercents();
575 textLayoutModule->lspacingCO->insertItem(
576 Spacing::Single, qt_("Single"));
577 textLayoutModule->lspacingCO->insertItem(
578 Spacing::Onehalf, qt_("OneHalf"));
579 textLayoutModule->lspacingCO->insertItem(
580 Spacing::Double, qt_("Double"));
581 textLayoutModule->lspacingCO->insertItem(
582 Spacing::Other, qt_("Custom"));
584 // initialize the length validator
585 bc().addCheckedLineEdit(textLayoutModule->skipLE);
587 fontModule = new UiWidget<Ui::FontUi>;
589 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
590 this, SLOT(change_adaptor()));
591 connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
592 this, SLOT(romanChanged(int)));
593 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
594 this, SLOT(change_adaptor()));
595 connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
596 this, SLOT(sansChanged(int)));
597 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
598 this, SLOT(change_adaptor()));
599 connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
600 this, SLOT(ttChanged(int)));
601 connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
602 this, SLOT(change_adaptor()));
603 connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
604 this, SLOT(change_adaptor()));
605 connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
606 this, SLOT(change_adaptor()));
607 connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
608 this, SLOT(change_adaptor()));
609 connect(fontModule->fontScCB, SIGNAL(clicked()),
610 this, SLOT(change_adaptor()));
611 connect(fontModule->fontOsfCB, SIGNAL(clicked()),
612 this, SLOT(change_adaptor()));
614 for (int n = 0; tex_fonts_roman[n][0]; ++n) {
615 QString font = qt_(tex_fonts_roman_gui[n]);
616 if (!isFontAvailable(tex_fonts_roman[n]))
617 font += qt_(" (not installed)");
618 fontModule->fontsRomanCO->addItem(font);
620 for (int n = 0; tex_fonts_sans[n][0]; ++n) {
621 QString font = qt_(tex_fonts_sans_gui[n]);
622 if (!isFontAvailable(tex_fonts_sans[n]))
623 font += qt_(" (not installed)");
624 fontModule->fontsSansCO->addItem(font);
626 for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
627 QString font = qt_(tex_fonts_monospaced_gui[n]);
628 if (!isFontAvailable(tex_fonts_monospaced[n]))
629 font += qt_(" (not installed)");
630 fontModule->fontsTypewriterCO->addItem(font);
633 fontModule->fontsizeCO->addItem(qt_("Default"));
634 fontModule->fontsizeCO->addItem(qt_("10"));
635 fontModule->fontsizeCO->addItem(qt_("11"));
636 fontModule->fontsizeCO->addItem(qt_("12"));
638 for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
639 fontModule->fontsDefaultCO->addItem(
640 qt_(GuiDocument::fontfamilies_gui[n]));
643 pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
645 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
646 this, SLOT(setCustomPapersize(int)));
647 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
648 this, SLOT(setCustomPapersize(int)));
649 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
650 this, SLOT(portraitChanged()));
651 connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
652 this, SLOT(change_adaptor()));
653 connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
654 this, SLOT(change_adaptor()));
655 connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
656 this, SLOT(change_adaptor()));
657 connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
658 this, SLOT(change_adaptor()));
659 connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
660 this, SLOT(change_adaptor()));
661 connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
662 this, SLOT(change_adaptor()));
663 connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
664 this, SLOT(change_adaptor()));
665 connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
666 this, SLOT(change_adaptor()));
667 connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
668 this, SLOT(change_adaptor()));
670 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
671 pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
672 pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
673 pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
674 pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
675 bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
676 pageLayoutModule->paperheightL);
677 bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
678 pageLayoutModule->paperwidthL);
681 QComboBox * cb = pageLayoutModule->papersizeCO;
682 cb->addItem(qt_("Default"));
683 cb->addItem(qt_("Custom"));
684 cb->addItem(qt_("US letter"));
685 cb->addItem(qt_("US legal"));
686 cb->addItem(qt_("US executive"));
687 cb->addItem(qt_("A3"));
688 cb->addItem(qt_("A4"));
689 cb->addItem(qt_("A5"));
690 cb->addItem(qt_("B3"));
691 cb->addItem(qt_("B4"));
692 cb->addItem(qt_("B5"));
693 // remove the %-items from the unit choice
694 pageLayoutModule->paperwidthUnitCO->noPercents();
695 pageLayoutModule->paperheightUnitCO->noPercents();
696 pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
697 pageLayoutModule->paperheightLE));
698 pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
699 pageLayoutModule->paperwidthLE));
702 marginsModule = new UiWidget<Ui::MarginsUi>;
704 connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
705 this, SLOT(setCustomMargins(bool)));
706 connect(marginsModule->marginCB, SIGNAL(clicked()),
707 this, SLOT(change_adaptor()));
708 connect(marginsModule->topLE, SIGNAL(textChanged(const QString &)),
709 this, SLOT(change_adaptor()));
710 connect(marginsModule->topUnit, SIGNAL(activated(int)),
711 this, SLOT(change_adaptor()));
712 connect(marginsModule->bottomLE, SIGNAL(textChanged(const QString &)),
713 this, SLOT(change_adaptor()));
714 connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
715 this, SLOT(change_adaptor()));
716 connect(marginsModule->innerLE, SIGNAL(textChanged(const QString &)),
717 this, SLOT(change_adaptor()));
718 connect(marginsModule->innerUnit, SIGNAL(activated(int)),
719 this, SLOT(change_adaptor()));
720 connect(marginsModule->outerLE, SIGNAL(textChanged(const QString &)),
721 this, SLOT(change_adaptor()));
722 connect(marginsModule->outerUnit, SIGNAL(activated(int)),
723 this, SLOT(change_adaptor()));
724 connect(marginsModule->headheightLE, SIGNAL(textChanged(const QString &)),
725 this, SLOT(change_adaptor()));
726 connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
727 this, SLOT(change_adaptor()));
728 connect(marginsModule->headsepLE, SIGNAL(textChanged(const QString &)),
729 this, SLOT(change_adaptor()));
730 connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
731 this, SLOT(change_adaptor()));
732 connect(marginsModule->footskipLE, SIGNAL(textChanged(const QString&)),
733 this, SLOT(change_adaptor()));
734 connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
735 this, SLOT(change_adaptor()));
736 connect(marginsModule->columnsepLE, SIGNAL(textChanged(const QString&)),
737 this, SLOT(change_adaptor()));
738 connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
739 this, SLOT(change_adaptor()));
740 marginsModule->topLE->setValidator(unsignedLengthValidator(
741 marginsModule->topLE));
742 marginsModule->bottomLE->setValidator(unsignedLengthValidator(
743 marginsModule->bottomLE));
744 marginsModule->innerLE->setValidator(unsignedLengthValidator(
745 marginsModule->innerLE));
746 marginsModule->outerLE->setValidator(unsignedLengthValidator(
747 marginsModule->outerLE));
748 marginsModule->headsepLE->setValidator(unsignedLengthValidator(
749 marginsModule->headsepLE));
750 marginsModule->headheightLE->setValidator(unsignedLengthValidator(
751 marginsModule->headheightLE));
752 marginsModule->footskipLE->setValidator(unsignedLengthValidator(
753 marginsModule->footskipLE));
754 marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
755 marginsModule->columnsepLE));
757 bc().addCheckedLineEdit(marginsModule->topLE,
758 marginsModule->topL);
759 bc().addCheckedLineEdit(marginsModule->bottomLE,
760 marginsModule->bottomL);
761 bc().addCheckedLineEdit(marginsModule->innerLE,
762 marginsModule->innerL);
763 bc().addCheckedLineEdit(marginsModule->outerLE,
764 marginsModule->outerL);
765 bc().addCheckedLineEdit(marginsModule->headsepLE,
766 marginsModule->headsepL);
767 bc().addCheckedLineEdit(marginsModule->headheightLE,
768 marginsModule->headheightL);
769 bc().addCheckedLineEdit(marginsModule->footskipLE,
770 marginsModule->footskipL);
771 bc().addCheckedLineEdit(marginsModule->columnsepLE,
772 marginsModule->columnsepL);
775 langModule = new UiWidget<Ui::LanguageUi>;
777 connect(langModule->languageCO, SIGNAL(activated(int)),
778 this, SLOT(change_adaptor()));
779 connect(langModule->defaultencodingRB, SIGNAL(clicked()),
780 this, SLOT(change_adaptor()));
781 connect(langModule->otherencodingRB, SIGNAL(clicked()),
782 this, SLOT(change_adaptor()));
783 connect(langModule->encodingCO, SIGNAL(activated(int)),
784 this, SLOT(change_adaptor()));
785 connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
786 this, SLOT(change_adaptor()));
789 QList<LanguagePair>::const_iterator lit = langs.begin();
790 QList<LanguagePair>::const_iterator lend = langs.end();
791 for (; lit != lend; ++lit)
792 langModule->languageCO->addItem(lit->first);
794 // Always put the default encoding in the first position.
795 // It is special because the displayed text is translated.
796 langModule->encodingCO->addItem(qt_("LaTeX default"));
797 Encodings::const_iterator it = encodings.begin();
798 Encodings::const_iterator const end = encodings.end();
799 for (; it != end; ++it)
800 langModule->encodingCO->addItem(toqstr(it->latexName()));
802 langModule->quoteStyleCO->addItem(qt_("``text''"));
803 langModule->quoteStyleCO->addItem(qt_("''text''"));
804 langModule->quoteStyleCO->addItem(qt_(",,text``"));
805 langModule->quoteStyleCO->addItem(qt_(",,text''"));
806 langModule->quoteStyleCO->addItem(qt_("<<text>>"));
807 langModule->quoteStyleCO->addItem(qt_(">>text<<"));
810 numberingModule = new UiWidget<Ui::NumberingUi>;
812 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
813 this, SLOT(change_adaptor()));
814 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
815 this, SLOT(change_adaptor()));
816 connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
817 this, SLOT(updateNumbering()));
818 connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
819 this, SLOT(updateNumbering()));
820 numberingModule->tocTW->setColumnCount(3);
821 numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
822 numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
823 numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
826 biblioModule = new UiWidget<Ui::BiblioUi>;
827 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
828 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
829 connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
830 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
832 connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
833 this, SLOT(change_adaptor()));
834 connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
835 this, SLOT(change_adaptor()));
836 connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
837 this, SLOT(change_adaptor()));
838 connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
839 this, SLOT(change_adaptor()));
840 connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
841 this, SLOT(change_adaptor()));
843 biblioModule->citeStyleCO->addItem(qt_("Author-year"));
844 biblioModule->citeStyleCO->addItem(qt_("Numerical"));
845 biblioModule->citeStyleCO->setCurrentIndex(0);
848 mathsModule = new UiWidget<Ui::MathsUi>;
849 connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
850 mathsModule->amsCB, SLOT(setDisabled(bool)));
851 connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
852 mathsModule->esintCB, SLOT(setDisabled(bool)));
854 connect(mathsModule->amsCB, SIGNAL(clicked()),
855 this, SLOT(change_adaptor()));
856 connect(mathsModule->amsautoCB, SIGNAL(clicked()),
857 this, SLOT(change_adaptor()));
858 connect(mathsModule->esintCB, SIGNAL(clicked()),
859 this, SLOT(change_adaptor()));
860 connect(mathsModule->esintautoCB, SIGNAL(clicked()),
861 this, SLOT(change_adaptor()));
863 latexModule = new UiWidget<Ui::LaTeXUi>;
865 connect(latexModule->optionsLE, SIGNAL(textChanged(const QString &)),
866 this, SLOT(change_adaptor()));
867 connect(latexModule->psdriverCO, SIGNAL(activated(int)),
868 this, SLOT(change_adaptor()));
869 connect(latexModule->classCO, SIGNAL(activated(int)),
870 this, SLOT(classChanged()));
871 connect(latexModule->classCO, SIGNAL(activated(int)),
872 this, SLOT(change_adaptor()));
873 connect(latexModule->layoutPB, SIGNAL(clicked()),
874 this, SLOT(browseLayout()));
877 new ModuleSelMan(latexModule->availableLV, latexModule->selectedLV,
878 latexModule->addPB, latexModule->deletePB,
879 latexModule->upPB, latexModule->downPB,
880 availableModel(), selectedModel());
881 connect(selectionManager, SIGNAL(updateHook()),
882 this, SLOT(updateModuleInfo()));
883 connect(selectionManager, SIGNAL(updateHook()),
884 this, SLOT(change_adaptor()));
886 // postscript drivers
887 for (int n = 0; tex_graphics[n][0]; ++n) {
888 QString enc = qt_(tex_graphics_gui[n]);
889 latexModule->psdriverCO->addItem(enc);
892 latexModule->classCO->setModel(&classes_model_);
893 LayoutFileList const & bcl = LayoutFileList::get();
894 vector<LayoutFileIndex> classList = bcl.classList();
895 sort(classList.begin(), classList.end(), less_textclass_avail_desc());
897 vector<LayoutFileIndex>::const_iterator cit = classList.begin();
898 vector<LayoutFileIndex>::const_iterator cen = classList.end();
899 for (int i = 0; cit != cen; ++cit, ++i) {
900 LayoutFile const & tc = bcl[*cit];
901 docstring item = (tc.isTeXClassAvailable()) ?
902 from_utf8(tc.description()) :
903 bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
904 classes_model_.insertRow(i, toqstr(item), *cit);
908 branchesModule = new GuiBranches;
909 connect(branchesModule, SIGNAL(changed()),
910 this, SLOT(change_adaptor()));
913 preambleModule = new PreambleModule;
914 connect(preambleModule, SIGNAL(changed()),
915 this, SLOT(change_adaptor()));
918 bulletsModule = new BulletsModule;
919 connect(bulletsModule, SIGNAL(changed()),
920 this, SLOT(change_adaptor()));
923 embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
924 connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
925 this, SLOT(addExtraEmbeddedFile()));
926 connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
927 this, SLOT(removeExtraEmbeddedFile()));
930 pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
932 connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
933 this, SLOT(change_adaptor()));
934 connect(pdfSupportModule->titleLE, SIGNAL(textChanged(const QString &)),
935 this, SLOT(change_adaptor()));
936 connect(pdfSupportModule->authorLE, SIGNAL(textChanged(const QString &)),
937 this, SLOT(change_adaptor()));
938 connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(const QString &)),
939 this, SLOT(change_adaptor()));
940 connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(const QString &)),
941 this, SLOT(change_adaptor()));
942 connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
943 this, SLOT(change_adaptor()));
944 connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
945 this, SLOT(change_adaptor()));
946 connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
947 this, SLOT(change_adaptor()));
948 connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
949 this, SLOT(change_adaptor()));
950 connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
951 this, SLOT(change_adaptor()));
952 connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
953 this, SLOT(change_adaptor()));
954 connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
955 this, SLOT(change_adaptor()));
956 connect(pdfSupportModule->backrefCB, SIGNAL(toggled(bool)),
957 this, SLOT(change_adaptor()));
958 connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
959 this, SLOT(change_adaptor()));
960 connect(pdfSupportModule->pagebackrefCB, SIGNAL(toggled(bool)),
961 this, SLOT(change_adaptor()));
962 connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
963 this, SLOT(change_adaptor()));
964 connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(const QString &)),
965 this, SLOT(change_adaptor()));
968 floatModule = new FloatPlacement;
969 connect(floatModule, SIGNAL(changed()),
970 this, SLOT(change_adaptor()));
972 docPS->addPanel(latexModule, qt_("Document Class"));
973 docPS->addPanel(fontModule, qt_("Fonts"));
974 docPS->addPanel(textLayoutModule, qt_("Text Layout"));
975 docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
976 docPS->addPanel(marginsModule, qt_("Page Margins"));
977 docPS->addPanel(langModule, qt_("Language"));
978 docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
979 docPS->addPanel(biblioModule, qt_("Bibliography"));
980 docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
981 docPS->addPanel(mathsModule, qt_("Math Options"));
982 docPS->addPanel(floatModule, qt_("Float Placement"));
983 docPS->addPanel(bulletsModule, qt_("Bullets"));
984 docPS->addPanel(branchesModule, qt_("Branches"));
985 docPS->addPanel(embeddedFilesModule, qt_("Embedded Files"));
986 docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
987 docPS->setCurrentPanel(qt_("Document Class"));
988 // FIXME: hack to work around resizing bug in Qt >= 4.2
989 // bug verified with Qt 4.2.{0-3} (JSpitzm)
990 #if QT_VERSION >= 0x040200
991 docPS->updateGeometry();
996 void GuiDocument::showPreamble()
998 docPS->setCurrentPanel(qt_("LaTeX Preamble"));
1002 void GuiDocument::saveDefaultClicked()
1008 void GuiDocument::useDefaultsClicked()
1014 void GuiDocument::change_adaptor()
1020 docstring GuiDocument::validate_listings_params()
1022 // use a cache here to avoid repeated validation
1023 // of the same parameters
1024 static string param_cache = string();
1025 static docstring msg_cache = docstring();
1027 if (textLayoutModule->bypassCB->isChecked())
1030 string params = fromqstr(textLayoutModule->listingsED->toPlainText());
1031 if (params != param_cache) {
1032 param_cache = params;
1033 msg_cache = InsetListingsParams(params).validate();
1039 void GuiDocument::set_listings_msg()
1041 static bool isOK = true;
1042 docstring msg = validate_listings_params();
1047 // listingsTB->setTextColor("black");
1048 textLayoutModule->listingsTB->setPlainText(
1049 qt_("Input listings parameters on the right. Enter ? for a list of parameters."));
1052 // listingsTB->setTextColor("red");
1053 textLayoutModule->listingsTB->setPlainText(toqstr(msg));
1058 void GuiDocument::setLSpacing(int item)
1060 textLayoutModule->lspacingLE->setEnabled(item == 3);
1064 void GuiDocument::setSkip(int item)
1066 bool const enable = (item == 3);
1067 textLayoutModule->skipLE->setEnabled(enable);
1068 textLayoutModule->skipLengthCO->setEnabled(enable);
1072 void GuiDocument::enableSkip(bool skip)
1074 textLayoutModule->skipCO->setEnabled(skip);
1075 textLayoutModule->skipLE->setEnabled(skip);
1076 textLayoutModule->skipLengthCO->setEnabled(skip);
1078 setSkip(textLayoutModule->skipCO->currentIndex());
1081 void GuiDocument::portraitChanged()
1083 setMargins(pageLayoutModule->papersizeCO->currentIndex());
1086 void GuiDocument::setMargins(bool custom)
1088 marginsModule->marginCB->setChecked(custom);
1089 setCustomMargins(custom);
1093 void GuiDocument::setCustomPapersize(int papersize)
1095 bool const custom = (papersize == 1);
1097 pageLayoutModule->paperwidthL->setEnabled(custom);
1098 pageLayoutModule->paperwidthLE->setEnabled(custom);
1099 pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1100 pageLayoutModule->paperheightL->setEnabled(custom);
1101 pageLayoutModule->paperheightLE->setEnabled(custom);
1102 pageLayoutModule->paperheightLE->setFocus();
1103 pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1107 void GuiDocument::setColSep()
1109 setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1113 void GuiDocument::setCustomMargins(bool custom)
1115 marginsModule->topL->setEnabled(!custom);
1116 marginsModule->topLE->setEnabled(!custom);
1117 marginsModule->topUnit->setEnabled(!custom);
1119 marginsModule->bottomL->setEnabled(!custom);
1120 marginsModule->bottomLE->setEnabled(!custom);
1121 marginsModule->bottomUnit->setEnabled(!custom);
1123 marginsModule->innerL->setEnabled(!custom);
1124 marginsModule->innerLE->setEnabled(!custom);
1125 marginsModule->innerUnit->setEnabled(!custom);
1127 marginsModule->outerL->setEnabled(!custom);
1128 marginsModule->outerLE->setEnabled(!custom);
1129 marginsModule->outerUnit->setEnabled(!custom);
1131 marginsModule->headheightL->setEnabled(!custom);
1132 marginsModule->headheightLE->setEnabled(!custom);
1133 marginsModule->headheightUnit->setEnabled(!custom);
1135 marginsModule->headsepL->setEnabled(!custom);
1136 marginsModule->headsepLE->setEnabled(!custom);
1137 marginsModule->headsepUnit->setEnabled(!custom);
1139 marginsModule->footskipL->setEnabled(!custom);
1140 marginsModule->footskipLE->setEnabled(!custom);
1141 marginsModule->footskipUnit->setEnabled(!custom);
1143 bool const enableColSep = !custom &&
1144 textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1145 marginsModule->columnsepL->setEnabled(enableColSep);
1146 marginsModule->columnsepLE->setEnabled(enableColSep);
1147 marginsModule->columnsepUnit->setEnabled(enableColSep);
1151 void GuiDocument::updateFontsize(string const & items, string const & sel)
1153 fontModule->fontsizeCO->clear();
1154 fontModule->fontsizeCO->addItem(qt_("Default"));
1156 for (int n = 0; !token(items,'|',n).empty(); ++n)
1157 fontModule->fontsizeCO->
1158 addItem(toqstr(token(items,'|',n)));
1160 for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1161 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1162 fontModule->fontsizeCO->setCurrentIndex(n);
1169 void GuiDocument::romanChanged(int item)
1171 string const font = tex_fonts_roman[item];
1172 fontModule->fontScCB->setEnabled(providesSC(font));
1173 fontModule->fontOsfCB->setEnabled(providesOSF(font));
1177 void GuiDocument::sansChanged(int item)
1179 string const font = tex_fonts_sans[item];
1180 bool scaleable = providesScale(font);
1181 fontModule->scaleSansSB->setEnabled(scaleable);
1182 fontModule->scaleSansLA->setEnabled(scaleable);
1186 void GuiDocument::ttChanged(int item)
1188 string const font = tex_fonts_monospaced[item];
1189 bool scaleable = providesScale(font);
1190 fontModule->scaleTypewriterSB->setEnabled(scaleable);
1191 fontModule->scaleTypewriterLA->setEnabled(scaleable);
1195 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1198 pageLayoutModule->pagestyleCO->clear();
1199 pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1201 for (int n = 0; !token(items,'|',n).empty(); ++n) {
1202 string style = token(items, '|', n);
1203 docstring style_gui = _(style);
1204 pagestyles.push_back(pair<string, docstring>(style, style_gui));
1205 pageLayoutModule->pagestyleCO->addItem(toqstr(style_gui));
1208 if (sel == "default") {
1209 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1215 for (size_t i = 0; i < pagestyles.size(); ++i)
1216 if (pagestyles[i].first == sel)
1217 nn = pageLayoutModule->pagestyleCO->findText(
1218 toqstr(pagestyles[i].second));
1221 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1225 void GuiDocument::browseLayout()
1227 QString const label1 = qt_("Layouts|#o#O");
1228 QString const dir1 = toqstr(lyxrc.document_path);
1229 FileFilterList const filter(_("LyX Layout (*.layout)"));
1230 QString file = browseRelFile(QString(), bufferFilepath(),
1231 qt_("Local layout file"), filter, false,
1234 if (!suffixIs(fromqstr(file), ".layout"))
1237 FileName layoutFile = makeAbsPath(fromqstr(file),
1238 fromqstr(bufferFilepath()));
1240 // load the layout file
1241 LayoutFileList & bcl = LayoutFileList::get();
1242 string classname = layoutFile.onlyFileName();
1243 LayoutFileIndex name = bcl.addLayoutFile(
1244 classname.substr(0, classname.size() - 7),
1245 layoutFile.onlyPath().absFilename());
1248 Alert::error(_("Error"),
1249 _("Unable to read local layout file."));
1253 // do not trigger classChanged if there is no change.
1254 if (latexModule->classCO->currentText() == toqstr(name))
1258 int idx = latexModule->classCO->findText(toqstr(name));
1260 classes_model_.insertRow(0, toqstr(name), name);
1261 latexModule->classCO->setCurrentIndex(0);
1263 latexModule->classCO->setCurrentIndex(idx);
1268 void GuiDocument::classChanged()
1270 int idx = latexModule->classCO->currentIndex();
1273 string const classname = classes_model_.getIDString(idx);
1274 // check if this is a local layout file
1275 if (prefixIs(classname, LayoutFileList::localPrefix)) {
1276 int const ret = Alert::prompt(_("Local layout file"),
1277 _("The layout file you have selected is a local layout\n"
1278 "file, not one in the system or user directory. Your\n"
1279 "document may not work with this layout if you do not\n"
1280 "keep the layout file in the same directory."),
1281 1, 1, _("&Set Layout"), _("&Cancel"));
1283 // try to reset the layout combo
1284 setLayoutComboByIDString(bp_.baseClassID());
1288 if (!bp_.setBaseClass(classname)) {
1289 Alert::error(_("Error"), _("Unable to set document class."));
1292 if (lyxrc.auto_reset_options) {
1293 if (applyPB->isEnabled()) {
1294 int const ret = Alert::prompt(_("Unapplied changes"),
1295 _("Some changes in the dialog were not yet applied.\n"
1296 "If you do not apply now, they will be lost after this action."),
1297 1, 1, _("&Apply"), _("&Dismiss"));
1301 bp_.useClassDefaults();
1308 // This is an insanely complicated attempt to make this sort of thing
1309 // work with RTL languages.
1310 docstring formatStrVec(vector<string> const & v, docstring const & s)
1312 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
1313 int const vSize = v.size();
1316 else if (v.size() == 1)
1317 return from_ascii(v[0]);
1318 else if (v.size() == 2) {
1319 docstring retval = _("%1$s and %2$s");
1320 retval = subst(retval, _("and"), s);
1321 return bformat(retval, from_ascii(v[0]), from_ascii(v[1]));
1323 //The idea here is to format all but the last two items...
1324 docstring t2 = _("%1$s, %2$s");
1325 docstring retval = from_ascii(v[0]);
1326 for (int i = 1; i < vSize - 2; ++i)
1327 retval = bformat(t2, retval, from_ascii(v[i]));
1328 //...and then to plug them, and the last two, into this schema
1329 docstring t = _("%1$s, %2$s, and %3$s");
1330 t = subst(t, _("and"), s);
1331 return bformat(t, retval, from_ascii(v[vSize - 2]), from_ascii(v[vSize - 1]));
1334 vector<string> idsToNames(vector<string> const & idList)
1336 vector<string> retval;
1337 vector<string>::const_iterator it = idList.begin();
1338 vector<string>::const_iterator end = idList.end();
1339 for (; it != end; ++it) {
1340 LyXModule const * const mod = moduleList[*it];
1342 retval.push_back(*it + " (Unavailable)");
1344 retval.push_back(mod->getName());
1351 void GuiDocument::updateModuleInfo()
1353 selectionManager->update();
1355 //Module description
1356 bool const focusOnSelected = selectionManager->selectedFocused();
1357 QListView const * const lv =
1358 focusOnSelected ? latexModule->selectedLV : latexModule->availableLV;
1359 if (lv->selectionModel()->selectedIndexes().isEmpty()) {
1360 latexModule->infoML->document()->clear();
1363 QModelIndex const & idx = lv->selectionModel()->currentIndex();
1364 GuiIdListModel const & idModel =
1365 focusOnSelected ? modules_sel_model_ : modules_av_model_;
1366 string const modName = idModel.getIDString(idx.row());
1367 docstring desc = getModuleDescription(modName);
1369 vector<string> pkgList = getPackageList(modName);
1370 docstring pkgdesc = formatStrVec(pkgList, _("and"));
1371 if (!pkgdesc.empty()) {
1374 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
1377 pkgList = getRequiredList(modName);
1378 if (!pkgList.empty()) {
1379 vector<string> const reqDescs = idsToNames(pkgList);
1380 pkgdesc = formatStrVec(reqDescs, _("or"));
1383 desc += bformat(_("Module required: %1$s."), pkgdesc);
1386 pkgList = getExcludedList(modName);
1387 if (!pkgList.empty()) {
1388 vector<string> const reqDescs = idsToNames(pkgList);
1389 pkgdesc = formatStrVec(reqDescs, _( "and"));
1392 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
1395 if (!isModuleAvailable(modName)) {
1398 desc += _("WARNING: Some packages are unavailable!");
1401 latexModule->infoML->document()->setPlainText(toqstr(desc));
1405 void GuiDocument::setExtraEmbeddedFileList()
1407 embeddedFilesModule->extraLW->clear();
1408 // add current embedded files
1409 vector<string> const & files = buffer().params().extraEmbeddedFiles();
1410 vector<string>::const_iterator fit = files.begin();
1411 vector<string>::const_iterator fit_end = files.end();
1412 for (; fit != fit_end; ++fit)
1413 embeddedFilesModule->extraLW->addItem(toqstr(*fit));
1417 void GuiDocument::addExtraEmbeddedFile()
1419 QString const label1 = qt_("Documents|#o#O");
1420 QString const dir1 = toqstr(lyxrc.document_path);
1421 FileFilterList const filter(_("LyX Layout (*.layout);;LaTeX Classes (*.{cls,sty});;BibTeX Databases (*.{bib,bst})"));
1422 QString file = browseRelFile(QString(), bufferFilepath(),
1423 qt_("Extra embedded file"), filter, true, label1, dir1);
1428 if (embeddedFilesModule->extraLW->findItems(file, Qt::MatchExactly).empty())
1429 embeddedFilesModule->extraLW->addItem(file);
1433 void GuiDocument::removeExtraEmbeddedFile()
1435 int index = embeddedFilesModule->extraLW->currentRow();
1436 delete embeddedFilesModule->extraLW->takeItem(index);
1440 void GuiDocument::updateNumbering()
1442 DocumentClass const & tclass = bp_.documentClass();
1444 numberingModule->tocTW->setUpdatesEnabled(false);
1445 numberingModule->tocTW->clear();
1447 int const depth = numberingModule->depthSL->value();
1448 int const toc = numberingModule->tocSL->value();
1449 QString const no = qt_("No");
1450 QString const yes = qt_("Yes");
1451 QTreeWidgetItem * item = 0;
1453 DocumentClass::const_iterator lit = tclass.begin();
1454 DocumentClass::const_iterator len = tclass.end();
1455 for (; lit != len; ++lit) {
1456 int const toclevel = lit->toclevel;
1457 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
1458 item = new QTreeWidgetItem(numberingModule->tocTW);
1459 item->setText(0, toqstr(translateIfPossible(lit->name())));
1460 item->setText(1, (toclevel <= depth) ? yes : no);
1461 item->setText(2, (toclevel <= toc) ? yes : no);
1465 numberingModule->tocTW->setUpdatesEnabled(true);
1466 numberingModule->tocTW->update();
1470 void GuiDocument::apply(BufferParams & params)
1473 preambleModule->apply(params);
1476 params.setCiteEngine(biblio::ENGINE_BASIC);
1478 if (biblioModule->citeNatbibRB->isChecked()) {
1479 bool const use_numerical_citations =
1480 biblioModule->citeStyleCO->currentIndex();
1481 if (use_numerical_citations)
1482 params.setCiteEngine(biblio::ENGINE_NATBIB_NUMERICAL);
1484 params.setCiteEngine(biblio::ENGINE_NATBIB_AUTHORYEAR);
1486 } else if (biblioModule->citeJurabibRB->isChecked())
1487 params.setCiteEngine(biblio::ENGINE_JURABIB);
1489 params.use_bibtopic =
1490 biblioModule->bibtopicCB->isChecked();
1492 // language & quotes
1493 if (langModule->defaultencodingRB->isChecked()) {
1494 params.inputenc = "auto";
1496 int i = langModule->encodingCO->currentIndex();
1498 params.inputenc = "default";
1501 fromqstr(langModule->encodingCO->currentText());
1504 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
1505 switch (langModule->quoteStyleCO->currentIndex()) {
1507 lga = InsetQuotes::EnglishQ;
1510 lga = InsetQuotes::SwedishQ;
1513 lga = InsetQuotes::GermanQ;
1516 lga = InsetQuotes::PolishQ;
1519 lga = InsetQuotes::FrenchQ;
1522 lga = InsetQuotes::DanishQ;
1525 params.quotes_language = lga;
1527 int const pos = langModule->languageCO->currentIndex();
1528 params.language = lyx::languages.getLanguage(fromqstr(lang_[pos]));
1531 if (params.documentClass().hasTocLevels()) {
1532 params.tocdepth = numberingModule->tocSL->value();
1533 params.secnumdepth = numberingModule->depthSL->value();
1537 params.user_defined_bullet(0) = bulletsModule->getBullet(0);
1538 params.user_defined_bullet(1) = bulletsModule->getBullet(1);
1539 params.user_defined_bullet(2) = bulletsModule->getBullet(2);
1540 params.user_defined_bullet(3) = bulletsModule->getBullet(3);
1543 params.graphicsDriver =
1544 tex_graphics[latexModule->psdriverCO->currentIndex()];
1547 int idx = latexModule->classCO->currentIndex();
1549 string const classname = classes_model_.getIDString(idx);
1550 params.setBaseClass(classname);
1554 params.clearLayoutModules();
1555 int const srows = modules_sel_model_.rowCount();
1556 vector<string> selModList;
1557 for (int i = 0; i < srows; ++i)
1558 params.addLayoutModule(modules_sel_model_.getIDString(i));
1560 if (mathsModule->amsautoCB->isChecked()) {
1561 params.use_amsmath = BufferParams::package_auto;
1563 if (mathsModule->amsCB->isChecked())
1564 params.use_amsmath = BufferParams::package_on;
1566 params.use_amsmath = BufferParams::package_off;
1569 if (mathsModule->esintautoCB->isChecked())
1570 params.use_esint = BufferParams::package_auto;
1572 if (mathsModule->esintCB->isChecked())
1573 params.use_esint = BufferParams::package_on;
1575 params.use_esint = BufferParams::package_off;
1578 if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
1579 params.pagestyle = "default";
1581 docstring style_gui =
1582 qstring_to_ucs4(pageLayoutModule->pagestyleCO->currentText());
1583 for (size_t i = 0; i < pagestyles.size(); ++i)
1584 if (pagestyles[i].second == style_gui)
1585 params.pagestyle = pagestyles[i].first;
1588 switch (textLayoutModule->lspacingCO->currentIndex()) {
1590 params.spacing().set(Spacing::Single);
1593 params.spacing().set(Spacing::Onehalf);
1596 params.spacing().set(Spacing::Double);
1599 params.spacing().set(Spacing::Other,
1600 fromqstr(textLayoutModule->lspacingLE->text()));
1604 if (textLayoutModule->twoColumnCB->isChecked())
1609 // text should have passed validation
1610 params.listings_params =
1611 InsetListingsParams(fromqstr(textLayoutModule->listingsED->toPlainText())).params();
1613 if (textLayoutModule->indentRB->isChecked())
1614 params.paragraph_separation = BufferParams::PARSEP_INDENT;
1616 params.paragraph_separation = BufferParams::PARSEP_SKIP;
1618 switch (textLayoutModule->skipCO->currentIndex()) {
1620 params.setDefSkip(VSpace(VSpace::SMALLSKIP));
1623 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1626 params.setDefSkip(VSpace(VSpace::BIGSKIP));
1631 widgetsToLength(textLayoutModule->skipLE,
1632 textLayoutModule->skipLengthCO)
1634 params.setDefSkip(vs);
1638 // DocumentDefskipCB assures that this never happens
1639 // so Assert then !!! - jbl
1640 params.setDefSkip(VSpace(VSpace::MEDSKIP));
1645 fromqstr(latexModule->optionsLE->text());
1647 params.float_placement = floatModule->get();
1651 tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1654 tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1656 params.fontsTypewriter =
1657 tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1659 params.fontsSansScale = fontModule->scaleSansSB->value();
1661 params.fontsTypewriterScale = fontModule->scaleTypewriterSB->value();
1663 params.fontsSC = fontModule->fontScCB->isChecked();
1665 params.fontsOSF = fontModule->fontOsfCB->isChecked();
1667 params.fontsDefaultFamily = GuiDocument::fontfamilies[
1668 fontModule->fontsDefaultCO->currentIndex()];
1670 if (fontModule->fontsizeCO->currentIndex() == 0)
1671 params.fontsize = "default";
1674 fromqstr(fontModule->fontsizeCO->currentText());
1677 params.papersize = PAPER_SIZE(
1678 pageLayoutModule->papersizeCO->currentIndex());
1680 // custom, A3, B3 and B4 paper sizes need geometry
1681 int psize = pageLayoutModule->papersizeCO->currentIndex();
1682 bool geom_papersize = (psize == 1 || psize == 5 || psize == 8 || psize == 9);
1684 params.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
1685 pageLayoutModule->paperwidthUnitCO);
1687 params.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
1688 pageLayoutModule->paperheightUnitCO);
1690 if (pageLayoutModule->facingPagesCB->isChecked())
1691 params.sides = TwoSides;
1693 params.sides = OneSide;
1695 if (pageLayoutModule->landscapeRB->isChecked())
1696 params.orientation = ORIENTATION_LANDSCAPE;
1698 params.orientation = ORIENTATION_PORTRAIT;
1701 params.use_geometry = !marginsModule->marginCB->isChecked()
1704 Ui::MarginsUi const * m = marginsModule;
1706 params.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
1707 params.topmargin = widgetsToLength(m->topLE, m->topUnit);
1708 params.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
1709 params.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
1710 params.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
1711 params.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
1712 params.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
1713 params.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
1715 branchesModule->apply(params);
1718 PDFOptions & pdf = params.pdfoptions();
1719 pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
1720 pdf.title = fromqstr(pdfSupportModule->titleLE->text());
1721 pdf.author = fromqstr(pdfSupportModule->authorLE->text());
1722 pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
1723 pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
1725 pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
1726 pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
1727 pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
1728 pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
1730 pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
1731 pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
1732 pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
1733 pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
1734 pdf.backref = pdfSupportModule->backrefCB->isChecked();
1735 pdf.pagebackref = pdfSupportModule->pagebackrefCB->isChecked();
1736 if (pdfSupportModule->fullscreenCB->isChecked())
1737 pdf.pagemode = pdf.pagemode_fullscreen;
1739 pdf.pagemode.clear();
1740 pdf.quoted_options = pdf.quoted_options_check(
1741 fromqstr(pdfSupportModule->optionsLE->text()));
1744 vector<string> & files = params.extraEmbeddedFiles();
1746 for (int i = 0; i < embeddedFilesModule->extraLW->count(); ++i) {
1747 QListWidgetItem * item = embeddedFilesModule->extraLW->item(i);
1748 files.push_back(fromqstr(item->text()));
1753 static int findPos(QStringList const & vec, QString const & val)
1755 for (int i = 0; i != vec.size(); ++i)
1762 void GuiDocument::updateParams()
1768 void GuiDocument::updateParams(BufferParams const & params)
1770 // set the default unit
1771 Length::UNIT defaultUnit = Length::CM;
1772 switch (lyxrc.default_papersize) {
1773 case PAPER_DEFAULT: break;
1775 case PAPER_USLETTER:
1777 case PAPER_USEXECUTIVE:
1778 defaultUnit = Length::IN;
1787 defaultUnit = Length::CM;
1794 preambleModule->update(params, id());
1797 biblioModule->citeDefaultRB->setChecked(
1798 params.getEngine() == biblio::ENGINE_BASIC);
1800 biblioModule->citeNatbibRB->setChecked(
1801 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL ||
1802 params.getEngine() == biblio::ENGINE_NATBIB_AUTHORYEAR);
1804 biblioModule->citeStyleCO->setCurrentIndex(
1805 params.getEngine() == biblio::ENGINE_NATBIB_NUMERICAL);
1807 biblioModule->citeJurabibRB->setChecked(
1808 params.getEngine() == biblio::ENGINE_JURABIB);
1810 biblioModule->bibtopicCB->setChecked(
1811 params.use_bibtopic);
1813 // language & quotes
1814 int const pos = findPos(lang_, toqstr(params.language->lang()));
1815 langModule->languageCO->setCurrentIndex(pos);
1817 langModule->quoteStyleCO->setCurrentIndex(
1818 params.quotes_language);
1820 bool default_enc = true;
1821 if (params.inputenc != "auto") {
1822 default_enc = false;
1823 if (params.inputenc == "default") {
1824 langModule->encodingCO->setCurrentIndex(0);
1826 int const i = langModule->encodingCO->findText(
1827 toqstr(params.inputenc));
1829 langModule->encodingCO->setCurrentIndex(i);
1831 // unknown encoding. Set to default.
1835 langModule->defaultencodingRB->setChecked(default_enc);
1836 langModule->otherencodingRB->setChecked(!default_enc);
1839 int const min_toclevel = documentClass().min_toclevel();
1840 int const max_toclevel = documentClass().max_toclevel();
1841 if (documentClass().hasTocLevels()) {
1842 numberingModule->setEnabled(true);
1843 numberingModule->depthSL->setMinimum(min_toclevel - 1);
1844 numberingModule->depthSL->setMaximum(max_toclevel);
1845 numberingModule->depthSL->setValue(params.secnumdepth);
1846 numberingModule->tocSL->setMaximum(min_toclevel - 1);
1847 numberingModule->tocSL->setMaximum(max_toclevel);
1848 numberingModule->tocSL->setValue(params.tocdepth);
1851 numberingModule->setEnabled(false);
1852 numberingModule->tocTW->clear();
1856 bulletsModule->setBullet(0, params.user_defined_bullet(0));
1857 bulletsModule->setBullet(1, params.user_defined_bullet(1));
1858 bulletsModule->setBullet(2, params.user_defined_bullet(2));
1859 bulletsModule->setBullet(3, params.user_defined_bullet(3));
1860 bulletsModule->init();
1863 int nitem = findToken(tex_graphics, params.graphicsDriver);
1865 latexModule->psdriverCO->setCurrentIndex(nitem);
1868 mathsModule->amsCB->setChecked(
1869 params.use_amsmath == BufferParams::package_on);
1870 mathsModule->amsautoCB->setChecked(
1871 params.use_amsmath == BufferParams::package_auto);
1873 mathsModule->esintCB->setChecked(
1874 params.use_esint == BufferParams::package_on);
1875 mathsModule->esintautoCB->setChecked(
1876 params.use_esint == BufferParams::package_auto);
1878 switch (params.spacing().getSpace()) {
1879 case Spacing::Other: nitem = 3; break;
1880 case Spacing::Double: nitem = 2; break;
1881 case Spacing::Onehalf: nitem = 1; break;
1882 case Spacing::Default: case Spacing::Single: nitem = 0; break;
1886 string const & layoutID = params.baseClassID();
1887 setLayoutComboByIDString(layoutID);
1889 updatePagestyle(documentClass().opt_pagestyle(),
1892 textLayoutModule->lspacingCO->setCurrentIndex(nitem);
1893 if (params.spacing().getSpace() == Spacing::Other) {
1894 textLayoutModule->lspacingLE->setText(
1895 toqstr(params.spacing().getValueAsString()));
1899 if (params.paragraph_separation == BufferParams::PARSEP_INDENT)
1900 textLayoutModule->indentRB->setChecked(true);
1902 textLayoutModule->skipRB->setChecked(true);
1905 switch (params.getDefSkip().kind()) {
1906 case VSpace::SMALLSKIP:
1909 case VSpace::MEDSKIP:
1912 case VSpace::BIGSKIP:
1915 case VSpace::LENGTH:
1918 string const length = params.getDefSkip().asLyXCommand();
1919 lengthToWidgets(textLayoutModule->skipLE,
1920 textLayoutModule->skipLengthCO,
1921 length, defaultUnit);
1928 textLayoutModule->skipCO->setCurrentIndex(skip);
1931 textLayoutModule->twoColumnCB->setChecked(
1932 params.columns == 2);
1934 // break listings_params to multiple lines
1936 InsetListingsParams(params.listings_params).separatedParams();
1937 textLayoutModule->listingsED->setPlainText(toqstr(lstparams));
1939 if (!params.options.empty()) {
1940 latexModule->optionsLE->setText(
1941 toqstr(params.options));
1943 latexModule->optionsLE->setText(QString());
1946 floatModule->set(params.float_placement);
1949 updateFontsize(documentClass().opt_fontsize(),
1952 int n = findToken(tex_fonts_roman, params.fontsRoman);
1954 fontModule->fontsRomanCO->setCurrentIndex(n);
1958 n = findToken(tex_fonts_sans, params.fontsSans);
1960 fontModule->fontsSansCO->setCurrentIndex(n);
1964 n = findToken(tex_fonts_monospaced, params.fontsTypewriter);
1966 fontModule->fontsTypewriterCO->setCurrentIndex(n);
1970 fontModule->fontScCB->setChecked(params.fontsSC);
1971 fontModule->fontOsfCB->setChecked(params.fontsOSF);
1972 fontModule->scaleSansSB->setValue(params.fontsSansScale);
1973 fontModule->scaleTypewriterSB->setValue(params.fontsTypewriterScale);
1974 n = findToken(GuiDocument::fontfamilies, params.fontsDefaultFamily);
1976 fontModule->fontsDefaultCO->setCurrentIndex(n);
1979 int const psize = params.papersize;
1980 pageLayoutModule->papersizeCO->setCurrentIndex(psize);
1981 setCustomPapersize(psize);
1983 bool const landscape =
1984 params.orientation == ORIENTATION_LANDSCAPE;
1985 pageLayoutModule->landscapeRB->setChecked(landscape);
1986 pageLayoutModule->portraitRB->setChecked(!landscape);
1988 pageLayoutModule->facingPagesCB->setChecked(
1989 params.sides == TwoSides);
1992 lengthToWidgets(pageLayoutModule->paperwidthLE,
1993 pageLayoutModule->paperwidthUnitCO, params.paperwidth, defaultUnit);
1995 lengthToWidgets(pageLayoutModule->paperheightLE,
1996 pageLayoutModule->paperheightUnitCO, params.paperheight, defaultUnit);
1999 Ui::MarginsUi * m = marginsModule;
2001 setMargins(!params.use_geometry);
2003 lengthToWidgets(m->topLE, m->topUnit,
2004 params.topmargin, defaultUnit);
2006 lengthToWidgets(m->bottomLE, m->bottomUnit,
2007 params.bottommargin, defaultUnit);
2009 lengthToWidgets(m->innerLE, m->innerUnit,
2010 params.leftmargin, defaultUnit);
2012 lengthToWidgets(m->outerLE, m->outerUnit,
2013 params.rightmargin, defaultUnit);
2015 lengthToWidgets(m->headheightLE, m->headheightUnit,
2016 params.headheight, defaultUnit);
2018 lengthToWidgets(m->headsepLE, m->headsepUnit,
2019 params.headsep, defaultUnit);
2021 lengthToWidgets(m->footskipLE, m->footskipUnit,
2022 params.footskip, defaultUnit);
2024 lengthToWidgets(m->columnsepLE, m->columnsepUnit,
2025 params.columnsep, defaultUnit);
2027 branchesModule->update(params);
2030 PDFOptions const & pdf = params.pdfoptions();
2031 pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
2032 pdfSupportModule->titleLE->setText(toqstr(pdf.title));
2033 pdfSupportModule->authorLE->setText(toqstr(pdf.author));
2034 pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
2035 pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
2037 pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
2038 pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
2039 pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
2041 pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
2043 pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
2044 pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
2045 pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
2046 pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
2047 pdfSupportModule->backrefCB->setChecked(pdf.backref);
2048 pdfSupportModule->pagebackrefCB->setChecked(pdf.pagebackref);
2049 pdfSupportModule->fullscreenCB->setChecked
2050 (pdf.pagemode == pdf.pagemode_fullscreen);
2052 pdfSupportModule->optionsLE->setText(
2053 toqstr(pdf.quoted_options));
2055 setExtraEmbeddedFileList();
2059 void GuiDocument::applyView()
2065 void GuiDocument::saveDocDefault()
2067 // we have to apply the params first
2073 void GuiDocument::updateAvailableModules()
2075 modules_av_model_.clear();
2076 vector<modInfoStruct> const modInfoList = getModuleInfo();
2077 int const mSize = modInfoList.size();
2078 for (int i = 0; i != mSize; ++i) {
2079 modInfoStruct const & modInfo = modInfoList[i];
2080 modules_av_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
2085 void GuiDocument::updateSelectedModules()
2087 // and selected ones, too
2088 modules_sel_model_.clear();
2089 vector<modInfoStruct> const selModList = getSelectedModules();
2090 int const sSize = selModList.size();
2091 for (int i = 0; i != sSize; ++i) {
2092 modInfoStruct const & modInfo = selModList[i];
2093 modules_sel_model_.insertRow(i, qt_(modInfo.name), modInfo.id);
2098 void GuiDocument::updateContents()
2100 if (id() == current_id_)
2103 updateAvailableModules();
2104 updateSelectedModules();
2106 //FIXME It'd be nice to make sure here that the selected
2107 //modules are consistent: That required modules are actually
2108 //selected, and that we don't have conflicts. If so, we could
2109 //at least pop up a warning.
2115 void GuiDocument::forceUpdate()
2117 // reset to force dialog update
2123 void GuiDocument::useClassDefaults()
2125 if (applyPB->isEnabled()) {
2126 int const ret = Alert::prompt(_("Unapplied changes"),
2127 _("Some changes in the dialog were not yet applied.\n"
2128 "If you do not apply now, they will be lost after this action."),
2129 1, 1, _("&Apply"), _("&Dismiss"));
2134 int idx = latexModule->classCO->currentIndex();
2135 string const classname = classes_model_.getIDString(idx);
2136 if (!bp_.setBaseClass(classname)) {
2137 Alert::error(_("Error"), _("Unable to set document class."));
2140 bp_.useClassDefaults();
2145 void GuiDocument::setLayoutComboByIDString(std::string const & idString)
2147 int idx = classes_model_.findIDString(idString);
2149 Alert::warning(_("Can't set layout!"),
2150 bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
2152 latexModule->classCO->setCurrentIndex(idx);
2156 bool GuiDocument::isValid()
2158 return validate_listings_params().empty()
2159 && (textLayoutModule->skipCO->currentIndex() != 3
2160 || !textLayoutModule->skipLE->text().isEmpty());
2164 char const * const GuiDocument::fontfamilies[5] = {
2165 "default", "rmdefault", "sfdefault", "ttdefault", ""
2169 char const * GuiDocument::fontfamilies_gui[5] = {
2170 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
2174 bool GuiDocument::initialiseParams(string const &)
2176 bp_ = buffer().params();
2182 void GuiDocument::clearParams()
2184 bp_ = BufferParams();
2188 BufferId GuiDocument::id() const
2194 vector<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
2196 return moduleNames_;
2200 vector<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
2202 vector<string> const & mods = params().getModules();
2203 vector<string>::const_iterator it = mods.begin();
2204 vector<string>::const_iterator end = mods.end();
2205 vector<modInfoStruct> mInfo;
2206 for (; it != end; ++it) {
2209 LyXModule * mod = moduleList[*it];
2211 m.name = mod->getName();
2213 m.name = *it + " (Not Found)";
2220 DocumentClass const & GuiDocument::documentClass() const
2222 return bp_.documentClass();
2226 static void dispatch_bufferparams(Dialog const & dialog,
2227 BufferParams const & bp, kb_action lfun)
2230 ss << "\\begin_header\n";
2232 ss << "\\end_header\n";
2233 dialog.dispatch(FuncRequest(lfun, ss.str()));
2237 void GuiDocument::dispatchParams()
2239 // This must come first so that a language change is correctly noticed
2242 // Apply the BufferParams. Note that this will set the base class
2243 // and then update the buffer's layout.
2244 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
2246 // Generate the colours requested by each new branch.
2247 BranchList & branchlist = params().branchlist();
2248 if (!branchlist.empty()) {
2249 BranchList::const_iterator it = branchlist.begin();
2250 BranchList::const_iterator const end = branchlist.end();
2251 for (; it != end; ++it) {
2252 docstring const & current_branch = it->getBranch();
2253 Branch const * branch = branchlist.find(current_branch);
2254 string const x11hexname = X11hexname(branch->getColor());
2255 // display the new color
2256 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
2257 dispatch(FuncRequest(LFUN_SET_COLOR, str));
2260 // Open insets of selected branches, close deselected ones
2261 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
2264 // FIXME: If we used an LFUN, we would not need those two lines:
2265 bufferview()->processUpdateFlags(Update::Force | Update::FitCursor);
2269 void GuiDocument::setLanguage() const
2271 Language const * const newL = bp_.language;
2272 if (buffer().params().language == newL)
2275 string const & lang_name = newL->lang();
2276 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
2280 void GuiDocument::saveAsDefault() const
2282 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
2286 bool GuiDocument::isFontAvailable(string const & font) const
2288 if (font == "default" || font == "cmr"
2289 || font == "cmss" || font == "cmtt")
2290 // these are standard
2292 if (font == "lmodern" || font == "lmss" || font == "lmtt")
2293 return LaTeXFeatures::isAvailable("lmodern");
2294 if (font == "times" || font == "palatino"
2295 || font == "helvet" || font == "courier")
2296 return LaTeXFeatures::isAvailable("psnfss");
2297 if (font == "cmbr" || font == "cmtl")
2298 return LaTeXFeatures::isAvailable("cmbright");
2299 if (font == "utopia")
2300 return LaTeXFeatures::isAvailable("utopia")
2301 || LaTeXFeatures::isAvailable("fourier");
2302 if (font == "beraserif" || font == "berasans"
2303 || font == "beramono")
2304 return LaTeXFeatures::isAvailable("bera");
2305 return LaTeXFeatures::isAvailable(font);
2309 bool GuiDocument::providesOSF(string const & font) const
2312 return isFontAvailable("eco");
2313 if (font == "palatino")
2314 return isFontAvailable("mathpazo");
2319 bool GuiDocument::providesSC(string const & font) const
2321 if (font == "palatino")
2322 return isFontAvailable("mathpazo");
2323 if (font == "utopia")
2324 return isFontAvailable("fourier");
2329 bool GuiDocument::providesScale(string const & font) const
2331 return font == "helvet" || font == "luximono"
2332 || font == "berasans" || font == "beramono";
2336 void GuiDocument::loadModuleInfo()
2338 moduleNames_.clear();
2339 LyXModuleList::const_iterator it = moduleList.begin();
2340 LyXModuleList::const_iterator end = moduleList.end();
2341 for (; it != end; ++it) {
2344 m.name = it->getName();
2345 moduleNames_.push_back(m);
2350 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
2353 } // namespace frontend
2356 #include "GuiDocument_moc.cpp"