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