]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiPrefs.h
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[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 private:
336         QStringList lang_;
337 };
338
339
340 class PrefPrinter : public PrefModule, public Ui::PrefPrinterUi
341 {
342         Q_OBJECT
343 public:
344         PrefPrinter(QWidget * parent = 0);
345
346         void apply(LyXRC & rc) const;
347         void update(LyXRC const & rc);
348 };
349
350
351 class PrefUserInterface : public PrefModule, public Ui::PrefUi
352 {
353         Q_OBJECT
354 public:
355         PrefUserInterface(GuiPreferences * form, QWidget * parent = 0);
356
357         void apply(LyXRC & rc) const;
358         void update(LyXRC const & rc);
359
360 public Q_SLOTS:
361         void select_ui();
362 };
363
364
365 class PrefEdit : public PrefModule, public Ui::PrefEditUi
366 {
367         Q_OBJECT
368 public:
369         PrefEdit(GuiPreferences * form, QWidget * parent = 0);
370
371         void apply(LyXRC & rc) const;
372         void update(LyXRC const & rc);
373 };
374
375
376
377 class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
378 {
379 public:
380         GuiShortcutDialog(QWidget * parent);
381 };
382
383
384 class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
385 {
386         Q_OBJECT
387 private:
388         enum item_type {
389                 System,         //< loaded from a bind file
390                 UserBind,       //< \bind loaded from user.bind
391                 UserUnbind,     //< \unbind loaded from user.bind, with corresponding
392                                         //<    entry in system bind file
393                 UserExtraUnbind //< \unbind loaded from user.bind, without
394                                                 //<    corresponding entry in system bind file.
395         };
396 public:
397         PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);
398
399         void apply(LyXRC & rc) const;
400         void update(LyXRC const & rc);
401         void updateShortcutsTW();
402         ///
403         void setItemType(QTreeWidgetItem * item, item_type tag);
404         QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
405                 KeySequence const & shortcut, item_type tag);
406
407 public Q_SLOTS:
408         void select_bind();
409         void on_newPB_pressed();
410         void on_removePB_pressed();
411         void on_searchLE_textEdited();
412         ///
413         void on_shortcutsTW_itemSelectionChanged();
414         void shortcut_okPB_pressed();
415         void shortcut_clearPB_pressed();
416         void on_shortcutsTW_itemDoubleClicked();
417
418 private:
419         ///
420         GuiShortcutDialog * shortcut_;
421         ///
422         ButtonController shortcut_bc_;
423         /// category items
424         QTreeWidgetItem * editItem_;
425         QTreeWidgetItem * mathItem_;
426         QTreeWidgetItem * bufferItem_;
427         QTreeWidgetItem * layoutItem_;
428         QTreeWidgetItem * systemItem_;
429         // system_bind_ holds bindings from rc.bind_file
430         // user_bind_ holds \bind bindings from user.bind
431         // user_unbind_ holds \unbind bindings from user.bind
432         // When an item is inserted, it is added to user_bind_
433         // When an item from system_bind_ is deleted, it is added to user_unbind_
434         // When an item in user_bind_ or user_unbind_ is deleted, it is 
435         //      deleted (unbind)
436         KeyMap system_bind_;
437         KeyMap user_bind_;
438         KeyMap user_unbind_;
439 };
440
441
442 class PrefIdentity : public PrefModule, public Ui::PrefIdentityUi
443 {
444         Q_OBJECT
445 public:
446         PrefIdentity(QWidget * parent = 0);
447
448         void apply(LyXRC & rc) const;
449         void update(LyXRC const & rc);
450 };
451
452
453 class GuiPreferences : public GuiDialog, public Ui::PrefsUi
454 {
455         Q_OBJECT
456 public:
457         GuiPreferences(GuiView & lv);
458
459         void apply(LyXRC & rc) const;
460         void updateRc(LyXRC const & rc);
461
462 public Q_SLOTS:
463         void change_adaptor();
464
465 public:
466         ///
467         void add(PrefModule * module);
468         /// Apply changes
469         void applyView();
470         /// update (do we need this?)
471         void updateContents();
472
473         std::vector<PrefModule *> modules_;
474
475         ///
476         bool initialiseParams(std::string const &);
477         ///
478         void clearParams() {}
479         ///
480         void dispatchParams();
481         ///
482         bool isBufferDependent() const { return false; }
483
484         /// various file pickers
485         QString browsebind(QString const & file) const;
486         QString browseUI(QString const & file) const;
487         QString browsekbmap(QString const & file) const;
488         QString browsedict(QString const & file) const;
489
490         /// general browse
491         QString browse(QString const & file, QString const & title) const;
492
493         /// browse directory
494         QString browsedir(QString const & path, QString const & title) const;
495
496         /// set a color
497         void setColor(ColorCode col, std::string const & hex);
498
499         /// update the screen fonts after change
500         void updateScreenFonts();
501
502         /// adjust the prefs paper sizes
503         PAPER_SIZE toPaperSize(int i) const;
504         /// adjust the prefs paper sizes
505         int fromPaperSize(PAPER_SIZE papersize) const;
506
507         LyXRC & rc() { return rc_; }
508         Converters & converters() { return converters_; }
509         Formats & formats() { return formats_; }
510         Movers & movers() { return movers_; }
511
512 private:
513         /// temporary lyxrc
514         LyXRC rc_;
515         /// temporary converters
516         Converters converters_;
517         /// temporary formats
518         Formats formats_;
519         /// temporary movers
520         Movers movers_;
521
522         /// A list of colors to be dispatched
523         std::vector<std::string> colors_;
524
525         bool redraw_gui_;
526         bool update_screen_font_;
527 };
528
529
530 } // namespace frontend
531 } // namespace lyx
532
533 #endif // GUIPREFS_H