]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
ab199d1f1dd04fb67d175f774ea20106257f37d0
[lyx.git] / src / frontends / qt4 / GuiPrefs.h
1 // -*- C++ -*-
2 /**
3  * \file GuiPrefs.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUIPREFS_H
13 #define GUIPREFS_H
14
15 #include "GuiDialog.h"
16 #include "ControlPrefs.h"
17 #include "Color.h"
18 #include "LyXRC.h"
19 #include "Format.h"
20
21 #include "ui_PrefsUi.h"
22
23 #include "ui_PrefPlaintextUi.h"
24 #include "ui_PrefDateUi.h"
25 #include "ui_PrefKeyboardUi.h"
26 #include "ui_PrefLatexUi.h"
27 #include "ui_PrefScreenFontsUi.h"
28 #include "ui_PrefColorsUi.h"
29 #include "ui_PrefDisplayUi.h"
30 #include "ui_PrefPathsUi.h"
31 #include "ui_PrefSpellcheckerUi.h"
32 #include "ui_PrefConvertersUi.h"
33 #include "ui_PrefFileformatsUi.h"
34 #include "ui_PrefLanguageUi.h"
35 #include "ui_PrefPrinterUi.h"
36 #include "ui_PrefUi.h"
37 #include "ui_PrefIdentityUi.h"
38
39 #include <QDialog>
40 #include <QValidator>
41
42 #include <vector>
43
44 namespace lyx {
45
46 class Converters;
47 class Formats;
48 class Movers;
49
50 namespace frontend {
51
52 class GuiPrefsDialog;
53
54 class PrefModule : public QWidget
55 {
56         Q_OBJECT
57 public:
58         PrefModule(docstring const & t,
59                         GuiPrefsDialog * form = 0, QWidget * parent = 0)
60                 : QWidget(parent), title_(t), form_(form)
61         {}
62
63         virtual void apply(LyXRC & rc) const = 0;
64         virtual void update(LyXRC const & rc) = 0;
65
66         docstring const & title() const { return title_; }
67
68 protected:
69         docstring title_;
70         GuiPrefsDialog * form_;
71
72 Q_SIGNALS:
73         void changed();
74 };
75
76
77 class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi
78 {
79         Q_OBJECT
80 public:
81         PrefPlaintext(QWidget * parent = 0);
82
83         virtual void apply(LyXRC & rc) const;
84         virtual void update(LyXRC const & rc);
85 };
86
87
88 class PrefDate : public PrefModule, public Ui::PrefDateUi
89 {
90         Q_OBJECT
91 public:
92         PrefDate(QWidget * parent = 0);
93
94         virtual void apply(LyXRC & rc) const;
95         virtual void update(LyXRC const & rc);
96 };
97
98
99 class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi
100 {
101         Q_OBJECT
102 public:
103         PrefKeyboard(GuiPrefsDialog * form, QWidget * parent = 0);
104
105         virtual void apply(LyXRC & rc) const;
106         virtual void update(LyXRC const & rc);
107
108 private Q_SLOTS:
109         void on_firstKeymapPB_clicked(bool);
110         void on_secondKeymapPB_clicked(bool);
111         void on_keymapCB_toggled(bool);
112
113 private:
114         QString testKeymap(QString keymap);
115 };
116
117
118 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
119 {
120         Q_OBJECT
121 public:
122         PrefLatex(GuiPrefsDialog * form, QWidget * parent = 0);
123
124         virtual void apply(LyXRC & rc) const;
125         virtual void update(LyXRC const & rc);
126 };
127
128
129 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
130 {
131         Q_OBJECT
132 public:
133         PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent = 0);
134
135         virtual void apply(LyXRC & rc) const;
136         virtual void update(LyXRC const & rc);
137
138 private Q_SLOTS:
139         void select_roman(const QString&);
140         void select_sans(const QString&);
141         void select_typewriter(const QString&);
142 };
143
144
145 class PrefColors : public PrefModule, public Ui::PrefColorsUi
146 {
147         Q_OBJECT
148 public:
149         PrefColors(GuiPrefsDialog * form, QWidget * parent = 0);
150
151         void apply(LyXRC & rc) const;
152         void update(LyXRC const & rc);
153
154 private Q_SLOTS:
155         void change_color();
156         void change_lyxObjects_selection();
157
158 private:
159         std::vector<Color_color> lcolors_;
160         // FIXME the use of mutable here is required due to the
161         // fact that initialization is not done in the controller
162         // but in the constructor.
163         std::vector<QString> curcolors_;
164         std::vector<QString> newcolors_;
165
166 };
167
168
169 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
170 {
171         Q_OBJECT
172 public:
173         PrefDisplay(QWidget * parent = 0);
174
175         void apply(LyXRC & rc) const;
176         void update(LyXRC const & rc);
177 };
178
179
180 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
181 {
182         Q_OBJECT
183 public:
184         PrefPaths(GuiPrefsDialog * form, QWidget * parent = 0);
185
186         void apply(LyXRC & rc) const;
187         void update(LyXRC const & rc);
188
189 private Q_SLOTS:
190         void select_templatedir();
191         void select_tempdir();
192         void select_backupdir();
193         void select_workingdir();
194         void select_lyxpipe();
195
196 };
197
198
199 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
200 {
201         Q_OBJECT
202 public:
203         PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent = 0);
204
205         void apply(LyXRC & rc) const;
206         void update(LyXRC const & rc);
207
208 private Q_SLOTS:
209         void select_dict();
210 };
211
212
213 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
214 {
215         Q_OBJECT
216 public:
217         PrefConverters(GuiPrefsDialog * form, QWidget * parent = 0);
218
219         void apply(LyXRC & rc) const;
220         void update(LyXRC const & rc);
221
222 public Q_SLOTS:
223         void updateGui();
224
225 private Q_SLOTS:
226         void update_converter();
227         void switch_converter();
228         void converter_changed();
229         void remove_converter();
230         void on_cacheCB_stateChanged(int state);
231
232 private:
233         void updateButtons();
234 };
235
236
237 class FormatValidator : public QValidator
238 {
239 public:
240         FormatValidator(QWidget *, Formats const & f);
241         void fixup(QString & input) const;
242         QValidator::State validate(QString & input, int & pos) const;
243 private:
244         virtual std::string str(Formats::const_iterator it) const = 0;
245         int nr() const;
246         Formats const & formats_;
247 };
248
249
250 class FormatNameValidator : public FormatValidator
251 {
252 public:
253         FormatNameValidator(QWidget *, Formats const & f);
254 private:
255         std::string str(Formats::const_iterator it) const;
256 };
257
258 class FormatPrettynameValidator : public FormatValidator
259 {
260 public:
261         FormatPrettynameValidator(QWidget *, Formats const & f);
262 private:
263         std::string str(Formats::const_iterator it) const;
264 };
265
266
267 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
268 {
269         Q_OBJECT
270 public:
271         PrefFileformats(GuiPrefsDialog * form, QWidget * parent = 0);
272
273         void apply(LyXRC & rc) const;
274         void update(LyXRC const & rc);
275         void updateView();
276
277 Q_SIGNALS:
278         void formatsChanged();
279
280 private Q_SLOTS:
281         void on_copierED_textEdited(const QString & s);
282         void on_extensionED_textEdited(const QString &);
283         void on_viewerED_textEdited(const QString &);
284         void on_editorED_textEdited(const QString &);
285         void on_shortcutED_textEdited(const QString &);
286         void on_formatED_editingFinished();
287         void on_formatED_textChanged(const QString &);
288         void on_formatsCB_currentIndexChanged(int);
289         void on_formatsCB_editTextChanged(const QString &);
290         void on_formatNewPB_clicked();
291         void on_formatRemovePB_clicked();
292         void setFlags();
293         void updatePrettyname();
294
295 private:
296         Format & currentFormat();
297 };
298
299
300 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
301 {
302         Q_OBJECT
303 public:
304         PrefLanguage(QWidget * parent = 0);
305
306         void apply(LyXRC & rc) const;
307         void update(LyXRC const & rc);
308
309 private:
310         std::vector<std::string> lang_;
311 };
312
313
314 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
315 {
316         Q_OBJECT
317 public:
318         PrefPrinter(QWidget * parent = 0);
319
320         void apply(LyXRC & rc) const;
321         void update(LyXRC const & rc);
322 };
323
324
325 class PrefUserInterface : public PrefModule, public Ui::PrefUi
326 {
327         Q_OBJECT
328 public:
329         PrefUserInterface(GuiPrefsDialog * form, QWidget * parent = 0);
330
331         void apply(LyXRC & rc) const;
332         void update(LyXRC const & rc);
333
334 public Q_SLOTS:
335         void select_ui();
336         void select_bind();
337         void on_loadWindowSizeCB_toggled(bool);
338
339 };
340
341
342 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
343 {
344         Q_OBJECT
345 public:
346         PrefIdentity(QWidget * parent = 0);
347
348         void apply(LyXRC & rc) const;
349         void update(LyXRC const & rc);
350 };
351
352 ///
353 class GuiPrefsDialog : public GuiDialog, public Ui::PrefsUi
354 {
355         Q_OBJECT
356 public:
357         GuiPrefsDialog(LyXView & lv);
358
359         void apply(LyXRC & rc) const;
360         void updateRc(LyXRC const & rc);
361
362 public Q_SLOTS:
363         void change_adaptor();
364
365 public:
366         //
367         void closeEvent(QCloseEvent * e);
368         ///
369         void add(PrefModule * module);
370         ///
371         Converters & converters();
372         ///
373         Formats & formats();
374         ///
375         Movers & movers();
376         /// parent controller
377         ControlPrefs & controller();
378         /// Apply changes
379         void applyView();
380         /// update (do we need this?)
381         void updateContents();
382
383         std::vector<PrefModule *> modules_;
384 };
385
386
387 } // namespace frontend
388 } // namespace lyx
389
390 #endif // GUIPREFS_H