]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
math stuff
[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 "GuiDialog.h"
17 #include "BulletsModule.h"
18 #include "GuiSelectionManager.h"
19 #include "BufferParams.h"
20
21 #include "support/FileName.h"
22 #include "support/filetools.h"
23 #include "support/types.h"
24
25 #include "ui_DocumentUi.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 typedef void const * BufferId;
55 ///
56 typedef std::map<std::string, support::FileName> ModuleMap;
57
58 #include <QDialog>
59 #include <QStringList>
60 #include <QStringListModel>
61
62 #include <vector>
63 #include <string>
64
65 template<class UI>
66 class UiWidget : public QWidget, public UI
67 {
68 public:
69         UiWidget(QWidget * parent = 0) : QWidget(parent) { UI::setupUi(this); }
70 };
71
72
73 class GuiDocument : public GuiDialog, public Ui::DocumentUi, public Controller
74 {
75         Q_OBJECT
76 public:
77         GuiDocument(LyXView & lv);
78
79         void updateParams(BufferParams const & params);
80         void apply(BufferParams & params);
81
82         void updateFontsize(std::string const &, std::string const &);
83         void updatePagestyle(std::string const &, std::string const &);
84
85         void showPreamble();
86         /// validate listings parameters and return an error message, if any
87         docstring validate_listings_params();
88
89 public Q_SLOTS:
90         void updateNumbering();
91         void change_adaptor();
92         void set_listings_msg();
93         void saveDefaultClicked();
94         void useDefaultsClicked();
95
96 private Q_SLOTS:
97         void updateParams();
98         void setLSpacing(int);
99         void setMargins(bool);
100         void setCustomPapersize(int);
101         void setCustomMargins(bool);
102         void romanChanged(int);
103         void sansChanged(int);
104         void ttChanged(int);
105         void setSkip(int);
106         void enableSkip(bool);
107         void portraitChanged();
108         void classChanged();
109         void updateModuleInfo();
110         
111 private:
112         void closeEvent(QCloseEvent * e);
113
114 private:
115         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
116         UiWidget<Ui::FontUi> *fontModule;
117         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
118         UiWidget<Ui::MarginsUi> *marginsModule;
119         UiWidget<Ui::LanguageUi> *langModule;
120         UiWidget<Ui::NumberingUi> *numberingModule;
121         UiWidget<Ui::BiblioUi> *biblioModule;
122         UiWidget<Ui::MathsUi> *mathsModule;
123         UiWidget<Ui::LaTeXUi> *latexModule;
124         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
125         PreambleModule *preambleModule;
126         
127         GuiBranches *branchesModule;
128
129         BulletsModule * bulletsModule;
130         FloatPlacement * floatModule;
131
132         GuiSelectionManager * selectionManager;
133
134         // FIXME
135         std::vector<std::string> lang_;
136
137         /// parent controller
138         Controller & controller() { return *this; }
139         /// Available modules
140         QStringListModel * availableModel() { return &available_model_; }
141         /// Selected modules
142         QStringListModel * selectedModel() { return &selected_model_; }
143 private:
144         /// Apply changes
145         void applyView();
146         /// update
147         void updateContents();
148         /// save as default template
149         void saveDocDefault();
150         /// reset to default params
151         void useClassDefaults();
152         /// available modules
153         QStringListModel available_model_;
154         /// selected modules
155         QStringListModel selected_model_;
156
157 protected:
158         /// return false if validate_listings_params returns error
159         bool isValid();
160
161         /// font family names for BufferParams::fontsDefaultFamily
162         static char const * const fontfamilies[5];
163         /// GUI names corresponding fontfamilies
164         static char const * fontfamilies_gui[5];
165         ///
166         bool initialiseParams(std::string const & data);
167         ///
168         void clearParams();
169         ///
170         void dispatchParams();
171         ///
172         bool isBufferDependent() const { return true; }
173         /// always true since we don't manipulate document contents
174         bool canApply() const { return true; }
175         ///
176         TextClass const & textClass() const;
177         ///
178         BufferParams & params() { return bp_; }
179         ///
180         BufferParams const & params() const { return bp_; }
181         ///
182         BufferId id() const;
183         /// List of available modules
184         std::vector<std::string> getModuleNames();
185         /// Modules in use in current buffer
186         std::vector<std::string> const & getSelectedModules();
187         ///
188         std::string getModuleDescription(std::string const & modName) const;
189         ///
190         std::vector<std::string> getPackageList(std::string const & modName) const;
191         ///
192         void setLanguage() const;
193         ///
194         void saveAsDefault() const;
195         ///
196         bool isFontAvailable(std::string const & font) const;
197         /// does this font provide Old Style figures?
198         bool providesOSF(std::string const & font) const;
199         /// does this font provide true Small Caps?
200         bool providesSC(std::string const & font) const;
201         /// does this font provide size adjustment?
202         bool providesScale(std::string const & font) const;
203 private:
204         ///
205         void loadModuleNames();
206         ///
207         BufferParams bp_;
208         /// List of names of available modules
209         std::vector<std::string> moduleNames_;
210 };
211
212
213 typedef void const * BufferId;
214
215
216 class PreambleModule : public UiWidget<Ui::PreambleUi>
217 {
218         Q_OBJECT
219 public:
220         PreambleModule();
221         void update(BufferParams const & params, BufferId id);
222         void apply(BufferParams & params);
223
224 Q_SIGNALS:
225         /// signal that something's changed in the Widget.
226         void changed();
227
228 private:
229         void closeEvent(QCloseEvent *);
230         void on_preambleTE_textChanged() { changed(); }
231
232 private:
233         typedef std::map<BufferId, std::pair<int,int> > Coords;
234         Coords preamble_coords_;
235         BufferId current_id_;
236 };
237
238
239 } // namespace frontend
240 } // namespace lyx
241
242 #endif // QDOCUMENT_H