]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.cpp
The View->Source pane resets the format every time you click into
[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 "GuiApplication.h"
17 #include "GuiBranches.h"
18 #include "GuiIndices.h"
19 #include "GuiSelectionManager.h"
20 #include "LaTeXHighlighter.h"
21 #include "LengthCombo.h"
22 #include "PanelStack.h"
23 #include "Validator.h"
24
25 #include "LayoutFile.h"
26 #include "BranchList.h"
27 #include "buffer_funcs.h"
28 #include "Buffer.h"
29 #include "BufferParams.h"
30 #include "BufferView.h"
31 #include "Color.h"
32 #include "ColorCache.h"
33 #include "Encoding.h"
34 #include "FloatPlacement.h"
35 #include "Format.h"
36 #include "FuncRequest.h"
37 #include "HSpace.h"
38 #include "IndicesList.h"
39 #include "Language.h"
40 #include "LaTeXFeatures.h"
41 #include "Layout.h"
42 #include "LayoutModuleList.h"
43 #include "LyXRC.h"
44 #include "ModuleList.h"
45 #include "OutputParams.h"
46 #include "PDFOptions.h"
47 #include "qt_helpers.h"
48 #include "Spacing.h"
49 #include "TextClass.h"
50
51 #include "insets/InsetListingsParams.h"
52
53 #include "support/debug.h"
54 #include "support/FileName.h"
55 #include "support/filetools.h"
56 #include "support/gettext.h"
57 #include "support/lstrings.h"
58
59 #include "frontends/alert.h"
60
61 #include <QAbstractItemModel>
62 #include <QHeaderView>
63 #include <QColor>
64 #include <QColorDialog>
65 #include <QCloseEvent>
66 #include <QFontDatabase>
67 #include <QScrollBar>
68 #include <QTextCursor>
69
70 #include <sstream>
71 #include <vector>
72
73 #ifdef IN
74 #undef IN
75 #endif
76
77
78 // a style sheet for buttons
79 // this is for example used for the background color setting button
80 static inline QString colorButtonStyleSheet(QColor const & bgColor)
81 {
82         if (bgColor.isValid()) {
83                 QString rc = QLatin1String("background-color:");
84                 rc += bgColor.name();
85                 return rc;
86         }
87         return QString();
88 }
89
90
91 using namespace std;
92 using namespace lyx::support;
93
94
95 namespace {
96
97 char const * const tex_graphics[] =
98 {
99         "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
100         "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
101         "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
102         "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
103         "xetex", "none", ""
104 };
105
106
107 char const * const tex_graphics_gui[] =
108 {
109         N_("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", N_("None"), ""
114 };
115
116
117 char const * const tex_fonts_roman[] =
118 {
119         "default", "cmr", "lmodern", "ae", "times", "palatino",
120         "charter", "newcent", "bookman", "utopia", "beraserif",
121         "ccfonts", "chancery", ""
122 };
123
124
125 char const * tex_fonts_roman_gui[] =
126 {
127         N_("Default"), N_("Computer Modern Roman"), N_("Latin Modern Roman"),
128         N_("AE (Almost European)"), N_("Times Roman"), N_("Palatino"),
129         N_("Bitstream Charter"), N_("New Century Schoolbook"), N_("Bookman"),
130         N_("Utopia"),  N_("Bera Serif"), N_("Concrete Roman"), N_("Zapf Chancery"),
131         ""
132 };
133
134
135 char const * const tex_fonts_sans[] =
136 {
137         "default", "cmss", "lmss", "helvet", "avant", "berasans", "cmbr", ""
138 };
139
140
141 char const * tex_fonts_sans_gui[] =
142 {
143         N_("Default"), N_("Computer Modern Sans"), N_("Latin Modern Sans"),
144         N_("Helvetica"), N_("Avant Garde"), N_("Bera Sans"), N_("CM Bright"), ""
145 };
146
147
148 char const * const tex_fonts_monospaced[] =
149 {
150         "default", "cmtt", "lmtt", "courier", "beramono", "luximono", "cmtl", ""
151 };
152
153
154 char const * tex_fonts_monospaced_gui[] =
155 {
156         N_("Default"), N_("Computer Modern Typewriter"),
157         N_("Latin Modern Typewriter"), N_("Courier"), N_("Bera Mono"),
158         N_("LuxiMono"), N_("CM Typewriter Light"), ""
159 };
160
161
162 char const * backref_opts[] =
163 {
164         "false", "section", "slide", "page", ""
165 };
166
167
168 char const * backref_opts_gui[] =
169 {
170         N_("Off"), N_("Section"), N_("Slide"), N_("Page"), ""
171 };
172
173
174 vector<pair<string, QString> > pagestyles;
175
176
177 } // anonymous namespace
178
179 namespace lyx {
180
181 RGBColor set_backgroundcolor;
182 bool is_backgroundcolor;
183 RGBColor set_fontcolor;
184 bool is_fontcolor;
185 RGBColor set_notefontcolor;
186 RGBColor set_boxbgcolor;
187
188 namespace {
189 // used when sorting the textclass list.
190 class less_textclass_avail_desc
191         : public binary_function<string, string, int>
192 {
193 public:
194         bool operator()(string const & lhs, string const & rhs) const
195         {
196                 // Ordering criteria:
197                 //   1. Availability of text class
198                 //   2. Description (lexicographic)
199                 LayoutFile const & tc1 = LayoutFileList::get()[lhs];
200                 LayoutFile const & tc2 = LayoutFileList::get()[rhs];
201                 int const order = compare_no_case(
202                         translateIfPossible(from_utf8(tc1.description())),
203                         translateIfPossible(from_utf8(tc2.description())));
204                 return (tc1.isTeXClassAvailable() && !tc2.isTeXClassAvailable()) ||
205                         (tc1.isTeXClassAvailable() == tc2.isTeXClassAvailable() && order < 0);
206         }
207 };
208
209 }
210
211 namespace frontend {
212 namespace {
213
214 vector<string> getRequiredList(string const & modName)
215 {
216         LyXModule const * const mod = theModuleList[modName];
217         if (!mod)
218                 return vector<string>(); //empty such thing
219         return mod->getRequiredModules();
220 }
221
222
223 vector<string> getExcludedList(string const & modName)
224 {
225         LyXModule const * const mod = theModuleList[modName];
226         if (!mod)
227                 return vector<string>(); //empty such thing
228         return mod->getExcludedModules();
229 }
230
231
232 docstring getModuleDescription(string const & modName)
233 {
234         LyXModule const * const mod = theModuleList[modName];
235         if (!mod)
236                 return _("Module not found!");
237         // FIXME Unicode
238         return translateIfPossible(from_utf8(mod->getDescription()));
239 }
240
241
242 vector<string> getPackageList(string const & modName)
243 {
244         LyXModule const * const mod = theModuleList[modName];
245         if (!mod)
246                 return vector<string>(); //empty such thing
247         return mod->getPackageList();
248 }
249
250
251 bool isModuleAvailable(string const & modName)
252 {
253         LyXModule const * const mod = theModuleList[modName];
254         if (!mod)
255                 return false;
256         return mod->isAvailable();
257 }
258
259 } // anonymous namespace
260
261
262 /////////////////////////////////////////////////////////////////////
263 //
264 // ModuleSelectionManager
265 //
266 /////////////////////////////////////////////////////////////////////
267
268 /// SelectionManager for use with modules
269 class ModuleSelectionManager : public GuiSelectionManager
270 {
271 public:
272         ///
273         ModuleSelectionManager(
274                 QTreeView * availableLV,
275                 QListView * selectedLV,
276                 QPushButton * addPB,
277                 QPushButton * delPB,
278                 QPushButton * upPB,
279                 QPushButton * downPB,
280                 GuiIdListModel * availableModel,
281                 GuiIdListModel * selectedModel,
282                 GuiDocument const * container)
283         : GuiSelectionManager(availableLV, selectedLV, addPB, delPB,
284                                 upPB, downPB, availableModel, selectedModel), container_(container)
285                 {}
286         ///
287         void updateProvidedModules(LayoutModuleList const & pm)
288                         { provided_modules_ = pm.list(); }
289         ///
290         void updateExcludedModules(LayoutModuleList const & em)
291                         { excluded_modules_ = em.list(); }
292 private:
293         ///
294         virtual void updateAddPB();
295         ///
296         virtual void updateUpPB();
297         ///
298         virtual void updateDownPB();
299         ///
300         virtual void updateDelPB();
301         /// returns availableModel as a GuiIdListModel
302         GuiIdListModel * getAvailableModel()
303         {
304                 return dynamic_cast<GuiIdListModel *>(availableModel);
305         }
306         /// returns selectedModel as a GuiIdListModel
307         GuiIdListModel * getSelectedModel()
308         {
309                 return dynamic_cast<GuiIdListModel *>(selectedModel);
310         }
311         /// keeps a list of the modules the text class provides
312         list<string> provided_modules_;
313         /// similarly...
314         list<string> excluded_modules_;
315         ///
316         GuiDocument const * container_;
317 };
318
319 void ModuleSelectionManager::updateAddPB()
320 {
321         int const arows = availableModel->rowCount();
322         QModelIndexList const avail_sels =
323                         availableLV->selectionModel()->selectedIndexes();
324
325         // disable if there aren't any modules (?), if none of them is chosen
326         // in the dialog, or if the chosen one is already selected for use.
327         if (arows == 0 || avail_sels.isEmpty() || isSelected(avail_sels.first())) {
328                 addPB->setEnabled(false);
329                 return;
330         }
331
332         QModelIndex const & idx = availableLV->selectionModel()->currentIndex();
333         string const modname = getAvailableModel()->getIDString(idx.row());
334
335         bool const enable =
336                 container_->params().moduleCanBeAdded(modname);
337         addPB->setEnabled(enable);
338 }
339
340
341 void ModuleSelectionManager::updateDownPB()
342 {
343         int const srows = selectedModel->rowCount();
344         if (srows == 0) {
345                 downPB->setEnabled(false);
346                 return;
347         }
348         QModelIndex const & curidx = selectedLV->selectionModel()->currentIndex();
349         int const curRow = curidx.row();
350         if (curRow < 0 || curRow >= srows - 1) { // invalid or last item
351                 downPB->setEnabled(false);
352                 return;
353         }
354
355         // determine whether immediately succeding element requires this one
356         string const curmodname = getSelectedModel()->getIDString(curRow);
357         string const nextmodname = getSelectedModel()->getIDString(curRow + 1);
358
359         vector<string> reqs = getRequiredList(nextmodname);
360
361         // if it doesn't require anything....
362         if (reqs.empty()) {
363                 downPB->setEnabled(true);
364                 return;
365         }
366
367         // Enable it if this module isn't required.
368         // FIXME This should perhaps be more flexible and check whether, even
369         // if the next one is required, there is also an earlier one that will do.
370         downPB->setEnabled(
371                         find(reqs.begin(), reqs.end(), curmodname) == reqs.end());
372 }
373
374 void ModuleSelectionManager::updateUpPB()
375 {
376         int const srows = selectedModel->rowCount();
377         if (srows == 0) {
378                 upPB->setEnabled(false);
379                 return;
380         }
381
382         QModelIndex const & curIdx = selectedLV->selectionModel()->currentIndex();
383         int curRow = curIdx.row();
384         if (curRow <= 0 || curRow > srows - 1) { // first item or invalid
385                 upPB->setEnabled(false);
386                 return;
387         }
388         string const curmodname = getSelectedModel()->getIDString(curRow);
389
390         // determine whether immediately preceding element is required by this one
391         vector<string> reqs = getRequiredList(curmodname);
392
393         // if this one doesn't require anything....
394         if (reqs.empty()) {
395                 upPB->setEnabled(true);
396                 return;
397         }
398
399
400         // Enable it if the preceding module isn't required.
401         // NOTE This is less flexible than it might be. We could check whether, even
402         // if the previous one is required, there is an earlier one that would do.
403         string const premod = getSelectedModel()->getIDString(curRow - 1);
404         upPB->setEnabled(find(reqs.begin(), reqs.end(), premod) == reqs.end());
405 }
406
407 void ModuleSelectionManager::updateDelPB()
408 {
409         int const srows = selectedModel->rowCount();
410         if (srows == 0) {
411                 deletePB->setEnabled(false);
412                 return;
413         }
414
415         QModelIndex const & curidx =
416                 selectedLV->selectionModel()->currentIndex();
417         int const curRow = curidx.row();
418         if (curRow < 0 || curRow >= srows) { // invalid index?
419                 deletePB->setEnabled(false);
420                 return;
421         }
422
423         string const curmodname = getSelectedModel()->getIDString(curRow);
424
425         // We're looking here for a reason NOT to enable the button. If we
426         // find one, we disable it and return. If we don't, we'll end up at
427         // the end of the function, and then we enable it.
428         for (int i = curRow + 1; i < srows; ++i) {
429                 string const thisMod = getSelectedModel()->getIDString(i);
430                 vector<string> reqs = getRequiredList(thisMod);
431                 //does this one require us?
432                 if (find(reqs.begin(), reqs.end(), curmodname) == reqs.end())
433                         //no...
434                         continue;
435
436                 // OK, so this module requires us
437                 // is there an EARLIER module that also satisfies the require?
438                 // NOTE We demand that it be earlier to keep the list of modules
439                 // consistent with the rule that a module must be proceeded by a
440                 // required module. There would be more flexible ways to proceed,
441                 // but that would be a lot more complicated, and the logic here is
442                 // already complicated. (That's why I've left the debugging code.)
443                 // lyxerr << "Testing " << thisMod << endl;
444                 bool foundone = false;
445                 for (int j = 0; j < curRow; ++j) {
446                         string const mod = getSelectedModel()->getIDString(j);
447                         // lyxerr << "In loop: Testing " << mod << endl;
448                         // do we satisfy the require?
449                         if (find(reqs.begin(), reqs.end(), mod) != reqs.end()) {
450                                 // lyxerr << mod << " does the trick." << endl;
451                                 foundone = true;
452                                 break;
453                         }
454                 }
455                 // did we find a module to satisfy the require?
456                 if (!foundone) {
457                         // lyxerr << "No matching module found." << endl;
458                         deletePB->setEnabled(false);
459                         return;
460                 }
461         }
462         // lyxerr << "All's well that ends well." << endl;
463         deletePB->setEnabled(true);
464 }
465
466
467 /////////////////////////////////////////////////////////////////////
468 //
469 // PreambleModule
470 //
471 /////////////////////////////////////////////////////////////////////
472
473 PreambleModule::PreambleModule() : current_id_(0)
474 {
475         // This is not a memory leak. The object will be destroyed
476         // with this.
477         (void) new LaTeXHighlighter(preambleTE->document());
478         setFocusProxy(preambleTE);
479         connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
480 }
481
482
483 void PreambleModule::update(BufferParams const & params, BufferId id)
484 {
485         QString preamble = toqstr(params.preamble);
486         // Nothing to do if the params and preamble are unchanged.
487         if (id == current_id_
488                 && preamble == preambleTE->document()->toPlainText())
489                 return;
490
491         QTextCursor cur = preambleTE->textCursor();
492         // Save the coords before switching to the new one.
493         preamble_coords_[current_id_] =
494                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
495
496         // Save the params address for further use.
497         current_id_ = id;
498         preambleTE->document()->setPlainText(preamble);
499         Coords::const_iterator it = preamble_coords_.find(current_id_);
500         if (it == preamble_coords_.end())
501                 // First time we open this one.
502                 preamble_coords_[current_id_] = make_pair(0, 0);
503         else {
504                 // Restore saved coords.
505                 QTextCursor cur = preambleTE->textCursor();
506                 cur.setPosition(it->second.first);
507                 preambleTE->setTextCursor(cur);
508                 preambleTE->verticalScrollBar()->setValue(it->second.second);
509         }
510 }
511
512
513 void PreambleModule::apply(BufferParams & params)
514 {
515         params.preamble = fromqstr(preambleTE->document()->toPlainText());
516 }
517
518
519 void PreambleModule::closeEvent(QCloseEvent * e)
520 {
521         // Save the coords before closing.
522         QTextCursor cur = preambleTE->textCursor();
523         preamble_coords_[current_id_] =
524                 make_pair(cur.position(), preambleTE->verticalScrollBar()->value());
525         e->accept();
526 }
527
528
529 /////////////////////////////////////////////////////////////////////
530 //
531 // LocalLayout
532 //
533 /////////////////////////////////////////////////////////////////////
534
535
536 LocalLayout::LocalLayout() : current_id_(0), is_valid_(false)
537 {
538         connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
539         connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
540         connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
541 }
542
543
544 void LocalLayout::update(BufferParams const & params, BufferId id)
545 {
546         QString layout = toqstr(params.local_layout);
547         // Nothing to do if the params and preamble are unchanged.
548         if (id == current_id_
549                 && layout == locallayoutTE->document()->toPlainText())
550                 return;
551
552         // Save the params address for further use.
553         current_id_ = id;
554         locallayoutTE->document()->setPlainText(layout);
555         validate();
556 }
557
558
559 void LocalLayout::apply(BufferParams & params)
560 {
561         string const layout = fromqstr(locallayoutTE->document()->toPlainText());
562         params.local_layout = layout;
563 }
564
565
566 void LocalLayout::textChanged()
567 {
568         static const QString unknown = qt_("Press button to check validity...");
569
570         is_valid_ = false;
571         validLB->setText(unknown);
572         validatePB->setEnabled(true);
573         convertPB->setEnabled(false);
574         changed();
575 }
576
577
578 void LocalLayout::convert() {
579         string const layout =
580                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
581         string const newlayout = TextClass::convert(layout);
582         LYXERR0(newlayout);
583         if (newlayout.empty()) {
584                 Alert::error(_("Conversion Failed!"),
585                       _("Failed to convert local layout to current format."));
586         } else {
587                 locallayoutTE->setPlainText(toqstr(newlayout));
588         }
589         validate();
590 }
591
592
593 void LocalLayout::convertPressed() {
594         convert();
595         changed();
596 }
597
598
599 void LocalLayout::validate() {
600         static const QString valid = qt_("Layout is valid!");
601         static const QString vtext =
602                 toqstr("<p style=\"font-weight: bold; \">")
603                   + valid + toqstr("</p>");
604         static const QString invalid = qt_("Layout is invalid!");
605         static const QString ivtext =
606                 toqstr("<p style=\"color: #c00000; font-weight: bold; \">")
607                   + invalid + toqstr("</p>");
608
609         string const layout =
610                 fromqstr(locallayoutTE->document()->toPlainText().trimmed());
611         if (layout.empty()) {
612                 is_valid_ = true;
613                 validatePB->setEnabled(false);
614                 validLB->setText("");
615                 convertPB->hide();
616                 convertLB->hide();
617         } else {
618                 TextClass::ReturnValues const ret = TextClass::validate(layout);
619                 is_valid_ = (ret == TextClass::OK) || (ret == TextClass::OK_OLDFORMAT);
620                 validatePB->setEnabled(false);
621                 validLB->setText(is_valid_ ? vtext : ivtext);
622                 if (ret == TextClass::OK_OLDFORMAT) {
623                         convertPB->show();
624                         convertPB->setEnabled(true);
625                         convertLB->setText(qt_("Convert to current format"));
626                         convertLB->show();
627                 } else {
628                         convertPB->hide();
629                         convertLB->hide();
630                 }
631         }
632 }
633
634
635 void LocalLayout::validatePressed() {
636         validate();
637         changed();
638 }
639
640
641 /////////////////////////////////////////////////////////////////////
642 //
643 // DocumentDialog
644 //
645 /////////////////////////////////////////////////////////////////////
646
647
648 GuiDocument::GuiDocument(GuiView & lv)
649         : GuiDialog(lv, "document", qt_("Document Settings"))
650 {
651         setupUi(this);
652
653         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
654         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
655         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
656         connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
657
658         connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
659         connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
660
661         // Manage the restore, ok, apply, restore and cancel/close buttons
662         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
663         bc().setOK(okPB);
664         bc().setApply(applyPB);
665         bc().setCancel(closePB);
666         bc().setRestore(restorePB);
667
668
669         // text layout
670         textLayoutModule = new UiWidget<Ui::TextLayoutUi>;
671         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
672                 this, SLOT(change_adaptor()));
673         connect(textLayoutModule->lspacingCO, SIGNAL(activated(int)),
674                 this, SLOT(setLSpacing(int)));
675         connect(textLayoutModule->lspacingLE, SIGNAL(textChanged(const QString &)),
676                 this, SLOT(change_adaptor()));
677
678         connect(textLayoutModule->indentRB, SIGNAL(clicked()),
679                 this, SLOT(change_adaptor()));
680         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
681                 textLayoutModule->indentCO, SLOT(setEnabled(bool)));
682         connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
683                 this, SLOT(change_adaptor()));
684         connect(textLayoutModule->indentCO, SIGNAL(activated(int)),
685                 this, SLOT(setIndent(int)));
686         connect(textLayoutModule->indentLE, SIGNAL(textChanged(const QString &)),
687                 this, SLOT(change_adaptor()));
688         connect(textLayoutModule->indentLengthCO, SIGNAL(activated(int)),
689                 this, SLOT(change_adaptor()));
690
691         connect(textLayoutModule->skipRB, SIGNAL(clicked()),
692                 this, SLOT(change_adaptor()));
693         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
694                 textLayoutModule->skipCO, SLOT(setEnabled(bool)));
695         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
696                 this, SLOT(change_adaptor()));
697         connect(textLayoutModule->skipCO, SIGNAL(activated(int)),
698                 this, SLOT(setSkip(int)));
699         connect(textLayoutModule->skipLE, SIGNAL(textChanged(const QString &)),
700                 this, SLOT(change_adaptor()));
701         connect(textLayoutModule->skipLengthCO, SIGNAL(activated(int)),
702                 this, SLOT(change_adaptor()));
703
704         connect(textLayoutModule->indentRB, SIGNAL(toggled(bool)),
705                 this, SLOT(enableIndent(bool)));
706         connect(textLayoutModule->skipRB, SIGNAL(toggled(bool)),
707                 this, SLOT(enableSkip(bool)));
708
709         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
710                 this, SLOT(change_adaptor()));
711         connect(textLayoutModule->twoColumnCB, SIGNAL(clicked()),
712                 this, SLOT(setColSep()));
713         connect(textLayoutModule->justCB, SIGNAL(clicked()),
714                 this, SLOT(change_adaptor()));
715
716         textLayoutModule->lspacingLE->setValidator(new QDoubleValidator(
717                 textLayoutModule->lspacingLE));
718         textLayoutModule->indentLE->setValidator(unsignedLengthValidator(
719                 textLayoutModule->indentLE));
720         textLayoutModule->skipLE->setValidator(unsignedGlueLengthValidator(
721                 textLayoutModule->skipLE));
722
723         textLayoutModule->indentCO->addItem(qt_("Default"));
724         textLayoutModule->indentCO->addItem(qt_("Custom"));
725         textLayoutModule->skipCO->addItem(qt_("SmallSkip"));
726         textLayoutModule->skipCO->addItem(qt_("MedSkip"));
727         textLayoutModule->skipCO->addItem(qt_("BigSkip"));
728         textLayoutModule->skipCO->addItem(qt_("Custom"));
729         textLayoutModule->lspacingCO->insertItem(
730                 Spacing::Single, qt_("Single"));
731         textLayoutModule->lspacingCO->insertItem(
732                 Spacing::Onehalf, qt_("OneHalf"));
733         textLayoutModule->lspacingCO->insertItem(
734                 Spacing::Double, qt_("Double"));
735         textLayoutModule->lspacingCO->insertItem(
736                 Spacing::Other, qt_("Custom"));
737         // initialize the length validator
738         bc().addCheckedLineEdit(textLayoutModule->indentLE);
739         bc().addCheckedLineEdit(textLayoutModule->skipLE);
740
741
742         // master/child handling
743         masterChildModule = new UiWidget<Ui::MasterChildUi>;
744
745         connect(masterChildModule->childrenTW, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
746                 this, SLOT(includeonlyClicked(QTreeWidgetItem *, int)));
747         connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
748                 masterChildModule->childrenTW, SLOT(setEnabled(bool)));
749         connect(masterChildModule->includeonlyRB, SIGNAL(toggled(bool)),
750                 masterChildModule->maintainAuxCB, SLOT(setEnabled(bool)));
751         connect(masterChildModule->includeallRB, SIGNAL(clicked()),
752                 this, SLOT(change_adaptor()));
753         connect(masterChildModule->includeonlyRB, SIGNAL(clicked()),
754                 this, SLOT(change_adaptor()));
755         connect(masterChildModule->maintainAuxCB, SIGNAL(clicked()),
756                 this, SLOT(change_adaptor()));
757         masterChildModule->childrenTW->setColumnCount(2);
758         masterChildModule->childrenTW->headerItem()->setText(0, qt_("Child Document"));
759         masterChildModule->childrenTW->headerItem()->setText(1, qt_("Include to Output"));
760         masterChildModule->childrenTW->resizeColumnToContents(1);
761         masterChildModule->childrenTW->resizeColumnToContents(2);
762
763
764         // output
765         outputModule = new UiWidget<Ui::OutputUi>;
766
767         connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
768                 this, SLOT(change_adaptor()));
769         connect(outputModule->mathimgSB, SIGNAL(valueChanged(double)),
770                 this, SLOT(change_adaptor()));
771         connect(outputModule->strictCB, SIGNAL(stateChanged(int)),
772                 this, SLOT(change_adaptor()));
773         connect(outputModule->cssCB, SIGNAL(stateChanged(int)),
774                 this, SLOT(change_adaptor()));
775         connect(outputModule->mathoutCB, SIGNAL(currentIndexChanged(int)),
776                 this, SLOT(change_adaptor()));
777
778         connect(outputModule->outputsyncCB, SIGNAL(clicked()),
779                 this, SLOT(change_adaptor()));
780         connect(outputModule->synccustomCB, SIGNAL(editTextChanged(QString)),
781                 this, SLOT(change_adaptor()));
782         outputModule->synccustomCB->addItem("");
783         outputModule->synccustomCB->addItem("\\synctex=1");
784         outputModule->synccustomCB->addItem("\\synctex=-1");
785         outputModule->synccustomCB->addItem("\\usepackage[active]{srcltx}");
786
787         outputModule->synccustomCB->setValidator(new NoNewLineValidator(
788                 outputModule->synccustomCB));
789
790         // fonts
791         fontModule = new UiWidget<Ui::FontUi>;
792         connect(fontModule->osFontsCB, SIGNAL(clicked()),
793                 this, SLOT(change_adaptor()));
794         connect(fontModule->osFontsCB, SIGNAL(toggled(bool)),
795                 this, SLOT(osFontsChanged(bool)));
796         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
797                 this, SLOT(change_adaptor()));
798         connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
799                 this, SLOT(romanChanged(int)));
800         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
801                 this, SLOT(change_adaptor()));
802         connect(fontModule->fontsSansCO, SIGNAL(activated(int)),
803                 this, SLOT(sansChanged(int)));
804         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
805                 this, SLOT(change_adaptor()));
806         connect(fontModule->fontsTypewriterCO, SIGNAL(activated(int)),
807                 this, SLOT(ttChanged(int)));
808         connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
809                 this, SLOT(change_adaptor()));
810         connect(fontModule->fontencCO, SIGNAL(activated(int)),
811                 this, SLOT(change_adaptor()));
812         connect(fontModule->fontencCO, SIGNAL(activated(int)),
813                 this, SLOT(fontencChanged(int)));
814         connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
815                 this, SLOT(change_adaptor()));
816         connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
817                 this, SLOT(change_adaptor()));
818         connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
819                 this, SLOT(change_adaptor()));
820         connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
821                 this, SLOT(change_adaptor()));
822         connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
823                 this, SLOT(change_adaptor()));
824         connect(fontModule->fontScCB, SIGNAL(clicked()),
825                 this, SLOT(change_adaptor()));
826         connect(fontModule->fontOsfCB, SIGNAL(clicked()),
827                 this, SLOT(change_adaptor()));
828
829         fontModule->fontencLE->setValidator(new NoNewLineValidator(
830                 fontModule->fontencLE));
831         fontModule->cjkFontLE->setValidator(new NoNewLineValidator(
832                 fontModule->cjkFontLE));
833
834         updateFontlist();
835
836         fontModule->fontsizeCO->addItem(qt_("Default"));
837         fontModule->fontsizeCO->addItem(qt_("10"));
838         fontModule->fontsizeCO->addItem(qt_("11"));
839         fontModule->fontsizeCO->addItem(qt_("12"));
840
841         fontModule->fontencCO->addItem(qt_("Default"));
842         fontModule->fontencCO->addItem(qt_("Custom"));
843         fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
844
845         for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
846                 fontModule->fontsDefaultCO->addItem(
847                         qt_(GuiDocument::fontfamilies_gui[n]));
848
849         if (!LaTeXFeatures::isAvailable("fontspec"))
850                 fontModule->osFontsCB->setToolTip(
851                         qt_("Use OpenType and TrueType fonts directly (requires XeTeX or LuaTeX)\n"
852                             "You need to install the package \"fontspec\" to use this feature"));
853
854
855         // page layout
856         pageLayoutModule = new UiWidget<Ui::PageLayoutUi>;
857         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
858                 this, SLOT(papersizeChanged(int)));
859         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
860                 this, SLOT(papersizeChanged(int)));
861         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
862                 this, SLOT(change_adaptor()));
863         connect(pageLayoutModule->papersizeCO, SIGNAL(activated(int)),
864                 this, SLOT(change_adaptor()));
865         connect(pageLayoutModule->paperheightLE, SIGNAL(textChanged(const QString &)),
866                 this, SLOT(change_adaptor()));
867         connect(pageLayoutModule->paperwidthLE, SIGNAL(textChanged(const QString &)),
868                 this, SLOT(change_adaptor()));
869         connect(pageLayoutModule->paperwidthUnitCO, SIGNAL(activated(int)),
870                 this, SLOT(change_adaptor()));
871         connect(pageLayoutModule->paperheightUnitCO, SIGNAL(activated(int)),
872                 this, SLOT(change_adaptor()));
873         connect(pageLayoutModule->portraitRB, SIGNAL(clicked()),
874                 this, SLOT(change_adaptor()));
875         connect(pageLayoutModule->landscapeRB, SIGNAL(clicked()),
876                 this, SLOT(change_adaptor()));
877         connect(pageLayoutModule->facingPagesCB, SIGNAL(clicked()),
878                 this, SLOT(change_adaptor()));
879         connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
880                 this, SLOT(change_adaptor()));
881
882         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
883         pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
884         pageLayoutModule->pagestyleCO->addItem(qt_("plain"));
885         pageLayoutModule->pagestyleCO->addItem(qt_("headings"));
886         pageLayoutModule->pagestyleCO->addItem(qt_("fancy"));
887         bc().addCheckedLineEdit(pageLayoutModule->paperheightLE,
888                 pageLayoutModule->paperheightL);
889         bc().addCheckedLineEdit(pageLayoutModule->paperwidthLE,
890                 pageLayoutModule->paperwidthL);
891
892         QComboBox * cb = pageLayoutModule->papersizeCO;
893         cb->addItem(qt_("Default"));
894         cb->addItem(qt_("Custom"));
895         cb->addItem(qt_("US letter"));
896         cb->addItem(qt_("US legal"));
897         cb->addItem(qt_("US executive"));
898         cb->addItem(qt_("A0"));
899         cb->addItem(qt_("A1"));
900         cb->addItem(qt_("A2"));
901         cb->addItem(qt_("A3"));
902         cb->addItem(qt_("A4"));
903         cb->addItem(qt_("A5"));
904         cb->addItem(qt_("A6"));
905         cb->addItem(qt_("B0"));
906         cb->addItem(qt_("B1"));
907         cb->addItem(qt_("B2"));
908         cb->addItem(qt_("B3"));
909         cb->addItem(qt_("B4"));
910         cb->addItem(qt_("B5"));
911         cb->addItem(qt_("B6"));
912         cb->addItem(qt_("C0"));
913         cb->addItem(qt_("C1"));
914         cb->addItem(qt_("C2"));
915         cb->addItem(qt_("C3"));
916         cb->addItem(qt_("C4"));
917         cb->addItem(qt_("C5"));
918         cb->addItem(qt_("C6"));
919         cb->addItem(qt_("JIS B0"));
920         cb->addItem(qt_("JIS B1"));
921         cb->addItem(qt_("JIS B2"));
922         cb->addItem(qt_("JIS B3"));
923         cb->addItem(qt_("JIS B4"));
924         cb->addItem(qt_("JIS B5"));
925         cb->addItem(qt_("JIS B6"));
926         // remove the %-items from the unit choice
927         pageLayoutModule->paperwidthUnitCO->noPercents();
928         pageLayoutModule->paperheightUnitCO->noPercents();
929         pageLayoutModule->paperheightLE->setValidator(unsignedLengthValidator(
930                 pageLayoutModule->paperheightLE));
931         pageLayoutModule->paperwidthLE->setValidator(unsignedLengthValidator(
932                 pageLayoutModule->paperwidthLE));
933
934
935         // margins
936         marginsModule = new UiWidget<Ui::MarginsUi>;
937         connect(marginsModule->marginCB, SIGNAL(toggled(bool)),
938                 this, SLOT(setCustomMargins(bool)));
939         connect(marginsModule->marginCB, SIGNAL(clicked()),
940                 this, SLOT(change_adaptor()));
941         connect(marginsModule->topLE, SIGNAL(textChanged(QString)),
942                 this, SLOT(change_adaptor()));
943         connect(marginsModule->topUnit, SIGNAL(activated(int)),
944                 this, SLOT(change_adaptor()));
945         connect(marginsModule->bottomLE, SIGNAL(textChanged(QString)),
946                 this, SLOT(change_adaptor()));
947         connect(marginsModule->bottomUnit, SIGNAL(activated(int)),
948                 this, SLOT(change_adaptor()));
949         connect(marginsModule->innerLE, SIGNAL(textChanged(QString)),
950                 this, SLOT(change_adaptor()));
951         connect(marginsModule->innerUnit, SIGNAL(activated(int)),
952                 this, SLOT(change_adaptor()));
953         connect(marginsModule->outerLE, SIGNAL(textChanged(QString)),
954                 this, SLOT(change_adaptor()));
955         connect(marginsModule->outerUnit, SIGNAL(activated(int)),
956                 this, SLOT(change_adaptor()));
957         connect(marginsModule->headheightLE, SIGNAL(textChanged(QString)),
958                 this, SLOT(change_adaptor()));
959         connect(marginsModule->headheightUnit, SIGNAL(activated(int)),
960                 this, SLOT(change_adaptor()));
961         connect(marginsModule->headsepLE, SIGNAL(textChanged(QString)),
962                 this, SLOT(change_adaptor()));
963         connect(marginsModule->headsepUnit, SIGNAL(activated(int)),
964                 this, SLOT(change_adaptor()));
965         connect(marginsModule->footskipLE, SIGNAL(textChanged(QString)),
966                 this, SLOT(change_adaptor()));
967         connect(marginsModule->footskipUnit, SIGNAL(activated(int)),
968                 this, SLOT(change_adaptor()));
969         connect(marginsModule->columnsepLE, SIGNAL(textChanged(QString)),
970                 this, SLOT(change_adaptor()));
971         connect(marginsModule->columnsepUnit, SIGNAL(activated(int)),
972                 this, SLOT(change_adaptor()));
973         marginsModule->topLE->setValidator(unsignedLengthValidator(
974                 marginsModule->topLE));
975         marginsModule->bottomLE->setValidator(unsignedLengthValidator(
976                 marginsModule->bottomLE));
977         marginsModule->innerLE->setValidator(unsignedLengthValidator(
978                 marginsModule->innerLE));
979         marginsModule->outerLE->setValidator(unsignedLengthValidator(
980                 marginsModule->outerLE));
981         marginsModule->headsepLE->setValidator(unsignedLengthValidator(
982                 marginsModule->headsepLE));
983         marginsModule->headheightLE->setValidator(unsignedLengthValidator(
984                 marginsModule->headheightLE));
985         marginsModule->footskipLE->setValidator(unsignedLengthValidator(
986                 marginsModule->footskipLE));
987         marginsModule->columnsepLE->setValidator(unsignedLengthValidator(
988                 marginsModule->columnsepLE));
989
990         bc().addCheckedLineEdit(marginsModule->topLE,
991                 marginsModule->topL);
992         bc().addCheckedLineEdit(marginsModule->bottomLE,
993                 marginsModule->bottomL);
994         bc().addCheckedLineEdit(marginsModule->innerLE,
995                 marginsModule->innerL);
996         bc().addCheckedLineEdit(marginsModule->outerLE,
997                 marginsModule->outerL);
998         bc().addCheckedLineEdit(marginsModule->headsepLE,
999                 marginsModule->headsepL);
1000         bc().addCheckedLineEdit(marginsModule->headheightLE,
1001                 marginsModule->headheightL);
1002         bc().addCheckedLineEdit(marginsModule->footskipLE,
1003                 marginsModule->footskipL);
1004         bc().addCheckedLineEdit(marginsModule->columnsepLE,
1005                 marginsModule->columnsepL);
1006
1007
1008         // language & quote
1009         langModule = new UiWidget<Ui::LanguageUi>;
1010         connect(langModule->languageCO, SIGNAL(activated(int)),
1011                 this, SLOT(change_adaptor()));
1012         connect(langModule->defaultencodingRB, SIGNAL(clicked()),
1013                 this, SLOT(change_adaptor()));
1014         connect(langModule->otherencodingRB, SIGNAL(clicked()),
1015                 this, SLOT(change_adaptor()));
1016         connect(langModule->encodingCO, SIGNAL(activated(int)),
1017                 this, SLOT(change_adaptor()));
1018         connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
1019                 this, SLOT(change_adaptor()));
1020         connect(langModule->languagePackageCO, SIGNAL(activated(int)),
1021                 this, SLOT(change_adaptor()));
1022         connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
1023                 this, SLOT(change_adaptor()));
1024         connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
1025                 this, SLOT(languagePackageChanged(int)));
1026
1027         langModule->languagePackageLE->setValidator(new NoNewLineValidator(
1028                 langModule->languagePackageLE));
1029
1030         QAbstractItemModel * language_model = guiApp->languageModel();
1031         // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
1032         language_model->sort(0);
1033         langModule->languageCO->setModel(language_model);
1034         langModule->languageCO->setModelColumn(0);
1035
1036         // Always put the default encoding in the first position.
1037         langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
1038         QStringList encodinglist;
1039         Encodings::const_iterator it = encodings.begin();
1040         Encodings::const_iterator const end = encodings.end();
1041         for (; it != end; ++it)
1042                 encodinglist.append(qt_(it->guiName()));
1043         encodinglist.sort();
1044         langModule->encodingCO->addItems(encodinglist);
1045
1046         langModule->quoteStyleCO->addItem(qt_("``text''"));
1047         langModule->quoteStyleCO->addItem(qt_("''text''"));
1048         langModule->quoteStyleCO->addItem(qt_(",,text``"));
1049         langModule->quoteStyleCO->addItem(qt_(",,text''"));
1050         langModule->quoteStyleCO->addItem(qt_("<<text>>"));
1051         langModule->quoteStyleCO->addItem(qt_(">>text<<"));
1052
1053         langModule->languagePackageCO->addItem(
1054                 qt_("Default"), toqstr("default"));
1055         langModule->languagePackageCO->addItem(
1056                 qt_("Automatic"), toqstr("auto"));
1057         langModule->languagePackageCO->addItem(
1058                 qt_("Always Babel"), toqstr("babel"));
1059         langModule->languagePackageCO->addItem(
1060                 qt_("Custom"), toqstr("custom"));
1061         langModule->languagePackageCO->addItem(
1062                 qt_("None[[language package]]"), toqstr("none"));
1063
1064
1065         // color
1066         colorModule = new UiWidget<Ui::ColorUi>;
1067         connect(colorModule->fontColorPB, SIGNAL(clicked()),
1068                 this, SLOT(changeFontColor()));
1069         connect(colorModule->delFontColorTB, SIGNAL(clicked()),
1070                 this, SLOT(deleteFontColor()));
1071         connect(colorModule->noteFontColorPB, SIGNAL(clicked()),
1072                 this, SLOT(changeNoteFontColor()));
1073         connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()),
1074                 this, SLOT(deleteNoteFontColor()));
1075         connect(colorModule->backgroundPB, SIGNAL(clicked()),
1076                 this, SLOT(changeBackgroundColor()));
1077         connect(colorModule->delBackgroundTB, SIGNAL(clicked()),
1078                 this, SLOT(deleteBackgroundColor()));
1079         connect(colorModule->boxBackgroundPB, SIGNAL(clicked()),
1080                 this, SLOT(changeBoxBackgroundColor()));
1081         connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()),
1082                 this, SLOT(deleteBoxBackgroundColor()));
1083
1084
1085         // numbering
1086         numberingModule = new UiWidget<Ui::NumberingUi>;
1087         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1088                 this, SLOT(change_adaptor()));
1089         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1090                 this, SLOT(change_adaptor()));
1091         connect(numberingModule->depthSL, SIGNAL(valueChanged(int)),
1092                 this, SLOT(updateNumbering()));
1093         connect(numberingModule->tocSL, SIGNAL(valueChanged(int)),
1094                 this, SLOT(updateNumbering()));
1095         numberingModule->tocTW->setColumnCount(3);
1096         numberingModule->tocTW->headerItem()->setText(0, qt_("Example"));
1097         numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered"));
1098         numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC"));
1099         numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents);
1100
1101
1102         // biblio
1103         biblioModule = new UiWidget<Ui::BiblioUi>;
1104         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1105                 biblioModule->citationStyleL, SLOT(setEnabled(bool)));
1106         connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
1107                 biblioModule->citeStyleCO, SLOT(setEnabled(bool)));
1108         connect(biblioModule->citeDefaultRB, SIGNAL(clicked()),
1109                 this, SLOT(change_adaptor()));
1110         connect(biblioModule->citeNatbibRB, SIGNAL(clicked()),
1111                 this, SLOT(change_adaptor()));
1112         connect(biblioModule->citeStyleCO, SIGNAL(activated(int)),
1113                 this, SLOT(change_adaptor()));
1114         connect(biblioModule->citeJurabibRB, SIGNAL(clicked()),
1115                 this, SLOT(change_adaptor()));
1116         connect(biblioModule->bibtopicCB, SIGNAL(clicked()),
1117                 this, SLOT(change_adaptor()));
1118         connect(biblioModule->bibtexCO, SIGNAL(activated(int)),
1119                 this, SLOT(bibtexChanged(int)));
1120         connect(biblioModule->bibtexOptionsLE, SIGNAL(textChanged(QString)),
1121                 this, SLOT(change_adaptor()));
1122
1123         biblioModule->bibtexOptionsLE->setValidator(new NoNewLineValidator(
1124                 biblioModule->bibtexOptionsLE));
1125
1126         biblioModule->citeStyleCO->addItem(qt_("Author-year"));
1127         biblioModule->citeStyleCO->addItem(qt_("Numerical"));
1128         biblioModule->citeStyleCO->setCurrentIndex(0);
1129
1130         // NOTE: we do not provide "custom" here for security reasons!
1131         biblioModule->bibtexCO->clear();
1132         biblioModule->bibtexCO->addItem(qt_("Default"), QString("default"));
1133         for (set<string>::const_iterator it = lyxrc.bibtex_alternatives.begin();
1134                              it != lyxrc.bibtex_alternatives.end(); ++it) {
1135                 QString const command = toqstr(*it).left(toqstr(*it).indexOf(" "));
1136                 biblioModule->bibtexCO->addItem(command, command);
1137         }
1138
1139
1140         // indices
1141         indicesModule = new GuiIndices;
1142         connect(indicesModule, SIGNAL(changed()),
1143                 this, SLOT(change_adaptor()));
1144
1145
1146         // maths
1147         mathsModule = new UiWidget<Ui::MathsUi>;
1148         connect(mathsModule->amsautoCB, SIGNAL(toggled(bool)),
1149                 mathsModule->amsCB, SLOT(setDisabled(bool)));
1150         connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)),
1151                 mathsModule->esintCB, SLOT(setDisabled(bool)));
1152         connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)),
1153                 mathsModule->mhchemCB, SLOT(setDisabled(bool)));
1154         connect(mathsModule->mathdotsautoCB, SIGNAL(toggled(bool)),
1155                 mathsModule->mathdotsCB, SLOT(setDisabled(bool)));
1156         connect(mathsModule->undertildeautoCB, SIGNAL(toggled(bool)),
1157                 mathsModule->undertildeCB, SLOT(setDisabled(bool)));
1158
1159         connect(mathsModule->amsCB, SIGNAL(clicked()),
1160                 this, SLOT(change_adaptor()));
1161         connect(mathsModule->amsautoCB, SIGNAL(clicked()),
1162                 this, SLOT(change_adaptor()));
1163         connect(mathsModule->esintCB, SIGNAL(clicked()),
1164                 this, SLOT(change_adaptor()));
1165         connect(mathsModule->esintautoCB, SIGNAL(clicked()),
1166                 this, SLOT(change_adaptor()));
1167         connect(mathsModule->mhchemCB, SIGNAL(clicked()),
1168                 this, SLOT(change_adaptor()));
1169         connect(mathsModule->mhchemautoCB, SIGNAL(clicked()),
1170                 this, SLOT(change_adaptor()));
1171         connect(mathsModule->mathdotsCB, SIGNAL(clicked()),
1172                 this, SLOT(change_adaptor()));
1173         connect(mathsModule->mathdotsautoCB, SIGNAL(clicked()),
1174                 this, SLOT(change_adaptor()));
1175         connect(mathsModule->undertildeCB, SIGNAL(clicked()),
1176                 this, SLOT(change_adaptor()));
1177         connect(mathsModule->undertildeautoCB, SIGNAL(clicked()),
1178                 this, SLOT(change_adaptor()));
1179
1180
1181         // latex class
1182         latexModule = new UiWidget<Ui::LaTeXUi>;
1183         connect(latexModule->optionsLE, SIGNAL(textChanged(QString)),
1184                 this, SLOT(change_adaptor()));
1185         connect(latexModule->defaultOptionsCB, SIGNAL(clicked()),
1186                 this, SLOT(change_adaptor()));
1187         connect(latexModule->psdriverCO, SIGNAL(activated(int)),
1188                 this, SLOT(change_adaptor()));
1189         connect(latexModule->classCO, SIGNAL(activated(int)),
1190                 this, SLOT(classChanged()));
1191         connect(latexModule->classCO, SIGNAL(activated(int)),
1192                 this, SLOT(change_adaptor()));
1193         connect(latexModule->layoutPB, SIGNAL(clicked()),
1194                 this, SLOT(browseLayout()));
1195         connect(latexModule->layoutPB, SIGNAL(clicked()),
1196                 this, SLOT(change_adaptor()));
1197         connect(latexModule->childDocGB, SIGNAL(clicked()),
1198                 this, SLOT(change_adaptor()));
1199         connect(latexModule->childDocLE, SIGNAL(textChanged(QString)),
1200                 this, SLOT(change_adaptor()));
1201         connect(latexModule->childDocPB, SIGNAL(clicked()),
1202                 this, SLOT(browseMaster()));
1203         connect(latexModule->suppressDateCB, SIGNAL(clicked()),
1204                 this, SLOT(change_adaptor()));
1205         connect(latexModule->refstyleCB, SIGNAL(clicked()),
1206                 this, SLOT(change_adaptor()));
1207
1208         latexModule->optionsLE->setValidator(new NoNewLineValidator(
1209                 latexModule->optionsLE));
1210         latexModule->childDocLE->setValidator(new NoNewLineValidator(
1211                 latexModule->childDocLE));
1212
1213         // postscript drivers
1214         for (int n = 0; tex_graphics[n][0]; ++n) {
1215                 QString enc = qt_(tex_graphics_gui[n]);
1216                 latexModule->psdriverCO->addItem(enc);
1217         }
1218         // latex classes
1219         latexModule->classCO->setModel(&classes_model_);
1220         LayoutFileList const & bcl = LayoutFileList::get();
1221         vector<LayoutFileIndex> classList = bcl.classList();
1222         sort(classList.begin(), classList.end(), less_textclass_avail_desc());
1223
1224         vector<LayoutFileIndex>::const_iterator cit  = classList.begin();
1225         vector<LayoutFileIndex>::const_iterator cen = classList.end();
1226         for (int i = 0; cit != cen; ++cit, ++i) {
1227                 LayoutFile const & tc = bcl[*cit];
1228                 docstring item = (tc.isTeXClassAvailable()) ?
1229                         from_utf8(tc.description()) :
1230                         bformat(_("Unavailable: %1$s"), from_utf8(tc.description()));
1231                 classes_model_.insertRow(i, toqstr(item), *cit);
1232         }
1233
1234
1235         // branches
1236         branchesModule = new GuiBranches;
1237         connect(branchesModule, SIGNAL(changed()),
1238                 this, SLOT(change_adaptor()));
1239         connect(branchesModule, SIGNAL(renameBranches(docstring const &, docstring const &)),
1240                 this, SLOT(branchesRename(docstring const &, docstring const &)));
1241         updateUnknownBranches();
1242
1243
1244         // preamble
1245         preambleModule = new PreambleModule;
1246         connect(preambleModule, SIGNAL(changed()),
1247                 this, SLOT(change_adaptor()));
1248
1249         localLayout = new LocalLayout;
1250         connect(localLayout, SIGNAL(changed()),
1251                 this, SLOT(change_adaptor()));
1252
1253
1254         // bullets
1255         bulletsModule = new BulletsModule;
1256         connect(bulletsModule, SIGNAL(changed()),
1257                 this, SLOT(change_adaptor()));
1258
1259
1260         // Modules
1261         modulesModule = new UiWidget<Ui::ModulesUi>;
1262         modulesModule->availableLV->header()->setVisible(false);
1263         modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents);
1264         modulesModule->availableLV->header()->setStretchLastSection(false);
1265         selectionManager =
1266                 new ModuleSelectionManager(modulesModule->availableLV,
1267                         modulesModule->selectedLV,
1268                         modulesModule->addPB, modulesModule->deletePB,
1269                         modulesModule->upPB, modulesModule->downPB,
1270                         availableModel(), selectedModel(), this);
1271         connect(selectionManager, SIGNAL(updateHook()),
1272                 this, SLOT(updateModuleInfo()));
1273         connect(selectionManager, SIGNAL(updateHook()),
1274                 this, SLOT(change_adaptor()));
1275         connect(selectionManager, SIGNAL(selectionChanged()),
1276                 this, SLOT(modulesChanged()));
1277
1278
1279         // PDF support
1280         pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
1281         connect(pdfSupportModule->use_hyperrefGB, SIGNAL(toggled(bool)),
1282                 this, SLOT(change_adaptor()));
1283         connect(pdfSupportModule->titleLE, SIGNAL(textChanged(QString)),
1284                 this, SLOT(change_adaptor()));
1285         connect(pdfSupportModule->authorLE, SIGNAL(textChanged(QString)),
1286                 this, SLOT(change_adaptor()));
1287         connect(pdfSupportModule->subjectLE, SIGNAL(textChanged(QString)),
1288                 this, SLOT(change_adaptor()));
1289         connect(pdfSupportModule->keywordsLE, SIGNAL(textChanged(QString)),
1290                 this, SLOT(change_adaptor()));
1291         connect(pdfSupportModule->bookmarksGB, SIGNAL(toggled(bool)),
1292                 this, SLOT(change_adaptor()));
1293         connect(pdfSupportModule->bookmarksnumberedCB, SIGNAL(toggled(bool)),
1294                 this, SLOT(change_adaptor()));
1295         connect(pdfSupportModule->bookmarksopenGB, SIGNAL(toggled(bool)),
1296                 this, SLOT(change_adaptor()));
1297         connect(pdfSupportModule->bookmarksopenlevelSB, SIGNAL(valueChanged(int)),
1298                 this, SLOT(change_adaptor()));
1299         connect(pdfSupportModule->breaklinksCB, SIGNAL(toggled(bool)),
1300                 this, SLOT(change_adaptor()));
1301         connect(pdfSupportModule->pdfborderCB, SIGNAL(toggled(bool)),
1302                 this, SLOT(change_adaptor()));
1303         connect(pdfSupportModule->colorlinksCB, SIGNAL(toggled(bool)),
1304                 this, SLOT(change_adaptor()));
1305         connect(pdfSupportModule->backrefCO, SIGNAL(activated(int)),
1306                 this, SLOT(change_adaptor()));
1307         connect(pdfSupportModule->pdfusetitleCB, SIGNAL(toggled(bool)),
1308                 this, SLOT(change_adaptor()));
1309         connect(pdfSupportModule->fullscreenCB, SIGNAL(toggled(bool)),
1310                 this, SLOT(change_adaptor()));
1311         connect(pdfSupportModule->optionsLE, SIGNAL(textChanged(QString)),
1312                 this, SLOT(change_adaptor()));
1313
1314         pdfSupportModule->titleLE->setValidator(new NoNewLineValidator(
1315                 pdfSupportModule->titleLE));
1316         pdfSupportModule->authorLE->setValidator(new NoNewLineValidator(
1317                 pdfSupportModule->authorLE));
1318         pdfSupportModule->subjectLE->setValidator(new NoNewLineValidator(
1319                 pdfSupportModule->subjectLE));
1320         pdfSupportModule->keywordsLE->setValidator(new NoNewLineValidator(
1321                 pdfSupportModule->keywordsLE));
1322         pdfSupportModule->optionsLE->setValidator(new NoNewLineValidator(
1323                 pdfSupportModule->optionsLE));
1324
1325         for (int i = 0; backref_opts[i][0]; ++i)
1326                 pdfSupportModule->backrefCO->addItem(qt_(backref_opts_gui[i]));
1327
1328
1329         // float
1330         floatModule = new FloatPlacement;
1331         connect(floatModule, SIGNAL(changed()),
1332                 this, SLOT(change_adaptor()));
1333
1334
1335         // listings
1336         listingsModule = new UiWidget<Ui::ListingsSettingsUi>;
1337         connect(listingsModule->listingsED, SIGNAL(textChanged()),
1338                 this, SLOT(change_adaptor()));
1339         connect(listingsModule->bypassCB, SIGNAL(clicked()),
1340                 this, SLOT(change_adaptor()));
1341         connect(listingsModule->bypassCB, SIGNAL(clicked()),
1342                 this, SLOT(setListingsMessage()));
1343         connect(listingsModule->listingsED, SIGNAL(textChanged()),
1344                 this, SLOT(setListingsMessage()));
1345         listingsModule->listingsTB->setPlainText(
1346                 qt_("Input listings parameters below. Enter ? for a list of parameters."));
1347
1348
1349         // add the panels
1350         docPS->addPanel(latexModule, qt_("Document Class"));
1351         docPS->addPanel(masterChildModule, qt_("Child Documents"));
1352         docPS->addPanel(modulesModule, qt_("Modules"));
1353         docPS->addPanel(localLayout, qt_("Local Layout"));
1354         docPS->addPanel(fontModule, qt_("Fonts"));
1355         docPS->addPanel(textLayoutModule, qt_("Text Layout"));
1356         docPS->addPanel(pageLayoutModule, qt_("Page Layout"));
1357         docPS->addPanel(marginsModule, qt_("Page Margins"));
1358         docPS->addPanel(langModule, qt_("Language"));
1359         docPS->addPanel(colorModule, qt_("Colors"));
1360         docPS->addPanel(numberingModule, qt_("Numbering & TOC"));
1361         docPS->addPanel(biblioModule, qt_("Bibliography"));
1362         docPS->addPanel(indicesModule, qt_("Indexes"));
1363         docPS->addPanel(pdfSupportModule, qt_("PDF Properties"));
1364         docPS->addPanel(mathsModule, qt_("Math Options"));
1365         docPS->addPanel(floatModule, qt_("Float Placement"));
1366         docPS->addPanel(listingsModule, qt_("Listings"));
1367         docPS->addPanel(bulletsModule, qt_("Bullets"));
1368         docPS->addPanel(branchesModule, qt_("Branches"));
1369         docPS->addPanel(outputModule, qt_("Output"));
1370         docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
1371         docPS->setCurrentPanel(qt_("Document Class"));
1372 // FIXME: hack to work around resizing bug in Qt >= 4.2
1373 // bug verified with Qt 4.2.{0-3} (JSpitzm)
1374 #if QT_VERSION >= 0x040200
1375         docPS->updateGeometry();
1376 #endif
1377 }
1378
1379
1380 void GuiDocument::saveDefaultClicked()
1381 {
1382         saveDocDefault();
1383 }
1384
1385
1386 void GuiDocument::useDefaultsClicked()
1387 {
1388         useClassDefaults();
1389 }
1390
1391
1392 void GuiDocument::change_adaptor()
1393 {
1394         changed();
1395 }
1396
1397
1398 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
1399 {
1400         if (item == 0)
1401                 return;
1402
1403         string child = fromqstr(item->text(0));
1404         if (child.empty())
1405                 return;
1406
1407         if (std::find(includeonlys_.begin(),
1408                       includeonlys_.end(), child) != includeonlys_.end())
1409                 includeonlys_.remove(child);
1410         else
1411                 includeonlys_.push_back(child);
1412
1413         updateIncludeonlys();
1414         changed();
1415 }
1416
1417
1418 QString GuiDocument::validateListingsParameters()
1419 {
1420         // use a cache here to avoid repeated validation
1421         // of the same parameters
1422         static string param_cache;
1423         static QString msg_cache;
1424
1425         if (listingsModule->bypassCB->isChecked())
1426                 return QString();
1427
1428         string params = fromqstr(listingsModule->listingsED->toPlainText());
1429         if (params != param_cache) {
1430                 param_cache = params;
1431                 msg_cache = toqstr(InsetListingsParams(params).validate());
1432         }
1433         return msg_cache;
1434 }
1435
1436
1437 void GuiDocument::setListingsMessage()
1438 {
1439         static bool isOK = true;
1440         QString msg = validateListingsParameters();
1441         if (msg.isEmpty()) {
1442                 if (isOK)
1443                         return;
1444                 isOK = true;
1445                 // listingsTB->setTextColor("black");
1446                 listingsModule->listingsTB->setPlainText(
1447                         qt_("Input listings parameters below. "
1448                 "Enter ? for a list of parameters."));
1449         } else {
1450                 isOK = false;
1451                 // listingsTB->setTextColor("red");
1452                 listingsModule->listingsTB->setPlainText(msg);
1453         }
1454 }
1455
1456
1457 void GuiDocument::setLSpacing(int item)
1458 {
1459         textLayoutModule->lspacingLE->setEnabled(item == 3);
1460 }
1461
1462
1463 void GuiDocument::setIndent(int item)
1464 {
1465         bool const enable = (item == 1);
1466         textLayoutModule->indentLE->setEnabled(enable);
1467         textLayoutModule->indentLengthCO->setEnabled(enable);
1468         textLayoutModule->skipLE->setEnabled(false);
1469         textLayoutModule->skipLengthCO->setEnabled(false);
1470         isValid();
1471 }
1472
1473
1474 void GuiDocument::enableIndent(bool indent)
1475 {
1476         textLayoutModule->skipLE->setEnabled(!indent);
1477         textLayoutModule->skipLengthCO->setEnabled(!indent);
1478         if (indent)
1479                 setIndent(textLayoutModule->indentCO->currentIndex());
1480 }
1481
1482
1483 void GuiDocument::setSkip(int item)
1484 {
1485         bool const enable = (item == 3);
1486         textLayoutModule->skipLE->setEnabled(enable);
1487         textLayoutModule->skipLengthCO->setEnabled(enable);
1488         isValid();
1489 }
1490
1491
1492 void GuiDocument::enableSkip(bool skip)
1493 {
1494         textLayoutModule->indentLE->setEnabled(!skip);
1495         textLayoutModule->indentLengthCO->setEnabled(!skip);
1496         if (skip)
1497                 setSkip(textLayoutModule->skipCO->currentIndex());
1498 }
1499
1500
1501 void GuiDocument::setMargins()
1502 {
1503         bool const extern_geometry =
1504                 documentClass().provides("geometry");
1505         marginsModule->marginCB->setEnabled(!extern_geometry);
1506         if (extern_geometry) {
1507                 marginsModule->marginCB->setChecked(false);
1508                 setCustomMargins(true);
1509         } else {
1510                 marginsModule->marginCB->setChecked(!bp_.use_geometry);
1511                 setCustomMargins(!bp_.use_geometry);
1512         }
1513 }
1514
1515
1516 void GuiDocument::papersizeChanged(int paper_size)
1517 {
1518         setCustomPapersize(paper_size == 1);
1519 }
1520
1521
1522 void GuiDocument::setCustomPapersize(bool custom)
1523 {
1524         pageLayoutModule->paperwidthL->setEnabled(custom);
1525         pageLayoutModule->paperwidthLE->setEnabled(custom);
1526         pageLayoutModule->paperwidthUnitCO->setEnabled(custom);
1527         pageLayoutModule->paperheightL->setEnabled(custom);
1528         pageLayoutModule->paperheightLE->setEnabled(custom);
1529         pageLayoutModule->paperheightLE->setFocus();
1530         pageLayoutModule->paperheightUnitCO->setEnabled(custom);
1531 }
1532
1533
1534 void GuiDocument::setColSep()
1535 {
1536         setCustomMargins(marginsModule->marginCB->checkState() == Qt::Checked);
1537 }
1538
1539
1540 void GuiDocument::setCustomMargins(bool custom)
1541 {
1542         marginsModule->topL->setEnabled(!custom);
1543         marginsModule->topLE->setEnabled(!custom);
1544         marginsModule->topUnit->setEnabled(!custom);
1545
1546         marginsModule->bottomL->setEnabled(!custom);
1547         marginsModule->bottomLE->setEnabled(!custom);
1548         marginsModule->bottomUnit->setEnabled(!custom);
1549
1550         marginsModule->innerL->setEnabled(!custom);
1551         marginsModule->innerLE->setEnabled(!custom);
1552         marginsModule->innerUnit->setEnabled(!custom);
1553
1554         marginsModule->outerL->setEnabled(!custom);
1555         marginsModule->outerLE->setEnabled(!custom);
1556         marginsModule->outerUnit->setEnabled(!custom);
1557
1558         marginsModule->headheightL->setEnabled(!custom);
1559         marginsModule->headheightLE->setEnabled(!custom);
1560         marginsModule->headheightUnit->setEnabled(!custom);
1561
1562         marginsModule->headsepL->setEnabled(!custom);
1563         marginsModule->headsepLE->setEnabled(!custom);
1564         marginsModule->headsepUnit->setEnabled(!custom);
1565
1566         marginsModule->footskipL->setEnabled(!custom);
1567         marginsModule->footskipLE->setEnabled(!custom);
1568         marginsModule->footskipUnit->setEnabled(!custom);
1569
1570         bool const enableColSep = !custom &&
1571                         textLayoutModule->twoColumnCB->checkState() == Qt::Checked;
1572         marginsModule->columnsepL->setEnabled(enableColSep);
1573         marginsModule->columnsepLE->setEnabled(enableColSep);
1574         marginsModule->columnsepUnit->setEnabled(enableColSep);
1575 }
1576
1577
1578 void GuiDocument::changeBackgroundColor()
1579 {
1580         QColor const & newColor = QColorDialog::getColor(
1581                 rgb2qcolor(set_backgroundcolor), asQWidget());
1582         if (!newColor.isValid())
1583                 return;
1584         // set the button color and text
1585         colorModule->backgroundPB->setStyleSheet(
1586                 colorButtonStyleSheet(newColor));
1587         colorModule->backgroundPB->setText(qt_("&Change..."));
1588         // save color
1589         set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
1590         is_backgroundcolor = true;
1591         changed();
1592 }
1593
1594
1595 void GuiDocument::deleteBackgroundColor()
1596 {
1597         // set the button color back to default by setting an empty StyleSheet
1598         colorModule->backgroundPB->setStyleSheet(QLatin1String(""));
1599         // change button text
1600         colorModule->backgroundPB->setText(qt_("&Default..."));
1601         // save default color (white)
1602         set_backgroundcolor = rgbFromHexName("#ffffff");
1603         is_backgroundcolor = false;
1604         changed();
1605 }
1606
1607
1608 void GuiDocument::changeFontColor()
1609 {
1610         QColor const & newColor = QColorDialog::getColor(
1611                 rgb2qcolor(set_fontcolor), asQWidget());
1612         if (!newColor.isValid())
1613                 return;
1614         // set the button color and text
1615         colorModule->fontColorPB->setStyleSheet(
1616                 colorButtonStyleSheet(newColor));
1617         colorModule->fontColorPB->setText(qt_("&Change..."));
1618         // save color
1619         set_fontcolor = rgbFromHexName(fromqstr(newColor.name()));
1620         is_fontcolor = true;
1621         changed();
1622 }
1623
1624
1625 void GuiDocument::deleteFontColor()
1626 {
1627         // set the button color back to default by setting an empty StyleSheet
1628         colorModule->fontColorPB->setStyleSheet(QLatin1String(""));
1629         // change button text
1630         colorModule->fontColorPB->setText(qt_("&Default..."));
1631         // save default color (black)
1632         set_fontcolor = rgbFromHexName("#000000");
1633         is_fontcolor = false;
1634         changed();
1635 }
1636
1637
1638 void GuiDocument::changeNoteFontColor()
1639 {
1640         QColor const & newColor = QColorDialog::getColor(
1641                 rgb2qcolor(set_notefontcolor), asQWidget());
1642         if (!newColor.isValid())
1643                 return;
1644         // set the button color
1645         colorModule->noteFontColorPB->setStyleSheet(
1646                 colorButtonStyleSheet(newColor));
1647         // save color
1648         set_notefontcolor = rgbFromHexName(fromqstr(newColor.name()));
1649         changed();
1650 }
1651
1652
1653 void GuiDocument::deleteNoteFontColor()
1654 {
1655         // set the button color back to pref
1656         theApp()->getRgbColor(Color_greyedouttext, set_notefontcolor);
1657         colorModule->noteFontColorPB->setStyleSheet(
1658                 colorButtonStyleSheet(rgb2qcolor(set_notefontcolor)));
1659         changed();
1660 }
1661
1662
1663 void GuiDocument::changeBoxBackgroundColor()
1664 {
1665         QColor const & newColor = QColorDialog::getColor(
1666                 rgb2qcolor(set_boxbgcolor), asQWidget());
1667         if (!newColor.isValid())
1668                 return;
1669         // set the button color
1670         colorModule->boxBackgroundPB->setStyleSheet(
1671                 colorButtonStyleSheet(newColor));
1672         // save color
1673         set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name()));
1674         changed();
1675 }
1676
1677
1678 void GuiDocument::deleteBoxBackgroundColor()
1679 {
1680         // set the button color back to pref
1681         theApp()->getRgbColor(Color_shadedbg, set_boxbgcolor);
1682         colorModule->boxBackgroundPB->setStyleSheet(
1683                 colorButtonStyleSheet(rgb2qcolor(set_boxbgcolor)));
1684         changed();
1685 }
1686
1687
1688 void GuiDocument::osFontsChanged(bool nontexfonts)
1689 {
1690         bool const tex_fonts = !nontexfonts;
1691         updateFontlist();
1692         updateDefaultFormat();
1693         langModule->encodingCO->setEnabled(tex_fonts &&
1694                 !langModule->defaultencodingRB->isChecked());
1695         langModule->defaultencodingRB->setEnabled(tex_fonts);
1696         langModule->otherencodingRB->setEnabled(tex_fonts);
1697
1698         fontModule->fontsDefaultCO->setEnabled(tex_fonts);
1699         fontModule->fontsDefaultLA->setEnabled(tex_fonts);
1700         fontModule->cjkFontLE->setEnabled(tex_fonts);
1701         fontModule->cjkFontLA->setEnabled(tex_fonts);
1702         string font;
1703         if (tex_fonts)
1704                 font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
1705         bool scaleable = providesScale(font);
1706         fontModule->scaleSansSB->setEnabled(scaleable);
1707         fontModule->scaleSansLA->setEnabled(scaleable);
1708         if (tex_fonts)
1709                 font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
1710         scaleable = providesScale(font);
1711         fontModule->scaleTypewriterSB->setEnabled(scaleable);
1712         fontModule->scaleTypewriterLA->setEnabled(scaleable);
1713         if (tex_fonts)
1714                 font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
1715         fontModule->fontScCB->setEnabled(providesSC(font));
1716         fontModule->fontOsfCB->setEnabled(providesOSF(font));
1717
1718         fontModule->fontencLA->setEnabled(tex_fonts);
1719         fontModule->fontencCO->setEnabled(tex_fonts);
1720         if (!tex_fonts)
1721                 fontModule->fontencLE->setEnabled(false);
1722         else
1723                 fontencChanged(fontModule->fontencCO->currentIndex());
1724 }
1725
1726
1727 void GuiDocument::updateFontsize(string const & items, string const & sel)
1728 {
1729         fontModule->fontsizeCO->clear();
1730         fontModule->fontsizeCO->addItem(qt_("Default"));
1731
1732         for (int n = 0; !token(items,'|',n).empty(); ++n)
1733                 fontModule->fontsizeCO->
1734                         addItem(toqstr(token(items,'|',n)));
1735
1736         for (int n = 0; n < fontModule->fontsizeCO->count(); ++n) {
1737                 if (fromqstr(fontModule->fontsizeCO->itemText(n)) == sel) {
1738                         fontModule->fontsizeCO->setCurrentIndex(n);
1739                         break;
1740                 }
1741         }
1742 }
1743
1744
1745 void GuiDocument::updateFontlist()
1746 {
1747         fontModule->fontsRomanCO->clear();
1748         fontModule->fontsSansCO->clear();
1749         fontModule->fontsTypewriterCO->clear();
1750
1751         // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
1752         if (fontModule->osFontsCB->isChecked()) {
1753                 fontModule->fontsRomanCO->addItem(qt_("Default"), QString("default"));
1754                 fontModule->fontsSansCO->addItem(qt_("Default"), QString("default"));
1755                 fontModule->fontsTypewriterCO->addItem(qt_("Default"), QString("default"));
1756
1757                 QFontDatabase fontdb;
1758                 QStringList families(fontdb.families());
1759                 for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
1760                         fontModule->fontsRomanCO->addItem(*it, *it);
1761                         fontModule->fontsSansCO->addItem(*it, *it);
1762                         fontModule->fontsTypewriterCO->addItem(*it, *it);
1763                 }
1764                 return;
1765         }
1766
1767         for (int n = 0; tex_fonts_roman[n][0]; ++n) {
1768                 QString font = qt_(tex_fonts_roman_gui[n]);
1769                 if (!isFontAvailable(tex_fonts_roman[n]))
1770                         font += qt_(" (not installed)");
1771                 fontModule->fontsRomanCO->addItem(font, qt_(tex_fonts_roman[n]));
1772         }
1773         for (int n = 0; tex_fonts_sans[n][0]; ++n) {
1774                 QString font = qt_(tex_fonts_sans_gui[n]);
1775                 if (!isFontAvailable(tex_fonts_sans[n]))
1776                         font += qt_(" (not installed)");
1777                 fontModule->fontsSansCO->addItem(font, qt_(tex_fonts_sans[n]));
1778         }
1779         for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
1780                 QString font = qt_(tex_fonts_monospaced_gui[n]);
1781                 if (!isFontAvailable(tex_fonts_monospaced[n]))
1782                         font += qt_(" (not installed)");
1783                 fontModule->fontsTypewriterCO->addItem(font, qt_(tex_fonts_monospaced[n]));
1784         }
1785 }
1786
1787
1788 void GuiDocument::fontencChanged(int item)
1789 {
1790         fontModule->fontencLE->setEnabled(item == 1);
1791 }
1792
1793
1794 void GuiDocument::romanChanged(int item)
1795 {
1796         if (fontModule->osFontsCB->isChecked())
1797                 return;
1798         string const font = tex_fonts_roman[item];
1799         fontModule->fontScCB->setEnabled(providesSC(font));
1800         fontModule->fontOsfCB->setEnabled(providesOSF(font));
1801 }
1802
1803
1804 void GuiDocument::sansChanged(int item)
1805 {
1806         if (fontModule->osFontsCB->isChecked())
1807                 return;
1808         string const font = tex_fonts_sans[item];
1809         bool scaleable = providesScale(font);
1810         fontModule->scaleSansSB->setEnabled(scaleable);
1811         fontModule->scaleSansLA->setEnabled(scaleable);
1812 }
1813
1814
1815 void GuiDocument::ttChanged(int item)
1816 {
1817         if (fontModule->osFontsCB->isChecked())
1818                 return;
1819         string const font = tex_fonts_monospaced[item];
1820         bool scaleable = providesScale(font);
1821         fontModule->scaleTypewriterSB->setEnabled(scaleable);
1822         fontModule->scaleTypewriterLA->setEnabled(scaleable);
1823 }
1824
1825
1826 void GuiDocument::updatePagestyle(string const & items, string const & sel)
1827 {
1828         pagestyles.clear();
1829         pageLayoutModule->pagestyleCO->clear();
1830         pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
1831
1832         for (int n = 0; !token(items, '|', n).empty(); ++n) {
1833                 string style = token(items, '|', n);
1834                 QString style_gui = qt_(style);
1835                 pagestyles.push_back(pair<string, QString>(style, style_gui));
1836                 pageLayoutModule->pagestyleCO->addItem(style_gui);
1837         }
1838
1839         if (sel == "default") {
1840                 pageLayoutModule->pagestyleCO->setCurrentIndex(0);
1841                 return;
1842         }
1843
1844         int nn = 0;
1845
1846         for (size_t i = 0; i < pagestyles.size(); ++i)
1847                 if (pagestyles[i].first == sel)
1848                         nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
1849
1850         if (nn > 0)
1851                 pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
1852 }
1853
1854
1855 void GuiDocument::browseLayout()
1856 {
1857         QString const label1 = qt_("Layouts|#o#O");
1858         QString const dir1 = toqstr(lyxrc.document_path);
1859         QStringList const filter(qt_("LyX Layout (*.layout)"));
1860         QString file = browseRelToParent(QString(), bufferFilePath(),
1861                 qt_("Local layout file"), filter, false,
1862                 label1, dir1);
1863
1864         if (!file.endsWith(".layout"))
1865                 return;
1866
1867         FileName layoutFile = support::makeAbsPath(fromqstr(file),
1868                 fromqstr(bufferFilePath()));
1869
1870         int const ret = Alert::prompt(_("Local layout file"),
1871                 _("The layout file you have selected is a local layout\n"
1872                   "file, not one in the system or user directory. Your\n"
1873                   "document may not work with this layout if you do not\n"
1874                   "keep the layout file in the document directory."),
1875                   1, 1, _("&Set Layout"), _("&Cancel"));
1876         if (ret == 1)
1877                 return;
1878
1879         // load the layout file
1880         LayoutFileList & bcl = LayoutFileList::get();
1881         string classname = layoutFile.onlyFileName();
1882         // this will update an existing layout if that layout has been loaded before.
1883         LayoutFileIndex name = bcl.addLocalLayout(
1884                 classname.substr(0, classname.size() - 7),
1885                 layoutFile.onlyPath().absFileName());
1886
1887         if (name.empty()) {
1888                 Alert::error(_("Error"),
1889                         _("Unable to read local layout file."));
1890                 return;
1891         }
1892
1893         // do not trigger classChanged if there is no change.
1894         if (latexModule->classCO->currentText() == toqstr(name))
1895                 return;
1896
1897         // add to combo box
1898         int idx = latexModule->classCO->findText(toqstr(name));
1899         if (idx == -1) {
1900                 classes_model_.insertRow(0, toqstr(name), name);
1901                 latexModule->classCO->setCurrentIndex(0);
1902         } else
1903                 latexModule->classCO->setCurrentIndex(idx);
1904
1905         classChanged();
1906 }
1907
1908
1909 void GuiDocument::browseMaster()
1910 {
1911         QString const title = qt_("Select master document");
1912         QString const dir1 = toqstr(lyxrc.document_path);
1913         QString const old = latexModule->childDocLE->text();
1914         QString const docpath = toqstr(support::onlyPath(buffer().absFileName()));
1915         QStringList const filter(qt_("LyX Files (*.lyx)"));
1916         QString file = browseRelToSub(old, docpath, title, filter, false,
1917                 qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
1918
1919         if (!file.isEmpty())
1920                 latexModule->childDocLE->setText(file);
1921 }
1922
1923
1924 void GuiDocument::classChanged()
1925 {
1926         int idx = latexModule->classCO->currentIndex();
1927         if (idx < 0)
1928                 return;
1929         string const classname = classes_model_.getIDString(idx);
1930
1931         // check whether the selected modules have changed.
1932         bool modules_changed = false;
1933         unsigned int const srows = selectedModel()->rowCount();
1934         if (srows != bp_.getModules().size())
1935                 modules_changed = true;
1936         else {
1937                 list<string>::const_iterator mit = bp_.getModules().begin();
1938                 list<string>::const_iterator men = bp_.getModules().end();
1939                 for (unsigned int i = 0; i < srows && mit != men; ++i, ++mit)
1940                         if (selectedModel()->getIDString(i) != *mit) {
1941                                 modules_changed = true;
1942                                 break;
1943                         }
1944         }
1945
1946         if (modules_changed || lyxrc.auto_reset_options) {
1947                 if (applyPB->isEnabled()) {
1948                         int const ret = Alert::prompt(_("Unapplied changes"),
1949                                         _("Some changes in the dialog were not yet applied.\n"
1950                                         "If you do not apply now, they will be lost after this action."),
1951                                         1, 1, _("&Apply"), _("&Dismiss"));
1952                         if (ret == 0)
1953                                 applyView();
1954                 }
1955         }
1956
1957         // We load the TextClass as soon as it is selected. This is
1958         // necessary so that other options in the dialog can be updated
1959         // according to the new class. Note, however, that, if you use
1960         // the scroll wheel when sitting on the combo box, we'll load a
1961         // lot of TextClass objects very quickly....
1962         if (!bp_.setBaseClass(classname)) {
1963                 Alert::error(_("Error"), _("Unable to set document class."));
1964                 return;
1965         }
1966         if (lyxrc.auto_reset_options)
1967                 bp_.useClassDefaults();
1968
1969         // With the introduction of modules came a distinction between the base
1970         // class and the document class. The former corresponds to the main layout
1971         // file; the latter is that plus the modules (or the document-specific layout,
1972         // or  whatever else there could be). Our parameters come from the document
1973         // class. So when we set the base class, we also need to recreate the document
1974         // class. Otherwise, we still have the old one.
1975         bp_.makeDocumentClass();
1976         paramsToDialog();
1977 }
1978
1979
1980 void GuiDocument::languagePackageChanged(int i)
1981 {
1982          langModule->languagePackageLE->setEnabled(
1983                 langModule->languagePackageCO->itemData(i).toString() == "custom");
1984 }
1985
1986
1987 void GuiDocument::bibtexChanged(int n)
1988 {
1989         biblioModule->bibtexOptionsLE->setEnabled(
1990                 biblioModule->bibtexCO->itemData(n).toString() != "default");
1991         changed();
1992 }
1993
1994
1995 namespace {
1996         // FIXME unicode
1997         // both of these should take a vector<docstring>
1998
1999         // This is an insanely complicated attempt to make this sort of thing
2000         // work with RTL languages.
2001         docstring formatStrVec(vector<string> const & v, docstring const & s)
2002         {
2003                 //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
2004                 if (v.size() == 0)
2005                         return docstring();
2006                 if (v.size() == 1)
2007                         return translateIfPossible(from_utf8(v[0]));
2008                 if (v.size() == 2) {
2009                         docstring retval = _("%1$s and %2$s");
2010                         retval = subst(retval, _("and"), s);
2011                         return bformat(retval, translateIfPossible(from_utf8(v[0])),
2012                                        translateIfPossible(from_utf8(v[1])));
2013                 }
2014                 // The idea here is to format all but the last two items...
2015                 int const vSize = v.size();
2016                 docstring t2 = _("%1$s, %2$s");
2017                 docstring retval = translateIfPossible(from_utf8(v[0]));
2018                 for (int i = 1; i < vSize - 2; ++i)
2019                         retval = bformat(t2, retval, translateIfPossible(from_utf8(v[i])));
2020                 //...and then to  plug them, and the last two, into this schema
2021                 docstring t = _("%1$s, %2$s, and %3$s");
2022                 t = subst(t, _("and"), s);
2023                 return bformat(t, retval, translateIfPossible(from_utf8(v[vSize - 2])),
2024                                translateIfPossible(from_utf8(v[vSize - 1])));
2025         }
2026
2027         vector<string> idsToNames(vector<string> const & idList)
2028         {
2029                 vector<string> retval;
2030                 vector<string>::const_iterator it  = idList.begin();
2031                 vector<string>::const_iterator end = idList.end();
2032                 for (; it != end; ++it) {
2033                         LyXModule const * const mod = theModuleList[*it];
2034                         if (!mod)
2035                                 retval.push_back(to_utf8(bformat(_("%1$s (unavailable)"),
2036                                                 translateIfPossible(from_utf8(*it)))));
2037                         else
2038                                 retval.push_back(mod->getName());
2039                 }
2040                 return retval;
2041         }
2042 } // end anonymous namespace
2043
2044
2045 void GuiDocument::modulesToParams(BufferParams & bp)
2046 {
2047         // update list of loaded modules
2048         bp.clearLayoutModules();
2049         int const srows = modules_sel_model_.rowCount();
2050         for (int i = 0; i < srows; ++i)
2051                 bp.addLayoutModule(modules_sel_model_.getIDString(i));
2052
2053         // update the list of removed modules
2054         bp.clearRemovedModules();
2055         LayoutModuleList const & reqmods = bp.baseClass()->defaultModules();
2056         list<string>::const_iterator rit = reqmods.begin();
2057         list<string>::const_iterator ren = reqmods.end();
2058
2059         // check each of the default modules
2060         for (; rit != ren; rit++) {
2061                 list<string>::const_iterator mit = bp.getModules().begin();
2062                 list<string>::const_iterator men = bp.getModules().end();
2063                 bool found = false;
2064                 for (; mit != men; mit++) {
2065                         if (*rit == *mit) {
2066                                 found = true;
2067                                 break;
2068                         }
2069                 }
2070                 if (!found) {
2071                         // the module isn't present so must have been removed by the user
2072                         bp.addRemovedModule(*rit);
2073                 }
2074         }
2075 }
2076
2077 void GuiDocument::modulesChanged()
2078 {
2079         modulesToParams(bp_);
2080         bp_.makeDocumentClass();
2081         paramsToDialog();
2082 }
2083
2084
2085 void GuiDocument::updateModuleInfo()
2086 {
2087         selectionManager->update();
2088
2089         //Module description
2090         bool const focus_on_selected = selectionManager->selectedFocused();
2091         QAbstractItemView * lv;
2092         if (focus_on_selected)
2093                 lv = modulesModule->selectedLV;
2094         else
2095                 lv= modulesModule->availableLV;
2096         if (lv->selectionModel()->selectedIndexes().isEmpty()) {
2097                 modulesModule->infoML->document()->clear();
2098                 return;
2099         }
2100         QModelIndex const & idx = lv->selectionModel()->currentIndex();
2101         GuiIdListModel const & id_model =
2102                         focus_on_selected  ? modules_sel_model_ : modules_av_model_;
2103         string const modName = id_model.getIDString(idx.row());
2104         docstring desc = getModuleDescription(modName);
2105
2106         LayoutModuleList const & provmods = bp_.baseClass()->providedModules();
2107         if (std::find(provmods.begin(), provmods.end(), modName) != provmods.end()) {
2108                 if (!desc.empty())
2109                         desc += "\n";
2110                 desc += _("Module provided by document class.");
2111         }
2112
2113         vector<string> pkglist = getPackageList(modName);
2114         docstring pkgdesc = formatStrVec(pkglist, _("and"));
2115         if (!pkgdesc.empty()) {
2116                 if (!desc.empty())
2117                         desc += "\n";
2118                 desc += bformat(_("Package(s) required: %1$s."), pkgdesc);
2119         }
2120
2121         pkglist = getRequiredList(modName);
2122         if (!pkglist.empty()) {
2123                 vector<string> const reqdescs = idsToNames(pkglist);
2124                 pkgdesc = formatStrVec(reqdescs, _("or"));
2125                 if (!desc.empty())
2126                         desc += "\n";
2127                 desc += bformat(_("Modules required: %1$s."), pkgdesc);
2128         }
2129
2130         pkglist = getExcludedList(modName);
2131         if (!pkglist.empty()) {
2132                 vector<string> const reqdescs = idsToNames(pkglist);
2133                 pkgdesc = formatStrVec(reqdescs, _( "and"));
2134                 if (!desc.empty())
2135                         desc += "\n";
2136                 desc += bformat(_("Modules excluded: %1$s."), pkgdesc);
2137         }
2138
2139         if (!isModuleAvailable(modName)) {
2140                 if (!desc.empty())
2141                         desc += "\n";
2142                 desc += _("WARNING: Some required packages are unavailable!");
2143         }
2144
2145         modulesModule->infoML->document()->setPlainText(toqstr(desc));
2146 }
2147
2148
2149 void GuiDocument::updateNumbering()
2150 {
2151         DocumentClass const & tclass = documentClass();
2152
2153         numberingModule->tocTW->setUpdatesEnabled(false);
2154         numberingModule->tocTW->clear();
2155
2156         int const depth = numberingModule->depthSL->value();
2157         int const toc = numberingModule->tocSL->value();
2158         QString const no = qt_("No");
2159         QString const yes = qt_("Yes");
2160         QTreeWidgetItem * item = 0;
2161
2162         DocumentClass::const_iterator lit = tclass.begin();
2163         DocumentClass::const_iterator len = tclass.end();
2164         for (; lit != len; ++lit) {
2165                 int const toclevel = lit->toclevel;
2166                 if (toclevel != Layout::NOT_IN_TOC && lit->labeltype == LABEL_COUNTER) {
2167                         item = new QTreeWidgetItem(numberingModule->tocTW);
2168                         item->setText(0, toqstr(translateIfPossible(lit->name())));
2169                         item->setText(1, (toclevel <= depth) ? yes : no);
2170                         item->setText(2, (toclevel <= toc) ? yes : no);
2171                 }
2172         }
2173
2174         numberingModule->tocTW->setUpdatesEnabled(true);
2175         numberingModule->tocTW->update();
2176 }
2177
2178
2179 void GuiDocument::updateDefaultFormat()
2180 {
2181         if (!bufferview())
2182                 return;
2183         // make a copy in order to consider unapplied changes
2184         BufferParams param_copy = buffer().params();
2185         param_copy.useNonTeXFonts = fontModule->osFontsCB->isChecked();
2186         int const idx = latexModule->classCO->currentIndex();
2187         if (idx >= 0) {
2188                 string const classname = classes_model_.getIDString(idx);
2189                 param_copy.setBaseClass(classname);
2190                 param_copy.makeDocumentClass();
2191         }
2192         outputModule->defaultFormatCO->blockSignals(true);
2193         outputModule->defaultFormatCO->clear();
2194         outputModule->defaultFormatCO->addItem(qt_("Default"),
2195                                 QVariant(QString("default")));
2196         typedef vector<Format const *> Formats;
2197         Formats formats = param_copy.exportableFormats(true);
2198         Formats::const_iterator cit = formats.begin();
2199         Formats::const_iterator end = formats.end();
2200         for (; cit != end; ++cit)
2201                 outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
2202                                 QVariant(toqstr((*cit)->name())));
2203         outputModule->defaultFormatCO->blockSignals(false);
2204 }
2205
2206
2207 bool GuiDocument::isChildIncluded(string const & child)
2208 {
2209         if (includeonlys_.empty())
2210                 return false;
2211         return (std::find(includeonlys_.begin(),
2212                           includeonlys_.end(), child) != includeonlys_.end());
2213 }
2214
2215
2216 void GuiDocument::applyView()
2217 {
2218         // preamble
2219         preambleModule->apply(bp_);
2220         localLayout->apply(bp_);
2221
2222         // date
2223         bp_.suppress_date = latexModule->suppressDateCB->isChecked();
2224         bp_.use_refstyle  = latexModule->refstyleCB->isChecked();
2225
2226         // biblio
2227         bp_.setCiteEngine(ENGINE_BASIC);
2228
2229         if (biblioModule->citeNatbibRB->isChecked()) {
2230                 bool const use_numerical_citations =
2231                         biblioModule->citeStyleCO->currentIndex();
2232                 if (use_numerical_citations)
2233                         bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
2234                 else
2235                         bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
2236
2237         } else if (biblioModule->citeJurabibRB->isChecked())
2238                 bp_.setCiteEngine(ENGINE_JURABIB);
2239
2240         bp_.use_bibtopic =
2241                 biblioModule->bibtopicCB->isChecked();
2242
2243         string const bibtex_command =
2244                 fromqstr(biblioModule->bibtexCO->itemData(
2245                         biblioModule->bibtexCO->currentIndex()).toString());
2246         string const bibtex_options =
2247                 fromqstr(biblioModule->bibtexOptionsLE->text());
2248         if (bibtex_command == "default" || bibtex_options.empty())
2249                 bp_.bibtex_command = bibtex_command;
2250         else
2251                 bp_.bibtex_command = bibtex_command + " " + bibtex_options;
2252
2253         buffer().removeBiblioTempFiles();
2254
2255         // Indices
2256         indicesModule->apply(bp_);
2257
2258         // language & quotes
2259         if (langModule->defaultencodingRB->isChecked()) {
2260                 bp_.inputenc = "auto";
2261         } else {
2262                 int i = langModule->encodingCO->currentIndex();
2263                 if (i == 0)
2264                         bp_.inputenc = "default";
2265                 else {
2266                         QString const enc_gui =
2267                                 langModule->encodingCO->currentText();
2268                         Encodings::const_iterator it = encodings.begin();
2269                         Encodings::const_iterator const end = encodings.end();
2270                         bool found = false;
2271                         for (; it != end; ++it) {
2272                                 if (qt_(it->guiName()) == enc_gui) {
2273                                         bp_.inputenc = it->latexName();
2274                                         found = true;
2275                                         break;
2276                                 }
2277                         }
2278                         if (!found) {
2279                                 // should not happen
2280                                 lyxerr << "GuiDocument::apply: Unknown encoding! Resetting to default" << endl;
2281                                 bp_.inputenc = "default";
2282                         }
2283                 }
2284         }
2285
2286         InsetQuotes::QuoteLanguage lga = InsetQuotes::EnglishQuotes;
2287         switch (langModule->quoteStyleCO->currentIndex()) {
2288         case 0:
2289                 lga = InsetQuotes::EnglishQuotes;
2290                 break;
2291         case 1:
2292                 lga = InsetQuotes::SwedishQuotes;
2293                 break;
2294         case 2:
2295                 lga = InsetQuotes::GermanQuotes;
2296                 break;
2297         case 3:
2298                 lga = InsetQuotes::PolishQuotes;
2299                 break;
2300         case 4:
2301                 lga = InsetQuotes::FrenchQuotes;
2302                 break;
2303         case 5:
2304                 lga = InsetQuotes::DanishQuotes;
2305                 break;
2306         }
2307         bp_.quotes_language = lga;
2308
2309         QString const lang = langModule->languageCO->itemData(
2310                 langModule->languageCO->currentIndex()).toString();
2311         bp_.language = lyx::languages.getLanguage(fromqstr(lang));
2312
2313         QString const pack = langModule->languagePackageCO->itemData(
2314                 langModule->languagePackageCO->currentIndex()).toString();
2315         if (pack == "custom")
2316                 bp_.lang_package =
2317                         fromqstr(langModule->languagePackageLE->text());
2318         else
2319                 bp_.lang_package = fromqstr(pack);
2320
2321         //color
2322         bp_.backgroundcolor = set_backgroundcolor;
2323         bp_.isbackgroundcolor = is_backgroundcolor;
2324         bp_.fontcolor = set_fontcolor;
2325         bp_.isfontcolor = is_fontcolor;
2326         bp_.notefontcolor = set_notefontcolor;
2327         bp_.boxbgcolor = set_boxbgcolor;
2328
2329         // numbering
2330         if (bp_.documentClass().hasTocLevels()) {
2331                 bp_.tocdepth = numberingModule->tocSL->value();
2332                 bp_.secnumdepth = numberingModule->depthSL->value();
2333         }
2334
2335         // bullets
2336         bp_.user_defined_bullet(0) = bulletsModule->bullet(0);
2337         bp_.user_defined_bullet(1) = bulletsModule->bullet(1);
2338         bp_.user_defined_bullet(2) = bulletsModule->bullet(2);
2339         bp_.user_defined_bullet(3) = bulletsModule->bullet(3);
2340
2341         // packages
2342         bp_.graphics_driver =
2343                 tex_graphics[latexModule->psdriverCO->currentIndex()];
2344
2345         // text layout
2346         int idx = latexModule->classCO->currentIndex();
2347         if (idx >= 0) {
2348                 string const classname = classes_model_.getIDString(idx);
2349                 bp_.setBaseClass(classname);
2350         }
2351
2352         // Modules
2353         modulesToParams(bp_);
2354
2355         // Math
2356         if (mathsModule->amsautoCB->isChecked())
2357                 bp_.use_amsmath = BufferParams::package_auto;
2358         else {
2359                 if (mathsModule->amsCB->isChecked())
2360                         bp_.use_amsmath = BufferParams::package_on;
2361                 else
2362                         bp_.use_amsmath = BufferParams::package_off;
2363         }
2364         if (mathsModule->esintautoCB->isChecked())
2365                 bp_.use_esint = BufferParams::package_auto;
2366         else {
2367                 if (mathsModule->esintCB->isChecked())
2368                         bp_.use_esint = BufferParams::package_on;
2369                 else
2370                         bp_.use_esint = BufferParams::package_off;
2371         }
2372         if (mathsModule->mhchemautoCB->isChecked())
2373                 bp_.use_mhchem = BufferParams::package_auto;
2374         else {
2375                 if (mathsModule->mhchemCB->isChecked())
2376                         bp_.use_mhchem = BufferParams::package_on;
2377                 else
2378                         bp_.use_mhchem = BufferParams::package_off;
2379         }
2380         if (mathsModule->mathdotsautoCB->isChecked())
2381                 bp_.use_mathdots = BufferParams::package_auto;
2382         else {
2383                 if (mathsModule->mathdotsCB->isChecked())
2384                         bp_.use_mathdots = BufferParams::package_on;
2385                 else
2386                         bp_.use_mathdots = BufferParams::package_off;
2387         }
2388         if (mathsModule->undertildeautoCB->isChecked())
2389                 bp_.use_undertilde = BufferParams::package_auto;
2390         else {
2391                 if (mathsModule->undertildeCB->isChecked())
2392                         bp_.use_undertilde = BufferParams::package_on;
2393                 else
2394                         bp_.use_undertilde = BufferParams::package_off;
2395         }
2396
2397         // Page Layout
2398         if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
2399                 bp_.pagestyle = "default";
2400         else {
2401                 QString style_gui = pageLayoutModule->pagestyleCO->currentText();
2402                 for (size_t i = 0; i != pagestyles.size(); ++i)
2403                         if (pagestyles[i].second == style_gui)
2404                                 bp_.pagestyle = pagestyles[i].first;
2405         }
2406
2407         // Text Layout
2408         switch (textLayoutModule->lspacingCO->currentIndex()) {
2409         case 0:
2410                 bp_.spacing().set(Spacing::Single);
2411                 break;
2412         case 1:
2413                 bp_.spacing().set(Spacing::Onehalf);
2414                 break;
2415         case 2:
2416                 bp_.spacing().set(Spacing::Double);
2417                 break;
2418         case 3: {
2419                 string s = widgetToDoubleStr(textLayoutModule->lspacingLE);
2420                 if (s.empty())
2421                         bp_.spacing().set(Spacing::Single);
2422                 else
2423                         bp_.spacing().set(Spacing::Other, s);
2424                 break;
2425                 }
2426         }
2427
2428         if (textLayoutModule->twoColumnCB->isChecked())
2429                 bp_.columns = 2;
2430         else
2431                 bp_.columns = 1;
2432
2433         bp_.justification = textLayoutModule->justCB->isChecked();
2434
2435         if (textLayoutModule->indentRB->isChecked()) {
2436                 // if paragraphs are separated by an indentation
2437                 bp_.paragraph_separation = BufferParams::ParagraphIndentSeparation;
2438                 switch (textLayoutModule->indentCO->currentIndex()) {
2439                 case 0:
2440                         bp_.setIndentation(HSpace(HSpace::DEFAULT));
2441                         break;
2442                 case 1: {
2443                         HSpace indent = HSpace(
2444                                 widgetsToLength(textLayoutModule->indentLE,
2445                                 textLayoutModule->indentLengthCO)
2446                                 );
2447                         bp_.setIndentation(indent);
2448                         break;
2449                         }
2450                 default:
2451                         // this should never happen
2452                         bp_.setIndentation(HSpace(HSpace::DEFAULT));
2453                         break;
2454                 }
2455         } else {
2456                 // if paragraphs are separated by a skip
2457                 bp_.paragraph_separation = BufferParams::ParagraphSkipSeparation;
2458                 switch (textLayoutModule->skipCO->currentIndex()) {
2459                 case 0:
2460                         bp_.setDefSkip(VSpace(VSpace::SMALLSKIP));
2461                         break;
2462                 case 1:
2463                         bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2464                         break;
2465                 case 2:
2466                         bp_.setDefSkip(VSpace(VSpace::BIGSKIP));
2467                         break;
2468                 case 3:
2469                         {
2470                         VSpace vs = VSpace(
2471                                 widgetsToLength(textLayoutModule->skipLE,
2472                                 textLayoutModule->skipLengthCO)
2473                                 );
2474                         bp_.setDefSkip(vs);
2475                         break;
2476                         }
2477                 default:
2478                         // this should never happen
2479                         bp_.setDefSkip(VSpace(VSpace::MEDSKIP));
2480                         break;
2481                 }
2482         }
2483
2484         bp_.options =
2485                 fromqstr(latexModule->optionsLE->text());
2486
2487         bp_.use_default_options =
2488                 latexModule->defaultOptionsCB->isChecked();
2489
2490         if (latexModule->childDocGB->isChecked())
2491                 bp_.master =
2492                         fromqstr(latexModule->childDocLE->text());
2493         else
2494                 bp_.master = string();
2495
2496         // Master/Child
2497         bp_.clearIncludedChildren();
2498         if (masterChildModule->includeonlyRB->isChecked()) {
2499                 list<string>::const_iterator it = includeonlys_.begin();
2500                 for (; it != includeonlys_.end() ; ++it) {
2501                         bp_.addIncludedChildren(*it);
2502                 }
2503         }
2504         bp_.maintain_unincluded_children =
2505                 masterChildModule->maintainAuxCB->isChecked();
2506
2507         // Float Placement
2508         bp_.float_placement = floatModule->get();
2509
2510         // Listings
2511         // text should have passed validation
2512         bp_.listings_params =
2513                 InsetListingsParams(fromqstr(listingsModule->listingsED->toPlainText())).params();
2514
2515         // output
2516         bp_.default_output_format = fromqstr(outputModule->defaultFormatCO->itemData(
2517                 outputModule->defaultFormatCO->currentIndex()).toString());
2518
2519         bool const nontexfonts = fontModule->osFontsCB->isChecked();
2520         bp_.useNonTeXFonts = nontexfonts;
2521
2522         bp_.output_sync = outputModule->outputsyncCB->isChecked();
2523         
2524         bp_.output_sync_macro = fromqstr(outputModule->synccustomCB->currentText());
2525
2526         int mathfmt = outputModule->mathoutCB->currentIndex();
2527         if (mathfmt == -1)
2528                 mathfmt = 0;
2529         BufferParams::MathOutput const mo =
2530                 static_cast<BufferParams::MathOutput>(mathfmt);
2531         bp_.html_math_output = mo;
2532         bp_.html_be_strict = outputModule->strictCB->isChecked();
2533         bp_.html_css_as_file = outputModule->cssCB->isChecked();
2534         bp_.html_math_img_scale = outputModule->mathimgSB->value();
2535
2536         // fonts
2537         bp_.fonts_roman =
2538                 fromqstr(fontModule->fontsRomanCO->
2539                         itemData(fontModule->fontsRomanCO->currentIndex()).toString());
2540
2541         bp_.fonts_sans =
2542                 fromqstr(fontModule->fontsSansCO->
2543                         itemData(fontModule->fontsSansCO->currentIndex()).toString());
2544
2545         bp_.fonts_typewriter =
2546                 fromqstr(fontModule->fontsTypewriterCO->
2547                         itemData(fontModule->fontsTypewriterCO->currentIndex()).toString());
2548
2549         if (fontModule->fontencCO->currentIndex() == 0)
2550                 bp_.fontenc = "global";
2551         else if (fontModule->fontencCO->currentIndex() == 1)
2552                 bp_.fontenc = fromqstr(fontModule->fontencLE->text());
2553         else if (fontModule->fontencCO->currentIndex() == 2)
2554                 bp_.fontenc = "default";
2555
2556         bp_.fonts_cjk =
2557                 fromqstr(fontModule->cjkFontLE->text());
2558
2559         bp_.fonts_sans_scale = fontModule->scaleSansSB->value();
2560
2561         bp_.fonts_typewriter_scale = fontModule->scaleTypewriterSB->value();
2562
2563         bp_.fonts_expert_sc = fontModule->fontScCB->isChecked();
2564
2565         bp_.fonts_old_figures = fontModule->fontOsfCB->isChecked();
2566
2567         if (nontexfonts)
2568                 bp_.fonts_default_family = "default";
2569         else
2570                 bp_.fonts_default_family = GuiDocument::fontfamilies[
2571                         fontModule->fontsDefaultCO->currentIndex()];
2572
2573         if (fontModule->fontsizeCO->currentIndex() == 0)
2574                 bp_.fontsize = "default";
2575         else
2576                 bp_.fontsize =
2577                         fromqstr(fontModule->fontsizeCO->currentText());
2578
2579         // paper
2580         bp_.papersize = PAPER_SIZE(
2581                 pageLayoutModule->papersizeCO->currentIndex());
2582
2583         bp_.paperwidth = widgetsToLength(pageLayoutModule->paperwidthLE,
2584                 pageLayoutModule->paperwidthUnitCO);
2585
2586         bp_.paperheight = widgetsToLength(pageLayoutModule->paperheightLE,
2587                 pageLayoutModule->paperheightUnitCO);
2588
2589         if (pageLayoutModule->facingPagesCB->isChecked())
2590                 bp_.sides = TwoSides;
2591         else
2592                 bp_.sides = OneSide;
2593
2594         if (pageLayoutModule->landscapeRB->isChecked())
2595                 bp_.orientation = ORIENTATION_LANDSCAPE;
2596         else
2597                 bp_.orientation = ORIENTATION_PORTRAIT;
2598
2599         // margins
2600         bp_.use_geometry = !marginsModule->marginCB->isChecked();
2601
2602         Ui::MarginsUi const * m = marginsModule;
2603
2604         bp_.leftmargin = widgetsToLength(m->innerLE, m->innerUnit);
2605         bp_.topmargin = widgetsToLength(m->topLE, m->topUnit);
2606         bp_.rightmargin = widgetsToLength(m->outerLE, m->outerUnit);
2607         bp_.bottommargin = widgetsToLength(m->bottomLE, m->bottomUnit);
2608         bp_.headheight = widgetsToLength(m->headheightLE, m->headheightUnit);
2609         bp_.headsep = widgetsToLength(m->headsepLE, m->headsepUnit);
2610         bp_.footskip = widgetsToLength(m->footskipLE, m->footskipUnit);
2611         bp_.columnsep = widgetsToLength(m->columnsepLE, m->columnsepUnit);
2612
2613         // branches
2614         branchesModule->apply(bp_);
2615
2616         // PDF support
2617         PDFOptions & pdf = bp_.pdfoptions();
2618         pdf.use_hyperref = pdfSupportModule->use_hyperrefGB->isChecked();
2619         pdf.title = fromqstr(pdfSupportModule->titleLE->text());
2620         pdf.author = fromqstr(pdfSupportModule->authorLE->text());
2621         pdf.subject = fromqstr(pdfSupportModule->subjectLE->text());
2622         pdf.keywords = fromqstr(pdfSupportModule->keywordsLE->text());
2623
2624         pdf.bookmarks = pdfSupportModule->bookmarksGB->isChecked();
2625         pdf.bookmarksnumbered = pdfSupportModule->bookmarksnumberedCB->isChecked();
2626         pdf.bookmarksopen = pdfSupportModule->bookmarksopenGB->isChecked();
2627         pdf.bookmarksopenlevel = pdfSupportModule->bookmarksopenlevelSB->value();
2628
2629         pdf.breaklinks = pdfSupportModule->breaklinksCB->isChecked();
2630         pdf.pdfborder = pdfSupportModule->pdfborderCB->isChecked();
2631         pdf.pdfusetitle = pdfSupportModule->pdfusetitleCB->isChecked();
2632         pdf.colorlinks = pdfSupportModule->colorlinksCB->isChecked();
2633         pdf.backref =
2634                 backref_opts[pdfSupportModule->backrefCO->currentIndex()];
2635         if (pdfSupportModule->fullscreenCB->isChecked())
2636                 pdf.pagemode = pdf.pagemode_fullscreen;
2637         else
2638                 pdf.pagemode.clear();
2639         pdf.quoted_options = pdf.quoted_options_check(
2640                                 fromqstr(pdfSupportModule->optionsLE->text()));
2641 }
2642
2643
2644 void GuiDocument::paramsToDialog()
2645 {
2646         // set the default unit
2647         Length::UNIT const default_unit = Length::defaultUnit();
2648
2649         // preamble
2650         preambleModule->update(bp_, id());
2651         localLayout->update(bp_, id());
2652
2653         // date
2654         latexModule->suppressDateCB->setChecked(bp_.suppress_date);
2655         latexModule->refstyleCB->setChecked(bp_.use_refstyle);
2656
2657         // biblio
2658         biblioModule->citeDefaultRB->setChecked(
2659                 bp_.citeEngine() == ENGINE_BASIC);
2660
2661         biblioModule->citeNatbibRB->setChecked(
2662                 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
2663                 bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
2664
2665         biblioModule->citeStyleCO->setCurrentIndex(
2666                 bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
2667
2668         biblioModule->citeJurabibRB->setChecked(
2669                 bp_.citeEngine() == ENGINE_JURABIB);
2670
2671         biblioModule->bibtopicCB->setChecked(
2672                 bp_.use_bibtopic);
2673
2674         string command;
2675         string options =
2676                 split(bp_.bibtex_command, command, ' ');
2677
2678         int const bpos = biblioModule->bibtexCO->findData(toqstr(command));
2679         if (bpos != -1) {
2680                 biblioModule->bibtexCO->setCurrentIndex(bpos);
2681                 biblioModule->bibtexOptionsLE->setText(toqstr(options).trimmed());
2682         } else {
2683                 // We reset to default if we do not know the specified compiler
2684                 // This is for security reasons
2685                 biblioModule->bibtexCO->setCurrentIndex(
2686                         biblioModule->bibtexCO->findData(toqstr("default")));
2687                 biblioModule->bibtexOptionsLE->clear();
2688         }
2689         biblioModule->bibtexOptionsLE->setEnabled(
2690                 biblioModule->bibtexCO->currentIndex() != 0);
2691
2692         // indices
2693         indicesModule->update(bp_);
2694
2695         // language & quotes
2696         int const pos = langModule->languageCO->findData(toqstr(
2697                 bp_.language->lang()));
2698         langModule->languageCO->setCurrentIndex(pos);
2699
2700         langModule->quoteStyleCO->setCurrentIndex(
2701                 bp_.quotes_language);
2702
2703         bool default_enc = true;
2704         if (bp_.inputenc != "auto") {
2705                 default_enc = false;
2706                 if (bp_.inputenc == "default") {
2707                         langModule->encodingCO->setCurrentIndex(0);
2708                 } else {
2709                         string enc_gui;
2710                         Encodings::const_iterator it = encodings.begin();
2711                         Encodings::const_iterator const end = encodings.end();
2712                         for (; it != end; ++it) {
2713                                 if (it->latexName() == bp_.inputenc) {
2714                                         enc_gui = it->guiName();
2715                                         break;
2716                                 }
2717                         }
2718                         int const i = langModule->encodingCO->findText(
2719                                         qt_(enc_gui));
2720                         if (i >= 0)
2721                                 langModule->encodingCO->setCurrentIndex(i);
2722                         else
2723                                 // unknown encoding. Set to default.
2724                                 default_enc = true;
2725                 }
2726         }
2727         langModule->defaultencodingRB->setChecked(default_enc);
2728         langModule->otherencodingRB->setChecked(!default_enc);
2729
2730         int const p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
2731         if (p == -1) {
2732                 langModule->languagePackageCO->setCurrentIndex(
2733                           langModule->languagePackageCO->findData("custom"));
2734                 langModule->languagePackageLE->setText(toqstr(bp_.lang_package));
2735         } else {
2736                 langModule->languagePackageCO->setCurrentIndex(p);
2737                 langModule->languagePackageLE->clear();
2738         }
2739
2740         //color
2741         if (bp_.isfontcolor) {
2742                 colorModule->fontColorPB->setStyleSheet(
2743                         colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor)));
2744         }
2745         set_fontcolor = bp_.fontcolor;
2746         is_fontcolor = bp_.isfontcolor;
2747
2748         colorModule->noteFontColorPB->setStyleSheet(
2749                 colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor)));
2750         set_notefontcolor = bp_.notefontcolor;
2751
2752         if (bp_.isbackgroundcolor) {
2753                 colorModule->backgroundPB->setStyleSheet(
2754                         colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
2755         }
2756         set_backgroundcolor = bp_.backgroundcolor;
2757         is_backgroundcolor = bp_.isbackgroundcolor;
2758
2759         colorModule->boxBackgroundPB->setStyleSheet(
2760                 colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor)));
2761         set_boxbgcolor = bp_.boxbgcolor;
2762
2763         // numbering
2764         int const min_toclevel = documentClass().min_toclevel();
2765         int const max_toclevel = documentClass().max_toclevel();
2766         if (documentClass().hasTocLevels()) {
2767                 numberingModule->setEnabled(true);
2768                 numberingModule->depthSL->setMinimum(min_toclevel - 1);
2769                 numberingModule->depthSL->setMaximum(max_toclevel);
2770                 numberingModule->depthSL->setValue(bp_.secnumdepth);
2771                 numberingModule->tocSL->setMaximum(min_toclevel - 1);
2772                 numberingModule->tocSL->setMaximum(max_toclevel);
2773                 numberingModule->tocSL->setValue(bp_.tocdepth);
2774                 updateNumbering();
2775         } else {
2776                 numberingModule->setEnabled(false);
2777                 numberingModule->tocTW->clear();
2778         }
2779
2780         // bullets
2781         bulletsModule->setBullet(0, bp_.user_defined_bullet(0));
2782         bulletsModule->setBullet(1, bp_.user_defined_bullet(1));
2783         bulletsModule->setBullet(2, bp_.user_defined_bullet(2));
2784         bulletsModule->setBullet(3, bp_.user_defined_bullet(3));
2785         bulletsModule->init();
2786
2787         // packages
2788         int nitem = findToken(tex_graphics, bp_.graphics_driver);
2789         if (nitem >= 0)
2790                 latexModule->psdriverCO->setCurrentIndex(nitem);
2791         updateModuleInfo();
2792
2793         mathsModule->amsCB->setChecked(
2794                 bp_.use_amsmath == BufferParams::package_on);
2795         mathsModule->amsautoCB->setChecked(
2796                 bp_.use_amsmath == BufferParams::package_auto);
2797
2798         mathsModule->esintCB->setChecked(
2799                 bp_.use_esint == BufferParams::package_on);
2800         mathsModule->esintautoCB->setChecked(
2801                 bp_.use_esint == BufferParams::package_auto);
2802
2803         mathsModule->mhchemCB->setChecked(
2804                 bp_.use_mhchem == BufferParams::package_on);
2805         mathsModule->mhchemautoCB->setChecked(
2806                 bp_.use_mhchem == BufferParams::package_auto);
2807
2808         mathsModule->mathdotsCB->setChecked(
2809                 bp_.use_mathdots == BufferParams::package_on);
2810         mathsModule->mathdotsautoCB->setChecked(
2811                 bp_.use_mathdots == BufferParams::package_auto);
2812
2813         mathsModule->undertildeCB->setChecked(
2814                 bp_.use_undertilde == BufferParams::package_on);
2815         mathsModule->undertildeautoCB->setChecked(
2816                 bp_.use_undertilde == BufferParams::package_auto);
2817
2818         switch (bp_.spacing().getSpace()) {
2819                 case Spacing::Other: nitem = 3; break;
2820                 case Spacing::Double: nitem = 2; break;
2821                 case Spacing::Onehalf: nitem = 1; break;
2822                 case Spacing::Default: case Spacing::Single: nitem = 0; break;
2823         }
2824
2825         // text layout
2826         string const & layoutID = bp_.baseClassID();
2827         setLayoutComboByIDString(layoutID);
2828
2829         updatePagestyle(documentClass().opt_pagestyle(),
2830                                  bp_.pagestyle);
2831
2832         textLayoutModule->lspacingCO->setCurrentIndex(nitem);
2833         if (bp_.spacing().getSpace() == Spacing::Other) {
2834                 doubleToWidget(textLayoutModule->lspacingLE,
2835                         bp_.spacing().getValueAsString());
2836         }
2837         setLSpacing(nitem);
2838
2839         if (bp_.paragraph_separation == BufferParams::ParagraphIndentSeparation) {
2840                 textLayoutModule->indentRB->setChecked(true);
2841                 string indentation = bp_.getIndentation().asLyXCommand();
2842                 int indent = 0;
2843                 if (indentation != "default") {
2844                         lengthToWidgets(textLayoutModule->indentLE,
2845                         textLayoutModule->indentLengthCO,
2846                         indentation, default_unit);
2847                         indent = 1;
2848                 }
2849                 textLayoutModule->indentCO->setCurrentIndex(indent);
2850                 setIndent(indent);
2851         } else {
2852                 textLayoutModule->skipRB->setChecked(true);
2853                 int skip = 0;
2854                 switch (bp_.getDefSkip().kind()) {
2855                 case VSpace::SMALLSKIP:
2856                         skip = 0;
2857                         break;
2858                 case VSpace::MEDSKIP:
2859                         skip = 1;
2860                         break;
2861                 case VSpace::BIGSKIP:
2862                         skip = 2;
2863                         break;
2864                 case VSpace::LENGTH:
2865                         {
2866                         skip = 3;
2867                         string const length = bp_.getDefSkip().asLyXCommand();
2868                         lengthToWidgets(textLayoutModule->skipLE,
2869                                 textLayoutModule->skipLengthCO,
2870                                 length, default_unit);
2871                         break;
2872                         }
2873                 default:
2874                         skip = 0;
2875                         break;
2876                 }
2877                 textLayoutModule->skipCO->setCurrentIndex(skip);
2878                 setSkip(skip);
2879         }
2880
2881         textLayoutModule->twoColumnCB->setChecked(
2882                 bp_.columns == 2);
2883         textLayoutModule->justCB->setChecked(bp_.justification);
2884
2885         if (!bp_.options.empty()) {
2886                 latexModule->optionsLE->setText(
2887                         toqstr(bp_.options));
2888         } else {
2889                 latexModule->optionsLE->setText(QString());
2890         }
2891
2892         // latex
2893         latexModule->defaultOptionsCB->setChecked(
2894                         bp_.use_default_options);
2895         updateSelectedModules();
2896         selectionManager->updateProvidedModules(
2897                         bp_.baseClass()->providedModules());
2898         selectionManager->updateExcludedModules(
2899                         bp_.baseClass()->excludedModules());
2900
2901         if (!documentClass().options().empty()) {
2902                 latexModule->defaultOptionsLE->setText(
2903                         toqstr(documentClass().options()));
2904         } else {
2905                 latexModule->defaultOptionsLE->setText(
2906                         toqstr(_("[No options predefined]")));
2907         }
2908
2909         latexModule->defaultOptionsLE->setEnabled(
2910                 bp_.use_default_options
2911                 && !documentClass().options().empty());
2912
2913         latexModule->defaultOptionsCB->setEnabled(
2914                 !documentClass().options().empty());
2915
2916         if (!bp_.master.empty()) {
2917                 latexModule->childDocGB->setChecked(true);
2918                 latexModule->childDocLE->setText(
2919                         toqstr(bp_.master));
2920         } else {
2921                 latexModule->childDocLE->setText(QString());
2922                 latexModule->childDocGB->setChecked(false);
2923         }
2924
2925         // Master/Child
2926         if (!bufferview() || !buffer().hasChildren()) {
2927                 masterChildModule->childrenTW->clear();
2928                 includeonlys_.clear();
2929                 docPS->showPanel(qt_("Child Documents"), false);
2930                 if (docPS->isCurrentPanel(qt_("Child Documents")))
2931                         docPS->setCurrentPanel(qt_("Document Class"));
2932         } else {
2933                 docPS->showPanel(qt_("Child Documents"), true);
2934                 masterChildModule->setEnabled(true);
2935                 includeonlys_ = bp_.getIncludedChildren();
2936                 updateIncludeonlys();
2937         }
2938         masterChildModule->maintainAuxCB->setChecked(
2939                 bp_.maintain_unincluded_children);
2940
2941         // Float Settings
2942         floatModule->set(bp_.float_placement);
2943
2944         // ListingsSettings
2945         // break listings_params to multiple lines
2946         string lstparams =
2947                 InsetListingsParams(bp_.listings_params).separatedParams();
2948         listingsModule->listingsED->setPlainText(toqstr(lstparams));
2949
2950         // Output
2951         // update combobox with formats
2952         updateDefaultFormat();
2953         int index = outputModule->defaultFormatCO->findData(toqstr(
2954                 bp_.default_output_format));
2955         // set to default if format is not found
2956         if (index == -1)
2957                 index = 0;
2958         outputModule->defaultFormatCO->setCurrentIndex(index);
2959         bool const os_fonts_available =
2960                 bp_.baseClass()->outputType() == lyx::LATEX
2961                 && LaTeXFeatures::isAvailable("fontspec");
2962         fontModule->osFontsCB->setEnabled(os_fonts_available);
2963         fontModule->osFontsCB->setChecked(
2964                 os_fonts_available && bp_.useNonTeXFonts);
2965
2966         outputModule->outputsyncCB->setChecked(bp_.output_sync);
2967         outputModule->synccustomCB->setEditText(toqstr(bp_.output_sync_macro));
2968
2969         outputModule->mathimgSB->setValue(bp_.html_math_img_scale);
2970         outputModule->mathoutCB->setCurrentIndex(bp_.html_math_output);
2971         outputModule->strictCB->setChecked(bp_.html_be_strict);
2972         outputModule->cssCB->setChecked(bp_.html_css_as_file);
2973
2974         // Fonts
2975         updateFontsize(documentClass().opt_fontsize(),
2976                         bp_.fontsize);
2977
2978         QString font = toqstr(bp_.fonts_roman);
2979         int rpos = fontModule->fontsRomanCO->findData(font);
2980         if (rpos == -1) {
2981                 rpos = fontModule->fontsRomanCO->count();
2982                 fontModule->fontsRomanCO->addItem(font + qt_(" (not installed)"), font);
2983         }
2984         fontModule->fontsRomanCO->setCurrentIndex(rpos);
2985
2986         font = toqstr(bp_.fonts_sans);
2987         int spos = fontModule->fontsSansCO->findData(font);
2988         if (spos == -1) {
2989                 spos = fontModule->fontsSansCO->count();
2990                 fontModule->fontsSansCO->addItem(font + qt_(" (not installed)"), font);
2991         }
2992         fontModule->fontsSansCO->setCurrentIndex(spos);
2993
2994         font = toqstr(bp_.fonts_typewriter);
2995         int tpos = fontModule->fontsTypewriterCO->findData(font);
2996         if (tpos == -1) {
2997                 tpos = fontModule->fontsTypewriterCO->count();
2998                 fontModule->fontsTypewriterCO->addItem(font + qt_(" (not installed)"), font);
2999         }
3000         fontModule->fontsTypewriterCO->setCurrentIndex(tpos);
3001
3002         if (bp_.useNonTeXFonts && os_fonts_available) {
3003                 fontModule->fontencLA->setEnabled(false);
3004                 fontModule->fontencCO->setEnabled(false);
3005                 fontModule->fontencLE->setEnabled(false);
3006         } else {
3007                 fontModule->fontencLA->setEnabled(true);
3008                 fontModule->fontencCO->setEnabled(true);
3009                 fontModule->fontencLE->setEnabled(true);
3010                 romanChanged(rpos);
3011                 sansChanged(spos);
3012                 ttChanged(tpos);
3013         }
3014
3015         if (!bp_.fonts_cjk.empty())
3016                 fontModule->cjkFontLE->setText(
3017                         toqstr(bp_.fonts_cjk));
3018         else
3019                 fontModule->cjkFontLE->setText(QString());
3020
3021         fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
3022         fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
3023         fontModule->scaleSansSB->setValue(bp_.fonts_sans_scale);
3024         fontModule->scaleTypewriterSB->setValue(bp_.fonts_typewriter_scale);
3025
3026         int nn = findToken(GuiDocument::fontfamilies, bp_.fonts_default_family);
3027         if (nn >= 0)
3028                 fontModule->fontsDefaultCO->setCurrentIndex(nn);
3029
3030         if (bp_.fontenc == "global") {
3031                 fontModule->fontencCO->setCurrentIndex(0);
3032                 fontModule->fontencLE->setEnabled(false);
3033         } else if (bp_.fontenc == "default") {
3034                 fontModule->fontencCO->setCurrentIndex(2);
3035                 fontModule->fontencLE->setEnabled(false);
3036         } else {
3037                 fontModule->fontencCO->setCurrentIndex(1);
3038                 fontModule->fontencLE->setText(toqstr(bp_.fontenc));
3039         }
3040
3041         // paper
3042         bool const extern_geometry =
3043                 documentClass().provides("geometry");
3044         int const psize = bp_.papersize;
3045         pageLayoutModule->papersizeCO->setCurrentIndex(psize);
3046         setCustomPapersize(!extern_geometry && psize == 1);
3047         pageLayoutModule->papersizeCO->setEnabled(!extern_geometry);
3048
3049         bool const landscape =
3050                 bp_.orientation == ORIENTATION_LANDSCAPE;
3051         pageLayoutModule->landscapeRB->setChecked(landscape);
3052         pageLayoutModule->portraitRB->setChecked(!landscape);
3053         pageLayoutModule->landscapeRB->setEnabled(!extern_geometry);
3054         pageLayoutModule->portraitRB->setEnabled(!extern_geometry);
3055
3056         pageLayoutModule->facingPagesCB->setChecked(
3057                 bp_.sides == TwoSides);
3058
3059         lengthToWidgets(pageLayoutModule->paperwidthLE,
3060                 pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, default_unit);
3061         lengthToWidgets(pageLayoutModule->paperheightLE,
3062                 pageLayoutModule->paperheightUnitCO, bp_.paperheight, default_unit);
3063
3064         // margins
3065         Ui::MarginsUi * m = marginsModule;
3066
3067         setMargins();
3068
3069         lengthToWidgets(m->topLE, m->topUnit,
3070                 bp_.topmargin, default_unit);
3071
3072         lengthToWidgets(m->bottomLE, m->bottomUnit,
3073                 bp_.bottommargin, default_unit);
3074
3075         lengthToWidgets(m->innerLE, m->innerUnit,
3076                 bp_.leftmargin, default_unit);
3077
3078         lengthToWidgets(m->outerLE, m->outerUnit,
3079                 bp_.rightmargin, default_unit);
3080
3081         lengthToWidgets(m->headheightLE, m->headheightUnit,
3082                 bp_.headheight, default_unit);
3083
3084         lengthToWidgets(m->headsepLE, m->headsepUnit,
3085                 bp_.headsep, default_unit);
3086
3087         lengthToWidgets(m->footskipLE, m->footskipUnit,
3088                 bp_.footskip, default_unit);
3089
3090         lengthToWidgets(m->columnsepLE, m->columnsepUnit,
3091                 bp_.columnsep, default_unit);
3092
3093         // branches
3094         updateUnknownBranches();
3095         branchesModule->update(bp_);
3096
3097         // PDF support
3098         PDFOptions const & pdf = bp_.pdfoptions();
3099         pdfSupportModule->use_hyperrefGB->setChecked(pdf.use_hyperref);
3100         if (bp_.documentClass().provides("hyperref"))
3101                 pdfSupportModule->use_hyperrefGB->setTitle(qt_("C&ustomize Hyperref Options"));
3102         else
3103                 pdfSupportModule->use_hyperrefGB->setTitle(qt_("&Use Hyperref Support"));
3104         pdfSupportModule->titleLE->setText(toqstr(pdf.title));
3105         pdfSupportModule->authorLE->setText(toqstr(pdf.author));
3106         pdfSupportModule->subjectLE->setText(toqstr(pdf.subject));
3107         pdfSupportModule->keywordsLE->setText(toqstr(pdf.keywords));
3108
3109         pdfSupportModule->bookmarksGB->setChecked(pdf.bookmarks);
3110         pdfSupportModule->bookmarksnumberedCB->setChecked(pdf.bookmarksnumbered);
3111         pdfSupportModule->bookmarksopenGB->setChecked(pdf.bookmarksopen);
3112
3113         pdfSupportModule->bookmarksopenlevelSB->setValue(pdf.bookmarksopenlevel);
3114
3115         pdfSupportModule->breaklinksCB->setChecked(pdf.breaklinks);
3116         pdfSupportModule->pdfborderCB->setChecked(pdf.pdfborder);
3117         pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
3118         pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
3119
3120         nn = findToken(backref_opts, pdf.backref);
3121         if (nn >= 0)
3122                 pdfSupportModule->backrefCO->setCurrentIndex(nn);
3123
3124         pdfSupportModule->fullscreenCB->setChecked
3125                 (pdf.pagemode == pdf.pagemode_fullscreen);
3126
3127         pdfSupportModule->optionsLE->setText(
3128                 toqstr(pdf.quoted_options));
3129
3130         // Make sure that the bc is in the INITIAL state
3131         if (bc().policy().buttonStatus(ButtonPolicy::RESTORE))
3132                 bc().restore();
3133
3134         // clear changed branches cache
3135         changedBranches_.clear();
3136 }
3137
3138
3139 void GuiDocument::saveDocDefault()
3140 {
3141         // we have to apply the params first
3142         applyView();
3143         saveAsDefault();
3144 }
3145
3146
3147 void GuiDocument::updateAvailableModules()
3148 {
3149         modules_av_model_.clear();
3150         list<modInfoStruct> const & modInfoList = getModuleInfo();
3151         list<modInfoStruct>::const_iterator mit = modInfoList.begin();
3152         list<modInfoStruct>::const_iterator men = modInfoList.end();
3153         for (int i = 0; mit != men; ++mit, ++i)
3154                 modules_av_model_.insertRow(i, mit->name, mit->id,
3155                                 mit->description);
3156 }
3157
3158
3159 void GuiDocument::updateSelectedModules()
3160 {
3161         modules_sel_model_.clear();
3162         list<modInfoStruct> const selModList = getSelectedModules();
3163         list<modInfoStruct>::const_iterator mit = selModList.begin();
3164         list<modInfoStruct>::const_iterator men = selModList.end();
3165         for (int i = 0; mit != men; ++mit, ++i)
3166                 modules_sel_model_.insertRow(i, mit->name, mit->id,
3167                                 mit->description);
3168 }
3169
3170
3171 void GuiDocument::updateIncludeonlys()
3172 {
3173         masterChildModule->childrenTW->clear();
3174         QString const no = qt_("No");
3175         QString const yes = qt_("Yes");
3176
3177         if (includeonlys_.empty()) {
3178                 masterChildModule->includeallRB->setChecked(true);
3179                 masterChildModule->childrenTW->setEnabled(false);
3180                 masterChildModule->maintainAuxCB->setEnabled(false);
3181         } else {
3182                 masterChildModule->includeonlyRB->setChecked(true);
3183                 masterChildModule->childrenTW->setEnabled(true);
3184                 masterChildModule->maintainAuxCB->setEnabled(true);
3185         }
3186         QTreeWidgetItem * item = 0;
3187         ListOfBuffers children = buffer().getChildren();
3188         ListOfBuffers::const_iterator it  = children.begin();
3189         ListOfBuffers::const_iterator end = children.end();
3190         bool has_unincluded = false;
3191         bool all_unincluded = true;
3192         for (; it != end; ++it) {
3193                 item = new QTreeWidgetItem(masterChildModule->childrenTW);
3194                 // FIXME Unicode
3195                 string const name =
3196                         to_utf8(makeRelPath(from_utf8((*it)->fileName().absFileName()),
3197                                                         from_utf8(buffer().filePath())));
3198                 item->setText(0, toqstr(name));
3199                 item->setText(1, isChildIncluded(name) ? yes : no);
3200                 if (!isChildIncluded(name))
3201                         has_unincluded = true;
3202                 else
3203                         all_unincluded = false;
3204         }
3205         // Both if all childs are included and if none is included
3206         // is equal to "include all" (i.e., ommit \includeonly).
3207         // Thus, reset the GUI.
3208         if (!has_unincluded || all_unincluded) {
3209                 masterChildModule->includeallRB->setChecked(true);
3210                 masterChildModule->childrenTW->setEnabled(false);
3211                 includeonlys_.clear();
3212         }
3213         // If all are included, we need to update again.
3214         if (!has_unincluded)
3215                 updateIncludeonlys();
3216 }
3217
3218
3219 void GuiDocument::updateContents()
3220 {
3221         // Nothing to do here as the document settings is not cursor dependant.
3222         return;
3223 }
3224
3225
3226 void GuiDocument::useClassDefaults()
3227 {
3228         if (applyPB->isEnabled()) {
3229                 int const ret = Alert::prompt(_("Unapplied changes"),
3230                                 _("Some changes in the dialog were not yet applied.\n"
3231                                   "If you do not apply now, they will be lost after this action."),
3232                                 1, 1, _("&Apply"), _("&Dismiss"));
3233                 if (ret == 0)
3234                         applyView();
3235         }
3236
3237         int idx = latexModule->classCO->currentIndex();
3238         string const classname = classes_model_.getIDString(idx);
3239         if (!bp_.setBaseClass(classname)) {
3240                 Alert::error(_("Error"), _("Unable to set document class."));
3241                 return;
3242         }
3243         bp_.useClassDefaults();
3244         paramsToDialog();
3245 }
3246
3247
3248 void GuiDocument::setLayoutComboByIDString(string const & idString)
3249 {
3250         int idx = classes_model_.findIDString(idString);
3251         if (idx < 0)
3252                 Alert::warning(_("Can't set layout!"),
3253                         bformat(_("Unable to set layout for ID: %1$s"), from_utf8(idString)));
3254         else
3255                 latexModule->classCO->setCurrentIndex(idx);
3256 }
3257
3258
3259 bool GuiDocument::isValid()
3260 {
3261         return
3262                 validateListingsParameters().isEmpty() &&
3263                 localLayout->isValid() &&
3264                 (
3265                         // if we're asking for skips between paragraphs
3266                         !textLayoutModule->skipRB->isChecked() ||
3267                         // then either we haven't chosen custom
3268                         textLayoutModule->skipCO->currentIndex() != 3 ||
3269                         // or else a length has been given
3270                         !textLayoutModule->skipLE->text().isEmpty()
3271                 ) &&
3272                 (
3273                         // if we're asking for indentation
3274                         !textLayoutModule->indentRB->isChecked() ||
3275                         // then either we haven't chosen custom
3276                         textLayoutModule->indentCO->currentIndex() != 1 ||
3277                         // or else a length has been given
3278                         !textLayoutModule->indentLE->text().isEmpty()
3279                 );
3280 }
3281
3282
3283 char const * const GuiDocument::fontfamilies[5] = {
3284         "default", "rmdefault", "sfdefault", "ttdefault", ""
3285 };
3286
3287
3288 char const * GuiDocument::fontfamilies_gui[5] = {
3289         N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
3290 };
3291
3292
3293 bool GuiDocument::initialiseParams(string const &)
3294 {
3295         BufferView const * view = bufferview();
3296         if (!view) {
3297                 bp_ = BufferParams();
3298                 paramsToDialog();
3299                 return true;
3300         }
3301         bp_ = view->buffer().params();
3302         loadModuleInfo();
3303         updateAvailableModules();
3304         //FIXME It'd be nice to make sure here that the selected
3305         //modules are consistent: That required modules are actually
3306         //selected, and that we don't have conflicts. If so, we could
3307         //at least pop up a warning.
3308         paramsToDialog();
3309         return true;
3310 }
3311
3312
3313 void GuiDocument::clearParams()
3314 {
3315         bp_ = BufferParams();
3316 }
3317
3318
3319 BufferId GuiDocument::id() const
3320 {
3321         BufferView const * const view = bufferview();
3322         return view? &view->buffer() : 0;
3323 }
3324
3325
3326 list<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
3327 {
3328         return moduleNames_;
3329 }
3330
3331
3332 list<GuiDocument::modInfoStruct> const
3333                 GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
3334 {
3335         LayoutModuleList::const_iterator it =  mods.begin();
3336         LayoutModuleList::const_iterator end = mods.end();
3337         list<modInfoStruct> mInfo;
3338         for (; it != end; ++it) {
3339                 modInfoStruct m;
3340                 m.id = *it;
3341                 LyXModule const * const mod = theModuleList[*it];
3342                 if (mod)
3343                         // FIXME Unicode
3344                         m.name = toqstr(translateIfPossible(from_utf8(mod->getName())));
3345                 else
3346                         m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")");
3347                 mInfo.push_back(m);
3348         }
3349         return mInfo;
3350 }
3351
3352
3353 list<GuiDocument::modInfoStruct> const GuiDocument::getSelectedModules()
3354 {
3355         return makeModuleInfo(params().getModules());
3356 }
3357
3358
3359 list<GuiDocument::modInfoStruct> const GuiDocument::getProvidedModules()
3360 {
3361         return makeModuleInfo(params().baseClass()->providedModules());
3362 }
3363
3364
3365 DocumentClass const & GuiDocument::documentClass() const
3366 {
3367         return bp_.documentClass();
3368 }
3369
3370
3371 static void dispatch_bufferparams(Dialog const & dialog,
3372         BufferParams const & bp, FuncCode lfun)
3373 {
3374         ostringstream ss;
3375         ss << "\\begin_header\n";
3376         bp.writeFile(ss);
3377         ss << "\\end_header\n";
3378         dialog.dispatch(FuncRequest(lfun, ss.str()));
3379 }
3380
3381
3382 void GuiDocument::dispatchParams()
3383 {
3384         // This must come first so that a language change is correctly noticed
3385         setLanguage();
3386
3387         // Apply the BufferParams. Note that this will set the base class
3388         // and then update the buffer's layout.
3389         dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
3390
3391         if (!params().master.empty()) {
3392                 FileName const master_file = support::makeAbsPath(params().master,
3393                            support::onlyPath(buffer().absFileName()));
3394                 if (isLyXFileName(master_file.absFileName())) {
3395                         Buffer * master = checkAndLoadLyXFile(master_file);
3396                         if (master) {
3397                                 if (master->isChild(const_cast<Buffer *>(&buffer())))
3398                                         const_cast<Buffer &>(buffer()).setParent(master);
3399                                 else
3400                                         Alert::warning(_("Assigned master does not include this file"),
3401                                                 bformat(_("You must include this file in the document\n"
3402                                                           "'%1$s' in order to use the master document\n"
3403                                                           "feature."), from_utf8(params().master)));
3404                         } else
3405                                 Alert::warning(_("Could not load master"),
3406                                                 bformat(_("The master document '%1$s'\n"
3407                                                            "could not be loaded."),
3408                                                            from_utf8(params().master)));
3409                 }
3410         }
3411
3412         // Generate the colours requested by each new branch.
3413         BranchList & branchlist = params().branchlist();
3414         if (!branchlist.empty()) {
3415                 BranchList::const_iterator it = branchlist.begin();
3416                 BranchList::const_iterator const end = branchlist.end();
3417                 for (; it != end; ++it) {
3418                         docstring const & current_branch = it->branch();
3419                         Branch const * branch = branchlist.find(current_branch);
3420                         string const x11hexname = X11hexname(branch->color());
3421                         // display the new color
3422                         docstring const str = current_branch + ' ' + from_ascii(x11hexname);
3423                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
3424                 }
3425
3426                 // Open insets of selected branches, close deselected ones
3427                 dispatch(FuncRequest(LFUN_INSET_FORALL,
3428                         "Branch inset-toggle assign"));
3429         }
3430         // rename branches in the document
3431         executeBranchRenaming();
3432         // and clear changed branches cache
3433         changedBranches_.clear();
3434
3435         // Generate the colours requested by indices.
3436         IndicesList & indiceslist = params().indiceslist();
3437         if (!indiceslist.empty()) {
3438                 IndicesList::const_iterator it = indiceslist.begin();
3439                 IndicesList::const_iterator const end = indiceslist.end();
3440                 for (; it != end; ++it) {
3441                         docstring const & current_index = it->shortcut();
3442                         Index const * index = indiceslist.findShortcut(current_index);
3443                         string const x11hexname = X11hexname(index->color());
3444                         // display the new color
3445                         docstring const str = current_index + ' ' + from_ascii(x11hexname);
3446                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
3447                 }
3448         }
3449         // FIXME LFUN
3450         // If we used an LFUN, we would not need these two lines:
3451         BufferView * bv = const_cast<BufferView *>(bufferview());
3452         bv->processUpdateFlags(Update::Force | Update::FitCursor);
3453 }
3454
3455
3456 void GuiDocument::setLanguage() const
3457 {
3458         Language const * const newL = bp_.language;
3459         if (buffer().params().language == newL)
3460                 return;
3461
3462         string const & lang_name = newL->lang();
3463         dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
3464 }
3465
3466
3467 void GuiDocument::saveAsDefault() const
3468 {
3469         dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
3470 }
3471
3472
3473 bool GuiDocument::isFontAvailable(string const & font) const
3474 {
3475         if (font == "default" || font == "cmr"
3476             || font == "cmss" || font == "cmtt")
3477                 // these are standard
3478                 return true;
3479         if (font == "lmodern" || font == "lmss" || font == "lmtt")
3480                 return LaTeXFeatures::isAvailable("lmodern");
3481         if (font == "times" || font == "palatino"
3482                  || font == "helvet" || font == "courier")
3483                 return LaTeXFeatures::isAvailable("psnfss");
3484         if (font == "cmbr" || font == "cmtl")
3485                 return LaTeXFeatures::isAvailable("cmbright");
3486         if (font == "utopia")
3487                 return LaTeXFeatures::isAvailable("utopia")
3488                         || LaTeXFeatures::isAvailable("fourier");
3489         if (font == "beraserif" || font == "berasans"
3490                 || font == "beramono")
3491                 return LaTeXFeatures::isAvailable("bera");
3492         return LaTeXFeatures::isAvailable(font);
3493 }
3494
3495
3496 bool GuiDocument::providesOSF(string const & font) const
3497 {
3498         if (fontModule->osFontsCB->isChecked())
3499                 // FIXME: we should check if the fonts really
3500                 // have OSF support. But how?
3501                 return true;
3502         if (font == "cmr")
3503                 return isFontAvailable("eco");
3504         if (font == "palatino")
3505                 return isFontAvailable("mathpazo");
3506         return false;
3507 }
3508
3509
3510 bool GuiDocument::providesSC(string const & font) const
3511 {
3512         if (fontModule->osFontsCB->isChecked())
3513                 return false;
3514         if (font == "palatino")
3515                 return isFontAvailable("mathpazo");
3516         if (font == "utopia")
3517                 return isFontAvailable("fourier");
3518         return false;
3519 }
3520
3521
3522 bool GuiDocument::providesScale(string const & font) const
3523 {
3524         if (fontModule->osFontsCB->isChecked())
3525                 return true;
3526         return font == "helvet" || font == "luximono"
3527                 || font == "berasans"  || font == "beramono";
3528 }
3529
3530
3531 void GuiDocument::loadModuleInfo()
3532 {
3533         moduleNames_.clear();
3534         LyXModuleList::const_iterator it  = theModuleList.begin();
3535         LyXModuleList::const_iterator end = theModuleList.end();
3536         for (; it != end; ++it) {
3537                 modInfoStruct m;
3538                 m.id = it->getID();
3539                 // FIXME Unicode
3540                 m.name = toqstr(translateIfPossible(from_utf8(it->getName())));
3541                 // this is supposed to give us the first sentence of the description
3542                 // FIXME Unicode
3543                 QString desc =
3544                         toqstr(translateIfPossible(from_utf8(it->getDescription())));
3545                 int const pos = desc.indexOf(".");
3546                 if (pos > 0)
3547                         desc.truncate(pos + 1);
3548                 m.description = desc;
3549                 moduleNames_.push_back(m);
3550         }
3551 }
3552
3553
3554 void GuiDocument::updateUnknownBranches()
3555 {
3556         if (!bufferview())
3557                 return;
3558         list<docstring> used_branches;
3559         buffer().getUsedBranches(used_branches);
3560         list<docstring>::const_iterator it = used_branches.begin();
3561         QStringList unknown_branches;
3562         for (; it != used_branches.end() ; ++it) {
3563                 if (!buffer().params().branchlist().find(*it))
3564                         unknown_branches.append(toqstr(*it));
3565         }
3566         branchesModule->setUnknownBranches(unknown_branches);
3567 }
3568
3569
3570 void GuiDocument::branchesRename(docstring const & oldname, docstring const & newname)
3571 {
3572         map<docstring, docstring>::iterator it = changedBranches_.begin();
3573         for (; it != changedBranches_.end() ; ++it) {
3574                 if (it->second == oldname) {
3575                         // branch has already been renamed
3576                         it->second = newname;
3577                         return;
3578                 }
3579         }
3580         // store new name
3581         changedBranches_[oldname] = newname;
3582 }
3583
3584
3585 void GuiDocument::executeBranchRenaming() const
3586 {
3587         map<docstring, docstring>::const_iterator it = changedBranches_.begin();
3588         for (; it != changedBranches_.end() ; ++it) {
3589                 docstring const arg = '"' + it->first + '"' + " " + '"' + it->second + '"';
3590                 dispatch(FuncRequest(LFUN_BRANCHES_RENAME, arg));
3591         }
3592 }
3593
3594
3595 Dialog * createGuiDocument(GuiView & lv) { return new GuiDocument(lv); }
3596
3597
3598 } // namespace frontend
3599 } // namespace lyx
3600
3601 #include "moc_GuiDocument.cpp"