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