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