Stellarium 0.12.3
StelShortcutGroup.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 STELSHORTCUT_HPP
21 #define STELSHORTCUT_HPP
22 
23 #include <QObject>
24 #include <QMap>
25 #include <QAction>
26 
27 QT_FORWARD_DECLARE_CLASS(StelShortcutGroup)
28 
29 class StelShortcut : public QObject
30 {
31  Q_OBJECT
32 public:
33  StelShortcut(const QString& id, StelShortcutGroup* group, const QString& text,
34  const QString& primaryKey, const QString& altKey,
35  bool checkable, bool autoRepeat = true, bool global = false, QGraphicsWidget *parent = NULL);
36 
37  ~StelShortcut();
38 
39  QAction* getAction() const { return m_action; }
40  StelShortcutGroup* getGroup() const { return m_group; }
41 
42  QString getId() const { return m_id; }
43  QString getText() const { return m_text; }
44  QKeySequence getPrimaryKey() const { return m_primaryKey; }
45  QKeySequence getAltKey() const { return m_altKey; }
46  bool isTemporary() const { return m_temporary; }
47 
48  QVariant toQVariant() const;
49 
50  void setText(const QString& text);
51  void setPrimaryKey(const QKeySequence& key);
52  void setAltKey(const QKeySequence& key);
53  void setCheckable(bool c);
54  void setAutoRepeat(bool ar);
55  void setGlobal(bool g);
56  void setTemporary(bool temp);
57 #ifndef DISABLE_SCRIPTING
58  void setScript(const QString& scriptText);
59  void setScriptPath(const QString& scriptPath);
60 #endif
61 
62 signals:
63  void shortcutChanged(StelShortcut* shortcut);
64 
65 #ifndef DISABLE_SCRIPTING
66 public slots:
67  void runScript() const;
68 #endif
69 
70 protected slots:
71  void updateActionShortcuts();
72 
73 private:
74  QAction* m_action;
75  StelShortcutGroup* m_group;
76 
77  QString m_id;
78  QString m_text;
79  QKeySequence m_primaryKey;
80  QKeySequence m_altKey;
81  bool m_checkable;
82  bool m_autoRepeat;
83  bool m_global;
84  // defines whether shortcut exists only in current session
85  bool m_temporary;
86  QString m_script;
87  QString m_scriptFile;
88 };
89 
90 
91 
92 class StelShortcutGroup : public QObject
93 {
94  Q_OBJECT
95 public:
96  StelShortcutGroup(QString id, QString text = "");
97 
98  ~StelShortcutGroup();
99 
100  QAction* registerAction(const QString& actionId, bool temporary, const QString& text, const QString& primaryKey,
101  const QString& altKey, bool checkable, bool autoRepeat = true,
102  bool global = false, QGraphicsWidget *parent = 0);
103 
104  QAction* getAction(const QString &actionId);
105  StelShortcut* getShortcut(const QString& id);
106  QList<StelShortcut*> getActionList() const;
107 
108  QString getId() const { return m_id; }
109  QString getText() const { return m_text; }
110  QString getPluginId() const {return m_pluginId; }
111  bool isEnabled() const { return m_enabled; }
112 
113  QVariant toQVariant() const;
114 
115 signals:
116  void shortcutChanged(StelShortcut* shortcut);
117 
118 public slots:
119  // enable/disable all actions of the group
120  // need for editing shortcuts without trigging any actions
121  void setEnabled(bool enable);
122  void setPluginId(const QString& pluginId);
123  // clear and delete all shortuts
124 
125 private:
126  QString m_id;
127  QString m_text;
128  QString m_pluginId;
129  bool m_enabled;
130  QMap<QString, StelShortcut*> m_shortcuts;
131 };
132 
133 #endif // STELSHORTCUT_HPP