OSDN Git Service

406273e71179ef9a49eade74e12d49903699f522
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / actionmanager / command_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef COMMAND_P_H
35 #define COMMAND_P_H
36
37 #include "command.h"
38
39 #include <utils/proxyaction.h>
40 #include <coreplugin/icontext.h>
41
42 #include <QtCore/QList>
43 #include <QtCore/QMultiMap>
44 #include <QtCore/QPointer>
45 #include <QtCore/QMap>
46 #include <QtGui/QKeySequence>
47
48 namespace Core {
49 namespace Internal {
50
51 class CommandPrivate : public Core::Command
52 {
53     Q_OBJECT
54 public:
55     CommandPrivate(int id);
56     virtual ~CommandPrivate() {}
57
58     void setDefaultKeySequence(const QKeySequence &key);
59     QKeySequence defaultKeySequence() const;
60
61     void setKeySequence(const QKeySequence &key);
62
63     void setDefaultText(const QString &text);
64     QString defaultText() const;
65
66     int id() const;
67
68     QAction *action() const;
69     QShortcut *shortcut() const;
70     Context context() const;
71
72
73     void setAttribute(CommandAttribute attr);
74     void removeAttribute(CommandAttribute attr);
75     bool hasAttribute(CommandAttribute attr) const;
76
77     virtual void setCurrentContext(const Context &context) = 0;
78
79     QString stringWithAppendedShortcut(const QString &str) const;
80
81 protected:
82     Context m_context;
83     CommandAttributes m_attributes;
84     int m_id;
85     QKeySequence m_defaultKey;
86     QString m_defaultText;
87     bool m_isKeyInitialized;
88 };
89
90 class Shortcut : public CommandPrivate
91 {
92     Q_OBJECT
93 public:
94     Shortcut(int id);
95
96     void setKeySequence(const QKeySequence &key);
97     QKeySequence keySequence() const;
98
99     virtual void setDefaultText(const QString &key);
100     virtual QString defaultText() const;
101
102     void setShortcut(QShortcut *shortcut);
103     QShortcut *shortcut() const;
104
105     void setContext(const Context &context);
106     Context context() const;
107     void setCurrentContext(const Context &context);
108
109     bool isActive() const;
110
111     bool isScriptable() const;
112     bool isScriptable(const Context &) const;
113     void setScriptable(bool value);
114
115 private:
116     QShortcut *m_shortcut;
117     QString m_defaultText;
118     bool m_scriptable;
119 };
120
121 class Action : public CommandPrivate
122 {
123     Q_OBJECT
124 public:
125     Action(int id);
126
127     void setKeySequence(const QKeySequence &key);
128     QKeySequence keySequence() const;
129
130     QAction *action() const;
131
132     void setCurrentContext(const Context &context);
133     bool isActive() const;
134     void addOverrideAction(QAction *action, const Context &context, bool scriptable);
135     void removeOverrideAction(QAction *action);
136     bool isEmpty() const;
137
138     bool isScriptable() const;
139     bool isScriptable(const Context &context) const;
140
141     void setAttribute(CommandAttribute attr);
142     void removeAttribute(CommandAttribute attr);
143
144 private slots:
145     void updateActiveState();
146
147 private:
148     void setActive(bool state);
149
150     Utils::ProxyAction *m_action;
151     QString m_toolTip;
152
153     QMap<int, QPointer<QAction> > m_contextActionMap;
154     QMap<QAction*, bool> m_scriptableMap;
155     bool m_active;
156     bool m_contextInitialized;
157 };
158
159 } // namespace Internal
160 } // namespace Core
161
162 #endif // COMMAND_P_H