]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
The shell escape patch
[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 LyXModule;
45 class TextClass;
46
47 namespace frontend {
48
49 class FloatPlacement;
50 class GuiBranches;
51 class GuiIndices;
52 class ModuleSelectionManager;
53 class PreambleModule;
54 class LocalLayout;
55 class FontModule;
56
57 ///
58 typedef void const * BufferId;
59
60 template<class UI>
61 class UiWidget : public QWidget, public UI
62 {
63 public:
64         UiWidget(QWidget * parent) : QWidget(parent) { UI::setupUi(this); }
65 };
66
67
68 class GuiDocument : public GuiDialog, public Ui::DocumentUi
69 {
70         Q_OBJECT
71 public:
72         GuiDocument(GuiView & lv);
73
74         void paramsToDialog();
75         void updateFontsize(std::string const &, std::string const &);
76         void updateFontlist();
77         void updateDefaultFormat();
78         void updateCiteStyles(std::vector<std::string> const &,
79                               CiteEngineType const & sel = ENGINE_TYPE_AUTHORYEAR);
80         void updateEngineType(std::string const &, CiteEngineType const &);
81         void updatePagestyle(std::string const &, std::string const &);
82         bool isChildIncluded(std::string const &);
83
84         ///
85         BufferParams const & params() const { return bp_; }
86
87 public Q_SLOTS:
88         void onBufferViewChanged();//override
89
90 private Q_SLOTS:
91         void updateNumbering();
92         void change_adaptor();
93         void shellescapeChanged();
94         void includeonlyClicked(QTreeWidgetItem * item, int);
95         void setListingsMessage();
96         void listingsPackageChanged(int);
97         void saveDefaultClicked();
98         void useDefaultsClicked();
99         void setLSpacing(int);
100         void setMargins();
101         void papersizeChanged(int);
102         void setColSep();
103         void setCustomMargins(bool);
104         void fontencChanged(int);
105         void romanChanged(int);
106         void sansChanged(int);
107         void ttChanged(int);
108         void fontOsfToggled(bool state);
109         void fontScToggled(bool state);
110         void setIndent(int);
111         void enableIndent(bool);
112         void setSkip(int);
113         void enableSkip(bool);
114         void allowMathIndent();
115         void enableMathIndent(int);
116         void browseLayout();
117         void browseMaster();
118         void classChanged();
119         void classChanged_adaptor();
120         void languagePackageChanged(int);
121         void biblioChanged();
122         void rescanBibFiles();
123         void resetDefaultBibfile(std::string const & which = std::string());
124         void resetDefaultBbxBibfile();
125         void resetDefaultCbxBibfile();
126         void citeEngineChanged(int);
127         void citeStyleChanged();
128         void bibtexChanged(int);
129         void updateResetDefaultBiblio();
130         void matchBiblatexStyles();
131         void updateEngineDependends();
132         void updateModuleInfo();
133         void modulesChanged();
134         void changeBackgroundColor();
135         void deleteBackgroundColor();
136         void changeFontColor();
137         void deleteFontColor();
138         void changeNoteFontColor();
139         void deleteNoteFontColor();
140         void changeBoxBackgroundColor();
141         void deleteBoxBackgroundColor();
142         void languageChanged(int);
143         void osFontsChanged(bool);
144         void mathFontChanged(int);
145         void branchesRename(docstring const &, docstring const &);
146         void allPackagesAuto();
147         void allPackagesAlways();
148         void allPackagesNot();
149 private:
150         /// validate listings parameters and return an error message, if any
151         QString validateListingsParameters();
152
153         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
154         UiWidget<Ui::MasterChildUi> *masterChildModule;
155         FontModule *fontModule;
156         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
157         UiWidget<Ui::MarginsUi> *marginsModule;
158         UiWidget<Ui::LanguageUi> *langModule;
159         UiWidget<Ui::ColorUi> *colorModule;
160         UiWidget<Ui::NumberingUi> *numberingModule;
161         UiWidget<Ui::BiblioUi> *biblioModule;
162         UiWidget<Ui::MathsUi> *mathsModule;
163         UiWidget<Ui::LaTeXUi> *latexModule;
164         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
165         UiWidget<Ui::ModulesUi> *modulesModule;
166         UiWidget<Ui::OutputUi> *outputModule;
167         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
168         PreambleModule * preambleModule;
169         LocalLayout * localLayout;
170
171         GuiBranches * branchesModule;
172         GuiIndices * indicesModule;
173
174         BulletsModule * bulletsModule;
175         FloatPlacement * floatModule;
176
177         ModuleSelectionManager * selectionManager;
178
179         /// Available modules
180         GuiIdListModel * availableModel() { return &modules_av_model_; }
181         /// Selected modules
182         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
183
184         /// Apply changes
185         void applyView();
186         /// update
187         void updateContents();
188         ///
189         void updateAvailableModules();
190         ///
191         void updateSelectedModules();
192         ///
193         void updateIncludeonlys();
194         ///
195         void updateDefaultBiblio(std::string const & style,
196                                  std::string const & which = std::string());
197         /// save as default template
198         void saveDocDefault();
199         /// reset to default params
200         void useClassDefaults();
201         ///
202         void setLayoutComboByIDString(std::string const & idString);
203         /// Update quotes styles combo, indicating the current language's default
204         void updateQuoteStyles(bool const set = false);
205
206         /// available modules
207         GuiIdListModel modules_av_model_;
208         /// selected modules
209         GuiIdListModel modules_sel_model_;
210
211         /// return false if validate_listings_params returns error
212         bool isValid();
213
214         /// font family names for BufferParams::fonts_default_family
215         static char const * const fontfamilies[5];
216         /// GUI names corresponding fontfamilies
217         static char const * fontfamilies_gui[5];
218         ///
219         bool initialiseParams(std::string const & data);
220         ///
221         void clearParams();
222         ///
223         void dispatchParams();
224         ///
225         void modulesToParams(BufferParams &);
226         ///
227         bool isBufferDependent() const { return true; }
228         /// always true since we don't manipulate document contents
229         bool canApply() const { return true; }
230         ///
231         DocumentClass const & documentClass() const;
232         ///
233         BufferParams & params() { return bp_; }
234         ///
235         BufferId id() const;
236         ///
237         struct modInfoStruct {
238                 QString name;
239                 std::string id;
240                 QString description;
241         };
242         ///
243         static modInfoStruct modInfo(LyXModule const & mod);
244         /// List of available modules
245         std::list<modInfoStruct> const & getModuleInfo();
246         /// Modules in use in current buffer
247         std::list<modInfoStruct> const getSelectedModules();
248         ///
249         std::list<modInfoStruct> const getProvidedModules();
250         ///
251         std::list<modInfoStruct> const
252                         makeModuleInfo(LayoutModuleList const & mods);
253         ///
254         void setLanguage() const;
255         ///
256         void saveAsDefault() const;
257         /// does this font provide Old Style figures?
258         bool providesOSF(QString const & font) const;
259         /// does this font provide true Small Caps?
260         bool providesSC(QString const & font) const;
261         /** does this font provide OSF and Small Caps only via
262          * a single, undifferentiated expert option?
263          */
264         bool hasMonolithicExpertSet(QString const & font) const;
265         /// does this font provide size adjustment?
266         bool providesScale(QString const & font) const;
267         /// does this font provide an alternative without math?
268         bool providesNoMath(QString const & font) const;
269         ///
270         void executeBranchRenaming() const;
271         ///
272         void setCustomPapersize(bool custom);
273 private:
274         ///
275         void loadModuleInfo();
276         ///
277         void updateUnknownBranches();
278         ///
279         void updateTexFonts();
280         ///
281         void updateMathFonts(QString const & rm);
282         ///
283         void updateFontOptions();
284         ///
285         bool ot1() const;
286         ///
287         bool completeFontset() const;
288         ///
289         bool noMathFont() const;
290         ///
291         void allPackages(int);
292         ///
293         bool isBiblatex() const;
294         ///
295         BufferParams bp_;
296         /// List of names of available modules
297         std::list<modInfoStruct> moduleNames_;
298         ///
299         std::map<docstring, docstring> changedBranches_;
300         ///
301         std::list<std::string> includeonlys_;
302         ///
303         bool biblioChanged_;
304         /// Track if a non-module document param changed
305         bool nonModuleChanged_;
306 };
307
308
309 class PreambleModule : public UiWidget<Ui::PreambleUi>
310 {
311         Q_OBJECT
312 public:
313         PreambleModule(QWidget * parent);
314         void update(BufferParams const & params, BufferId id);
315         void apply(BufferParams & params);
316
317 Q_SIGNALS:
318         /// signal that something's changed in the Widget.
319         void changed();
320
321 private:
322         void closeEvent(QCloseEvent *);
323         void on_preambleTE_textChanged() { changed(); }
324
325 private:
326         typedef std::map<BufferId, std::pair<int,int> > Coords;
327         Coords preamble_coords_;
328         BufferId current_id_;
329 };
330
331
332 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
333 {
334         Q_OBJECT
335 public:
336         LocalLayout(QWidget * parent);
337         void update(BufferParams const & params, BufferId id);
338         void apply(BufferParams & params);
339         bool isValid() const { return validated_; }
340
341 Q_SIGNALS:
342         /// signal that something's changed in the Widget.
343         void changed();
344
345 private:
346         void validate();
347         void convert();
348         void hideConvert();
349 private Q_SLOTS:
350         void textChanged();
351         void validatePressed();
352         void convertPressed();
353
354 private:
355         BufferId current_id_;
356         bool validated_;
357 };
358
359
360 class FontModule : public UiWidget<Ui::FontUi>
361 {
362         Q_OBJECT
363 public:
364         FontModule(QWidget * parent) : UiWidget<Ui::FontUi>(parent),
365            font_sf_scale(100), font_tt_scale(100) {}
366         /// The roman font currently not selected by osFontsCB->isChecked()
367         QString font_roman;
368         /// The sans font currently not selected by osFontsCB->isChecked()
369         QString font_sans;
370         /// The typewriter font currently not selected by osFontsCB->isChecked()
371         QString font_typewriter;
372         /// The math font currently not selected by osFontsCB->isChecked()
373         QString font_math;
374         /// The sans font scale currently not selected by osFontsCB->isChecked()
375         int font_sf_scale;
376         /// The typewriter font scale currently not selected by osFontsCB->isChecked()
377         int font_tt_scale;
378 };
379
380
381 } // namespace frontend
382 } // namespace lyx
383
384 #endif // GUIDOCUMENT_H