OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / libs / cplusplus / Icons.cpp
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 #include "Icons.h"
35
36 #include <FullySpecifiedType.h>
37 #include <Scope.h>
38 #include <Symbols.h>
39 #include <Type.h>
40
41 using namespace CPlusPlus;
42 using CPlusPlus::Icons;
43
44 Icons::Icons()
45     : _classIcon(QLatin1String(":/codemodel/images/class.png")),
46       _enumIcon(QLatin1String(":/codemodel/images/enum.png")),
47       _enumeratorIcon(QLatin1String(":/codemodel/images/enumerator.png")),
48       _funcPublicIcon(QLatin1String(":/codemodel/images/func.png")),
49       _funcProtectedIcon(QLatin1String(":/codemodel/images/func_prot.png")),
50       _funcPrivateIcon(QLatin1String(":/codemodel/images/func_priv.png")),
51       _namespaceIcon(QLatin1String(":/codemodel/images/namespace.png")),
52       _varPublicIcon(QLatin1String(":/codemodel/images/var.png")),
53       _varProtectedIcon(QLatin1String(":/codemodel/images/var_prot.png")),
54       _varPrivateIcon(QLatin1String(":/codemodel/images/var_priv.png")),
55       _signalIcon(QLatin1String(":/codemodel/images/signal.png")),
56       _slotPublicIcon(QLatin1String(":/codemodel/images/slot.png")),
57       _slotProtectedIcon(QLatin1String(":/codemodel/images/slot_prot.png")),
58       _slotPrivateIcon(QLatin1String(":/codemodel/images/slot_priv.png")),
59       _keywordIcon(QLatin1String(":/codemodel/images/keyword.png")),
60       _macroIcon(QLatin1String(":/codemodel/images/macro.png"))
61 {
62 }
63
64 QIcon Icons::iconForSymbol(const Symbol *symbol) const
65 {
66     return iconForType(iconTypeForSymbol(symbol));
67 }
68
69 QIcon Icons::keywordIcon() const
70 {
71     return _keywordIcon;
72 }
73
74 QIcon Icons::macroIcon() const
75 {
76     return _macroIcon;
77 }
78
79 Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol)
80 {
81     if (const Template *templ = symbol->asTemplate()) {
82         if (Symbol *decl = templ->declaration())
83             return iconTypeForSymbol(decl);
84     }
85
86     FullySpecifiedType symbolType = symbol->type();
87     if (symbol->isFunction() || (symbol->isDeclaration() && symbolType &&
88                                  symbolType->isFunctionType()))
89     {
90         const Function *function = symbol->asFunction();
91         if (!function)
92             function = symbol->type()->asFunctionType();
93
94         if (function->isSlot()) {
95             if (function->isPublic()) {
96                 return SlotPublicIconType;
97             } else if (function->isProtected()) {
98                 return SlotProtectedIconType;
99             } else if (function->isPrivate()) {
100                 return SlotPrivateIconType;
101             }
102         } else if (function->isSignal()) {
103             return SignalIconType;
104         } else if (symbol->isPublic()) {
105             return FuncPublicIconType;
106         } else if (symbol->isProtected()) {
107             return FuncProtectedIconType;
108         } else if (symbol->isPrivate()) {
109             return FuncPrivateIconType;
110         }
111     } else if (symbol->enclosingScope() && symbol->enclosingScope()->isEnum()) {
112         return EnumeratorIconType;
113     } else if (symbol->isDeclaration() || symbol->isArgument()) {
114         if (symbol->isPublic()) {
115             return VarPublicIconType;
116         } else if (symbol->isProtected()) {
117             return VarProtectedIconType;
118         } else if (symbol->isPrivate()) {
119             return VarPrivateIconType;
120         }
121     } else if (symbol->isEnum()) {
122         return EnumIconType;
123     } else if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
124         return ClassIconType;
125     } else if (symbol->isObjCClass() || symbol->isObjCForwardClassDeclaration()) {
126         return ClassIconType;
127     } else if (symbol->isObjCProtocol() || symbol->isObjCForwardProtocolDeclaration()) {
128         return ClassIconType;
129     } else if (symbol->isObjCMethod()) {
130         return FuncPublicIconType;
131     } else if (symbol->isNamespace()) {
132         return NamespaceIconType;
133     } else if (symbol->isUsingNamespaceDirective() ||
134                symbol->isUsingDeclaration()) {
135         // TODO: Might be nice to have a different icons for these things
136         return NamespaceIconType;
137     }
138
139     return UnknownIconType;
140 }
141
142 QIcon Icons::iconForType(IconType type) const
143 {
144     switch(type) {
145     case ClassIconType:
146         return _classIcon;
147     case EnumIconType:
148         return _enumIcon;
149     case EnumeratorIconType:
150         return _enumeratorIcon;
151     case FuncPublicIconType:
152         return _funcPublicIcon;
153     case FuncProtectedIconType:
154         return _funcProtectedIcon;
155     case FuncPrivateIconType:
156         return _funcPrivateIcon;
157     case NamespaceIconType:
158         return _namespaceIcon;
159     case VarPublicIconType:
160         return _varPublicIcon;
161     case VarProtectedIconType:
162         return _varProtectedIcon;
163     case VarPrivateIconType:
164         return _varPrivateIcon;
165     case SignalIconType:
166         return _signalIcon;
167     case SlotPublicIconType:
168         return _slotPublicIcon;
169     case SlotProtectedIconType:
170         return _slotProtectedIcon;
171     case SlotPrivateIconType:
172         return _slotPrivateIcon;
173     case KeywordIconType:
174         return _keywordIcon;
175     case MacroIconType:
176         return _macroIcon;
177     default:
178         break;
179     }
180     return QIcon();
181 }