1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "qmljsicons.h"
34 #include <QtCore/QDebug>
35 #include <QtCore/QDir>
36 #include <QtCore/QHash>
37 #include <QtCore/QPair>
39 using namespace QmlJS;
40 using namespace QmlJS::AST;
48 Icons *Icons::m_instance = 0;
55 QIcon publicMemberIcon;
56 QIcon functionDeclarationIcon;
57 QHash<QPair<QString,QString>,QIcon> iconHash;
64 : m_d(new IconsPrivate)
66 m_d->elementIcon = QIcon(QLatin1String(":/qmljs/images/element.png"));
67 m_d->propertyIcon = QIcon(QLatin1String(":/qmljs/images/property.png"));
68 m_d->publicMemberIcon = QIcon(QLatin1String(":/qmljs/images/publicmember.png"));
69 m_d->functionDeclarationIcon = QIcon(QLatin1String(":/qmljs/images/func.png"));
78 Icons *Icons::instance()
81 m_instance = new Icons();
85 void Icons::setIconFilesPath(const QString &iconPath)
87 if (iconPath == m_d->resourcePath)
90 m_d->resourcePath = iconPath;
93 qDebug() << "QmlJSIcons -" << "parsing" << iconPath;
94 QDir topDir(iconPath);
95 foreach (const QFileInfo &subDirInfo, topDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
97 qDebug() << "QmlJSIcons - parsing" << subDirInfo.absoluteFilePath();
98 const QString packageName = subDirInfo.fileName();
99 QDir subDir(subDirInfo.absoluteFilePath() + QLatin1String("/16x16"));
100 foreach (const QFileInfo &iconFile, subDir.entryInfoList(QDir::Files)) {
101 QIcon icon(iconFile.absoluteFilePath());
104 qDebug() << "QmlJSIcons - skipping" << iconFile.absoluteFilePath();
108 qDebug() << "QmlJSIcons - adding" << packageName << iconFile.baseName() << "icon to database";
109 QPair<QString,QString> element(packageName, iconFile.baseName());
110 m_d->iconHash.insert(element, icon);
115 QIcon Icons::icon(const QString &packageName, const QString typeName) const
117 QPair<QString,QString> element(packageName, typeName);
119 qDebug() << "QmlJSIcons - icon for" << packageName << typeName << "requested" << m_d->iconHash.contains(element);
120 return m_d->iconHash.value(element);
123 QIcon Icons::icon(Node *node) const
125 if (dynamic_cast<AST::UiObjectDefinition*>(node)) {
126 return objectDefinitionIcon();
128 if (dynamic_cast<AST::UiScriptBinding*>(node)) {
129 return scriptBindingIcon();
135 QIcon Icons::objectDefinitionIcon() const
137 return m_d->elementIcon;
140 QIcon Icons::scriptBindingIcon() const
142 return m_d->propertyIcon;
145 QIcon Icons::publicMemberIcon() const
147 return m_d->publicMemberIcon;
150 QIcon Icons::functionDeclarationIcon() const
152 return m_d->functionDeclarationIcon;