GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
shortcut-manager.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2014-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 namespace octave
34 {
35  class enter_shortcut : public QLineEdit
36  {
37  Q_OBJECT
38 
39  public:
40 
41  enter_shortcut (QWidget *p = nullptr);
42 
43  ~enter_shortcut (void) = default;
44 
45  virtual void keyPressEvent (QKeyEvent *e);
46 
47  public slots:
48 
49  void handle_direct_shortcut (int);
50 
51  private:
52 
54 
55  };
56 
57  class shortcut_manager : public QWidget
58  {
59  Q_OBJECT
60 
61  public:
62 
63  enum
64  {
68  };
69 
70  shortcut_manager (void);
71 
72  // No copying!
73 
74  shortcut_manager (const shortcut_manager&) = delete;
75 
77 
78  ~shortcut_manager (void) = default;
79 
80  static void init_data (void)
81  {
82  if (instance_ok ())
84  }
85 
86  static void write_shortcuts (QSettings *settings, bool closing)
87  {
88  if (instance_ok ())
89  instance->do_write_shortcuts (settings, closing);
90  }
91 
92  static void set_shortcut (QAction *action, const QString& key)
93  {
94  if (instance_ok ())
95  instance->do_set_shortcut (action, key);
96  }
97 
98  static void fill_treewidget (QTreeWidget *tree_view)
99  {
100  if (instance_ok ())
101  instance->do_fill_treewidget (tree_view);
102  }
103 
104  static void import_export (int action)
105  {
106  if (instance_ok ())
107  instance->do_import_export (action);
108  }
109 
111 
112  public slots:
113 
114  static void cleanup_instance (void) { delete instance; instance = nullptr; }
115 
116  protected slots:
117 
118  void handle_double_clicked (QTreeWidgetItem*, int);
119  void shortcut_dialog_finished (int);
121 
122  private:
123 
124  static bool instance_ok (void);
125 
126  void init (const QString&, const QString&, const QKeySequence&);
127  void do_init_data ();
128  void do_write_shortcuts (QSettings *settings, bool closing);
129  void do_set_shortcut (QAction *action, const QString& key);
130  void do_fill_treewidget (QTreeWidget *tree_view);
131  bool do_import_export (int action);
132  void shortcut_dialog (int);
133  void import_shortcuts (QSettings *settings);
134  bool overwrite_all_shortcuts (void);
135 
137  {
138  public:
139 
140  shortcut_t (void)
141  : m_tree_item (nullptr), m_description (), m_settings_key (),
142  m_actual_sc (QKeySequence ()), m_default_sc (QKeySequence ())
143  { }
144 
148  {
149  m_actual_sc = x.m_actual_sc;
150  m_default_sc = x.m_default_sc;
151  }
152 
154  {
155  if (&x != this)
156  {
157  m_tree_item = x.m_tree_item;
158  m_description = x.m_description;
159  m_settings_key = x.m_settings_key;
160 
161  m_actual_sc = QKeySequence ();
162  m_default_sc = QKeySequence ();
163 
164  m_actual_sc = x.m_actual_sc;
165  m_default_sc = x.m_default_sc;
166  }
167 
168  return *this;
169  }
170 
171  ~shortcut_t (void) = default;
172 
173  QTreeWidgetItem *m_tree_item;
174  QString m_description;
175  QString m_settings_key;
176  QKeySequence m_actual_sc;
177  QKeySequence m_default_sc;
178  };
179 
181  QHash<QString, int> m_shortcut_hash;
182  QHash<QString, int> m_action_hash;
183  QHash <QString, QTreeWidgetItem*> m_level_hash;
184  QHash<int, QTreeWidgetItem*> m_index_item_hash;
185  QHash<QTreeWidgetItem*, int> m_item_index_hash;
186 
191 
192  QSettings *m_settings;
193  };
194 }
195 
196 // FIXME: This is temporary and should be removed when all classes that
197 // use the shortcut_manager class are also inside the octave namespace.
199 
200 #endif
void do_fill_treewidget(QTreeWidget *tree_view)
static void cleanup_instance(void)
void do_set_shortcut(QAction *action, const QString &key)
static void import_export(int action)
QHash< int, QTreeWidgetItem * > m_index_item_hash
QHash< QString, int > m_action_hash
bool do_import_export(int action)
virtual void keyPressEvent(QKeyEvent *e)
static void fill_treewidget(QTreeWidget *tree_view)
i e
Definition: data.cc:2591
QHash< QString, int > m_shortcut_hash
enter_shortcut * m_edit_actual
static shortcut_manager * instance
shortcut_manager & operator=(const shortcut_manager &)=delete
void do_write_shortcuts(QSettings *settings, bool closing)
static void init_data(void)
static void set_shortcut(QAction *action, const QString &key)
void init(const QString &, const QString &, const QKeySequence &)
void import_shortcuts(QSettings *settings)
QHash< QTreeWidgetItem *, int > m_item_index_hash
static bool instance_ok(void)
QHash< QString, QTreeWidgetItem * > m_level_hash
enter_shortcut(QWidget *p=nullptr)
static void write_shortcuts(QSettings *settings, bool closing)
~shortcut_manager(void)=default
~enter_shortcut(void)=default
p
Definition: lu.cc:138
void handle_double_clicked(QTreeWidgetItem *, int)
shortcut_t & operator=(const shortcut_t &x)
QList< shortcut_t > m_sc
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x