]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
* fix spelling in comments to please John.
[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
95         /// general browse
96         QString browse(QString const & file, QString const & title) const;
97
98         /// set a color
99         void setColor(ColorCode col, QString const & hex);
100
101         /// update the screen fonts after change
102         void updateScreenFonts();
103
104         /// adjust the prefs paper sizes
105         PAPER_SIZE toPaperSize(int i) const;
106         /// adjust the prefs paper sizes
107         int fromPaperSize(PAPER_SIZE papersize) const;
108
109         LyXRC & rc() { return rc_; }
110         Converters & converters() { return converters_; }
111         Formats & formats() { return formats_; }
112         Movers & movers() { return movers_; }
113
114 private:
115         ///
116         void addModule(PrefModule * module);
117
118         /// temporary lyxrc
119         LyXRC rc_;
120         /// temporary converters
121         Converters converters_;
122         /// temporary formats
123         Formats formats_;
124         /// temporary movers
125         Movers movers_;
126
127         /// A list of colors to be dispatched
128         std::vector<std::string> colors_;
129
130         bool redraw_gui_;
131         bool update_screen_font_;
132 };
133
134
135 class PrefModule : public QWidget
136 {
137         Q_OBJECT
138 public:
139         PrefModule(QString const & cat, QString const & t,
140                         GuiPreferences * form)
141                 : QWidget(form), category_(cat), title_(t), form_(form)
142         {}
143
144         virtual void apply(LyXRC & rc) const = 0;
145         virtual void update(LyXRC const & rc) = 0;
146
147         QString const & category() const { return category_; }
148         QString const & title() const { return title_; }
149
150 protected:
151         QString category_;
152         QString title_;
153         GuiPreferences * form_;
154
155 Q_SIGNALS:
156         void changed();
157 };
158
159
160 class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi
161 {
162         Q_OBJECT
163 public:
164         PrefPlaintext(GuiPreferences * form);
165
166         virtual void apply(LyXRC & rc) const;
167         virtual void update(LyXRC const & rc);
168 };
169
170
171 class PrefDate : public PrefModule, public Ui::PrefDateUi
172 {
173         Q_OBJECT
174 public:
175         PrefDate(GuiPreferences * form);
176
177         virtual void apply(LyXRC & rc) const;
178         virtual void update(LyXRC const & rc);
179
180 private Q_SLOTS:
181         void on_DateED_textChanged(const QString &);
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         virtual void enableCB();
213 private Q_SLOTS:
214         void on_popupTextCB_clicked();
215         void on_inlineTextCB_clicked();
216 };
217
218
219 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
220 {
221         Q_OBJECT
222 public:
223         PrefLatex(GuiPreferences * form);
224
225         virtual void apply(LyXRC & rc) const;
226         virtual void update(LyXRC const & rc);
227
228 private Q_SLOTS:
229         void on_latexEncodingCB_stateChanged(int state);
230         void on_latexBibtexCO_activated(int n);
231         void on_latexIndexCO_activated(int n);
232
233 private:
234         ///
235         std::set<std::string> bibtex_alternatives;
236         ///
237         std::set<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 private Q_SLOTS:
287         void on_instantPreviewCO_currentIndexChanged(int);
288 };
289
290
291 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
292 {
293         Q_OBJECT
294 public:
295         PrefPaths(GuiPreferences * form);
296
297         void apply(LyXRC & rc) const;
298         void update(LyXRC const & rc);
299
300 private Q_SLOTS:
301         void selectExampledir();
302         void selectTemplatedir();
303         void selectTempdir();
304         void selectBackupdir();
305         void selectWorkingdir();
306         void selectThesaurusdir();
307         void selectHunspelldir();
308         void selectLyxPipe();
309
310 };
311
312
313 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
314 {
315         Q_OBJECT
316 public:
317         PrefSpellchecker(GuiPreferences * form);
318
319         void apply(LyXRC & rc) const;
320         void update(LyXRC const & rc);
321
322 };
323
324
325 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
326 {
327         Q_OBJECT
328 public:
329         PrefConverters(GuiPreferences * form);
330
331         void apply(LyXRC & rc) const;
332         void update(LyXRC const & rc);
333
334 public Q_SLOTS:
335         void updateGui();
336
337 private Q_SLOTS:
338         void updateConverter();
339         void switchConverter();
340         void removeConverter();
341         void changeConverter();
342         void on_cacheCB_stateChanged(int state);
343
344 private:
345         void updateButtons();
346 };
347
348
349 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
350 {
351         Q_OBJECT
352 public:
353         PrefFileformats(GuiPreferences * form);
354
355         void apply(LyXRC & rc) const;
356         void update(LyXRC const & rc);
357         void updateView();
358
359 Q_SIGNALS:
360         void formatsChanged();
361
362 private Q_SLOTS:
363         void on_copierED_textEdited(const QString & s);
364         void on_extensionED_textEdited(const QString &);
365         void on_viewerED_textEdited(const QString &);
366         void on_editorED_textEdited(const QString &);
367         void on_shortcutED_textEdited(const QString &);
368         void on_formatED_editingFinished();
369         void on_formatED_textChanged(const QString &);
370         void on_formatsCB_currentIndexChanged(int);
371         void on_formatsCB_editTextChanged(const QString &);
372         void on_formatNewPB_clicked();
373         void on_formatRemovePB_clicked();
374         void on_viewerCO_currentIndexChanged(int i);
375         void on_editorCO_currentIndexChanged(int i);
376         void setFlags();
377         void updatePrettyname();
378
379 private:
380         Format & currentFormat();
381         ///
382         void updateViewers();
383         ///
384         void updateEditors();
385         ///
386         LyXRC::Alternatives viewer_alternatives;
387         ///
388         LyXRC::Alternatives editor_alternatives;
389 };
390
391
392 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
393 {
394         Q_OBJECT
395 public:
396         PrefLanguage(GuiPreferences * form);
397
398         void apply(LyXRC & rc) const;
399         void update(LyXRC const & rc);
400
401 private Q_SLOTS:
402         void on_uiLanguageCO_currentIndexChanged(int);
403 };
404
405
406 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
407 {
408         Q_OBJECT
409 public:
410         PrefPrinter(GuiPreferences * form);
411
412         void apply(LyXRC & rc) const;
413         void update(LyXRC const & rc);
414 };
415
416
417 class PrefUserInterface : public PrefModule, public Ui::PrefUi
418 {
419         Q_OBJECT
420 public:
421         PrefUserInterface(GuiPreferences * form);
422
423         void apply(LyXRC & rc) const;
424         void update(LyXRC const & rc);
425
426 public Q_SLOTS:
427         void selectUi();
428         void on_clearSessionPB_clicked();
429 };
430
431
432 class PrefEdit : public PrefModule, public Ui::PrefEditUi
433 {
434         Q_OBJECT
435 public:
436         PrefEdit(GuiPreferences * form);
437
438         void apply(LyXRC & rc) const;
439         void update(LyXRC const & rc);
440 };
441
442
443
444 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
445 {
446 public:
447         GuiShortcutDialog(QWidget * parent);
448 };
449
450
451 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
452 {
453         Q_OBJECT
454 public:
455         PrefShortcuts(GuiPreferences * form);
456
457         void apply(LyXRC & rc) const;
458         void update(LyXRC const & rc);
459         void updateShortcutsTW();
460         void modifyShortcut();
461         void removeShortcut();
462         ///
463         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
464         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
465                 KeySequence const & shortcut, KeyMap::ItemType tag);
466
467 public Q_SLOTS:
468         void selectBind();
469         void on_modifyPB_pressed();
470         void on_newPB_pressed();
471         void on_removePB_pressed();
472         void on_searchLE_textEdited();
473         ///
474         void on_shortcutsTW_itemSelectionChanged();
475         void on_shortcutsTW_itemDoubleClicked();
476         ///
477         void shortcutOkPressed();
478         void shortcutCancelPressed();
479         void shortcutClearPressed();
480         void shortcutRemovePressed();
481
482 private:
483         ///
484         GuiShortcutDialog * shortcut_;
485         ///
486         ButtonController shortcut_bc_;
487         /// category items
488         QTreeWidgetItem * editItem_;
489         QTreeWidgetItem * mathItem_;
490         QTreeWidgetItem * bufferItem_;
491         QTreeWidgetItem * layoutItem_;
492         QTreeWidgetItem * systemItem_;
493         // system_bind_ holds bindings from rc.bind_file
494         // user_bind_ holds \bind bindings from user.bind
495         // user_unbind_ holds \unbind bindings from user.bind
496         // When an item is inserted, it is added to user_bind_
497         // When an item from system_bind_ is deleted, it is added to user_unbind_
498         // When an item in user_bind_ or user_unbind_ is deleted, it is 
499         //      deleted (unbind)
500         KeyMap system_bind_;
501         KeyMap user_bind_;
502         KeyMap user_unbind_;
503         ///
504         QString save_lfun_;
505 };
506
507
508 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
509 {
510         Q_OBJECT
511 public:
512         PrefIdentity(GuiPreferences * form);
513
514         void apply(LyXRC & rc) const;
515         void update(LyXRC const & rc);
516 };
517
518
519 } // namespace frontend
520 } // namespace lyx
521
522 #endif // GUIPREFS_H