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