]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
3e45906e32675c89f033522ba2be23e7f8fd1876
[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 private Q_SLOTS:
182         void on_DateED_textChanged(const QString &);
183 };
184
185
186 class PrefInput : public PrefModule, public Ui::PrefInputUi
187 {
188         Q_OBJECT
189 public:
190         PrefInput(GuiPreferences * form);
191
192         virtual void apply(LyXRC & rc) const;
193         virtual void update(LyXRC const & rc);
194
195 private Q_SLOTS:
196         void on_firstKeymapPB_clicked(bool);
197         void on_secondKeymapPB_clicked(bool);
198         void on_keymapCB_toggled(bool);
199
200 private:
201         QString testKeymap(QString const & keymap);
202 };
203
204
205 class PrefCompletion : public PrefModule, public Ui::PrefCompletionUi
206 {
207         Q_OBJECT
208 public:
209         PrefCompletion(GuiPreferences * form);
210
211         virtual void apply(LyXRC & rc) const;
212         virtual void update(LyXRC const & rc);
213 };
214
215
216 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
217 {
218         Q_OBJECT
219 public:
220         PrefLatex(GuiPreferences * form);
221
222         virtual void apply(LyXRC & rc) const;
223         virtual void update(LyXRC const & rc);
224
225 private Q_SLOTS:
226         void on_latexBibtexCO_activated(int n);
227         void on_latexIndexCO_activated(int n);
228
229 private:
230         ///
231         std::vector<std::string> bibtex_alternatives;
232         ///
233         std::vector<std::string> index_alternatives;
234 };
235
236
237 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
238 {
239         Q_OBJECT
240 public:
241         PrefScreenFonts(GuiPreferences * form);
242
243         virtual void apply(LyXRC & rc) const;
244         virtual void update(LyXRC const & rc);
245
246 private Q_SLOTS:
247         void select_roman(const QString&);
248         void select_sans(const QString&);
249         void select_typewriter(const QString&);
250 };
251
252
253 class PrefColors : public PrefModule, public Ui::PrefColorsUi
254 {
255         Q_OBJECT
256 public:
257         PrefColors(GuiPreferences * form);
258
259         void apply(LyXRC & rc) const;
260         void update(LyXRC const & rc);
261
262 private Q_SLOTS:
263         void change_color();
264         void change_lyxObjects_selection();
265
266 private:
267         std::vector<ColorCode> lcolors_;
268         std::vector<QString> curcolors_;
269         std::vector<QString> newcolors_;
270 };
271
272
273 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
274 {
275         Q_OBJECT
276 public:
277         PrefDisplay(GuiPreferences * form);
278
279         void apply(LyXRC & rc) const;
280         void update(LyXRC const & rc);
281 };
282
283
284 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
285 {
286         Q_OBJECT
287 public:
288         PrefPaths(GuiPreferences * form);
289
290         void apply(LyXRC & rc) const;
291         void update(LyXRC const & rc);
292
293 private Q_SLOTS:
294         void select_exampledir();
295         void select_templatedir();
296         void select_tempdir();
297         void select_backupdir();
298         void select_workingdir();
299         void select_thesaurusdir();
300         void select_lyxpipe();
301
302 };
303
304
305 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
306 {
307         Q_OBJECT
308 public:
309         PrefSpellchecker(GuiPreferences * form);
310
311         void apply(LyXRC & rc) const;
312         void update(LyXRC const & rc);
313
314 private Q_SLOTS:
315         void select_dict();
316 };
317
318
319 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
320 {
321         Q_OBJECT
322 public:
323         PrefConverters(GuiPreferences * form);
324
325         void apply(LyXRC & rc) const;
326         void update(LyXRC const & rc);
327
328 public Q_SLOTS:
329         void updateGui();
330
331 private Q_SLOTS:
332         void update_converter();
333         void switch_converter();
334         void converter_changed();
335         void remove_converter();
336         void on_cacheCB_stateChanged(int state);
337
338 private:
339         void updateButtons();
340 };
341
342
343 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
344 {
345         Q_OBJECT
346 public:
347         PrefFileformats(GuiPreferences * form);
348
349         void apply(LyXRC & rc) const;
350         void update(LyXRC const & rc);
351         void updateView();
352
353 Q_SIGNALS:
354         void formatsChanged();
355
356 private Q_SLOTS:
357         void on_copierED_textEdited(const QString & s);
358         void on_extensionED_textEdited(const QString &);
359         void on_viewerED_textEdited(const QString &);
360         void on_editorED_textEdited(const QString &);
361         void on_shortcutED_textEdited(const QString &);
362         void on_formatED_editingFinished();
363         void on_formatED_textChanged(const QString &);
364         void on_formatsCB_currentIndexChanged(int);
365         void on_formatsCB_editTextChanged(const QString &);
366         void on_formatNewPB_clicked();
367         void on_formatRemovePB_clicked();
368         void setFlags();
369         void updatePrettyname();
370
371 private:
372         Format & currentFormat();
373 };
374
375
376 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
377 {
378         Q_OBJECT
379 public:
380         PrefLanguage(GuiPreferences * form);
381
382         void apply(LyXRC & rc) const;
383         void update(LyXRC const & rc);
384
385 private Q_SLOTS:
386         void on_uiLanguageCO_currentIndexChanged(int);
387 };
388
389
390 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
391 {
392         Q_OBJECT
393 public:
394         PrefPrinter(GuiPreferences * form);
395
396         void apply(LyXRC & rc) const;
397         void update(LyXRC const & rc);
398 };
399
400
401 class PrefUserInterface : public PrefModule, public Ui::PrefUi
402 {
403         Q_OBJECT
404 public:
405         PrefUserInterface(GuiPreferences * form);
406
407         void apply(LyXRC & rc) const;
408         void update(LyXRC const & rc);
409
410 public Q_SLOTS:
411         void select_ui();
412         void on_clearSessionPB_clicked();
413 };
414
415
416 class PrefEdit : public PrefModule, public Ui::PrefEditUi
417 {
418         Q_OBJECT
419 public:
420         PrefEdit(GuiPreferences * form);
421
422         void apply(LyXRC & rc) const;
423         void update(LyXRC const & rc);
424 };
425
426
427
428 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
429 {
430 public:
431         GuiShortcutDialog(QWidget * parent);
432 };
433
434
435 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
436 {
437         Q_OBJECT
438 public:
439         PrefShortcuts(GuiPreferences * form);
440
441         void apply(LyXRC & rc) const;
442         void update(LyXRC const & rc);
443         void updateShortcutsTW();
444         void modifyShortcut();
445         void removeShortcut();
446         ///
447         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
448         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
449                 KeySequence const & shortcut, KeyMap::ItemType tag);
450
451 public Q_SLOTS:
452         void select_bind();
453         void on_modifyPB_pressed();
454         void on_newPB_pressed();
455         void on_removePB_pressed();
456         void on_searchLE_textEdited();
457         ///
458         void on_shortcutsTW_itemSelectionChanged();
459         void shortcut_okPB_pressed();
460         void shortcut_cancelPB_pressed();
461         void shortcut_clearPB_pressed();
462         void shortcut_removePB_pressed();
463         void on_shortcutsTW_itemDoubleClicked();
464
465 private:
466         ///
467         GuiShortcutDialog * shortcut_;
468         ///
469         ButtonController shortcut_bc_;
470         /// category items
471         QTreeWidgetItem * editItem_;
472         QTreeWidgetItem * mathItem_;
473         QTreeWidgetItem * bufferItem_;
474         QTreeWidgetItem * layoutItem_;
475         QTreeWidgetItem * systemItem_;
476         // system_bind_ holds bindings from rc.bind_file
477         // user_bind_ holds \bind bindings from user.bind
478         // user_unbind_ holds \unbind bindings from user.bind
479         // When an item is inserted, it is added to user_bind_
480         // When an item from system_bind_ is deleted, it is added to user_unbind_
481         // When an item in user_bind_ or user_unbind_ is deleted, it is 
482         //      deleted (unbind)
483         KeyMap system_bind_;
484         KeyMap user_bind_;
485         KeyMap user_unbind_;
486         ///
487         QString save_lfun_;
488 };
489
490
491 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
492 {
493         Q_OBJECT
494 public:
495         PrefIdentity(GuiPreferences * form);
496
497         void apply(LyXRC & rc) const;
498         void update(LyXRC const & rc);
499 };
500
501
502 } // namespace frontend
503 } // namespace lyx
504
505 #endif // GUIPREFS_H