]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Restore Andre's TextClassIndex, but now in the form of BaseClassIndex. It seems worth...
[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 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 typedef void const * BufferId;
102
103
104 class GuiDocument : public GuiDialog, public Ui::DocumentUi
105 {
106         Q_OBJECT
107 public:
108         GuiDocument(GuiView & lv);
109
110         void updateParams(BufferParams const & params);
111         void apply(BufferParams & params);
112
113         void updateFontsize(std::string const &, std::string const &);
114         void updatePagestyle(std::string const &, std::string const &);
115
116         void showPreamble();
117         /// validate listings parameters and return an error message, if any
118         docstring validate_listings_params();
119
120 public Q_SLOTS:
121         void updateNumbering();
122         void change_adaptor();
123         void set_listings_msg();
124         void saveDefaultClicked();
125         void useDefaultsClicked();
126
127 private Q_SLOTS:
128         void updateParams();
129         void setLSpacing(int);
130         void setMargins(bool);
131         void setCustomPapersize(int);
132         void setColSep();
133         void setCustomMargins(bool);
134         void romanChanged(int);
135         void sansChanged(int);
136         void ttChanged(int);
137         void setSkip(int);
138         void enableSkip(bool);
139         void portraitChanged();
140         void classChanged();
141         void updateModuleInfo();
142         void updateEmbeddedFileList();
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         // FIXME
166         std::vector<std::string> lang_;
167
168         /// Available modules
169         GuiIdListModel * availableModel() { return &available_model_; }
170         /// Selected modules
171         GuiIdListModel * selectedModel() { return &selected_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         /// available modules
188         GuiIdListModel available_model_;
189         /// selected modules
190         GuiIdListModel selected_model_;
191         /// current buffer
192         BufferId current_id_;
193
194 protected:
195         /// return false if validate_listings_params returns error
196         bool isValid();
197
198         /// font family names for BufferParams::fontsDefaultFamily
199         static char const * const fontfamilies[5];
200         /// GUI names corresponding fontfamilies
201         static char const * fontfamilies_gui[5];
202         ///
203         bool initialiseParams(std::string const & data);
204         ///
205         void clearParams();
206         ///
207         void dispatchParams();
208         ///
209         bool isBufferDependent() const { return true; }
210         /// always true since we don't manipulate document contents
211         bool canApply() const { return true; }
212         ///
213         TextClass const & textClass() const;
214         ///
215         BufferParams & params() { return bp_; }
216         ///
217         BufferParams const & params() const { return bp_; }
218         ///
219         BufferId id() const;
220         ///
221         struct modInfoStruct {
222                 std::string name;
223                 std::string id;
224         };
225         /// List of available modules
226         std::vector<modInfoStruct> const & getModuleInfo();
227         /// Modules in use in current buffer
228         std::vector<modInfoStruct> const getSelectedModules();
229         ///
230         void setLanguage() const;
231         ///
232         void saveAsDefault() const;
233         ///
234         bool isFontAvailable(std::string const & font) const;
235         /// does this font provide Old Style figures?
236         bool providesOSF(std::string const & font) const;
237         /// does this font provide true Small Caps?
238         bool providesSC(std::string const & font) const;
239         /// does this font provide size adjustment?
240         bool providesScale(std::string const & font) const;
241 private:
242         ///
243         void loadModuleInfo();
244         ///
245         BufferParams bp_;
246         /// List of names of available modules
247         std::vector<modInfoStruct> moduleNames_;
248 };
249
250
251 class PreambleModule : public UiWidget<Ui::PreambleUi>
252 {
253         Q_OBJECT
254 public:
255         PreambleModule();
256         void update(BufferParams const & params, BufferId id);
257         void apply(BufferParams & params);
258
259 Q_SIGNALS:
260         /// signal that something's changed in the Widget.
261         void changed();
262
263 private:
264         void closeEvent(QCloseEvent *);
265         void on_preambleTE_textChanged() { changed(); }
266
267 private:
268         typedef std::map<BufferId, std::pair<int,int> > Coords;
269         Coords preamble_coords_;
270         BufferId current_id_;
271 };
272
273
274 } // namespace frontend
275 } // namespace lyx
276
277 #endif // GUIDOCUMENT_H