]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.cpp
8-char tab stops are too big in the preamble editor.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
1 /**
2  * \file GuiDocument.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Richard Heck (modules)
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiDocument.h"
15
16 #include "CategorizedCombo.h"
17 #include "GuiApplication.h"
18 #include "GuiBranches.h"
19 #include "GuiIndices.h"
20 #include "GuiSelectionManager.h"
21 #include "LaTeXHighlighter.h"
22 #include "LengthCombo.h"
23 #include "PanelStack.h"
24 #include "Validator.h"
25
26 #include "LayoutFile.h"
27 #include "BranchList.h"
28 #include "buffer_funcs.h"
29 #include "Buffer.h"
30 #include "BufferParams.h"
31 #include "BufferView.h"
32 #include "CiteEnginesList.h"
33 #include "Color.h"
34 #include "ColorCache.h"
35 #include "Converter.h"
36 #include "Cursor.h"
37 #include "Encoding.h"
38 #include "FloatPlacement.h"
39 #include "Format.h"
40 #include "FuncRequest.h"
41 #include "IndicesList.h"
42 #include "Language.h"
43 #include "LaTeXFeatures.h"
44 #include "LaTeXFonts.h"
45 #include "Layout.h"
46 #include "LayoutEnums.h"
47 #include "LayoutModuleList.h"
48 #include "LyXRC.h"
49 #include "ModuleList.h"
50 #include "OutputParams.h"
51 #include "PDFOptions.h"
52 #include "qt_helpers.h"
53 #include "Session.h"
54 #include "Spacing.h"
55 #include "TextClass.h"
56 #include "Undo.h"
57 #include "VSpace.h"
58
59 #include "insets/InsetListingsParams.h"
60
61 #include "support/debug.h"
62 #include "support/FileName.h"
63 #include "support/filetools.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
67
68 #include "frontends/alert.h"
69
70 #include <QAbstractItemModel>
71 #include <QHeaderView>
72 #include <QColor>
73 #include <QColorDialog>
74 #include <QCloseEvent>
75 #include <QFontDatabase>
76 #include <QScrollBar>
77 #include <QTextBoundaryFinder>
78 #include <QTextCursor>
79
80 #include <sstream>
81 #include <vector>
82
83 #ifdef IN
84 #undef IN
85 #endif
86
87
88 // a style sheet for buttons
89 // this is for example used for the background color setting button
90 static inline QString colorButtonStyleSheet(QColor const & bgColor)
91 {
92         if (bgColor.isValid()) {
93                 QString rc = QLatin1String("background-color:");
94                 rc += bgColor.name();
95                 return rc;
96         }
97         return QString();
98 }
99
100
101 using namespace std;
102 using namespace lyx::support;
103
104
105 namespace {
106
107 char const * const tex_graphics[] =
108 {
109         "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
110         "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
111         "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
112         "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
113         "xetex", "none", ""
114 };
115
116
117 char const * const tex_graphics_gui[] =
118 {
119         N_("Default"), "dvialw", "DviLaser", "dvipdf", "DVIPDFM", "DVIPDFMx",
120         "Dvips", "DVIPSONE", "DVItoPS", "DVIWIN", "DVIWindo", "dvi2ps", "EmTeX",
121         "LN", "OzTeX", "pctexhp", "pctexps", "pctexwin", "PCTeX32", "pdfTeX",
122         "psprint", "pubps", "tcidvi", "Textures", "TrueTeX", "VTeX", "xdvi",
123         "XeTeX", N_("None"), ""
124 };
125
126
127 char const * backref_opts[] =
128 {
129         "false", "section", "slide", "page", ""
130 };
131
132
133 char const * backref_opts_gui[] =
134 {
135         N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
136 };
137
138
139 char const * lst_packages[] =
140 {
141         "Listings", "Minted", ""
142 };
143
144
145 vector<string> engine_types_;
146 vector<pair<string, QString> > pagestyles;
147
148 QMap<QString, QString> rmfonts_;
149 QMap<QString, QString> sffonts_;
150 QMap<QString, QString> ttfonts_;
151 QMap<QString, QString> mathfonts_;
152
153
154 } // anonymous namespace
155
156 namespace lyx {
157
158 RGBColor set_backgroundcolor;
159 bool is_backgroundcolor;
160 RGBColor set_fontcolor;
161 bool is_fontcolor;
162 RGBColor set_notefontcolor;
163 RGBColor set_boxbgcolor;
164 bool forced_fontspec_activation;
165
166 namespace {
167 // used when sorting the textclass list.
168 class less_textclass_avail_desc
169         : public binary_function<string, string, int>
170 {
171 public:
172         bool operator()(string const & lhs, string const & rhs) const
173         {
174                 // Ordering criteria:
175                 //   1. Availability of text class
176                 //   2. Description (lexicographic)
177                 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
178                 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
179                 int const order = compare_no_case(
180                         translateIfPossible(from_utf8(tc1.description())),
181                         translateIfPossible(from_utf8(tc2.description())));
182                 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
183                         (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
184         }
185 };
186
187 } // namespace
188
189 namespace frontend {
190 namespace {
191
192 vector<string> getRequiredList(string const & modName)
193 {
194         LyXModule const * const mod = theModuleList[modName];
195         if (!mod)
196                 return vector<string>(); //empty such thing
197         return mod->getRequiredModules();
198 }
199
200
201 vector<string> getExcludedList(string const & modName)
202 {
203         LyXModule const * const mod = theModuleList[modName];
204         if (!mod)
205                 return vector<string>(); //empty such thing
206         return mod->getExcludedModules();
207 }
208
209
210 docstring getModuleCategory(string const & modName)
211 {
212         LyXModule const * const mod = theModuleList[modName];
213         if (!mod)
214                 return docstring();
215         return from_utf8(mod->category());
216 }
217
218
219 docstring getModuleDescription(string const & modName)
220 {
221         LyXModule const * const mod = theModuleList[modName];
222         if (!mod)
223                 return _("Module not found!");
224         // FIXME Unicode
225         return translateIfPossible(from_utf8(mod->getDescription()));
226 }
227
228
229 vector<string> getPackageList(string const & modName)
230 {
231         LyXModule const * const mod = theModuleList[modName];
232         if (!mod)
233                 return vector<string>(); //empty such thing
234         return mod->getPackageList();
235 }
236
237
238 bool isModuleAvailable(string const & modName)
239 {
240         LyXModule const * const mod = theModuleList[modName];
241         if (!mod)
242                 return false;
243         return mod->isAvailable();
244 }
245
246 } // anonymous namespace
247
248
249 /////////////////////////////////////////////////////////////////////
250 //
251 // ModuleSelectionManager
252 //
253 /////////////////////////////////////////////////////////////////////
254
255 /// SelectionManager for use with modules
256 class ModuleSelectionManager : public GuiSelectionManager
257 {
258 public:
259         ///
260         ModuleSelectionManager(QObject * parent,
261                                QTreeView * availableLV,
262                                QListView * selectedLV,
263                                QPushButton * addPB,
264                                QPushButton * delPB,
265                                QPushButton * upPB,
266                                QPushButton * downPB,
267                                GuiIdListModel * availableModel,
268                                GuiIdListModel * selectedModel,
269                                GuiDocument const * container)
270                 : GuiSelectionManager(parent, availableLV, selectedLV, addPB, delPB,
271                                       upPB, downPB, availableModel, selectedModel),
272                   container_(container)
273                 {}
274         ///
275         void updateProvidedModules(LayoutModuleList const & pm)
276                         { provided_modules_ = pm.list(); }
277         ///
278         void updateExcludedModules(LayoutModuleList const & em)
279                         { excluded_modules_ = em.list(); }
280 private:
281         ///
282         virtual void updateAddPB();
283         ///
284         virtual void updateUpPB();
285         ///
286         virtual void updateDownPB();
287         ///
288         virtual void updateDelPB();
289         /// returns availableModel as a GuiIdListModel
290         GuiIdListModel * getAvailableModel()
291         {
292                 return dynamic_cast<GuiIdListModel *>(availableModel);
293         }
294         /// returns selectedModel as a GuiIdListModel
295         GuiIdListModel * getSelectedModel()
296         {
297                 return dynamic_cast<GuiIdListModel *>(selectedModel);
298         }
299         /// keeps a list of the modules the text class provides
300         list<string> provided_modules_;
301         /// similarly...
302         list<string> excluded_modules_;
303         ///
304         GuiDocument const * container_;
305 };
306
307 void ModuleSelectionManager::updateAddPB()
308 {
309         int const arows = availableModel->rowCount();
310         QModelIndexList const avail_sels =
311                         availableLV->selectionModel()->selectedIndexes();
312
313         // disable if there aren't any modules (?), if none of them is chosen
314         // in the dialog, or if the chosen one is already selected for use.
315         if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
316                 addPB->setEnabled(false);
317                 return;
318         }
319
320         QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
321         string const modname = getAvailableModel()->getIDString(idx.row());
322
323         bool const enable =
324                 container_->params().layoutModuleCanBeAdded(modname);
325         addPB->setEnabled(enable);
326 }
327
328
329 void ModuleSelectionManager::updateDownPB()
330 {
331         int const srows = selectedModel->rowCount();
332         if (srows == 0) {
333                 downPB->setEnabled(false);
334                 return;
335         }
336         QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
337         int const curRow = curidx.row();
338         if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
339                 downPB->setEnabled(false);
340                 return;
341         }
342
343         // determine whether immediately succeding element requires this one
344         string const curmodname = getSelectedModel()->getIDString(curRow);
345         string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
346
347         vector<string> reqs = getRequiredList(nextmodname);
348
349         // if it doesn't require anything....
350         if (reqs.empty()) {
351                 downPB->setEnabled(true);
352                 return;
353         }
354
355         // Enable it if this module isn't required.
356         // FIXME This should perhaps be more flexible and check whether, even
357         // if the next one is required, there is also an earlier one that will do.
358         downPB->setEnabled(
359                         find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
360 }
361
362 void ModuleSelectionManager::updateUpPB()
363 {
364         int const srows = selectedModel->rowCount();
365         if (srows == 0) {
366                 upPB->setEnabled(false);
367                 return;
368         }
369
370         QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
371         int curRow = curIdx.row();
372         if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
373                 upPB->setEnabled(false);
374                 return;
375         }
376         string const curmodname = getSelectedModel()->getIDString(curRow);
377
378         // determine whether immediately preceding element is required by this one
379         vector<string> reqs = getRequiredList(curmodname);
380
381         // if this one doesn't require anything....
382         if (reqs.empty()) {
383                 upPB->setEnabled(true);
384                 return;
385         }
386
387
388         // Enable it if the preceding module isn't required.
389         // NOTE This is less flexible than it might be. We could check whether, even
390         // if the previous one is required, there is an earlier one that would do.
391         string const premod = getSelectedModel()->getIDString(curRow - 1);
392         upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
393 }
394
395 void ModuleSelectionManager::updateDelPB()
396 {
397         int const srows = selectedModel->rowCount();
398         if (srows == 0) {
399                 deletePB->setEnabled(false);
400                 return;
401         }
402
403         QModelIndex const & curidx =
404                 selectedLV->selectionModel()->currentIndex();
405         int const curRow = curidx.row();
406         if (curRow < 0 || curRow >= srows) { // invalid index?
407                 deletePB->setEnabled(false);
408                 return;
409         }
410
411         string const curmodname = getSelectedModel()->getIDString(curRow);
412
413         // We're looking here for a reason NOT to enable the button. If we
414         // find one, we disable it and return. If we don't, we'll end up at
415         // the end of the function, and then we enable it.
416         for (int i = curRow + 1; i < srows; ++i) {
417                 string const thisMod = getSelectedModel()->getIDString(i);
418                 vector<string> reqs = getRequiredList(thisMod);
419                 //does this one require us?
420                 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
421                         //no...
422                         continue;
423
424                 // OK, so this module requires us
425                 // is there an EARLIER module that also satisfies the require?
426                 // NOTE We demand that it be earlier to keep the list of modules
427                 // consistent with the rule that a module must be proceeded by a
428                 // required module. There would be more flexible ways to proceed,
429                 // but that would be a lot more complicated, and the logic here is
430                 // already complicated. (That's why I've left the debugging code.)
431                 // lyxerr << "Testing " << thisMod << endl;
432                 bool foundone = false;
433                 for (int j = 0; j < curRow; ++j) {
434                         string const mod = getSelectedModel()->getIDString(j);
435                         // lyxerr << "In loop: Testing " << mod << endl;
436                         // do we satisfy the require?
437                         if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
438                                 // lyxerr << mod << " does the trick." << endl;
439                                 foundone = true;
440                                 break;
441                         }
442                 }
443                 // did we find a module to satisfy the require?
444                 if (!foundone) {
445                         // lyxerr << "No matching module found." << endl;
446                         deletePB->setEnabled(false);
447                         return;
448                 }
449         }
450         // lyxerr << "All's well that ends well." << endl;
451         deletePB->setEnabled(true);
452 }
453
454
455 /////////////////////////////////////////////////////////////////////
456 //
457 // PreambleModule
458 //
459 /////////////////////////////////////////////////////////////////////
460
461 PreambleModule::PreambleModule(QWidget * parent)
462         : UiWidget<Ui::PreambleUi>(parent), current_id_(0)
463 {
464         // This is not a memory leak. The object will be destroyed
465         // with this.
466         // @ is letter in the LyX user preamble
467         (void) new LaTeXHighlighter(preambleTE->document(), true);
468         preambleTE->setFont(guiApp->typewriterSystemFont());
469         preambleTE->setWordWrapMode(QTextOption::NoWrap);
470         setFocusProxy(preambleTE);
471         connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
472         connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
473         connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
474         connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
475         checkFindButton();
476         // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
477         const int tabStop = 4;
478         QFontMetrics metrics(preambleTE->currentFont());
479         preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
480 }
481
482
483 void PreambleModule::checkFindButton()
484 {
485         findButtonPB->setEnabled(!findLE->text().isEmpty());
486 }
487
488
489 void PreambleModule::findText()
490 {
491         bool const found = preambleTE->find(findLE->text());
492         if (!found) {
493                 // wrap
494                 QTextCursor qtcur = preambleTE->textCursor();
495                 qtcur.movePosition(QTextCursor::Start);
496                 preambleTE->setTextCursor(qtcur);
497                 preambleTE->find(findLE->text());
498         }
499 }
500
501
502 void PreambleModule::update(BufferParams const & params, BufferId id)
503 {
504         QString preamble = toqstr(params.preamble);
505         // Nothing to do if the params and preamble are unchanged.
506         if (id == current_id_
507                 && preamble == preambleTE->document()->toPlainText())
508                 return;
509
510         QTextCursor cur = preambleTE->textCursor();
511         // Save the coords before switching to the new one.
512         preamble_coords_[current_id_] =
513                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
514
515         // Save the params address for further use.
516         current_id_ = id;
517         preambleTE->document()->setPlainText(preamble);
518         Coords::const_iterator it = preamble_coords_.find(current_id_);
519         if (it == preamble_coords_.end())
520                 // First time we open this one.
521                 preamble_coords_[current_id_] = make_pair(0, 0);
522         else {
523                 // Restore saved coords.
524                 cur = preambleTE->textCursor();
525                 cur.setPosition(it->second.first);
526                 preambleTE->setTextCursor(cur);
527                 preambleTE->verticalScrollBar()->setValue(it->second.second);
528         }
529 }
530
531
532 void PreambleModule::apply(BufferParams & params)
533 {
534         params.preamble = qstring_to_ucs4(preambleTE->document()->toPlainText());
535 }
536
537
538 void PreambleModule::closeEvent(QCloseEvent * e)
539 {
540         // Save the coords before closing.
541         QTextCursor cur = preambleTE->textCursor();
542         preamble_coords_[current_id_] =
543                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
544         e->accept();
545 }
546
547
548 /////////////////////////////////////////////////////////////////////
549 //
550 // LocalLayout
551 //
552 /////////////////////////////////////////////////////////////////////
553
554
555 LocalLayout::LocalLayout(QWidget * parent)
556         : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
557 {
558         connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
559         connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
560         connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
561 }
562
563
564 void LocalLayout::update(BufferParams const & params, BufferId id)
565 {
566         QString layout = toqstr(params.getLocalLayout(false));
567         // Nothing to do if the params and preamble are unchanged.
568         if (id == current_id_
569                 && layout == locallayoutTE->document()->toPlainText())
570                 return;
571
572         // Save the params address for further use.
573         current_id_ = id;
574         locallayoutTE->document()->setPlainText(layout);
575         validate();
576 }
577
578
579 void LocalLayout::apply(BufferParams & params)
580 {
581         docstring const layout =
582                 qstring_to_ucs4(locallayoutTE->document()->toPlainText());
583         params.setLocalLayout(layout, false);
584 }
585
586
587 void LocalLayout::hideConvert()
588 {
589         convertPB->setEnabled(false);
590         convertLB->setText("");
591         convertPB->hide();
592         convertLB->hide();
593 }
594
595
596 void LocalLayout::textChanged()
597 {
598         static const QString message =
599                 qt_("Press button to check validity...");
600         string const layout =
601                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
602
603         if (layout.empty()) {
604                 validated_ = true;
605                 validatePB->setEnabled(false);
606                 validLB->setText("");
607                 hideConvert();
608                 changed();
609         } else if (!validatePB->isEnabled()) {
610                 // if that's already enabled, we shouldn't need to do anything.
611                 validated_ = false;
612                 validLB->setText(message);
613                 validatePB->setEnabled(true);
614                 hideConvert();
615                 changed();
616         }
617 }
618
619
620 void LocalLayout::convert() {
621         string const layout =
622                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
623         string const newlayout = TextClass::convert(layout);
624         if (!newlayout.empty())
625                 locallayoutTE->setPlainText(toqstr(newlayout));
626         validate();
627 }
628
629
630 void LocalLayout::convertPressed() {
631         convert();
632         hideConvert();
633         changed();
634 }
635
636
637 void LocalLayout::validate() {
638         // Bold text
639         static const QString vpar("<p style=\"font-weight: bold;\">%1</p>");
640         // Flashy red bold text
641         static const QString ivpar("<p style=\"color: #c00000; font-weight: bold; \">"
642                                    "%1</p>");
643         string const layout =
644                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
645         if (!layout.empty()) {
646                 TextClass::ReturnValues const ret = TextClass::validate(layout);
647                 validated_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
648                 validatePB->setEnabled(false);
649                 validLB->setText(validated_ ? vpar.arg(qt_("Layout is valid!"))
650                                             : ivpar.arg(qt_("Layout is invalid!")));
651                 if (ret == TextClass::OK_OLDFORMAT) {
652                         convertPB->show();
653                         // Testing conversion to LYXFILE_LAYOUT_FORMAT at this point
654                         // already.
655                         if (TextClass::convert(layout).empty()) {
656                                 // Conversion failed. If LAYOUT_FORMAT > LYXFILE_LAYOUT_FORMAT,
657                                 // then maybe the layout is still valid, but its format is more
658                                 // recent than LYXFILE_LAYOUT_FORMAT. However, if LAYOUT_FORMAT
659                                 // == LYXFILE_LAYOUT_FORMAT then something is definitely wrong.
660                                 convertPB->setEnabled(false);
661                                 const QString text = (LAYOUT_FORMAT == LYXFILE_LAYOUT_FORMAT)
662                                         ? ivpar.arg(qt_("Conversion to current format impossible!"))
663                                         : vpar.arg(qt_("Conversion to current stable format "
664                                                        "impossible."));
665                                 convertLB->setText(text);
666                         } else {
667                                 convertPB->setEnabled(true);
668                                 convertLB->setText(qt_("Convert to current format"));
669                         }
670                         convertLB->show();
671                 } else {
672                         convertPB->hide();
673                         convertLB->hide();
674                 }
675         }
676 }
677
678
679 void LocalLayout::validatePressed() {
680         validate();
681         changed();
682 }
683
684
685 /////////////////////////////////////////////////////////////////////
686 //
687 // DocumentDialog
688 //
689 /////////////////////////////////////////////////////////////////////
690
691
692 GuiDocument::GuiDocument(GuiView & lv)
693         : GuiDialog(lv, "document", qt_("Document Settings")),
694           biblioChanged_(false), nonModuleChanged_(false),
695           modulesChanged_(false), shellescapeChanged_(false)
696 {
697         setupUi(this);
698
699         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
700         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
701         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
702         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
703
704         connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
705         connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
706
707         // Manage the restore, ok, apply, restore and cancel/close buttons
708         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
709         bc().setOK(okPB);
710         bc().setApply(applyPB);
711         bc().setCancel(closePB);
712         bc().setRestore(restorePB);
713
714
715         // text layout
716         textLayoutModule = new UiWidget<Ui::TextLayoutUi>(this);
717         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
718                 this, SLOT(change_adaptor()));
719         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
720                 this, SLOT(setLSpacing(int)));
721         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
722                 this, SLOT(change_adaptor()));
723
724         connect(textLayoutModule->indentRB, SIGNAL(clicked()),
725                 this, SLOT(change_adaptor()));
726         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
727                 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
728         connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
729                 this, SLOT(change_adaptor()));
730         connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
731                 this, SLOT(setIndent(int)));
732         connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
733                 this, SLOT(change_adaptor()));
734         connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
735                 this, SLOT(change_adaptor()));
736
737         connect(textLayoutModule->skipRB, SIGNAL(clicked()),
738                 this, SLOT(change_adaptor()));
739         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
740                 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
741         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
742                 this, SLOT(change_adaptor()));
743         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
744                 this, SLOT(setSkip(int)));
745         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
746                 this, SLOT(change_adaptor()));
747         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
748                 this, SLOT(change_adaptor()));
749
750         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
751                 this, SLOT(enableIndent(bool)));
752         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
753                 this, SLOT(enableSkip(bool)));
754
755         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
756                 this, SLOT(change_adaptor()));
757         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
758                 this, SLOT(setColSep()));
759         connect(textLayoutModule->justCB, SIGNAL(clicked()),
760                 this, SLOT(change_adaptor()));
761
762         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
763                 textLayoutModule->lspacingLE));
764         textLayoutModule->indentLE->setValidator(new LengthValidator(
765                 textLayoutModule->indentLE));
766         textLayoutModule->skipLE->setValidator(new LengthValidator(
767                 textLayoutModule->skipLE));
768
769         textLayoutModule->indentCO->addItem(qt_("Default"));
770         textLayoutModule->indentCO->addItem(qt_("Custom"));
771         textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
772         textLayoutModule->skipCO->addItem(qt_("MedSkip"));
773         textLayoutModule->skipCO->addItem(qt_("BigSkip"));
774         textLayoutModule->skipCO->addItem(qt_("Custom"));
775         textLayoutModule->lspacingCO->insertItem(
776                 Spacing::Single, qt_("Single"));
777         textLayoutModule->lspacingCO->insertItem(
778                 Spacing::Onehalf, qt_("OneHalf"));
779         textLayoutModule->lspacingCO->insertItem(
780                 Spacing::Double, qt_("Double"));
781         textLayoutModule->lspacingCO->insertItem(
782                 Spacing::Other, qt_("Custom"));
783         // initialize the length validator
784         bc().addCheckedLineEdit(textLayoutModule->indentLE);
785         bc().addCheckedLineEdit(textLayoutModule->skipLE);
786
787
788         // master/child handling
789         masterChildModule = new UiWidget<Ui::MasterChildUi>(this);
790
791         connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
792                 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
793         connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
794                 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
795         connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
796                 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
797         connect(masterChildModule->includeallRB, SIGNAL(clicked()),
798                 this, SLOT(change_adaptor()));
799         connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
800                 this, SLOT(change_adaptor()));
801         connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
802                 this, SLOT(change_adaptor()));
803         masterChildModule->childrenTW->setColumnCount(2);
804         masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
805         masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
806         masterChildModule->childrenTW->resizeColumnToContents(1);
807         masterChildModule->childrenTW->resizeColumnToContents(2);
808
809
810         // Formats
811         outputModule = new UiWidget<Ui::OutputUi>(this);
812
813         connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
814                 this, SLOT(change_adaptor()));
815         connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
816                 this, SLOT(change_adaptor()));
817         connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
818                 this, SLOT(change_adaptor()));
819         connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
820                 this, SLOT(change_adaptor()));
821         connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
822                 this, SLOT(change_adaptor()));
823
824         connect(outputModule->shellescapeCB, SIGNAL(stateChanged(int)),
825                 this, SLOT(shellescapeChanged()));
826         connect(outputModule->outputsyncCB, SIGNAL(clicked()),
827                 this, SLOT(change_adaptor()));
828         connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
829                 this, SLOT(change_adaptor()));
830         outputModule->synccustomCB->addItem("");
831         outputModule->synccustomCB->addItem("\\synctex=1");
832         outputModule->synccustomCB->addItem("\\synctex=-1");
833         outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
834
835         outputModule->synccustomCB->setValidator(new NoNewLineValidator(
836                 outputModule->synccustomCB));
837
838         connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
839                 this, SLOT(change_adaptor()));
840
841         // fonts
842         fontModule = new FontModule(this);
843         connect(fontModule->osFontsCB, SIGNAL(clicked()),
844                 this, SLOT(change_adaptor()));
845         connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
846                 this, SLOT(osFontsChanged(bool)));
847         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
848                 this, SLOT(change_adaptor()));
849         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
850                 this, SLOT(romanChanged(int)));
851         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
852                 this, SLOT(change_adaptor()));
853         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
854                 this, SLOT(sansChanged(int)));
855         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
856                 this, SLOT(change_adaptor()));
857         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
858                 this, SLOT(ttChanged(int)));
859         connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
860                 this, SLOT(change_adaptor()));
861         connect(fontModule->fontsMathCO, SIGNAL(activated(int)),
862                 this, SLOT(mathFontChanged(int)));
863         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
864                 this, SLOT(change_adaptor()));
865         connect(fontModule->fontencCO, SIGNAL(activated(int)),
866                 this, SLOT(change_adaptor()));
867         connect(fontModule->fontencCO, SIGNAL(activated(int)),
868                 this, SLOT(fontencChanged(int)));
869         connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
870                 this, SLOT(change_adaptor()));
871         connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
872                 this, SLOT(change_adaptor()));
873         connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
874                 this, SLOT(change_adaptor()));
875         connect(fontModule->microtypeCB, SIGNAL(clicked()),
876                 this, SLOT(change_adaptor()));
877         connect(fontModule->dashesCB, SIGNAL(clicked()),
878                 this, SLOT(change_adaptor()));
879         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
880                 this, SLOT(change_adaptor()));
881         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
882                 this, SLOT(change_adaptor()));
883         connect(fontModule->fontScCB, SIGNAL(clicked()),
884                 this, SLOT(change_adaptor()));
885         connect(fontModule->fontScCB, SIGNAL(toggled(bool)),
886                 this, SLOT(fontScToggled(bool)));
887         connect(fontModule->fontOsfCB, SIGNAL(clicked()),
888                 this, SLOT(change_adaptor()));
889         connect(fontModule->fontOsfCB, SIGNAL(toggled(bool)),
890                 this, SLOT(fontOsfToggled(bool)));
891
892         fontModule->fontencLE->setValidator(new NoNewLineValidator(
893                 fontModule->fontencLE));
894         fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
895                 fontModule->cjkFontLE));
896
897         updateFontlist();
898
899         fontModule->fontsizeCO->addItem(qt_("Default"));
900         fontModule->fontsizeCO->addItem(qt_("10"));
901         fontModule->fontsizeCO->addItem(qt_("11"));
902         fontModule->fontsizeCO->addItem(qt_("12"));
903
904         fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
905         fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
906         fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
907
908         for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
909                 fontModule->fontsDefaultCO->addItem(
910                         qt_(GuiDocument::fontfamilies_gui[n]));
911
912         if (!LaTeXFeatures::isAvailable("fontspec"))
913                 fontModule->osFontsCB->setToolTip(
914                         qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
915                             "You need to install the package \"fontspec\" to use this feature"));
916
917
918         // page layout
919         pageLayoutModule = new UiWidget<Ui::PageLayoutUi>(this);
920         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
921                 this, SLOT(papersizeChanged(int)));
922         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
923                 this, SLOT(papersizeChanged(int)));
924         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
925                 this, SLOT(change_adaptor()));
926         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
927                 this, SLOT(change_adaptor()));
928         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
929                 this, SLOT(change_adaptor()));
930         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
931                 this, SLOT(change_adaptor()));
932         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
933                 this, SLOT(change_adaptor()));
934         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
935                 this, SLOT(change_adaptor()));
936         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
937                 this, SLOT(change_adaptor()));
938         connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
939                 this, SLOT(change_adaptor()));
940         connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
941                 this, SLOT(change_adaptor()));
942         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
943                 this, SLOT(change_adaptor()));
944
945         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
946         pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
947         pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
948         pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
949         pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
950         bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
951                 pageLayoutModule->paperheightL);
952         bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
953                 pageLayoutModule->paperwidthL);
954
955         QComboBox * cb = pageLayoutModule->papersizeCO;
956         cb->addItem(qt_("Default"));
957         cb->addItem(qt_("Custom"));
958         cb->addItem(qt_("US letter"));
959         cb->addItem(qt_("US legal"));
960         cb->addItem(qt_("US executive"));
961         cb->addItem(qt_("A0"));
962         cb->addItem(qt_("A1"));
963         cb->addItem(qt_("A2"));
964         cb->addItem(qt_("A3"));
965         cb->addItem(qt_("A4"));
966         cb->addItem(qt_("A5"));
967         cb->addItem(qt_("A6"));
968         cb->addItem(qt_("B0"));
969         cb->addItem(qt_("B1"));
970         cb->addItem(qt_("B2"));
971         cb->addItem(qt_("B3"));
972         cb->addItem(qt_("B4"));
973         cb->addItem(qt_("B5"));
974         cb->addItem(qt_("B6"));
975         cb->addItem(qt_("C0"));
976         cb->addItem(qt_("C1"));
977         cb->addItem(qt_("C2"));
978         cb->addItem(qt_("C3"));
979         cb->addItem(qt_("C4"));
980         cb->addItem(qt_("C5"));
981         cb->addItem(qt_("C6"));
982         cb->addItem(qt_("JIS B0"));
983         cb->addItem(qt_("JIS B1"));
984         cb->addItem(qt_("JIS B2"));
985         cb->addItem(qt_("JIS B3"));
986         cb->addItem(qt_("JIS B4"));
987         cb->addItem(qt_("JIS B5"));
988         cb->addItem(qt_("JIS B6"));
989         // remove the %-items from the unit choice
990         pageLayoutModule->paperwidthUnitCO->noPercents();
991         pageLayoutModule->paperheightUnitCO->noPercents();
992         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
993                 pageLayoutModule->paperheightLE));
994         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
995                 pageLayoutModule->paperwidthLE));
996
997
998         // margins
999         marginsModule = new UiWidget<Ui::MarginsUi>(this);
1000         connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
1001                 this, SLOT(setCustomMargins(bool)));
1002         connect(marginsModule->marginCB, SIGNAL(clicked()),
1003                 this, SLOT(change_adaptor()));
1004         connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
1005                 this, SLOT(change_adaptor()));
1006         connect(marginsModule->topUnit, SIGNAL(activated(int)),
1007                 this, SLOT(change_adaptor()));
1008         connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
1009                 this, SLOT(change_adaptor()));
1010         connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
1011                 this, SLOT(change_adaptor()));
1012         connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
1013                 this, SLOT(change_adaptor()));
1014         connect(marginsModule->innerUnit, SIGNAL(activated(int)),
1015                 this, SLOT(change_adaptor()));
1016         connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
1017                 this, SLOT(change_adaptor()));
1018         connect(marginsModule->outerUnit, SIGNAL(activated(int)),
1019                 this, SLOT(change_adaptor()));
1020         connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
1021                 this, SLOT(change_adaptor()));
1022         connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
1023                 this, SLOT(change_adaptor()));
1024         connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
1025                 this, SLOT(change_adaptor()));
1026         connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
1027                 this, SLOT(change_adaptor()));
1028         connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
1029                 this, SLOT(change_adaptor()));
1030         connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
1031                 this, SLOT(change_adaptor()));
1032         connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
1033                 this, SLOT(change_adaptor()));
1034         connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
1035                 this, SLOT(change_adaptor()));
1036         marginsModule->topLE->setValidator(new LengthValidator(
1037                 marginsModule->topLE));
1038         marginsModule->bottomLE->setValidator(new LengthValidator(
1039                 marginsModule->bottomLE));
1040         marginsModule->innerLE->setValidator(new LengthValidator(
1041                 marginsModule->innerLE));
1042         marginsModule->outerLE->setValidator(new LengthValidator(
1043                 marginsModule->outerLE));
1044         marginsModule->headsepLE->setValidator(new LengthValidator(
1045                 marginsModule->headsepLE));
1046         marginsModule->headheightLE->setValidator(new LengthValidator(
1047                 marginsModule->headheightLE));
1048         marginsModule->footskipLE->setValidator(new LengthValidator(
1049                 marginsModule->footskipLE));
1050         marginsModule->columnsepLE->setValidator(new LengthValidator(
1051                 marginsModule->columnsepLE));
1052
1053         bc().addCheckedLineEdit(marginsModule->topLE,
1054                 marginsModule->topL);
1055         bc().addCheckedLineEdit(marginsModule->bottomLE,
1056                 marginsModule->bottomL);
1057         bc().addCheckedLineEdit(marginsModule->innerLE,
1058                 marginsModule->innerL);
1059         bc().addCheckedLineEdit(marginsModule->outerLE,
1060                 marginsModule->outerL);
1061         bc().addCheckedLineEdit(marginsModule->headsepLE,
1062                 marginsModule->headsepL);
1063         bc().addCheckedLineEdit(marginsModule->headheightLE,
1064                 marginsModule->headheightL);
1065         bc().addCheckedLineEdit(marginsModule->footskipLE,
1066                 marginsModule->footskipL);
1067         bc().addCheckedLineEdit(marginsModule->columnsepLE,
1068                 marginsModule->columnsepL);
1069
1070
1071         // language & quote
1072         langModule = new UiWidget<Ui::LanguageUi>(this);
1073         connect(langModule->languageCO, SIGNAL(activated(int)),
1074                 this, SLOT(change_adaptor()));
1075         connect(langModule->languageCO, SIGNAL(activated(int)),
1076                 this, SLOT(languageChanged(int)));
1077         connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1078                 this, SLOT(change_adaptor()));
1079         connect(langModule->otherencodingRB, SIGNAL(clicked()),
1080                 this, SLOT(change_adaptor()));
1081         connect(langModule->encodingCO, SIGNAL(activated(int)),
1082                 this, SLOT(change_adaptor()));
1083         connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1084                 this, SLOT(change_adaptor()));
1085         connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1086                 this, SLOT(change_adaptor()));
1087         connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1088                 this, SLOT(change_adaptor()));
1089         connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1090                 this, SLOT(languagePackageChanged(int)));
1091         connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
1092                 this, SLOT(change_adaptor()));
1093
1094         langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1095                 langModule->languagePackageLE));
1096
1097         QAbstractItemModel * language_model = guiApp->languageModel();
1098         // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1099         language_model->sort(0);
1100         langModule->languageCO->setModel(language_model);
1101         langModule->languageCO->setModelColumn(0);
1102
1103         // Always put the default encoding in the first position.
1104         langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1105         QStringList encodinglist;
1106         for (auto const & encvar : encodings) {
1107                 if (!encvar.unsafe() && !encvar.guiName().empty())
1108                         encodinglist.append(qt_(encvar.guiName()));
1109         }
1110         encodinglist.sort();
1111         langModule->encodingCO->addItems(encodinglist);
1112
1113         langModule->languagePackageCO->addItem(
1114                 qt_("Default"), toqstr("default"));
1115         langModule->languagePackageCO->addItem(
1116                 qt_("Automatic"), toqstr("auto"));
1117         langModule->languagePackageCO->addItem(
1118                 qt_("Always Babel"), toqstr("babel"));
1119         langModule->languagePackageCO->addItem(
1120                 qt_("Custom"), toqstr("custom"));
1121         langModule->languagePackageCO->addItem(
1122                 qt_("None[[language package]]"), toqstr("none"));
1123
1124
1125         // color
1126         colorModule = new UiWidget<Ui::ColorUi>(this);
1127         connect(colorModule->fontColorPB, SIGNAL(clicked()),
1128                 this, SLOT(changeFontColor()));
1129         connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1130                 this, SLOT(deleteFontColor()));
1131         connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1132                 this, SLOT(changeNoteFontColor()));
1133         connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1134                 this, SLOT(deleteNoteFontColor()));
1135         connect(colorModule->backgroundPB, SIGNAL(clicked()),
1136                 this, SLOT(changeBackgroundColor()));
1137         connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1138                 this, SLOT(deleteBackgroundColor()));
1139         connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1140                 this, SLOT(changeBoxBackgroundColor()));
1141         connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1142                 this, SLOT(deleteBoxBackgroundColor()));
1143
1144
1145         // numbering
1146         numberingModule = new UiWidget<Ui::NumberingUi>(this);
1147         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1148                 this, SLOT(change_adaptor()));
1149         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1150                 this, SLOT(change_adaptor()));
1151         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1152                 this, SLOT(updateNumbering()));
1153         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1154                 this, SLOT(updateNumbering()));
1155         numberingModule->tocTW->setColumnCount(3);
1156         numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1157         numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1158         numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1159         setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents);
1160
1161         // biblio
1162         biblioModule = new UiWidget<Ui::BiblioUi>(this);
1163         connect(biblioModule->citeEngineCO, SIGNAL(activated(int)),
1164                 this, SLOT(citeEngineChanged(int)));
1165         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1166                 this, SLOT(citeStyleChanged()));
1167         connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1168                 this, SLOT(biblioChanged()));
1169         connect(biblioModule->bibunitsCO, SIGNAL(activated(int)),
1170                 this, SLOT(biblioChanged()));
1171         connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1172                 this, SLOT(bibtexChanged(int)));
1173         connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1174                 this, SLOT(biblioChanged()));
1175         connect(biblioModule->citePackageOptionsLE, SIGNAL(textChanged(QString)),
1176                 this, SLOT(biblioChanged()));
1177         connect(biblioModule->defaultBiblioCO, SIGNAL(activated(int)),
1178                 this, SLOT(biblioChanged()));
1179         connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1180                 this, SLOT(biblioChanged()));
1181         connect(biblioModule->defaultBiblioCO, SIGNAL(editTextChanged(QString)),
1182                 this, SLOT(updateResetDefaultBiblio()));
1183         connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
1184                 this, SLOT(biblioChanged()));
1185         connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1186                 this, SLOT(biblioChanged()));
1187         connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
1188                 this, SLOT(updateResetDefaultBiblio()));
1189         connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
1190                 this, SLOT(biblioChanged()));
1191         connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1192                 this, SLOT(biblioChanged()));
1193         connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
1194                 this, SLOT(updateResetDefaultBiblio()));
1195         connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
1196                 this, SLOT(rescanBibFiles()));
1197         connect(biblioModule->resetDefaultBiblioPB, SIGNAL(clicked()),
1198                 this, SLOT(resetDefaultBibfile()));
1199         connect(biblioModule->resetCbxPB, SIGNAL(clicked()),
1200                 this, SLOT(resetDefaultCbxBibfile()));
1201         connect(biblioModule->resetBbxPB, SIGNAL(clicked()),
1202                 this, SLOT(resetDefaultBbxBibfile()));
1203         connect(biblioModule->matchBbxPB, SIGNAL(clicked()),
1204                 this, SLOT(matchBiblatexStyles()));
1205
1206         biblioModule->citeEngineCO->clear();
1207         for (LyXCiteEngine const & cet : theCiteEnginesList) {
1208                 biblioModule->citeEngineCO->addItem(qt_(cet.getName()), toqstr(cet.getID()));
1209                 int const i = biblioModule->citeEngineCO->findData(toqstr(cet.getID()));
1210                 biblioModule->citeEngineCO->setItemData(i, qt_(cet.getDescription()),
1211                                                         Qt::ToolTipRole);
1212         }
1213
1214         biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1215                 biblioModule->bibtexOptionsLE));
1216         biblioModule->defaultBiblioCO->lineEdit()->setValidator(new NoNewLineValidator(
1217                 biblioModule->defaultBiblioCO->lineEdit()));
1218         biblioModule->citePackageOptionsLE->setValidator(new NoNewLineValidator(
1219                 biblioModule->citePackageOptionsLE));
1220
1221         // NOTE: we do not provide "custom" here for security reasons!
1222         biblioModule->bibtexCO->clear();
1223         biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1224         for (auto const & alts : lyxrc.bibtex_alternatives) {
1225                 QString const command = toqstr(alts).left(toqstr(alts).indexOf(" "));
1226                 biblioModule->bibtexCO->addItem(command, command);
1227         }
1228
1229
1230         // indices
1231         indicesModule = new GuiIndices;
1232         connect(indicesModule, SIGNAL(changed()),
1233                 this, SLOT(change_adaptor()));
1234
1235
1236         // maths
1237         mathsModule = new UiWidget<Ui::MathsUi>(this);
1238         QStringList headers;
1239         headers << qt_("Package") << qt_("Load automatically")
1240                 << qt_("Load always") << qt_("Do not load");
1241         mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
1242         setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
1243         map<string, string> const & packages = BufferParams::auto_packages();
1244         mathsModule->packagesTW->setRowCount(packages.size());
1245         int packnum = 0;
1246         for (auto const & pkgvar : packages) {
1247                 docstring const package = from_ascii(pkgvar.first);
1248                 QString autoTooltip = qt_(pkgvar.second);
1249                 QString alwaysTooltip;
1250                 if (package == "amsmath")
1251                         alwaysTooltip =
1252                                 qt_("The AMS LaTeX packages are always used");
1253                 else
1254                         alwaysTooltip = toqstr(bformat(
1255                                 _("The LaTeX package %1$s is always used"),
1256                                 package));
1257                 QString neverTooltip;
1258                 if (package == "amsmath")
1259                         neverTooltip =
1260                                 qt_("The AMS LaTeX packages are never used");
1261                 else
1262                         neverTooltip = toqstr(bformat(
1263                                 _("The LaTeX package %1$s is never used"),
1264                                 package));
1265                 QRadioButton * autoRB = new QRadioButton(mathsModule);
1266                 QRadioButton * alwaysRB = new QRadioButton(mathsModule);
1267                 QRadioButton * neverRB = new QRadioButton(mathsModule);
1268                 QButtonGroup * packageGroup = new QButtonGroup(mathsModule);
1269                 packageGroup->addButton(autoRB);
1270                 packageGroup->addButton(alwaysRB);
1271                 packageGroup->addButton(neverRB);
1272                 autoRB->setToolTip(autoTooltip);
1273                 alwaysRB->setToolTip(alwaysTooltip);
1274                 neverRB->setToolTip(neverTooltip);
1275
1276                 // Pack the buttons in a layout in order to get proper alignment
1277                 QWidget * autoRBWidget = new QWidget();
1278                 QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
1279                 autoRBLayout->addWidget(autoRB);
1280                 autoRBLayout->setAlignment(Qt::AlignCenter);
1281                 autoRBLayout->setContentsMargins(0, 0, 0, 0);
1282                 autoRBWidget->setLayout(autoRBLayout);
1283
1284                 QWidget * alwaysRBWidget = new QWidget();
1285                 QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
1286                 alwaysRBLayout->addWidget(alwaysRB);
1287                 alwaysRBLayout->setAlignment(Qt::AlignCenter);
1288                 alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
1289                 alwaysRBWidget->setLayout(alwaysRBLayout);
1290
1291                 QWidget * neverRBWidget = new QWidget();
1292                 QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
1293                 neverRBLayout->addWidget(neverRB);
1294                 neverRBLayout->setAlignment(Qt::AlignCenter);
1295                 neverRBLayout->setContentsMargins(0, 0, 0, 0);
1296                 neverRBWidget->setLayout(neverRBLayout);
1297
1298                 QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
1299                 mathsModule->packagesTW->setItem(packnum, 0, pack);
1300                 mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
1301                 mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
1302                 mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
1303
1304                 connect(autoRB, SIGNAL(clicked()),
1305                         this, SLOT(change_adaptor()));
1306                 connect(alwaysRB, SIGNAL(clicked()),
1307                         this, SLOT(change_adaptor()));
1308                 connect(neverRB, SIGNAL(clicked()),
1309                         this, SLOT(change_adaptor()));
1310                 ++packnum;
1311         }
1312         connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1313                 this, SLOT(allPackagesAuto()));
1314         connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1315                 this, SLOT(allPackagesAlways()));
1316         connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1317                 this, SLOT(allPackagesNot()));
1318         connect(mathsModule->allPackagesAutoPB, SIGNAL(clicked()),
1319                 this, SLOT(change_adaptor()));
1320         connect(mathsModule->allPackagesAlwaysPB, SIGNAL(clicked()),
1321                 this, SLOT(change_adaptor()));
1322         connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
1323                 this, SLOT(change_adaptor()));
1324         connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
1325                 this, SLOT(change_adaptor()));
1326
1327         connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1328                 this, SLOT(change_adaptor()));
1329         connect(mathsModule->MathIndentCB, SIGNAL(toggled(bool)),
1330                 this, SLOT(allowMathIndent()));
1331         connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1332                 this, SLOT(change_adaptor()));
1333         connect(mathsModule->MathIndentCO, SIGNAL(activated(int)),
1334                 this, SLOT(enableMathIndent(int)));
1335         connect(mathsModule->MathIndentLE, SIGNAL(textChanged(const QString &)),
1336                 this, SLOT(change_adaptor()));
1337         connect(mathsModule->MathIndentLengthCO, SIGNAL(activated(int)),
1338                 this, SLOT(change_adaptor()));
1339
1340
1341         mathsModule->MathIndentCO->addItem(qt_("Default"));
1342         mathsModule->MathIndentCO->addItem(qt_("Custom"));
1343         mathsModule->MathIndentLE->setValidator(new LengthValidator(
1344                 mathsModule->MathIndentLE));
1345         // initialize the length validator
1346         bc().addCheckedLineEdit(mathsModule->MathIndentLE);
1347         mathsModule->MathNumberingPosCO->addItem(qt_("Left"));
1348         mathsModule->MathNumberingPosCO->addItem(qt_("Default"));
1349         mathsModule->MathNumberingPosCO->addItem(qt_("Right"));
1350         mathsModule->MathNumberingPosCO->setCurrentIndex(1);
1351
1352
1353         // latex class
1354         latexModule = new UiWidget<Ui::LaTeXUi>(this);
1355         connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1356                 this, SLOT(change_adaptor()));
1357         connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1358                 this, SLOT(change_adaptor()));
1359         connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1360                 this, SLOT(change_adaptor()));
1361         connect(latexModule->classCO, SIGNAL(activated(int)),
1362                 this, SLOT(classChanged_adaptor()));
1363         connect(latexModule->classCO, SIGNAL(activated(int)),
1364                 this, SLOT(change_adaptor()));
1365         connect(latexModule->layoutPB, SIGNAL(clicked()),
1366                 this, SLOT(browseLayout()));
1367         connect(latexModule->layoutPB, SIGNAL(clicked()),
1368                 this, SLOT(change_adaptor()));
1369         connect(latexModule->childDocGB, SIGNAL(clicked()),
1370                 this, SLOT(change_adaptor()));
1371         connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1372                 this, SLOT(change_adaptor()));
1373         connect(latexModule->childDocPB, SIGNAL(clicked()),
1374                 this, SLOT(browseMaster()));
1375         connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1376                 this, SLOT(change_adaptor()));
1377         connect(latexModule->refstyleCB, SIGNAL(clicked()),
1378                 this, SLOT(change_adaptor()));
1379
1380         latexModule->optionsLE->setValidator(new NoNewLineValidator(
1381                 latexModule->optionsLE));
1382         latexModule->childDocLE->setValidator(new NoNewLineValidator(
1383                 latexModule->childDocLE));
1384
1385         // postscript drivers
1386         for (int n = 0; tex_graphics[n][0]; ++n) {
1387                 QString enc = qt_(tex_graphics_gui[n]);
1388                 latexModule->psdriverCO->addItem(enc);
1389         }
1390         // latex classes
1391         LayoutFileList const & bcl = LayoutFileList::get();
1392         vector<LayoutFileIndex> classList = bcl.classList();
1393         sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1394
1395         for (auto const & cvar : classList) {
1396                 LayoutFile const & tc = bcl[cvar];
1397                 bool const available = tc.isTeXClassAvailable();
1398                 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
1399                 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
1400                 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
1401                 if (!available) {
1402                         docstring const output_type = (tc.outputType() == lyx::DOCBOOK) ? _("DocBook") : _("LaTeX");
1403                         tooltip += '\n' + toqstr(bformat(_("Class not found by LyX. "
1404                                                            "Please check if you have the matching %1$s class "
1405                                                            "and all required packages (%2$s) installed."),
1406                                                          output_type, from_utf8(tc.prerequisites(", "))));
1407                 }
1408                 latexModule->classCO->addItemSort(toqstr(tc.name()),
1409                                                   toqstr(guiname),
1410                                                   toqstr(translateIfPossible(from_utf8(tc.category()))),
1411                                                   tooltip,
1412                                                   true, true, true, available);
1413         }
1414
1415
1416         // branches
1417         branchesModule = new GuiBranches(this);
1418         connect(branchesModule, SIGNAL(changed()),
1419                 this, SLOT(change_adaptor()));
1420         connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1421                 this, SLOT(branchesRename(docstring const &, docstring const &)));
1422         connect(branchesModule, SIGNAL(okPressed()), this, SLOT(slotOK()));
1423         updateUnknownBranches();
1424
1425
1426         // preamble
1427         preambleModule = new PreambleModule(this);
1428         connect(preambleModule, SIGNAL(changed()),
1429                 this, SLOT(change_adaptor()));
1430
1431         localLayout = new LocalLayout(this);
1432         connect(localLayout, SIGNAL(changed()),
1433                 this, SLOT(change_adaptor()));
1434
1435
1436         // bullets
1437         bulletsModule = new BulletsModule(this);
1438         connect(bulletsModule, SIGNAL(changed()),
1439                 this, SLOT(change_adaptor()));
1440
1441
1442         // Modules
1443         modulesModule = new UiWidget<Ui::ModulesUi>(this);
1444         modulesModule->availableLV->header()->setVisible(false);
1445         setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents);
1446         modulesModule->availableLV->header()->setStretchLastSection(false);
1447         selectionManager =
1448                 new ModuleSelectionManager(this, modulesModule->availableLV,
1449                                            modulesModule->selectedLV,
1450                                            modulesModule->addPB,
1451                                            modulesModule->deletePB,
1452                                            modulesModule->upPB,
1453                                            modulesModule->downPB,
1454                                            availableModel(), selectedModel(), this);
1455         connect(selectionManager, SIGNAL(updateHook()),
1456                 this, SLOT(updateModuleInfo()));
1457         connect(selectionManager, SIGNAL(selectionChanged()),
1458                 this, SLOT(modulesChanged()));
1459
1460
1461         // PDF support
1462         pdfSupportModule = new UiWidget<Ui::PDFSupportUi>(this);
1463         connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1464                 this, SLOT(change_adaptor()));
1465         connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1466                 this, SLOT(change_adaptor()));
1467         connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1468                 this, SLOT(change_adaptor()));
1469         connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1470                 this, SLOT(change_adaptor()));
1471         connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1472                 this, SLOT(change_adaptor()));
1473         connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1474                 this, SLOT(change_adaptor()));
1475         connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1476                 this, SLOT(change_adaptor()));
1477         connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1478                 this, SLOT(change_adaptor()));
1479         connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1480                 this, SLOT(change_adaptor()));
1481         connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1482                 this, SLOT(change_adaptor()));
1483         connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1484                 this, SLOT(change_adaptor()));
1485         connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1486                 this, SLOT(change_adaptor()));
1487         connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1488                 this, SLOT(change_adaptor()));
1489         connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1490                 this, SLOT(change_adaptor()));
1491         connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1492                 this, SLOT(change_adaptor()));
1493         connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1494                 this, SLOT(change_adaptor()));
1495
1496         pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1497                 pdfSupportModule->titleLE));
1498         pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1499                 pdfSupportModule->authorLE));
1500         pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1501                 pdfSupportModule->subjectLE));
1502         pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1503                 pdfSupportModule->keywordsLE));
1504         pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1505                 pdfSupportModule->optionsLE));
1506
1507         for (int i = 0; backref_opts[i][0]; ++i)
1508                 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1509
1510
1511         // float
1512         floatModule = new FloatPlacement;
1513         connect(floatModule, SIGNAL(changed()),
1514                 this, SLOT(change_adaptor()));
1515
1516
1517         // listings
1518         listingsModule = new UiWidget<Ui::ListingsSettingsUi>(this);
1519         connect(listingsModule->listingsED, SIGNAL(textChanged()),
1520                 this, SLOT(change_adaptor()));
1521         connect(listingsModule->bypassCB, SIGNAL(clicked()),
1522                 this, SLOT(change_adaptor()));
1523         connect(listingsModule->bypassCB, SIGNAL(clicked()),
1524                 this, SLOT(setListingsMessage()));
1525         connect(listingsModule->packageCO, SIGNAL(activated(int)),
1526                 this, SLOT(change_adaptor()));
1527         connect(listingsModule->packageCO, SIGNAL(activated(int)),
1528                 this, SLOT(listingsPackageChanged(int)));
1529         connect(listingsModule->listingsED, SIGNAL(textChanged()),
1530                 this, SLOT(setListingsMessage()));
1531         listingsModule->listingsTB->setPlainText(
1532                 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1533
1534         for (int i = 0; lst_packages[i][0]; ++i)
1535             listingsModule->packageCO->addItem(lst_packages[i]);
1536
1537
1538         // add the panels
1539         docPS->addPanel(latexModule, N_("Document Class"));
1540         docPS->addPanel(masterChildModule, N_("Child Documents"));
1541         docPS->addPanel(modulesModule, N_("Modules"));
1542         docPS->addPanel(localLayout, N_("Local Layout"));
1543         docPS->addPanel(fontModule, N_("Fonts"));
1544         docPS->addPanel(textLayoutModule, N_("Text Layout"));
1545         docPS->addPanel(pageLayoutModule, N_("Page Layout"));
1546         docPS->addPanel(marginsModule, N_("Page Margins"));
1547         docPS->addPanel(langModule, N_("Language"));
1548         docPS->addPanel(colorModule, N_("Colors"));
1549         docPS->addPanel(numberingModule, N_("Numbering & TOC"));
1550         docPS->addPanel(biblioModule, N_("Bibliography"));
1551         docPS->addPanel(indicesModule, N_("Indexes"));
1552         docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
1553         docPS->addPanel(mathsModule, N_("Math Options"));
1554         docPS->addPanel(floatModule, N_("Float Placement"));
1555         docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
1556         docPS->addPanel(bulletsModule, N_("Bullets"));
1557         docPS->addPanel(branchesModule, N_("Branches"));
1558         docPS->addPanel(outputModule, N_("Formats[[output]]"));
1559         docPS->addPanel(preambleModule, N_("LaTeX Preamble"));
1560         docPS->setCurrentPanel("Document Class");
1561 // FIXME: hack to work around resizing bug in Qt >= 4.2
1562 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1563 #if QT_VERSION >= 0x040200
1564         docPS->updateGeometry();
1565 #endif
1566 }
1567
1568
1569 void GuiDocument::onBufferViewChanged()
1570 {
1571         if (isVisibleView())
1572                 initialiseParams("");
1573 }
1574
1575
1576 void GuiDocument::saveDefaultClicked()
1577 {
1578         saveDocDefault();
1579 }
1580
1581
1582 void GuiDocument::useDefaultsClicked()
1583 {
1584         useClassDefaults();
1585 }
1586
1587
1588 void GuiDocument::change_adaptor()
1589 {
1590         nonModuleChanged_ = true;
1591         changed();
1592 }
1593
1594
1595 void GuiDocument::shellescapeChanged()
1596 {
1597         shellescapeChanged_ = true;
1598         changed();
1599 }
1600
1601
1602 void GuiDocument::slotApply()
1603 {
1604         bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1605         bool wasclean = buffer().isClean();
1606         GuiDialog::slotApply();
1607         if (wasclean && only_shellescape_changed)
1608                 buffer().markClean();
1609         modulesChanged_ = false;
1610 }
1611
1612
1613 void GuiDocument::slotOK()
1614 {
1615         bool only_shellescape_changed = !nonModuleChanged_ && !modulesChanged_;
1616         bool wasclean = buffer().isClean();
1617         GuiDialog::slotOK();
1618         if (wasclean && only_shellescape_changed)
1619                 buffer().markClean();
1620         modulesChanged_ = false;
1621 }
1622
1623
1624 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1625 {
1626         if (item == 0)
1627                 return;
1628
1629         string child = fromqstr(item->text(0));
1630         if (child.empty())
1631                 return;
1632
1633         if (std::find(includeonlys_.begin(),
1634                       includeonlys_.end(), child) != includeonlys_.end())
1635                 includeonlys_.remove(child);
1636         else
1637                 includeonlys_.push_back(child);
1638
1639         updateIncludeonlys();
1640         change_adaptor();
1641 }
1642
1643
1644 QString GuiDocument::validateListingsParameters()
1645 {
1646         if (listingsModule->bypassCB->isChecked())
1647                 return QString();
1648         string const package =
1649             lst_packages[listingsModule->packageCO->currentIndex()];
1650         string params = fromqstr(listingsModule->listingsED->toPlainText());
1651         InsetListingsParams lstparams(params);
1652         lstparams.setMinted(package == "Minted");
1653         return toqstr(lstparams.validate());
1654 }
1655
1656
1657 void GuiDocument::setListingsMessage()
1658 {
1659         // FIXME THREAD
1660         static bool isOK = true;
1661         QString msg = validateListingsParameters();
1662         if (msg.isEmpty()) {
1663                 if (isOK)
1664                         return;
1665                 isOK = true;
1666                 // listingsTB->setTextColor("black");
1667                 listingsModule->listingsTB->setPlainText(
1668                         qt_("Input listings parameters below. "
1669                             "Enter ? for a list of parameters."));
1670         } else {
1671                 isOK = false;
1672                 // listingsTB->setTextColor("red");
1673                 listingsModule->listingsTB->setPlainText(msg);
1674         }
1675 }
1676
1677
1678 void GuiDocument::listingsPackageChanged(int index)
1679 {
1680         string const package = lst_packages[index];
1681         if (package == "Minted" && lyxrc.pygmentize_command.empty()) {
1682                 Alert::warning(_("Pygments driver command not found!"),
1683                     _("The driver command necessary to use the minted package\n"
1684                       "(pygmentize) has not been found. Make sure you have\n"
1685                       "the python-pygments module installed or, if the driver\n"
1686                       "is named differently, to add the following line to the\n"
1687                       "document preamble:\n\n"
1688                       "\\AtBeginDocument{\\renewcommand{\\MintedPygmentize}{driver}}\n\n"
1689                       "where 'driver' is name of the driver command."));
1690         }
1691 }
1692
1693
1694 void GuiDocument::setLSpacing(int item)
1695 {
1696         textLayoutModule->lspacingLE->setEnabled(item == 3);
1697 }
1698
1699
1700 void GuiDocument::setIndent(int item)
1701 {
1702         bool const enable = (item == 1);
1703         textLayoutModule->indentLE->setEnabled(enable);
1704         textLayoutModule->indentLengthCO->setEnabled(enable);
1705         textLayoutModule->skipLE->setEnabled(false);
1706         textLayoutModule->skipLengthCO->setEnabled(false);
1707         isValid();
1708 }
1709
1710
1711 void GuiDocument::enableIndent(bool indent)
1712 {
1713         textLayoutModule->skipLE->setEnabled(!indent);
1714         textLayoutModule->skipLengthCO->setEnabled(!indent);
1715         if (indent)
1716                 setIndent(textLayoutModule->indentCO->currentIndex());
1717 }
1718
1719
1720 void GuiDocument::setSkip(int item)
1721 {
1722         bool const enable = (item == 3);
1723         textLayoutModule->skipLE->setEnabled(enable);
1724         textLayoutModule->skipLengthCO->setEnabled(enable);
1725         isValid();
1726 }
1727
1728
1729 void GuiDocument::enableSkip(bool skip)
1730 {
1731         textLayoutModule->indentLE->setEnabled(!skip);
1732         textLayoutModule->indentLengthCO->setEnabled(!skip);
1733         if (skip)
1734                 setSkip(textLayoutModule->skipCO->currentIndex());
1735 }
1736
1737 void GuiDocument::allowMathIndent() {
1738         // only disable when not checked, checked does not always allow enabling
1739         if (!mathsModule->MathIndentCB->isChecked()) {
1740                 mathsModule->MathIndentLE->setEnabled(false);
1741                 mathsModule->MathIndentLengthCO->setEnabled(false);
1742         }
1743         if (mathsModule->MathIndentCB->isChecked()
1744             && mathsModule->MathIndentCO->currentIndex() == 1) {
1745                         mathsModule->MathIndentLE->setEnabled(true);
1746                         mathsModule->MathIndentLengthCO->setEnabled(true);
1747         }
1748         isValid();
1749 }
1750
1751 void GuiDocument::enableMathIndent(int item)
1752 {
1753         bool const enable = (item == 1);
1754         mathsModule->MathIndentLE->setEnabled(enable);
1755         mathsModule->MathIndentLengthCO->setEnabled(enable);
1756         isValid();
1757 }
1758
1759
1760 void GuiDocument::setMargins()
1761 {
1762         bool const extern_geometry =
1763                 documentClass().provides("geometry");
1764         marginsModule->marginCB->setEnabled(!extern_geometry);
1765         if (extern_geometry) {
1766                 marginsModule->marginCB->setChecked(false);
1767                 setCustomMargins(true);
1768         } else {
1769                 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1770                 setCustomMargins(!bp_.use_geometry);
1771         }
1772 }
1773
1774
1775 void GuiDocument::papersizeChanged(int paper_size)
1776 {
1777         setCustomPapersize(paper_size == 1);
1778 }
1779
1780
1781 void GuiDocument::setCustomPapersize(bool custom)
1782 {
1783         pageLayoutModule->paperwidthL->setEnabled(custom);
1784         pageLayoutModule->paperwidthLE->setEnabled(custom);
1785         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1786         pageLayoutModule->paperheightL->setEnabled(custom);
1787         pageLayoutModule->paperheightLE->setEnabled(custom);
1788         pageLayoutModule->paperheightLE->setFocus();
1789         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1790 }
1791
1792
1793 void GuiDocument::setColSep()
1794 {
1795         setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1796 }
1797
1798
1799 void GuiDocument::setCustomMargins(bool custom)
1800 {
1801         marginsModule->topL->setEnabled(!custom);
1802         marginsModule->topLE->setEnabled(!custom);
1803         marginsModule->topUnit->setEnabled(!custom);
1804
1805         marginsModule->bottomL->setEnabled(!custom);
1806         marginsModule->bottomLE->setEnabled(!custom);
1807         marginsModule->bottomUnit->setEnabled(!custom);
1808
1809         marginsModule->innerL->setEnabled(!custom);
1810         marginsModule->innerLE->setEnabled(!custom);
1811         marginsModule->innerUnit->setEnabled(!custom);
1812
1813         marginsModule->outerL->setEnabled(!custom);
1814         marginsModule->outerLE->setEnabled(!custom);
1815         marginsModule->outerUnit->setEnabled(!custom);
1816
1817         marginsModule->headheightL->setEnabled(!custom);
1818         marginsModule->headheightLE->setEnabled(!custom);
1819         marginsModule->headheightUnit->setEnabled(!custom);
1820
1821         marginsModule->headsepL->setEnabled(!custom);
1822         marginsModule->headsepLE->setEnabled(!custom);
1823         marginsModule->headsepUnit->setEnabled(!custom);
1824
1825         marginsModule->footskipL->setEnabled(!custom);
1826         marginsModule->footskipLE->setEnabled(!custom);
1827         marginsModule->footskipUnit->setEnabled(!custom);
1828
1829         bool const enableColSep = !custom &&
1830                         textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1831         marginsModule->columnsepL->setEnabled(enableColSep);
1832         marginsModule->columnsepLE->setEnabled(enableColSep);
1833         marginsModule->columnsepUnit->setEnabled(enableColSep);
1834 }
1835
1836
1837 void GuiDocument::changeBackgroundColor()
1838 {
1839         QColor const & newColor = QColorDialog::getColor(
1840                 rgb2qcolor(set_backgroundcolor), asQWidget());
1841         if (!newColor.isValid())
1842                 return;
1843         // set the button color and text
1844         colorModule->backgroundPB->setStyleSheet(
1845                 colorButtonStyleSheet(newColor));
1846         colorModule->backgroundPB->setText(qt_("&Change..."));
1847         // save color
1848         set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1849         is_backgroundcolor = true;
1850         change_adaptor();
1851 }
1852
1853
1854 void GuiDocument::deleteBackgroundColor()
1855 {
1856         // set the button color back to default by setting an empty StyleSheet
1857         colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1858         // change button text
1859         colorModule->backgroundPB->setText(qt_("&Default..."));
1860         // save default color (white)
1861         set_backgroundcolor = rgbFromHexName("#ffffff");
1862         is_backgroundcolor = false;
1863         change_adaptor();
1864 }
1865
1866
1867 void GuiDocument::changeFontColor()
1868 {
1869         QColor const & newColor = QColorDialog::getColor(
1870                 rgb2qcolor(set_fontcolor), asQWidget());
1871         if (!newColor.isValid())
1872                 return;
1873         // set the button color and text
1874         colorModule->fontColorPB->setStyleSheet(
1875                 colorButtonStyleSheet(newColor));
1876         colorModule->fontColorPB->setText(qt_("&Change..."));
1877         // save color
1878         set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1879         is_fontcolor = true;
1880         change_adaptor();
1881 }
1882
1883
1884 void GuiDocument::deleteFontColor()
1885 {
1886         // set the button color back to default by setting an empty StyleSheet
1887         colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1888         // change button text
1889         colorModule->fontColorPB->setText(qt_("&Default..."));
1890         // save default color (black)
1891         set_fontcolor = rgbFromHexName("#000000");
1892         is_fontcolor = false;
1893         change_adaptor();
1894 }
1895
1896
1897 void GuiDocument::changeNoteFontColor()
1898 {
1899         QColor const & newColor = QColorDialog::getColor(
1900                 rgb2qcolor(set_notefontcolor), asQWidget());
1901         if (!newColor.isValid())
1902                 return;
1903         // set the button color
1904         colorModule->noteFontColorPB->setStyleSheet(
1905                 colorButtonStyleSheet(newColor));
1906         // save color
1907         set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1908         change_adaptor();
1909 }
1910
1911
1912 void GuiDocument::deleteNoteFontColor()
1913 {
1914         // set the button color back to pref
1915         theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1916         colorModule->noteFontColorPB->setStyleSheet(
1917                 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1918         change_adaptor();
1919 }
1920
1921
1922 void GuiDocument::changeBoxBackgroundColor()
1923 {
1924         QColor const & newColor = QColorDialog::getColor(
1925                 rgb2qcolor(set_boxbgcolor), asQWidget());
1926         if (!newColor.isValid())
1927                 return;
1928         // set the button color
1929         colorModule->boxBackgroundPB->setStyleSheet(
1930                 colorButtonStyleSheet(newColor));
1931         // save color
1932         set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1933         change_adaptor();
1934 }
1935
1936
1937 void GuiDocument::deleteBoxBackgroundColor()
1938 {
1939         // set the button color back to pref
1940         theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1941         colorModule->boxBackgroundPB->setStyleSheet(
1942                 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1943         change_adaptor();
1944 }
1945
1946
1947 void GuiDocument::updateQuoteStyles(bool const set)
1948 {
1949         Language const * lang = lyx::languages.getLanguage(
1950                 fromqstr(langModule->languageCO->itemData(
1951                         langModule->languageCO->currentIndex()).toString()));
1952
1953         InsetQuotesParams::QuoteStyle def = bp_.getQuoteStyle(lang->quoteStyle());
1954
1955         langModule->quoteStyleCO->clear();
1956
1957         bool has_default = false;
1958         for (int i = 0; i < quoteparams.stylescount(); ++i) {
1959                 InsetQuotesParams::QuoteStyle qs = InsetQuotesParams::QuoteStyle(i);
1960                 if (qs == InsetQuotesParams::DynamicQuotes)
1961                         continue;
1962                 bool const langdef = (qs == def);
1963                 if (langdef) {
1964                         // add the default style on top
1965                         langModule->quoteStyleCO->insertItem(0,
1966                                 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1967                         has_default = true;
1968                 }
1969                 else
1970                         langModule->quoteStyleCO->addItem(
1971                                 toqstr(quoteparams.getGuiLabel(qs, langdef)), qs);
1972         }
1973         if (set && has_default)
1974                 // (re)set to the default style
1975                 langModule->quoteStyleCO->setCurrentIndex(0);
1976 }
1977
1978
1979 void GuiDocument::languageChanged(int i)
1980 {
1981         // some languages only work with polyglossia
1982         Language const * lang = lyx::languages.getLanguage(
1983                 fromqstr(langModule->languageCO->itemData(i).toString()));
1984         if (lang->babel().empty() && !lang->polyglossia().empty()) {
1985                         // If we force to switch fontspec on, store
1986                         // current state (#8717)
1987                         if (fontModule->osFontsCB->isEnabled())
1988                                 forced_fontspec_activation =
1989                                         !fontModule->osFontsCB->isChecked();
1990                         fontModule->osFontsCB->setChecked(true);
1991                         fontModule->osFontsCB->setEnabled(false);
1992         }
1993         else {
1994                 fontModule->osFontsCB->setEnabled(true);
1995                 // If we have forced to switch fontspec on,
1996                 // restore previous state (#8717)
1997                 if (forced_fontspec_activation)
1998                         fontModule->osFontsCB->setChecked(false);
1999                 forced_fontspec_activation = false;
2000         }
2001
2002         // set appropriate quotation mark style
2003         updateQuoteStyles(true);
2004 }
2005
2006
2007 void GuiDocument::osFontsChanged(bool nontexfonts)
2008 {
2009         bool const tex_fonts = !nontexfonts;
2010         // store current fonts
2011         QString const font_roman = fontModule->fontsRomanCO->itemData(
2012                         fontModule->fontsRomanCO->currentIndex()).toString();
2013         QString const font_sans = fontModule->fontsSansCO->itemData(
2014                         fontModule->fontsSansCO->currentIndex()).toString();
2015         QString const font_typewriter = fontModule->fontsTypewriterCO->itemData(
2016                         fontModule->fontsTypewriterCO->currentIndex()).toString();
2017         QString const font_math = fontModule->fontsMathCO->itemData(
2018                         fontModule->fontsMathCO->currentIndex()).toString();
2019         int const font_sf_scale = fontModule->scaleSansSB->value();
2020         int const font_tt_scale = fontModule->scaleTypewriterSB->value();
2021
2022         updateFontlist();
2023         // store default format
2024         QString const dformat = outputModule->defaultFormatCO->itemData(
2025                 outputModule->defaultFormatCO->currentIndex()).toString();
2026         updateDefaultFormat();
2027         // try to restore default format
2028         int index = outputModule->defaultFormatCO->findData(dformat);
2029         // set to default if format is not found
2030         if (index == -1)
2031                 index = 0;
2032         outputModule->defaultFormatCO->setCurrentIndex(index);
2033
2034         // try to restore fonts which were selected two toggles ago
2035         index = fontModule->fontsRomanCO->findData(fontModule->font_roman);
2036         if (index != -1)
2037                 fontModule->fontsRomanCO->setCurrentIndex(index);
2038         index = fontModule->fontsSansCO->findData(fontModule->font_sans);
2039         if (index != -1)
2040                 fontModule->fontsSansCO->setCurrentIndex(index);
2041         index = fontModule->fontsTypewriterCO->findData(fontModule->font_typewriter);
2042         if (index != -1)
2043                 fontModule->fontsTypewriterCO->setCurrentIndex(index);
2044         index = fontModule->fontsMathCO->findData(fontModule->font_math);
2045         if (index != -1)
2046                 fontModule->fontsMathCO->setCurrentIndex(index);
2047         // save fonts for next next toggle
2048         fontModule->font_roman = font_roman;
2049         fontModule->font_sans = font_sans;
2050         fontModule->font_typewriter = font_typewriter;
2051         fontModule->font_math = font_math;
2052         fontModule->font_sf_scale = font_sf_scale;
2053         fontModule->font_tt_scale = font_tt_scale;
2054
2055         langModule->encodingCO->setEnabled(tex_fonts &&
2056                 !langModule->defaultencodingRB->isChecked());
2057         langModule->defaultencodingRB->setEnabled(tex_fonts);
2058         langModule->otherencodingRB->setEnabled(tex_fonts);
2059
2060         fontModule->fontsDefaultCO->setEnabled(tex_fonts);
2061         fontModule->fontsDefaultLA->setEnabled(tex_fonts);
2062         fontModule->cjkFontLE->setEnabled(tex_fonts);
2063         fontModule->cjkFontLA->setEnabled(tex_fonts);
2064
2065         updateFontOptions();
2066
2067         fontModule->fontencLA->setEnabled(tex_fonts);
2068         fontModule->fontencCO->setEnabled(tex_fonts);
2069         if (!tex_fonts)
2070                 fontModule->fontencLE->setEnabled(false);
2071         else
2072                 fontencChanged(fontModule->fontencCO->currentIndex());
2073 }
2074
2075
2076 void GuiDocument::mathFontChanged(int)
2077 {
2078         updateFontOptions();
2079 }
2080
2081
2082 void GuiDocument::fontOsfToggled(bool state)
2083 {
2084         if (fontModule->osFontsCB->isChecked())
2085                 return;
2086         QString font = fontModule->fontsRomanCO->itemData(
2087                         fontModule->fontsRomanCO->currentIndex()).toString();
2088         if (hasMonolithicExpertSet(font))
2089                 fontModule->fontScCB->setChecked(state);
2090 }
2091
2092
2093 void GuiDocument::fontScToggled(bool state)
2094 {
2095         if (fontModule->osFontsCB->isChecked())
2096                 return;
2097         QString font = fontModule->fontsRomanCO->itemData(
2098                         fontModule->fontsRomanCO->currentIndex()).toString();
2099         if (hasMonolithicExpertSet(font))
2100                 fontModule->fontOsfCB->setChecked(state);
2101 }
2102
2103
2104 void GuiDocument::updateFontOptions()
2105 {
2106         bool const tex_fonts = !fontModule->osFontsCB->isChecked();
2107         QString font;
2108         if (tex_fonts)
2109                 font = fontModule->fontsSansCO->itemData(
2110                                 fontModule->fontsSansCO->currentIndex()).toString();
2111         bool scaleable = providesScale(font);
2112         fontModule->scaleSansSB->setEnabled(scaleable);
2113         fontModule->scaleSansLA->setEnabled(scaleable);
2114         if (tex_fonts)
2115                 font = fontModule->fontsTypewriterCO->itemData(
2116                                 fontModule->fontsTypewriterCO->currentIndex()).toString();
2117         scaleable = providesScale(font);
2118         fontModule->scaleTypewriterSB->setEnabled(scaleable);
2119         fontModule->scaleTypewriterLA->setEnabled(scaleable);
2120         if (tex_fonts)
2121                 font = fontModule->fontsRomanCO->itemData(
2122                                 fontModule->fontsRomanCO->currentIndex()).toString();
2123         fontModule->fontScCB->setEnabled(providesSC(font));
2124         fontModule->fontOsfCB->setEnabled(providesOSF(font));
2125         updateMathFonts(font);
2126 }
2127
2128
2129 void GuiDocument::updateFontsize(string const & items, string const & sel)
2130 {
2131         fontModule->fontsizeCO->clear();
2132         fontModule->fontsizeCO->addItem(qt_("Default"));
2133
2134         for (int n = 0; !token(items,'|',n).empty(); ++n)
2135                 fontModule->fontsizeCO->
2136                         addItem(toqstr(token(items,'|',n)));
2137
2138         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
2139                 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
2140                         fontModule->fontsizeCO->setCurrentIndex(n);
2141                         break;
2142                 }
2143         }
2144 }
2145
2146
2147 bool GuiDocument::ot1() const
2148 {
2149         QString const fontenc =
2150                 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
2151         return (fontenc == "default"
2152                 || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
2153                 || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
2154 }
2155
2156
2157 bool GuiDocument::completeFontset() const
2158 {
2159         return (fontModule->fontsSansCO->itemData(
2160                         fontModule->fontsSansCO->currentIndex()).toString() == "default"
2161                 && fontModule->fontsSansCO->itemData(
2162                         fontModule->fontsTypewriterCO->currentIndex()).toString() == "default");
2163 }
2164
2165
2166 bool GuiDocument::noMathFont() const
2167 {
2168         return (fontModule->fontsMathCO->itemData(
2169                 fontModule->fontsMathCO->currentIndex()).toString() == "default");
2170 }
2171
2172
2173 void GuiDocument::updateTexFonts()
2174 {
2175         LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
2176
2177         LaTeXFonts::TexFontMap::const_iterator it = texfontmap.begin();
2178         LaTeXFonts::TexFontMap::const_iterator end = texfontmap.end();
2179         for (; it != end; ++it) {
2180                 LaTeXFont lf = it->second;
2181                 if (lf.name().empty()) {
2182                         LYXERR0("Error: Unnamed font: " << it->first);
2183                         continue;
2184                 }
2185                 docstring const family = lf.family();
2186                 docstring guiname = translateIfPossible(lf.guiname());
2187                 if (!lf.available(ot1(), noMathFont()))
2188                         guiname += _(" (not installed)");
2189                 if (family == "rm")
2190                         rmfonts_.insert(toqstr(guiname), toqstr(it->first));
2191                 else if (family == "sf")
2192                         sffonts_.insert(toqstr(guiname), toqstr(it->first));
2193                 else if (family == "tt")
2194                         ttfonts_.insert(toqstr(guiname), toqstr(it->first));
2195                 else if (family == "math")
2196                         mathfonts_.insert(toqstr(guiname), toqstr(it->first));
2197         }
2198 }
2199
2200
2201 void GuiDocument::updateFontlist()
2202 {
2203         fontModule->fontsRomanCO->clear();
2204         fontModule->fontsSansCO->clear();
2205         fontModule->fontsTypewriterCO->clear();
2206         fontModule->fontsMathCO->clear();
2207
2208         // With fontspec (XeTeX, LuaTeX), we have access to all system fonts, but not the LaTeX fonts
2209         if (fontModule->osFontsCB->isChecked()) {
2210                 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2211                 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2212                 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2213                 QString unimath = qt_("Non-TeX Fonts Default");
2214                 if (!LaTeXFeatures::isAvailable("unicode-math"))
2215                         unimath += qt_(" (not available)");
2216                 fontModule->fontsMathCO->addItem(qt_("Class Default (TeX Fonts)"), QString("auto"));
2217                 fontModule->fontsMathCO->addItem(unimath, QString("default"));
2218
2219                 QFontDatabase fontdb;
2220                 QStringList families(fontdb.families());
2221                 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
2222                         fontModule->fontsRomanCO->addItem(*it, *it);
2223                         fontModule->fontsSansCO->addItem(*it, *it);
2224                         fontModule->fontsTypewriterCO->addItem(*it, *it);
2225                 }
2226                 return;
2227         }
2228
2229         if (rmfonts_.empty())
2230                 updateTexFonts();
2231
2232         fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
2233         QMap<QString, QString>::const_iterator rmi = rmfonts_.constBegin();
2234         while (rmi != rmfonts_.constEnd()) {
2235                 fontModule->fontsRomanCO->addItem(rmi.key(), rmi.value());
2236                 ++rmi;
2237         }
2238
2239         fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
2240         QMap<QString, QString>::const_iterator sfi = sffonts_.constBegin();
2241         while (sfi != sffonts_.constEnd()) {
2242                 fontModule->fontsSansCO->addItem(sfi.key(), sfi.value());
2243                 ++sfi;
2244         }
2245
2246         fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
2247         QMap<QString, QString>::const_iterator tti = ttfonts_.constBegin();
2248         while (tti != ttfonts_.constEnd()) {
2249                 fontModule->fontsTypewriterCO->addItem(tti.key(), tti.value());
2250                 ++tti;
2251         }
2252
2253         fontModule->fontsMathCO->addItem(qt_("Automatic"), QString("auto"));
2254         fontModule->fontsMathCO->addItem(qt_("Class Default"), QString("default"));
2255         QMap<QString, QString>::const_iterator mmi = mathfonts_.constBegin();
2256         while (mmi != mathfonts_.constEnd()) {
2257                 fontModule->fontsMathCO->addItem(mmi.key(), mmi.value());
2258                 ++mmi;
2259         }
2260 }
2261
2262
2263 void GuiDocument::fontencChanged(int item)
2264 {
2265         fontModule->fontencLE->setEnabled(
2266                 fontModule->fontencCO->itemData(item).toString() == "custom");
2267         // The availability of TeX fonts depends on the font encoding
2268         updateTexFonts();
2269         updateFontOptions();
2270 }
2271
2272
2273 void GuiDocument::updateMathFonts(QString const & rm)
2274 {
2275         if (fontModule->osFontsCB->isChecked())
2276                 return;
2277         QString const math =
2278                 fontModule->fontsMathCO->itemData(fontModule->fontsMathCO->currentIndex()).toString();
2279         int const i = fontModule->fontsMathCO->findData("default");
2280         if (providesNoMath(rm) && i == -1)
2281                 fontModule->fontsMathCO->insertItem(1, qt_("Class Default"), QString("default"));
2282         else if (!providesNoMath(rm) && i != -1) {
2283                 int const c = fontModule->fontsMathCO->currentIndex();
2284                 fontModule->fontsMathCO->removeItem(i);
2285                 if (c == i)
2286                         fontModule->fontsMathCO->setCurrentIndex(0);
2287         }
2288 }
2289
2290
2291 void GuiDocument::romanChanged(int item)
2292 {
2293         if (fontModule->osFontsCB->isChecked())
2294                 return;
2295         QString const font =
2296                 fontModule->fontsRomanCO->itemData(item).toString();
2297         fontModule->fontScCB->setEnabled(providesSC(font));
2298         fontModule->fontOsfCB->setEnabled(providesOSF(font));
2299         updateMathFonts(font);
2300 }
2301
2302
2303 void GuiDocument::sansChanged(int item)
2304 {
2305         if (fontModule->osFontsCB->isChecked())
2306                 return;
2307         QString const font =
2308                 fontModule->fontsSansCO->itemData(item).toString();
2309         bool scaleable = providesScale(font);
2310         fontModule->scaleSansSB->setEnabled(scaleable);
2311         fontModule->scaleSansLA->setEnabled(scaleable);
2312 }
2313
2314
2315 void GuiDocument::ttChanged(int item)
2316 {
2317         if (fontModule->osFontsCB->isChecked())
2318                 return;
2319         QString const font =
2320                 fontModule->fontsTypewriterCO->itemData(item).toString();
2321         bool scaleable = providesScale(font);
2322         fontModule->scaleTypewriterSB->setEnabled(scaleable);
2323         fontModule->scaleTypewriterLA->setEnabled(scaleable);
2324 }
2325
2326
2327 void GuiDocument::updatePagestyle(string const & items, string const & sel)
2328 {
2329         pagestyles.clear();
2330         pageLayoutModule->pagestyleCO->clear();
2331         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
2332
2333         for (int n = 0; !token(items, '|', n).empty(); ++n) {
2334                 string style = token(items, '|', n);
2335                 QString style_gui = qt_(style);
2336                 pagestyles.push_back(pair<string, QString>(style, style_gui));
2337                 pageLayoutModule->pagestyleCO->addItem(style_gui);
2338         }
2339
2340         if (sel == "default") {
2341                 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
2342                 return;
2343         }
2344
2345         int nn = 0;
2346
2347         for (size_t i = 0; i < pagestyles.size(); ++i)
2348                 if (pagestyles[i].first == sel)
2349                         nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
2350
2351         if (nn > 0)
2352                 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
2353 }
2354
2355
2356 void GuiDocument::browseLayout()
2357 {
2358         QString const label1 = qt_("Lay&outs");
2359         QString const dir1 = toqstr(lyxrc.document_path);
2360         QStringList const filter(qt_("LyX Layout (*.layout)"));
2361         QString file = browseRelToParent(QString(), bufferFilePath(),
2362                 qt_("Local layout file"), filter, false,
2363                 label1, dir1);
2364
2365         if (!file.endsWith(".layout"))
2366                 return;
2367
2368         FileName layoutFile = support::makeAbsPath(fromqstr(file),
2369                 fromqstr(bufferFilePath()));
2370
2371         int const ret = Alert::prompt(_("Local layout file"),
2372                 _("The layout file you have selected is a local layout\n"
2373                   "file, not one in the system or user directory.\n"
2374                   "Your document will not work with this layout if you\n"
2375                   "move the layout file to a different directory."),
2376                   1, 1, _("&Set Layout"), _("&Cancel"));
2377         if (ret == 1)
2378                 return;
2379
2380         // load the layout file
2381         LayoutFileList & bcl = LayoutFileList::get();
2382         string classname = layoutFile.onlyFileName();
2383         // this will update an existing layout if that layout has been loaded before.
2384         LayoutFileIndex name = support::onlyFileName(bcl.addLocalLayout(
2385                 classname.substr(0, classname.size() - 7),
2386                 layoutFile.onlyPath().absFileName()));
2387
2388         if (name.empty()) {
2389                 Alert::error(_("Error"),
2390                         _("Unable to read local layout file."));
2391                 return;
2392         }
2393
2394         const_cast<Buffer &>(buffer()).setLayoutPos(layoutFile.onlyPath().absFileName());
2395
2396         // do not trigger classChanged if there is no change.
2397         if (latexModule->classCO->currentText() == toqstr(name))
2398                 return;
2399
2400         // add to combo box
2401         bool const avail = latexModule->classCO->set(toqstr(name));
2402         if (!avail) {
2403                 LayoutFile const & tc = bcl[name];
2404                 docstring const guiname = translateIfPossible(from_utf8(tc.description()));
2405                 // tooltip sensu "KOMA-Script Article [Class 'scrartcl']"
2406                 QString tooltip = toqstr(bformat(_("%1$s [Class '%2$s']"), guiname, from_utf8(tc.latexname())));
2407                 tooltip += '\n' + qt_("This is a local layout file.");
2408                 latexModule->classCO->addItemSort(toqstr(tc.name()), toqstr(guiname),
2409                                                   toqstr(translateIfPossible(from_utf8(tc.category()))),
2410                                                   tooltip,
2411                                                   true, true, true, true);
2412                 latexModule->classCO->set(toqstr(name));
2413         }
2414
2415         classChanged();
2416 }
2417
2418
2419 void GuiDocument::browseMaster()
2420 {
2421         QString const title = qt_("Select master document");
2422         QString const dir1 = toqstr(lyxrc.document_path);
2423         QString const old = latexModule->childDocLE->text();
2424         QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
2425         QStringList const filter(qt_("LyX Files (*.lyx)"));
2426         QString file = browseRelToSub(old, docpath, title, filter, false,
2427                 qt_("D&ocuments"), toqstr(lyxrc.document_path));
2428
2429         if (!file.isEmpty())
2430                 latexModule->childDocLE->setText(file);
2431 }
2432
2433
2434 void GuiDocument::classChanged_adaptor()
2435 {
2436         const_cast<Buffer &>(buffer()).setLayoutPos(string());
2437         classChanged();
2438 }
2439
2440
2441 void GuiDocument::classChanged()
2442 {
2443         int idx = latexModule->classCO->currentIndex();
2444         if (idx < 0)
2445                 return;
2446         string const classname = fromqstr(latexModule->classCO->getData(idx));
2447
2448         if (applyPB->isEnabled()) {
2449                 int const ret = Alert::prompt(_("Unapplied changes"),
2450                                 _("Some changes in the dialog were not yet applied.\n"
2451                                 "If you do not apply now, they will be lost after this action."),
2452                                 1, 1, _("&Apply"), _("&Dismiss"));
2453                 if (ret == 0)
2454                         applyView();
2455         }
2456
2457         // We load the TextClass as soon as it is selected. This is
2458         // necessary so that other options in the dialog can be updated
2459         // according to the new class. Note, however, that, if you use
2460         // the scroll wheel when sitting on the combo box, we'll load a
2461         // lot of TextClass objects very quickly....
2462         if (!bp_.setBaseClass(classname)) {
2463                 Alert::error(_("Error"), _("Unable to set document class."));
2464                 return;
2465         }
2466         if (lyxrc.auto_reset_options)
2467                 bp_.useClassDefaults();
2468
2469         // With the introduction of modules came a distinction between the base
2470         // class and the document class. The former corresponds to the main layout
2471         // file; the latter is that plus the modules (or the document-specific layout,
2472         // or  whatever else there could be). Our parameters come from the document
2473         // class. So when we set the base class, we also need to recreate the document
2474         // class. Otherwise, we still have the old one.
2475         bp_.makeDocumentClass();
2476         paramsToDialog();
2477 }
2478
2479
2480 void GuiDocument::languagePackageChanged(int i)
2481 {
2482          langModule->languagePackageLE->setEnabled(
2483                 langModule->languagePackageCO->itemData(i).toString() == "custom");
2484 }
2485
2486
2487 void GuiDocument::biblioChanged()
2488 {
2489         biblioChanged_ = true;
2490         change_adaptor();
2491 }
2492
2493
2494 void GuiDocument::checkPossibleCiteEngines()
2495 {
2496         // Check if the class provides a specific engine,
2497         // and if so, enforce this.
2498         string force_engine;
2499         if (documentClass().provides("natbib")
2500             || documentClass().provides("natbib-internal"))
2501                 force_engine = "natbib";
2502         else if (documentClass().provides("jurabib"))
2503                 force_engine = "jurabib";
2504         else if (documentClass().provides("biblatex"))
2505                 force_engine = "biblatex";
2506         else if (documentClass().provides("biblatex-natbib"))
2507                 force_engine = "biblatex-natbib";
2508
2509         if (!force_engine.empty())
2510                 biblioModule->citeEngineCO->setCurrentIndex(
2511                         biblioModule->citeEngineCO->findData(toqstr(force_engine)));
2512         biblioModule->citeEngineCO->setEnabled(force_engine.empty());
2513 }
2514
2515
2516 void GuiDocument::rescanBibFiles()
2517 {
2518         if (isBiblatex())
2519                 rescanTexStyles("bbx cbx");
2520         else
2521                 rescanTexStyles("bst");
2522 }
2523
2524
2525 void GuiDocument::resetDefaultBibfile(string const & which)
2526 {
2527         QString const engine =
2528                 biblioModule->citeEngineCO->itemData(
2529                                 biblioModule->citeEngineCO->currentIndex()).toString();
2530
2531         CiteEngineType const cet =
2532                 CiteEngineType(biblioModule->citeStyleCO->itemData(
2533                                                           biblioModule->citeStyleCO->currentIndex()).toInt());
2534
2535         updateDefaultBiblio(theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet), which);
2536 }
2537
2538
2539 void GuiDocument::resetDefaultBbxBibfile()
2540 {
2541         resetDefaultBibfile("bbx");
2542 }
2543
2544
2545 void GuiDocument::resetDefaultCbxBibfile()
2546 {
2547         resetDefaultBibfile("cbx");
2548 }
2549
2550
2551 void GuiDocument::citeEngineChanged(int n)
2552 {
2553         QString const engine =
2554                 biblioModule->citeEngineCO->itemData(n).toString();
2555
2556         vector<string> const engs =
2557                 theCiteEnginesList[fromqstr(engine)]->getEngineType();
2558
2559         updateCiteStyles(engs);
2560         updateEngineDependends();
2561         resetDefaultBibfile();
2562         biblioChanged();
2563 }
2564
2565
2566 void GuiDocument::updateEngineDependends()
2567 {
2568         bool const biblatex = isBiblatex();
2569
2570         // These are only useful with BibTeX
2571         biblioModule->defaultBiblioCO->setEnabled(!biblatex);
2572         biblioModule->bibtexStyleLA->setEnabled(!biblatex);
2573         biblioModule->resetDefaultBiblioPB->setEnabled(!biblatex);
2574         biblioModule->bibtopicCB->setEnabled(!biblatex);
2575
2576         // These are only useful with Biblatex
2577         biblioModule->biblatexBbxCO->setEnabled(biblatex);
2578         biblioModule->biblatexBbxLA->setEnabled(biblatex);
2579         biblioModule->biblatexCbxCO->setEnabled(biblatex);
2580         biblioModule->biblatexCbxLA->setEnabled(biblatex);
2581         biblioModule->resetBbxPB->setEnabled(biblatex);
2582         biblioModule->resetCbxPB->setEnabled(biblatex);
2583         biblioModule->matchBbxPB->setEnabled(biblatex);
2584
2585         // These are useful with biblatex, jurabib and natbib
2586         QString const engine =
2587                 biblioModule->citeEngineCO->itemData(
2588                                 biblioModule->citeEngineCO->currentIndex()).toString();
2589         LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
2590
2591         bool const citepack = ce->requires("biblatex.sty") || ce->requires("jurabib.sty")
2592                         || ce->requires("natbib.sty");
2593         biblioModule->citePackageOptionsLE->setEnabled(citepack);
2594         biblioModule->citePackageOptionsL->setEnabled(citepack);
2595 }
2596
2597
2598 void GuiDocument::citeStyleChanged()
2599 {
2600         QString const engine =
2601                 biblioModule->citeEngineCO->itemData(
2602                                 biblioModule->citeEngineCO->currentIndex()).toString();
2603         QString const currentDef = isBiblatex() ?
2604                 biblioModule->biblatexBbxCO->currentText()
2605                 : biblioModule->defaultBiblioCO->currentText();
2606         if (theCiteEnginesList[fromqstr(engine)]->isDefaultBiblio(fromqstr(currentDef)))
2607                 resetDefaultBibfile();
2608
2609         biblioChanged();
2610 }
2611
2612
2613 void GuiDocument::bibtexChanged(int n)
2614 {
2615         biblioModule->bibtexOptionsLE->setEnabled(
2616                 biblioModule->bibtexCO->itemData(n).toString() != "default");
2617         biblioChanged();
2618 }
2619
2620
2621 void GuiDocument::updateCiteStyles(vector<string> const & engs, CiteEngineType const & sel)
2622 {
2623         biblioModule->citeStyleCO->clear();
2624
2625         vector<string>::const_iterator it  = engs.begin();
2626         vector<string>::const_iterator end = engs.end();
2627         for (; it != end; ++it) {
2628                 if (*it == "default")
2629                         biblioModule->citeStyleCO->addItem(qt_("Basic numerical"),
2630                                                            ENGINE_TYPE_DEFAULT);
2631                 else if (*it == "authoryear")
2632                         biblioModule->citeStyleCO->addItem(qt_("Author-year"),
2633                                                            ENGINE_TYPE_AUTHORYEAR);
2634                 else if (*it == "numerical")
2635                         biblioModule->citeStyleCO->addItem(qt_("Author-number"),
2636                                                            ENGINE_TYPE_NUMERICAL);
2637         }
2638         int i = biblioModule->citeStyleCO->findData(sel);
2639         if (biblioModule->citeStyleCO->findData(sel) == -1)
2640                 i = 0;
2641         biblioModule->citeStyleCO->setCurrentIndex(i);
2642
2643         biblioModule->citationStyleL->setEnabled(engs.size() > 1);
2644         biblioModule->citeStyleCO->setEnabled(engs.size() > 1);
2645 }
2646
2647
2648 void GuiDocument::updateEngineType(string const & items, CiteEngineType const & sel)
2649 {
2650         engine_types_.clear();
2651
2652         int nn = 0;
2653
2654         for (int n = 0; !token(items, '|', n).empty(); ++n) {
2655                 nn += 1;
2656                 string style = token(items, '|', n);
2657                 engine_types_.push_back(style);
2658         }
2659
2660         updateCiteStyles(engine_types_, sel);
2661 }
2662
2663
2664 namespace {
2665         // FIXME unicode
2666         // both of these should take a vector<docstring>
2667
2668         // This is an insanely complicated attempt to make this sort of thing
2669         // work with RTL languages.
2670         docstring formatStrVec(vector<string> const & v, docstring const & s)
2671         {
2672                 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2673                 if (v.empty())
2674                         return docstring();
2675                 if (v.size() == 1)
2676                         return translateIfPossible(from_utf8(v[0]));
2677                 if (v.size() == 2) {
2678                         docstring retval = _("%1$s and %2$s");
2679                         retval = subst(retval, _("and"), s);
2680                         return bformat(retval, translateIfPossible(from_utf8(v[0])),
2681                                        translateIfPossible(from_utf8(v[1])));
2682                 }
2683                 // The idea here is to format all but the last two items...
2684                 int const vSize = v.size();
2685                 docstring t2 = _("%1$s, %2$s");
2686                 docstring retval = translateIfPossible(from_utf8(v[0]));
2687                 for (int i = 1; i < vSize - 2; ++i)
2688                         retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2689                 //...and then to  plug them, and the last two, into this schema
2690                 docstring t = _("%1$s, %2$s, and %3$s");
2691                 t = subst(t, _("and"), s);
2692                 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2693                                translateIfPossible(from_utf8(v[vSize - 1])));
2694         }
2695
2696         vector<string> idsToNames(vector<string> const & idList)
2697         {
2698                 vector<string> retval;
2699                 vector<string>::const_iterator it  = idList.begin();
2700                 vector<string>::const_iterator end = idList.end();
2701                 for (; it != end; ++it) {
2702                         LyXModule const * const mod = theModuleList[*it];
2703                         if (!mod)
2704                                 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2705                                                 translateIfPossible(from_utf8(*it)))));
2706                         else
2707                                 retval.push_back(mod->getName());
2708                 }
2709                 return retval;
2710         }
2711 } // end anonymous namespace
2712
2713
2714 void GuiDocument::modulesToParams(BufferParams & bp)
2715 {
2716         // update list of loaded modules
2717         bp.clearLayoutModules();
2718         int const srows = modules_sel_model_.rowCount();
2719         for (int i = 0; i < srows; ++i)
2720                 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2721
2722         // update the list of removed modules
2723         bp.clearRemovedModules();
2724         LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2725         list<string>::const_iterator rit = reqmods.begin();
2726         list<string>::const_iterator ren = reqmods.end();
2727
2728         // check each of the default modules
2729         for (; rit != ren; ++rit) {
2730                 list<string>::const_iterator mit = bp.getModules().begin();
2731                 list<string>::const_iterator men = bp.getModules().end();
2732                 bool found = false;
2733                 for (; mit != men; ++mit) {
2734                         if (*rit == *mit) {
2735                                 found = true;
2736                                 break;
2737                         }
2738                 }
2739                 if (!found) {
2740                         // the module isn't present so must have been removed by the user
2741                         bp.addRemovedModule(*rit);
2742                 }
2743         }
2744 }
2745
2746 void GuiDocument::modulesChanged()
2747 {
2748         modulesToParams(bp_);
2749
2750         if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
2751                 int const ret = Alert::prompt(_("Unapplied changes"),
2752                                 _("Some changes in the dialog were not yet applied.\n"
2753                                 "If you do not apply now, they will be lost after this action."),
2754                                 1, 1, _("&Apply"), _("&Dismiss"));
2755                 if (ret == 0)
2756                         applyView();
2757         }
2758
2759         modulesChanged_ = true;
2760         bp_.makeDocumentClass();
2761         paramsToDialog();
2762         changed();
2763 }
2764
2765
2766 void GuiDocument::updateModuleInfo()
2767 {
2768         selectionManager->update();
2769
2770         //Module description
2771         bool const focus_on_selected = selectionManager->selectedFocused();
2772         QAbstractItemView * lv;
2773         if (focus_on_selected)
2774                 lv = modulesModule->selectedLV;
2775         else
2776                 lv = modulesModule->availableLV;
2777         if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2778                 modulesModule->infoML->document()->clear();
2779                 return;
2780         }
2781         QModelIndex const & idx = lv->selectionModel()->currentIndex();
2782         GuiIdListModel const & id_model =
2783                         focus_on_selected  ? modules_sel_model_ : modules_av_model_;
2784         string const modName = id_model.getIDString(idx.row());
2785         docstring desc = getModuleDescription(modName);
2786
2787         LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2788         if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2789                 if (!desc.empty())
2790                         desc += "\n";
2791                 desc += _("Module provided by document class.");
2792         }
2793
2794         docstring cat = getModuleCategory(modName);
2795         if (!cat.empty()) {
2796                 if (!desc.empty())
2797                         desc += "\n";
2798                 desc += bformat(_("Category: %1$s."), cat);
2799         }
2800
2801         vector<string> pkglist = getPackageList(modName);
2802         docstring pkgdesc = formatStrVec(pkglist, _("and"));
2803         if (!pkgdesc.empty()) {
2804                 if (!desc.empty())
2805                         desc += "\n";
2806                 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2807         }
2808
2809         pkglist = getRequiredList(modName);
2810         if (!pkglist.empty()) {
2811                 vector<string> const reqdescs = idsToNames(pkglist);
2812                 pkgdesc = formatStrVec(reqdescs, _("or"));
2813                 if (!desc.empty())
2814                         desc += "\n";
2815                 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2816         }
2817
2818         pkglist = getExcludedList(modName);
2819         if (!pkglist.empty()) {
2820                 vector<string> const reqdescs = idsToNames(pkglist);
2821                 pkgdesc = formatStrVec(reqdescs, _( "and"));
2822                 if (!desc.empty())
2823                         desc += "\n";
2824                 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2825         }
2826
2827         if (!isModuleAvailable(modName)) {
2828                 if (!desc.empty())
2829                         desc += "\n";
2830                 desc += _("WARNING: Some required packages are unavailable!");
2831         }
2832
2833         modulesModule->infoML->document()->setPlainText(toqstr(desc));
2834 }
2835
2836
2837 void GuiDocument::updateNumbering()
2838 {
2839         DocumentClass const & tclass = documentClass();
2840
2841         numberingModule->tocTW->setUpdatesEnabled(false);
2842         numberingModule->tocTW->clear();
2843
2844         int const depth = numberingModule->depthSL->value();
2845         int const toc = numberingModule->tocSL->value();
2846         QString const no = qt_("No");
2847         QString const yes = qt_("Yes");
2848         QTreeWidgetItem * item = 0;
2849
2850         DocumentClass::const_iterator lit = tclass.begin();
2851         DocumentClass::const_iterator len = tclass.end();
2852         for (; lit != len; ++lit) {
2853                 int const toclevel = lit->toclevel;
2854                 if (toclevel != Layout::NOT_IN_TOC && !lit->counter.empty()) {
2855                         item = new QTreeWidgetItem(numberingModule->tocTW);
2856                         item->setText(0, toqstr(translateIfPossible(lit->name())));
2857                         item->setText(1, (toclevel <= depth) ? yes : no);
2858                         item->setText(2, (toclevel <= toc) ? yes : no);
2859                 }
2860         }
2861
2862         numberingModule->tocTW->setUpdatesEnabled(true);
2863         numberingModule->tocTW->update();
2864 }
2865
2866
2867 void GuiDocument::updateDefaultFormat()
2868 {
2869         if (!bufferview())
2870                 return;
2871         // make a copy in order to consider unapplied changes
2872         BufferParams param_copy = buffer().params();
2873         param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2874         int const idx = latexModule->classCO->currentIndex();
2875         if (idx >= 0) {
2876                 string const classname = fromqstr(latexModule->classCO->getData(idx));
2877                 param_copy.setBaseClass(classname);
2878                 param_copy.makeDocumentClass(true);
2879         }
2880         outputModule->defaultFormatCO->blockSignals(true);
2881         outputModule->defaultFormatCO->clear();
2882         outputModule->defaultFormatCO->addItem(qt_("Default"),
2883                                 QVariant(QString("default")));
2884         FormatList const & formats =
2885                                 param_copy.exportableFormats(true);
2886         for (Format const * f : formats)
2887                 outputModule->defaultFormatCO->addItem
2888                         (toqstr(translateIfPossible(f->prettyname())),
2889                          QVariant(toqstr(f->name())));
2890         outputModule->defaultFormatCO->blockSignals(false);
2891 }
2892
2893
2894 bool GuiDocument::isChildIncluded(string const & child)
2895 {
2896         if (includeonlys_.empty())
2897                 return false;
2898         return (std::find(includeonlys_.begin(),
2899                           includeonlys_.end(), child) != includeonlys_.end());
2900 }
2901
2902
2903 void GuiDocument::applyView()
2904 {
2905         // preamble
2906         preambleModule->apply(bp_);
2907         localLayout->apply(bp_);
2908
2909         // date
2910         bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2911         bp_.use_refstyle  = latexModule->refstyleCB->isChecked();
2912
2913         // biblio
2914         string const engine =
2915                 fromqstr(biblioModule->citeEngineCO->itemData(
2916                                 biblioModule->citeEngineCO->currentIndex()).toString());
2917         bp_.setCiteEngine(engine);
2918
2919         CiteEngineType const style = CiteEngineType(biblioModule->citeStyleCO->itemData(
2920                 biblioModule->citeStyleCO->currentIndex()).toInt());
2921         if (theCiteEnginesList[engine]->hasEngineType(style))
2922                 bp_.setCiteEngineType(style);
2923         else
2924                 bp_.setCiteEngineType(ENGINE_TYPE_DEFAULT);
2925
2926         bp_.splitbib(biblioModule->bibtopicCB->isChecked());
2927
2928         bp_.multibib = fromqstr(biblioModule->bibunitsCO->itemData(
2929                                 biblioModule->bibunitsCO->currentIndex()).toString());
2930
2931         bp_.setDefaultBiblioStyle(fromqstr(biblioModule->defaultBiblioCO->currentText()));
2932
2933         bp_.biblatex_bibstyle = fromqstr(biblioModule->biblatexBbxCO->currentText());
2934         bp_.biblatex_citestyle = fromqstr(biblioModule->biblatexCbxCO->currentText());
2935         bp_.biblio_opts = fromqstr(biblioModule->citePackageOptionsLE->text());
2936
2937         string const bibtex_command =
2938                 fromqstr(biblioModule->bibtexCO->itemData(
2939                         biblioModule->bibtexCO->currentIndex()).toString());
2940         string const bibtex_options =
2941                 fromqstr(biblioModule->bibtexOptionsLE->text());
2942         if (bibtex_command == "default" || bibtex_options.empty())
2943                 bp_.bibtex_command = bibtex_command;
2944         else
2945                 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2946
2947         if (biblioChanged_) {
2948                 buffer().invalidateBibinfoCache();
2949                 buffer().removeBiblioTempFiles();
2950         }
2951
2952         // Indices
2953         indicesModule->apply(bp_);
2954
2955         // language & quotes
2956         if (langModule->defaultencodingRB->isChecked()) {
2957                 bp_.inputenc = "auto";
2958         } else {
2959                 int i = langModule->encodingCO->currentIndex();
2960                 if (i == 0)
2961                         bp_.inputenc = "default";
2962                 else {
2963                         QString const enc_gui =
2964                                 langModule->encodingCO->currentText();
2965                         Encodings::const_iterator it = encodings.begin();
2966                         Encodings::const_iterator const end = encodings.end();
2967                         bool found = false;
2968                         for (; it != end; ++it) {
2969                                 if (qt_(it->guiName()) == enc_gui &&
2970                                     !it->unsafe()) {
2971                                         bp_.inputenc = it->name();
2972                                         found = true;
2973                                         break;
2974                                 }
2975                         }
2976                         if (!found) {
2977                                 // should not happen
2978                                 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2979                                 bp_.inputenc = "default";
2980                         }
2981                 }
2982         }
2983
2984         bp_.quotes_style = (InsetQuotesParams::QuoteStyle) langModule->quoteStyleCO->itemData(
2985                 langModule->quoteStyleCO->currentIndex()).toInt();
2986         bp_.dynamic_quotes = langModule->dynamicQuotesCB->isChecked();
2987
2988         QString const langname = langModule->languageCO->itemData(
2989                 langModule->languageCO->currentIndex()).toString();
2990         Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
2991         Cursor & cur = const_cast<BufferView *>(bufferview())->cursor();
2992         // If current cursor language was the document language, then update it too.
2993         if (cur.current_font.language() == bp_.language) {
2994                 cur.current_font.setLanguage(newlang);
2995                 cur.real_current_font.setLanguage(newlang);
2996         }
2997         bp_.language = newlang;
2998
2999         QString const pack = langModule->languagePackageCO->itemData(
3000                 langModule->languagePackageCO->currentIndex()).toString();
3001         if (pack == "custom")
3002                 bp_.lang_package =
3003                         fromqstr(langModule->languagePackageLE->text());
3004         else
3005                 bp_.lang_package = fromqstr(pack);
3006
3007         //color
3008         bp_.backgroundcolor = set_backgroundcolor;
3009         bp_.isbackgroundcolor = is_backgroundcolor;
3010         bp_.fontcolor = set_fontcolor;
3011         bp_.isfontcolor = is_fontcolor;
3012         bp_.notefontcolor = set_notefontcolor;
3013         bp_.boxbgcolor = set_boxbgcolor;
3014
3015         // numbering
3016         if (bp_.documentClass().hasTocLevels()) {
3017                 bp_.tocdepth = numberingModule->tocSL->value();
3018                 bp_.secnumdepth = numberingModule->depthSL->value();
3019         }
3020
3021         // bullets
3022         bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
3023         bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
3024         bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
3025         bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
3026
3027         // packages
3028         bp_.graphics_driver =
3029                 tex_graphics[latexModule->psdriverCO->currentIndex()];
3030
3031         // text layout
3032         int idx = latexModule->classCO->currentIndex();
3033         if (idx >= 0) {
3034                 string const classname = fromqstr(latexModule->classCO->getData(idx));
3035                 bp_.setBaseClass(classname);
3036         }
3037
3038         // Modules
3039         modulesToParams(bp_);
3040
3041         // Math
3042         map<string, string> const & packages = BufferParams::auto_packages();
3043         for (map<string, string>::const_iterator it = packages.begin();
3044              it != packages.end(); ++it) {
3045                 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3046                 if (!item)
3047                         continue;
3048                 int row = mathsModule->packagesTW->row(item);
3049
3050                 QRadioButton * rb =
3051                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3052                 if (rb->isChecked()) {
3053                         bp_.use_package(it->first, BufferParams::package_auto);
3054                         continue;
3055                 }
3056                 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3057                 if (rb->isChecked()) {
3058                         bp_.use_package(it->first, BufferParams::package_on);
3059                         continue;
3060                 }
3061                 rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3062                 if (rb->isChecked())
3063                         bp_.use_package(it->first, BufferParams::package_off);
3064         }
3065         // if math is indented
3066         bp_.is_math_indent = mathsModule->MathIndentCB->isChecked();
3067         if (bp_.is_math_indent) {
3068                 // if formulas are indented
3069                 switch (mathsModule->MathIndentCO->currentIndex()) {
3070                 case 0:
3071                         bp_.setMathIndent(Length());
3072                         break;
3073                 case 1: {
3074                         Length mathindent(widgetsToLength(mathsModule->MathIndentLE,
3075                                                           mathsModule->MathIndentLengthCO));
3076                         bp_.setMathIndent(mathindent);
3077                         break;
3078                 }
3079                 default:
3080                         // this should never happen
3081                         bp_.setMathIndent(Length());
3082                         break;
3083                 }
3084         }
3085         switch (mathsModule->MathNumberingPosCO->currentIndex()) {
3086                 case 0:
3087                         bp_.math_numbering_side = BufferParams::LEFT;
3088                         break;
3089                 case 1:
3090                         bp_.math_numbering_side = BufferParams::DEFAULT;
3091                         break;
3092                 case 2:
3093                         bp_.math_numbering_side = BufferParams::RIGHT;
3094                         break;
3095                 default:
3096                         // this should never happen
3097                         bp_.math_numbering_side = BufferParams::DEFAULT;
3098                         break;
3099         }
3100
3101         // Page Layout
3102         if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
3103                 bp_.pagestyle = "default";
3104         else {
3105                 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
3106                 for (size_t i = 0; i != pagestyles.size(); ++i)
3107                         if (pagestyles[i].second == style_gui)
3108                                 bp_.pagestyle = pagestyles[i].first;
3109         }
3110
3111         // Text Layout
3112         switch (textLayoutModule->lspacingCO->currentIndex()) {
3113         case 0:
3114                 bp_.spacing().set(Spacing::Single);
3115                 break;
3116         case 1:
3117                 bp_.spacing().set(Spacing::Onehalf);
3118                 break;
3119         case 2:
3120                 bp_.spacing().set(Spacing::Double);
3121                 break;
3122         case 3: {
3123                 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
3124                 if (s.empty())
3125                         bp_.spacing().set(Spacing::Single);
3126                 else
3127                         bp_.spacing().set(Spacing::Other, s);
3128                 break;
3129                 }
3130         }
3131
3132         if (textLayoutModule->twoColumnCB->isChecked())
3133                 bp_.columns = 2;
3134         else
3135                 bp_.columns = 1;
3136
3137         bp_.justification = textLayoutModule->justCB->isChecked();
3138
3139         if (textLayoutModule->indentRB->isChecked()) {
3140                 // if paragraphs are separated by an indentation
3141                 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
3142                 switch (textLayoutModule->indentCO->currentIndex()) {
3143                 case 0:
3144                         bp_.setParIndent(Length());
3145                         break;
3146                 case 1: {
3147                         Length parindent(widgetsToLength(textLayoutModule->indentLE,
3148                                                          textLayoutModule->indentLengthCO));
3149                         bp_.setParIndent(parindent);
3150                         break;
3151                 }
3152                 default:
3153                         // this should never happen
3154                         bp_.setParIndent(Length());
3155                         break;
3156                 }
3157         } else {
3158                 // if paragraphs are separated by a skip
3159                 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
3160                 switch (textLayoutModule->skipCO->currentIndex()) {
3161                 case 0:
3162                         bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
3163                         break;
3164                 case 1:
3165                         bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3166                         break;
3167                 case 2:
3168                         bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
3169                         break;
3170                 case 3:
3171                         {
3172                         VSpace vs = VSpace(
3173                                 widgetsToLength(textLayoutModule->skipLE,
3174                                 textLayoutModule->skipLengthCO)
3175                                 );
3176                         bp_.setDefSkip(vs);
3177                         break;
3178                         }
3179                 default:
3180                         // this should never happen
3181                         bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
3182                         break;
3183                 }
3184         }
3185
3186         bp_.options =
3187                 fromqstr(latexModule->optionsLE->text());
3188
3189         bp_.use_default_options =
3190                 latexModule->defaultOptionsCB->isChecked();
3191
3192         if (latexModule->childDocGB->isChecked())
3193                 bp_.master =
3194                         fromqstr(latexModule->childDocLE->text());
3195         else
3196                 bp_.master = string();
3197
3198         // Master/Child
3199         bp_.clearIncludedChildren();
3200         if (masterChildModule->includeonlyRB->isChecked()) {
3201                 list<string>::const_iterator it = includeonlys_.begin();
3202                 for (; it != includeonlys_.end() ; ++it) {
3203                         bp_.addIncludedChildren(*it);
3204                 }
3205         }
3206         bp_.maintain_unincluded_children =
3207                 masterChildModule->maintainAuxCB->isChecked();
3208
3209         // Float Placement
3210         bp_.float_placement = floatModule->get();
3211
3212         // Listings
3213         // text should have passed validation
3214         idx = listingsModule->packageCO->currentIndex();
3215         bp_.use_minted = string(lst_packages[idx]) == "Minted";
3216         bp_.listings_params =
3217                 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
3218
3219         // Formats
3220         bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
3221                 outputModule->defaultFormatCO->currentIndex()).toString());
3222
3223         bool const nontexfonts = fontModule->osFontsCB->isChecked();
3224         bp_.useNonTeXFonts = nontexfonts;
3225
3226         bp_.shell_escape = outputModule->shellescapeCB->isChecked();
3227         if (!bp_.shell_escape)
3228             theSession().shellescapeFiles().remove(buffer().absFileName());
3229         else if (!theSession().shellescapeFiles().find(buffer().absFileName()))
3230             theSession().shellescapeFiles().insert(buffer().absFileName());
3231         Buffer & buf = const_cast<Buffer &>(buffer());
3232         buf.params().shell_escape = bp_.shell_escape;
3233
3234         bp_.output_sync = outputModule->outputsyncCB->isChecked();
3235
3236         bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
3237
3238         int mathfmt = outputModule->mathoutCB->currentIndex();
3239         if (mathfmt == -1)
3240                 mathfmt = 0;
3241         BufferParams::MathOutput const mo =
3242                 static_cast<BufferParams::MathOutput>(mathfmt);
3243         bp_.html_math_output = mo;
3244         bp_.html_be_strict = outputModule->strictCB->isChecked();
3245         bp_.html_css_as_file = outputModule->cssCB->isChecked();
3246         bp_.html_math_img_scale = outputModule->mathimgSB->value();
3247         bp_.display_pixel_ratio = theGuiApp()->pixelRatio();
3248
3249         bp_.save_transient_properties =
3250                 outputModule->saveTransientPropertiesCB->isChecked();
3251
3252         // fonts
3253         bp_.fonts_roman[nontexfonts] =
3254                 fromqstr(fontModule->fontsRomanCO->
3255                         itemData(fontModule->fontsRomanCO->currentIndex()).toString());
3256         bp_.fonts_roman[!nontexfonts] = fromqstr(fontModule->font_roman);
3257
3258         bp_.fonts_sans[nontexfonts] =
3259                 fromqstr(fontModule->fontsSansCO->
3260                         itemData(fontModule->fontsSansCO->currentIndex()).toString());
3261         bp_.fonts_sans[!nontexfonts] = fromqstr(fontModule->font_sans);
3262
3263         bp_.fonts_typewriter[nontexfonts] =
3264                 fromqstr(fontModule->fontsTypewriterCO->
3265                         itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
3266         bp_.fonts_typewriter[!nontexfonts] = fromqstr(fontModule->font_typewriter);
3267
3268         bp_.fonts_math[nontexfonts] =
3269                 fromqstr(fontModule->fontsMathCO->
3270                         itemData(fontModule->fontsMathCO->currentIndex()).toString());
3271         bp_.fonts_math[!nontexfonts] = fromqstr(fontModule->font_math);
3272
3273         QString const fontenc =
3274                 fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
3275         if (fontenc == "custom")
3276                 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
3277         else
3278                 bp_.fontenc = fromqstr(fontenc);
3279
3280         bp_.fonts_cjk =
3281                 fromqstr(fontModule->cjkFontLE->text());
3282
3283         bp_.use_microtype = fontModule->microtypeCB->isChecked();
3284         bp_.use_dash_ligatures = !fontModule->dashesCB->isChecked();
3285
3286         bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
3287         bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
3288
3289         bp_.fonts_typewriter_scale[nontexfonts] = fontModule->scaleTypewriterSB->value();
3290         bp_.fonts_typewriter_scale[!nontexfonts] = fontModule->font_tt_scale;
3291
3292         bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
3293
3294         bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
3295
3296         if (nontexfonts)
3297                 bp_.fonts_default_family = "default";
3298         else
3299                 bp_.fonts_default_family = GuiDocument::fontfamilies[
3300                         fontModule->fontsDefaultCO->currentIndex()];
3301
3302         if (fontModule->fontsizeCO->currentIndex() == 0)
3303                 bp_.fontsize = "default";
3304         else
3305                 bp_.fontsize =
3306                         fromqstr(fontModule->fontsizeCO->currentText());
3307
3308         // paper
3309         bp_.papersize = PAPER_SIZE(
3310                 pageLayoutModule->papersizeCO->currentIndex());
3311
3312         bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
3313                 pageLayoutModule->paperwidthUnitCO);
3314
3315         bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
3316                 pageLayoutModule->paperheightUnitCO);
3317
3318         if (pageLayoutModule->facingPagesCB->isChecked())
3319                 bp_.sides = TwoSides;
3320         else
3321                 bp_.sides = OneSide;
3322
3323         if (pageLayoutModule->landscapeRB->isChecked())
3324                 bp_.orientation = ORIENTATION_LANDSCAPE;
3325         else
3326                 bp_.orientation = ORIENTATION_PORTRAIT;
3327
3328         // margins
3329         bp_.use_geometry = !marginsModule->marginCB->isChecked();
3330
3331         Ui::MarginsUi const * m = marginsModule;
3332
3333         bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
3334         bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
3335         bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
3336         bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
3337         bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
3338         bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
3339         bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
3340         bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
3341
3342         // branches
3343         branchesModule->apply(bp_);
3344
3345         // PDF support
3346         PDFOptions & pdf = bp_.pdfoptions();
3347         pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
3348         pdf.title = fromqstr(pdfSupportModule->titleLE->text());
3349         pdf.author = fromqstr(pdfSupportModule->authorLE->text());
3350         pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
3351         pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
3352
3353         pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
3354         pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
3355         pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
3356         pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
3357
3358         pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
3359         pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
3360         pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
3361         pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
3362         pdf.backref =
3363                 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
3364         if (pdfSupportModule->fullscreenCB->isChecked())
3365                 pdf.pagemode = pdf.pagemode_fullscreen;
3366         else
3367                 pdf.pagemode.clear();
3368         pdf.quoted_options = pdf.quoted_options_check(
3369                                 fromqstr(pdfSupportModule->optionsLE->text()));
3370
3371         // reset trackers
3372         nonModuleChanged_ = false;
3373         shellescapeChanged_ = false;
3374 }
3375
3376
3377 void GuiDocument::paramsToDialog()
3378 {
3379         // set the default unit
3380         Length::UNIT const default_unit = Length::defaultUnit();
3381
3382         // preamble
3383         preambleModule->update(bp_, id());
3384         localLayout->update(bp_, id());
3385
3386         // date
3387         latexModule->suppressDateCB->setChecked(bp_.suppress_date);
3388         latexModule->refstyleCB->setChecked(bp_.use_refstyle);
3389
3390         // biblio
3391         string const cite_engine = bp_.citeEngine().list().front();
3392
3393         biblioModule->citeEngineCO->setCurrentIndex(
3394                 biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
3395
3396         updateEngineType(documentClass().opt_enginetype(),
3397                 bp_.citeEngineType());
3398
3399         checkPossibleCiteEngines();
3400
3401         biblioModule->citeStyleCO->setCurrentIndex(
3402                 biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
3403
3404         biblioModule->bibtopicCB->setChecked(bp_.splitbib());
3405
3406         biblioModule->bibunitsCO->clear();
3407         biblioModule->bibunitsCO->addItem(qt_("No"), QString());
3408         if (documentClass().hasLaTeXLayout("part"))
3409                 biblioModule->bibunitsCO->addItem(qt_("per part"), toqstr("part"));
3410         if (documentClass().hasLaTeXLayout("chapter"))
3411                 biblioModule->bibunitsCO->addItem(qt_("per chapter"), toqstr("chapter"));
3412         if (documentClass().hasLaTeXLayout("section"))
3413                 biblioModule->bibunitsCO->addItem(qt_("per section"), toqstr("section"));
3414         if (documentClass().hasLaTeXLayout("subsection"))
3415                 biblioModule->bibunitsCO->addItem(qt_("per subsection"), toqstr("subsection"));
3416         biblioModule->bibunitsCO->addItem(qt_("per child document"), toqstr("child"));
3417
3418         int const mbpos = biblioModule->bibunitsCO->findData(toqstr(bp_.multibib));
3419         if (mbpos != -1)
3420                 biblioModule->bibunitsCO->setCurrentIndex(mbpos);
3421         else
3422                 biblioModule->bibunitsCO->setCurrentIndex(0);
3423
3424         updateEngineDependends();
3425
3426         if (isBiblatex()) {
3427                 updateDefaultBiblio(bp_.biblatex_bibstyle, "bbx");
3428                 updateDefaultBiblio(bp_.biblatex_citestyle, "cbx");
3429         } else
3430                 updateDefaultBiblio(bp_.defaultBiblioStyle());
3431
3432         biblioModule->citePackageOptionsLE->setText(toqstr(bp_.biblio_opts));
3433
3434         string command;
3435         string options =
3436                 split(bp_.bibtex_command, command, ' ');
3437
3438         int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
3439         if (bpos != -1) {
3440                 biblioModule->bibtexCO->setCurrentIndex(bpos);
3441                 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
3442         } else {
3443                 // We reset to default if we do not know the specified compiler
3444                 // This is for security reasons
3445                 biblioModule->bibtexCO->setCurrentIndex(
3446                         biblioModule->bibtexCO->findData(toqstr("default")));
3447                 biblioModule->bibtexOptionsLE->clear();
3448         }
3449         biblioModule->bibtexOptionsLE->setEnabled(
3450                 biblioModule->bibtexCO->currentIndex() != 0);
3451
3452         biblioChanged_ = false;
3453
3454         // indices
3455         // We may be called when there is no Buffer, e.g., when
3456         // the last view has just been closed.
3457         bool const isReadOnly = isBufferAvailable() ? buffer().isReadonly() : false;
3458         indicesModule->update(bp_, isReadOnly);
3459
3460         // language & quotes
3461         int const pos = langModule->languageCO->findData(toqstr(
3462                 bp_.language->lang()));
3463         langModule->languageCO->setCurrentIndex(pos);
3464
3465         updateQuoteStyles();
3466
3467         langModule->quoteStyleCO->setCurrentIndex(
3468                 langModule->quoteStyleCO->findData(bp_.quotes_style));
3469         langModule->dynamicQuotesCB->setChecked(bp_.dynamic_quotes);
3470
3471         bool default_enc = true;
3472         if (bp_.inputenc != "auto") {
3473                 default_enc = false;
3474                 if (bp_.inputenc == "default") {
3475                         langModule->encodingCO->setCurrentIndex(0);
3476                 } else {
3477                         string enc_gui;
3478                         Encodings::const_iterator it = encodings.begin();
3479                         Encodings::const_iterator const end = encodings.end();
3480                         for (; it != end; ++it) {
3481                                 if (it->name() == bp_.inputenc &&
3482                                     !it->unsafe()) {
3483                                         enc_gui = it->guiName();
3484                                         break;
3485                                 }
3486                         }
3487                         int const i = langModule->encodingCO->findText(
3488                                         qt_(enc_gui));
3489                         if (i >= 0)
3490                                 langModule->encodingCO->setCurrentIndex(i);
3491                         else
3492                                 // unknown encoding. Set to default.
3493                                 default_enc = true;
3494                 }
3495         }
3496         langModule->defaultencodingRB->setChecked(default_enc);
3497         langModule->otherencodingRB->setChecked(!default_enc);
3498
3499         int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
3500         if (p == -1) {
3501                 langModule->languagePackageCO->setCurrentIndex(
3502                           langModule->languagePackageCO->findData("custom"));
3503                 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
3504         } else {
3505                 langModule->languagePackageCO->setCurrentIndex(p);
3506                 langModule->languagePackageLE->clear();
3507         }
3508
3509         //color
3510         if (bp_.isfontcolor) {
3511                 colorModule->fontColorPB->setStyleSheet(
3512                         colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
3513         }
3514         set_fontcolor = bp_.fontcolor;
3515         is_fontcolor = bp_.isfontcolor;
3516
3517         colorModule->noteFontColorPB->setStyleSheet(
3518                 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
3519         set_notefontcolor = bp_.notefontcolor;
3520
3521         if (bp_.isbackgroundcolor) {
3522                 colorModule->backgroundPB->setStyleSheet(
3523                         colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
3524         }
3525         set_backgroundcolor = bp_.backgroundcolor;
3526         is_backgroundcolor = bp_.isbackgroundcolor;
3527
3528         colorModule->boxBackgroundPB->setStyleSheet(
3529                 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
3530         set_boxbgcolor = bp_.boxbgcolor;
3531
3532         // numbering
3533         int const min_toclevel = documentClass().min_toclevel();
3534         int const max_toclevel = documentClass().max_toclevel();
3535         if (documentClass().hasTocLevels()) {
3536                 numberingModule->setEnabled(true);
3537                 numberingModule->depthSL->setMinimum(min_toclevel - 1);
3538                 numberingModule->depthSL->setMaximum(max_toclevel);
3539                 numberingModule->depthSL->setValue(bp_.secnumdepth);
3540                 numberingModule->tocSL->setMaximum(min_toclevel - 1);
3541                 numberingModule->tocSL->setMaximum(max_toclevel);
3542                 numberingModule->tocSL->setValue(bp_.tocdepth);
3543                 updateNumbering();
3544         } else {
3545                 numberingModule->setEnabled(false);
3546                 numberingModule->tocTW->clear();
3547         }
3548
3549         // bullets
3550         bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
3551         bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
3552         bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
3553         bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
3554         bulletsModule->init();
3555
3556         // packages
3557         int nitem = findToken(tex_graphics, bp_.graphics_driver);
3558         if (nitem >= 0)
3559                 latexModule->psdriverCO->setCurrentIndex(nitem);
3560         updateModuleInfo();
3561
3562         // math
3563         mathsModule->MathIndentCB->setChecked(bp_.is_math_indent);
3564         if (bp_.is_math_indent) {
3565                 Length const mathindent = bp_.getMathIndent();
3566                 int indent = 0;
3567                 if (!mathindent.empty()) {
3568                         lengthToWidgets(mathsModule->MathIndentLE,
3569                                         mathsModule->MathIndentLengthCO,
3570                                         mathindent, default_unit);
3571                         indent = 1;
3572                 }
3573                 mathsModule->MathIndentCO->setCurrentIndex(indent);
3574                 enableMathIndent(indent);
3575         }
3576         switch(bp_.math_numbering_side) {
3577         case BufferParams::LEFT:
3578                 mathsModule->MathNumberingPosCO->setCurrentIndex(0);
3579                 break;
3580         case BufferParams::DEFAULT:
3581                 mathsModule->MathNumberingPosCO->setCurrentIndex(1);
3582                 break;
3583         case BufferParams::RIGHT:
3584                 mathsModule->MathNumberingPosCO->setCurrentIndex(2);
3585         }
3586
3587         map<string, string> const & packages = BufferParams::auto_packages();
3588         for (map<string, string>::const_iterator it = packages.begin();
3589              it != packages.end(); ++it) {
3590                 QTableWidgetItem * item = mathsModule->packagesTW->findItems(toqstr(it->first), Qt::MatchExactly)[0];
3591                 if (!item)
3592                         continue;
3593                 int row = mathsModule->packagesTW->row(item);
3594                 switch (bp_.use_package(it->first)) {
3595                         case BufferParams::package_off: {
3596                                 QRadioButton * rb =
3597                                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
3598                                 rb->setChecked(true);
3599                                 break;
3600                         }
3601                         case BufferParams::package_on: {
3602                                 QRadioButton * rb =
3603                                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
3604                                 rb->setChecked(true);
3605                                 break;
3606                         }
3607                         case BufferParams::package_auto: {
3608                                 QRadioButton * rb =
3609                                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
3610                                 rb->setChecked(true);
3611                                 break;
3612                         }
3613                 }
3614         }
3615
3616         switch (bp_.spacing().getSpace()) {
3617                 case Spacing::Other: nitem = 3; break;
3618                 case Spacing::Double: nitem = 2; break;
3619                 case Spacing::Onehalf: nitem = 1; break;
3620                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
3621         }
3622
3623         // text layout
3624         string const & layoutID = bp_.baseClassID();
3625         setLayoutComboByIDString(layoutID);
3626
3627         updatePagestyle(documentClass().opt_pagestyle(),
3628                                  bp_.pagestyle);
3629
3630         textLayoutModule->lspacingCO->setCurrentIndex(nitem);
3631         if (bp_.spacing().getSpace() == Spacing::Other) {
3632                 doubleToWidget(textLayoutModule->lspacingLE,
3633                         bp_.spacing().getValueAsString());
3634         }
3635         setLSpacing(nitem);
3636
3637         if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
3638                 textLayoutModule->indentRB->setChecked(true);
3639                 string parindent = bp_.getParIndent().asString();
3640                 int indent = 0;
3641                 if (!parindent.empty()) {
3642                         lengthToWidgets(textLayoutModule->indentLE,
3643                                         textLayoutModule->indentLengthCO,
3644                                         parindent, default_unit);
3645                         indent = 1;
3646                 }
3647                 textLayoutModule->indentCO->setCurrentIndex(indent);
3648                 setIndent(indent);
3649         } else {
3650                 textLayoutModule->skipRB->setChecked(true);
3651                 int skip = 0;
3652                 switch (bp_.getDefSkip().kind()) {
3653                 case VSpace::SMALLSKIP:
3654                         skip = 0;
3655                         break;
3656                 case VSpace::MEDSKIP:
3657                         skip = 1;
3658                         break;
3659                 case VSpace::BIGSKIP:
3660                         skip = 2;
3661                         break;
3662                 case VSpace::LENGTH:
3663                         {
3664                         skip = 3;
3665                         string const length = bp_.getDefSkip().asLyXCommand();
3666                         lengthToWidgets(textLayoutModule->skipLE,
3667                                 textLayoutModule->skipLengthCO,
3668                                 length, default_unit);
3669                         break;
3670                         }
3671                 default:
3672                         skip = 0;
3673                         break;
3674                 }
3675                 textLayoutModule->skipCO->setCurrentIndex(skip);
3676                 setSkip(skip);
3677         }
3678
3679         textLayoutModule->twoColumnCB->setChecked(
3680                 bp_.columns == 2);
3681         textLayoutModule->justCB->setChecked(bp_.justification);
3682
3683         if (!bp_.options.empty()) {
3684                 latexModule->optionsLE->setText(
3685                         toqstr(bp_.options));
3686         } else {
3687                 latexModule->optionsLE->setText(QString());
3688         }
3689
3690         // latex
3691         latexModule->defaultOptionsCB->setChecked(
3692                         bp_.use_default_options);
3693         updateSelectedModules();
3694         selectionManager->updateProvidedModules(
3695                         bp_.baseClass()->providedModules());
3696         selectionManager->updateExcludedModules(
3697                         bp_.baseClass()->excludedModules());
3698
3699         if (!documentClass().options().empty()) {
3700                 latexModule->defaultOptionsLE->setText(
3701                         toqstr(documentClass().options()));
3702         } else {
3703                 latexModule->defaultOptionsLE->setText(
3704                         toqstr(_("[No options predefined]")));
3705         }
3706
3707         latexModule->defaultOptionsLE->setEnabled(
3708                 bp_.use_default_options
3709                 && !documentClass().options().empty());
3710
3711         latexModule->defaultOptionsCB->setEnabled(
3712                 !documentClass().options().empty());
3713
3714         if (!bp_.master.empty()) {
3715                 latexModule->childDocGB->setChecked(true);
3716                 latexModule->childDocLE->setText(
3717                         toqstr(bp_.master));
3718         } else {
3719                 latexModule->childDocLE->setText(QString());
3720                 latexModule->childDocGB->setChecked(false);
3721         }
3722
3723         // Master/Child
3724         if (!bufferview() || !buffer().hasChildren()) {
3725                 masterChildModule->childrenTW->clear();
3726                 includeonlys_.clear();
3727                 docPS->showPanel("Child Documents", false);
3728                 if (docPS->isCurrentPanel("Child Documents"))
3729                         docPS->setCurrentPanel("Document Class");
3730         } else {
3731                 docPS->showPanel("Child Documents", true);
3732                 masterChildModule->setEnabled(true);
3733                 includeonlys_ = bp_.getIncludedChildren();
3734                 updateIncludeonlys();
3735         }
3736         masterChildModule->maintainAuxCB->setChecked(
3737                 bp_.maintain_unincluded_children);
3738
3739         // Float Settings
3740         floatModule->set(bp_.float_placement);
3741
3742         // ListingsSettings
3743         // break listings_params to multiple lines
3744         string lstparams =
3745                 InsetListingsParams(bp_.listings_params).separatedParams();
3746         listingsModule->listingsED->setPlainText(toqstr(lstparams));
3747         int nn = findToken(lst_packages, bp_.use_minted ? "Minted" : "Listings");
3748         if (nn >= 0)
3749                 listingsModule->packageCO->setCurrentIndex(nn);
3750
3751
3752         // Fonts
3753         // some languages only work with polyglossia/XeTeX
3754         Language const * lang = lyx::languages.getLanguage(
3755                 fromqstr(langModule->languageCO->itemData(
3756                         langModule->languageCO->currentIndex()).toString()));
3757         bool const need_fontspec =
3758                 lang->babel().empty() && !lang->polyglossia().empty();
3759         bool const os_fonts_available =
3760                 bp_.baseClass()->outputType() == lyx::LATEX
3761                 && LaTeXFeatures::isAvailable("fontspec");
3762         fontModule->osFontsCB->setEnabled(os_fonts_available && !need_fontspec);
3763         fontModule->osFontsCB->setChecked(
3764                 (os_fonts_available && bp_.useNonTeXFonts) || need_fontspec);
3765         updateFontsize(documentClass().opt_fontsize(),
3766                         bp_.fontsize);
3767
3768         QString font = toqstr(bp_.fontsRoman());
3769         int rpos = fontModule->fontsRomanCO->findData(font);
3770         if (rpos == -1) {
3771                 rpos = fontModule->fontsRomanCO->count();
3772                 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
3773         }
3774         fontModule->fontsRomanCO->setCurrentIndex(rpos);
3775         fontModule->font_roman = toqstr(bp_.fonts_roman[!bp_.useNonTeXFonts]);
3776
3777         font = toqstr(bp_.fontsSans());
3778         int spos = fontModule->fontsSansCO->findData(font);
3779         if (spos == -1) {
3780                 spos = fontModule->fontsSansCO->count();
3781                 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
3782         }
3783         fontModule->fontsSansCO->setCurrentIndex(spos);
3784         fontModule->font_sans = toqstr(bp_.fonts_sans[!bp_.useNonTeXFonts]);
3785
3786         font = toqstr(bp_.fontsTypewriter());
3787         int tpos = fontModule->fontsTypewriterCO->findData(font);
3788         if (tpos == -1) {
3789                 tpos = fontModule->fontsTypewriterCO->count();
3790                 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
3791         }
3792         fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3793         fontModule->font_typewriter = toqstr(bp_.fonts_typewriter[!bp_.useNonTeXFonts]);
3794
3795         font = toqstr(bp_.fontsMath());
3796         int mpos = fontModule->fontsMathCO->findData(font);
3797         if (mpos == -1) {
3798                 mpos = fontModule->fontsMathCO->count();
3799                 fontModule->fontsMathCO->addItem(font + qt_(" (not installed)"), font);
3800         }
3801         fontModule->fontsMathCO->setCurrentIndex(mpos);
3802         fontModule->font_math = toqstr(bp_.fonts_math[!bp_.useNonTeXFonts]);
3803
3804         if (bp_.useNonTeXFonts && os_fonts_available) {
3805                 fontModule->fontencLA->setEnabled(false);
3806                 fontModule->fontencCO->setEnabled(false);
3807                 fontModule->fontencLE->setEnabled(false);
3808         } else {
3809                 fontModule->fontencLA->setEnabled(true);
3810                 fontModule->fontencCO->setEnabled(true);
3811                 fontModule->fontencLE->setEnabled(true);
3812                 romanChanged(rpos);
3813                 sansChanged(spos);
3814                 ttChanged(tpos);
3815         }
3816
3817         if (!bp_.fonts_cjk.empty())
3818                 fontModule->cjkFontLE->setText(
3819                         toqstr(bp_.fonts_cjk));
3820         else
3821                 fontModule->cjkFontLE->setText(QString());
3822
3823         fontModule->microtypeCB->setChecked(bp_.use_microtype);
3824         fontModule->dashesCB->setChecked(!bp_.use_dash_ligatures);
3825
3826         fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3827         fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3828         fontModule->scaleSansSB->setValue(bp_.fontsSansScale());
3829         fontModule->font_sf_scale = bp_.fonts_sans_scale[!bp_.useNonTeXFonts];
3830         fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale());
3831         fontModule->font_tt_scale = bp_.fonts_typewriter_scale[!bp_.useNonTeXFonts];
3832
3833         nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3834         if (nn >= 0)
3835                 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3836
3837         if (bp_.fontenc == "global" || bp_.fontenc == "default") {
3838                 fontModule->fontencCO->setCurrentIndex(
3839                         fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
3840                 fontModule->fontencLE->setEnabled(false);
3841         } else {
3842                 fontModule->fontencCO->setCurrentIndex(1);
3843                 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3844         }
3845
3846         // Formats
3847         // This must be set _after_ fonts since updateDefaultFormat()
3848         // checks osFontsCB settings.
3849         // update combobox with formats
3850         updateDefaultFormat();
3851         int index = outputModule->defaultFormatCO->findData(toqstr(
3852                 bp_.default_output_format));
3853         // set to default if format is not found
3854         if (index == -1)
3855                 index = 0;
3856         outputModule->defaultFormatCO->setCurrentIndex(index);
3857
3858         outputModule->shellescapeCB->setChecked(bp_.shell_escape);
3859         outputModule->outputsyncCB->setChecked(bp_.output_sync);
3860         outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
3861
3862         outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
3863         outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
3864         outputModule->strictCB->setChecked(bp_.html_be_strict);
3865         outputModule->cssCB->setChecked(bp_.html_css_as_file);
3866
3867         outputModule->saveTransientPropertiesCB
3868                 ->setChecked(bp_.save_transient_properties);
3869
3870         // paper
3871         bool const extern_geometry =
3872                 documentClass().provides("geometry");
3873         int const psize = bp_.papersize;
3874         pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3875         setCustomPapersize(!extern_geometry && psize == 1);
3876         pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3877
3878         bool const landscape =
3879                 bp_.orientation == ORIENTATION_LANDSCAPE;
3880         pageLayoutModule->landscapeRB->setChecked(landscape);
3881         pageLayoutModule->portraitRB->setChecked(!landscape);
3882         pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3883         pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3884
3885         pageLayoutModule->facingPagesCB->setChecked(
3886                 bp_.sides == TwoSides);
3887
3888         lengthToWidgets(pageLayoutModule->paperwidthLE,
3889                 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3890         lengthToWidgets(pageLayoutModule->paperheightLE,
3891                 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3892
3893         // margins
3894         Ui::MarginsUi * m = marginsModule;
3895
3896         setMargins();
3897
3898         lengthToWidgets(m->topLE, m->topUnit,
3899                 bp_.topmargin, default_unit);
3900
3901         lengthToWidgets(m->bottomLE, m->bottomUnit,
3902                 bp_.bottommargin, default_unit);
3903
3904         lengthToWidgets(m->innerLE, m->innerUnit,
3905                 bp_.leftmargin, default_unit);
3906
3907         lengthToWidgets(m->outerLE, m->outerUnit,
3908                 bp_.rightmargin, default_unit);
3909
3910         lengthToWidgets(m->headheightLE, m->headheightUnit,
3911                 bp_.headheight, default_unit);
3912
3913         lengthToWidgets(m->headsepLE, m->headsepUnit,
3914                 bp_.headsep, default_unit);
3915
3916         lengthToWidgets(m->footskipLE, m->footskipUnit,
3917                 bp_.footskip, default_unit);
3918
3919         lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3920                 bp_.columnsep, default_unit);
3921
3922         // branches
3923         updateUnknownBranches();
3924         branchesModule->update(bp_);
3925
3926         // PDF support
3927         PDFOptions const & pdf = bp_.pdfoptions();
3928         pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3929         if (bp_.documentClass().provides("hyperref"))
3930                 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3931         else
3932                 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3933         pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3934         pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3935         pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3936         pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3937
3938         pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3939         pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3940         pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3941
3942         pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3943
3944         pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3945         pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3946         pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3947         pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3948
3949         nn = findToken(backref_opts, pdf.backref);
3950         if (nn >= 0)
3951                 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3952
3953         pdfSupportModule->fullscreenCB->setChecked
3954                 (pdf.pagemode == pdf.pagemode_fullscreen);
3955
3956         pdfSupportModule->optionsLE->setText(
3957                 toqstr(pdf.quoted_options));
3958
3959         // Make sure that the bc is in the INITIAL state
3960         if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3961                 bc().restore();
3962
3963         // clear changed branches cache
3964         changedBranches_.clear();
3965
3966         // reset trackers
3967         nonModuleChanged_ = false;
3968         shellescapeChanged_ = false;
3969 }
3970
3971
3972 void GuiDocument::saveDocDefault()
3973 {
3974         // we have to apply the params first
3975         applyView();
3976         saveAsDefault();
3977 }
3978
3979
3980 void GuiDocument::updateAvailableModules()
3981 {
3982         modules_av_model_.clear();
3983         list<modInfoStruct> modInfoList = getModuleInfo();
3984         // Sort names according to the locale
3985         modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) {
3986                         return 0 < b.name.localeAwareCompare(a.name);
3987                 });
3988         int i = 0;
3989         for (modInfoStruct const & m : modInfoList) {
3990                 modules_av_model_.insertRow(i, m.name, m.id, m.description);
3991                 ++i;
3992         }
3993 }
3994
3995
3996 void GuiDocument::updateSelectedModules()
3997 {
3998         modules_sel_model_.clear();
3999         list<modInfoStruct> const selModList = getSelectedModules();
4000         int i = 0;
4001         for (modInfoStruct const & m : selModList) {
4002                 modules_sel_model_.insertRow(i, m.name, m.id, m.description);
4003                 ++i;
4004         }
4005 }
4006
4007
4008 void GuiDocument::updateIncludeonlys()
4009 {
4010         masterChildModule->childrenTW->clear();
4011         QString const no = qt_("No");
4012         QString const yes = qt_("Yes");
4013
4014         if (includeonlys_.empty()) {
4015                 masterChildModule->includeallRB->setChecked(true);
4016                 masterChildModule->childrenTW->setEnabled(false);
4017                 masterChildModule->maintainAuxCB->setEnabled(false);
4018         } else {
4019                 masterChildModule->includeonlyRB->setChecked(true);
4020                 masterChildModule->childrenTW->setEnabled(true);
4021                 masterChildModule->maintainAuxCB->setEnabled(true);
4022         }
4023         ListOfBuffers children = buffer().getChildren();
4024         ListOfBuffers::const_iterator it  = children.begin();
4025         ListOfBuffers::const_iterator end = children.end();
4026         bool has_unincluded = false;
4027         bool all_unincluded = true;
4028         for (; it != end; ++it) {
4029                 QTreeWidgetItem * item = new QTreeWidgetItem(masterChildModule->childrenTW);
4030                 // FIXME Unicode
4031                 string const name =
4032                         to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
4033                                                         from_utf8(buffer().filePath())));
4034                 item->setText(0, toqstr(name));
4035                 item->setText(1, isChildIncluded(name) ? yes : no);
4036                 if (!isChildIncluded(name))
4037                         has_unincluded = true;
4038                 else
4039                         all_unincluded = false;
4040         }
4041         // Both if all childs are included and if none is included
4042         // is equal to "include all" (i.e., omit \includeonly).
4043         // Thus, reset the GUI.
4044         if (!has_unincluded || all_unincluded) {
4045                 masterChildModule->includeallRB->setChecked(true);
4046                 masterChildModule->childrenTW->setEnabled(false);
4047                 includeonlys_.clear();
4048         }
4049         // If all are included, we need to update again.
4050         if (!has_unincluded)
4051                 updateIncludeonlys();
4052 }
4053
4054
4055 bool GuiDocument::isBiblatex() const
4056 {
4057         QString const engine =
4058                 biblioModule->citeEngineCO->itemData(
4059                                 biblioModule->citeEngineCO->currentIndex()).toString();
4060
4061         // this can happen if the cite engine is unknown, which can happen
4062         // if one is using a file that came from someone else, etc. in that
4063         // case, we crash if we proceed.
4064         if (engine.isEmpty())
4065             return false;
4066
4067         return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
4068 }
4069
4070
4071 void GuiDocument::updateDefaultBiblio(string const & style,
4072                                       string const & which)
4073 {
4074         QString const bibstyle = toqstr(style);
4075         biblioModule->defaultBiblioCO->clear();
4076
4077         int item_nr = -1;
4078
4079         if (isBiblatex()) {
4080                 if (which != "cbx") {
4081                         // First the bbx styles
4082                         biblioModule->biblatexBbxCO->clear();
4083                         QStringList str = texFileList("bbxFiles.lst");
4084                         // test whether we have a valid list, otherwise run rescan
4085                         if (str.isEmpty()) {
4086                                 rescanTexStyles("bbx");
4087                                 str = texFileList("bbxFiles.lst");
4088                         }
4089                         for (int i = 0; i != str.size(); ++i)
4090                                 str[i] = onlyFileName(str[i]);
4091                         // sort on filename only (no path)
4092                         str.sort();
4093
4094                         for (int i = 0; i != str.count(); ++i) {
4095                                 QString item = changeExtension(str[i], "");
4096                                 if (item == bibstyle)
4097                                         item_nr = i;
4098                                 biblioModule->biblatexBbxCO->addItem(item);
4099                         }
4100
4101                         if (item_nr == -1 && !bibstyle.isEmpty()) {
4102                                 biblioModule->biblatexBbxCO->addItem(bibstyle);
4103                                 item_nr = biblioModule->biblatexBbxCO->count() - 1;
4104                         }
4105
4106                         if (item_nr != -1)
4107                                 biblioModule->biblatexBbxCO->setCurrentIndex(item_nr);
4108                         else
4109                                 biblioModule->biblatexBbxCO->clearEditText();
4110                 }
4111
4112                 if (which != "bbx") {
4113                         // now the cbx styles
4114                         biblioModule->biblatexCbxCO->clear();
4115                         QStringList str = texFileList("cbxFiles.lst");
4116                         // test whether we have a valid list, otherwise run rescan
4117                         if (str.isEmpty()) {
4118                                 rescanTexStyles("cbx");
4119                                 str = texFileList("cbxFiles.lst");
4120                         }
4121                         for (int i = 0; i != str.size(); ++i)
4122                                 str[i] = onlyFileName(str[i]);
4123                         // sort on filename only (no path)
4124                         str.sort();
4125
4126                         for (int i = 0; i != str.count(); ++i) {
4127                                 QString item = changeExtension(str[i], "");
4128                                 if (item == bibstyle)
4129                                         item_nr = i;
4130                                 biblioModule->biblatexCbxCO->addItem(item);
4131                         }
4132
4133                         if (item_nr == -1 && !bibstyle.isEmpty()) {
4134                                 biblioModule->biblatexCbxCO->addItem(bibstyle);
4135                                 item_nr = biblioModule->biblatexCbxCO->count() - 1;
4136                         }
4137
4138                         if (item_nr != -1)
4139                                 biblioModule->biblatexCbxCO->setCurrentIndex(item_nr);
4140                         else
4141                                 biblioModule->biblatexCbxCO->clearEditText();
4142                 }
4143         } else {// BibTeX
4144                 biblioModule->biblatexBbxCO->clear();
4145                 biblioModule->biblatexCbxCO->clear();
4146                 QStringList str = texFileList("bstFiles.lst");
4147                 // test whether we have a valid list, otherwise run rescan
4148                 if (str.isEmpty()) {
4149                         rescanTexStyles("bst");
4150                         str = texFileList("bstFiles.lst");
4151                 }
4152                 for (int i = 0; i != str.size(); ++i)
4153                         str[i] = onlyFileName(str[i]);
4154                 // sort on filename only (no path)
4155                 str.sort();
4156
4157                 for (int i = 0; i != str.count(); ++i) {
4158                         QString item = changeExtension(str[i], "");
4159                         if (item == bibstyle)
4160                                 item_nr = i;
4161                         biblioModule->defaultBiblioCO->addItem(item);
4162                 }
4163
4164                 if (item_nr == -1 && !bibstyle.isEmpty()) {
4165                         biblioModule->defaultBiblioCO->addItem(bibstyle);
4166                         item_nr = biblioModule->defaultBiblioCO->count() - 1;
4167                 }
4168
4169                 if (item_nr != -1)
4170                         biblioModule->defaultBiblioCO->setCurrentIndex(item_nr);
4171                 else
4172                         biblioModule->defaultBiblioCO->clearEditText();
4173         }
4174
4175         updateResetDefaultBiblio();
4176 }
4177
4178
4179 void GuiDocument::updateResetDefaultBiblio()
4180 {
4181         QString const engine =
4182                 biblioModule->citeEngineCO->itemData(
4183                                 biblioModule->citeEngineCO->currentIndex()).toString();
4184         CiteEngineType const cet =
4185                 CiteEngineType(biblioModule->citeStyleCO->itemData(
4186                                                           biblioModule->citeStyleCO->currentIndex()).toInt());
4187
4188         string const defbib = theCiteEnginesList[fromqstr(engine)]->getDefaultBiblio(cet);
4189         if (isBiblatex()) {
4190                 QString const bbx = biblioModule->biblatexBbxCO->currentText();
4191                 QString const cbx = biblioModule->biblatexCbxCO->currentText();
4192                 biblioModule->resetCbxPB->setEnabled(defbib != fromqstr(cbx));
4193                 biblioModule->resetBbxPB->setEnabled(defbib != fromqstr(bbx));
4194                 biblioModule->matchBbxPB->setEnabled(bbx != cbx && !cbx.isEmpty()
4195                         && biblioModule->biblatexBbxCO->findText(cbx) != -1);
4196         } else
4197                 biblioModule->resetDefaultBiblioPB->setEnabled(
4198                         defbib != fromqstr(biblioModule->defaultBiblioCO->currentText()));
4199 }
4200
4201
4202 void GuiDocument::matchBiblatexStyles()
4203 {
4204         updateDefaultBiblio(fromqstr(biblioModule->biblatexCbxCO->currentText()), "bbx");
4205         biblioChanged();
4206 }
4207
4208
4209 void GuiDocument::updateContents()
4210 {
4211         // Nothing to do here as the document settings is not cursor dependant.
4212         return;
4213 }
4214
4215
4216 void GuiDocument::useClassDefaults()
4217 {
4218         if (applyPB->isEnabled()) {
4219                 int const ret = Alert::prompt(_("Unapplied changes"),
4220                                 _("Some changes in the dialog were not yet applied.\n"
4221                                   "If you do not apply now, they will be lost after this action."),
4222                                 1, 1, _("&Apply"), _("&Dismiss"));
4223                 if (ret == 0)
4224                         applyView();
4225         }
4226
4227         int idx = latexModule->classCO->currentIndex();
4228         string const classname = fromqstr(latexModule->classCO->getData(idx));
4229         if (!bp_.setBaseClass(classname)) {
4230                 Alert::error(_("Error"), _("Unable to set document class."));
4231                 return;
4232         }
4233         bp_.useClassDefaults();
4234         paramsToDialog();
4235         changed();
4236 }
4237
4238
4239 void GuiDocument::setLayoutComboByIDString(string const & idString)
4240 {
4241         if (!latexModule->classCO->set(toqstr(idString)))
4242                 Alert::warning(_("Can't set layout!"),
4243                         bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
4244 }
4245
4246
4247 bool GuiDocument::isValid()
4248 {
4249         return
4250                 validateListingsParameters().isEmpty() &&
4251                 localLayout->isValid() &&
4252                 (
4253                         // if we're asking for skips between paragraphs
4254                         !textLayoutModule->skipRB->isChecked() ||
4255                         // then either we haven't chosen custom
4256                         textLayoutModule->skipCO->currentIndex() != 3 ||
4257                         // or else a length has been given
4258                         !textLayoutModule->skipLE->text().isEmpty()
4259                 ) &&
4260                 (
4261                         // if we're asking for indentation
4262                         !textLayoutModule->indentRB->isChecked() ||
4263                         // then either we haven't chosen custom
4264                         textLayoutModule->indentCO->currentIndex() != 1 ||
4265                         // or else a length has been given
4266                         !textLayoutModule->indentLE->text().isEmpty()
4267                 ) &&
4268                 (
4269                         // if we're asking for math indentation
4270                         !mathsModule->MathIndentCB->isChecked() ||
4271                         // then either we haven't chosen custom
4272                         mathsModule->MathIndentCO->currentIndex() != 1 ||
4273                         // or else a length has been given
4274                         !mathsModule->MathIndentLE->text().isEmpty()
4275                 );
4276 }
4277
4278
4279 char const * const GuiDocument::fontfamilies[5] = {
4280         "default", "rmdefault", "sfdefault", "ttdefault", ""
4281 };
4282
4283
4284 char const * GuiDocument::fontfamilies_gui[5] = {
4285         N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
4286 };
4287
4288
4289 bool GuiDocument::initialiseParams(string const &)
4290 {
4291         BufferView const * view = bufferview();
4292         if (!view) {
4293                 bp_ = BufferParams();
4294                 paramsToDialog();
4295                 return true;
4296         }
4297         bp_ = view->buffer().params();
4298         loadModuleInfo();
4299         updateAvailableModules();
4300         //FIXME It'd be nice to make sure here that the selected
4301         //modules are consistent: That required modules are actually
4302         //selected, and that we don't have conflicts. If so, we could
4303         //at least pop up a warning.
4304         paramsToDialog();
4305         return true;
4306 }
4307
4308
4309 void GuiDocument::clearParams()
4310 {
4311         bp_ = BufferParams();
4312 }
4313
4314
4315 BufferId GuiDocument::id() const
4316 {
4317         BufferView const * const view = bufferview();
4318         return view? &view->buffer() : 0;
4319 }
4320
4321
4322 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
4323 {
4324         return moduleNames_;
4325 }
4326
4327
4328 list<GuiDocument::modInfoStruct> const
4329 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
4330 {
4331         list<modInfoStruct> mInfo;
4332         for (string const & name : mods) {
4333                 modInfoStruct m;
4334                 LyXModule const * const mod = theModuleList[name];
4335                 if (mod)
4336                         m = modInfo(*mod);
4337                 else {
4338                         m.id = name;
4339                         m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")");
4340                 }
4341                 mInfo.push_back(m);
4342         }
4343         return mInfo;
4344 }
4345
4346
4347 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
4348 {
4349         return makeModuleInfo(params().getModules());
4350 }
4351
4352
4353 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
4354 {
4355         return makeModuleInfo(params().baseClass()->providedModules());
4356 }
4357
4358
4359 DocumentClass const & GuiDocument::documentClass() const
4360 {
4361         return bp_.documentClass();
4362 }
4363
4364
4365 static void dispatch_bufferparams(Dialog const & dialog,
4366         BufferParams const & bp, FuncCode lfun, Buffer const * buf)
4367 {
4368         ostringstream ss;
4369         ss << "\\begin_header\n";
4370         bp.writeFile(ss, buf);
4371         ss << "\\end_header\n";
4372         dialog.dispatch(FuncRequest(lfun, ss.str()));
4373 }
4374
4375
4376 void GuiDocument::dispatchParams()
4377 {
4378         // We need a non-const buffer object.
4379         Buffer & buf = const_cast<BufferView *>(bufferview())->buffer();
4380         // There may be several undo records; group them (bug #8998)
4381         // This handles undo groups automagically
4382         UndoGroupHelper ugh(&buf);
4383
4384         // This must come first so that a language change is correctly noticed
4385         setLanguage();
4386
4387         // Apply the BufferParams. Note that this will set the base class
4388         // and then update the buffer's layout.
4389         dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY, &buffer());
4390
4391         if (!params().master.empty()) {
4392                 FileName const master_file = support::makeAbsPath(params().master,
4393                            support::onlyPath(buffer().absFileName()));
4394                 if (isLyXFileName(master_file.absFileName())) {
4395                         Buffer * master = checkAndLoadLyXFile(master_file);
4396                         if (master) {
4397                                 if (master->isChild(const_cast<Buffer *>(&buffer())))
4398                                         const_cast<Buffer &>(buffer()).setParent(master);
4399                                 else
4400                                         Alert::warning(_("Assigned master does not include this file"),
4401                                                 bformat(_("You must include this file in the document\n"
4402                                                           "'%1$s' in order to use the master document\n"
4403                                                           "feature."), from_utf8(params().master)));
4404                         } else
4405                                 Alert::warning(_("Could not load master"),
4406                                                 bformat(_("The master document '%1$s'\n"
4407                                                            "could not be loaded."),
4408                                                            from_utf8(params().master)));
4409                 }
4410         }
4411
4412         // Generate the colours requested by each new branch.
4413         BranchList & branchlist = params().branchlist();
4414         if (!branchlist.empty()) {
4415                 BranchList::const_iterator it = branchlist.begin();
4416                 BranchList::const_iterator const end = branchlist.end();
4417                 for (; it != end; ++it) {
4418                         docstring const & current_branch = it->branch();
4419                         Branch const * branch = branchlist.find(current_branch);
4420                         string const x11hexname = X11hexname(branch->color());
4421                         // display the new color
4422                         docstring const str = current_branch + ' ' + from_ascii(x11hexname);
4423                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
4424                 }
4425         }
4426         // rename branches in the document
4427         executeBranchRenaming();
4428         // and clear changed branches cache
4429         changedBranches_.clear();
4430
4431         // Generate the colours requested by indices.
4432         IndicesList & indiceslist = params().indiceslist();
4433         if (!indiceslist.empty()) {
4434                 IndicesList::const_iterator it = indiceslist.begin();
4435                 IndicesList::const_iterator const end = indiceslist.end();
4436                 for (; it != end; ++it) {
4437                         docstring const & current_index = it->shortcut();
4438                         Index const * index = indiceslist.findShortcut(current_index);
4439                         string const x11hexname = X11hexname(index->color());
4440                         // display the new color
4441                         docstring const str = current_index + ' ' + from_ascii(x11hexname);
4442                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
4443                 }
4444         }
4445         // FIXME LFUN
4446         // If we used an LFUN, we would not need these two lines:
4447         BufferView * bv = const_cast<BufferView *>(bufferview());
4448         bv->processUpdateFlags(Update::Force | Update::FitCursor);
4449 }
4450
4451
4452 void GuiDocument::setLanguage() const
4453 {
4454         Language const * const newL = bp_.language;
4455         if (buffer().params().language == newL)
4456                 return;
4457
4458         string const & lang_name = newL->lang();
4459         dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
4460 }
4461
4462
4463 void GuiDocument::saveAsDefault() const
4464 {
4465         dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT, &buffer());
4466 }
4467
4468
4469 bool GuiDocument::providesOSF(QString const & font) const
4470 {
4471         if (fontModule->osFontsCB->isChecked())
4472                 // FIXME: we should check if the fonts really
4473                 // have OSF support. But how?
4474                 return true;
4475         return theLaTeXFonts().getLaTeXFont(
4476                                 qstring_to_ucs4(font)).providesOSF(ot1(),
4477                                                                    completeFontset(),
4478                                                                    noMathFont());
4479 }
4480
4481
4482 bool GuiDocument::providesSC(QString const & font) const
4483 {
4484         if (fontModule->osFontsCB->isChecked())
4485                 return false;
4486         return theLaTeXFonts().getLaTeXFont(
4487                                 qstring_to_ucs4(font)).providesSC(ot1(),
4488                                                                   completeFontset(),
4489                                                                   noMathFont());
4490 }
4491
4492
4493 bool GuiDocument::providesScale(QString const & font) const
4494 {
4495         if (fontModule->osFontsCB->isChecked())
4496                 return true;
4497         return theLaTeXFonts().getLaTeXFont(
4498                                 qstring_to_ucs4(font)).providesScale(ot1(),
4499                                                                      completeFontset(),
4500                                                                      noMathFont());
4501 }
4502
4503
4504 bool GuiDocument::providesNoMath(QString const & font) const
4505 {
4506         if (fontModule->osFontsCB->isChecked())
4507                 return false;
4508         return theLaTeXFonts().getLaTeXFont(
4509                                 qstring_to_ucs4(font)).providesNoMath(ot1(),
4510                                                                       completeFontset());
4511 }
4512
4513
4514 bool GuiDocument::hasMonolithicExpertSet(QString const & font) const
4515 {
4516         if (fontModule->osFontsCB->isChecked())
4517                 return false;
4518         return theLaTeXFonts().getLaTeXFont(
4519                                 qstring_to_ucs4(font)).hasMonolithicExpertSet(ot1(),
4520                                                                               completeFontset(),
4521                                                                               noMathFont());
4522 }
4523
4524
4525 //static
4526 GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod)
4527 {
4528         // FIXME Unicode: docstrings would be better for these parameters but this
4529         // change requires a lot of others
4530         modInfoStruct m;
4531         m.id = mod.getID();
4532         m.name = toqstr(translateIfPossible(from_utf8(mod.getName())));
4533         QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription())));
4534         // Find the first sentence of the description
4535         QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc);
4536         int pos = bf.toNextBoundary();
4537         if (pos > 0)
4538                 desc.truncate(pos);
4539         QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id));
4540         // Tooltip is the desc followed by the module name
4541         m.description = QString("%1<i>%2</i>")
4542                 .arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").arg(desc),
4543                      modulename);
4544         return m;
4545 }
4546
4547
4548 void GuiDocument::loadModuleInfo()
4549 {
4550         moduleNames_.clear();
4551         for (LyXModule const & mod : theModuleList)
4552                 if (mod.category().substr(0, 8) != "Citation")
4553                         moduleNames_.push_back(modInfo(mod));
4554 }
4555
4556
4557 void GuiDocument::updateUnknownBranches()
4558 {
4559         if (!bufferview())
4560                 return;
4561         list<docstring> used_branches;
4562         buffer().getUsedBranches(used_branches);
4563         list<docstring>::const_iterator it = used_branches.begin();
4564         QStringList unknown_branches;
4565         for (; it != used_branches.end() ; ++it) {
4566                 if (!buffer().params().branchlist().find(*it))
4567                         unknown_branches.append(toqstr(*it));
4568         }
4569         branchesModule->setUnknownBranches(unknown_branches);
4570 }
4571
4572
4573 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
4574 {
4575         map<docstring, docstring>::iterator it = changedBranches_.begin();
4576         for (; it != changedBranches_.end() ; ++it) {
4577                 if (it->second == oldname) {
4578                         // branch has already been renamed
4579                         it->second = newname;
4580                         return;
4581                 }
4582         }
4583         // store new name
4584         changedBranches_[oldname] = newname;
4585 }
4586
4587
4588 void GuiDocument::executeBranchRenaming() const
4589 {
4590         map<docstring, docstring>::const_iterator it = changedBranches_.begin();
4591         for (; it != changedBranches_.end() ; ++it) {
4592                 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
4593                 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
4594         }
4595 }
4596
4597
4598 void GuiDocument::allPackagesAuto()
4599 {
4600         allPackages(1);
4601 }
4602
4603
4604 void GuiDocument::allPackagesAlways()
4605 {
4606         allPackages(2);
4607 }
4608
4609
4610 void GuiDocument::allPackagesNot()
4611 {
4612         allPackages(3);
4613 }
4614
4615
4616 void GuiDocument::allPackages(int col)
4617 {
4618         for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
4619                 QRadioButton * rb =
4620                         (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
4621                 rb->setChecked(true);
4622         }
4623 }
4624
4625
4626 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
4627
4628
4629 } // namespace frontend
4630 } // namespace lyx
4631
4632 #include "moc_GuiDocument.cpp"