]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Rename is_valid_ as validated_, which is a bit more informative.
[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 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 setIndent(int);
102         void enableIndent(bool);
103         void setSkip(int);
104         void enableSkip(bool);
105         void browseLayout();
106         void browseMaster();
107         void classChanged();
108         void languagePackageChanged(int);
109         void biblioChanged();
110         void bibtexChanged(int);
111         void setAuthorYear(bool);
112         void setNumerical(bool);
113         void updateModuleInfo();
114         void modulesChanged();
115         void changeBackgroundColor();
116         void deleteBackgroundColor();
117         void changeFontColor();
118         void deleteFontColor();
119         void changeNoteFontColor();
120         void deleteNoteFontColor();
121         void changeBoxBackgroundColor();
122         void deleteBoxBackgroundColor();
123         void osFontsChanged(bool);
124         void branchesRename(docstring const &, docstring const &);
125 private:
126         /// validate listings parameters and return an error message, if any
127         QString validateListingsParameters();
128
129         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
130         UiWidget<Ui::MasterChildUi> *masterChildModule;
131         UiWidget<Ui::FontUi> *fontModule;
132         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
133         UiWidget<Ui::MarginsUi> *marginsModule;
134         UiWidget<Ui::LanguageUi> *langModule;
135         UiWidget<Ui::ColorUi> *colorModule;
136         UiWidget<Ui::NumberingUi> *numberingModule;
137         UiWidget<Ui::BiblioUi> *biblioModule;
138         UiWidget<Ui::MathsUi> *mathsModule;
139         UiWidget<Ui::LaTeXUi> *latexModule;
140         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
141         UiWidget<Ui::ModulesUi> *modulesModule;
142         UiWidget<Ui::OutputUi> *outputModule;
143         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
144         PreambleModule * preambleModule;
145         LocalLayout * localLayout;
146
147         GuiBranches * branchesModule;
148         GuiIndices * indicesModule;
149
150         BulletsModule * bulletsModule;
151         FloatPlacement * floatModule;
152
153         ModuleSelectionManager * selectionManager;
154
155         /// Available modules
156         GuiIdListModel * availableModel() { return &modules_av_model_; }
157         /// Selected modules
158         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
159
160         /// Apply changes
161         void applyView();
162         /// update
163         void updateContents();
164         ///
165         void updateAvailableModules();
166         ///
167         void updateSelectedModules();
168         ///
169         void updateIncludeonlys();
170         /// save as default template
171         void saveDocDefault();
172         /// reset to default params
173         void useClassDefaults();
174         ///
175         void setLayoutComboByIDString(std::string const & idString);
176
177         /// available classes
178         GuiIdListModel classes_model_;
179         /// available modules
180         GuiIdListModel modules_av_model_;
181         /// selected modules
182         GuiIdListModel modules_sel_model_;
183         /// current buffer
184         BufferId current_id_;
185
186         /// return false if validate_listings_params returns error
187         bool isValid();
188
189         /// font family names for BufferParams::fonts_default_family
190         static char const * const fontfamilies[5];
191         /// GUI names corresponding fontfamilies
192         static char const * fontfamilies_gui[5];
193         ///
194         bool initialiseParams(std::string const & data);
195         ///
196         void clearParams();
197         ///
198         void dispatchParams();
199         ///
200         void modulesToParams(BufferParams &);
201         ///
202         bool isBufferDependent() const { return true; }
203         /// always true since we don't manipulate document contents
204         bool canApply() const { return true; }
205         ///
206         DocumentClass const & documentClass() const;
207         ///
208         BufferParams & params() { return bp_; }
209         ///
210         BufferId id() const;
211         ///
212         struct modInfoStruct {
213                 QString name;
214                 std::string id;
215                 QString description;
216         };
217         /// List of available modules
218         std::list<modInfoStruct> const & getModuleInfo();
219         /// Modules in use in current buffer
220         std::list<modInfoStruct> const getSelectedModules();
221         ///
222         std::list<modInfoStruct> const getProvidedModules();
223         ///
224         std::list<modInfoStruct> const
225                         makeModuleInfo(LayoutModuleList const & mods);
226         ///
227         void setLanguage() const;
228         ///
229         void saveAsDefault() const;
230         ///
231         bool isFontAvailable(std::string const & font) const;
232         /// does this font provide Old Style figures?
233         bool providesOSF(std::string const & font) const;
234         /// does this font provide true Small Caps?
235         bool providesSC(std::string const & font) const;
236         /// does this font provide size adjustment?
237         bool providesScale(std::string const & font) const;
238         ///
239         void executeBranchRenaming() const;
240         ///
241         void setCustomPapersize(bool custom);
242 private:
243         ///
244         void loadModuleInfo();
245         ///
246         void updateUnknownBranches();
247         ///
248         BufferParams bp_;
249         /// List of names of available modules
250         std::list<modInfoStruct> moduleNames_;
251         ///
252         std::map<docstring, docstring> changedBranches_;
253         ///
254         std::list<std::string> includeonlys_;
255         ///
256         bool biblioChanged_;
257 };
258
259
260 class PreambleModule : public UiWidget<Ui::PreambleUi>
261 {
262         Q_OBJECT
263 public:
264         PreambleModule();
265         void update(BufferParams const & params, BufferId id);
266         void apply(BufferParams & params);
267
268 Q_SIGNALS:
269         /// signal that something's changed in the Widget.
270         void changed();
271
272 private:
273         void closeEvent(QCloseEvent *);
274         void on_preambleTE_textChanged() { changed(); }
275
276 private:
277         typedef std::map<BufferId, std::pair<int,int> > Coords;
278         Coords preamble_coords_;
279         BufferId current_id_;
280 };
281
282
283 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
284 {
285         Q_OBJECT
286 public:
287         LocalLayout();
288         void update(BufferParams const & params, BufferId id);
289         void apply(BufferParams & params);
290         bool isValid() const { return validated_; }
291
292 Q_SIGNALS:
293         /// signal that something's changed in the Widget.
294         void changed();
295
296 private:
297         void validate();
298         void convert();
299 private Q_SLOTS:
300         void textChanged();
301         void validatePressed();
302         void convertPressed();
303
304 private:
305         BufferId current_id_;
306         bool validated_;
307 };
308
309
310 } // namespace frontend
311 } // namespace lyx
312
313 #endif // GUIDOCUMENT_H