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