]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
fileformat change: support to specify a document-wide font color
[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
23 #include "ui_BiblioUi.h"
24 #include "ui_ColorUi.h"
25 #include "ui_DocumentUi.h"
26 #include "ui_FontUi.h"
27 #include "ui_LanguageUi.h"
28 #include "ui_LaTeXUi.h"
29 #include "ui_ListingsSettingsUi.h"
30 #include "ui_MarginsUi.h"
31 #include "ui_MasterChildUi.h"
32 #include "ui_MathsUi.h"
33 #include "ui_ModulesUi.h"
34 #include "ui_NumberingUi.h"
35 #include "ui_OutputUi.h"
36 #include "ui_PageLayoutUi.h"
37 #include "ui_PDFSupportUi.h"
38 #include "ui_PreambleUi.h"
39 #include "ui_TextLayoutUi.h"
40
41 namespace lyx {
42
43 class BufferParams;
44 class LayoutModuleList;
45 class TextClass;
46
47 namespace frontend {
48
49 class FloatPlacement;
50 class GuiBranches;
51 class GuiIndices;
52 class ModuleSelectionManager;
53 class PreambleModule;
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 class GuiDocument : public GuiDialog, public Ui::DocumentUi
67 {
68         Q_OBJECT
69 public:
70         GuiDocument(GuiView & lv);
71
72         void paramsToDialog();
73         void updateFontsize(std::string const &, std::string const &);
74         void updateFontlist();
75         void updateDefaultFormat();
76         void updatePagestyle(std::string const &, std::string const &);
77         bool isChildIncluded(std::string const &);
78
79         void showPreamble();
80         ///
81         BufferParams const & params() const { return bp_; }
82
83 private Q_SLOTS:
84         void updateNumbering();
85         void change_adaptor();
86         void includeonlyClicked(QTreeWidgetItem * item, int);
87         void setListingsMessage();
88         void saveDefaultClicked();
89         void useDefaultsClicked();
90         void setLSpacing(int);
91         void setMargins(bool);
92         void papersizeChanged(int);
93         void setColSep();
94         void setCustomMargins(bool);
95         void fontencChanged(int);
96         void romanChanged(int);
97         void sansChanged(int);
98         void ttChanged(int);
99         void setIndent(int);
100         void enableIndent(bool);
101         void setSkip(int);
102         void enableSkip(bool);
103         void portraitChanged();
104         void browseLayout();
105         void browseMaster();
106         void classChanged();
107         void bibtexChanged(int);
108         void updateModuleInfo();
109         void modulesChanged();
110         void changeBackgroundColor();
111         void deleteBackgroundColor();
112         void changeFontColor();
113         void deleteFontColor();
114         void changeNoteFontColor();
115         void deleteNoteFontColor();
116         void xetexChanged(bool);
117         void branchesRename(docstring const &, docstring const &);
118 private:
119         /// validate listings parameters and return an error message, if any
120         QString validateListingsParameters();
121
122         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
123         UiWidget<Ui::MasterChildUi> *masterChildModule;
124         UiWidget<Ui::FontUi> *fontModule;
125         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
126         UiWidget<Ui::MarginsUi> *marginsModule;
127         UiWidget<Ui::LanguageUi> *langModule;
128         UiWidget<Ui::ColorUi> *colorModule;
129         UiWidget<Ui::NumberingUi> *numberingModule;
130         UiWidget<Ui::BiblioUi> *biblioModule;
131         UiWidget<Ui::MathsUi> *mathsModule;
132         UiWidget<Ui::LaTeXUi> *latexModule;
133         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
134         UiWidget<Ui::ModulesUi> *modulesModule;
135         UiWidget<Ui::OutputUi> *outputModule;
136         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
137         PreambleModule * preambleModule;
138         
139         GuiBranches * branchesModule;
140         GuiIndices * indicesModule;
141
142         BulletsModule * bulletsModule;
143         FloatPlacement * floatModule;
144
145         ModuleSelectionManager * selectionManager;
146
147         /// Available modules
148         GuiIdListModel * availableModel() { return &modules_av_model_; }
149         /// Selected modules
150         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
151
152         /// Apply changes
153         void applyView();
154         /// update
155         void updateContents();
156         ///
157         void updateAvailableModules();
158         ///
159         void updateSelectedModules();
160         ///
161         void updateIncludeonlys();
162         /// save as default template
163         void saveDocDefault();
164         /// reset to default params
165         void useClassDefaults();
166         ///
167         void setLayoutComboByIDString(std::string const & idString);
168         /// available classes
169         GuiIdListModel classes_model_;
170         /// available modules
171         GuiIdListModel modules_av_model_;
172         /// selected modules
173         GuiIdListModel modules_sel_model_;
174         /// current buffer
175         BufferId current_id_;
176
177         /// return false if validate_listings_params returns error
178         bool isValid();
179
180         /// font family names for BufferParams::fontsDefaultFamily
181         static char const * const fontfamilies[5];
182         /// GUI names corresponding fontfamilies
183         static char const * fontfamilies_gui[5];
184         ///
185         bool initialiseParams(std::string const & data);
186         ///
187         void clearParams();
188         ///
189         void dispatchParams();
190         ///
191         void modulesToParams(BufferParams &);
192         ///
193         bool isBufferDependent() const { return true; }
194         /// always true since we don't manipulate document contents
195         bool canApply() const { return true; }
196         ///
197         DocumentClass const & documentClass() const;
198         ///
199         BufferParams & params() { return bp_; }
200         ///
201         BufferId id() const;
202         ///
203         struct modInfoStruct {
204                 QString name;
205                 std::string id;
206                 QString description;
207         };
208         /// List of available modules
209         std::list<modInfoStruct> const & getModuleInfo();
210         /// Modules in use in current buffer
211         std::list<modInfoStruct> const getSelectedModules();
212         ///
213         std::list<modInfoStruct> const getProvidedModules();
214         ///
215         std::list<modInfoStruct> const 
216                         makeModuleInfo(LayoutModuleList const & mods);
217         ///
218         void setLanguage() const;
219         ///
220         void saveAsDefault() const;
221         ///
222         bool isFontAvailable(std::string const & font) const;
223         /// does this font provide Old Style figures?
224         bool providesOSF(std::string const & font) const;
225         /// does this font provide true Small Caps?
226         bool providesSC(std::string const & font) const;
227         /// does this font provide size adjustment?
228         bool providesScale(std::string const & font) const;
229         ///
230         void executeBranchRenaming() const;
231         ///
232         void setCustomPapersize(bool custom);
233 private:
234         ///
235         void loadModuleInfo();
236         ///
237         void updateUnknownBranches();
238         ///
239         BufferParams bp_;
240         /// List of names of available modules
241         std::list<modInfoStruct> moduleNames_;
242         ///
243         std::map<docstring, docstring> changedBranches_;
244         ///
245         std::list<std::string> includeonlys_;
246 };
247
248
249 class PreambleModule : public UiWidget<Ui::PreambleUi>
250 {
251         Q_OBJECT
252 public:
253         PreambleModule();
254         void update(BufferParams const & params, BufferId id);
255         void apply(BufferParams & params);
256
257 Q_SIGNALS:
258         /// signal that something's changed in the Widget.
259         void changed();
260
261 private:
262         void closeEvent(QCloseEvent *);
263         void on_preambleTE_textChanged() { changed(); }
264
265 private:
266         typedef std::map<BufferId, std::pair<int,int> > Coords;
267         Coords preamble_coords_;
268         BufferId current_id_;
269 };
270
271
272 } // namespace frontend
273 } // namespace lyx
274
275 #endif // GUIDOCUMENT_H