1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
39 #include <utils/proxyaction.h>
40 #include <coreplugin/icontext.h>
42 #include <QtCore/QList>
43 #include <QtCore/QMultiMap>
44 #include <QtCore/QPointer>
45 #include <QtCore/QMap>
46 #include <QtGui/QKeySequence>
51 class CommandPrivate : public Core::Command
55 CommandPrivate(int id);
56 virtual ~CommandPrivate() {}
58 void setDefaultKeySequence(const QKeySequence &key);
59 QKeySequence defaultKeySequence() const;
61 void setKeySequence(const QKeySequence &key);
63 void setDefaultText(const QString &text);
64 QString defaultText() const;
68 QAction *action() const;
69 QShortcut *shortcut() const;
70 Context context() const;
73 void setAttribute(CommandAttribute attr);
74 void removeAttribute(CommandAttribute attr);
75 bool hasAttribute(CommandAttribute attr) const;
77 virtual void setCurrentContext(const Context &context) = 0;
79 QString stringWithAppendedShortcut(const QString &str) const;
83 CommandAttributes m_attributes;
85 QKeySequence m_defaultKey;
86 QString m_defaultText;
87 bool m_isKeyInitialized;
90 class Shortcut : public CommandPrivate
96 void setKeySequence(const QKeySequence &key);
97 QKeySequence keySequence() const;
99 virtual void setDefaultText(const QString &key);
100 virtual QString defaultText() const;
102 void setShortcut(QShortcut *shortcut);
103 QShortcut *shortcut() const;
105 void setContext(const Context &context);
106 Context context() const;
107 void setCurrentContext(const Context &context);
109 bool isActive() const;
111 bool isScriptable() const;
112 bool isScriptable(const Context &) const;
113 void setScriptable(bool value);
116 QShortcut *m_shortcut;
117 QString m_defaultText;
121 class Action : public CommandPrivate
127 void setKeySequence(const QKeySequence &key);
128 QKeySequence keySequence() const;
130 QAction *action() const;
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;
138 bool isScriptable() const;
139 bool isScriptable(const Context &context) const;
141 void setAttribute(CommandAttribute attr);
142 void removeAttribute(CommandAttribute attr);
145 void updateActiveState();
148 void setActive(bool state);
150 Utils::ProxyAction *m_action;
153 QMap<int, QPointer<QAction> > m_contextActionMap;
154 QMap<QAction*, bool> m_scriptableMap;
156 bool m_contextInitialized;
159 } // namespace Internal
162 #endif // COMMAND_P_H