]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiPrefs.h
Constify
[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
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_PrefUi.h"
43 #include "ui_PrefIdentityUi.h"
44 #include "ui_ShortcutUi.h"
45
46 #include <string>
47 #include <vector>
48
49
50 namespace lyx {
51
52 namespace frontend {
53
54 class GuiLyXFiles;
55 class PrefModule;
56
57 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
58 {
59         Q_OBJECT
60 public:
61         GuiPreferences(GuiView & lv);
62
63         void applyRC(LyXRC & rc) const;
64         void updateRC(LyXRC const & rc);
65
66 public Q_SLOTS:
67         void change_adaptor();
68         void slotFileSelected(QString);
69
70 Q_SIGNALS:
71         void prefsApplied(LyXRC const & rc);
72
73 public:
74         /// Apply changes
75         void applyView() override;
76
77         std::vector<PrefModule *> modules_;
78
79         ///
80         bool initialiseParams(std::string const &) override;
81         ///
82         void clearParams() override {}
83         ///
84         void dispatchParams() override;
85         ///
86         bool isBufferDependent() const override { return false; }
87
88         /// various file pickers
89         QString browsebind(QString const & file);
90         QString browseUI(QString const & file);
91         QString browsekbmap(QString const & file);
92
93         /// general browse
94         QString browse(QString const & file, QString const & title) const;
95
96         /// set a color
97         void setColor(ColorCode col, QString const & hex);
98
99         LyXRC & rc() { return rc_; }
100         Converters & converters() { return converters_; }
101         Formats & formats() { return formats_; }
102         Movers & movers() { return movers_; }
103
104 private:
105         ///
106         void addModule(PrefModule * module);
107         ///
108         QString browseLibFile(QString const & dir,
109                 QString const & name, QString const & ext);
110
111         /// temporary lyxrc
112         LyXRC rc_;
113         /// temporary converters
114         Converters converters_;
115         /// temporary formats
116         Formats formats_;
117         /// temporary movers
118         Movers movers_;
119
120         /// A list of colors to be dispatched
121         std::vector<std::string> colors_;
122         /// UI file selector
123         GuiLyXFiles * guilyxfiles_;
124         /// Selected UI file
125         QString uifile_;
126 };
127
128
129 class PrefModule : public QWidget
130 {
131         Q_OBJECT
132 public:
133         PrefModule(QString const & cat, QString const & t,
134                         GuiPreferences * form)
135                 : QWidget(form), category_(cat), title_(t), form_(form)
136         {}
137
138         virtual void applyRC(LyXRC & rc) const = 0;
139         virtual void updateRC(LyXRC const & rc) = 0;
140
141         QString const & category() const { return category_; }
142         QString const & title() const { return title_; }
143
144 protected:
145         QString category_;
146         QString title_;
147         GuiPreferences * form_;
148
149 Q_SIGNALS:
150         void changed();
151 };
152
153
154 class PrefOutput : public PrefModule, public Ui::PrefOutputUi
155 {
156         Q_OBJECT
157 public:
158         PrefOutput(GuiPreferences * form);
159
160         void applyRC(LyXRC & rc) const override;
161         void updateRC(LyXRC const & rc) override;
162 };
163
164
165 class PrefInput : public PrefModule, public Ui::PrefInputUi
166 {
167         Q_OBJECT
168 public:
169         PrefInput(GuiPreferences * form);
170
171         void applyRC(LyXRC & rc) const override;
172         void updateRC(LyXRC const & rc) override;
173
174 private Q_SLOTS:
175         void on_firstKeymapPB_clicked(bool);
176         void on_secondKeymapPB_clicked(bool);
177         void on_keymapCB_toggled(bool);
178         void on_scrollzoomEnableCB_toggled(bool);
179
180 private:
181         QString testKeymap(QString const & keymap);
182 };
183
184
185 class PrefCompletion : public PrefModule, public Ui::PrefCompletionUi
186 {
187         Q_OBJECT
188 public:
189         PrefCompletion(GuiPreferences * form);
190
191         void applyRC(LyXRC & rc) const override;
192         void updateRC(LyXRC const & rc) override;
193         virtual void enableCB();
194 private Q_SLOTS:
195         void on_popupTextCB_clicked();
196         void on_inlineTextCB_clicked();
197 };
198
199
200 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
201 {
202         Q_OBJECT
203 public:
204         PrefLatex(GuiPreferences * form);
205
206         void applyRC(LyXRC & rc) const override;
207         void updateRC(LyXRC const & rc) override;
208
209 private Q_SLOTS:
210         void on_latexBibtexCO_activated(int n);
211         void on_latexJBibtexCO_activated(int n);
212         void on_latexIndexCO_activated(int n);
213
214 private:
215         ///
216         std::set<std::string> bibtex_alternatives;
217         ///
218         std::set<std::string> jbibtex_alternatives;
219         ///
220         std::set<std::string> index_alternatives;
221 };
222
223
224 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
225 {
226         Q_OBJECT
227 public:
228         PrefScreenFonts(GuiPreferences * form);
229
230         void applyRC(LyXRC & rc) const override;
231         void updateRC(LyXRC const & rc) override;
232
233 private Q_SLOTS:
234         void selectRoman(const QString&);
235         void selectSans(const QString&);
236         void selectTypewriter(const QString&);
237
238 public Q_SLOTS:
239         void updateScreenFontSizes(LyXRC const & rc);
240 };
241
242
243 class PrefColors : public PrefModule, public Ui::PrefColorsUi
244 {
245         Q_OBJECT
246 public:
247         PrefColors(GuiPreferences * form);
248
249         void applyRC(LyXRC & rc) const override;
250         void updateRC(LyXRC const & rc) override;
251
252 private Q_SLOTS:
253         void changeColor();
254         void resetColor();
255         void resetAllColor();
256         void changeSysColor();
257         void changeLyxObjectsSelection();
258         bool setColor(int const row, QColor const new_color,
259                       QString const old_color);
260         bool isDefaultColor(int const row, QString const color);
261         void setDisabledResets();
262
263 private:
264         ///
265         QColor getDefaultColorByRow(int const row);
266         ///
267         std::vector<ColorCode> lcolors_;
268         ///
269         std::vector<QString> curcolors_;
270         ///
271         std::vector<QString> newcolors_;
272 };
273
274
275 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
276 {
277         Q_OBJECT
278 public:
279         PrefDisplay(GuiPreferences * form);
280
281         void applyRC(LyXRC & rc) const override;
282         void updateRC(LyXRC const & rc) override;
283
284 private Q_SLOTS:
285         void on_instantPreviewCO_currentIndexChanged(int);
286 };
287
288
289 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
290 {
291         Q_OBJECT
292 public:
293         PrefPaths(GuiPreferences * form);
294
295         void applyRC(LyXRC & rc) const override;
296         void updateRC(LyXRC const & rc) override;
297
298 private Q_SLOTS:
299         void selectExampledir();
300         void selectTemplatedir();
301         void selectTempdir();
302         void selectBackupdir();
303         void selectWorkingdir();
304         void selectThesaurusdir();
305         void selectHunspelldir();
306         void selectLyxPipe();
307
308 };
309
310
311 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
312 {
313         Q_OBJECT
314 public:
315         PrefSpellchecker(GuiPreferences * form);
316
317         void applyRC(LyXRC & rc) const override;
318         void updateRC(LyXRC const & rc) override;
319
320 private Q_SLOTS:
321         void on_spellcheckerCB_currentIndexChanged(int);
322 };
323
324
325 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
326 {
327         Q_OBJECT
328 public:
329         PrefConverters(GuiPreferences * form);
330
331         void applyRC(LyXRC & rc) const override;
332         void updateRC(LyXRC const & rc) override;
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         void on_needauthForbiddenCB_toggled(bool);
344         void on_needauthCB_toggled(bool);
345
346 private:
347         void updateButtons();
348 };
349
350
351 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
352 {
353         Q_OBJECT
354 public:
355         PrefFileformats(GuiPreferences * form);
356
357         void applyRC(LyXRC & rc) const override;
358         void updateRC(LyXRC const & rc) override;
359         void updateView();
360
361 Q_SIGNALS:
362         void formatsChanged();
363
364 private Q_SLOTS:
365         void on_copierED_textEdited(const QString & s);
366         void on_extensionsED_textEdited(const QString &);
367         void on_viewerED_textEdited(const QString &);
368         void on_editorED_textEdited(const QString &);
369         void on_mimeED_textEdited(const QString &);
370         void on_shortcutED_textEdited(const QString &);
371         void on_formatED_editingFinished();
372         void on_formatED_textChanged(const QString &);
373         void on_formatsCB_currentIndexChanged(int);
374         void on_formatsCB_editTextChanged(const QString &);
375         void on_formatNewPB_clicked();
376         void on_formatRemovePB_clicked();
377         void on_viewerCO_currentIndexChanged(int i);
378         void on_editorCO_currentIndexChanged(int i);
379         void setFlags();
380         void updatePrettyname();
381
382 private:
383         Format & currentFormat();
384         ///
385         void updateViewers();
386         ///
387         void updateEditors();
388         ///
389         LyXRC::Alternatives viewer_alternatives;
390         ///
391         LyXRC::Alternatives editor_alternatives;
392 };
393
394
395 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
396 {
397         Q_OBJECT
398 public:
399         PrefLanguage(GuiPreferences * form);
400
401         void applyRC(LyXRC & rc) const override;
402         void updateRC(LyXRC const & rc) override;
403
404 private Q_SLOTS:
405         void on_uiLanguageCO_currentIndexChanged(int);
406         void on_languagePackageCO_currentIndexChanged(int);
407         void on_defaultDecimalSepCO_currentIndexChanged(int);
408 private:
409         ///
410         QString save_langpack_;
411 };
412
413
414 class PrefUserInterface : public PrefModule, public Ui::PrefUi
415 {
416         Q_OBJECT
417 public:
418         PrefUserInterface(GuiPreferences * form);
419
420         void applyRC(LyXRC & rc) const override;
421         void updateRC(LyXRC const & rc) override;
422
423 public Q_SLOTS:
424         void selectUi();
425 };
426
427
428 class PrefDocHandling : public PrefModule, public Ui::PrefDocHandlingUi
429 {
430         Q_OBJECT
431 public:
432         PrefDocHandling(GuiPreferences * form);
433
434         void applyRC(LyXRC & rc) const override;
435         void updateRC(LyXRC const & rc) override;
436
437 public Q_SLOTS:
438         void on_clearSessionPB_clicked();
439 };
440
441
442
443 class PrefEdit : public PrefModule, public Ui::PrefEditUi
444 {
445         Q_OBJECT
446 public:
447         PrefEdit(GuiPreferences * form);
448
449         void applyRC(LyXRC & rc) const override;
450         void updateRC(LyXRC const & rc) override;
451
452 public Q_SLOTS:
453         void on_fullscreenLimitCB_toggled(bool);
454         void on_citationSearchCB_toggled(bool);
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 override;
473         void updateRC(LyXRC const & rc) override;
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 override;
551         void updateRC(LyXRC const & rc) override;
552 };
553
554
555 } // namespace frontend
556 } // namespace lyx
557
558 #endif // GUIPREFS_H