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