GNU Octave  4.0.0
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-2015 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 #ifndef SHORTCUT_MANAGER_H
24 #define SHORTCUT_MANAGER_H
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:
59 
60  static void init_data ()
61  {
62  if (instance_ok ())
64  }
65 
66  static void write_shortcuts (int set, QSettings *settings, bool closing)
67  {
68  if (instance_ok ())
69  instance->do_write_shortcuts (set, settings, closing);
70  }
71 
72  static void set_shortcut (QAction *action, const QString& key)
73  {
74  if (instance_ok ())
75  instance->do_set_shortcut (action, key);
76  }
77 
78  static void fill_treewidget (QTreeWidget *tree_view)
79  {
80  if (instance_ok ())
81  instance->do_fill_treewidget (tree_view);
82  }
83 
84  static void import_export (bool import, int set)
85  {
86  if (instance_ok ())
87  instance->do_import_export (import, set);
88  }
89 
90 public slots:
91 
92 signals:
93 
94 protected:
95 
96 protected slots:
97 
98  void handle_double_clicked (QTreeWidgetItem*, int);
99  void shortcut_dialog_finished (int);
101 
102 private:
103 
105  static void cleanup_instance (void) { delete instance; instance = 0; }
106 
107  // No copying!
108 
111 
112  static bool instance_ok (void);
113 
114  void init (QString, QString, QKeySequence);
115  void do_init_data ();
116  void do_write_shortcuts (int set, QSettings *settings, bool closing);
117  void do_set_shortcut (QAction *action, const QString& key);
118  void do_fill_treewidget (QTreeWidget *tree_view);
119  void do_import_export (bool import, int set);
120  void shortcut_dialog (int);
121  void import_shortcuts (int set, QSettings *settings);
122 
124  {
125  public:
126 
127  shortcut_t (void)
128  : tree_item (0), description (), settings_key (),
129  actual_sc (new QKeySequence[2]), default_sc (new QKeySequence[2])
130  {
131  actual_sc[0] = QKeySequence ();
132  actual_sc[1] = QKeySequence ();
133 
134  default_sc[0] = QKeySequence ();
135  default_sc[1] = QKeySequence ();
136  }
137 
141  actual_sc (new QKeySequence[2]), default_sc (new QKeySequence[2])
142  {
143  actual_sc[0] = x.actual_sc[0];
144  actual_sc[1] = x.actual_sc[1];
145 
146  default_sc[0] = x.default_sc[0];
147  default_sc[1] = x.default_sc[1];
148  }
149 
151  {
152  if (&x != this)
153  {
154  tree_item = x.tree_item;
157 
158  actual_sc = new QKeySequence[2];
159  default_sc = new QKeySequence[2];
160 
161  actual_sc[0] = x.actual_sc[0];
162  actual_sc[1] = x.actual_sc[1];
163 
164  default_sc[0] = x.default_sc[0];
165  default_sc[1] = x.default_sc[1];
166  }
167 
168  return *this;
169  }
170 
171  ~shortcut_t (void)
172  {
173  delete [] actual_sc;
174  delete [] default_sc;
175  }
176 
177  QTreeWidgetItem *tree_item;
178  QString description;
179  QString settings_key;
180  QKeySequence *actual_sc;
181  QKeySequence *default_sc;
182  };
183 
185  QHash<QString, int> _shortcut_hash;
186  QHash<QString, int> _action_hash;
187  QHash <QString, QTreeWidgetItem*> _level_hash;
188  QHash<int, QTreeWidgetItem*> _index_item_hash;
189  QHash<QTreeWidgetItem*, int> _item_index_hash;
190 
193  QLabel *_label_default;
195 
196  QSettings *_settings;
198 
199 };
200 
201 
202 #endif // SHORTCUT_MANAGER_H
QHash< int, QTreeWidgetItem * > _index_item_hash
QHash< QTreeWidgetItem *, int > _item_index_hash
void do_import_export(bool import, int set)
void init(QString, QString, QKeySequence)
enter_shortcut * _edit_actual
QSettings * _settings
void shortcut_dialog_set_default()
static shortcut_manager * instance
void handle_double_clicked(QTreeWidgetItem *, int)
QHash< QString, int > _action_hash
shortcut_manager & operator=(const shortcut_manager &)
void do_write_shortcuts(int set, QSettings *settings, bool closing)
void handle_direct_shortcut(int)
shortcut_t & operator=(const shortcut_t &x)
static void cleanup_instance(void)
static void fill_treewidget(QTreeWidget *tree_view)
static void import_export(bool import, int set)
enter_shortcut(QWidget *p=0)
virtual void keyPressEvent(QKeyEvent *e)
static void write_shortcuts(int set, QSettings *settings, bool closing)
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 const double * x
void import_shortcuts(int set, QSettings *settings)
void shortcut_dialog_finished(int)
static void init_data()