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