]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrefs.h
do what the FIXME suggested
[lyx.git] / src / frontends / qt4 / GuiPrefs.h
index 72b8d22dfd1aa027d91dd3d9e1fc6274cbf08ac8..ec37c76a607967dfac899b5cddaa48b45ff0eb9a 100644 (file)
@@ -5,6 +5,8 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ * \author Bo Peng
+ * \author Edwin Leuven
  *
  * Full author contact details are available in file CREDITS.
  */
 #define GUIPREFS_H
 
 #include "GuiDialog.h"
-#include "ControlPrefs.h"
-#include "Color.h"
+
+#include "ColorCode.h"
+#include "Converter.h"
+#include "Format.h"
+#include "KeyMap.h"
+#include "lfuns.h"
 #include "LyXRC.h"
+#include "Mover.h"
 
 #include "ui_PrefsUi.h"
 
 #include "ui_PrefPlaintextUi.h"
 #include "ui_PrefDateUi.h"
-#include "ui_PrefKeyboardUi.h"
+#include "ui_PrefInputUi.h"
 #include "ui_PrefLatexUi.h"
 #include "ui_PrefScreenFontsUi.h"
 #include "ui_PrefColorsUi.h"
 #include "ui_PrefDisplayUi.h"
 #include "ui_PrefPathsUi.h"
+#include "ui_PrefShortcutsUi.h"
 #include "ui_PrefSpellcheckerUi.h"
 #include "ui_PrefConvertersUi.h"
-#include "ui_PrefCopiersUi.h"
 #include "ui_PrefFileformatsUi.h"
 #include "ui_PrefLanguageUi.h"
 #include "ui_PrefPrinterUi.h"
 #include "ui_PrefUi.h"
 #include "ui_PrefIdentityUi.h"
+#include "ui_ShortcutUi.h"
 
 #include <QDialog>
+#include <QValidator>
 
+#include <string>
 #include <vector>
 
