]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiPrefs.h
Regenerate previews after zoom (#11919)
[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
19 #include "ColorCode.h"
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 namespace frontend {
54
55 class GuiLyXFiles;
56 class PrefModule;
57
58 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
59 {
60         Q_OBJECT
61 public:
62         GuiPreferences(GuiView & lv);
63
64         void applyRC(LyXRC & rc) const;
65         void updateRC(LyXRC const & rc);
66
67 public Q_SLOTS:
68         void change_adaptor();
69         void slotFileSelected(QString);
70
71 Q_SIGNALS:
72         void prefsApplied(LyXRC const & rc);
73
74 public:
75         /// Apply changes
76         void applyView() override;
77
78         std::vector<PrefModule *> modules_;
79
80         ///
81         bool initialiseParams(std::string const &) override;
82         ///
83         void clearParams() override {}
84         ///
85         void dispatchParams() override;
86         ///
87         bool isBufferDependent() const override { return false; }
88
89         /// various file pickers
90         QString browsebind(QString const & file);
91         QString browseUI(QString const & file);
92         QString browsekbmap(QString const & file);
93
94         /// general browse
95         QString browse(QString const & file, QString const & title) const;
96
97         /// set a color
98         void setColor(ColorCode col, QString const & hex);
99
100         LyXRC & rc() { return rc_; }
101         Converters & converters() { return converters_; }
102         Formats & formats() { return formats_; }
103         Movers & movers() { return movers_; }
104
105 private:
106         ///
107         void addModule(PrefModule * module);
108         ///
109         QString browseLibFile(QString const & dir,
110                 QString const & name, QString const & ext);
111
112         /// temporary lyxrc
113         LyXRC rc_;
114         /// temporary converters
115         Converters converters_;
116         /// temporary formats
117         Formats formats_;
118         /// temporary movers
119         Movers movers_;
120
121         /// A list of colors to be dispatched
122         std::vector<std::string> colors_;
123         /// UI file selector
124         GuiLyXFiles * guilyxfiles_;
125         /// Selected UI file
126         QString uifile_;
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 applyRC(LyXRC & rc) const = 0;
140         virtual void updateRC(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         void applyRC(LyXRC & rc) const override;
162         void updateRC(LyXRC const & rc) override;
163 };
164
165
166 class PrefInput : public PrefModule, public Ui::PrefInputUi
167 {
168         Q_OBJECT
169 public:
170         PrefInput(GuiPreferences * form);
171
172         void applyRC(LyXRC & rc) const override;
173         void updateRC(LyXRC const & rc) override;
174
175 private Q_SLOTS:
176         void on_firstKeymapPB_clicked(bool);
177         void on_secondKeymapPB_clicked(bool);
178         void on_keymapCB_toggled(bool);
179         void on_scrollzoomEnableCB_toggled(bool);
180
181 private:
182         QString testKeymap(QString const & keymap);
183 };
184
185
186 class PrefCompletion : public PrefModule, public Ui::PrefCompletionUi
187 {
188         Q_OBJECT
189 public:
190         PrefCompletion(GuiPreferences * form);
191
192         void applyRC(LyXRC & rc) const override;
193         void updateRC(LyXRC const & rc) override;
194         virtual void enableCB();
195 private Q_SLOTS:
196         void on_popupTextCB_clicked();
197         void on_inlineTextCB_clicked();
198 };
199
200
201 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
202 {
203         Q_OBJECT
204 public:
205         PrefLatex(GuiPreferences * form);
206
207         void applyRC(LyXRC & rc) const override;
208         void updateRC(LyXRC const & rc) override;
209
210 private Q_SLOTS:
211         void on_latexBibtexCO_activated(int n);
212         void on_latexJBibtexCO_activated(int n);
213         void on_latexIndexCO_activated(int n);
214
215 private:
216         ///
217         std::set<std::string> bibtex_alternatives;
218         ///
219         std::set<std::string> jbibtex_alternatives;
220         ///
221         std::set<std::string> index_alternatives;
222 };
223
224
225 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
226 {
227         Q_OBJECT
228 public:
229         PrefScreenFonts(GuiPreferences * form);
230
231         void applyRC(LyXRC & rc) const override;
232         void updateRC(LyXRC const & rc) override;
233
234 private Q_SLOTS:
235         void selectRoman(const QString&);
236         void selectSans(const QString&);
237         void selectTypewriter(const QString&);
238
239 public Q_SLOTS:
240         void updateScreenFontSizes(LyXRC const & rc);
241 };
242
243
244 class PrefColors : public PrefModule, public Ui::PrefColorsUi
245 {
246         Q_OBJECT
247 public:
248         PrefColors(GuiPreferences * form);
249
250         void applyRC(LyXRC & rc) const override;
251         void updateRC(LyXRC const & rc) override;
252
253 private Q_SLOTS:
254         void changeColor();
255         void resetColor();
256         void resetAllColor();
257         void changeSysColor();
258         void changeLyxObjectsSelection();
259         bool setColor(int const row, QColor const & new_color,
260                       QString const & old_color);
261         bool isDefaultColor(int const row, QString const & color);
262         void setDisabledResets();
263
264 private:
265         ///
266         QColor getDefaultColorByRow(int const row);
267         ///
268         std::vector<ColorCode> lcolors_;
269         ///
270         std::vector<QString> curcolors_;
271         ///
272         std::vector<QString> newcolors_;
273 };
274
275
276 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
277 {
278         Q_OBJECT
279 public:
280         PrefDisplay(GuiPreferences * form);
281
282         void applyRC(LyXRC & rc) const override;
283         void updateRC(LyXRC const & rc) override;
284
285 private Q_SLOTS:
286         void on_instantPreviewCO_currentIndexChanged(int);
287 };
288
289
290 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
291 {
292         Q_OBJECT
293 public:
294         PrefPaths(GuiPreferences * form);
295
296         void applyRC(LyXRC & rc) const override;
297         void updateRC(LyXRC const & rc) override;
298
299 private Q_SLOTS:
300         void selectExampledir();
301         void selectTemplatedir();
302         void selectTempdir();
303         void selectBackupdir();
304         void selectWorkingdir();
305         void selectThesaurusdir();
306         void selectHunspelldir();
307         void selectLyxPipe();
308
309 };
310
311
312 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
313 {
314         Q_OBJECT
315 public:
316         PrefSpellchecker(GuiPreferences * form);
317
318         void applyRC(LyXRC & rc) const override;
319         void updateRC(LyXRC const & rc) override;
320
321 private Q_SLOTS:
322         void on_spellcheckerCB_currentIndexChanged(int);
323 };
324
325
326 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
327 {
328         Q_OBJECT
329 public:
330         PrefConverters(GuiPreferences * form);
331
332         void applyRC(LyXRC & rc) const override;
333         void updateRC(LyXRC const & rc) override;
334
335 public Q_SLOTS:
336         void updateGui();
337
338 private Q_SLOTS:
339         void updateConverter();
340         void switchConverter();
341         void removeConverter();
342         void changeConverter();
343         void on_cacheCB_stateChanged(int state);
344         void on_needauthForbiddenCB_toggled(bool);
345         void on_needauthCB_toggled(bool);
346
347 private:
348         void updateButtons();
349 };
350
351
352 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
353 {
354         Q_OBJECT
355 public:
356         PrefFileformats(GuiPreferences * form);
357
358         void applyRC(LyXRC & rc) const override;
359         void updateRC(LyXRC const & rc) override;
360         void updateView();
361
362 Q_SIGNALS:
363         void formatsChanged();
364
365 private Q_SLOTS:
366         void on_copierED_textEdited(const QString & s);
367         void on_extensionsED_textEdited(const QString &);
368         void on_viewerED_textEdited(const QString &);
369         void on_editorED_textEdited(const QString &);
370         void on_mimeED_textEdited(const QString &);
371         void on_shortcutED_textEdited(const QString &);
372         void on_formatED_editingFinished();
373         void on_formatED_textChanged(const QString &);
374         void on_formatsCB_currentIndexChanged(int);
375         void on_formatsCB_editTextChanged(const QString &);
376         void on_formatNewPB_clicked();
377         void on_formatRemovePB_clicked();
378         void on_viewerCO_currentIndexChanged(int i);
379         void on_editorCO_currentIndexChanged(int i);
380         void setFlags();
381         void updatePrettyname();
382
383 private:
384         Format & currentFormat();
385         ///
386         void updateViewers();
387         ///
388         void updateEditors();
389         ///
390         LyXRC::Alternatives viewer_alternatives;
391         ///
392         LyXRC::Alternatives editor_alternatives;
393 };
394
395
396 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
397 {
398         Q_OBJECT
399 public:
400         PrefLanguage(GuiPreferences * form);
401
402         void applyRC(LyXRC & rc) const override;
403         void updateRC(LyXRC const & rc) override;
404
405 private Q_SLOTS:
406         void on_uiLanguageCO_currentIndexChanged(int);
407         void on_languagePackageCO_currentIndexChanged(int);
408         void on_defaultDecimalSepCO_currentIndexChanged(int);
409 private:
410         ///
411         QString save_langpack_;
412 };
413
414
415 class PrefUserInterface : public PrefModule, public Ui::PrefUi
416 {
417         Q_OBJECT
418 public:
419         PrefUserInterface(GuiPreferences * form);
420
421         void applyRC(LyXRC & rc) const override;
422         void updateRC(LyXRC const & rc) override;
423
424 public Q_SLOTS:
425         void selectUi();
426 };
427
428
429 class PrefDocHandling : public PrefModule, public Ui::PrefDocHandlingUi
430 {
431         Q_OBJECT
432 public:
433         PrefDocHandling(GuiPreferences * form);
434
435         void applyRC(LyXRC & rc) const override;
436         void updateRC(LyXRC const & rc) override;
437
438 public Q_SLOTS:
439         void on_clearSessionPB_clicked();
440 };
441
442
443
444 class PrefEdit : public PrefModule, public Ui::PrefEditUi
445 {
446         Q_OBJECT
447 public:
448         PrefEdit(GuiPreferences * form);
449
450         void applyRC(LyXRC & rc) const override;
451         void updateRC(LyXRC const & rc) override;
452
453 public Q_SLOTS:
454         void on_screenLimitCB_toggled(bool);
455         void on_citationSearchCB_toggled(bool);
456 };
457
458
459
460 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
461 {
462 public:
463         GuiShortcutDialog(QWidget * parent);
464 };
465
466
467 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
468 {
469         Q_OBJECT
470 public:
471         PrefShortcuts(GuiPreferences * form);
472
473         void applyRC(LyXRC & rc) const override;
474         void updateRC(LyXRC const & rc) override;
475         void updateShortcutsTW();
476
477 public Q_SLOTS:
478         void selectBind();
479         void on_modifyPB_pressed();
480         void on_newPB_pressed();
481         void on_removePB_pressed();
482         void on_searchLE_textEdited();
483         ///
484         void on_shortcutsTW_itemSelectionChanged();
485         void on_shortcutsTW_itemDoubleClicked();
486         ///
487         void shortcutOkPressed();
488         void shortcutCancelPressed();
489         void shortcutClearPressed();
490         void shortcutRemovePressed();
491
492 private:
493         void modifyShortcut();
494         /// remove selected binding, restore default value
495         void removeShortcut();
496         /// remove bindings, do not restore default values
497         void deactivateShortcuts(QList<QTreeWidgetItem*> const & items);
498         /// check the new binding k->func, and remove existing bindings to k after
499         /// asking the user. We exclude lfun_to_modify from this test: we assume
500         /// that if the user clicked "modify" then they agreed to modify the
501         /// binding. Returns false if the shortcut is invalid or the user cancels.
502         bool validateNewShortcut(FuncRequest const & func,
503                                  KeySequence const & k,
504                                  QString const & lfun_to_modify);
505         /// compute current active shortcut
506         FuncRequest currentBinding(KeySequence const & k);
507         ///
508         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
509         ///
510         static KeyMap::ItemType itemType(QTreeWidgetItem & item);
511         /// some items need to be always hidden, for instance empty rebound
512         /// system keys
513         static bool isAlwaysHidden(QTreeWidgetItem & item);
514         /// unhide an empty system binding that may have been hidden
515         /// returns either null or the unhidden shortcut
516         void unhideEmpty(QString const & lfun, bool select);
517         ///
518         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun,
519                 KeySequence const & shortcut, KeyMap::ItemType tag);
520         ///
521         GuiShortcutDialog * shortcut_;
522         ///
523         ButtonController shortcut_bc_;
524         /// category items
525         QTreeWidgetItem * editItem_;
526         QTreeWidgetItem * mathItem_;
527         QTreeWidgetItem * bufferItem_;
528         QTreeWidgetItem * layoutItem_;
529         QTreeWidgetItem * systemItem_;
530         // system_bind_ holds bindings from rc.bind_file
531         // user_bind_ holds \bind bindings from user.bind
532         // user_unbind_ holds \unbind bindings from user.bind
533         // When an item is inserted, it is added to user_bind_
534         // When an item from system_bind_ is deleted, it is added to user_unbind_
535         // When an item in user_bind_ or user_unbind_ is deleted, it is
536         //      deleted (unbind)
537         KeyMap system_bind_;
538         KeyMap user_bind_;
539         KeyMap user_unbind_;
540         ///
541         QString save_lfun_;
542 };
543
544
545 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
546 {
547         Q_OBJECT
548 public:
549         PrefIdentity(GuiPreferences * form);
550
551         void applyRC(LyXRC & rc) const override;
552         void updateRC(LyXRC const & rc) override;
553 };
554
555
556 } // namespace frontend
557 } // namespace lyx
558
559 #endif // GUIPREFS_H