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