]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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_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 classChanged();
139         void updateModuleInfo();
140
141 private:
142         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
143         UiWidget<Ui::FontUi> *fontModule;
144         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
145         UiWidget<Ui::MarginsUi> *marginsModule;
146         UiWidget<Ui::LanguageUi> *langModule;
147         UiWidget<Ui::NumberingUi> *numberingModule;
148         UiWidget<Ui::BiblioUi> *biblioModule;
149         UiWidget<Ui::MathsUi> *mathsModule;
150         UiWidget<Ui::LaTeXUi> *latexModule;
151         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
152         PreambleModule *preambleModule;
153         
154         GuiBranches *branchesModule;
155
156         BulletsModule * bulletsModule;
157         FloatPlacement * floatModule;
158
159         GuiSelectionManager * selectionManager;
160
161         ///
162         QStringList lang_;
163
164         /// Available modules
165         GuiIdListModel * availableModel() { return &modules_av_model_; }
166         /// Selected modules
167         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
168 private:
169         /// Apply changes
170         void applyView();
171         /// update
172         void updateContents();
173         /// force content update
174         void forceUpdate();
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         ///
184         void setLayoutComboByIDString(std::string const & idString);
185         /// available classes
186         GuiIdListModel classes_model_;
187         /// available modules
188         GuiIdListModel modules_av_model_;
189         /// selected modules
190         GuiIdListModel modules_sel_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         DocumentClass const & documentClass() 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                 QString name;
223                 std::string id;
224                 QString description;
225         };
226         /// List of available modules
227         std::vector<modInfoStruct> const & getModuleInfo();
228         /// Modules in use in current buffer
229         std::vector<modInfoStruct> const getSelectedModules();
230         ///
231         void setLanguage() const;
232         ///
233         void saveAsDefault() const;
234         ///
235         bool isFontAvailable(std::string const & font) const;
236         /// does this font provide Old Style figures?
237         bool providesOSF(std::string const & font) const;
238         /// does this font provide true Small Caps?
239         bool providesSC(std::string const & font) const;
240         /// does this font provide size adjustment?
241         bool providesScale(std::string const & font) const;
242 private:
243         ///
244         void loadModuleInfo();
245         ///
246         BufferParams bp_;
247         /// List of names of available modules
248         std::vector<modInfoStruct> moduleNames_;
249 };
250
251
252 class PreambleModule : public UiWidget<Ui::PreambleUi>
253 {
254         Q_OBJECT
255 public:
256         PreambleModule();
257         void update(BufferParams const & params, BufferId id);
258         void apply(BufferParams & params);
259
260 Q_SIGNALS:
261         /// signal that something's changed in the Widget.
262         void changed();
263
264 private:
265         void closeEvent(QCloseEvent *);
266         void on_preambleTE_textChanged() { changed(); }
267
268 private:
269         typedef std::map<BufferId, std::pair<int,int> > Coords;
270         Coords preamble_coords_;
271         BufferId current_id_;
272 };
273
274
275 } // namespace frontend
276 } // namespace lyx
277
278 #endif // GUIDOCUMENT_H