]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiPrefs.h
373f14d12717d0a3e32de24d81f28609d0f2095c
[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  * \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 "Color.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 Color_color;
57 class Converters;
58 class Formats;
59 class Movers;
60
61 namespace frontend {
62
63 class GuiPreferences;
64
65 class PrefModule : public QWidget
66 {
67         Q_OBJECT
68 public:
69         PrefModule(docstring const & t,
70                         GuiPreferences * form = 0, QWidget * parent = 0)
71                 : QWidget(parent), title_(t), form_(form)
72         {}
73
74         virtual void apply(LyXRC & rc) const = 0;
75         virtual void update(LyXRC const & rc) = 0;
76
77         docstring const & title() const { return title_; }
78
79 protected:
80         docstring title_;
81         GuiPreferences * form_;
82
83 Q_SIGNALS:
84         void changed();
85 };
86
87
88 class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi
89 {
90         Q_OBJECT
91 public:
92         PrefPlaintext(QWidget * parent = 0);
93
94         virtual void apply(LyXRC & rc) const;
95         virtual void update(LyXRC const & rc);
96 };
97
98
99 class PrefDate : public PrefModule, public Ui::PrefDateUi
100 {
101         Q_OBJECT
102 public:
103         PrefDate(QWidget * parent = 0);
104
105         virtual void apply(LyXRC & rc) const;
106         virtual void update(LyXRC const & rc);
107 };
108
109
110 class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi
111 {
112         Q_OBJECT
113 public:
114         PrefKeyboard(GuiPreferences * form, QWidget * parent = 0);
115
116         virtual void apply(LyXRC & rc) const;
117         virtual void update(LyXRC const & rc);
118
119 private Q_SLOTS:
120         void on_firstKeymapPB_clicked(bool);
121         void on_secondKeymapPB_clicked(bool);
122         void on_keymapCB_toggled(bool);
123
124 private:
125         QString testKeymap(QString keymap);
126 };
127
128
129 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
130 {
131         Q_OBJECT
132 public:
133         PrefLatex(GuiPreferences * form, QWidget * parent = 0);
134
135         virtual void apply(LyXRC & rc) const;
136         virtual void update(LyXRC const & rc);
137 };
138
139
140 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
141 {
142         Q_OBJECT
143 public:
144         PrefScreenFonts(GuiPreferences * form, QWidget * parent = 0);
145
146         virtual void apply(LyXRC & rc) const;
147         virtual void update(LyXRC const & rc);
148
149 private Q_SLOTS:
150         void select_roman(const QString&);
151         void select_sans(const QString&);
152         void select_typewriter(const QString&);
153 };
154
155
156 class PrefColors : public PrefModule, public Ui::PrefColorsUi
157 {
158         Q_OBJECT
159 public:
160         PrefColors(GuiPreferences * form, QWidget * parent = 0);
161
162         void apply(LyXRC & rc) const;
163         void update(LyXRC const & rc);
164
165 private Q_SLOTS:
166         void change_color();
167         void change_lyxObjects_selection();
168
169 private:
170         std::vector<Color_color> lcolors_;
171         // FIXME the use of mutable here is required due to the
172         // fact that initialization is not done in the controller
173         // but in the constructor.
174         std::vector<QString> curcolors_;
175         std::vector<QString> newcolors_;
176
177 };
178
179
180 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
181 {
182         Q_OBJECT
183 public:
184         PrefDisplay(QWidget * parent = 0);
185
186         void apply(LyXRC & rc) const;
187         void update(LyXRC const & rc);
188 };
189
190
191 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
192 {
193         Q_OBJECT
194 public:
195         PrefPaths(GuiPreferences * form, QWidget * parent = 0);
196
197         void apply(LyXRC & rc) const;
198         void update(LyXRC const & rc);
199
200 private Q_SLOTS:
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         void on_loadWindowSizeCB_toggled(bool);
348
349 };
350
351
352 /**
353  * A lineedit for inputting shortcuts
354  */
355 class ShortcutEdit : public QLineEdit {
356         Q_OBJECT
357 public:
358         ShortcutEdit(QWidget * parent) : QLineEdit(parent) {}
359 protected Q_SLOTS:
360         void keyPressEvent(QKeyEvent * e);
361         bool event(QEvent* e);
362 };
363
364
365 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
366 {
367 public:
368         GuiShortcutDialog(QWidget * parent);
369         ShortcutEdit * shortcutLE;
370 };
371
372
373 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
374 {
375         Q_OBJECT
376 private:
377         enum item_type {
378                 System,         //< loaded from a bind file
379                 UserBind,       //< \bind loaded from user.bind
380                 UserUnbind,     //< \unbind loaded from user.bind, with corresponding
381                                         //<    entry in system bind file
382                 UserExtraUnbind //< \unbind loaded from user.bind, without
383                                                 //<    corresponding entry in system bind file.
384         };
385 public:
386         PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);
387
388         void apply(LyXRC & rc) const;
389         void update(LyXRC const & rc);
390         void updateShortcutsTW();
391         ///
392         void setItemType(QTreeWidgetItem * item, item_type tag);
393         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
394                 KeySequence const & shortcut, item_type tag);
395
396 public Q_SLOTS:
397         void select_bind();
398         void on_newPB_pressed();
399         void on_removePB_pressed();
400         void on_searchPB_pressed();
401         void on_searchLE_textChanged();
402         ///
403         void on_shortcutsTW_itemSelectionChanged();
404         void shortcut_okPB_pressed();
405         void shortcut_clearPB_pressed();
406         void on_shortcutsTW_itemDoubleClicked();
407
408 private:
409         ///
410         GuiShortcutDialog * shortcut_;
411         ///
412         ButtonController shortcut_bc_;
413         /// category items
414         QTreeWidgetItem * editItem_;
415         QTreeWidgetItem * mathItem_;
416         QTreeWidgetItem * bufferItem_;
417         QTreeWidgetItem * layoutItem_;
418         QTreeWidgetItem * systemItem_;
419         // system_bind_ holds bindings from rc.bind_file
420         // user_bind_ holds \bind bindings from user.bind
421         // user_unbind_ holds \unbind bindings from user.bind
422         // When an item is inserted, it is added to user_bind_
423         // When an item from system_bind_ is deleted, it is added to user_unbind_
424         // When an item in user_bind_ or user_unbind_ is deleted, it is 
425         //      deleted (unbind)
426         KeyMap system_bind_;
427         KeyMap user_bind_;
428         KeyMap user_unbind_;
429 };
430
431
432 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
433 {
434         Q_OBJECT
435 public:
436         PrefIdentity(QWidget * parent = 0);
437
438         void apply(LyXRC & rc) const;
439         void update(LyXRC const & rc);
440 };
441
442
443 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
444 {
445         Q_OBJECT
446 public:
447         GuiPreferences(LyXView & lv);
448
449         void apply(LyXRC & rc) const;
450         void updateRc(LyXRC const & rc);
451
452 public Q_SLOTS:
453         void change_adaptor();
454
455 public:
456         //
457         void closeEvent(QCloseEvent * e);
458         ///
459         void add(PrefModule * module);
460         /// Apply changes
461         void applyView();
462         /// update (do we need this?)
463         void updateContents();
464
465         std::vector<PrefModule *> modules_;
466
467         ///
468         bool initialiseParams(std::string const &);
469         ///
470         void clearParams() {}
471         ///
472         void dispatchParams();
473         ///
474         bool isBufferDependent() const { return false; }
475
476         /// various file pickers
477         docstring const browsebind(docstring const & file) const;
478         docstring const browseUI(docstring const & file) const;
479         docstring const browsekbmap(docstring const & file) const;
480         docstring const browsedict(docstring const & file) const;
481
482         /// general browse
483         docstring const browse(docstring const & file,
484                                  docstring const & title) const;
485
486         /// browse directory
487         docstring const browsedir(docstring const & path,
488                                     docstring const & title) const;
489
490         /// set a color
491         void setColor(Color_color col, std::string const & hex);
492
493         /// update the screen fonts after change
494         void updateScreenFonts();
495
496         /// adjust the prefs paper sizes
497         PAPER_SIZE toPaperSize(int i) const;
498         /// adjust the prefs paper sizes
499         int fromPaperSize(PAPER_SIZE papersize) const;
500
501         LyXRC & rc() { return rc_; }
502         Converters & converters() { return converters_; }
503         Formats & formats() { return formats_; }
504         Movers & movers() { return movers_; }
505
506 private:
507         /// temporary lyxrc
508         LyXRC rc_;
509         /// temporary converters
510         Converters converters_;
511         /// temporary formats
512         Formats formats_;
513         /// temporary movers
514         Movers movers_;
515
516         /// A list of colors to be dispatched
517         std::vector<std::string> colors_;
518
519         bool redraw_gui_;
520         bool update_screen_font_;
521 };
522
523
524 } // namespace frontend
525 } // namespace lyx
526
527 #endif // GUIPREFS_H