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