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