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