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