]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
remove duplicated code, (fix cmake merge)
[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 QModelIndex getSelectedIndex(QListView * lv);
57
58 ///
59 typedef void const * BufferId;
60
61 template<class UI>
62 class UiWidget : public QWidget, public UI
63 {
64 public:
65         UiWidget(QWidget * parent = 0) : QWidget(parent) { UI::setupUi(this); }
66 };
67
68
69 class ModuleSelMan : public GuiSelectionManager 
70 {
71 public:
72         ModuleSelMan(
73                 QListView * availableLV, 
74                 QListView * selectedLV,
75                 QPushButton * addPB, 
76                 QPushButton * delPB, 
77                 QPushButton * upPB, 
78                 QPushButton * downPB,
79                 GuiIdListModel * availableModel,
80                 GuiIdListModel * selectedModel);
81 private:
82         ///
83         virtual void updateAddPB();
84         ///
85         virtual void updateUpPB();
86         ///
87         virtual void updateDownPB();
88         ///
89         virtual void updateDelPB();
90         /// returns availableModel as a GuiIdListModel
91         GuiIdListModel * getAvailableModel() 
92         {
93                 return dynamic_cast<GuiIdListModel *>(availableModel);
94         };
95         /// returns selectedModel as a GuiIdListModel
96         GuiIdListModel * getSelectedModel() 
97         {
98                 return dynamic_cast<GuiIdListModel *>(selectedModel);
99         };
100 };
101
102
103 class GuiDocument : public GuiDialog, public Ui::DocumentUi
104 {
105         Q_OBJECT
106 public:
107         GuiDocument(GuiView & lv);
108
109         void updateParams(BufferParams const & params);
110         void apply(BufferParams & params);
111
112         void updateFontsize(std::string const &, std::string const &);
113         void updatePagestyle(std::string const &, std::string const &);
114
115         void showPreamble();
116         /// validate listings parameters and return an error message, if any
117         docstring validate_listings_params();
118
119 public Q_SLOTS:
120         void updateNumbering();
121         void change_adaptor();
122         void set_listings_msg();
123         void saveDefaultClicked();
124         void useDefaultsClicked();
125
126 private Q_SLOTS:
127         void updateParams();
128         void setLSpacing(int);
129         void setMargins(bool);
130         void setCustomPapersize(int);
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         void closeEvent(QCloseEvent * e);
144
145 private:
146         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
147         UiWidget<Ui::FontUi> *fontModule;
148         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
149         UiWidget<Ui::MarginsUi> *marginsModule;
150         UiWidget<Ui::LanguageUi> *langModule;
151         UiWidget<Ui::NumberingUi> *numberingModule;
152         UiWidget<Ui::BiblioUi> *biblioModule;
153         UiWidget<Ui::MathsUi> *mathsModule;
154         UiWidget<Ui::LaTeXUi> *latexModule;
155         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
156         UiWidget<Ui::EmbeddedFilesUi> *embeddedFilesModule;
157         PreambleModule *preambleModule;
158         
159         GuiBranches *branchesModule;
160
161         BulletsModule * bulletsModule;
162         FloatPlacement * floatModule;
163
164         GuiSelectionManager * selectionManager;
165
166         // FIXME
167         std::vector<std::string> lang_;
168
169         /// Available modules
170         GuiIdListModel * availableModel() { return &available_model_; }
171         /// Selected modules
172         GuiIdListModel * selectedModel() { return &selected_model_; }
173 private:
174         /// Apply changes
175         void applyView();
176         /// update
177         void updateContents();
178         ///
179         void updateAvailableModules();
180         ///
181         void updateSelectedModules();
182         /// save as default template
183         void saveDocDefault();
184         /// reset to default params
185         void useClassDefaults();
186         /// available modules
187         GuiIdListModel available_model_;
188         /// selected modules
189         GuiIdListModel selected_model_;
190
191 protected:
192         /// return false if validate_listings_params returns error
193         bool isValid();
194
195         /// font family names for BufferParams::fontsDefaultFamily
196         static char const * const fontfamilies[5];
197         /// GUI names corresponding fontfamilies
198         static char const * fontfamilies_gui[5];
199         ///
200         bool initialiseParams(std::string const & data);
201         ///
202         void clearParams();
203         ///
204         void dispatchParams();
205         ///
206         bool isBufferDependent() const { return true; }
207         /// always true since we don't manipulate document contents
208         bool canApply() const { return true; }
209         ///
210         TextClass const & textClass() const;
211         ///
212         BufferParams & params() { return bp_; }
213         ///
214         BufferParams const & params() const { return bp_; }
215         ///
216         BufferId id() const;
217         ///
218         struct modInfoStruct {
219                 std::string name;
220                 std::string id;
221         };
222         /// List of available modules
223         std::vector<modInfoStruct> const & getModuleInfo();
224         /// Modules in use in current buffer
225         std::vector<modInfoStruct> const getSelectedModules();
226         ///
227         void setLanguage() const;
228         ///
229         void saveAsDefault() const;
230         ///
231         bool isFontAvailable(std::string const & font) const;
232         /// does this font provide Old Style figures?
233         bool providesOSF(std::string const & font) const;
234         /// does this font provide true Small Caps?
235         bool providesSC(std::string const & font) const;
236         /// does this font provide size adjustment?
237         bool providesScale(std::string const & font) const;
238 private:
239         ///
240         void loadModuleInfo();
241         ///
242         BufferParams bp_;
243         /// List of names of available modules
244         std::vector<modInfoStruct> moduleNames_;
245 };
246
247
248 typedef void const * BufferId;
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