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