]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
do what the FIXME suggested
[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_PrefInputUi.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 PrefInput : public PrefModule, public Ui::PrefInputUi
110 {
111         Q_OBJECT
112 public:
113         PrefInput(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_exampledir();
201         void select_templatedir();
202         void select_tempdir();
203         void select_backupdir();
204         void select_workingdir();
205         void select_lyxpipe();
206
207 };
208
209
210 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
211 {
212         Q_OBJECT
213 public:
214         PrefSpellchecker(GuiPreferences * form, QWidget * parent = 0);
215
216         void apply(LyXRC & rc) const;
217         void update(LyXRC const & rc);
218
219 private Q_SLOTS:
220         void select_dict();
221 };
222
223
224 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
225 {
226         Q_OBJECT
227 public:
228         PrefConverters(GuiPreferences * form, QWidget * parent = 0);
229
230         void apply(LyXRC & rc) const;
231         void update(LyXRC const & rc);
232
233 public Q_SLOTS:
234         void updateGui();
235
236 private Q_SLOTS:
237         void update_converter();
238         void switch_converter();
239         void converter_changed();
240         void remove_converter();
241         void on_cacheCB_stateChanged(int state);
242
243 private:
244         void updateButtons();
245 };
246
247
248 class FormatValidator : public QValidator
249 {
250 public:
251         FormatValidator(QWidget *, Formats const & f);
252         void fixup(QString & input) const;
253         QValidator::State validate(QString & input, int & pos) const;
254 private:
255         virtual std::string str(Formats::const_iterator it) const = 0;
256         int nr() const;
257         Formats const & formats_;
258 };
259
260
261 class FormatNameValidator : public FormatValidator
262 {
263 public:
264         FormatNameValidator(QWidget *, Formats const & f);
265 private:
266         std::string str(Formats::const_iterator it) const;
267 };
268
269 class FormatPrettynameValidator : public FormatValidator
270 {
271 public:
272         FormatPrettynameValidator(QWidget *, Formats const & f);
273 private:
274         std::string str(Formats::const_iterator it) const;
275 };
276
277
278 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
279 {
280         Q_OBJECT
281 public:
282         PrefFileformats(GuiPreferences * form, QWidget * parent = 0);
283
284         void apply(LyXRC & rc) const;
285         void update(LyXRC const & rc);
286         void updateView();
287
288 Q_SIGNALS:
289         void formatsChanged();
290
291 private Q_SLOTS:
292         void on_copierED_textEdited(const QString & s);
293         void on_extensionED_textEdited(const QString &);
294         void on_viewerED_textEdited(const QString &);
295         void on_editorED_textEdited(const QString &);
296         void on_shortcutED_textEdited(const QString &);
297         void on_formatED_editingFinished();
298         void on_formatED_textChanged(const QString &);
299         void on_formatsCB_currentIndexChanged(int);
300         void on_formatsCB_editTextChanged(const QString &);
301         void on_formatNewPB_clicked();
302         void on_formatRemovePB_clicked();
303         void setFlags();
304         void updatePrettyname();
305
306 private:
307         Format & currentFormat();
308 };
309
310
311 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
312 {
313         Q_OBJECT
314 public:
315         PrefLanguage(QWidget * parent = 0);
316
317         void apply(LyXRC & rc) const;
318         void update(LyXRC const & rc);
319
320 private:
321         std::vector<std::string> lang_;
322 };
323
324
325 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
326 {
327         Q_OBJECT
328 public:
329         PrefPrinter(QWidget * parent = 0);
330
331         void apply(LyXRC & rc) const;
332         void update(LyXRC const & rc);
333 };
334
335
336 class PrefUserInterface : public PrefModule, public Ui::PrefUi
337 {
338         Q_OBJECT
339 public:
340         PrefUserInterface(GuiPreferences * form, QWidget * parent = 0);
341
342         void apply(LyXRC & rc) const;
343         void update(LyXRC const & rc);
344
345 public Q_SLOTS:
346         void select_ui();
347 };
348
349
350 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
351 {
352 public:
353         GuiShortcutDialog(QWidget * parent);
354 };
355
356
357 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
358 {
359         Q_OBJECT
360 private:
361         enum item_type {
362                 System,         //< loaded from a bind file
363                 UserBind,       //< \bind loaded from user.bind
364                 UserUnbind,     //< \unbind loaded from user.bind, with corresponding
365                                         //<    entry in system bind file
366                 UserExtraUnbind //< \unbind loaded from user.bind, without
367                                                 //<    corresponding entry in system bind file.
368         };
369 public:
370         PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);
371
372         void apply(LyXRC & rc) const;
373         void update(LyXRC const & rc);
374         void updateShortcutsTW();
375         ///
376         void setItemType(QTreeWidgetItem * item, item_type tag);
377         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
378                 KeySequence const & shortcut, item_type tag);
379
380 public Q_SLOTS:
381         void select_bind();
382         void on_newPB_pressed();
383         void on_removePB_pressed();
384         void on_searchLE_textEdited();
385         ///
386         void on_shortcutsTW_itemSelectionChanged();
387         void shortcut_okPB_pressed();
388         void shortcut_clearPB_pressed();
389         void on_shortcutsTW_itemDoubleClicked();
390
391 private:
392         ///
393         GuiShortcutDialog * shortcut_;
394         ///
395         ButtonController shortcut_bc_;
396         /// category items
397         QTreeWidgetItem * editItem_;
398         QTreeWidgetItem * mathItem_;
399         QTreeWidgetItem * bufferItem_;
400         QTreeWidgetItem * layoutItem_;
401         QTreeWidgetItem * systemItem_;
402         // system_bind_ holds bindings from rc.bind_file
403         // user_bind_ holds \bind bindings from user.bind
404         // user_unbind_ holds \unbind bindings from user.bind
405         // When an item is inserted, it is added to user_bind_
406         // When an item from system_bind_ is deleted, it is added to user_unbind_
407         // When an item in user_bind_ or user_unbind_ is deleted, it is 
408         //      deleted (unbind)
409         KeyMap system_bind_;
410         KeyMap user_bind_;
411         KeyMap user_unbind_;
412 };
413
414
415 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
416 {
417         Q_OBJECT
418 public:
419         PrefIdentity(QWidget * parent = 0);
420
421         void apply(LyXRC & rc) const;
422         void update(LyXRC const & rc);
423 };
424
425
426 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
427 {
428         Q_OBJECT
429 public:
430         GuiPreferences(GuiView & lv);
431
432         void apply(LyXRC & rc) const;
433         void updateRc(LyXRC const & rc);
434
435 public Q_SLOTS:
436         void change_adaptor();
437
438 public:
439         ///
440         void add(PrefModule * module);
441         /// Apply changes
442         void applyView();
443         /// update (do we need this?)
444         void updateContents();
445
446         std::vector<PrefModule *> modules_;
447
448         ///
449         bool initialiseParams(std::string const &);
450         ///
451         void clearParams() {}
452         ///
453         void dispatchParams();
454         ///
455         bool isBufferDependent() const { return false; }
456
457         /// various file pickers
458         docstring const browsebind(docstring const & file) const;
459         docstring const browseUI(docstring const & file) const;
460         docstring const browsekbmap(docstring const & file) const;
461         docstring const browsedict(docstring const & file) const;
462
463         /// general browse
464         docstring const browse(docstring const & file,
465                                  docstring const & title) const;
466
467         /// browse directory
468         docstring const browsedir(docstring const & path,
469                                     docstring const & title) const;
470
471         /// set a color
472         void setColor(ColorCode col, std::string const & hex);
473
474         /// update the screen fonts after change
475         void updateScreenFonts();
476
477         /// adjust the prefs paper sizes
478         PAPER_SIZE toPaperSize(int i) const;
479         /// adjust the prefs paper sizes
480         int fromPaperSize(PAPER_SIZE papersize) const;
481
482         LyXRC & rc() { return rc_; }
483         Converters & converters() { return converters_; }
484         Formats & formats() { return formats_; }
485         Movers & movers() { return movers_; }
486
487 private:
488         /// temporary lyxrc
489         LyXRC rc_;
490         /// temporary converters
491         Converters converters_;
492         /// temporary formats
493         Formats formats_;
494         /// temporary movers
495         Movers movers_;
496
497         /// A list of colors to be dispatched
498         std::vector<std::string> colors_;
499
500         bool redraw_gui_;
501         bool update_screen_font_;
502 };
503
504
505 } // namespace frontend
506 } // namespace lyx
507
508 #endif // GUIPREFS_H