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