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