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