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