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