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