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