+
 namespace lyx {
 
 class Converters;
@@ -48,14 +59,14 @@ class Movers;
 
 namespace frontend {
 
-class GuiPrefsDialog;
+class GuiPreferences;
 
 class PrefModule : public QWidget
 {
        Q_OBJECT
 public:
        PrefModule(docstring const & t,
-                       GuiPrefsDialog * form = 0, QWidget * parent = 0)
+                       GuiPreferences * form = 0, QWidget * parent = 0)
                : QWidget(parent), title_(t), form_(form)
        {}
 
@@ -66,7 +77,7 @@ public:
 
 protected:
        docstring title_;
-       GuiPrefsDialog * form_;
+       GuiPreferences * form_;
 
 Q_SIGNALS:
        void changed();
@@ -95,11 +106,11 @@ public:
 };
 
 
-class PrefKeyboard : public PrefModule, public Ui::PrefKeyboardUi
+class PrefInput : public PrefModule, public Ui::PrefInputUi
 {
        Q_OBJECT
 public:
-       PrefKeyboard(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefInput(GuiPreferences * form, QWidget * parent = 0);
 
        virtual void apply(LyXRC & rc) const;
        virtual void update(LyXRC const & rc);
@@ -118,7 +129,7 @@ class PrefLatex : public PrefModule, public Ui::PrefLatexUi
 {
        Q_OBJECT
 public:
-       PrefLatex(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefLatex(GuiPreferences * form, QWidget * parent = 0);
 
        virtual void apply(LyXRC & rc) const;
        virtual void update(LyXRC const & rc);
@@ -129,7 +140,7 @@ class PrefScreenFonts : public PrefModule, public Ui::PrefScreenFontsUi
 {
        Q_OBJECT
 public:
-       PrefScreenFonts(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefScreenFonts(GuiPreferences * form, QWidget * parent = 0);
 
        virtual void apply(LyXRC & rc) const;
        virtual void update(LyXRC const & rc);
@@ -145,7 +156,7 @@ class PrefColors : public PrefModule, public Ui::PrefColorsUi
 {
        Q_OBJECT
 public:
-       PrefColors(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefColors(GuiPreferences * form, QWidget * parent = 0);
 
        void apply(LyXRC & rc) const;
        void update(LyXRC const & rc);
@@ -155,7 +166,7 @@ private Q_SLOTS:
        void change_lyxObjects_selection();
 
 private:
-       std::vector<Color_color> lcolors_;
+       std::vector<ColorCode> lcolors_;
        // FIXME the use of mutable here is required due to the
        // fact that initialization is not done in the controller
        // but in the constructor.
@@ -180,12 +191,13 @@ class PrefPaths : public PrefModule, public Ui::PrefPathsUi
 {
        Q_OBJECT
 public:
-       PrefPaths(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefPaths(GuiPreferences * form, QWidget * parent = 0);
 
        void apply(LyXRC & rc) const;
        void update(LyXRC const & rc);
 
 private Q_SLOTS:
+       void select_exampledir();
        void select_templatedir();
        void select_tempdir();
        void select_backupdir();
@@ -199,7 +211,7 @@ class PrefSpellchecker : public PrefModule, public Ui::PrefSpellcheckerUi
 {
        Q_OBJECT
 public:
-       PrefSpellchecker(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefSpellchecker(GuiPreferences * form, QWidget * parent = 0);
 
        void apply(LyXRC & rc) const;
        void update(LyXRC const & rc);
@@ -213,7 +225,7 @@ class PrefConverters : public PrefModule, public Ui::PrefConvertersUi
 {
        Q_OBJECT
 public:
-       PrefConverters(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefConverters(GuiPreferences * form, QWidget * parent = 0);
 
        void apply(LyXRC & rc) const;
        void update(LyXRC const & rc);
@@ -233,27 +245,33 @@ private:
 };
 
 
-class PrefCopiers : public PrefModule, public Ui::PrefCopiersUi
+class FormatValidator : public QValidator
 {
-       Q_OBJECT
 public:
-       PrefCopiers(GuiPrefsDialog * form, QWidget * parent = 0);
-
-       void apply(LyXRC & rc) const;
-       void update(LyXRC const & rc);
+       FormatValidator(QWidget *, Formats const & f);
+       void fixup(QString & input) const;
+       QValidator::State validate(QString & input, int & pos) const;
+private:
+       virtual std::string str(Formats::const_iterator it) const = 0;
+       int nr() const;
+       Formats const & formats_;
+};
 
-       void updateView();
 
-private Q_SLOTS:
-       void switch_copierLB(int nr);
-       void switch_copierCO(int nr);
-       void copiers_changed();
-       void new_copier();
-       void modify_copier();
-       void remove_copier();
+class FormatNameValidator : public FormatValidator
+{
+public:
+       FormatNameValidator(QWidget *, Formats const & f);
+private:
+       std::string str(Formats::const_iterator it) const;
+};
 
+class FormatPrettynameValidator : public FormatValidator
+{
+public:
+       FormatPrettynameValidator(QWidget *, Formats const & f);
 private:
-       void updateButtons();
+       std::string str(Formats::const_iterator it) const;
 };
 
 
@@ -261,23 +279,32 @@ class PrefFileformats : public PrefModule, public Ui::PrefFileformatsUi
 {
        Q_OBJECT
 public:
-       PrefFileformats(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefFileformats(GuiPreferences * form, QWidget * parent = 0);
 
        void apply(LyXRC & rc) const;
        void update(LyXRC const & rc);
-
        void updateView();
+
 Q_SIGNALS:
        void formatsChanged();
-private:
-       void updateButtons();
 
 private Q_SLOTS:
-       void switch_format(int);
-       void fileformat_changed();
-       void new_format();
-       void modify_format();
-       void remove_format();
+       void on_copierED_textEdited(const QString & s);
+       void on_extensionED_textEdited(const QString &);
+       void on_viewerED_textEdited(const QString &);
+       void on_editorED_textEdited(const QString &);
+       void on_shortcutED_textEdited(const QString &);
+       void on_formatED_editingFinished();
+       void on_formatED_textChanged(const QString &);
+       void on_formatsCB_currentIndexChanged(int);
+       void on_formatsCB_editTextChanged(const QString &);
+       void on_formatNewPB_clicked();
+       void on_formatRemovePB_clicked();
+       void setFlags();
+       void updatePrettyname();
+
+private:
+       Format & currentFormat();
 };
 
 
@@ -310,16 +337,78 @@ class PrefUserInterface : public PrefModule, public Ui::PrefUi
 {
        Q_OBJECT
 public:
-       PrefUserInterface(GuiPrefsDialog * form, QWidget * parent = 0);
+       PrefUserInterface(GuiPreferences * form, QWidget * parent = 0);
 
        void apply(LyXRC & rc) const;
        void update(LyXRC const & rc);
 
 public Q_SLOTS:
        void select_ui();
+};
+
+
+class GuiShortcutDialog : public QDialog, public Ui::shortcutUi
+{
+public:
+       GuiShortcutDialog(QWidget * parent);
+};
+
+
+class PrefShortcuts : public PrefModule, public Ui::PrefShortcuts
+{
+       Q_OBJECT
+private:
+       enum item_type {
+               System,         //< loaded from a bind file
+               UserBind,       //< \bind loaded from user.bind
+               UserUnbind,     //< \unbind loaded from user.bind, with corresponding
+                                       //<    entry in system bind file
+               UserExtraUnbind //< \unbind loaded from user.bind, without
+                                               //<    corresponding entry in system bind file.
+       };
+public:
+       PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);
+
+       void apply(LyXRC & rc) const;
+       void update(LyXRC const & rc);
+       void updateShortcutsTW();
+       ///
+       void setItemType(QTreeWidgetItem * item, item_type tag);
+       QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, 
+               KeySequence const & shortcut, item_type tag);
+
+public Q_SLOTS:
        void select_bind();
-       void on_loadWindowSizeCB_toggled(bool);
+       void on_newPB_pressed();
+       void on_removePB_pressed();
+       void on_searchLE_textEdited();
+       ///
+       void on_shortcutsTW_itemSelectionChanged();
+       void shortcut_okPB_pressed();
+       void shortcut_clearPB_pressed();
+       void on_shortcutsTW_itemDoubleClicked();
 
+private:
+       ///
+       GuiShortcutDialog * shortcut_;
+       ///
+       ButtonController shortcut_bc_;
+       /// category items
+       QTreeWidgetItem * editItem_;
+       QTreeWidgetItem * mathItem_;
+       QTreeWidgetItem * bufferItem_;
+       QTreeWidgetItem * layoutItem_;
+       QTreeWidgetItem * systemItem_;
+       // system_bind_ holds bindings from rc.bind_file
+       // user_bind_ holds \bind bindings from user.bind
+       // user_unbind_ holds \unbind bindings from user.bind
+       // When an item is inserted, it is added to user_bind_
+       // When an item from system_bind_ is deleted, it is added to user_unbind_
+       // When an item in user_bind_ or user_unbind_ is deleted, it is 
+       //      deleted (unbind)
+       KeyMap system_bind_;
+       KeyMap user_bind_;
+       KeyMap user_unbind_;
 };
 
 
@@ -333,12 +422,12 @@ public:
        void update(LyXRC const & rc);
 };
 
-///
-class GuiPrefsDialog : public GuiDialog, public Ui::PrefsUi
+
+class GuiPreferences : public GuiDialog, public Ui::PrefsUi
 {
        Q_OBJECT
 public:
-       GuiPrefsDialog(LyXView & lv);
+       GuiPreferences(GuiView & lv);
 
        void apply(LyXRC & rc) const;
        void updateRc(LyXRC const & rc);
@@ -347,24 +436,69 @@ public Q_SLOTS:
        void change_adaptor();
 
 public:
-       //
-       void closeEvent(QCloseEvent * e);
        ///
        void add(PrefModule * module);
-       ///
-       Converters & converters();
-       ///
-       Formats & formats();
-       ///
-       Movers & movers();
-       /// parent controller
-       ControlPrefs & controller() const;
        /// Apply changes
        void applyView();
        /// update (do we need this?)
-       void update_contents();
+       void updateContents();
 
        std::vector<PrefModule *> modules_;
+
+       ///
+       bool initialiseParams(std::string const &);
+       ///
+       void clearParams() {}
+       ///
+       void dispatchParams();
+       ///
+       bool isBufferDependent() const { return false; }
+
+       /// various file pickers
+       docstring const browsebind(docstring const & file) const;
+       docstring const browseUI(docstring const & file) const;
+       docstring const browsekbmap(docstring const & file) const;
+       docstring const browsedict(docstring const & file) const;
+
+       /// general browse
+       docstring const browse(docstring const & file,
+                                docstring const & title) const;
+
+       /// browse directory
+       docstring const browsedir(docstring const & path,
+                                   docstring const & title) const;
+
+       /// set a color
+       void setColor(ColorCode col, std::string const & hex);
+
+       /// update the screen fonts after change
+       void updateScreenFonts();
+
+       /// adjust the prefs paper sizes
+       PAPER_SIZE toPaperSize(int i) const;
+       /// adjust the prefs paper sizes
+       int fromPaperSize(PAPER_SIZE papersize) const;
+
+       LyXRC & rc() { return rc_; }
+       Converters & converters() { return converters_; }
+       Formats & formats() { return formats_; }
+       Movers & movers() { return movers_; }
+
+private:
+       /// temporary lyxrc
+       LyXRC rc_;
+       /// temporary converters
+       Converters converters_;
+       /// temporary formats
+       Formats formats_;
+       /// temporary movers
+       Movers movers_;
+
+       /// A list of colors to be dispatched
+       std::vector<std::string> colors_;
+
+       bool redraw_gui_;
+       bool update_screen_font_;
 };