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