]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
09fa73101570ae23e5e704f1102bfdd97e430f56
[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 <QDialog>
17
18 #include "BufferParams.h"
19 #include "BulletsModule.h"
20 #include "GuiDialog.h"
21 #include "GuiIdListModel.h"
22
23 #include "ui_BiblioUi.h"
24 #include "ui_ColorUi.h"
25 #include "ui_DocumentUi.h"
26 #include "ui_FontUi.h"
27 #include "ui_LanguageUi.h"
28 #include "ui_LaTeXUi.h"
29 #include "ui_ListingsSettingsUi.h"
30 #include "ui_LocalLayoutUi.h"
31 #include "ui_MarginsUi.h"
32 #include "ui_MasterChildUi.h"
33 #include "ui_MathsUi.h"
34 #include "ui_ModulesUi.h"
35 #include "ui_NumberingUi.h"
36 #include "ui_OutputUi.h"
37 #include "ui_PageLayoutUi.h"
38 #include "ui_PDFSupportUi.h"
39 #include "ui_PreambleUi.h"
40 #include "ui_TextLayoutUi.h"
41
42 namespace lyx {
43
44 class BufferParams;
45 class LayoutModuleList;
46 class TextClass;
47
48 namespace frontend {
49
50 class FloatPlacement;
51 class GuiBranches;
52 class GuiIndices;
53 class ModuleSelectionManager;
54 class PreambleModule;
55 class LocalLayout;
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 updatePagestyle(std::string const &, std::string const &);
79         bool isChildIncluded(std::string const &);
80
81         ///
82         BufferParams const & params() const { return bp_; }
83
84 private Q_SLOTS:
85         void updateNumbering();
86         void change_adaptor();
87         void includeonlyClicked(QTreeWidgetItem * item, int);
88         void setListingsMessage();
89         void saveDefaultClicked();
90         void useDefaultsClicked();
91         void setLSpacing(int);
92         void setMargins();
93         void papersizeChanged(int);
94         void setColSep();
95         void setCustomMargins(bool);
96         void fontencChanged(int);
97         void romanChanged(int);
98         void sansChanged(int);
99         void ttChanged(int);
100         void setIndent(int);
101         void enableIndent(bool);
102         void setSkip(int);
103         void enableSkip(bool);
104         void browseLayout();
105         void browseMaster();
106         void classChanged();
107         void languagePackageChanged(int);
108         void bibtexChanged(int);
109         void updateModuleInfo();
110         void modulesChanged();
111         void changeBackgroundColor();
112         void deleteBackgroundColor();
113         void changeFontColor();
114         void deleteFontColor();
115         void changeNoteFontColor();
116         void deleteNoteFontColor();
117         void changeBoxBackgroundColor();
118         void deleteBoxBackgroundColor();
119         void osFontsChanged(bool);
120         void branchesRename(docstring const &, docstring const &);
121 private:
122         /// validate listings parameters and return an error message, if any
123         QString validateListingsParameters();
124
125         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
126         UiWidget<Ui::MasterChildUi> *masterChildModule;
127         UiWidget<Ui::FontUi> *fontModule;
128         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
129         UiWidget<Ui::MarginsUi> *marginsModule;
130         UiWidget<Ui::LanguageUi> *langModule;
131         UiWidget<Ui::ColorUi> *colorModule;
132         UiWidget<Ui::NumberingUi> *numberingModule;
133         UiWidget<Ui::BiblioUi> *biblioModule;
134         UiWidget<Ui::MathsUi> *mathsModule;
135         UiWidget<Ui::LaTeXUi> *latexModule;
136         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
137         UiWidget<Ui::ModulesUi> *modulesModule;
138         UiWidget<Ui::OutputUi> *outputModule;
139         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
140         PreambleModule * preambleModule;
141         LocalLayout * localLayout;
142
143         GuiBranches * branchesModule;
144         GuiIndices * indicesModule;
145
146         BulletsModule * bulletsModule;
147         FloatPlacement * floatModule;
148
149         ModuleSelectionManager * selectionManager;
150
151         /// Available modules
152         GuiIdListModel * availableModel() { return &modules_av_model_; }
153         /// Selected modules
154         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
155
156         /// Apply changes
157         void applyView();
158         /// update
159         void updateContents();
160         ///
161         void updateAvailableModules();
162         ///
163         void updateSelectedModules();
164         ///
165         void updateIncludeonlys();
166         /// save as default template
167         void saveDocDefault();
168         /// reset to default params
169         void useClassDefaults();
170         ///
171         void setLayoutComboByIDString(std::string const & idString);
172
173         /// available classes
174         GuiIdListModel classes_model_;
175         /// available modules
176         GuiIdListModel modules_av_model_;
177         /// selected modules
178         GuiIdListModel modules_sel_model_;
179         /// current buffer
180         BufferId current_id_;
181
182         /// return false if validate_listings_params returns error
183         bool isValid();
184
185         /// font family names for BufferParams::fonts_default_family
186         static char const * const fontfamilies[5];
187         /// GUI names corresponding fontfamilies
188         static char const * fontfamilies_gui[5];
189         ///
190         bool initialiseParams(std::string const & data);
191         ///
192         void clearParams();
193         ///
194         void dispatchParams();
195         ///
196         void modulesToParams(BufferParams &);
197         ///
198         bool isBufferDependent() const { return true; }
199         /// always true since we don't manipulate document contents
200         bool canApply() const { return true; }
201         ///
202         DocumentClass const & documentClass() const;
203         ///
204         BufferParams & params() { return bp_; }
205         ///
206         BufferId id() const;
207         ///
208         struct modInfoStruct {
209                 QString name;
210                 std::string id;
211                 QString description;
212         };
213         /// List of available modules
214         std::list<modInfoStruct> const & getModuleInfo();
215         /// Modules in use in current buffer
216         std::list<modInfoStruct> const getSelectedModules();
217         ///
218         std::list<modInfoStruct> const getProvidedModules();
219         ///
220         std::list<modInfoStruct> const
221                         makeModuleInfo(LayoutModuleList const & mods);
222         ///
223         void setLanguage() const;
224         ///
225         void saveAsDefault() const;
226         ///
227         bool isFontAvailable(std::string const & font) const;
228         /// does this font provide Old Style figures?
229         bool providesOSF(std::string const & font) const;
230         /// does this font provide true Small Caps?
231         bool providesSC(std::string const & font) const;
232         /// does this font provide size adjustment?
233         bool providesScale(std::string const & font) const;
234         ///
235         void executeBranchRenaming() const;
236         ///
237         void setCustomPapersize(bool custom);
238 private:
239         ///
240         void loadModuleInfo();
241         ///
242         void updateUnknownBranches();
243         ///
244         BufferParams bp_;
245         /// List of names of available modules
246         std::list<modInfoStruct> moduleNames_;
247         ///
248         std::map<docstring, docstring> changedBranches_;
249         ///
250         std::list<std::string> includeonlys_;
251 };
252
253
254 class PreambleModule : public UiWidget<Ui::PreambleUi>
255 {
256         Q_OBJECT
257 public:
258         PreambleModule();
259         void update(BufferParams const & params, BufferId id);
260         void apply(BufferParams & params);
261
262 Q_SIGNALS:
263         /// signal that something's changed in the Widget.
264         void changed();
265
266 private:
267         void closeEvent(QCloseEvent *);
268         void on_preambleTE_textChanged() { changed(); }
269
270 private:
271         typedef std::map<BufferId, std::pair<int,int> > Coords;
272         Coords preamble_coords_;
273         BufferId current_id_;
274 };
275
276
277 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
278 {
279         Q_OBJECT
280 public:
281         LocalLayout();
282         void update(BufferParams const & params, BufferId id);
283         void apply(BufferParams & params);
284         bool isValid() const { return is_valid_; }
285
286 Q_SIGNALS:
287         /// signal that something's changed in the Widget.
288         void changed();
289
290 private:
291         void validate();
292         void convert();
293 private Q_SLOTS:
294         void textChanged();
295         void validatePressed();
296         void convertPressed();
297
298 private:
299         BufferId current_id_;
300         bool is_valid_;
301 };
302
303
304 } // namespace frontend
305 } // namespace lyx
306
307 #endif // GUIDOCUMENT_H