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