2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-02-16 19:07:59 +02:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
#include "itemlibrarymodel.h"
|
2010-05-12 11:56:23 +02:00
|
|
|
#include "itemlibraryinfo.h"
|
2014-05-21 12:34:36 +02:00
|
|
|
#include "itemlibrarysectionmodel.h"
|
2014-05-21 15:35:03 +02:00
|
|
|
#include "itemlibraryitem.h"
|
2014-05-21 12:34:36 +02:00
|
|
|
|
2010-12-10 22:01:55 +01:00
|
|
|
#include <model.h>
|
|
|
|
|
#include <nodemetainfo.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
#include <QVariant>
|
2013-08-06 16:45:59 +02:00
|
|
|
#include <QMetaProperty>
|
2010-02-16 17:24:18 +02:00
|
|
|
#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
|
|
|
|
2013-08-06 16:45:59 +02:00
|
|
|
static bool inline registerItemLibrarySortedModel() {
|
2014-05-14 14:26:06 +02:00
|
|
|
qmlRegisterType<QmlDesigner::ItemLibrarySortedModel>();
|
2013-08-06 16:45:59 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2013-06-06 11:24:18 +02:00
|
|
|
static QHash<QString, bool> collapsedStateHash;
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2013-06-06 11:24:18 +02:00
|
|
|
void ItemLibraryModel::setExpanded(bool expanded, const QString §ion)
|
|
|
|
|
{
|
|
|
|
|
if (collapsedStateHash.contains(section))
|
|
|
|
|
collapsedStateHash.remove(section);
|
|
|
|
|
|
|
|
|
|
if (!expanded) //default is true
|
|
|
|
|
collapsedStateHash.insert(section, expanded);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 16:45:59 +02:00
|
|
|
ItemLibraryModel::ItemLibraryModel(QObject *parent)
|
2014-05-15 17:52:13 +02:00
|
|
|
: QAbstractListModel(parent),
|
2010-02-16 17:24:18 +02:00
|
|
|
m_itemIconSize(64, 64),
|
|
|
|
|
m_nextLibId(0)
|
|
|
|
|
{
|
2014-05-15 17:52:13 +02:00
|
|
|
addRoleNames();
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemLibraryModel::~ItemLibraryModel()
|
|
|
|
|
{
|
2014-05-15 17:52:13 +02:00
|
|
|
clearSections();
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-15 17:52:13 +02:00
|
|
|
int ItemLibraryModel::rowCount(const QModelIndex & /*parent*/) const
|
|
|
|
|
{
|
|
|
|
|
return visibleSectionCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ItemLibraryModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid() || index.row() +1 > visibleSectionCount())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_roleNames.contains(role)) {
|
|
|
|
|
QVariant value = visibleSections().at(index.row())->property(m_roleNames.value(role));
|
|
|
|
|
|
|
|
|
|
ItemLibrarySortedModel* model = qobject_cast<ItemLibrarySortedModel *>(value.value<QObject*>());
|
|
|
|
|
if (model)
|
|
|
|
|
return QVariant::fromValue(model);
|
|
|
|
|
|
|
|
|
|
ItemLibraryModel* model2 = qobject_cast<ItemLibraryModel *>(value.value<QObject*>());
|
|
|
|
|
if (model2)
|
|
|
|
|
return QVariant::fromValue(model2);
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qWarning() << Q_FUNC_INFO << "invalid role requested";
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2013-08-06 16:45:59 +02:00
|
|
|
foreach (ItemLibrarySectionModel* itemLibrarySectionModel, sections()) {
|
|
|
|
|
itemLibrarySectionModel->updateItemIconSize(itemIconSize);
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
int ItemLibraryModel::getItemSectionIndex(int itemLibId)
|
|
|
|
|
{
|
|
|
|
|
if (m_sections.contains(itemLibId))
|
2013-08-06 16:45:59 +02:00
|
|
|
return section(m_sections.value(itemLibId))->visibleItemIndex(itemLibId);
|
2010-03-10 12:45:49 +02:00
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ItemLibraryModel::getSectionLibId(int itemLibId)
|
|
|
|
|
{
|
|
|
|
|
return m_sections.value(itemLibId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ItemLibraryModel::isItemVisible(int itemLibId)
|
|
|
|
|
{
|
|
|
|
|
if (!m_sections.contains(itemLibId))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int sectionLibId = m_sections.value(itemLibId);
|
2014-05-15 17:52:13 +02:00
|
|
|
if (section(sectionLibId)->isVisible())
|
2010-03-10 12:45:49 +02:00
|
|
|
return false;
|
|
|
|
|
|
2013-08-06 16:45:59 +02:00
|
|
|
return section(sectionLibId)->isItemVisible(itemLibId);
|
2010-03-10 12:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-16 16:12:29 +02:00
|
|
|
Import entryToImport(const ItemLibraryEntry &entry)
|
2010-12-10 22:01:55 +01:00
|
|
|
{
|
2013-01-15 13:48:01 +01:00
|
|
|
if (entry.majorVersion() == -1 && entry.minorVersion() == -1)
|
|
|
|
|
return Import::createFileImport(entry.requiredImport());
|
|
|
|
|
|
2011-05-16 16:12:29 +02:00
|
|
|
return Import::createLibraryImport(entry.requiredImport(), QString::number(entry.majorVersion()) + QLatin1Char('.') +
|
|
|
|
|
QString::number(entry.minorVersion()));
|
|
|
|
|
|
2010-12-10 22:01:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|
2010-02-16 17:24:18 +02:00
|
|
|
{
|
2013-02-12 14:42:14 +01:00
|
|
|
if (!model)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
QMap<QString, int> sections;
|
|
|
|
|
|
2014-05-15 17:52:13 +02:00
|
|
|
clearSections();
|
2010-02-16 17:24:18 +02:00
|
|
|
m_itemInfos.clear();
|
2010-03-10 12:45:49 +02:00
|
|
|
m_sections.clear();
|
|
|
|
|
m_nextLibId = 0;
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-12-10 22:01:55 +01:00
|
|
|
QStringList imports;
|
|
|
|
|
foreach (const Import &import, model->imports())
|
|
|
|
|
if (import.isLibraryImport())
|
2011-02-25 15:27:13 +01:00
|
|
|
imports << import.url() + QLatin1Char(' ') + import.version();
|
2010-05-07 16:33:02 +02:00
|
|
|
|
2010-12-10 22:01:55 +01:00
|
|
|
foreach (ItemLibraryEntry entry, itemLibraryInfo->entries()) {
|
2010-05-07 16:33:02 +02:00
|
|
|
|
2012-12-20 15:33:53 +01:00
|
|
|
NodeMetaInfo metaInfo = model->metaInfo(entry.typeName(), -1, -1);
|
|
|
|
|
bool valid = metaInfo.isValid() && metaInfo.majorVersion() == entry.majorVersion();
|
2010-12-10 22:01:55 +01:00
|
|
|
|
2014-05-07 13:00:57 +02:00
|
|
|
if (valid
|
2012-12-20 15:33:53 +01:00
|
|
|
&& (entry.requiredImport().isEmpty()
|
2014-05-07 13:00:57 +02:00
|
|
|
|| model->hasImport(entryToImport(entry), true, true))) {
|
2010-12-10 22:01:55 +01:00
|
|
|
QString itemSectionName = entry.category();
|
|
|
|
|
ItemLibrarySectionModel *sectionModel;
|
2014-05-21 15:35:03 +02:00
|
|
|
ItemLibraryItem *itemModel;
|
2010-12-10 22:01:55 +01:00
|
|
|
int itemId = m_nextLibId++, sectionId;
|
|
|
|
|
|
|
|
|
|
if (sections.contains(itemSectionName)) {
|
|
|
|
|
sectionId = sections.value(itemSectionName);
|
2013-08-06 16:45:59 +02:00
|
|
|
sectionModel = section(sectionId);
|
2010-12-10 22:01:55 +01:00
|
|
|
} else {
|
|
|
|
|
sectionId = m_nextLibId++;
|
2013-08-06 16:45:59 +02:00
|
|
|
sectionModel = new ItemLibrarySectionModel(sectionId, itemSectionName, this);
|
2014-05-15 17:52:13 +02:00
|
|
|
addSection(sectionModel, sectionId);
|
2010-12-10 22:01:55 +01:00
|
|
|
sections.insert(itemSectionName, sectionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_itemInfos.insert(itemId, entry);
|
|
|
|
|
|
2014-05-21 15:35:03 +02:00
|
|
|
itemModel = new ItemLibraryItem(itemId, entry.name(), sectionModel);
|
2010-12-10 22:01:55 +01:00
|
|
|
|
|
|
|
|
// delayed creation of (default) icons
|
|
|
|
|
if (entry.iconPath().isEmpty())
|
2014-05-12 14:09:02 +02:00
|
|
|
entry.setIconPath(QStringLiteral(":/ItemLibrary/images/item-default-icon.png"));
|
2010-12-10 22:01:55 +01:00
|
|
|
if (entry.dragIcon().isNull())
|
|
|
|
|
entry.setDragIcon(createDragPixmap(getWidth(entry), getHeight(entry)));
|
|
|
|
|
|
|
|
|
|
itemModel->setItemIconPath(entry.iconPath());
|
|
|
|
|
itemModel->setItemIconSize(m_itemIconSize);
|
|
|
|
|
sectionModel->addSectionEntry(itemModel);
|
|
|
|
|
m_sections.insert(itemId, sectionId);
|
|
|
|
|
}
|
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);
|
2014-05-12 14:09:02 +02:00
|
|
|
mimeData->setData(QStringLiteral("application/vnd.bauhaus.itemlibraryinfo"), data);
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-05-12 14:09:02 +02:00
|
|
|
mimeData->removeFormat(QStringLiteral("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();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-15 17:52:13 +02:00
|
|
|
ItemLibrarySectionModel *ItemLibraryModel::section(int libraryId)
|
2013-08-06 16:45:59 +02:00
|
|
|
{
|
2014-05-15 17:52:13 +02:00
|
|
|
return m_sectionModels.value(libraryId);
|
2013-08-06 16:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ItemLibrarySectionModel *> ItemLibraryModel::sections() const
|
|
|
|
|
{
|
2014-05-15 17:52:13 +02:00
|
|
|
return m_sectionModels.values();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::addSection(ItemLibrarySectionModel *sectionModel, int sectionId)
|
|
|
|
|
{
|
|
|
|
|
m_sectionModels.insert(sectionId, sectionModel);
|
|
|
|
|
sectionModel->setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::clearSections()
|
|
|
|
|
{
|
|
|
|
|
beginResetModel();
|
|
|
|
|
qDeleteAll(m_sectionModels);
|
|
|
|
|
m_sectionModels.clear();
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryModel::registerQmlTypes()
|
|
|
|
|
{
|
|
|
|
|
qmlRegisterType<QmlDesigner::ItemLibrarySortedModel>();
|
|
|
|
|
qmlRegisterType<QmlDesigner::ItemLibraryModel>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ItemLibraryModel::visibleSectionCount() const
|
|
|
|
|
{
|
|
|
|
|
int visibleCount = 0;
|
|
|
|
|
|
|
|
|
|
QMap<int, ItemLibrarySectionModel*>::const_iterator sectionIterator = m_sectionModels.constBegin();
|
|
|
|
|
while (sectionIterator != m_sectionModels.constEnd()) {
|
|
|
|
|
ItemLibrarySectionModel *sectionModel = sectionIterator.value();
|
|
|
|
|
if (sectionModel->isVisible())
|
|
|
|
|
++visibleCount;
|
|
|
|
|
++sectionIterator;
|
|
|
|
|
qDebug() << __FUNCTION__ << visibleCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return visibleCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ItemLibrarySectionModel *> ItemLibraryModel::visibleSections() const
|
|
|
|
|
{
|
|
|
|
|
QList<ItemLibrarySectionModel *> visibleSectionList;
|
|
|
|
|
|
|
|
|
|
QMap<int, ItemLibrarySectionModel*>::const_iterator sectionIterator = m_sectionModels.constBegin();
|
|
|
|
|
while (sectionIterator != m_sectionModels.constEnd()) {
|
|
|
|
|
ItemLibrarySectionModel *sectionModel = sectionIterator.value();
|
|
|
|
|
if (sectionModel->isVisible())
|
|
|
|
|
visibleSectionList.append(sectionModel);
|
|
|
|
|
++sectionIterator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return visibleSectionList;
|
2013-08-06 16:45:59 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
void ItemLibraryModel::updateVisibility()
|
|
|
|
|
{
|
2013-08-06 16:45:59 +02:00
|
|
|
beginResetModel();
|
|
|
|
|
endResetModel();
|
2010-03-10 12:45:49 +02:00
|
|
|
bool changed = false;
|
|
|
|
|
|
2014-05-15 17:52:13 +02:00
|
|
|
QMap<int, ItemLibrarySectionModel*>::const_iterator sectionIterator = m_sectionModels.constBegin();
|
|
|
|
|
while (sectionIterator != m_sectionModels.constEnd()) {
|
|
|
|
|
ItemLibrarySectionModel *sectionModel = sectionIterator.value();
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
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))
|
2014-05-15 17:52:13 +02:00
|
|
|
sectionSearchText.clear();
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
bool sectionChanged = false,
|
|
|
|
|
sectionVisibility = sectionModel->updateSectionVisibility(sectionSearchText,
|
|
|
|
|
§ionChanged);
|
|
|
|
|
if (sectionChanged) {
|
|
|
|
|
changed = true;
|
|
|
|
|
if (sectionVisibility)
|
2014-05-15 17:52:13 +02:00
|
|
|
emit sectionVisibilityChanged(sectionIterator.key());
|
2010-03-10 12:45:49 +02:00
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2014-05-15 17:52:13 +02:00
|
|
|
changed |= sectionModel->setVisible(sectionVisibility);
|
|
|
|
|
++sectionIterator;
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
if (changed)
|
|
|
|
|
emit visibilityChanged();
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-15 17:52:13 +02:00
|
|
|
void ItemLibraryModel::addRoleNames()
|
|
|
|
|
{
|
|
|
|
|
int role = 0;
|
|
|
|
|
for (int propertyIndex = 0; propertyIndex < ItemLibrarySectionModel::staticMetaObject.propertyCount(); ++propertyIndex) {
|
|
|
|
|
QMetaProperty property = ItemLibrarySectionModel::staticMetaObject.property(propertyIndex);
|
|
|
|
|
m_roleNames.insert(role, property.name());
|
|
|
|
|
++role;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setRoleNames(m_roleNames);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 16:33:02 +02:00
|
|
|
int ItemLibraryModel::getWidth(const ItemLibraryEntry &itemLibraryEntry)
|
2010-04-28 10:11:28 +02:00
|
|
|
{
|
2010-05-07 12:49:13 +02:00
|
|
|
foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties())
|
2010-04-28 10:11:28 +02:00
|
|
|
{
|
2013-03-05 12:19:19 +01:00
|
|
|
if (property.name() == "width")
|
2010-04-28 10:11:28 +02:00
|
|
|
return property.value().toInt();
|
|
|
|
|
}
|
2014-05-15 17:52:13 +02:00
|
|
|
|
2010-04-28 10:11:28 +02:00
|
|
|
return 64;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-07 16:33:02 +02:00
|
|
|
int ItemLibraryModel::getHeight(const ItemLibraryEntry &itemLibraryEntry)
|
2010-04-28 10:11:28 +02:00
|
|
|
{
|
2010-05-07 12:49:13 +02:00
|
|
|
foreach (const ItemLibraryEntry::Property &property, itemLibraryEntry.properties())
|
2010-04-28 10:11:28 +02:00
|
|
|
{
|
2013-03-05 12:19:19 +01:00
|
|
|
if (property.name() == "height")
|
2010-04-28 10:11:28 +02:00
|
|
|
return property.value().toInt();
|
|
|
|
|
}
|
2014-05-15 17:52:13 +02:00
|
|
|
|
2010-04-28 10:11:28 +02:00
|
|
|
return 64;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-17 12:04:51 +02:00
|
|
|
QPixmap ItemLibraryModel::createDragPixmap(int , int )
|
2010-04-28 10:11:28 +02:00
|
|
|
{
|
2011-05-09 14:36:11 +02:00
|
|
|
QImage dragImage(10, 10, QImage::Format_ARGB32); // TODO: draw item drag icon
|
|
|
|
|
dragImage.fill(0x00ffffff); //### todo for now we disable the preview image
|
2010-04-28 10:11:28 +02:00
|
|
|
QPainter p(&dragImage);
|
|
|
|
|
QPen pen(Qt::gray);
|
2011-05-09 14:36:11 +02:00
|
|
|
// pen.setWidth(2);
|
|
|
|
|
// p.setPen(pen);
|
|
|
|
|
// p.drawRect(1, 1, dragImage.width() - 2, dragImage.height() - 2);
|
2010-04-28 10:11:28 +02:00
|
|
|
return QPixmap::fromImage(dragImage);
|
|
|
|
|
}
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2013-08-06 16:45:59 +02:00
|
|
|
void registerQmlTypes()
|
|
|
|
|
{
|
|
|
|
|
registerItemLibrarySortedModel();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
} // namespace QmlDesigner
|
2010-02-16 17:24:18 +02:00
|
|
|
|