]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Revert "BufferParams: get rid of the HSpace class for mathindent as requested by...
[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
90 private Q_SLOTS:
91         void updateNumbering();
92         void change_adaptor();
93         void includeonlyClicked(QTreeWidgetItem * item, int);
94         void setListingsMessage();
95         void saveDefaultClicked();
96         void useDefaultsClicked();
97         void setLSpacing(int);
98         void setMargins();
99         void papersizeChanged(int);
100         void setColSep();
101         void setCustomMargins(bool);
102         void fontencChanged(int);
103         void romanChanged(int);
104         void sansChanged(int);
105         void ttChanged(int);
106         void fontOsfToggled(bool state);
107         void fontScToggled(bool state);
108         void setIndent(int);
109         void enableIndent(bool);
110         void setSkip(int);
111         void enableSkip(bool);
112         void setMathIndent(int);
113         void browseLayout();
114         void browseMaster();
115         void classChanged();
116         void classChanged_adaptor();
117         void languagePackageChanged(int);
118         void biblioChanged();
119         void rescanBibFiles();
120         void resetDefaultBibfile(std::string const & which = std::string());
121         void resetDefaultBbxBibfile();
122         void resetDefaultCbxBibfile();
123         void citeEngineChanged(int);
124         void citeStyleChanged();
125         void bibtexChanged(int);
126         void updateResetDefaultBiblio();
127         void matchBiblatexStyles();
128         void updateEngineDependends();
129         void updateModuleInfo();
130         void modulesChanged();
131         void changeBackgroundColor();
132         void deleteBackgroundColor();
133         void changeFontColor();
134         void deleteFontColor();
135         void changeNoteFontColor();
136         void deleteNoteFontColor();
137         void changeBoxBackgroundColor();
138         void deleteBoxBackgroundColor();
139         void languageChanged(int);
140         void osFontsChanged(bool);
141         void mathFontChanged(int);
142         void branchesRename(docstring const &, docstring const &);
143         void allPackagesAuto();
144         void allPackagesAlways();
145         void allPackagesNot();
146 private:
147         /// validate listings parameters and return an error message, if any
148         QString validateListingsParameters();
149
150         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
151         UiWidget<Ui::MasterChildUi> *masterChildModule;
152         FontModule *fontModule;
153         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
154         UiWidget<Ui::MarginsUi> *marginsModule;
155         UiWidget<Ui::LanguageUi> *langModule;
156         UiWidget<Ui::ColorUi> *colorModule;
157         UiWidget<Ui::NumberingUi> *numberingModule;
158         UiWidget<Ui::BiblioUi> *biblioModule;
159         UiWidget<Ui::MathsUi> *mathsModule;
160         UiWidget<Ui::LaTeXUi> *latexModule;
161         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
162         UiWidget<Ui::ModulesUi> *modulesModule;
163         UiWidget<Ui::OutputUi> *outputModule;
164         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
165         PreambleModule * preambleModule;
166         LocalLayout * localLayout;
167
168         GuiBranches * branchesModule;
169         GuiIndices * indicesModule;
170
171         BulletsModule * bulletsModule;
172         FloatPlacement * floatModule;
173
174         ModuleSelectionManager * selectionManager;
175
176         /// Available modules
177         GuiIdListModel * availableModel() { return &modules_av_model_; }
178         /// Selected modules
179         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
180
181         /// Apply changes
182         void applyView();
183         /// update
184         void updateContents();
185         ///
186         void updateAvailableModules();
187         ///
188         void updateSelectedModules();
189         ///
190         void updateIncludeonlys();
191         ///
192         void updateDefaultBiblio(std::string const & style,
193                                  std::string const & which = std::string());
194         /// save as default template
195         void saveDocDefault();
196         /// reset to default params
197         void useClassDefaults();
198         ///
199         void setLayoutComboByIDString(std::string const & idString);
200         /// Update quotes styles combo, indicating the current language's default
201         void updateQuoteStyles(bool const set = false);
202
203         /// available modules
204         GuiIdListModel modules_av_model_;
205         /// selected modules
206         GuiIdListModel modules_sel_model_;
207
208         /// return false if validate_listings_params returns error
209         bool isValid();
210
211         /// font family names for BufferParams::fonts_default_family
212         static char const * const fontfamilies[5];
213         /// GUI names corresponding fontfamilies
214         static char const * fontfamilies_gui[5];
215         ///
216         bool initialiseParams(std::string const & data);
217         ///
218         void clearParams();
219         ///
220         void dispatchParams();
221         ///
222         void modulesToParams(BufferParams &);
223         ///
224         bool isBufferDependent() const { return true; }
225         /// always true since we don't manipulate document contents
226         bool canApply() const { return true; }
227         ///
228         DocumentClass const & documentClass() const;
229         ///
230         BufferParams & params() { return bp_; }
231         ///
232         BufferId id() const;
233         ///
234         struct modInfoStruct {
235                 QString name;
236                 std::string id;
237                 QString description;
238         };
239         ///
240         static modInfoStruct modInfo(LyXModule const & mod);
241         /// List of available modules
242         std::list<modInfoStruct> const & getModuleInfo();
243         /// Modules in use in current buffer
244         std::list<modInfoStruct> const getSelectedModules();
245         ///
246         std::list<modInfoStruct> const getProvidedModules();
247         ///
248         std::list<modInfoStruct> const
249                         makeModuleInfo(LayoutModuleList const & mods);
250         ///
251         void setLanguage() const;
252         ///
253         void saveAsDefault() const;
254         /// does this font provide Old Style figures?
255         bool providesOSF(QString const & font) const;
256         /// does this font provide true Small Caps?
257         bool providesSC(QString const & font) const;
258         /** does this font provide OSF and Small Caps only via 
259          * a single, undifferentiated expert option?
260          */
261         bool hasMonolithicExpertSet(QString const & font) const;
262         /// does this font provide size adjustment?
263         bool providesScale(QString const & font) const;
264         /// does this font provide an alternative without math?
265         bool providesNoMath(QString const & font) const;
266         ///
267         void executeBranchRenaming() const;
268         ///
269         void setCustomPapersize(bool custom);
270 private:
271         ///
272         void loadModuleInfo();
273         ///
274         void updateUnknownBranches();
275         ///
276         void updateTexFonts();
277         ///
278         void updateMathFonts(QString const & rm);
279         ///
280         void updateFontOptions();
281         ///
282         bool ot1() const;
283         ///
284         bool completeFontset() const;
285         ///
286         bool noMathFont() const;
287         ///
288         void allPackages(int);
289         ///
290         bool isBiblatex() const;
291         ///
292         BufferParams bp_;
293         /// List of names of available modules
294         std::list<modInfoStruct> moduleNames_;
295         ///
296         std::map<docstring, docstring> changedBranches_;
297         ///
298         std::list<std::string> includeonlys_;
299         ///
300         bool biblioChanged_;
301         /// Track if a non-module document param changed
302         bool nonModuleChanged_;
303 };
304
305
306 class PreambleModule : public UiWidget<Ui::PreambleUi>
307 {
308         Q_OBJECT
309 public:
310         PreambleModule(QWidget * parent);
311         void update(BufferParams const & params, BufferId id);
312         void apply(BufferParams & params);
313
314 Q_SIGNALS:
315         /// signal that something's changed in the Widget.
316         void changed();
317
318 private:
319         void closeEvent(QCloseEvent *);
320         void on_preambleTE_textChanged() { changed(); }
321
322 private:
323         typedef std::map<BufferId, std::pair<int,int> > Coords;
324         Coords preamble_coords_;
325         BufferId current_id_;
326 };
327
328
329 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
330 {
331         Q_OBJECT
332 public:
333         LocalLayout(QWidget * parent);
334         void update(BufferParams const & params, BufferId id);
335         void apply(BufferParams & params);
336         bool isValid() const { return validated_; }
337
338 Q_SIGNALS:
339         /// signal that something's changed in the Widget.
340         void changed();
341
342 private:
343         void validate();
344         void convert();
345         void hideConvert();
346 private Q_SLOTS:
347         void textChanged();
348         void validatePressed();
349         void convertPressed();
350
351 private:
352         BufferId current_id_;
353         bool validated_;
354 };
355
356
357 class FontModule : public UiWidget<Ui::FontUi>
358 {
359         Q_OBJECT
360 public:
361         FontModule(QWidget * parent) : UiWidget<Ui::FontUi>(parent),
362            font_sf_scale(100), font_tt_scale(100) {}
363         /// The roman font currently not selected by osFontsCB->isChecked()
364         QString font_roman;
365         /// The sans font currently not selected by osFontsCB->isChecked()
366         QString font_sans;
367         /// The typewriter font currently not selected by osFontsCB->isChecked()
368         QString font_typewriter;
369         /// The math font currently not selected by osFontsCB->isChecked()
370         QString font_math;
371         /// The sans font scale currently not selected by osFontsCB->isChecked()
372         int font_sf_scale;
373         /// The typewriter font scale currently not selected by osFontsCB->isChecked()
374         int font_tt_scale;
375 };
376
377
378 } // namespace frontend
379 } // namespace lyx
380
381 #endif // GUIDOCUMENT_H