Mercurial > octave-libgccjit
comparison libgui/src/shortcut-manager.h @ 18611:086093fbdc1a gui-release
first implementation of a shortcut manager (bug #41217)
* file-editor.cc (set_shortcuts): use shortcut-manager to set some shortcuts
* main_window.cc (set_global_shortcuts): use shortcut-manager to set some
shortcuts;
(construct_file_menu): all actions as class variables;
(construct_edit_menu): all actions as class variables;
* main_window.h: actions as class variables
* module.mk: new files shortcut_manager.cc, shortcut_manager.h
* octave-gui.cc (octave_start_gui): initialize the shortcut_manager
* settings-dialog.cc (constructor): call shortcut-manager for shortcut table
(write_changed_settings): call shortcut-manager for writing shortcuts
* settings-dialog.ui: new tab with a tree widget for the shortcuts
* shortcut_manager.cc (constructor, destructor): new class;
(instance_ok): checks if instance is valid, creates a new one otherwise;
(do_init_data): initialize the list with all shortcut's data;
(init): internal function for initializing the data list;
(do_fill_treewidget): fills the tree widget in the settings dialog;
(do_write_shortcuts): writes shortcuts from settings dialog into file;
(do_set_shortcut): setting the shortcut for an action;
(handle_double_clicked): slot for double clicking into the tree widget;
(shortcut_dialog): dialog for entering a new shortcut;
(shortcut_dialog_finished): processing the dialog's result;
(shortcut_dialog_set_default): setting the shortcut to it's default;
(enter_shortcut::enter_shortcut): new class derived from QLineEdit;
(enter_shortcut::handle_direct_shortcut): switch between normal editing and
directly entering a shortcut;
(enter_shortcut::keyPressEvent): event handler filtering the shortcuts;
* shortcut_manager.h (init_data): static function calling do_init_data;
(write_shortcuts): static function calling do_write_shortcuts;
(fill_treewidget): static function calling do_fill_treewidget;
(set_shortcut): static function calling do_set_shortcut;
author | Torsten <ttl@justmail.de> |
---|---|
date | Tue, 01 Apr 2014 21:29:48 +0200 |
parents | |
children | 1b289f45187f |
comparison
equal
deleted
inserted
replaced
18610:6e81b59d657c | 18611:086093fbdc1a |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2014 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 | |
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: | |
47 bool _direct_shortcut; | |
48 | |
49 }; | |
50 | |
51 | |
52 class shortcut_manager : public QWidget | |
53 { | |
54 Q_OBJECT | |
55 | |
56 public: | |
57 shortcut_manager (); | |
58 ~shortcut_manager (); | |
59 | |
60 static void init_data () | |
61 { | |
62 if (instance_ok ()) | |
63 instance->do_init_data (); | |
64 } | |
65 | |
66 static void write_shortcuts () | |
67 { | |
68 if (instance_ok ()) | |
69 instance->do_write_shortcuts (); | |
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 public slots: | |
85 | |
86 signals: | |
87 | |
88 protected: | |
89 | |
90 protected slots: | |
91 | |
92 void handle_double_clicked (QTreeWidgetItem*, int); | |
93 void shortcut_dialog_finished (int); | |
94 void shortcut_dialog_set_default (); | |
95 | |
96 private: | |
97 | |
98 static shortcut_manager *instance; | |
99 static void cleanup_instance (void) { delete instance; instance = 0; } | |
100 | |
101 // No copying! | |
102 | |
103 shortcut_manager (const shortcut_manager&); | |
104 shortcut_manager& operator = (const shortcut_manager&); | |
105 | |
106 static bool instance_ok (void); | |
107 | |
108 void init (QString, QString, QKeySequence); | |
109 void do_init_data (); | |
110 void do_write_shortcuts (); | |
111 void do_set_shortcut (QAction *action, const QString& key); | |
112 void do_fill_treewidget (QTreeWidget *tree_view); | |
113 void shortcut_dialog (int); | |
114 | |
115 struct shortcut_t | |
116 { | |
117 QString description; | |
118 QString settings_key; | |
119 QKeySequence actual_sc; | |
120 QKeySequence default_sc; | |
121 QTreeWidgetItem *tree_item; | |
122 }; | |
123 | |
124 QList<shortcut_t> _sc; | |
125 QHash<QString, int> _shortcut_hash; | |
126 QHash<QString, int> _action_hash; | |
127 QHash <QString, QTreeWidgetItem*> _level_hash; | |
128 QHash<int, QTreeWidgetItem*> _index_item_hash; | |
129 QHash<QTreeWidgetItem*, int> _item_index_hash; | |
130 | |
131 QDialog *_dialog; | |
132 enter_shortcut *_edit_actual; | |
133 QLabel *_label_default; | |
134 int _handled_index; | |
135 | |
136 }; | |
137 | |
138 | |
139 #endif // SHORTCUT_MANAGER_H |