Commit c5f32b9e authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.itemLibrary: The item library now also provides small icons

The item library now also provides small icons for the navigator.
parent ac4afcaa
......@@ -180,28 +180,22 @@ void NameItemDelegate::paint(QPainter *painter,
ModelNode node = m_TreeModel->nodeForIndex(index);
QIcon icon;
if (node.metaInfo().isValid()) {
icon=node.metaInfo().icon();
if (icon.isNull())
{
// if node has no own icon, search for it in the itemlibrary
const NodeMetaInfo typeInfo = node.metaInfo();
const ItemLibraryInfo *libraryInfo = node.metaInfo().metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> infoList = libraryInfo->entriesForType(typeInfo.typeName(),
typeInfo.majorVersion(),
typeInfo.minorVersion());
foreach (const ItemLibraryEntry &entry, infoList) {
if (!icon.isNull()) {
icon = entry.icon();
break;
}
if (node.isValid()) {
// if node has no own icon, search for it in the itemlibrary
const ItemLibraryInfo *libraryInfo = node.model()->metaInfo().itemLibraryInfo();
QList <ItemLibraryEntry> infoList = libraryInfo->entriesForType(node.type(),
node.majorVersion(),
node.minorVersion());
foreach (const ItemLibraryEntry &entry, infoList) {
if (icon.isNull()) {
icon = entry.icon();
break;
}
}
}
// if the library was also empty, use the default icon
if (icon.isNull())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
// if the library was also empty, use the default icon
if (icon.isNull())
icon = QIcon(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
// If no icon is present, leave an empty space of 24 pixels anyway
QPixmap pixmap = icon.pixmap(pixmapSide, pixmapSide);
......
......@@ -41,7 +41,7 @@ namespace Internal {
class ItemLibraryEntryData;
class ItemLibraryInfoPrivate;
class MetaInfoPrivate;
}
class ItemLibraryEntry;
......@@ -82,6 +82,7 @@ public:
void addProperty(const Property &p);
void addProperty(QString &name, QString &type, QString &value);
void setDragIcon(const QIcon &icon);
void setIcon(const QIcon &icon);
void setCategory(const QString &category);
void setQml(const QString &qml);
private:
......
......@@ -38,8 +38,6 @@
namespace QmlDesigner {
class NodeMetaInfo;
class EnumeratorMetaInfo;
class ItemLibraryEntry;
namespace Internal {
......@@ -58,7 +56,7 @@ protected:
void metaInfoHandler(QXmlStreamReader &reader);
void handleMetaInfoElement(QXmlStreamReader &reader);
void handleNodeElement(QXmlStreamReader &reader);
void handleNodeItemLibraryEntryElement(QXmlStreamReader &reader, const QString &className);
void handleNodeItemLibraryEntryElement(QXmlStreamReader &reader, const QString &className, const QIcon &icon);
void handleItemLibraryEntryPropertyElement(QXmlStreamReader &reader, ItemLibraryEntry &itemLibraryEntry);
private:
......
......@@ -85,6 +85,11 @@ void ItemLibraryEntry::setDragIcon(const QIcon &icon)
m_data->dragIcon = icon;
}
void ItemLibraryEntry::setIcon(const QIcon &icon)
{
m_data->icon = icon;
}
QIcon ItemLibraryEntry::dragIcon() const
{
return m_data->dragIcon;
......
......@@ -100,6 +100,8 @@ void MetaInfoParser::handleNodeElement(QXmlStreamReader &reader)
const QXmlStreamAttributes attributes = reader.attributes();
const QString className = attributes.value("name").toString();
const QIcon icon = QIcon(attributes.value("icon").toString());
if (className.isEmpty()) {
reader.raiseError("Invalid element 'node' - mandatory attribute 'name' is missing");
return;
......@@ -108,11 +110,11 @@ void MetaInfoParser::handleNodeElement(QXmlStreamReader &reader)
while (!reader.atEnd() && !(reader.isEndElement() && reader.name() == "node")) {
reader.readNext();
handleNodeItemLibraryEntryElement(reader, className);
handleNodeItemLibraryEntryElement(reader, className, icon);
}
}
void MetaInfoParser::handleNodeItemLibraryEntryElement(QXmlStreamReader &reader, const QString &className)
void MetaInfoParser::handleNodeItemLibraryEntryElement(QXmlStreamReader &reader, const QString &className, const QIcon &icon)
{
if (reader.isStartElement() && reader.name() == "itemlibraryentry")
{
......@@ -121,8 +123,9 @@ void MetaInfoParser::handleNodeItemLibraryEntryElement(QXmlStreamReader &reader,
ItemLibraryEntry entry;
entry.setType(className, 4, 7);
entry.setName(name);
entry.setIcon(icon);
QString iconPath = reader.attributes().value("icon").toString();
QString iconPath = reader.attributes().value("libraryIcon").toString();
if (!iconPath.isEmpty())
entry.setIconPath(iconPath);
......
<metainfo>
<node name="Qt/Item" icon=":/qtquickplugin/images/item-icon16.png">
<itemlibraryentry name="Item" category="Qt - Basic" icon=":/qtquickplugin/images/item-icon.png">
<itemlibraryentry name="Item" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/item-icon.png">
<property name="width" type="int" value="200"/>
<property name="height" type="int" value="200"/>
</itemlibraryentry>
</node>
<node name="Qt/Rectangle" category="Qt - Basic" isContainer="true" icon=":/qtquickplugin/images/rect-icon16.png">
<itemlibraryentry name="Rectangle" category="Qt - Basic" icon=":/qtquickplugin/images/rect-icon.png">
<node name="Qt/Rectangle" icon=":/qtquickplugin/images/rect-icon16.png">
<itemlibraryentry name="Rectangle" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/rect-icon.png">
<property name="color" type="QColor" value="#ffffff"/>
</itemlibraryentry>
</node>
<node name="Qt/Text" icon=":/qtquickplugin/images/text-icon16.png">
<itemlibraryentry name="Text" category="Qt - Basic" icon=":/qtquickplugin/images/text-icon.png">
<itemlibraryentry name="Text" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/text-icon.png">
<property name="width" type="int" value="80"/>
<property name="height" type="int" value="20"/>
<property name="text" type="QString" value="text"/>
......@@ -19,7 +19,7 @@
</itemlibraryentry>
</node>
<node name="Qt/TextEdit" icon=":/qtquickplugin/images/text-edit-icon16.png">
<itemlibraryentry name="Text Edit" category="Qt - Basic" icon=":/qtquickplugin/images/text-edit-icon.png">
<itemlibraryentry name="Text Edit" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/text-edit-icon.png">
<property name="width" type="int" value="80"/>
<property name="height" type="int" value="20"/>
<property name="text" type="QString" value="textEdit"/>
......@@ -27,7 +27,7 @@
</itemlibraryentry>
</node>
<node name="Qt/TextInput" icon=":/qtquickplugin/images/text-input-icon16.png">
<itemlibraryentry name="Text Input" category="Qt - Basic" icon=":/qtquickplugin/images/text-input-icon.png">
<itemlibraryentry name="Text Input" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/text-input-licon.png">
<property name="width" type="int" value="80"/>
<property name="height" type="int" value="20"/>
<property name="text" type="QString" value="textInput"/>
......@@ -35,67 +35,67 @@
</itemlibraryentry>
</node>
<node name="Qt/MouseArea" icon=":/qtquickplugin/images/mouse-area-icon16.png">
<itemlibraryentry name="Mouse Area" category="Qt - Interaction" icon=":/qtquickplugin/images/mouse-area-icon.png">
<itemlibraryentry name="Mouse Area" category="Qt - Interaction" libraryIcon=":/qtquickplugin/images/mouse-area-icon.png">
<property name="width" type="int" value="100"/>
<property name="height" type="int" value="100"/>
</itemlibraryentry>
</node>
<node name="Qt/Image" isContainer="true" icon=":/qtquickplugin/images/image-icon16.png">
<itemlibraryentry name="Image" category="Qt - Basic" icon=":/qtquickplugin/images/image-icon.png">
<node name="Qt/Image" icon=":/qtquickplugin/images/image-icon16.png">
<itemlibraryentry name="Image" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/image-icon.png">
<property name="width" type="int" value="100"/>
<property name="height" type="int" value="100"/>
<property name="source" type="QUrl" value="qrc:/qtquickplugin/images/template_image.png"/>
</itemlibraryentry>
</node>
<node name="Qt/BorderImage" icon=":/qtquickplugin/images/border-image-icon16.png">
<itemlibraryentry name="Border Image" category="Qt - Basic" icon=":/qtquickplugin/images/border-image-icon.png">
<itemlibraryentry name="Border Image" category="Qt - Basic" libraryIcon=":/qtquickplugin/images/border-image-icon.png">
<property name="width" type="int" value="100"/>
<property name="height" type="int" value="100"/>
<property name="source" type="QUrl" value="qrc:/qtquickplugin/images/template_image.png"/>
</itemlibraryentry>
</node>
<node name="Qt/Flickable" icon=":/qtquickplugin/images/flickable-icon16.png">
<itemlibraryentry name="Flickable" category="Qt - Widgets" icon=":/qtquickplugin/images/flickable-icon.png">
<itemlibraryentry name="Flickable" category="Qt - Widgets" libraryIcon=":/qtquickplugin/images/flickable-icon.png">
<property name="width" type="int" value="300"/>
<property name="height" type="int" value="300"/>
</itemlibraryentry>
</node>
<node name="Qt/Flipable" icon=":/qtquickplugin/images/flipable-icon16.png">
<itemlibraryentry name="Flipable" category="Qt - Widgets" icon=":/qtquickplugin/images/flipable-icon.png">
<itemlibraryentry name="Flipable" category="Qt - Widgets" libraryIcon=":/qtquickplugin/images/flipable-icon.png">
<property name="width" type="int" value="300"/>
<property name="height" type="int" value="300"/>
</itemlibraryentry>
</node>
<node name="Qt/GridView" icon=":/qtquickplugin/images/gridview-icon16.png">
<itemlibraryentry name="Grid View" category="Qt - Views" icon=":/qtquickplugin/images/gridview-icon.png">
<itemlibraryentry name="Grid View" category="Qt - Views" libraryIcon=":/qtquickplugin/images/gridview-icon.png">
<property name="width" type="int" value="300"/>
<property name="height" type="int" value="300"/>
</itemlibraryentry>
</node>
<node name="Qt/ListView" icon=":/qtquickplugin/images/listview-icon16.png">
<itemlibraryentry name="List View" category="Qt - Views" icon=":/qtquickplugin/images/listview-icon.png">
<itemlibraryentry name="List View" category="Qt - Views" libraryIcon=":/qtquickplugin/images/listview-icon.png">
<property name="width" type="int" value="300"/>
<property name="height" type="int" value="300"/>
</itemlibraryentry>
</node>
<node name="Qt/PathView" icon=":/qtquickplugin/images/pathview-icon16.png">
<itemlibraryentry name="Path View" category="Qt - Views" icon=":/qtquickplugin/images/pathview-icon.png">
<itemlibraryentry name="Path View" category="Qt - Views" libraryIcon=":/qtquickplugin/images/pathview-icon.png">
<property name="width" type="int" value="300"/>
<property name="height" type="int" value="300"/>
</itemlibraryentry>
</node>
<node name="Qt/FocusScope" icon=":/qtquickplugin/images/focusscope-icon16.png">
<itemlibraryentry name="Focus Scope" category="Qt - Interaction" icon=":/qtquickplugin/images/focusscope-icon.png">
<itemlibraryentry name="Focus Scope" category="Qt - Interaction" libraryIcon=":/qtquickplugin/images/focusscope-icon.png">
<property name="width" type="int" value="100"/>
<property name="height" type="int" value="100"/>
</itemlibraryentry>
</node>
<node name="QtWebKit/WebView" icon=":/qtquickplugin/images/webview-icon16.png">
<itemlibraryentry name="Web View" category="Qt - Widgets" icon=":/qtquickplugin/images/webview-icon.png">
<itemlibraryentry name="Web View" category="Qt - Widgets" libraryIcon=":/qtquickplugin/images/webview-icon.png">
<property name="width" type="int" value="300"/>
<property name="height" type="int" value="300"/>
<property name="url" type="QString" value="http://qt.nokia.com"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment