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