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