2010-01-07 12:14:35 +01:00
|
|
|
#include "itemlibrarymodel.h"
|
2010-02-16 17:24:18 +02:00
|
|
|
#include "metainfo.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QMimeData>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <QPainter>
|
2010-02-16 17:24:18 +02:00
|
|
|
#include <QPen>
|
|
|
|
|
#include <qdebug.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
template <class T>
|
|
|
|
|
ItemLibrarySortedModel<T>::ItemLibrarySortedModel(QObject *parent) :
|
|
|
|
|
QmlListModel(parent)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
ItemLibrarySortedModel<T>::~ItemLibrarySortedModel()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
clearElements();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
template <class T>
|
|
|
|
|
void ItemLibrarySortedModel<T>::clearElements()
|
|
|
|
|
{
|
|
|
|
|
while (m_elementOrder.count() > 0)
|
|
|
|
|
removeElement(m_elementOrder.at(0).libId);
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
template <class T>
|
|
|
|
|
void ItemLibrarySortedModel<T>::addElement(T *element, int libId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
struct order_struct orderEntry;
|
|
|
|
|
orderEntry.libId = libId;
|
|
|
|
|
orderEntry.visible = false;
|
|
|
|
|
|
|
|
|
|
int pos = 0;
|
|
|
|
|
while ((pos < m_elementOrder.count()) &&
|
|
|
|
|
(*(m_elementModels.value(m_elementOrder.at(pos).libId)) < *element))
|
|
|
|
|
++pos;
|
|
|
|
|
|
|
|
|
|
m_elementModels.insert(libId, element);
|
|
|
|
|
m_elementOrder.insert(pos, orderEntry);
|
|
|
|
|
|
|
|
|
|
setElementVisible(libId, true);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
template <class T>
|
|
|
|
|
void ItemLibrarySortedModel<T>::removeElement(int libId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
T *element = m_elementModels.value(libId);
|
|
|
|
|
int pos = findElement(libId);
|
|
|
|
|
struct order_struct orderEntry = m_elementOrder.at(pos);
|
|
|
|
|
|
|
|
|
|
setElementVisible(libId, false);
|
|
|
|
|
|
|
|
|
|
m_elementModels.remove(libId);
|
|
|
|
|
m_elementOrder.removeAt(pos);
|
|
|
|
|
|
|
|
|
|
delete element;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
bool ItemLibrarySortedModel<T>::elementVisible(int libId) const
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
int pos = findElement(libId);
|
|
|
|
|
return m_elementOrder.at(pos).visible;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
template <class T>
|
|
|
|
|
void ItemLibrarySortedModel<T>::setElementVisible(int libId, bool visible)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
int pos = findElement(libId),
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
|
|
if (m_elementOrder.at(pos).visible == visible)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; (i + offset) < pos;) {
|
|
|
|
|
if (m_elementOrder.at(i + offset).visible)
|
|
|
|
|
++i;
|
|
|
|
|
else
|
|
|
|
|
++offset;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
if (visible)
|
|
|
|
|
insert(pos - offset, *(m_elementModels.value(libId)));
|
|
|
|
|
else
|
|
|
|
|
remove(pos - offset);
|
|
|
|
|
|
|
|
|
|
m_elementOrder[pos].visible = visible;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
template <class T>
|
|
|
|
|
const QMap<int, T *> &ItemLibrarySortedModel<T>::elements() const
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
return m_elementModels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
T *ItemLibrarySortedModel<T>::elementModel(int libId)
|
|
|
|
|
{
|
|
|
|
|
return m_elementModels.value(libId);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
int ItemLibrarySortedModel<T>::findElement(int libId) const
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
int i = 0;
|
|
|
|
|
QListIterator<struct order_struct> it(m_elementOrder);
|
|
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
if (it.next().libId == libId)
|
|
|
|
|
return i;
|
|
|
|
|
++i;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemLibraryItemModel::ItemLibraryItemModel(QScriptEngine *scriptEngine, int itemLibId, const QString &itemName)
|
|
|
|
|
: QScriptValue(scriptEngine->newObject()),
|
|
|
|
|
m_scriptEngine(scriptEngine),
|
|
|
|
|
m_libId(itemLibId),
|
|
|
|
|
m_name(itemName),
|
|
|
|
|
m_icon(),
|
|
|
|
|
m_iconSize(64, 64)
|
|
|
|
|
{
|
|
|
|
|
QScriptValue pixmapScriptValue(m_scriptEngine->newVariant(QPixmap()));
|
|
|
|
|
|
|
|
|
|
setProperty(QLatin1String("itemLibId"), itemLibId);
|
|
|
|
|
setProperty(QLatin1String("itemName"), itemName);
|
|
|
|
|
setProperty(QLatin1String("itemPixmap"), pixmapScriptValue);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
ItemLibraryItemModel::~ItemLibraryItemModel()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
setProperty(QLatin1String("itemPixmap"), QVariant::Invalid);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
int ItemLibraryItemModel::itemLibId() const
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
return m_libId;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
QString ItemLibraryItemModel::itemName() const
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
return m_name;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
void ItemLibraryItemModel::setItemIcon(const QIcon &itemIcon)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
m_icon = itemIcon;
|
|
|
|
|
|
|
|
|
|
QScriptValue pixmapScriptValue(m_scriptEngine->newVariant(m_icon.pixmap(m_iconSize)));
|
|
|
|
|
setProperty(QLatin1String("itemPixmap"), pixmapScriptValue);
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
void ItemLibraryItemModel::setItemIconSize(const QSize &itemIconSize)
|
|
|
|
|
{
|
|
|
|
|
m_iconSize = itemIconSize;
|
|
|
|
|
// qDebug() << "set icon size" << itemIconSize;
|
|
|
|
|
setItemIcon(m_icon);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
bool ItemLibraryItemModel::operator<(const ItemLibraryItemModel &other) const
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
return itemName() < other.itemName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
ItemLibrarySectionModel::ItemLibrarySectionModel(QScriptEngine *scriptEngine, int sectionLibId, const QString §ionName, QObject *parent)
|
|
|
|
|
: QScriptValue(scriptEngine->newObject()),
|
|
|
|
|
m_name(sectionName),
|
|
|
|
|
m_sectionEntries(parent)
|
|
|
|
|
{
|
|
|
|
|
QScriptValue::setProperty(QLatin1String("sectionLibId"), sectionLibId);
|
|
|
|
|
QScriptValue::setProperty(QLatin1String("sectionName"), sectionName);
|
|
|
|
|
QScriptValue::setProperty(QLatin1String("sectionEntries"),
|
|
|
|
|
scriptEngine->newVariant(QVariant::fromValue(static_cast<QmlListModel *>(&m_sectionEntries))));
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
QString ItemLibrarySectionModel::sectionName() const
|
|
|
|
|
{
|
|
|
|
|
return m_name;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
void ItemLibrarySectionModel::addSectionEntry(ItemLibraryItemModel *sectionEntry)
|
|
|
|
|
{
|
|
|
|
|
m_sectionEntries.addElement(sectionEntry, sectionEntry->itemLibId());
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
void ItemLibrarySectionModel::removeSectionEntry(int itemLibId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
m_sectionEntries.removeElement(itemLibId);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
bool ItemLibrarySectionModel::updateSectionVisibility(const QString &searchText)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
bool haveVisibleItems = false;
|
|
|
|
|
QMap<int, ItemLibraryItemModel *>::const_iterator itemIt = m_sectionEntries.elements().constBegin();
|
|
|
|
|
while (itemIt != m_sectionEntries.elements().constEnd()) {
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
bool itemVisible = itemIt.value()->itemName().toLower().contains(searchText);
|
|
|
|
|
m_sectionEntries.setElementVisible(itemIt.key(), itemVisible);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
if (itemVisible)
|
|
|
|
|
haveVisibleItems = true;
|
|
|
|
|
|
|
|
|
|
++itemIt;
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
return haveVisibleItems;
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
void ItemLibrarySectionModel::updateItemIconSize(const QSize &itemIconSize)
|
|
|
|
|
{
|
|
|
|
|
foreach (ItemLibraryItemModel *item, m_sectionEntries.elements().values()) {
|
|
|
|
|
item->setItemIconSize(itemIconSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ItemLibrarySectionModel::operator<(const ItemLibrarySectionModel &other) const
|
|
|
|
|
{
|
|
|
|
|
return sectionName() < other.sectionName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemLibraryModel::ItemLibraryModel(QScriptEngine *scriptEngine, QObject *parent)
|
|
|
|
|
: ItemLibrarySortedModel<ItemLibrarySectionModel>(parent),
|
|
|
|
|
m_scriptEngine(scriptEngine),
|
|
|
|
|
m_metaInfo(0),
|
|
|
|
|
m_searchText(""),
|
|
|
|
|
m_itemIconSize(64, 64),
|
|
|
|
|
m_nextLibId(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ItemLibraryModel::~ItemLibraryModel()
|
|
|
|
|
{
|
|
|
|
|
if (m_metaInfo)
|
|
|
|
|
delete m_metaInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString ItemLibraryModel::searchText() const
|
|
|
|
|
{
|
|
|
|
|
return m_searchText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::setSearchText(const QString &searchText)
|
|
|
|
|
{
|
|
|
|
|
QString lowerSearchText = searchText.toLower();
|
|
|
|
|
|
|
|
|
|
if (m_searchText != lowerSearchText) {
|
|
|
|
|
m_searchText = lowerSearchText;
|
|
|
|
|
emit searchTextChanged();
|
|
|
|
|
|
|
|
|
|
updateVisibility();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::setItemIconSize(const QSize &itemIconSize)
|
|
|
|
|
{
|
|
|
|
|
m_itemIconSize = itemIconSize;
|
|
|
|
|
|
|
|
|
|
foreach (ItemLibrarySectionModel *section, elements().values())
|
|
|
|
|
section->updateItemIconSize(itemIconSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::update(const MetaInfo &metaInfo)
|
|
|
|
|
{
|
|
|
|
|
QMap<QString, int> sections;
|
|
|
|
|
|
|
|
|
|
clearElements();
|
|
|
|
|
m_itemInfos.clear();
|
|
|
|
|
|
|
|
|
|
if (!m_metaInfo) {
|
|
|
|
|
m_metaInfo = new MetaInfo(metaInfo);
|
2010-01-07 12:14:35 +01:00
|
|
|
} else {
|
2010-02-16 17:24:18 +02:00
|
|
|
*m_metaInfo = metaInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (const QString &type, metaInfo.itemLibraryItems()) {
|
|
|
|
|
foreach (const ItemLibraryInfo &itemLibraryRepresentation, itemLibraryRepresentations(type)) {
|
|
|
|
|
|
|
|
|
|
QString itemSectionName = itemLibraryRepresentation.category();
|
|
|
|
|
ItemLibrarySectionModel *sectionModel;
|
|
|
|
|
ItemLibraryItemModel *itemModel;
|
|
|
|
|
int itemId = m_nextLibId++, sectionId;
|
|
|
|
|
|
|
|
|
|
if (sections.contains(itemSectionName)) {
|
|
|
|
|
sectionId = sections.value(itemSectionName);
|
|
|
|
|
sectionModel = elementModel(sectionId);
|
|
|
|
|
} else {
|
|
|
|
|
sectionId = m_nextLibId++;
|
|
|
|
|
sectionModel = new ItemLibrarySectionModel(m_scriptEngine.data(), sectionId, itemSectionName, this);
|
|
|
|
|
addElement(sectionModel, sectionId);
|
|
|
|
|
sections.insert(itemSectionName, sectionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_itemInfos.insert(itemId, itemLibraryRepresentation);
|
|
|
|
|
|
|
|
|
|
itemModel = new ItemLibraryItemModel(m_scriptEngine.data(), itemId, itemLibraryRepresentation.name());
|
|
|
|
|
itemModel->setItemIcon(itemLibraryRepresentation.icon());
|
|
|
|
|
itemModel->setItemIconSize(m_itemIconSize);
|
|
|
|
|
sectionModel->addSectionEntry(itemModel);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
updateVisibility();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString ItemLibraryModel::getTypeName(int libId)
|
|
|
|
|
{
|
|
|
|
|
return m_itemInfos.value(libId).typeName();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
QMimeData *ItemLibraryModel::getMimeData(int libId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
QMimeData *mimeData = new QMimeData();
|
|
|
|
|
|
|
|
|
|
QByteArray data;
|
|
|
|
|
QDataStream stream(&data, QIODevice::WriteOnly);
|
|
|
|
|
stream << m_itemInfos.value(libId);
|
|
|
|
|
mimeData->setData(QLatin1String("application/vnd.bauhaus.itemlibraryinfo"), data);
|
|
|
|
|
|
|
|
|
|
const QIcon icon = m_itemInfos.value(libId).dragIcon();
|
|
|
|
|
if (!icon.isNull()) {
|
|
|
|
|
const QList<QSize> sizes = icon.availableSizes();
|
|
|
|
|
if (!sizes.isEmpty())
|
|
|
|
|
mimeData->setImageData(icon.pixmap(sizes.front()).toImage());
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
mimeData->removeFormat(QLatin1String("text/plain"));
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
return mimeData;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
QIcon ItemLibraryModel::getIcon(int libId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
return m_itemInfos.value(libId).icon();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
void ItemLibraryModel::updateVisibility()
|
|
|
|
|
{
|
|
|
|
|
QMap<int, ItemLibrarySectionModel *>::const_iterator sectionIt = elements().constBegin();
|
|
|
|
|
while (sectionIt != elements().constEnd()) {
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
ItemLibrarySectionModel *sectionModel = sectionIt.value();
|
|
|
|
|
QString sectionSearchText = m_searchText;
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
if (sectionModel->sectionName().toLower().contains(m_searchText))
|
|
|
|
|
sectionSearchText = "";
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
bool sectionVisibility = sectionModel->updateSectionVisibility(sectionSearchText);
|
|
|
|
|
setElementVisible(sectionIt.key(), sectionVisibility);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
++sectionIt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit visibilityUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<ItemLibraryInfo> ItemLibraryModel::itemLibraryRepresentations(const QString &type)
|
|
|
|
|
{
|
|
|
|
|
NodeMetaInfo nodeInfo = m_metaInfo->nodeMetaInfo(type);
|
|
|
|
|
QList<ItemLibraryInfo> itemLibraryRepresentationList = m_metaInfo->itemLibraryRepresentations(nodeInfo);
|
|
|
|
|
|
|
|
|
|
QImage dragImage(64, 64, QImage::Format_RGB32); // TODO: draw item drag icon
|
|
|
|
|
dragImage.fill(0xffffffff);
|
|
|
|
|
QPainter p(&dragImage);
|
|
|
|
|
QPen pen(Qt::gray);
|
|
|
|
|
pen.setWidth(2);
|
|
|
|
|
p.setPen(pen);
|
|
|
|
|
p.drawRect(1, 1, dragImage.width() - 2, dragImage.height() - 2);
|
|
|
|
|
QPixmap dragPixmap(QPixmap::fromImage(dragImage));
|
|
|
|
|
|
|
|
|
|
if (!m_metaInfo->hasNodeMetaInfo(type))
|
|
|
|
|
qWarning() << "ItemLibrary: type not declared: " << type;
|
|
|
|
|
|
|
|
|
|
static QIcon defaultIcon(QLatin1String(":/ItemLibrary/images/item-default-icon.png"));
|
|
|
|
|
|
|
|
|
|
if (itemLibraryRepresentationList.isEmpty() || !m_metaInfo->hasNodeMetaInfo(type)) {
|
|
|
|
|
QIcon icon = nodeInfo.icon();
|
|
|
|
|
if (icon.isNull())
|
|
|
|
|
icon = defaultIcon;
|
|
|
|
|
|
|
|
|
|
ItemLibraryInfo itemLibraryInfo;
|
|
|
|
|
itemLibraryInfo.setName(type);
|
|
|
|
|
itemLibraryInfo.setTypeName(nodeInfo.typeName());
|
|
|
|
|
itemLibraryInfo.setCategory(nodeInfo.category());
|
|
|
|
|
itemLibraryInfo.setIcon(icon);
|
|
|
|
|
itemLibraryInfo.setDragIcon(dragPixmap);
|
|
|
|
|
itemLibraryInfo.setMajorVersion(nodeInfo.majorVersion());
|
|
|
|
|
itemLibraryInfo.setMinorVersion(nodeInfo.minorVersion());
|
|
|
|
|
itemLibraryRepresentationList.append(itemLibraryInfo);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
foreach (ItemLibraryInfo itemLibraryRepresentation, itemLibraryRepresentationList) {
|
|
|
|
|
QIcon icon = itemLibraryRepresentation.icon();
|
|
|
|
|
if (itemLibraryRepresentation.icon().isNull())
|
|
|
|
|
itemLibraryRepresentation.setIcon(defaultIcon);
|
|
|
|
|
|
|
|
|
|
if (itemLibraryRepresentation.dragIcon().isNull())
|
|
|
|
|
itemLibraryRepresentation.setDragIcon(dragPixmap);
|
|
|
|
|
|
|
|
|
|
if (itemLibraryRepresentation.category().isEmpty())
|
|
|
|
|
itemLibraryRepresentation.setCategory(nodeInfo.category());
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
return itemLibraryRepresentationList;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlDesigner
|
2010-02-16 17:24:18 +02:00
|
|
|
|