GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
shortcut-manager.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2014-2017 Torsten <ttl@justmail.de>
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_shortcut_manager_h)
24 #define octave_shortcut_manager_h 1
25 
26 #include <QWidget>
27 #include <QTreeWidget>
28 #include <QLineEdit>
29 #include <QKeyEvent>
30 #include <QLabel>
31 #include <QSettings>
32 
33 class enter_shortcut : public QLineEdit
34 {
35  Q_OBJECT
36 
37 public:
38  enter_shortcut (QWidget *p = 0);
39  ~enter_shortcut ();
40 
41  virtual void keyPressEvent (QKeyEvent *e);
42 
43 public slots:
44  void handle_direct_shortcut (int);
45 
46 private:
48 
49 };
50 
51 
52 class shortcut_manager : public QWidget
53 {
54  Q_OBJECT
55 
56 public:
57 
58  enum
59  {
63  };
64 
67 
68  static void init_data ()
69  {
70  if (instance_ok ())
72  }
73 
74  static void write_shortcuts (QSettings *settings, bool closing)
75  {
76  if (instance_ok ())
77  instance->do_write_shortcuts (settings, closing);
78  }
79 
80  static void set_shortcut (QAction *action, const QString& key)
81  {
82  if (instance_ok ())
83  instance->do_set_shortcut (action, key);
84  }
85 
86  static void fill_treewidget (QTreeWidget *tree_view)
87  {
88  if (instance_ok ())
89  instance->do_fill_treewidget (tree_view);
90  }
91 
92  static void import_export (int action)
93  {
94  if (instance_ok ())
95  instance->do_import_export (action);
96  }
97 
99 
100 public slots:
101 
102  static void cleanup_instance (void) { delete instance; instance = 0; }
103 
104 signals:
105 
106 protected:
107 
108 protected slots:
109 
110  void handle_double_clicked (QTreeWidgetItem*, int);
111  void shortcut_dialog_finished (int);
113 
114 private:
115 
116  // No copying!
117 
118  static bool instance_ok (void);
119 
120  void init (const QString&, const QString&, const QKeySequence&);
121  void do_init_data ();
122  void do_write_shortcuts (QSettings *settings, bool closing);
123  void do_set_shortcut (QAction *action, const QString& key);
124  void do_fill_treewidget (QTreeWidget *tree_view);
125  bool do_import_export (int action);
126  void shortcut_dialog (int);
127  void import_shortcuts (QSettings *settings);
128  bool overwrite_all_shortcuts (void);
129 
131  {
132  public:
133 
134  shortcut_t (void)
135  : tree_item (0), description (), settings_key (),
136  actual_sc (QKeySequence ()), default_sc (QKeySequence ())
137  { }
138 
142  {
143  actual_sc = x.actual_sc;
145  }
146 
148  {
149  if (&x != this)
150  {
151  tree_item = x.tree_item;
154 
155  actual_sc = QKeySequence ();
156  default_sc = QKeySequence ();
157 
158  actual_sc = x.actual_sc;
160  }
161 
162  return *this;
163  }
164 
165  ~shortcut_t (void)
166  { }
167 
168  QTreeWidgetItem *tree_item;
169  QString description;
170  QString settings_key;
171  QKeySequence actual_sc;
172  QKeySequence default_sc;
173  };
174 
176  QHash<QString, int> _shortcut_hash;
177  QHash<QString, int> _action_hash;
178  QHash <QString, QTreeWidgetItem*> _level_hash;
179  QHash<int, QTreeWidgetItem*> _index_item_hash;
180  QHash<QTreeWidgetItem*, int> _item_index_hash;
181 
184  QLabel *_label_default;
186 
187  QSettings *_settings;
188 
189 };
190 
191 #endif
QHash< int, QTreeWidgetItem * > _index_item_hash
void init(const QString &, const QString &, const QKeySequence &)
static void import_export(int action)
QHash< QTreeWidgetItem *, int > _item_index_hash
bool do_import_export(int action)
enter_shortcut * _edit_actual
QSettings * _settings
void shortcut_dialog_set_default()
bool overwrite_all_shortcuts(void)
static void write_shortcuts(QSettings *settings, bool closing)
void import_shortcuts(QSettings *settings)
void do_write_shortcuts(QSettings *settings, bool closing)
static shortcut_manager * instance
void handle_double_clicked(QTreeWidgetItem *, int)
QHash< QString, int > _action_hash
i e
Definition: data.cc:2724
void handle_direct_shortcut(int)
shortcut_t & operator=(const shortcut_t &x)
static void cleanup_instance(void)
static void fill_treewidget(QTreeWidget *tree_view)
enter_shortcut(QWidget *p=0)
virtual void keyPressEvent(QKeyEvent *e)
p
Definition: lu.cc:138
QHash< QString, QTreeWidgetItem * > _level_hash
void do_fill_treewidget(QTreeWidget *tree_view)
shortcut_t(const shortcut_t &x)
QHash< QString, int > _shortcut_hash
static bool instance_ok(void)
void do_set_shortcut(QAction *action, const QString &key)
QList< shortcut_t > _sc
static void set_shortcut(QAction *action, const QString &key)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
void shortcut_dialog_finished(int)
static void init_data()