2010-01-07 12:14:35 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
|
|
|
|
** Commercial Usage
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
#include "itemlibrarywidget.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
#include <utils/filterlineedit.h>
|
2010-12-14 16:52:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-12-10 17:57:42 +01:00
|
|
|
#include "itemlibrarycomponents.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
#include "itemlibrarymodel.h"
|
2010-07-13 10:11:05 +10:00
|
|
|
#include "itemlibraryimageprovider.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
#include "customdraganddrop.h"
|
2010-12-10 22:01:55 +01:00
|
|
|
#include <model.h>
|
|
|
|
|
#include <metainfo.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
#include <QFileInfo>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include <QFileIconProvider>
|
2010-03-10 12:45:49 +02:00
|
|
|
#include <QDirModel>
|
|
|
|
|
#include <QStackedWidget>
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <QTabBar>
|
2010-02-16 17:24:18 +02:00
|
|
|
#include <QImageReader>
|
2010-03-10 12:45:49 +02:00
|
|
|
#include <QMimeData>
|
2010-07-02 16:42:34 +02:00
|
|
|
#include <QWheelEvent>
|
2010-12-14 16:52:29 +01:00
|
|
|
#include <QMenu>
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-02-26 14:47:44 +01:00
|
|
|
#include <QDeclarativeView>
|
|
|
|
|
#include <QDeclarativeItem>
|
|
|
|
|
#include <private/qdeclarativeengine_p.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
|
|
class MyFileIconProvider : public QFileIconProvider
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-02-16 17:24:18 +02:00
|
|
|
MyFileIconProvider(const QSize &iconSize)
|
|
|
|
|
: QFileIconProvider(),
|
|
|
|
|
m_iconSize(iconSize)
|
2010-01-07 12:14:35 +01:00
|
|
|
{}
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
virtual QIcon icon ( const QFileInfo & info ) const
|
|
|
|
|
{
|
|
|
|
|
QPixmap pixmap(info.absoluteFilePath());
|
2010-02-16 17:24:18 +02:00
|
|
|
if (pixmap.isNull()) {
|
|
|
|
|
QIcon defaultIcon(QFileIconProvider::icon(info));
|
|
|
|
|
pixmap = defaultIcon.pixmap(defaultIcon.actualSize(m_iconSize));
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
if (pixmap.width() == m_iconSize.width()
|
|
|
|
|
&& pixmap.height() == m_iconSize.height())
|
|
|
|
|
return pixmap;
|
|
|
|
|
|
|
|
|
|
if ((pixmap.width() > m_iconSize.width())
|
|
|
|
|
|| (pixmap.height() > m_iconSize.height()))
|
2010-04-08 14:59:06 +03:00
|
|
|
return pixmap.scaled(m_iconSize, Qt::KeepAspectRatio,
|
|
|
|
|
Qt::SmoothTransformation);
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
QPoint offset((m_iconSize.width() - pixmap.width()) / 2,
|
|
|
|
|
(m_iconSize.height() - pixmap.height()) / 2);
|
|
|
|
|
QImage newIcon(m_iconSize, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
|
newIcon.fill(Qt::transparent);
|
|
|
|
|
QPainter painter(&newIcon);
|
|
|
|
|
painter.drawPixmap(offset, pixmap);
|
|
|
|
|
return QPixmap::fromImage(newIcon);
|
|
|
|
|
}
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-02-16 17:24:18 +02:00
|
|
|
QSize m_iconSize;
|
2010-01-07 12:14:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- ItemLibraryPrivate
|
2010-12-10 17:57:42 +01:00
|
|
|
class ItemLibraryWidgetPrivate {
|
2010-01-07 12:14:35 +01:00
|
|
|
public:
|
2010-12-10 17:57:42 +01:00
|
|
|
ItemLibraryWidgetPrivate(QObject *object);
|
2010-01-07 12:14:35 +01:00
|
|
|
|
|
|
|
|
Internal::ItemLibraryModel *m_itemLibraryModel;
|
|
|
|
|
QDirModel *m_resourcesDirModel;
|
2010-03-10 12:45:49 +02:00
|
|
|
|
|
|
|
|
QStackedWidget *m_stackedWidget;
|
|
|
|
|
Utils::FilterLineEdit *m_lineEdit;
|
|
|
|
|
QDeclarativeView *m_itemsView;
|
|
|
|
|
Internal::ItemLibraryTreeView *m_resourcesView;
|
2010-05-12 11:56:23 +02:00
|
|
|
QWeakPointer<ItemLibraryInfo> m_itemLibraryInfo;
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-02-16 17:24:18 +02:00
|
|
|
QSize m_itemIconSize, m_resIconSize;
|
|
|
|
|
MyFileIconProvider m_iconProvider;
|
2010-12-10 22:01:55 +01:00
|
|
|
Model *model;
|
2010-01-07 12:14:35 +01:00
|
|
|
};
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
ItemLibraryWidgetPrivate::ItemLibraryWidgetPrivate(QObject *object) :
|
2010-01-07 12:14:35 +01:00
|
|
|
m_itemLibraryModel(0),
|
2010-03-10 12:45:49 +02:00
|
|
|
m_resourcesDirModel(0),
|
|
|
|
|
m_stackedWidget(0),
|
|
|
|
|
m_lineEdit(0),
|
2010-02-16 17:24:18 +02:00
|
|
|
m_itemsView(0),
|
2010-03-10 12:45:49 +02:00
|
|
|
m_resourcesView(0),
|
2010-03-31 17:16:22 +02:00
|
|
|
m_itemIconSize(24, 24),
|
|
|
|
|
m_resIconSize(24, 24),
|
2010-12-14 16:52:29 +01:00
|
|
|
m_iconProvider(m_resIconSize),
|
|
|
|
|
model(0)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(object);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
|
2010-01-07 12:14:35 +01:00
|
|
|
QFrame(parent),
|
2010-12-14 16:52:29 +01:00
|
|
|
m_d(new ItemLibraryWidgetPrivate(this)),
|
|
|
|
|
m_filterFlag(QtBasic)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-03-10 12:45:49 +02:00
|
|
|
setWindowTitle(tr("Library", "Title of library view"));
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
/* create Items view and its model */
|
2010-02-26 14:47:44 +01:00
|
|
|
m_d->m_itemsView = new QDeclarativeView(this);
|
2010-02-16 17:24:18 +02:00
|
|
|
m_d->m_itemsView->setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
m_d->m_itemsView->setAttribute(Qt::WA_NoSystemBackground);
|
|
|
|
|
m_d->m_itemsView->setAcceptDrops(false);
|
|
|
|
|
m_d->m_itemsView->setFocusPolicy(Qt::ClickFocus);
|
2010-02-26 14:47:44 +01:00
|
|
|
m_d->m_itemsView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
|
|
|
|
m_d->m_itemLibraryModel = new Internal::ItemLibraryModel(QDeclarativeEnginePrivate::getScriptEngine(m_d->m_itemsView->engine()), this);
|
2010-02-16 17:24:18 +02:00
|
|
|
m_d->m_itemLibraryModel->setItemIconSize(m_d->m_itemIconSize);
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
QDeclarativeContext *rootContext = m_d->m_itemsView->rootContext();
|
|
|
|
|
rootContext->setContextProperty(QLatin1String("itemLibraryModel"), m_d->m_itemLibraryModel);
|
|
|
|
|
rootContext->setContextProperty(QLatin1String("itemLibraryIconWidth"), m_d->m_itemIconSize.width());
|
|
|
|
|
rootContext->setContextProperty(QLatin1String("itemLibraryIconHeight"), m_d->m_itemIconSize.height());
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 17:16:15 +01:00
|
|
|
QColor highlightColor = palette().highlight().color();
|
|
|
|
|
if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
|
|
|
|
|
highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
|
|
|
|
|
m_d->m_itemsView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);
|
|
|
|
|
|
2010-03-18 14:35:23 +02:00
|
|
|
// loading the qml has to come after all needed context properties are set
|
|
|
|
|
m_d->m_itemsView->setSource(QUrl("qrc:/ItemLibrary/qml/ItemsView.qml"));
|
|
|
|
|
|
2010-02-26 14:47:44 +01:00
|
|
|
QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(m_d->m_itemsView->rootObject());
|
2010-02-22 10:01:08 +01:00
|
|
|
connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
|
|
|
|
|
connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDrop(int)));
|
2010-05-31 15:27:52 +03:00
|
|
|
connect(this, SIGNAL(scrollItemsView(QVariant)), rootItem, SLOT(scrollView(QVariant)));
|
2010-03-10 12:45:49 +02:00
|
|
|
connect(this, SIGNAL(resetItemsView()), rootItem, SLOT(resetView()));
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
/* create Resources view and its model */
|
|
|
|
|
m_d->m_resourcesDirModel = new QDirModel(this);
|
2010-02-16 17:24:18 +02:00
|
|
|
m_d->m_resourcesDirModel->setIconProvider(&m_d->m_iconProvider);
|
2010-03-10 12:45:49 +02:00
|
|
|
m_d->m_resourcesView = new Internal::ItemLibraryTreeView(this);
|
|
|
|
|
m_d->m_resourcesView->setModel(m_d->m_resourcesDirModel);
|
|
|
|
|
m_d->m_resourcesView->setIconSize(m_d->m_resIconSize);
|
|
|
|
|
|
2010-07-13 10:11:05 +10:00
|
|
|
/* create image provider for loading item icons */
|
|
|
|
|
m_d->m_itemsView->engine()->addImageProvider(QLatin1String("qmldesigner_itemlibrary"), new Internal::ItemLibraryImageProvider);
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
/* other widgets */
|
|
|
|
|
QTabBar *tabBar = new QTabBar(this);
|
|
|
|
|
tabBar->addTab(tr("Items", "Title of library items view"));
|
|
|
|
|
tabBar->addTab(tr("Resources", "Title of library resources view"));
|
|
|
|
|
tabBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
|
|
m_d->m_lineEdit = new Utils::FilterLineEdit(this);
|
|
|
|
|
m_d->m_lineEdit->setObjectName(QLatin1String("itemLibrarySearchInput"));
|
2010-03-16 11:42:12 +01:00
|
|
|
m_d->m_lineEdit->setPlaceholderText(tr("<Filter>", "Library search input hint text"));
|
2010-03-10 12:45:49 +02:00
|
|
|
m_d->m_lineEdit->setDragEnabled(false);
|
|
|
|
|
m_d->m_lineEdit->setMinimumWidth(75);
|
2010-04-29 18:37:04 +03:00
|
|
|
m_d->m_lineEdit->setTextMargins(0, 0, 20, 0);
|
2010-03-10 12:45:49 +02:00
|
|
|
QWidget *lineEditFrame = new QWidget(this);
|
|
|
|
|
lineEditFrame->setObjectName(QLatin1String("itemLibrarySearchInputFrame"));
|
|
|
|
|
QGridLayout *lineEditLayout = new QGridLayout(lineEditFrame);
|
|
|
|
|
lineEditLayout->setMargin(2);
|
|
|
|
|
lineEditLayout->setSpacing(0);
|
2010-04-29 18:37:04 +03:00
|
|
|
lineEditLayout->addItem(new QSpacerItem(5, 3, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 0, 1, 3);
|
|
|
|
|
lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 0);
|
|
|
|
|
lineEditLayout->addWidget(m_d->m_lineEdit, 1, 1, 1, 1);
|
|
|
|
|
lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 2);
|
2010-03-10 12:45:49 +02:00
|
|
|
connect(m_d->m_lineEdit, SIGNAL(filterChanged(QString)), this, SLOT(setSearchFilter(QString)));
|
|
|
|
|
|
|
|
|
|
m_d->m_stackedWidget = new QStackedWidget(this);
|
|
|
|
|
m_d->m_stackedWidget->addWidget(m_d->m_itemsView);
|
|
|
|
|
m_d->m_stackedWidget->addWidget(m_d->m_resourcesView);
|
|
|
|
|
connect(tabBar, SIGNAL(currentChanged(int)),
|
|
|
|
|
m_d->m_stackedWidget, SLOT(setCurrentIndex(int)));
|
|
|
|
|
connect(tabBar, SIGNAL(currentChanged(int)),
|
|
|
|
|
this, SLOT(updateSearch()));
|
|
|
|
|
|
2010-04-29 18:37:04 +03:00
|
|
|
QWidget *spacer = new QWidget(this);
|
|
|
|
|
spacer->setObjectName(QLatin1String("itemLibrarySearchInputSpacer"));
|
|
|
|
|
spacer->setFixedHeight(4);
|
|
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
QGridLayout *layout = new QGridLayout(this);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
layout->addWidget(tabBar, 0, 0, 1, 1);
|
2010-04-29 18:37:04 +03:00
|
|
|
layout->addWidget(spacer, 1, 0);
|
|
|
|
|
layout->addWidget(lineEditFrame, 2, 0, 1, 1);
|
|
|
|
|
layout->addWidget(m_d->m_stackedWidget, 3, 0, 1, 1);
|
2010-03-10 12:45:49 +02:00
|
|
|
|
|
|
|
|
setResourcePath(QDir::currentPath());
|
|
|
|
|
setSearchFilter(QString());
|
|
|
|
|
|
|
|
|
|
/* style sheets */
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
|
|
|
|
QFile file(":/qmldesigner/stylesheet.css");
|
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
|
|
|
|
setStyleSheet(styleSheet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QFile file(":/qmldesigner/scrollbar.css");
|
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
|
QString styleSheet = QLatin1String(file.readAll());
|
2010-03-10 12:45:49 +02:00
|
|
|
m_d->m_resourcesView->setStyleSheet(styleSheet);
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
ItemLibraryWidget::~ItemLibraryWidget()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-03-18 14:35:23 +02:00
|
|
|
/* workaround: delete the items view before the model is deleted.
|
|
|
|
|
This prevents qml warnings when the item library is destructed. */
|
|
|
|
|
delete m_d->m_itemsView;
|
2010-03-24 12:50:17 +02:00
|
|
|
delete m_d->m_resourcesView;
|
2010-01-07 12:14:35 +01:00
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo)
|
2010-03-10 12:45:49 +02:00
|
|
|
{
|
2010-05-12 11:56:23 +02:00
|
|
|
if (m_d->m_itemLibraryInfo.data() == itemLibraryInfo)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_d->m_itemLibraryInfo)
|
|
|
|
|
disconnect(m_d->m_itemLibraryInfo.data(), SIGNAL(entriesChanged()),
|
|
|
|
|
this, SLOT(updateModel()));
|
|
|
|
|
m_d->m_itemLibraryInfo = itemLibraryInfo;
|
|
|
|
|
if (itemLibraryInfo)
|
|
|
|
|
connect(m_d->m_itemLibraryInfo.data(), SIGNAL(entriesChanged()),
|
|
|
|
|
this, SLOT(updateModel()));
|
|
|
|
|
|
|
|
|
|
updateModel();
|
2010-04-19 14:36:02 +03:00
|
|
|
updateSearch();
|
2010-03-10 12:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
void ItemLibraryWidget::updateImports()
|
|
|
|
|
{
|
|
|
|
|
FilterChangeFlag filter;
|
|
|
|
|
filter = QtBasic;
|
|
|
|
|
if (m_d->model) {
|
|
|
|
|
QStringList imports;
|
|
|
|
|
foreach (const Import &import, m_d->model->imports())
|
|
|
|
|
if (import.isLibraryImport())
|
|
|
|
|
imports << import.url();
|
|
|
|
|
if (imports.contains("Qt.labs.Symbian", Qt::CaseInsensitive))
|
|
|
|
|
filter = Symbian;
|
|
|
|
|
if (imports.contains("com.Meego", Qt::CaseInsensitive))
|
|
|
|
|
filter = Meego;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setImportFilter(filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QToolButton *> ItemLibraryWidget::createToolBarWidgets()
|
|
|
|
|
{
|
|
|
|
|
QList<QToolButton *> buttons;
|
|
|
|
|
buttons << new QToolButton();
|
|
|
|
|
buttons.first()->setText("I ");
|
|
|
|
|
buttons.first()->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
|
|
|
|
buttons.first()->setToolTip("Manage imports for components");
|
|
|
|
|
buttons.first()->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
QMenu * menu = new QMenu;
|
|
|
|
|
QAction * basicQtAction = new QAction(menu);
|
|
|
|
|
basicQtAction->setCheckable(true);
|
|
|
|
|
basicQtAction->setText("Basic Qt Quick only");
|
|
|
|
|
QAction * symbianAction = new QAction(menu);
|
|
|
|
|
symbianAction->setCheckable(true);
|
|
|
|
|
symbianAction->setText("Symbian Components");
|
|
|
|
|
QAction * meegoAction= new QAction(menu);
|
|
|
|
|
meegoAction->setCheckable(true);
|
|
|
|
|
meegoAction->setText("Meego Components");
|
|
|
|
|
menu->addAction(basicQtAction);
|
|
|
|
|
menu->addAction(meegoAction);
|
|
|
|
|
menu->addAction(symbianAction);
|
|
|
|
|
buttons.first()->setMenu(menu);
|
|
|
|
|
|
|
|
|
|
connect(basicQtAction, SIGNAL(toggled(bool)), this, SLOT(onQtBasicOnlyChecked(bool)));
|
|
|
|
|
connect(this, SIGNAL(qtBasicOnlyChecked(bool)), basicQtAction, SLOT(setChecked(bool)));
|
|
|
|
|
|
|
|
|
|
connect(symbianAction, SIGNAL(toggled(bool)), this, SLOT(onSymbianChecked(bool)));
|
|
|
|
|
connect(this, SIGNAL(symbianChecked(bool)), symbianAction, SLOT(setChecked(bool)));
|
|
|
|
|
|
|
|
|
|
connect(meegoAction, SIGNAL(toggled(bool)), this, SLOT(onMeegoChecked(bool)));
|
|
|
|
|
connect(this, SIGNAL(meegoChecked(bool)), meegoAction, SLOT(setChecked(bool)));
|
|
|
|
|
|
|
|
|
|
updateImports();
|
|
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::setSearchFilter(const QString &searchFilter)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-03-10 12:45:49 +02:00
|
|
|
if (m_d->m_stackedWidget->currentIndex() == 0) {
|
2010-02-16 17:24:18 +02:00
|
|
|
m_d->m_itemLibraryModel->setSearchText(searchFilter);
|
2010-03-10 12:45:49 +02:00
|
|
|
emit resetItemsView();
|
2010-02-16 17:24:18 +02:00
|
|
|
m_d->m_itemsView->update();
|
|
|
|
|
} else {
|
|
|
|
|
QStringList nameFilterList;
|
|
|
|
|
if (searchFilter.contains('.')) {
|
|
|
|
|
nameFilterList.append(QString("*%1*").arg(searchFilter));
|
|
|
|
|
} else {
|
|
|
|
|
foreach (const QByteArray &extension, QImageReader::supportedImageFormats()) {
|
|
|
|
|
nameFilterList.append(QString("*%1*.%2").arg(searchFilter, QString::fromAscii(extension)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_d->m_resourcesDirModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
m_d->m_resourcesDirModel->setNameFilters(nameFilterList);
|
2010-12-14 16:52:29 +01:00
|
|
|
m_d->m_resourcesView->expandToDepth(1);
|
2010-03-10 12:45:49 +02:00
|
|
|
m_d->m_resourcesView->scrollToTop();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 22:01:55 +01:00
|
|
|
void ItemLibraryWidget::setModel(Model *model)
|
|
|
|
|
{
|
|
|
|
|
m_d->model = model;
|
2010-12-13 10:54:30 +01:00
|
|
|
if (!model)
|
|
|
|
|
return;
|
2010-12-10 22:01:55 +01:00
|
|
|
setItemLibraryInfo(model->metaInfo().itemLibraryInfo());
|
|
|
|
|
updateModel();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
|
|
|
|
|
void ItemLibraryWidget::setImportFilter(FilterChangeFlag flag)
|
|
|
|
|
{
|
|
|
|
|
if (!m_d->model)
|
|
|
|
|
return;
|
|
|
|
|
if (flag == m_filterFlag)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_filterFlag = flag;
|
|
|
|
|
if (flag == QtBasic) {
|
2010-12-15 13:31:07 +01:00
|
|
|
removeImport(QLatin1String("com.meego"));
|
2010-12-14 16:52:29 +01:00
|
|
|
removeImport(QLatin1String("Qt.labs.Symbian"));
|
|
|
|
|
emit qtBasicOnlyChecked(true);
|
|
|
|
|
emit meegoChecked(false);
|
|
|
|
|
emit symbianChecked(false);
|
|
|
|
|
} else if (flag == Symbian) {
|
|
|
|
|
addImport(QLatin1String("Qt.labs.Symbian"), QLatin1String("1.0"));
|
2010-12-15 13:31:07 +01:00
|
|
|
removeImport(QLatin1String("com.meego"));
|
2010-12-14 16:52:29 +01:00
|
|
|
emit qtBasicOnlyChecked(false);
|
|
|
|
|
emit meegoChecked(false);
|
|
|
|
|
emit symbianChecked(true);
|
|
|
|
|
} else if (flag == Meego) {
|
2010-12-15 13:31:07 +01:00
|
|
|
addImport(QLatin1String("com.meego"), QLatin1String("1.0"));
|
2010-12-14 16:52:29 +01:00
|
|
|
removeImport(QLatin1String("Qt.labs.Symbian"));
|
|
|
|
|
emit qtBasicOnlyChecked(false);
|
|
|
|
|
emit meegoChecked(true);
|
|
|
|
|
emit symbianChecked(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::onQtBasicOnlyChecked(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (b)
|
|
|
|
|
setImportFilter(QtBasic);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::onMeegoChecked(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (b)
|
|
|
|
|
setImportFilter(Meego);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::onSymbianChecked(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (b)
|
|
|
|
|
setImportFilter(Symbian);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::updateModel()
|
2010-05-12 11:56:23 +02:00
|
|
|
{
|
2010-12-10 22:01:55 +01:00
|
|
|
m_d->m_itemLibraryModel->update(m_d->m_itemLibraryInfo.data(), m_d->model);
|
2010-12-14 16:52:29 +01:00
|
|
|
updateImports();
|
2010-05-12 11:56:23 +02:00
|
|
|
updateSearch();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::updateSearch()
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-03-16 11:42:12 +01:00
|
|
|
setSearchFilter(m_d->m_lineEdit->text());
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::setResourcePath(const QString &resourcePath)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-03-10 12:45:49 +02:00
|
|
|
if (m_d->m_resourcesView->model() == m_d->m_resourcesDirModel)
|
|
|
|
|
m_d->m_resourcesView->setRootIndex(m_d->m_resourcesDirModel->index(resourcePath));
|
2010-04-19 14:36:02 +03:00
|
|
|
updateSearch();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::startDragAndDrop(int itemLibId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
QMimeData *mimeData = m_d->m_itemLibraryModel->getMimeData(itemLibId);
|
|
|
|
|
CustomItemLibraryDrag *drag = new CustomItemLibraryDrag(this);
|
|
|
|
|
const QImage image = qvariant_cast<QImage>(mimeData->imageData());
|
|
|
|
|
|
|
|
|
|
drag->setPixmap(m_d->m_itemLibraryModel->getIcon(itemLibId).pixmap(32, 32));
|
|
|
|
|
drag->setPreview(QPixmap::fromImage(image));
|
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
2010-02-26 14:47:44 +01:00
|
|
|
QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(m_d->m_itemsView->rootObject());
|
2010-02-22 10:01:08 +01:00
|
|
|
connect(rootItem, SIGNAL(stopDragAndDrop()), drag, SLOT(stopDrag()));
|
2010-02-16 17:24:18 +02:00
|
|
|
|
|
|
|
|
drag->exec();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::showItemInfo(int /*itemLibId*/)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2010-02-16 17:24:18 +02:00
|
|
|
// qDebug() << "showing item info about id" << itemLibId;
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::wheelEvent(QWheelEvent *event)
|
2010-05-31 15:27:52 +03:00
|
|
|
{
|
|
|
|
|
if (m_d->m_stackedWidget->currentIndex() == 0 &&
|
|
|
|
|
m_d->m_itemsView->rect().contains(event->pos())) {
|
|
|
|
|
emit scrollItemsView(event->delta());
|
|
|
|
|
event->accept();
|
|
|
|
|
} else
|
|
|
|
|
QFrame::wheelEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
void ItemLibraryWidget::removeImport(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
if (!m_d->model)
|
|
|
|
|
return;
|
|
|
|
|
foreach (const Import &import, m_d->model->imports())
|
|
|
|
|
if (import.isLibraryImport() && import.url().compare(name, Qt::CaseInsensitive) == 0)
|
|
|
|
|
m_d->model->removeImport(import);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::addImport(const QString &name, const QString &version)
|
|
|
|
|
{
|
|
|
|
|
if (!m_d->model)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_d->model->addImport(Import::createLibraryImport(name, version));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|