]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiPrefs.h
Localize the default decimal separator
[lyx.git] / src / frontends / qt / 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 #include "GuiLyXFiles.h"
19
20 #include "Converter.h"
21 #include "Format.h"
22 #include "KeyMap.h"
23 #include "LyXRC.h"
24 #include "Mover.h"
25
26 #include "ui_PrefsUi.h"
27
28 #include "ui_PrefOutputUi.h"
29 #include "ui_PrefInputUi.h"
30 #include "ui_PrefLatexUi.h"
31 #include "ui_PrefScreenFontsUi.h"
32 #include "ui_PrefCompletionUi.h"
33 #include "ui_PrefColorsUi.h"
34 #include "ui_PrefDisplayUi.h"
35 #include "ui_PrefDocHandlingUi.h"
36 #include "ui_PrefEditUi.h"
37 #include "ui_PrefPathsUi.h"
38 #include "ui_PrefShortcutsUi.h"
39 #include "ui_PrefSpellcheckerUi.h"
40 #include "ui_PrefConvertersUi.h"
41 #include "ui_PrefFileformatsUi.h"
42 #include "ui_PrefLanguageUi.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 applyRC(LyXRC & rc) const;
68         void updateRC(LyXRC const & rc);
69
70 public Q_SLOTS:
71         void change_adaptor();
72         void slotFileSelected(QString);
73
74 Q_SIGNALS:
75         void prefsApplied(LyXRC const & rc);
76
77 public:
78         /// Apply changes
79         void applyView();
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);
94         QString browseUI(QString const & file);
95         QString browsekbmap(QString const & file);
96
97         /// general browse
98         QString browse(QString const & file, QString const & title) const;
99
100         /// set a color
101         void setColor(ColorCode col, QString const & hex);
102
103         LyXRC & rc() { return rc_; }
104         Converters & converters() { return converters_; }
105         Formats & formats() { return formats_; }
106         Movers & movers() { return movers_; }
107
108 private:
109         ///
110         void addModule(PrefModule * module);
111         ///
112         QString browseLibFile(QString const & dir,
113                 QString const & name, QString const & ext);
114
115         /// temporary lyxrc
116         LyXRC rc_;
117         /// temporary converters
118         Converters converters_;
119         /// temporary formats
120         Formats formats_;
121         /// temporary movers
122         Movers movers_;
123
124         /// A list of colors to be dispatched
125         std::vector<std::string> colors_;
126         /// UI file selector
127         GuiLyXFiles * guilyxfiles_;
128         /// Selected UI file
129         QString uifile_;
130 };
131
132
133 class PrefModule : public QWidget
134 {
135         Q_OBJECT
136 public:
137         PrefModule(QString const & cat, QString const & t,
138                         GuiPreferences * form)
139                 : QWidget(form), category_(cat), title_(t), form_(form)
140         {}
141
142         virtual void applyRC(LyXRC & rc) const = 0;
143         virtual void updateRC(LyXRC const & rc) = 0;
144
145         QString const & category() const { return category_; }
146         QString const & title() const { return title_; }
147
148 protected:
149         QString category_;
150         QString title_;
151         GuiPreferences * form_;
152
153 Q_SIGNALS:
154         void changed();
155 };
156
157
158 class PrefOutput : public PrefModule, public Ui::PrefOutputUi
159 {
160         Q_OBJECT
161 public:
162         PrefOutput(GuiPreferences * form);
163
164         virtual void applyRC(LyXRC & rc) const;
165         virtual void updateRC(LyXRC const & rc);
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 applyRC(LyXRC & rc) const;
176         virtual void updateRC(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 applyRC(LyXRC & rc) const;
196         virtual void updateRC(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 applyRC(LyXRC & rc) const;
211         virtual void updateRC(LyXRC const & rc);
212
213 private Q_SLOTS:
214         void on_latexBibtexCO_activated(int n);
215         void on_latexJBibtexCO_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> jbibtex_alternatives;
223         ///
224         std::set<std::string> index_alternatives;
225 };
226
227
228 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
229 {
230         Q_OBJECT
231 public:
232         PrefScreenFonts(GuiPreferences * form);
233
234         virtual void applyRC(LyXRC & rc) const;
235         virtual void updateRC(LyXRC const & rc);
236
237 private Q_SLOTS:
238         void selectRoman(const QString&);
239         void selectSans(const QString&);
240         void selectTypewriter(const QString&);
241
242 public Q_SLOTS:
243         void updateScreenFontSizes(LyXRC const & rc);
244 };
245
246
247 class PrefColors : public PrefModule, public Ui::PrefColorsUi
248 {
249         Q_OBJECT
250 public:
251         PrefColors(GuiPreferences * form);
252
253         void applyRC(LyXRC & rc) const;
254         void updateRC(LyXRC const & rc);
255
256 private Q_SLOTS:
257         void changeColor();
258         void resetColor();
259         void resetAllColor();
260         void changeSysColor();
261         void changeLyxObjectsSelection();
262         bool setColor(int const row, QColor const new_color,
263                       QString const old_color);
264         bool isDefaultColor(int const row, QString const color);
265         void setDisabledResets();
266
267 private:
268         ///
269         QColor getDefaultColorByRow(int const row);
270         ///
271         std::vector<ColorCode> lcolors_;
272         ///
273         std::vector<QString> curcolors_;
274         ///
275         std::vector<QString> newcolors_;
276 };
277
278
279 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
280 {
281         Q_OBJECT
282 public:
283         PrefDisplay(GuiPreferences * form);
284
285         void applyRC(LyXRC & rc) const;
286         void updateRC(LyXRC const & rc);
287
288 private Q_SLOTS:
289         void on_instantPreviewCO_currentIndexChanged(int);
290 };
291
292
293 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
294 {
295         Q_OBJECT
296 public:
297         PrefPaths(GuiPreferences * form);
298
299         void applyRC(LyXRC & rc) const;
300         void updateRC(LyXRC const & rc);
301
302 private Q_SLOTS:
303         void selectExampledir();
304         void selectTemplatedir();
305         void selectTempdir();
306         void selectBackupdir();
307         void selectWorkingdir();
308         void selectThesaurusdir();
309         void selectHunspelldir();
310         void selectLyxPipe();
311
312 };
313
314
315 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
316 {
317         Q_OBJECT
318 public:
319         PrefSpellchecker(GuiPreferences * form);
320
321         void applyRC(LyXRC & rc) const;
322         void updateRC(LyXRC const & rc);
323
324 private Q_SLOTS:
325         void on_spellcheckerCB_currentIndexChanged(int);
326 };
327
328
329 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
330 {
331         Q_OBJECT
332 public:
333         PrefConverters(GuiPreferences * form);
334
335         void applyRC(LyXRC & rc) const;
336         void updateRC(LyXRC const & rc);
337
338 public Q_SLOTS:
339         void updateGui();
340
341 private Q_SLOTS:
342         void updateConverter();
343         void switchConverter();
344         void removeConverter();
345         void changeConverter();
346         void on_cacheCB_stateChanged(int state);
347         void on_needauthForbiddenCB_toggled(bool);
348         void on_needauthCB_toggled(bool);
349
350 private:
351         void updateButtons();
352 };
353
354
355 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
356 {
357         Q_OBJECT
358 public:
359         PrefFileformats(GuiPreferences * form);
360
361         void applyRC(LyXRC & rc) const;
362         void updateRC(LyXRC const & rc);
363         void updateView();
364
365 Q_SIGNALS:
366         void formatsChanged();
367
368 private Q_SLOTS:
369         void on_copierED_textEdited(const QString & s);
370         void on_extensionsED_textEdited(const QString &);
371         void on_viewerED_textEdited(const QString &);
372         void on_editorED_textEdited(const QString &);
373         void on_mimeED_textEdited(const QString &);
374         void on_shortcutED_textEdited(const QString &);
375         void on_formatED_editingFinished();
376         void on_formatED_textChanged(const QString &);
377         void on_formatsCB_currentIndexChanged(int);
378         void on_formatsCB_editTextChanged(const QString &);
379         void on_formatNewPB_clicked();
380         void on_formatRemovePB_clicked();
381         void on_viewerCO_currentIndexChanged(int i);
382         void on_editorCO_currentIndexChanged(int i);
383         void setFlags();
384         void updatePrettyname();
385
386 private:
387         Format & currentFormat();
388         ///
389         void updateViewers();
390         ///
391         void updateEditors();
392         ///
393         LyXRC::Alternatives viewer_alternatives;
394         ///
395         LyXRC::Alternatives editor_alternatives;
396 };
397
398
399 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
400 {
401         Q_OBJECT
402 public:
403         PrefLanguage(GuiPreferences * form);
404
405         void applyRC(LyXRC & rc) const;
406         void updateRC(LyXRC const & rc);
407
408 private Q_SLOTS:
409         void on_uiLanguageCO_currentIndexChanged(int);
410         void on_languagePackageCO_currentIndexChanged(int);
411         void on_defaultDecimalSepCO_currentIndexChanged(int);
412 private:
413         ///
414         QString save_langpack_;
415 };
416
417
418 class PrefUserInterface : public PrefModule, public Ui::PrefUi
419 {
420         Q_OBJECT
421 public:
422         PrefUserInterface(GuiPreferences * form);
423
424         void applyRC(LyXRC & rc) const;
425         void updateRC(LyXRC const & rc);
426
427 public Q_SLOTS:
428         void selectUi();
429 };
430
431
432 class PrefDocHandling : public PrefModule, public Ui::PrefDocHandlingUi
433 {
434         Q_OBJECT
435 public:
436         PrefDocHandling(GuiPreferences * form);
437
438         void applyRC(LyXRC & rc) const;
439         void updateRC(LyXRC const & rc);
440
441 public Q_SLOTS:
442         void on_clearSessionPB_clicked();
443 };
444
445
446
447 class PrefEdit : public PrefModule, public Ui::PrefEditUi
448 {
449         Q_OBJECT
450 public:
451         PrefEdit(GuiPreferences * form);
452
453         void applyRC(LyXRC & rc) const;
454         void updateRC(LyXRC const & rc);
455 };
456
457
458
459 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
460 {
461 public:
462         GuiShortcutDialog(QWidget * parent);
463 };
464
465
466 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
467 {
468         Q_OBJECT
469 public:
470         PrefShortcuts(GuiPreferences * form);
471
472         void applyRC(LyXRC & rc) const;
473         void updateRC(LyXRC const & rc);
474         void updateShortcutsTW();
475
476 public Q_SLOTS:
477         void selectBind();
478         void on_modifyPB_pressed();
479         void on_newPB_pressed();
480         void on_removePB_pressed();
481         void on_searchLE_textEdited();
482         ///
483         void on_shortcutsTW_itemSelectionChanged();
484         void on_shortcutsTW_itemDoubleClicked();
485         ///
486         void shortcutOkPressed();
487         void shortcutCancelPressed();
488         void shortcutClearPressed();
489         void shortcutRemovePressed();
490
491 private:
492         void modifyShortcut();
493         /// remove selected binding, restore default value
494         void removeShortcut();
495         /// remove bindings, do not restore default values
496         void deactivateShortcuts(QList<QTreeWidgetItem*> const & items);
497         /// check the new binding k->func, and remove existing bindings to k after
498         /// asking the user. We exclude lfun_to_modify from this test: we assume
499         /// that if the user clicked "modify" then they agreed to modify the
500         /// binding. Returns false if the shortcut is invalid or the user cancels.
501         bool validateNewShortcut(FuncRequest const & func,
502                                  KeySequence const & k,
503                                  QString const & lfun_to_modify);
504         /// compute current active shortcut
505         FuncRequest currentBinding(KeySequence const & k);
506         ///
507         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
508         ///
509         static KeyMap::ItemType itemType(QTreeWidgetItem & item);
510         /// some items need to be always hidden, for instance empty rebound
511         /// system keys
512         static bool isAlwaysHidden(QTreeWidgetItem & item);
513         /// unhide an empty system binding that may have been hidden
514         /// returns either null or the unhidden shortcut
515         void unhideEmpty(QString const & lfun, bool select);
516         ///
517         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun,
518                 KeySequence const & shortcut, KeyMap::ItemType tag);
519         ///
520         GuiShortcutDialog * shortcut_;
521         ///
522         ButtonController shortcut_bc_;
523         /// category items
524         QTreeWidgetItem * editItem_;
525         QTreeWidgetItem * mathItem_;
526         QTreeWidgetItem * bufferItem_;
527         QTreeWidgetItem * layoutItem_;
528         QTreeWidgetItem * systemItem_;
529         // system_bind_ holds bindings from rc.bind_file
530         // user_bind_ holds \bind bindings from user.bind
531         // user_unbind_ holds \unbind bindings from user.bind
532         // When an item is inserted, it is added to user_bind_
533         // When an item from system_bind_ is deleted, it is added to user_unbind_
534         // When an item in user_bind_ or user_unbind_ is deleted, it is
535         //      deleted (unbind)
536         KeyMap system_bind_;
537         KeyMap user_bind_;
538         KeyMap user_unbind_;
539         ///
540         QString save_lfun_;
541 };
542
543
544 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
545 {
546         Q_OBJECT
547 public:
548         PrefIdentity(GuiPreferences * form);
549
550         void applyRC(LyXRC & rc) const;
551         void updateRC(LyXRC const & rc);
552 };
553
554
555 } // namespace frontend
556 } // namespace lyx
557
558 #endif // GUIPREFS_H