Stellarium 0.12.4
StelShortcutMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2012 Anton Samoylov
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef STELSHORTCUTMGR_HPP
21 #define STELSHORTCUTMGR_HPP
22 
23 #include <QObject>
24 #include <QAction>
25 
26 class StelShortcutGroup;
27 class StelShortcut;
29 
34 class StelShortcutMgr : public QObject
35 {
36  Q_OBJECT
37 public:
39 
40  void init();
41 
46  bool loadShortcuts(const QString& filePath, bool overload = false);
48  void loadShortcuts();
49 
51  void saveShortcuts();
52 
53  void saveShortcuts(QIODevice* output) const;
54 
62  QAction* addGuiAction(const QString& actionId,
63  bool temporary,
64  const QString& text,
65  const QString& primaryKey,
66  const QString& altKey,
67  const QString &groupId,
68  bool checkable = true,
69  bool autoRepeat = false,
70  bool global = false);
71 
72  void changeActionPrimaryKey(const QString& actionId, const QString& groupId, QKeySequence newKey);
73  void changeActionAltKey(const QString& actionId, const QString& groupId, QKeySequence newKey);
74  void setShortcutText(const QString& actionId,
75  const QString& groupId,
76  const QString& description);
77 
83  QAction* getGuiAction(const QString& actionName);
84 
85 #ifndef DISABLE_SCRIPTING
86 
87  QAction* addScriptToAction(const QString& actionId, const QString& script, const QString& scriptAction = QString());
88 #endif
89 
91  QList<StelShortcutGroup*> getGroupList() const;
92 
93 signals:
94  void shortcutChanged(StelShortcut* shortcut);
95 
96 public slots:
100  void setAllActionsEnabled(bool enable);
101 
104 
105 private:
108  bool copyDefaultFile();
109 
113  QAction* getAction(const QString& groupId, const QString& actionId);
117  StelShortcut* getShortcut(const QString& groupId, const QString& shId);
125  void addGroup(const QString& id,
126  QString text,
127  const QString& pluginId = QString());
128 
130  StelAppGraphicsWidget* stelAppGraphicsWidget;
132  QMap<QString, StelShortcutGroup*> shGroups;
133 };
134 
135 #endif // STELSHORTCUTMGR_HPP