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