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