dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
command_p.h
Go to the documentation of this file.
1 
13 /*
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.
18  *
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.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef COMMAND_P_H
29 #define COMMAND_P_H
30 
31 #include "command.h"
32 #include "actionmanager_p.h"
33 
34 #include <QtCore/QList>
35 #include <QtCore/QMultiMap>
36 #include <QtCore/QPointer>
37 #include <QKeySequence>
38 
39 namespace Core {
40 namespace Internal {
41 
43  {
44  Q_OBJECT
45  public:
46  CommandPrivate(int id);
47  virtual ~CommandPrivate() {}
48 
49  virtual QString name() const = 0;
50 
51  void setDefaultKeySequence(const QKeySequence &key);
52  QKeySequence defaultKeySequence() const;
53 
54  void setDefaultText(const QString &text);
55  QString defaultText() const;
56 
57  int id() const;
58 
59  QAction *action() const;
60  QShortcut *shortcut() const;
61 
62  void setAttribute(CommandAttribute attr);
64  bool hasAttribute(CommandAttribute attr) const;
65 
66  virtual bool setCurrentContext(const QList<int> &context) = 0;
67 
68  QString stringWithAppendedShortcut(const QString &str) const;
69 
70  protected:
71  QString m_category;
73  int m_id;
74  QKeySequence m_defaultKey;
75  QString m_defaultText;
76  };
77 
78  class Shortcut : public CommandPrivate
79  {
80  Q_OBJECT
81  public:
82  Shortcut(int id);
83 
84  QString name() const;
85 
86  void setDefaultKeySequence(const QKeySequence &key);
87  void setKeySequence(const QKeySequence &key);
88  QKeySequence keySequence() const;
89 
90  virtual void setDefaultText(const QString &key);
91  virtual QString defaultText() const;
92 
93  void setShortcut(QShortcut *shortcut);
94  QShortcut *shortcut() const;
95 
96  void setContext(const QList<int> &context);
97  QList<int> context() const;
98  bool setCurrentContext(const QList<int> &context);
99 
100  bool isActive() const;
101 
102  private:
103  QList<int> m_context;
104  QShortcut *m_shortcut;
105  QString m_defaultText;
106  };
107 
108  class Action : public CommandPrivate
109  {
110  Q_OBJECT
111  public:
112  Action(int id);
113 
114  QString name() const;
115 
116  void setDefaultKeySequence(const QKeySequence &key);
117  void setKeySequence(const QKeySequence &key);
118  QKeySequence keySequence() const;
119 
120  virtual void setAction(QAction *action);
121  QAction *action() const;
122 
125 
126  protected:
128 
129  QAction *m_action;
131  QString m_toolTip;
132  };
133 
134  class OverrideableAction : public Action
135  {
136  Q_OBJECT
137 
138  public:
139  OverrideableAction(int id);
140 
141  void setAction(QAction *action);
142  bool setCurrentContext(const QList<int> &context);
143  void addOverrideAction(QAction *action, const QList<int> &context);
144  bool isActive() const;
145 
146  private slots:
147  void actionChanged();
148 
149  private:
150  QPointer<QAction> m_currentAction;
151  QList<int> m_context;
152  QMap<int, QPointer<QAction>> m_contextActionMap;
153  bool m_active;
154  bool m_contextInitialized;
155  };
156 
157 } // namespace Internal
158 } // namespace Core
159 
160 #endif // COMMAND_P_H
void addOverrideAction(QAction *action, const QList< int > &context)
Definition: command.cpp:473
void setKeySequence(const QKeySequence &key)
Definition: command.cpp:304
QKeySequence keySequence() const
Definition: command.cpp:310
bool setCurrentContext(const QList< int > &context)
Definition: command.cpp:325
bool isActive() const
Definition: command.cpp:337
QKeySequence keySequence() const
Definition: command.cpp:408
QString name() const
Definition: command.cpp:269
void setAction(QAction *action)
Definition: command.cpp:428
virtual QString name() const =0
void setKeySequence(const QKeySequence &key)
Definition: command.cpp:393
void setContext(const QList< int > &context)
Definition: command.cpp:287
void setDefaultKeySequence(const QKeySequence &key)
Definition: command.cpp:386
bool setCurrentContext(const QList< int > &context)
Definition: command.cpp:433
QString stringWithAppendedShortcut(const QString &str) const
Definition: command.cpp:249
QList< CommandLocation > locations() const
Definition: command.cpp:381
void setLocations(const QList< CommandLocation > &locations)
Definition: command.cpp:376
virtual void setAction(QAction *action)
Definition: command.cpp:362
void updateToolTipWithKeySequence()
Definition: command.cpp:400
virtual void setDefaultText(const QString &key)
Definition: command.cpp:315
QList< int > context() const
Definition: command.cpp:292
QShortcut * shortcut() const
Definition: command.cpp:282
void setDefaultKeySequence(const QKeySequence &key)
Definition: command.cpp:297
virtual bool setCurrentContext(const QList< int > &context)=0
void setDefaultText(const QString &text)
Definition: command.cpp:209
virtual QString defaultText() const
Definition: command.cpp:320
QKeySequence defaultKeySequence() const
Definition: command.cpp:204
bool hasAttribute(CommandAttribute attr) const
Definition: command.cpp:244
QAction * action() const
Definition: command.cpp:224
void setAttribute(CommandAttribute attr)
Definition: command.cpp:234
QString defaultText() const
Definition: command.cpp:214
QAction * action() const
Definition: command.cpp:371
QString name() const
Definition: command.cpp:354
void setDefaultKeySequence(const QKeySequence &key)
Definition: command.cpp:199
void removeAttribute(CommandAttribute attr)
Definition: command.cpp:239
QList< CommandLocation > m_locations
Definition: command_p.h:130
The class Command represents an action like a menu item, tool button, or shortcut. You don't create Command objects directly, instead use {ActionManager::registerAction()} to register an action and retrieve a Command. The Command object represents the user visible action and its properties. If multiple actions are registered with the same ID (but different contexts) the returned Command is the shared one between these actions.
Definition: command.h:43
void setShortcut(QShortcut *shortcut)
Definition: command.cpp:277
QShortcut * shortcut() const
Definition: command.cpp:229