]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiDocument.h
support for default master document.
[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 #include "GuiSelectionManager.h"
23
24 #include "ui_DocumentUi.h"
25 #include "ui_FontUi.h"
26 #include "ui_TextLayoutUi.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
37 #include <map>
38 #include <vector>
39
40 class FloatPlacement;
41
42 namespace lyx {
43
44 class BufferParams;
45 class TextClass;
46
47 namespace frontend {
48
49 class GuiBranches;
50 class PreambleModule;
51
52 ///
53 QModelIndex getSelectedIndex(QListView * lv);
54
55 ///
56 typedef void const * BufferId;
57
58 template<class UI>
59 class UiWidget : public QWidget, public UI
60 {
61 public:
62         UiWidget(QWidget * parent = 0) : QWidget(parent) { UI::setupUi(this); }
63 };
64
65
66 /// SelectionManager for use with modules
67 class ModuleSelMan : public GuiSelectionManager 
68 {
69 public:
70         ModuleSelMan(
71                 QListView * availableLV, 
72                 QListView * selectedLV,
73                 QPushButton * addPB, 
74                 QPushButton * delPB, 
75                 QPushButton * upPB, 
76                 QPushButton * downPB,
77                 GuiIdListModel * availableModel,
78                 GuiIdListModel * selectedModel);
79 private:
80         ///
81         virtual void updateAddPB();
82         ///
83         virtual void updateUpPB();
84         ///
85         virtual void updateDownPB();
86         ///
87         virtual void updateDelPB();
88         /// returns availableModel as a GuiIdListModel
89         GuiIdListModel * getAvailableModel() 
90         {
91                 return dynamic_cast<GuiIdListModel *>(availableModel);
92         };
93         /// returns selectedModel as a GuiIdListModel
94         GuiIdListModel * getSelectedModel() 
95         {
96                 return dynamic_cast<GuiIdListModel *>(selectedModel);
97         };
98 };
99
100
101 class GuiDocument : public GuiDialog, public Ui::DocumentUi
102 {
103         Q_OBJECT
104 public:
105         GuiDocument(GuiView & lv);
106
107         void updateParams(BufferParams const & params);
108         void apply(BufferParams & params);
109
110         void updateFontsize(std::string const &, std::string const &);
111         void updatePagestyle(std::string const &, std::string const &);
112
113         void showPreamble();
114         /// validate listings parameters and return an error message, if any
115         docstring validate_listings_params();
116
117 public Q_SLOTS:
118         void updateNumbering();
119         void change_adaptor();
120         void set_listings_msg();
121         void saveDefaultClicked();
122         void useDefaultsClicked();
123
124 private Q_SLOTS:
125         void updateParams();
126         void setLSpacing(int);
127         void setMargins(bool);
128         void setCustomPapersize(int);
129         void setColSep();
130         void setCustomMargins(bool);
131         void romanChanged(int);
132         void sansChanged(int);
133         void ttChanged(int);
134         void setSkip(int);
135         void enableSkip(bool);
136         void portraitChanged();
137         void browseLayout();
138         void browseMaster();
139         void classChanged();
140         void updateModuleInfo();
141
142 private:
143         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
144         UiWidget<Ui::FontUi> *fontModule;
145         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
146         UiWidget<Ui::MarginsUi> *marginsModule;
147         UiWidget<Ui::LanguageUi> *langModule;
148         UiWidget<Ui::NumberingUi> *numberingModule;
149         UiWidget<Ui::BiblioUi> *biblioModule;
150         UiWidget<Ui::MathsUi> *mathsModule;
151         UiWidget<Ui::LaTeXUi> *latexModule;
152         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
153         PreambleModule *preambleModule;
154         
155         GuiBranches *branchesModule;
156
157         BulletsModule * bulletsModule;
158         FloatPlacement * floatModule;
159
160         GuiSelectionManager * selectionManager;
161
162         ///
163         QStringList lang_;
164
165         /// Available modules
166         GuiIdListModel * availableModel() { return &modules_av_model_; }
167         /// Selected modules
168         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
169 private:
170         /// Apply changes
171         void applyView();
172         /// update
173         void updateContents();
174         /// force content update
175         void forceUpdate();
176         ///
177         void updateAvailableModules();
178         ///
179         void updateSelectedModules();
180         /// save as default template
181         void saveDocDefault();
182         /// reset to default params
183         void useClassDefaults();
184         ///
185         void setLayoutComboByIDString(std::string const & idString);
186         /// available classes
187         GuiIdListModel classes_model_;
188         /// available modules
189         GuiIdListModel modules_av_model_;
190         /// selected modules
191         GuiIdListModel modules_sel_model_;
192         /// current buffer
193         BufferId current_id_;
194
195 protected:
196         /// return false if validate_listings_params returns error
197         bool isValid();
198
199         /// font family names for BufferParams::fontsDefaultFamily
200         static char const * const fontfamilies[5];
201         /// GUI names corresponding fontfamilies
202         static char const * fontfamilies_gui[5];
203         ///
204         bool initialiseParams(std::string const & data);
205         ///
206         void clearParams();
207         ///
208         void dispatchParams();
209         ///
210         bool isBufferDependent() const { return true; }
211         /// always true since we don't manipulate document contents
212         bool canApply() const { return true; }
213         ///
214         DocumentClass const & documentClass() const;
215         ///
216         BufferParams & params() { return bp_; }
217         ///
218         BufferParams const & params() const { return bp_; }
219         ///
220         BufferId id() const;
221         ///
222         struct modInfoStruct {
223                 QString name;
224                 std::string id;
225                 QString description;
226         };
227         /// List of available modules
228         std::vector<modInfoStruct> const & getModuleInfo();
229         /// Modules in use in current buffer
230         std::vector<modInfoStruct> const getSelectedModules();
231         ///
232         void setLanguage() const;
233         ///
234         void saveAsDefault() const;
235         ///
236         bool isFontAvailable(std::string const & font) const;
237         /// does this font provide Old Style figures?
238         bool providesOSF(std::string const & font) const;
239         /// does this font provide true Small Caps?
240         bool providesSC(std::string const & font) const;
241         /// does this font provide size adjustment?
242         bool providesScale(std::string const & font) const;
243 private:
244         ///
245         void loadModuleInfo();
246         ///
247         BufferParams bp_;
248         /// List of names of available modules
249         std::vector<modInfoStruct> moduleNames_;
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 } // namespace frontend
277 } // namespace lyx
278
279 #endif // GUIDOCUMENT_H