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