]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Use <cstdint> instead of <boost/cstdint.hpp>
[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 #include <QStandardItemModel>
41
42 namespace lyx {
43
44 class BufferParams;
45 class LayoutModuleList;
46 class LyXModule;
47 class TextClass;
48
49 namespace support {
50         class TempFile;
51 }
52
53 namespace frontend {
54
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 private:
167         /// validate listings parameters and return an error message, if any
168         QString validateListingsParameters();
169
170         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
171         UiWidget<Ui::MasterChildUi> *masterChildModule;
172         FontModule *fontModule;
173         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
174         UiWidget<Ui::MarginsUi> *marginsModule;
175         UiWidget<Ui::LanguageUi> *langModule;
176         UiWidget<Ui::ColorUi> *colorModule;
177         UiWidget<Ui::NumberingUi> *numberingModule;
178         UiWidget<Ui::BiblioUi> *biblioModule;
179         UiWidget<Ui::MathsUi> *mathsModule;
180         UiWidget<Ui::LaTeXUi> *latexModule;
181         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
182         UiWidget<Ui::ModulesUi> *modulesModule;
183         UiWidget<Ui::OutputUi> *outputModule;
184         UiWidget<Ui::ListingsSettingsUi> *listingsModule;
185         PreambleModule * preambleModule;
186         LocalLayout * localLayout;
187
188         GuiBranches * branchesModule;
189         GuiIndices * indicesModule;
190
191         BulletsModule * bulletsModule;
192         FloatPlacement * floatModule;
193
194         ModuleSelectionManager * selectionManager;
195
196         /// Available modules
197         QStandardItemModel * availableModel() { return &modules_av_model_; }
198         /// Selected modules
199         GuiIdListModel * selectedModel() { return &modules_sel_model_; }
200
201         /// Apply changes
202         void applyView();
203         /// update
204         void updateContents();
205         ///
206         void updateAvailableModules();
207         ///
208         void updateSelectedModules();
209         ///
210         void updateIncludeonlys();
211         ///
212         void updateDefaultBiblio(std::string const & style,
213                                  std::string const & which = std::string());
214         /// save as default template
215         void saveDocDefault();
216         /// reset to default params
217         void useClassDefaults();
218         ///
219         void setLayoutComboByIDString(std::string const & idString);
220         /// Update quotes styles combo, indicating the current language's default
221         void updateQuoteStyles(bool const set = false);
222         ///
223         void getTableStyles();
224
225         /// available modules
226         QStandardItemModel modules_av_model_;
227         /// selected modules
228         GuiIdListModel modules_sel_model_;
229
230         /// Module filter
231         FancyLineEdit * filter_;
232
233         /// return false if validate_listings_params returns error
234         bool isValid();
235
236         /// font family names for BufferParams::fonts_default_family
237         static char const * const fontfamilies[5];
238         /// GUI names corresponding fontfamilies
239         static char const * fontfamilies_gui[5];
240         ///
241         bool initialiseParams(std::string const & data);
242         ///
243         void clearParams();
244         ///
245         void dispatchParams();
246         ///
247         void modulesToParams(BufferParams &);
248         ///
249         bool isBufferDependent() const { return true; }
250         /// always true since we don't manipulate document contents
251         bool canApply() const { return true; }
252         ///
253         DocumentClass const & documentClass() const;
254         ///
255         BufferParams & params() { return bp_; }
256         ///
257         BufferId id() const;
258         ///
259         struct modInfoStruct {
260                 QString name;
261                 std::string id;
262                 QString description;
263                 QString category;
264                 bool local;
265                 bool missingreqs;
266         };
267         ///
268         static modInfoStruct modInfo(LyXModule const & mod);
269         /// List of available modules
270         std::list<modInfoStruct> const & getModuleInfo();
271         /// Modules in use in current buffer
272         std::list<modInfoStruct> const getSelectedModules();
273         ///
274         std::list<modInfoStruct> const getProvidedModules();
275         ///
276         std::list<modInfoStruct> const
277                         makeModuleInfo(LayoutModuleList const & mods);
278         ///
279         void setLanguage() const;
280         ///
281         void saveAsDefault() const;
282         /// does this font provide Old Style figures?
283         bool providesOSF(QString const & font) const;
284         /// does this font provide true Small Caps?
285         bool providesSC(QString const & font) const;
286         /** does this font provide OSF and Small Caps only via
287          * a single, undifferentiated expert option?
288          */
289         bool hasMonolithicExpertSet(QString const & font) const;
290         /// does this font provide size adjustment?
291         bool providesScale(QString const & font) const;
292         /// does this font provide an alternative without math?
293         bool providesNoMath(QString const & font) const;
294         ///
295         void executeBranchRenaming() const;
296         ///
297         void setCustomPapersize(bool custom);
298 private:
299         ///
300         void loadModuleInfo();
301         ///
302         void updateUnknownBranches();
303         ///
304         void updateTexFonts();
305         ///
306         void updateMathFonts(QString const & rm);
307         ///
308         void updateFontOptions();
309         ///
310         bool ot1() const;
311         ///
312         bool completeFontset() const;
313         ///
314         bool noMathFont() const;
315         ///
316         void allPackages(int);
317         ///
318         bool isBiblatex() const;
319         ///
320         void checkPossibleCiteEngines();
321         ///
322         void filterModules(QString const & string);
323         ///
324         BufferParams bp_;
325         /// List of names of available modules
326         std::list<modInfoStruct> moduleNames_;
327         ///
328         std::map<docstring, docstring> changedBranches_;
329         ///
330         std::list<std::string> includeonlys_;
331         ///
332         bool biblioChanged_;
333         /// Track if a non-module document param changed
334         bool nonModuleChanged_;
335         /// Track if used modules changed
336         bool modulesChanged_;
337         /// Track if the shellescape param changed
338         bool shellescapeChanged_;
339 };
340
341
342 class PreambleModule : public UiWidget<Ui::PreambleUi>
343 {
344         Q_OBJECT
345 public:
346         PreambleModule(QWidget * parent);
347         void update(BufferParams const & params, BufferId id);
348         void apply(BufferParams & params);
349         bool editing() const { return (bool)tempfile_; }
350
351 Q_SIGNALS:
352         /// signal that something's changed in the Widget.
353         void changed();
354
355 private:
356         void closeEvent(QCloseEvent *);
357         void on_preambleTE_textChanged() { changed(); }
358
359         typedef std::map<BufferId, std::pair<int,int> > Coords;
360         Coords preamble_coords_;
361         BufferId current_id_;
362         unique_ptr<support::TempFile> tempfile_;
363
364 private Q_SLOTS:
365         ///
366         void checkFindButton();
367         void findText();
368         void editExternal();
369 };
370
371
372 class LocalLayout : public UiWidget<Ui::LocalLayoutUi>
373 {
374         Q_OBJECT
375 public:
376         LocalLayout(QWidget * parent);
377         void update(BufferParams const & params, BufferId id);
378         void apply(BufferParams & params);
379         bool isValid() const { return validated_; }
380         bool editing() const { return (bool)tempfile_; }
381
382 Q_SIGNALS:
383         /// signal that something's changed in the Widget.
384         void changed();
385
386 private:
387         void validate();
388         void convert();
389         void hideConvert();
390 private Q_SLOTS:
391         void textChanged();
392         void validatePressed();
393         void convertPressed();
394         void editExternal();
395
396 private:
397         BufferId current_id_;
398         bool validated_;
399         unique_ptr<support::TempFile> tempfile_;
400 };
401
402
403 class FontModule : public UiWidget<Ui::FontUi>
404 {
405         Q_OBJECT
406 public:
407         FontModule(QWidget * parent) : UiWidget<Ui::FontUi>(parent),
408            font_sf_scale(100), font_tt_scale(100) {}
409         /// The roman font currently not selected by osFontsCB->isChecked()
410         QString font_roman;
411         /// The sans font currently not selected by osFontsCB->isChecked()
412         QString font_sans;
413         /// The typewriter font currently not selected by osFontsCB->isChecked()
414         QString font_typewriter;
415         /// The math font currently not selected by osFontsCB->isChecked()
416         QString font_math;
417         /// The sans font scale currently not selected by osFontsCB->isChecked()
418         int font_sf_scale;
419         /// The typewriter font scale currently not selected by osFontsCB->isChecked()
420         int font_tt_scale;
421 };
422
423
424 } // namespace frontend
425 } // namespace lyx
426
427 #endif // GUIDOCUMENT_H