]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Do not show master's errors if compiling child
[lyx.git] / src / frontends / qt4 / GuiDocument.h
1 // -*- C++ -*-
2 /**
3  * \file GuiDocument.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Edwin Leuven
8  * \author Richard Heck (modules)
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef GUIDOCUMENT_H
14 #define GUIDOCUMENT_H
15
16 #include "BufferParams.h"
17 #include "BulletsModule.h"
18 #include "GuiDialog.h"
19 #include "GuiIdListModel.h"
20
21 #include "ui_BiblioUi.h"
22 #include "ui_ColorUi.h"
23 #include "ui_DocumentUi.h"
24 #include "ui_FontUi.h"
25 #include "ui_LanguageUi.h"
26 #include "ui_LaTeXUi.h"
27 #include "ui_ListingsSettingsUi.h"
28 #include "ui_LocalLayoutUi.h"
29 #include "ui_MarginsUi.h"
30 #include "ui_MasterChildUi.h"
31 #include "ui_MathsUi.h"
32 #include "ui_ModulesUi.h"
33 #include "ui_NumberingUi.h"
34 #include "ui_OutputUi.h"
35 #include "ui_PageLayoutUi.h"
36 #include "ui_PDFSupportUi.h"
37 #include "ui_PreambleUi.h"
38 #include "ui_TextLayoutUi.h"
39
40 namespace lyx {
41
42 class BufferParams;
43 class LayoutModuleList;
44 class LyXModule;
45 class TextClass;
46
47 namespace frontend {
48
49 class FloatPlacement;
50 class GuiBranches;
51 class GuiIndices;
52 class ModuleSelectionManager;
53 class PreambleModule;
54 class LocalLayout;
55 class FontModule;
56
57 ///
58 typedef void const * BufferId;
59
60 template<class UI>
61 class UiWidget : public QWidget, public UI
62 {
63 public:
64         UiWidget(QWidget * parent) : QWidget(parent) { UI::setupUi(this); }
65 };
66
67
68 class GuiDocument : public GuiDialog, public Ui::DocumentUi
69 {
70         Q_OBJECT
71 public:
72         GuiDocument(GuiView & lv);
73
74         void paramsToDialog();
75         void updateFontsize(std::string const &, std::string const &);
76         void updateFontlist();
77         void updateDefaultFormat();
78         void updateCiteStyles(std::vector<std::string> const &,
79                               CiteEngineType const & sel = ENGINE_TYPE_AUTHORYEAR);
80         void updateEngineType(std::string const &, CiteEngineType const &);
81         void updatePagestyle(std::string const &, std::string const &);
82         bool isChildIncluded(std::string const &);
83
84         ///
85         BufferParams const & params() const { return bp_; }
86
87 public Q_SLOTS:
88         void onBufferViewChanged();//override
89         // OK button clicked
90         void slotOK();
91         // Apply button clicked
92         void slotApply();
93
94 private Q_SLOTS:
95         void updateNumbering();
96         void change_adaptor();
97         void shellescapeChanged();
98         void includeonlyClicked(QTreeWidgetItem * item, int);
99         void setListingsMessage();
100         void listingsPackageChanged(int);
101         void saveDefaultClicked();
102         void useDefaultsClicked();
103         void setLSpacing(int);
104         void setMargins();
105         void papersizeChanged(int);
106         void setColSep();
107         void setCustomMargins(bool);
108         void fontencChanged(int);
109         void romanChanged(int);
110         void sansChanged(int);
111         void ttChanged(int);
112         void fontOsfToggled(bool state);
113         void fontScToggled(bool state);
114         void setIndent(int);
115         void enableIndent(bool);
116         void setSkip(int);
117         void enableSkip(bool);
118         void allowMathIndent();
119         void enableMathIndent(int);
120         void browseLayout();
121         void browseMaster();
122         void classChanged();
123         void classChanged_adaptor();
124         void languagePackageChanged(int);
125         void biblioChanged();
126         void rescanBibFiles();
127         void resetDefaultBibfile(std::string const & which = std::string());
128         void resetDefaultBbxBibfile();
129         void resetDefaultCbxBibfile();
130         void citeEngineChanged(int);
131         void citeStyleChanged();
132         void bibtexChanged(int);
133         void updateResetDefaultBiblio();
134         void matchBiblatexStyles();
135         void updateEngineDependends();
136         void updateModuleInfo();
137         void modulesChanged();
138         void changeBackgroundColor();
139         void deleteBackgroundColor();
140         void changeFontColor();
141         void deleteFontColor();
142         void changeNoteFontColor();
143         void deleteNoteFontColor();
144         void changeBoxBackgroundColor();
145         void deleteBoxBackgroundColor();
146         void languageChanged(int);
147         void osFontsChanged(bool);
148         void mathFontChanged(int);
149         void branchesRename(docstring const &, docstring const &);
150         void allPackagesAuto();
151         void allPackagesAlways();
152         void allPackagesNot();
153 private:
154         /// validate listings parameters and return an error message, if any
155         QString validateListingsParameters();
156
157         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
158         UiWidget<Ui::MasterChildUi> *masterChildModule;
159         FontModule *fontModule;
160         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
161         UiWidget<Ui::MarginsUi> *marginsModule;
162         UiWidget<Ui::LanguageUi> *langModule;
163         UiWidget<Ui::ColorUi> *colorModule;
164         UiWidget<Ui::NumberingUi> *numberingModule;
165         UiWidget<Ui::BiblioUi> *biblioModule;
166         UiWidget<Ui::MathsUi> *mathsModule;
167         UiWidget<Ui::LaTeXUi> *latexModule;
168         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
169         UiWidget<Ui::ModulesUi> *modulesModule;
170         UiWidget<Ui::OutputUi> *outputModule;
171         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
172         PreambleModule * preambleModule;
173         LocalLayout * localLayout;
174
175         GuiBranches * branchesModule;
176         GuiIndices * indicesModule;
177
178         BulletsModule * bulletsModule;
179         FloatPlacement * floatModule;
180
181         ModuleSelectionManager * selectionManager;
182
183         /// Available modules
184         GuiIdListModel * availableModel() { return &modules_av_model_; }
185         /// Selected modules
186         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
187
188         /// Apply changes
189         void applyView();
190         /// update
191         void updateContents();
192         ///
193         void updateAvailableModules();
194         ///
195         void updateSelectedModules();
196         ///
197         void updateIncludeonlys();
198         ///
199         void updateDefaultBiblio(std::string const & style,
200                                  std::string const & which = std::string());
201         /// save as default template
202         void saveDocDefault();
203         /// reset to default params
204         void useClassDefaults();
205         ///
206         void setLayoutComboByIDString(std::string const & idString);
207         /// Update quotes styles combo, indicating the current language's default
208         void updateQuoteStyles(bool const set = false);
209
210         /// available modules
211         GuiIdListModel modules_av_model_;
212         /// selected modules
213         GuiIdListModel modules_sel_model_;
214
215         /// return false if validate_listings_params returns error
216         bool isValid();
217
218         /// font family names for BufferParams::fonts_default_family
219         static char const * const fontfamilies[5];
220         /// GUI names corresponding fontfamilies
221         static char const * fontfamilies_gui[5];
222         ///
223         bool initialiseParams(std::string const & data);
224         ///
225         void clearParams();
226         ///
227         void dispatchParams();
228         ///
229         void modulesToParams(BufferParams &);
230         ///
231         bool isBufferDependent() const { return true; }
232         /// always true since we don't manipulate document contents
233         bool canApply() const { return true; }
234         ///
235         DocumentClass const & documentClass() const;
236         ///
237         BufferParams & params() { return bp_; }
238         ///
239         BufferId id() const;
240         ///
241         struct modInfoStruct {
242                 QString name;
243                 std::string id;
244                 QString description;
245         };
246         ///
247         static modInfoStruct modInfo(LyXModule const & mod);
248         /// List of available modules
249         std::list<modInfoStruct> const & getModuleInfo();
250         /// Modules in use in current buffer
251         std::list<modInfoStruct> const getSelectedModules();
252         ///
253         std::list<modInfoStruct> const getProvidedModules();
254         ///
255         std::list<modInfoStruct> const
256                         makeModuleInfo(LayoutModuleList const & mods);
257         ///
258         void setLanguage() const;
259         ///
260         void saveAsDefault() const;
261         /// does this font provide Old Style figures?
262         bool providesOSF(QString const & font) const;
263         /// does this font provide true Small Caps?
264         bool providesSC(QString const & font) const;
265         /** does this font provide OSF and Small Caps only via
266          * a single, undifferentiated expert option?
267          */
268         bool hasMonolithicExpertSet(QString const & font) const;
269         /// does this font provide size adjustment?
270         bool providesScale(QString const & font) const;
271         /// does this font provide an alternative without math?
272         bool providesNoMath(QString const & font) const;
273         ///
274         void executeBranchRenaming() const;
275         ///
276         void setCustomPapersize(bool custom);
277 private:
278         ///
279         void loadModuleInfo();
280         ///
281         void updateUnknownBranches();
282         ///
283         void updateTexFonts();
284         ///
285         void updateMathFonts(QString const & rm);
286         ///
287         void updateFontOptions();
288         ///
289         bool ot1() const;
290         ///
291         bool completeFontset() const;
292         ///
293         bool noMathFont() const;
294         ///
295         void allPackages(int);
296         ///
297         bool isBiblatex() const;
298         ///
299         void checkPossibleCiteEngines();
300         ///
301         BufferParams bp_;
302         /// List of names of available modules
303         std::list<modInfoStruct> moduleNames_;
304         ///
305         std::map<docstring, docstring> changedBranches_;
306         ///
307         std::list<std::string> includeonlys_;
308         ///
309         bool biblioChanged_;
310         /// Track if a non-module document param changed
311         bool nonModuleChanged_;
312         /// Track if used modules changed
313         bool modulesChanged_;
314         /// Track if the shellescape param changed
315         bool shellescapeChanged_;
316 };
317
318
319 class PreambleModule : public UiWidget<Ui::PreambleUi>
320 {
321         Q_OBJECT
322 public:
323         PreambleModule(QWidget * parent);
324         void update(BufferParams const & params, BufferId id);
325         void apply(BufferParams & params);
326
327 Q_SIGNALS:
328         /// signal that something's changed in the Widget.
329         void changed();
330
331 private:
332         void closeEvent(QCloseEvent *);
333         void on_preambleTE_textChanged() { changed(); }
334
335 private:
336         typedef std::map<BufferId, std::pair<int,int> > Coords;
337         Coords preamble_coords_;
338         BufferId current_id_;
339 };
340
341
342 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
343 {
344         Q_OBJECT
345 public:
346         LocalLayout(QWidget * parent);
347         void update(BufferParams const & params, BufferId id);
348         void apply(BufferParams & params);
349         bool isValid() const { return validated_; }
350
351 Q_SIGNALS:
352         /// signal that something's changed in the Widget.
353         void changed();
354
355 private:
356         void validate();
357         void convert();
358         void hideConvert();
359 private Q_SLOTS:
360         void textChanged();
361         void validatePressed();
362         void convertPressed();
363
364 private:
365         BufferId current_id_;
366         bool validated_;
367 };
368
369
370 class FontModule : public UiWidget<Ui::FontUi>
371 {
372         Q_OBJECT
373 public:
374         FontModule(QWidget * parent) : UiWidget<Ui::FontUi>(parent),
375            font_sf_scale(100), font_tt_scale(100) {}
376         /// The roman font currently not selected by osFontsCB->isChecked()
377         QString font_roman;
378         /// The sans font currently not selected by osFontsCB->isChecked()
379         QString font_sans;
380         /// The typewriter font currently not selected by osFontsCB->isChecked()
381         QString font_typewriter;
382         /// The math font currently not selected by osFontsCB->isChecked()
383         QString font_math;
384         /// The sans font scale currently not selected by osFontsCB->isChecked()
385         int font_sf_scale;
386         /// The typewriter font scale currently not selected by osFontsCB->isChecked()
387         int font_tt_scale;
388 };
389
390
391 } // namespace frontend
392 } // namespace lyx
393
394 #endif // GUIDOCUMENT_H