LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / actionmanager / command_p.h
blob01fd68e37a6a49de89f574c9704289db33bc3451
1 /**
2 ******************************************************************************
4 * @file command_p.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef COMMAND_P_H
30 #define COMMAND_P_H
32 #include "command.h"
33 #include "actionmanager_p.h"
35 #include <QtCore/QList>
36 #include <QtCore/QMultiMap>
37 #include <QtCore/QPointer>
38 #include <QKeySequence>
40 namespace Core {
41 namespace Internal {
42 class CommandPrivate : public Core::Command {
43 Q_OBJECT
44 public:
45 CommandPrivate(int id);
46 virtual ~CommandPrivate() {}
48 virtual QString name() const = 0;
50 void setDefaultKeySequence(const QKeySequence &key);
51 QKeySequence defaultKeySequence() const;
53 void setDefaultText(const QString &text);
54 QString defaultText() const;
56 int id() const;
58 QAction *action() const;
59 QShortcut *shortcut() const;
61 void setAttribute(CommandAttribute attr);
62 void removeAttribute(CommandAttribute attr);
63 bool hasAttribute(CommandAttribute attr) const;
65 virtual bool setCurrentContext(const QList<int> &context) = 0;
67 QString stringWithAppendedShortcut(const QString &str) const;
69 protected:
70 QString m_category;
71 int m_attributes;
72 int m_id;
73 QKeySequence m_defaultKey;
74 QString m_defaultText;
77 class Shortcut : public CommandPrivate {
78 Q_OBJECT
79 public:
80 Shortcut(int id);
82 QString name() const;
84 void setDefaultKeySequence(const QKeySequence &key);
85 void setKeySequence(const QKeySequence &key);
86 QKeySequence keySequence() const;
88 virtual void setDefaultText(const QString &key);
89 virtual QString defaultText() const;
91 void setShortcut(QShortcut *shortcut);
92 QShortcut *shortcut() const;
94 void setContext(const QList<int> &context);
95 QList<int> context() const;
96 bool setCurrentContext(const QList<int> &context);
98 bool isActive() const;
99 private:
100 QList<int> m_context;
101 QShortcut *m_shortcut;
102 QString m_defaultText;
105 class Action : public CommandPrivate {
106 Q_OBJECT
107 public:
108 Action(int id);
110 QString name() const;
112 void setDefaultKeySequence(const QKeySequence &key);
113 void setKeySequence(const QKeySequence &key);
114 QKeySequence keySequence() const;
116 virtual void setAction(QAction *action);
117 QAction *action() const;
119 void setLocations(const QList<CommandLocation> &locations);
120 QList<CommandLocation> locations() const;
122 protected:
123 void updateToolTipWithKeySequence();
125 QAction *m_action;
126 QList<CommandLocation> m_locations;
127 QString m_toolTip;
130 class OverrideableAction : public Action {
131 Q_OBJECT
133 public:
134 OverrideableAction(int id);
136 void setAction(QAction *action);
137 bool setCurrentContext(const QList<int> &context);
138 void addOverrideAction(QAction *action, const QList<int> &context);
139 bool isActive() const;
141 private slots:
142 void actionChanged();
144 private:
145 QPointer<QAction> m_currentAction;
146 QList<int> m_context;
147 QMap<int, QPointer<QAction> > m_contextActionMap;
148 bool m_active;
149 bool m_contextInitialized;
151 } // namespace Internal
152 } // namespace Core
154 #endif // COMMAND_P_H