]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
On Linux show in crash message box the backtrace
[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 "BufferParams.h"
17 #include "BulletsModule.h"
18 #include "GuiDialog.h"
19 #include "GuiIdListModel.h"
20
21 #include "ui_BiblioUi.h"
22 #include "ui_ColorUi.h"
23 #include "ui_DocumentUi.h"
24 #include "ui_FontUi.h"
25 #include "ui_LanguageUi.h"
26 #include "ui_LaTeXUi.h"
27 #include "ui_ListingsSettingsUi.h"
28 #include "ui_LocalLayoutUi.h"
29 #include "ui_MarginsUi.h"
30 #include "ui_MasterChildUi.h"
31 #include "ui_MathsUi.h"
32 #include "ui_ModulesUi.h"
33 #include "ui_NumberingUi.h"
34 #include "ui_OutputUi.h"
35 #include "ui_PageLayoutUi.h"
36 #include "ui_PDFSupportUi.h"
37 #include "ui_PreambleUi.h"
38 #include "ui_TextLayoutUi.h"
39
40 namespace lyx {
41
42 class BufferParams;
43 class LayoutModuleList;
44 class TextClass;
45
46 namespace frontend {
47
48 class FloatPlacement;
49 class GuiBranches;
50 class GuiIndices;
51 class ModuleSelectionManager;
52 class PreambleModule;
53 class LocalLayout;
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 updateEngineType(std::string const &, CiteEngineType const &);
77         void updatePagestyle(std::string const &, std::string const &);
78         bool isChildIncluded(std::string const &);
79
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();
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 fontOsfToggled(bool state);
100         void fontScToggled(bool state);
101         void setIndent(int);
102         void enableIndent(bool);
103         void setSkip(int);
104         void enableSkip(bool);
105         void browseLayout();
106         void browseMaster();
107         void classChanged();
108         void languagePackageChanged(int);
109         void biblioChanged();
110         void bibtexChanged(int);
111         void setAuthorYear(bool);
112         void setNumerical(bool);
113         void updateModuleInfo();
114         void modulesChanged();
115         void changeBackgroundColor();
116         void deleteBackgroundColor();
117         void changeFontColor();
118         void deleteFontColor();
119         void changeNoteFontColor();
120         void deleteNoteFontColor();
121         void changeBoxBackgroundColor();
122         void deleteBoxBackgroundColor();
123         void languageChanged(int);
124         void osFontsChanged(bool);
125         void mathFontChanged(int);
126         void branchesRename(docstring const &, docstring const &);
127         void allPackagesAuto();
128         void allPackagesAlways();
129         void allPackagesNot();
130 private:
131         /// validate listings parameters and return an error message, if any
132         QString validateListingsParameters();
133
134         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
135         UiWidget<Ui::MasterChildUi> *masterChildModule;
136         UiWidget<Ui::FontUi> *fontModule;
137         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
138         UiWidget<Ui::MarginsUi> *marginsModule;
139         UiWidget<Ui::LanguageUi> *langModule;
140         UiWidget<Ui::ColorUi> *colorModule;
141         UiWidget<Ui::NumberingUi> *numberingModule;
142         UiWidget<Ui::BiblioUi> *biblioModule;
143         UiWidget<Ui::MathsUi> *mathsModule;
144         UiWidget<Ui::LaTeXUi> *latexModule;
145         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
146         UiWidget<Ui::ModulesUi> *modulesModule;
147         UiWidget<Ui::OutputUi> *outputModule;
148         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
149         PreambleModule * preambleModule;
150         LocalLayout * localLayout;
151
152         GuiBranches * branchesModule;
153         GuiIndices * indicesModule;
154
155         BulletsModule * bulletsModule;
156         FloatPlacement * floatModule;
157
158         ModuleSelectionManager * selectionManager;
159
160         /// Available modules
161         GuiIdListModel * availableModel() { return &modules_av_model_; }
162         /// Selected modules
163         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
164
165         /// Apply changes
166         void applyView();
167         /// update
168         void updateContents();
169         ///
170         void updateAvailableModules();
171         ///
172         void updateSelectedModules();
173         ///
174         void updateIncludeonlys();
175         /// save as default template
176         void saveDocDefault();
177         /// reset to default params
178         void useClassDefaults();
179         ///
180         void setLayoutComboByIDString(std::string const & idString);
181
182         /// available modules
183         GuiIdListModel modules_av_model_;
184         /// selected modules
185         GuiIdListModel modules_sel_model_;
186
187         /// return false if validate_listings_params returns error
188         bool isValid();
189
190         /// font family names for BufferParams::fonts_default_family
191         static char const * const fontfamilies[5];
192         /// GUI names corresponding fontfamilies
193         static char const * fontfamilies_gui[5];
194         ///
195         bool initialiseParams(std::string const & data);
196         ///
197         void clearParams();
198         ///
199         void dispatchParams();
200         ///
201         void modulesToParams(BufferParams &);
202         ///
203         bool isBufferDependent() const { return true; }
204         /// always true since we don't manipulate document contents
205         bool canApply() const { return true; }
206         ///
207         DocumentClass const & documentClass() const;
208         ///
209         BufferParams & params() { return bp_; }
210         ///
211         BufferId id() const;
212         ///
213         struct modInfoStruct {
214                 QString name;
215                 std::string id;
216                 QString description;
217         };
218         /// List of available modules
219         std::list<modInfoStruct> const & getModuleInfo();
220         /// Modules in use in current buffer
221         std::list<modInfoStruct> const getSelectedModules();
222         ///
223         std::list<modInfoStruct> const getProvidedModules();
224         ///
225         std::list<modInfoStruct> const
226                         makeModuleInfo(LayoutModuleList const & mods);
227         ///
228         void setLanguage() const;
229         ///
230         void saveAsDefault() const;
231         /// does this font provide Old Style figures?
232         bool providesOSF(QString const & font) const;
233         /// does this font provide true Small Caps?
234         bool providesSC(QString const & font) const;
235         /** does this font provide OSF and Small Caps only via 
236          * a single, undifferentiated expert option?
237          */
238         bool hasMonolithicExpertSet(QString const & font) const;
239         /// does this font provide size adjustment?
240         bool providesScale(QString const & font) const;
241         /// does this font provide an alternative without math?
242         bool providesNoMath(QString const & font) const;
243         ///
244         void executeBranchRenaming() const;
245         ///
246         void setCustomPapersize(bool custom);
247 private:
248         ///
249         void loadModuleInfo();
250         ///
251         void updateUnknownBranches();
252         ///
253         void updateTexFonts();
254         ///
255         void updateMathFonts(QString const & rm);
256         ///
257         void updateFontOptions();
258         ///
259         bool ot1() const;
260         ///
261         bool completeFontset() const;
262         ///
263         bool noMathFont() const;
264         ///
265         void allPackages(int);
266         ///
267         BufferParams bp_;
268         /// List of names of available modules
269         std::list<modInfoStruct> moduleNames_;
270         ///
271         std::map<docstring, docstring> changedBranches_;
272         ///
273         std::list<std::string> includeonlys_;
274         ///
275         bool biblioChanged_;
276 };
277
278
279 class PreambleModule : public UiWidget<Ui::PreambleUi>
280 {
281         Q_OBJECT
282 public:
283         PreambleModule();
284         void update(BufferParams const & params, BufferId id);
285         void apply(BufferParams & params);
286
287 Q_SIGNALS:
288         /// signal that something's changed in the Widget.
289         void changed();
290
291 private:
292         void closeEvent(QCloseEvent *);
293         void on_preambleTE_textChanged() { changed(); }
294
295 private:
296         typedef std::map<BufferId, std::pair<int,int> > Coords;
297         Coords preamble_coords_;
298         BufferId current_id_;
299 };
300
301
302 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
303 {
304         Q_OBJECT
305 public:
306         LocalLayout();
307         void update(BufferParams const & params, BufferId id);
308         void apply(BufferParams & params);
309         bool isValid() const { return validated_; }
310
311 Q_SIGNALS:
312         /// signal that something's changed in the Widget.
313         void changed();
314
315 private:
316         void validate();
317         void convert();
318 private Q_SLOTS:
319         void textChanged();
320         void validatePressed();
321         void convertPressed();
322
323 private:
324         BufferId current_id_;
325         bool validated_;
326 };
327
328
329 } // namespace frontend
330 } // namespace lyx
331
332 #endif // GUIDOCUMENT_H