]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiPrefs.h
cb810c57f7f90519fe9c183fd5c5c6d25a36b062
[features.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() override;
80
81         std::vector<PrefModule *> modules_;
82
83         ///
84         bool initialiseParams(std::string const &) override;
85         ///
86         void clearParams() override {}
87         ///
88         void dispatchParams() override;
89         ///
90         bool isBufferDependent() const override { 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         void applyRC(LyXRC & rc) const override;
165         void updateRC(LyXRC const & rc) override;
166 };
167
168
169 class PrefInput : public PrefModule, public Ui::PrefInputUi
170 {
171         Q_OBJECT
172 public:
173         PrefInput(GuiPreferences * form);
174
175         void applyRC(LyXRC & rc) const override;
176         void updateRC(LyXRC const & rc) override;
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         void applyRC(LyXRC & rc) const override;
196         void updateRC(LyXRC const & rc) override;
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         void applyRC(LyXRC & rc) const override;
211         void updateRC(LyXRC const & rc) override;
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         void applyRC(LyXRC & rc) const override;
235         void updateRC(LyXRC const & rc) override;
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 override;
254         void updateRC(LyXRC const & rc) override;
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 override;
286         void updateRC(LyXRC const & rc) override;
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 override;
300         void updateRC(LyXRC const & rc) override;
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 override;
322         void updateRC(LyXRC const & rc) override;
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 override;
336         void updateRC(LyXRC const & rc) override;
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 override;
362         void updateRC(LyXRC const & rc) override;
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 override;
406         void updateRC(LyXRC const & rc) override;
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 override;
425         void updateRC(LyXRC const & rc) override;
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 override;
439         void updateRC(LyXRC const & rc) override;
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 override;
454         void updateRC(LyXRC const & rc) override;
455
456 public Q_SLOTS:
457         void on_fullscreenLimitCB_toggled(bool);
458         void on_citationSearchCB_toggled(bool);
459 };
460
461
462
463 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
464 {
465 public:
466         GuiShortcutDialog(QWidget * parent);
467 };
468
469
470 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
471 {
472         Q_OBJECT
473 public:
474         PrefShortcuts(GuiPreferences * form);
475
476         void applyRC(LyXRC & rc) const override;
477         void updateRC(LyXRC const & rc) override;
478         void updateShortcutsTW();
479
480 public Q_SLOTS:
481         void selectBind();
482         void on_modifyPB_pressed();
483         void on_newPB_pressed();
484         void on_removePB_pressed();
485         void on_searchLE_textEdited();
486         ///
487         void on_shortcutsTW_itemSelectionChanged();
488         void on_shortcutsTW_itemDoubleClicked();
489         ///
490         void shortcutOkPressed();
491         void shortcutCancelPressed();
492         void shortcutClearPressed();
493         void shortcutRemovePressed();
494
495 private:
496         void modifyShortcut();
497         /// remove selected binding, restore default value
498         void removeShortcut();
499         /// remove bindings, do not restore default values
500         void deactivateShortcuts(QList<QTreeWidgetItem*> const & items);
501         /// check the new binding k->func, and remove existing bindings to k after
502         /// asking the user. We exclude lfun_to_modify from this test: we assume
503         /// that if the user clicked "modify" then they agreed to modify the
504         /// binding. Returns false if the shortcut is invalid or the user cancels.
505         bool validateNewShortcut(FuncRequest const & func,
506                                  KeySequence const & k,
507                                  QString const & lfun_to_modify);
508         /// compute current active shortcut
509         FuncRequest currentBinding(KeySequence const & k);
510         ///
511         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
512         ///
513         static KeyMap::ItemType itemType(QTreeWidgetItem & item);
514         /// some items need to be always hidden, for instance empty rebound
515         /// system keys
516         static bool isAlwaysHidden(QTreeWidgetItem & item);
517         /// unhide an empty system binding that may have been hidden
518         /// returns either null or the unhidden shortcut
519         void unhideEmpty(QString const & lfun, bool select);
520         ///
521         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun,
522                 KeySequence const & shortcut, KeyMap::ItemType tag);
523         ///
524         GuiShortcutDialog * shortcut_;
525         ///
526         ButtonController shortcut_bc_;
527         /// category items
528         QTreeWidgetItem * editItem_;
529         QTreeWidgetItem * mathItem_;
530         QTreeWidgetItem * bufferItem_;
531         QTreeWidgetItem * layoutItem_;
532         QTreeWidgetItem * systemItem_;
533         // system_bind_ holds bindings from rc.bind_file
534         // user_bind_ holds \bind bindings from user.bind
535         // user_unbind_ holds \unbind bindings from user.bind
536         // When an item is inserted, it is added to user_bind_
537         // When an item from system_bind_ is deleted, it is added to user_unbind_
538         // When an item in user_bind_ or user_unbind_ is deleted, it is
539         //      deleted (unbind)
540         KeyMap system_bind_;
541         KeyMap user_bind_;
542         KeyMap user_unbind_;
543         ///
544         QString save_lfun_;
545 };
546
547
548 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
549 {
550         Q_OBJECT
551 public:
552         PrefIdentity(GuiPreferences * form);
553
554         void applyRC(LyXRC & rc) const override;
555         void updateRC(LyXRC const & rc) override;
556 };
557
558
559 } // namespace frontend
560 } // namespace lyx
561
562 #endif // GUIPREFS_H