]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiPrefs.h
Separate PrefShortcuts from PrefUi, in preparation for a shortcuts configuration...
[features.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
17 #include "Color.h"
18 #include "Converter.h"
19 #include "Format.h"
20 #include "LyXRC.h"
21 #include "Mover.h"
22
23 #include "ui_PrefsUi.h"
24
25 #include "ui_PrefPlaintextUi.h"
26 #include "ui_PrefDateUi.h"
27 #include "ui_PrefKeyboardUi.h"
28 #include "ui_PrefLatexUi.h"
29 #include "ui_PrefScreenFontsUi.h"
30 #include "ui_PrefColorsUi.h"
31 #include "ui_PrefDisplayUi.h"
32 #include "ui_PrefPathsUi.h"
33 #include "ui_PrefShortcutsUi.h"
34 #include "ui_PrefSpellcheckerUi.h"
35 #include "ui_PrefConvertersUi.h"
36 #include "ui_PrefFileformatsUi.h"
37 #include "ui_PrefLanguageUi.h"
38 #include "ui_PrefPrinterUi.h"
39 #include "ui_PrefUi.h"
40 #include "ui_PrefIdentityUi.h"
41
42 #include <QDialog>
43 #include <QValidator>
44
45 #include <string>
46 #include <vector>
47
48
49 namespace lyx {
50
51 class Color_color;
52 class Converters;
53 class Formats;
54 class Movers;
55
56 namespace frontend {
57
58 class GuiPreferences;
59
60 class PrefModule : public QWidget
61 {
62         Q_OBJECT
63 public:
64         PrefModule(docstring const & t,
65                         GuiPreferences * form = 0, QWidget * parent = 0)
66                 : QWidget(parent), title_(t), form_(form)
67         {}
68
69         virtual void apply(LyXRC & rc) const = 0;
70         virtual void update(LyXRC const & rc) = 0;
71
72         docstring const & title() const { return title_; }
73
74 protected:
75         docstring title_;
76         GuiPreferences * form_;
77
78 Q_SIGNALS:
79         void changed();
80 };
81
82
83 class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi
84 {
85         Q_OBJECT
86 public:
87         PrefPlaintext(QWidget * parent = 0);
88
89         virtual void apply(LyXRC & rc) const;
90         virtual void update(LyXRC const & rc);
91 };
92
93
94 class PrefDate : public PrefModule, public Ui::PrefDateUi
95 {
96         Q_OBJECT
97 public:
98         PrefDate(QWidget * parent = 0);
99
100         virtual void apply(LyXRC & rc) const;
101         virtual void update(LyXRC const & rc);
102 };
103
104
105 class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi
106 {
107         Q_OBJECT
108 public:
109         PrefKeyboard(GuiPreferences * form, QWidget * parent = 0);
110
111         virtual void apply(LyXRC & rc) const;
112         virtual void update(LyXRC const & rc);
113
114 private Q_SLOTS:
115         void on_firstKeymapPB_clicked(bool);
116         void on_secondKeymapPB_clicked(bool);
117         void on_keymapCB_toggled(bool);
118
119 private:
120         QString testKeymap(QString keymap);
121 };
122
123
124 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
125 {
126         Q_OBJECT
127 public:
128         PrefLatex(GuiPreferences * form, QWidget * parent = 0);
129
130         virtual void apply(LyXRC & rc) const;
131         virtual void update(LyXRC const & rc);
132 };
133
134
135 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
136 {
137         Q_OBJECT
138 public:
139         PrefScreenFonts(GuiPreferences * form, QWidget * parent = 0);
140
141         virtual void apply(LyXRC & rc) const;
142         virtual void update(LyXRC const & rc);
143
144 private Q_SLOTS:
145         void select_roman(const QString&);
146         void select_sans(const QString&);
147         void select_typewriter(const QString&);
148 };
149
150
151 class PrefColors : public PrefModule, public Ui::PrefColorsUi
152 {
153         Q_OBJECT
154 public:
155         PrefColors(GuiPreferences * form, QWidget * parent = 0);
156
157         void apply(LyXRC & rc) const;
158         void update(LyXRC const & rc);
159
160 private Q_SLOTS:
161         void change_color();
162         void change_lyxObjects_selection();
163
164 private:
165         std::vector<Color_color> lcolors_;
166         // FIXME the use of mutable here is required due to the
167         // fact that initialization is not done in the controller
168         // but in the constructor.
169         std::vector<QString> curcolors_;
170         std::vector<QString> newcolors_;
171
172 };
173
174
175 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
176 {
177         Q_OBJECT
178 public:
179         PrefDisplay(QWidget * parent = 0);
180
181         void apply(LyXRC & rc) const;
182         void update(LyXRC const & rc);
183 };
184
185
186 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
187 {
188         Q_OBJECT
189 public:
190         PrefPaths(GuiPreferences * form, QWidget * parent = 0);
191
192         void apply(LyXRC & rc) const;
193         void update(LyXRC const & rc);
194
195 private Q_SLOTS:
196         void select_templatedir();
197         void select_tempdir();
198         void select_backupdir();
199         void select_workingdir();
200         void select_lyxpipe();
201
202 };
203
204
205 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
206 {
207         Q_OBJECT
208 public:
209         PrefSpellchecker(GuiPreferences * form, QWidget * parent = 0);
210
211         void apply(LyXRC & rc) const;
212         void update(LyXRC const & rc);
213
214 private Q_SLOTS:
215         void select_dict();
216 };
217
218
219 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
220 {
221         Q_OBJECT
222 public:
223         PrefConverters(GuiPreferences * form, QWidget * parent = 0);
224
225         void apply(LyXRC & rc) const;
226         void update(LyXRC const & rc);
227
228 public Q_SLOTS:
229         void updateGui();
230
231 private Q_SLOTS:
232         void update_converter();
233         void switch_converter();
234         void converter_changed();
235         void remove_converter();
236         void on_cacheCB_stateChanged(int state);
237
238 private:
239         void updateButtons();
240 };
241
242
243 class FormatValidator : public QValidator
244 {
245 public:
246         FormatValidator(QWidget *, Formats const & f);
247         void fixup(QString & input) const;
248         QValidator::State validate(QString & input, int & pos) const;
249 private:
250         virtual std::string str(Formats::const_iterator it) const = 0;
251         int nr() const;
252         Formats const & formats_;
253 };
254
255
256 class FormatNameValidator : public FormatValidator
257 {
258 public:
259         FormatNameValidator(QWidget *, Formats const & f);
260 private:
261         std::string str(Formats::const_iterator it) const;
262 };
263
264 class FormatPrettynameValidator : public FormatValidator
265 {
266 public:
267         FormatPrettynameValidator(QWidget *, Formats const & f);
268 private:
269         std::string str(Formats::const_iterator it) const;
270 };
271
272
273 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
274 {
275         Q_OBJECT
276 public:
277         PrefFileformats(GuiPreferences * form, QWidget * parent = 0);
278
279         void apply(LyXRC & rc) const;
280         void update(LyXRC const & rc);
281         void updateView();
282
283 Q_SIGNALS:
284         void formatsChanged();
285
286 private Q_SLOTS:
287         void on_copierED_textEdited(const QString & s);
288         void on_extensionED_textEdited(const QString &);
289         void on_viewerED_textEdited(const QString &);
290         void on_editorED_textEdited(const QString &);
291         void on_shortcutED_textEdited(const QString &);
292         void on_formatED_editingFinished();
293         void on_formatED_textChanged(const QString &);
294         void on_formatsCB_currentIndexChanged(int);
295         void on_formatsCB_editTextChanged(const QString &);
296         void on_formatNewPB_clicked();
297         void on_formatRemovePB_clicked();
298         void setFlags();
299         void updatePrettyname();
300
301 private:
302         Format & currentFormat();
303 };
304
305
306 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
307 {
308         Q_OBJECT
309 public:
310         PrefLanguage(QWidget * parent = 0);
311
312         void apply(LyXRC & rc) const;
313         void update(LyXRC const & rc);
314
315 private:
316         std::vector<std::string> lang_;
317 };
318
319
320 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
321 {
322         Q_OBJECT
323 public:
324         PrefPrinter(QWidget * parent = 0);
325
326         void apply(LyXRC & rc) const;
327         void update(LyXRC const & rc);
328 };
329
330
331 class PrefUserInterface : public PrefModule, public Ui::PrefUi
332 {
333         Q_OBJECT
334 public:
335         PrefUserInterface(GuiPreferences * form, QWidget * parent = 0);
336
337         void apply(LyXRC & rc) const;
338         void update(LyXRC const & rc);
339
340 public Q_SLOTS:
341         void select_ui();
342         void on_loadWindowSizeCB_toggled(bool);
343
344 };
345
346
347 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
348 {
349         Q_OBJECT
350 public:
351         PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);
352
353         void apply(LyXRC & rc) const;
354         void update(LyXRC const & rc);
355
356 public Q_SLOTS:
357         void select_bind();
358
359 };
360
361
362 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
363 {
364         Q_OBJECT
365 public:
366         PrefIdentity(QWidget * parent = 0);
367
368         void apply(LyXRC & rc) const;
369         void update(LyXRC const & rc);
370 };
371
372
373 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
374 {
375         Q_OBJECT
376 public:
377         GuiPreferences(LyXView & lv);
378
379         void apply(LyXRC & rc) const;
380         void updateRc(LyXRC const & rc);
381
382 public Q_SLOTS:
383         void change_adaptor();
384
385 public:
386         //
387         void closeEvent(QCloseEvent * e);
388         ///
389         void add(PrefModule * module);
390         /// Apply changes
391         void applyView();
392         /// update (do we need this?)
393         void updateContents();
394
395         std::vector<PrefModule *> modules_;
396
397         ///
398         bool initialiseParams(std::string const &);
399         ///
400         void clearParams() {}
401         ///
402         void dispatchParams();
403         ///
404         bool isBufferDependent() const { return false; }
405
406         /// various file pickers
407         docstring const browsebind(docstring const & file) const;
408         docstring const browseUI(docstring const & file) const;
409         docstring const browsekbmap(docstring const & file) const;
410         docstring const browsedict(docstring const & file) const;
411
412         /// general browse
413         docstring const browse(docstring const & file,
414                                  docstring const & title) const;
415
416         /// browse directory
417         docstring const browsedir(docstring const & path,
418                                     docstring const & title) const;
419
420         /// set a color
421         void setColor(Color_color col, std::string const & hex);
422
423         /// update the screen fonts after change
424         void updateScreenFonts();
425
426         /// adjust the prefs paper sizes
427         PAPER_SIZE toPaperSize(int i) const;
428         /// adjust the prefs paper sizes
429         int fromPaperSize(PAPER_SIZE papersize) const;
430
431         LyXRC & rc() { return rc_; }
432         Converters & converters() { return converters_; }
433         Formats & formats() { return formats_; }
434         Movers & movers() { return movers_; }
435
436 private:
437         /// temporary lyxrc
438         LyXRC rc_;
439         /// temporary converters
440         Converters converters_;
441         /// temporary formats
442         Formats formats_;
443         /// temporary movers
444         Movers movers_;
445
446         /// A list of colors to be dispatched
447         std::vector<std::string> colors_;
448
449         bool redraw_gui_;
450         bool update_screen_font_;
451 };
452
453
454 } // namespace frontend
455 } // namespace lyx
456
457 #endif // GUIPREFS_H