]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
e4b5f19a96b6578f7cebec5fc1f667c0629852bb
[lyx.git] / src / frontends / qt4 / 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  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GUIPREFS_H
13 #define GUIPREFS_H
14
15 #include "GuiDialog.h"
16
17 #include "Color.h"
18 #include "Converter.h"
19 #include "Format.h"
20 #include "KeyMap.h"
21 #include "lfuns.h"
22 #include "LyXRC.h"
23 #include "Mover.h"
24
25 #include "ui_PrefsUi.h"
26
27 #include "ui_PrefPlaintextUi.h"
28 #include "ui_PrefDateUi.h"
29 #include "ui_PrefKeyboardUi.h"
30 #include "ui_PrefLatexUi.h"
31 #include "ui_PrefScreenFontsUi.h"
32 #include "ui_PrefColorsUi.h"
33 #include "ui_PrefDisplayUi.h"
34 #include "ui_PrefPathsUi.h"
35 #include "ui_PrefShortcutsUi.h"
36 #include "ui_PrefSpellcheckerUi.h"
37 #include "ui_PrefConvertersUi.h"
38 #include "ui_PrefFileformatsUi.h"
39 #include "ui_PrefLanguageUi.h"
40 #include "ui_PrefPrinterUi.h"
41 #include "ui_PrefUi.h"
42 #include "ui_PrefIdentityUi.h"
43 #include "ui_ShortcutUi.h"
44
45 #include <QDialog>
46 #include <QValidator>
47
48 #include <string>
49 #include <vector>
50
51
52 namespace lyx {
53
54 class Color_color;
55 class Converters;
56 class Formats;
57 class Movers;
58
59 namespace frontend {
60
61 class GuiPreferences;
62
63 class PrefModule : public QWidget
64 {
65         Q_OBJECT
66 public:
67         PrefModule(docstring const & t,
68                         GuiPreferences * form = 0, QWidget * parent = 0)
69                 : QWidget(parent), title_(t), form_(form)
70         {}
71
72         virtual void apply(LyXRC & rc) const = 0;
73         virtual void update(LyXRC const & rc) = 0;
74
75         docstring const & title() const { return title_; }
76
77 protected:
78         docstring title_;
79         GuiPreferences * form_;
80
81 Q_SIGNALS:
82         void changed();
83 };
84
85
86 class PrefPlaintext : public PrefModule, public Ui::PrefPlaintextUi
87 {
88         Q_OBJECT
89 public:
90         PrefPlaintext(QWidget * parent = 0);
91
92         virtual void apply(LyXRC & rc) const;
93         virtual void update(LyXRC const & rc);
94 };
95
96
97 class PrefDate : public PrefModule, public Ui::PrefDateUi
98 {
99         Q_OBJECT
100 public:
101         PrefDate(QWidget * parent = 0);
102
103         virtual void apply(LyXRC & rc) const;
104         virtual void update(LyXRC const & rc);
105 };
106
107
108 class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi
109 {
110         Q_OBJECT
111 public:
112         PrefKeyboard(GuiPreferences * form, QWidget * parent = 0);
113
114         virtual void apply(LyXRC & rc) const;
115         virtual void update(LyXRC const & rc);
116
117 private Q_SLOTS:
118         void on_firstKeymapPB_clicked(bool);
119         void on_secondKeymapPB_clicked(bool);
120         void on_keymapCB_toggled(bool);
121
122 private:
123         QString testKeymap(QString keymap);
124 };
125
126
127 class PrefLatex : public PrefModule, public Ui::PrefLatexUi
128 {
129         Q_OBJECT
130 public:
131         PrefLatex(GuiPreferences * form, QWidget * parent = 0);
132
133         virtual void apply(LyXRC & rc) const;
134         virtual void update(LyXRC const & rc);
135 };
136
137
138 class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
139 {
140         Q_OBJECT
141 public:
142         PrefScreenFonts(GuiPreferences * form, QWidget * parent = 0);
143
144         virtual void apply(LyXRC & rc) const;
145         virtual void update(LyXRC const & rc);
146
147 private Q_SLOTS:
148         void select_roman(const QString&);
149         void select_sans(const QString&);
150         void select_typewriter(const QString&);
151 };
152
153
154 class PrefColors : public PrefModule, public Ui::PrefColorsUi
155 {
156         Q_OBJECT
157 public:
158         PrefColors(GuiPreferences * form, QWidget * parent = 0);
159
160         void apply(LyXRC & rc) const;
161         void update(LyXRC const & rc);
162
163 private Q_SLOTS:
164         void change_color();
165         void change_lyxObjects_selection();
166
167 private:
168         std::vector<Color_color> lcolors_;
169         // FIXME the use of mutable here is required due to the
170         // fact that initialization is not done in the controller
171         // but in the constructor.
172         std::vector<QString> curcolors_;
173         std::vector<QString> newcolors_;
174
175 };
176
177
178 class PrefDisplay : public PrefModule, public Ui::PrefDisplayUi
179 {
180         Q_OBJECT
181 public:
182         PrefDisplay(QWidget * parent = 0);
183
184         void apply(LyXRC & rc) const;
185         void update(LyXRC const & rc);
186 };
187
188
189 class PrefPaths : public PrefModule, public Ui::PrefPathsUi
190 {
191         Q_OBJECT
192 public:
193         PrefPaths(GuiPreferences * form, QWidget * parent = 0);
194
195         void apply(LyXRC & rc) const;
196         void update(LyXRC const & rc);
197
198 private Q_SLOTS:
199         void select_templatedir();
200         void select_tempdir();
201         void select_backupdir();
202         void select_workingdir();
203         void select_lyxpipe();
204
205 };
206
207
208 class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
209 {
210         Q_OBJECT
211 public:
212         PrefSpellchecker(GuiPreferences * form, QWidget * parent = 0);
213
214         void apply(LyXRC & rc) const;
215         void update(LyXRC const & rc);
216
217 private Q_SLOTS:
218         void select_dict();
219 };
220
221
222 class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
223 {
224         Q_OBJECT
225 public:
226         PrefConverters(GuiPreferences * form, QWidget * parent = 0);
227
228         void apply(LyXRC & rc) const;
229         void update(LyXRC const & rc);
230
231 public Q_SLOTS:
232         void updateGui();
233
234 private Q_SLOTS:
235         void update_converter();
236         void switch_converter();
237         void converter_changed();
238         void remove_converter();
239         void on_cacheCB_stateChanged(int state);
240
241 private:
242         void updateButtons();
243 };
244
245
246 class FormatValidator : public QValidator
247 {
248 public:
249         FormatValidator(QWidget *, Formats const & f);
250         void fixup(QString & input) const;
251         QValidator::State validate(QString & input, int & pos) const;
252 private:
253         virtual std::string str(Formats::const_iterator it) const = 0;
254         int nr() const;
255         Formats const & formats_;
256 };
257
258
259 class FormatNameValidator : public FormatValidator
260 {
261 public:
262         FormatNameValidator(QWidget *, Formats const & f);
263 private:
264         std::string str(Formats::const_iterator it) const;
265 };
266
267 class FormatPrettynameValidator : public FormatValidator
268 {
269 public:
270         FormatPrettynameValidator(QWidget *, Formats const & f);
271 private:
272         std::string str(Formats::const_iterator it) const;
273 };
274
275
276 class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
277 {
278         Q_OBJECT
279 public:
280         PrefFileformats(GuiPreferences * form, QWidget * parent = 0);
281
282         void apply(LyXRC & rc) const;
283         void update(LyXRC const & rc);
284         void updateView();
285
286 Q_SIGNALS:
287         void formatsChanged();
288
289 private Q_SLOTS:
290         void on_copierED_textEdited(const QString & s);
291         void on_extensionED_textEdited(const QString &);
292         void on_viewerED_textEdited(const QString &);
293         void on_editorED_textEdited(const QString &);
294         void on_shortcutED_textEdited(const QString &);
295         void on_formatED_editingFinished();
296         void on_formatED_textChanged(const QString &);
297         void on_formatsCB_currentIndexChanged(int);
298         void on_formatsCB_editTextChanged(const QString &);
299         void on_formatNewPB_clicked();
300         void on_formatRemovePB_clicked();
301         void setFlags();
302         void updatePrettyname();
303
304 private:
305         Format & currentFormat();
306 };
307
308
309 class PrefLanguage : public PrefModule, public Ui::PrefLanguageUi
310 {
311         Q_OBJECT
312 public:
313         PrefLanguage(QWidget * parent = 0);
314
315         void apply(LyXRC & rc) const;
316         void update(LyXRC const & rc);
317
318 private:
319         std::vector<std::string> lang_;
320 };
321
322
323 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
324 {
325         Q_OBJECT
326 public:
327         PrefPrinter(QWidget * parent = 0);
328
329         void apply(LyXRC & rc) const;
330         void update(LyXRC const & rc);
331 };
332
333
334 class PrefUserInterface : public PrefModule, public Ui::PrefUi
335 {
336         Q_OBJECT
337 public:
338         PrefUserInterface(GuiPreferences * form, QWidget * parent = 0);
339
340         void apply(LyXRC & rc) const;
341         void update(LyXRC const & rc);
342
343 public Q_SLOTS:
344         void select_ui();
345         void on_loadWindowSizeCB_toggled(bool);
346
347 };
348
349
350 class GuiShortcutDialog : public QDialog, public Ui::ShortcutUi
351 {
352 public:
353         GuiShortcutDialog(QWidget * parent) : QDialog(parent)
354         {
355                 Ui::ShortcutUi::setupUi(this);
356                 QDialog::setModal(true);
357         }
358 };
359
360
361 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
362 {
363         Q_OBJECT
364 private:
365         enum item_type {
366                 System,         //< loaded from a bind file
367                 UserBind,       //< \bind loaded from user.bind
368                 UserUnbind,     //< \unbind loaded from user.bind, with corresponding
369                                         //<    entry in system bind file
370                 UserExtraUnbind //< \unbind loaded from user.bind, without
371                                                 //<    corresponding entry in system bind file.
372         };
373 public:
374         PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);
375
376         void apply(LyXRC & rc) const;
377         void update(LyXRC const & rc);
378         void updateShortcutsTW();
379         ///
380         void setItemType(QTreeWidgetItem * item, item_type tag);
381         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
382                 KeySequence const & shortcut, item_type tag);
383
384 public Q_SLOTS:
385         void select_bind();
386         void on_newPB_pressed();
387         void on_removePB_pressed();
388         void on_searchPB_pressed();
389         void on_searchLE_textChanged();
390         ///
391         void on_shortcutsTW_itemSelectionChanged();
392         void shortcut_okPB_pressed();
393         void on_shortcutsTW_itemDoubleClicked();
394
395 private:
396         ///
397         GuiShortcutDialog * shortcut_;
398         ///
399         ButtonController shortcut_bc_;
400         /// category items
401         QTreeWidgetItem * editItem_;
402         QTreeWidgetItem * mathItem_;
403         QTreeWidgetItem * bufferItem_;
404         QTreeWidgetItem * layoutItem_;
405         QTreeWidgetItem * systemItem_;
406         // system_bind_ holds bindings from rc.bind_file
407         // user_bind_ holds \bind bindings from user.bind
408         // user_unbind_ holds \unbind bindings from user.bind
409         // When an item is inserted, it is added to user_bind_
410         // When an item from system_bind_ is deleted, it is added to user_unbind_
411         // When an item in user_bind_ or user_unbind_ is deleted, it is 
412         //      deleted (unbind)
413         KeyMap system_bind_;
414         KeyMap user_bind_;
415         KeyMap user_unbind_;
416 };
417
418
419 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
420 {
421         Q_OBJECT
422 public:
423         PrefIdentity(QWidget * parent = 0);
424
425         void apply(LyXRC & rc) const;
426         void update(LyXRC const & rc);
427 };
428
429
430 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
431 {
432         Q_OBJECT
433 public:
434         GuiPreferences(LyXView & lv);
435
436         void apply(LyXRC & rc) const;
437         void updateRc(LyXRC const & rc);
438
439 public Q_SLOTS:
440         void change_adaptor();
441
442 public:
443         //
444         void closeEvent(QCloseEvent * e);
445         ///
446         void add(PrefModule * module);
447         /// Apply changes
448         void applyView();
449         /// update (do we need this?)
450         void updateContents();
451
452         std::vector<PrefModule *> modules_;
453
454         ///
455         bool initialiseParams(std::string const &);
456         ///
457         void clearParams() {}
458         ///
459         void dispatchParams();
460         ///
461         bool isBufferDependent() const { return false; }
462
463         /// various file pickers
464         docstring const browsebind(docstring const & file) const;
465         docstring const browseUI(docstring const & file) const;
466         docstring const browsekbmap(docstring const & file) const;
467         docstring const browsedict(docstring const & file) const;
468
469         /// general browse
470         docstring const browse(docstring const & file,
471                                  docstring const & title) const;
472
473         /// browse directory
474         docstring const browsedir(docstring const & path,
475                                     docstring const & title) const;
476
477         /// set a color
478         void setColor(Color_color col, std::string const & hex);
479
480         /// update the screen fonts after change
481         void updateScreenFonts();
482
483         /// adjust the prefs paper sizes
484         PAPER_SIZE toPaperSize(int i) const;
485         /// adjust the prefs paper sizes
486         int fromPaperSize(PAPER_SIZE papersize) const;
487
488         LyXRC & rc() { return rc_; }
489         Converters & converters() { return converters_; }
490         Formats & formats() { return formats_; }
491         Movers & movers() { return movers_; }
492
493 private:
494         /// temporary lyxrc
495         LyXRC rc_;
496         /// temporary converters
497         Converters converters_;
498         /// temporary formats
499         Formats formats_;
500         /// temporary movers
501         Movers movers_;
502
503         /// A list of colors to be dispatched
504         std::vector<std::string> colors_;
505
506         bool redraw_gui_;
507         bool update_screen_font_;
508 };
509
510
511 } // namespace frontend
512 } // namespace lyx
513
514 #endif // GUIPREFS_H