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