]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
On Linux show in crash message box the backtrace
[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 "Converter.h"
20 #include "Format.h"
21 #include "KeyMap.h"
22 #include "LyXRC.h"
23 #include "Mover.h"
24
25 #include "ui_PrefsUi.h"
26
27 #include "ui_PrefOutputUi.h"
28 #include "ui_PrefInputUi.h"
29 #include "ui_PrefLatexUi.h"
30 #include "ui_PrefScreenFontsUi.h"
31 #include "ui_PrefCompletionUi.h"
32 #include "ui_PrefColorsUi.h"
33 #include "ui_PrefDisplayUi.h"
34 #include "ui_PrefDocHandlingUi.h"
35 #include "ui_PrefEditUi.h"
36 #include "ui_PrefPathsUi.h"
37 #include "ui_PrefShortcutsUi.h"
38 #include "ui_PrefSpellcheckerUi.h"
39 #include "ui_PrefConvertersUi.h"
40 #include "ui_PrefFileformatsUi.h"
41 #include "ui_PrefLanguageUi.h"
42 #include "ui_PrefPrinterUi.h"
43 #include "ui_PrefUi.h"
44 #include "ui_PrefIdentityUi.h"
45 #include "ui_ShortcutUi.h"
46
47 #include <string>
48 #include <vector>
49
50
51 namespace lyx {
52
53 class Converters;
54 class Formats;
55 class Movers;
56
57 namespace frontend {
58
59 class PrefModule;
60
61 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
62 {
63         Q_OBJECT
64 public:
65         GuiPreferences(GuiView & lv);
66
67         void apply(LyXRC & rc) const;
68         void updateRc(LyXRC const & rc);
69
70 public Q_SLOTS:
71         void change_adaptor();
72
73 Q_SIGNALS:
74         void prefsApplied(LyXRC const & rc);
75
76 public:
77         /// Apply changes
78         void applyView();
79
80         std::vector<PrefModule *> modules_;
81
82         ///
83         bool initialiseParams(std::string const &);
84         ///
85         void clearParams() {}
86         ///
87         void dispatchParams();
88         ///
89         bool isBufferDependent() const { return false; }
90
91         /// various file pickers
92         QString browsebind(QString const & file) const;
93         QString browseUI(QString const & file) const;
94         QString browsekbmap(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         LyXRC & rc() { return rc_; }
106         Converters & converters() { return converters_; }
107         Formats & formats() { return formats_; }
108         Movers & movers() { return movers_; }
109
110 private:
111         ///
112         void addModule(PrefModule * module);
113
114         /// temporary lyxrc
115         LyXRC rc_;
116         /// temporary converters
117         Converters converters_;
118         /// temporary formats
119         Formats formats_;
120         /// temporary movers
121         Movers movers_;
122
123         /// A list of colors to be dispatched
124         std::vector<std::string> colors_;
125
126         bool update_screen_font_;
127 };
128
129
130 class PrefModule : public QWidget
131 {
132         Q_OBJECT
133 public:
134         PrefModule(QString const & cat, QString const & t,
135                         GuiPreferences * form)
136                 : QWidget(form), category_(cat), title_(t), form_(form)
137         {}
138
139         virtual void apply(LyXRC & rc) const = 0;
140         virtual void update(LyXRC const & rc) = 0;
141
142         QString const & category() const { return category_; }
143         QString const & title() const { return title_; }
144
145 protected:
146         QString category_;
147         QString title_;
148         GuiPreferences * form_;
149
150 Q_SIGNALS:
151         void changed();
152 };
153
154
155 class PrefOutput : public PrefModule, public Ui::PrefOutputUi
156 {
157         Q_OBJECT
158 public:
159         PrefOutput(GuiPreferences * form);
160
161         virtual void apply(LyXRC & rc) const;
162         virtual void update(LyXRC const & rc);
163
164 private Q_SLOTS:
165         void on_DateED_textChanged(const QString &);
166 };
167
168
169 class PrefInput : public PrefModule, public Ui::PrefInputUi
170 {
171         Q_OBJECT
172 public:
173         PrefInput(GuiPreferences * form);
174
175         virtual void apply(LyXRC & rc) const;
176         virtual void update(LyXRC const & rc);
177
178 private Q_SLOTS:
179         void on_firstKeymapPB_clicked(bool);
180         void on_secondKeymapPB_clicked(bool);
181         void on_keymapCB_toggled(bool);
182         void on_scrollzoomEnableCB_toggled(bool);
183
184 private:
185         QString testKeymap(QString const & keymap);
186 };
187
188
189 class PrefCompletion : public PrefModule, public Ui::PrefCompletionUi
190 {
191         Q_OBJECT
192 public:
193         PrefCompletion(GuiPreferences * form);
194
195         virtual void apply(LyXRC & rc) const;
196         virtual void update(LyXRC const & rc);
197         virtual void enableCB();
198 private Q_SLOTS:
199         void on_popupTextCB_clicked();
200         void on_inlineTextCB_clicked();
201 };
202
203
204 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
205 {
206         Q_OBJECT
207 public:
208         PrefLatex(GuiPreferences * form);
209
210         virtual void apply(LyXRC & rc) const;
211         virtual void update(LyXRC const & rc);
212
213 private Q_SLOTS:
214         void on_latexEncodingCB_stateChanged(int state);
215         void on_latexBibtexCO_activated(int n);
216         void on_latexIndexCO_activated(int n);
217
218 private:
219         ///
220         std::set<std::string> bibtex_alternatives;
221         ///
222         std::set<std::string> index_alternatives;
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 selectRoman(const QString&);
237         void selectSans(const QString&);
238         void selectTypewriter(const QString&);
239
240 public Q_SLOTS:
241         void updateScreenFontSizes(LyXRC const & rc);
242 };
243
244
245 class PrefColors : public PrefModule, public Ui::PrefColorsUi
246 {
247         Q_OBJECT
248 public:
249         PrefColors(GuiPreferences * form);
250
251         void apply(LyXRC & rc) const;
252         void update(LyXRC const & rc);
253
254 private Q_SLOTS:
255         void changeColor();
256         void changeSysColor();
257         void changeLyxObjectsSelection();
258
259 private:
260         std::vector<ColorCode> lcolors_;
261         std::vector<QString> curcolors_;
262         std::vector<QString> newcolors_;
263 };
264
265
266 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
267 {
268         Q_OBJECT
269 public:
270         PrefDisplay(GuiPreferences * form);
271
272         void apply(LyXRC & rc) const;
273         void update(LyXRC const & rc);
274
275 private Q_SLOTS:
276         void on_instantPreviewCO_currentIndexChanged(int);
277 };
278
279
280 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
281 {
282         Q_OBJECT
283 public:
284         PrefPaths(GuiPreferences * form);
285
286         void apply(LyXRC & rc) const;
287         void update(LyXRC const & rc);
288
289 private Q_SLOTS:
290         void selectExampledir();
291         void selectTemplatedir();
292         void selectTempdir();
293         void selectBackupdir();
294         void selectWorkingdir();
295         void selectThesaurusdir();
296         void selectHunspelldir();
297         void selectLyxPipe();
298
299 };
300
301
302 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
303 {
304         Q_OBJECT
305 public:
306         PrefSpellchecker(GuiPreferences * form);
307
308         void apply(LyXRC & rc) const;
309         void update(LyXRC const & rc);
310
311 private Q_SLOTS:
312         void on_spellcheckerCB_currentIndexChanged(int);
313 };
314
315
316 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
317 {
318         Q_OBJECT
319 public:
320         PrefConverters(GuiPreferences * form);
321
322         void apply(LyXRC & rc) const;
323         void update(LyXRC const & rc);
324
325 public Q_SLOTS:
326         void updateGui();
327
328 private Q_SLOTS:
329         void updateConverter();
330         void switchConverter();
331         void removeConverter();
332         void changeConverter();
333         void on_cacheCB_stateChanged(int state);
334
335 private:
336         void updateButtons();
337 };
338
339
340 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
341 {
342         Q_OBJECT
343 public:
344         PrefFileformats(GuiPreferences * form);
345
346         void apply(LyXRC & rc) const;
347         void update(LyXRC const & rc);
348         void updateView();
349
350 Q_SIGNALS:
351         void formatsChanged();
352
353 private Q_SLOTS:
354         void on_copierED_textEdited(const QString & s);
355         void on_extensionsED_textEdited(const QString &);
356         void on_viewerED_textEdited(const QString &);
357         void on_editorED_textEdited(const QString &);
358         void on_mimeED_textEdited(const QString &);
359         void on_shortcutED_textEdited(const QString &);
360         void on_formatED_editingFinished();
361         void on_formatED_textChanged(const QString &);
362         void on_formatsCB_currentIndexChanged(int);
363         void on_formatsCB_editTextChanged(const QString &);
364         void on_formatNewPB_clicked();
365         void on_formatRemovePB_clicked();
366         void on_viewerCO_currentIndexChanged(int i);
367         void on_editorCO_currentIndexChanged(int i);
368         void setFlags();
369         void updatePrettyname();
370
371 private:
372         Format & currentFormat();
373         ///
374         void updateViewers();
375         ///
376         void updateEditors();
377         ///
378         LyXRC::Alternatives viewer_alternatives;
379         ///
380         LyXRC::Alternatives editor_alternatives;
381 };
382
383
384 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
385 {
386         Q_OBJECT
387 public:
388         PrefLanguage(GuiPreferences * form);
389
390         void apply(LyXRC & rc) const;
391         void update(LyXRC const & rc);
392
393 private Q_SLOTS:
394         void on_uiLanguageCO_currentIndexChanged(int);
395         void on_languagePackageCO_currentIndexChanged(int);
396 };
397
398
399 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
400 {
401         Q_OBJECT
402 public:
403         PrefPrinter(GuiPreferences * form);
404
405         void apply(LyXRC & rc) const;
406         void update(LyXRC const & rc);
407 };
408
409
410 class PrefUserInterface : public PrefModule, public Ui::PrefUi
411 {
412         Q_OBJECT
413 public:
414         PrefUserInterface(GuiPreferences * form);
415
416         void apply(LyXRC & rc) const;
417         void update(LyXRC const & rc);
418
419 public Q_SLOTS:
420         void selectUi();
421 };
422
423
424 class PrefDocHandling : public PrefModule, public Ui::PrefDocHandlingUi
425 {
426         Q_OBJECT
427 public:
428         PrefDocHandling(GuiPreferences * form);
429
430         void apply(LyXRC & rc) const;
431         void update(LyXRC const & rc);
432
433 public Q_SLOTS:
434         void on_clearSessionPB_clicked();
435 };
436
437
438
439 class PrefEdit : public PrefModule, public Ui::PrefEditUi
440 {
441         Q_OBJECT
442 public:
443         PrefEdit(GuiPreferences * form);
444
445         void apply(LyXRC & rc) const;
446         void update(LyXRC const & rc);
447 };
448
449
450
451 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
452 {
453 public:
454         GuiShortcutDialog(QWidget * parent);
455 };
456
457
458 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
459 {
460         Q_OBJECT
461 public:
462         PrefShortcuts(GuiPreferences * form);
463
464         void apply(LyXRC & rc) const;
465         void update(LyXRC const & rc);
466         void updateShortcutsTW();
467         void modifyShortcut();
468         void removeShortcut();
469         ///
470         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
471         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
472                 KeySequence const & shortcut, KeyMap::ItemType tag);
473
474 public Q_SLOTS:
475         void selectBind();
476         void on_modifyPB_pressed();
477         void on_newPB_pressed();
478         void on_removePB_pressed();
479         void on_searchLE_textEdited();
480         ///
481         void on_shortcutsTW_itemSelectionChanged();
482         void on_shortcutsTW_itemDoubleClicked();
483         ///
484         void shortcutOkPressed();
485         void shortcutCancelPressed();
486         void shortcutClearPressed();
487         void shortcutRemovePressed();
488
489 private:
490         ///
491         GuiShortcutDialog * shortcut_;
492         ///
493         ButtonController shortcut_bc_;
494         /// category items
495         QTreeWidgetItem * editItem_;
496         QTreeWidgetItem * mathItem_;
497         QTreeWidgetItem * bufferItem_;
498         QTreeWidgetItem * layoutItem_;
499         QTreeWidgetItem * systemItem_;
500         // system_bind_ holds bindings from rc.bind_file
501         // user_bind_ holds \bind bindings from user.bind
502         // user_unbind_ holds \unbind bindings from user.bind
503         // When an item is inserted, it is added to user_bind_
504         // When an item from system_bind_ is deleted, it is added to user_unbind_
505         // When an item in user_bind_ or user_unbind_ is deleted, it is 
506         //      deleted (unbind)
507         KeyMap system_bind_;
508         KeyMap user_bind_;
509         KeyMap user_unbind_;
510         ///
511         QString save_lfun_;
512 };
513
514
515 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
516 {
517         Q_OBJECT
518 public:
519         PrefIdentity(GuiPreferences * form);
520
521         void apply(LyXRC & rc) const;
522         void update(LyXRC const & rc);
523 };
524
525
526 } // namespace frontend
527 } // namespace lyx
528
529 #endif // GUIPREFS_H