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