]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiDocument.h
Disable colsep box when single column.
[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 <QDialog>
17
18 #include "BufferParams.h"
19 #include "BulletsModule.h"
20 #include "GuiDialog.h"
21 #include "GuiIdListModel.h"
22 #include "GuiSelectionManager.h"
23
24 #include "support/types.h"
25
26 #include "ui_DocumentUi.h"
27 #include "ui_EmbeddedFilesUi.h"
28 #include "ui_FontUi.h"
29 #include "ui_TextLayoutUi.h"
30 #include "ui_MathsUi.h"
31 #include "ui_LaTeXUi.h"
32 #include "ui_PageLayoutUi.h"
33 #include "ui_LanguageUi.h"
34 #include "ui_BiblioUi.h"
35 #include "ui_NumberingUi.h"
36 #include "ui_MarginsUi.h"
37 #include "ui_PreambleUi.h"
38 #include "ui_PDFSupportUi.h"
39
40 #include <map>
41 #include <vector>
42
43 class FloatPlacement;
44
45 namespace lyx {
46
47 class BufferParams;
48 class TextClass;
49
50 namespace frontend {
51
52 class GuiBranches;
53 class PreambleModule;
54
55 ///
56 QModelIndex getSelectedIndex(QListView * lv);
57
58 ///
59 typedef void const * BufferId;
60
61 template<class UI>
62 class UiWidget : public QWidget, public UI
63 {
64 public:
65         UiWidget(QWidget * parent = 0) : QWidget(parent) { UI::setupUi(this); }
66 };
67
68
69 class ModuleSelMan : public GuiSelectionManager 
70 {
71 public:
72         ModuleSelMan(
73                 QListView * availableLV, 
74                 QListView * selectedLV,
75                 QPushButton * addPB, 
76                 QPushButton * delPB, 
77                 QPushButton * upPB, 
78                 QPushButton * downPB,
79                 GuiIdListModel * availableModel,
80                 GuiIdListModel * selectedModel);
81 private:
82         ///
83         virtual void updateAddPB();
84         ///
85         virtual void updateUpPB();
86         ///
87         virtual void updateDownPB();
88         ///
89         virtual void updateDelPB();
90         /// returns availableModel as a GuiIdListModel
91         GuiIdListModel * getAvailableModel() 
92         {
93                 return dynamic_cast<GuiIdListModel *>(availableModel);
94         };
95         /// returns selectedModel as a GuiIdListModel
96         GuiIdListModel * getSelectedModel() 
97         {
98                 return dynamic_cast<GuiIdListModel *>(selectedModel);
99         };
100 };
101
102
103 typedef void const * BufferId;
104
105
106 class GuiDocument : public GuiDialog, public Ui::DocumentUi
107 {
108         Q_OBJECT
109 public:
110         GuiDocument(GuiView & lv);
111
112         void updateParams(BufferParams const & params);
113         void apply(BufferParams & params);
114
115         void updateFontsize(std::string const &, std::string const &);
116         void updatePagestyle(std::string const &, std::string const &);
117
118         void showPreamble();
119         /// validate listings parameters and return an error message, if any
120         docstring validate_listings_params();
121
122 public Q_SLOTS:
123         void updateNumbering();
124         void change_adaptor();
125         void set_listings_msg();
126         void saveDefaultClicked();
127         void useDefaultsClicked();
128
129 private Q_SLOTS:
130         void updateParams();
131         void setLSpacing(int);
132         void setMargins(bool);
133         void setCustomPapersize(int);
134         void setColSep();
135         void setCustomMargins(bool);
136         void romanChanged(int);
137         void sansChanged(int);
138         void ttChanged(int);
139         void setSkip(int);
140         void enableSkip(bool);
141         void portraitChanged();
142         void classChanged();
143         void updateModuleInfo();
144         void updateEmbeddedFileList();
145
146 private:
147         UiWidget<Ui::TextLayoutUi> *textLayoutModule;
148         UiWidget<Ui::FontUi> *fontModule;
149         UiWidget<Ui::PageLayoutUi> *pageLayoutModule;
150         UiWidget<Ui::MarginsUi> *marginsModule;
151         UiWidget<Ui::LanguageUi> *langModule;
152         UiWidget<Ui::NumberingUi> *numberingModule;
153         UiWidget<Ui::BiblioUi> *biblioModule;
154         UiWidget<Ui::MathsUi> *mathsModule;
155         UiWidget<Ui::LaTeXUi> *latexModule;
156         UiWidget<Ui::PDFSupportUi> *pdfSupportModule;
157         UiWidget<Ui::EmbeddedFilesUi> *embeddedFilesModule;
158         PreambleModule *preambleModule;
159         
160         GuiBranches *branchesModule;
161
162         BulletsModule * bulletsModule;
163         FloatPlacement * floatModule;
164
165         GuiSelectionManager * selectionManager;
166
167         // FIXME
168         std::vector<std::string> lang_;
169
170         /// Available modules
171         GuiIdListModel * availableModel() { return &available_model_; }
172         /// Selected modules
173         GuiIdListModel * selectedModel() { return &selected_model_; }
174 private:
175         /// Apply changes
176         void applyView();
177         /// update
178         void updateContents();
179         /// force content update
180         void forceUpdate();
181         ///
182         void updateAvailableModules();
183         ///
184         void updateSelectedModules();
185         /// save as default template
186         void saveDocDefault();
187         /// reset to default params
188         void useClassDefaults();
189         /// available modules
190         GuiIdListModel available_model_;
191         /// selected modules
192         GuiIdListModel selected_model_;
193         /// current buffer
194         BufferId current_id_;
195
196 protected:
197         /// return false if validate_listings_params returns error
198         bool isValid();
199
200         /// font family names for BufferParams::fontsDefaultFamily
201         static char const * const fontfamilies[5];
202         /// GUI names corresponding fontfamilies
203         static char const * fontfamilies_gui[5];
204         ///
205         bool initialiseParams(std::string const & data);
206         ///
207         void clearParams();
208         ///
209         void dispatchParams();
210         ///
211         bool isBufferDependent() const { return true; }
212         /// always true since we don't manipulate document contents
213         bool canApply() const { return true; }
214         ///
215         TextClass const & textClass() const;
216         ///
217         BufferParams & params() { return bp_; }
218         ///
219         BufferParams const & params() const { return bp_; }
220         ///
221         BufferId id() const;
222         ///
223         struct modInfoStruct {
224                 std::string name;
225                 std::string id;
226         };
227         /// List of available modules
228         std::vector<modInfoStruct> const & getModuleInfo();
229         /// Modules in use in current buffer
230         std::vector<modInfoStruct> const getSelectedModules();
231         ///
232         void setLanguage() const;
233         ///
234         void saveAsDefault() const;
235         ///
236         bool isFontAvailable(std::string const & font) const;
237         /// does this font provide Old Style figures?
238         bool providesOSF(std::string const & font) const;
239         /// does this font provide true Small Caps?
240         bool providesSC(std::string const & font) const;
241         /// does this font provide size adjustment?
242         bool providesScale(std::string const & font) const;
243 private:
244         ///
245         void loadModuleInfo();
246         ///
247         BufferParams bp_;
248         /// List of names of available modules
249         std::vector<modInfoStruct> moduleNames_;
250 };
251
252
253 class PreambleModule : public UiWidget<Ui::PreambleUi>
254 {
255         Q_OBJECT
256 public:
257         PreambleModule();
258         void update(BufferParams const & params, BufferId id);
259         void apply(BufferParams & params);
260
261 Q_SIGNALS:
262         /// signal that something's changed in the Widget.
263         void changed();
264
265 private:
266         void closeEvent(QCloseEvent *);
267         void on_preambleTE_textChanged() { changed(); }
268
269 private:
270         typedef std::map<BufferId, std::pair<int,int> > Coords;
271         Coords preamble_coords_;
272         BufferId current_id_;
273 };
274
275
276 } // namespace frontend
277 } // namespace lyx
278
279 #endif // GUIDOCUMENT_H