]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiPrefs.h
Remove profiling.py
[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 "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);
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         void screenFontsChanged();
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 applyRC(LyXRC & rc) const override;
252         void updateRC(LyXRC const & rc) override;
253
254 private Q_SLOTS:
255         void changeColor();
256         void resetColor();
257         void resetAllColor();
258         void changeSysColor();
259         void changeLyxObjectsSelection();
260         bool setColor(int const row, QColor const & new_color,
261                       QString const & old_color);
262         bool isDefaultColor(int const row, QString const & color);
263         void setDisabledResets();
264
265 private:
266         ///
267         QColor getDefaultColorByRow(int const row);
268         ///
269         std::vector<ColorCode> lcolors_;
270         ///
271         std::vector<QString> curcolors_;
272         ///
273         std::vector<QString> newcolors_;
274 };
275
276
277 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
278 {
279         Q_OBJECT
280 public:
281         PrefDisplay(GuiPreferences * form);
282
283         void applyRC(LyXRC & rc) const override;
284         void updateRC(LyXRC const & rc) override;
285
286 private Q_SLOTS:
287         void on_instantPreviewCO_currentIndexChanged(int);
288 };
289
290
291 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
292 {
293         Q_OBJECT
294 public:
295         PrefPaths(GuiPreferences * form);
296
297         void applyRC(LyXRC & rc) const override;
298         void updateRC(LyXRC const & rc) override;
299
300 private Q_SLOTS:
301         void selectExampledir();
302         void selectTemplatedir();
303         void selectTempdir();
304         void selectBackupdir();
305         void selectWorkingdir();
306         void selectThesaurusdir();
307         void selectHunspelldir();
308         void selectLyxPipe();
309
310 };
311
312
313 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
314 {
315         Q_OBJECT
316 public:
317         PrefSpellchecker(GuiPreferences * form);
318
319         void applyRC(LyXRC & rc) const override;
320         void updateRC(LyXRC const & rc) override;
321
322 private Q_SLOTS:
323         void on_spellcheckerCB_currentIndexChanged(int);
324 };
325
326
327 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
328 {
329         Q_OBJECT
330 public:
331         PrefConverters(GuiPreferences * form);
332
333         void applyRC(LyXRC & rc) const override;
334         void updateRC(LyXRC const & rc) override;
335
336 public Q_SLOTS:
337         void updateGui();
338
339 private Q_SLOTS:
340         void updateConverter();
341         void switchConverter();
342         void removeConverter();
343         void changeConverter();
344         void on_cacheCB_stateChanged(int state);
345         void on_needauthForbiddenCB_toggled(bool);
346         void on_needauthCB_toggled(bool);
347
348 private:
349         void updateButtons();
350 };
351
352
353 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
354 {
355         Q_OBJECT
356 public:
357         PrefFileformats(GuiPreferences * form);
358
359         void applyRC(LyXRC & rc) const override;
360         void updateRC(LyXRC const & rc) override;
361         void updateView();
362
363 Q_SIGNALS:
364         void formatsChanged();
365
366 private Q_SLOTS:
367         void on_copierED_textEdited(const QString & s);
368         void on_extensionsED_textEdited(const QString &);
369         void on_viewerED_textEdited(const QString &);
370         void on_editorED_textEdited(const QString &);
371         void on_mimeED_textEdited(const QString &);
372         void on_shortcutED_textEdited(const QString &);
373         void on_formatED_editingFinished();
374         void on_formatED_textChanged(const QString &);
375         void on_formatsCB_currentIndexChanged(int);
376         void on_formatsCB_editTextChanged(const QString &);
377         void on_formatNewPB_clicked();
378         void on_formatRemovePB_clicked();
379         void on_viewerCO_currentIndexChanged(int i);
380         void on_editorCO_currentIndexChanged(int i);
381         void setFlags();
382         void updatePrettyname();
383
384 private:
385         Format & currentFormat();
386         ///
387         void updateViewers();
388         ///
389         void updateEditors();
390         ///
391         LyXRC::Alternatives viewer_alternatives;
392         ///
393         LyXRC::Alternatives editor_alternatives;
394 };
395
396
397 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
398 {
399         Q_OBJECT
400 public:
401         PrefLanguage(GuiPreferences * form);
402
403         void applyRC(LyXRC & rc) const override;
404         void updateRC(LyXRC const & rc) override;
405
406 private Q_SLOTS:
407         void on_uiLanguageCO_currentIndexChanged(int);
408         void on_languagePackageCO_currentIndexChanged(int);
409         void on_defaultDecimalSepCO_currentIndexChanged(int);
410 private:
411         ///
412         QString save_langpack_;
413 };
414
415
416 class PrefUserInterface : public PrefModule, public Ui::PrefUi
417 {
418         Q_OBJECT
419 public:
420         PrefUserInterface(GuiPreferences * form);
421
422         void applyRC(LyXRC & rc) const override;
423         void updateRC(LyXRC const & rc) override;
424
425 public Q_SLOTS:
426         void selectUi();
427 };
428
429
430 class PrefDocHandling : public PrefModule, public Ui::PrefDocHandlingUi
431 {
432         Q_OBJECT
433 public:
434         PrefDocHandling(GuiPreferences * form);
435
436         void applyRC(LyXRC & rc) const override;
437         void updateRC(LyXRC const & rc) override;
438
439 public Q_SLOTS:
440         void on_clearSessionPB_clicked();
441 };
442
443
444
445 class PrefEdit : public PrefModule, public Ui::PrefEditUi
446 {
447         Q_OBJECT
448 public:
449         PrefEdit(GuiPreferences * form);
450
451         void applyRC(LyXRC & rc) const override;
452         void updateRC(LyXRC const & rc) override;
453
454 public Q_SLOTS:
455         void on_screenLimitCB_toggled(bool);
456         void on_citationSearchCB_toggled(bool);
457 };
458
459
460
461 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
462 {
463         Q_OBJECT
464 public:
465         GuiShortcutDialog(QWidget * parent);
466
467 public Q_SLOTS:
468         void on_lfunLE_textChanged();
469
470 };
471
472
473 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
474 {
475         Q_OBJECT
476 public:
477         PrefShortcuts(GuiPreferences * form);
478
479         void applyRC(LyXRC & rc) const override;
480         void updateRC(LyXRC const & rc) override;
481         void updateShortcutsTW();
482
483 public Q_SLOTS:
484         void selectBind();
485         void on_modifyPB_pressed();
486         void on_newPB_pressed();
487         void on_removePB_pressed();
488         void on_searchLE_textEdited();
489         ///
490         void on_shortcutsTW_itemSelectionChanged();
491         void on_shortcutsTW_itemDoubleClicked();
492         ///
493         void shortcutOkPressed();
494         void shortcutCancelPressed();
495         void shortcutClearPressed();
496         void shortcutRemovePressed();
497
498 private:
499         void modifyShortcut();
500         /// remove selected binding, restore default value
501         void removeShortcut();
502         /// remove bindings, do not restore default values
503         void deactivateShortcuts(QList<QTreeWidgetItem*> const & items);
504         /// check the new binding k->func, and remove existing bindings to k after
505         /// asking the user. We exclude lfun_to_modify from this test: we assume
506         /// that if the user clicked "modify" then they agreed to modify the
507         /// binding. Returns false if the shortcut is invalid or the user cancels.
508         bool validateNewShortcut(FuncRequest const & func,
509                                  KeySequence const & k,
510                                  QString const & lfun_to_modify);
511         /// compute current active shortcut
512         FuncRequest currentBinding(KeySequence const & k);
513         ///
514         void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
515         ///
516         static KeyMap::ItemType itemType(QTreeWidgetItem & item);
517         /// some items need to be always hidden, for instance empty rebound
518         /// system keys
519         static bool isAlwaysHidden(QTreeWidgetItem & item);
520         /// unhide an empty system binding that may have been hidden
521         /// returns either null or the unhidden shortcut
522         void unhideEmpty(QString const & lfun, bool select);
523         ///
524         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun,
525                 KeySequence const & shortcut, KeyMap::ItemType tag);
526         ///
527         GuiShortcutDialog * shortcut_;
528         ///
529         ButtonController shortcut_bc_;
530         /// category items
531         QTreeWidgetItem * editItem_;
532         QTreeWidgetItem * mathItem_;
533         QTreeWidgetItem * bufferItem_;
534         QTreeWidgetItem * layoutItem_;
535         QTreeWidgetItem * systemItem_;
536         // system_bind_ holds bindings from rc.bind_file
537         // user_bind_ holds \bind bindings from user.bind
538         // user_unbind_ holds \unbind bindings from user.bind
539         // When an item is inserted, it is added to user_bind_
540         // When an item from system_bind_ is deleted, it is added to user_unbind_
541         // When an item in user_bind_ or user_unbind_ is deleted, it is
542         //      deleted (unbind)
543         KeyMap system_bind_;
544         KeyMap user_bind_;
545         KeyMap user_unbind_;
546         ///
547         QString save_lfun_;
548 };
549
550
551 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
552 {
553         Q_OBJECT
554 public:
555         PrefIdentity(GuiPreferences * form);
556
557         void applyRC(LyXRC & rc) const override;
558         void updateRC(LyXRC const & rc) override;
559 };
560
561
562 } // namespace frontend
563 } // namespace lyx
564
565 #endif // GUIPREFS_H