]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
do what the FIXME suggested
[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 "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 updateEmbeddedFileList();
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 &modules_av_model_; }
168         /// Selected modules
169         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
170 private:
171         /// Apply changes
172         void applyView();
173         /// update
174         void updateContents();
175         /// force content update
176         void forceUpdate();
177         ///
178         void updateAvailableModules();
179         ///
180         void updateSelectedModules();
181         /// save as default template
182         void saveDocDefault();
183         /// reset to default params
184         void useClassDefaults();
185         ///
186         void setLayoutComboByIDString(std::string const & idString);
187         /// available classes
188         GuiIdListModel classes_model_;
189         /// available modules
190         GuiIdListModel modules_av_model_;
191         /// selected modules
192         GuiIdListModel modules_sel_model_;
193         /// current buffer
194         BufferId current_id_;
195
196 protected:
197         /// return false if validate_listings_params returns error
198         bool isValid();
199
200         /// font family names for BufferParams::fontsDefaultFamily
201         static char const * const fontfamilies[5];
202         /// GUI names corresponding fontfamilies
203         static char const * fontfamilies_gui[5];
204         ///
205         bool initialiseParams(std::string const & data);
206         ///
207         void clearParams();
208         ///
209         void dispatchParams();
210         ///
211         bool isBufferDependent() const { return true; }
212         /// always true since we don't manipulate document contents
213         bool canApply() const { return true; }
214         ///
215         DocumentClass const & documentClass() const;
216         ///
217         BufferParams & params() { return bp_; }
218         ///
219         BufferParams const & params() const { return bp_; }
220         ///
221         BufferId id() const;
222         ///
223         struct modInfoStruct {
224                 std::string name;
225                 std::string id;
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