2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01: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-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-07 12:14:35 +01: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-01-07 12:14:35 +01: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.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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-01-07 12:14:35 +01:00
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
#include "itemlibrarywidget.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2010-12-14 16:52:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-01-07 12:14:35 +01:00
|
|
|
#include "itemlibrarymodel.h"
|
2010-07-13 10:11:05 +10:00
|
|
|
#include "itemlibraryimageprovider.h"
|
2010-12-10 22:01:55 +01:00
|
|
|
#include <model.h>
|
|
|
|
|
#include <metainfo.h>
|
2011-01-20 17:49:40 +01:00
|
|
|
#include "rewritingexception.h"
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
#include <QFileInfo>
|
2011-07-27 13:32:10 +02:00
|
|
|
#include <QFileSystemModel>
|
2010-03-10 12:45:49 +02:00
|
|
|
#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-12-16 11:33:19 +01:00
|
|
|
#include <QApplication>
|
2014-01-06 15:20:54 +01:00
|
|
|
#include <QTimer>
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2013-09-13 17:06:10 +02:00
|
|
|
#include <QQuickItem>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2013-10-31 14:22:13 +01:00
|
|
|
enum {
|
|
|
|
|
debug = false
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-07 12:14:35 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
|
2010-01-07 12:14:35 +01:00
|
|
|
QFrame(parent),
|
2012-08-29 15:57:03 +02:00
|
|
|
m_itemIconSize(24, 24),
|
|
|
|
|
m_resIconSize(24, 24),
|
2014-05-21 20:54:52 +03:00
|
|
|
m_iconProvider(m_resIconSize),
|
2013-09-13 17:06:10 +02:00
|
|
|
m_itemsView(new QQuickView()),
|
2012-08-29 15:57:03 +02:00
|
|
|
m_resourcesView(new Internal::ItemLibraryTreeView(this)),
|
2014-01-06 15:20:54 +01:00
|
|
|
m_filterFlag(QtBasic),
|
|
|
|
|
m_itemLibraryId(-1)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2013-08-06 16:45:59 +02:00
|
|
|
Internal::registerQmlTypes();
|
|
|
|
|
|
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 */
|
2013-09-13 17:06:10 +02:00
|
|
|
m_itemsView->setResizeMode(QQuickView::SizeRootObjectToView);
|
2013-10-31 14:22:13 +01:00
|
|
|
m_itemsView->engine()->setOutputWarningsToStandardError(debug);
|
2013-08-06 16:45:59 +02:00
|
|
|
m_itemLibraryModel = new Internal::ItemLibraryModel(this);
|
2012-08-29 15:57:03 +02:00
|
|
|
m_itemLibraryModel->setItemIconSize(m_itemIconSize);
|
|
|
|
|
|
2013-09-13 17:06:10 +02:00
|
|
|
QQmlContext *rootContext = m_itemsView->rootContext();
|
2014-05-12 14:09:02 +02:00
|
|
|
rootContext->setContextProperty(QStringLiteral("itemLibraryModel"), m_itemLibraryModel.data());
|
|
|
|
|
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
|
|
|
|
|
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), 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());
|
2014-05-12 14:09:02 +02:00
|
|
|
m_itemsView->rootContext()->setContextProperty(QStringLiteral("highlightColor"), highlightColor);
|
2010-03-10 17:16:15 +01:00
|
|
|
|
2010-03-18 14:35:23 +02:00
|
|
|
// loading the qml has to come after all needed context properties are set
|
2012-08-29 15:57:03 +02:00
|
|
|
m_itemsView->setSource(QUrl("qrc:/ItemLibrary/qml/ItemsView.qml"));
|
2010-03-18 14:35:23 +02:00
|
|
|
|
2013-09-13 17:06:10 +02:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem*>(m_itemsView->rootObject());
|
2010-02-22 10:01:08 +01:00
|
|
|
connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
|
2014-01-06 15:20:54 +01:00
|
|
|
connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDropDelayed(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 */
|
2012-08-29 15:57:03 +02:00
|
|
|
m_resourcesFileSystemModel = new QFileSystemModel(this);
|
|
|
|
|
m_resourcesFileSystemModel->setIconProvider(&m_iconProvider);
|
|
|
|
|
m_resourcesView->setModel(m_resourcesFileSystemModel.data());
|
|
|
|
|
m_resourcesView->setIconSize(m_resIconSize);
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-07-13 10:11:05 +10:00
|
|
|
/* create image provider for loading item icons */
|
2014-05-12 14:09:02 +02:00
|
|
|
m_itemsView->engine()->addImageProvider(QStringLiteral("qmldesigner_itemlibrary"), new Internal::ItemLibraryImageProvider);
|
2010-07-13 10:11:05 +10:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
/* other widgets */
|
|
|
|
|
QTabBar *tabBar = new QTabBar(this);
|
2013-03-13 11:39:36 +01:00
|
|
|
tabBar->addTab(tr("QML Types", "Title of library QML types view"));
|
2010-03-10 12:45:49 +02:00
|
|
|
tabBar->addTab(tr("Resources", "Title of library resources view"));
|
2013-08-14 17:42:48 +02:00
|
|
|
tabBar->addTab(tr("Imports", "Title of library imports view"));
|
2010-03-10 12:45:49 +02:00
|
|
|
tabBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2013-08-15 13:09:54 +02:00
|
|
|
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndexOfStackedWidget(int)));
|
|
|
|
|
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(updateSearch()));
|
|
|
|
|
|
2014-02-13 13:54:39 +01:00
|
|
|
m_filterLineEdit = new Utils::FancyLineEdit(this);
|
2014-05-12 14:09:02 +02:00
|
|
|
m_filterLineEdit->setObjectName(QStringLiteral("itemLibrarySearchInput"));
|
2013-08-15 13:09:54 +02:00
|
|
|
m_filterLineEdit->setPlaceholderText(tr("<Filter>", "Library search input hint text"));
|
|
|
|
|
m_filterLineEdit->setDragEnabled(false);
|
|
|
|
|
m_filterLineEdit->setMinimumWidth(75);
|
|
|
|
|
m_filterLineEdit->setTextMargins(0, 0, 20, 0);
|
2014-02-13 13:54:39 +01:00
|
|
|
m_filterLineEdit->setFiltering(true);
|
2010-03-10 12:45:49 +02:00
|
|
|
QWidget *lineEditFrame = new QWidget(this);
|
2014-05-12 14:09:02 +02:00
|
|
|
lineEditFrame->setObjectName(QStringLiteral("itemLibrarySearchInputFrame"));
|
2010-03-10 12:45:49 +02:00
|
|
|
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);
|
2013-08-15 13:09:54 +02:00
|
|
|
lineEditLayout->addWidget(m_filterLineEdit.data(), 1, 1, 1, 1);
|
2010-04-29 18:37:04 +03:00
|
|
|
lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 2);
|
2013-08-15 13:09:54 +02:00
|
|
|
connect(m_filterLineEdit.data(), SIGNAL(filterChanged(QString)), this, SLOT(setSearchFilter(QString)));
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2013-09-13 17:06:10 +02:00
|
|
|
QWidget *container = createWindowContainer(m_itemsView.data());
|
2012-08-29 15:57:03 +02:00
|
|
|
m_stackedWidget = new QStackedWidget(this);
|
2013-09-13 17:06:10 +02:00
|
|
|
m_stackedWidget->addWidget(container);
|
2012-08-29 15:57:03 +02:00
|
|
|
m_stackedWidget->addWidget(m_resourcesView.data());
|
2010-03-10 12:45:49 +02:00
|
|
|
|
2010-04-29 18:37:04 +03:00
|
|
|
QWidget *spacer = new QWidget(this);
|
2014-05-12 14:09:02 +02:00
|
|
|
spacer->setObjectName(QStringLiteral("itemLibrarySearchInputSpacer"));
|
2010-04-29 18:37:04 +03:00
|
|
|
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);
|
2012-08-29 15:57:03 +02:00
|
|
|
layout->addWidget(m_stackedWidget.data(), 3, 0, 1, 1);
|
2010-03-10 12:45:49 +02:00
|
|
|
|
|
|
|
|
setResourcePath(QDir::currentPath());
|
|
|
|
|
setSearchFilter(QString());
|
|
|
|
|
|
|
|
|
|
/* style sheets */
|
2014-05-12 14:09:02 +02:00
|
|
|
setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css")));
|
|
|
|
|
m_resourcesView->setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::setItemLibraryInfo(ItemLibraryInfo *itemLibraryInfo)
|
2010-03-10 12:45:49 +02:00
|
|
|
{
|
2012-08-29 15:57:03 +02:00
|
|
|
if (m_itemLibraryInfo.data() == itemLibraryInfo)
|
2010-05-12 11:56:23 +02:00
|
|
|
return;
|
|
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
if (m_itemLibraryInfo)
|
|
|
|
|
disconnect(m_itemLibraryInfo.data(), SIGNAL(entriesChanged()),
|
2010-05-12 11:56:23 +02:00
|
|
|
this, SLOT(updateModel()));
|
2012-08-29 15:57:03 +02:00
|
|
|
m_itemLibraryInfo = itemLibraryInfo;
|
2010-05-12 11:56:23 +02:00
|
|
|
if (itemLibraryInfo)
|
2012-08-29 15:57:03 +02:00
|
|
|
connect(m_itemLibraryInfo.data(), SIGNAL(entriesChanged()),
|
2010-05-12 11:56:23 +02:00
|
|
|
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;
|
2012-08-29 15:57:03 +02:00
|
|
|
if (m_model) {
|
2010-12-14 16:52:29 +01:00
|
|
|
QStringList imports;
|
2012-08-29 15:57:03 +02:00
|
|
|
foreach (const Import &import, m_model->imports())
|
2010-12-14 16:52:29 +01:00
|
|
|
if (import.isLibraryImport())
|
|
|
|
|
imports << import.url();
|
2011-08-22 11:43:03 +02:00
|
|
|
if (imports.contains("com.nokia.meego", Qt::CaseInsensitive))
|
2010-12-14 16:52:29 +01:00
|
|
|
filter = Meego;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setImportFilter(filter);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-14 17:42:48 +02:00
|
|
|
void ItemLibraryWidget::setImportsWidget(QWidget *importsWidget)
|
|
|
|
|
{
|
|
|
|
|
m_stackedWidget->addWidget(importsWidget);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
QList<QToolButton *> ItemLibraryWidget::createToolBarWidgets()
|
|
|
|
|
{
|
|
|
|
|
QList<QToolButton *> buttons;
|
2011-03-10 13:13:39 +01:00
|
|
|
|
2011-05-10 15:19:38 +02:00
|
|
|
return buttons; //import management gets disabled for now (TODO ###)
|
2011-03-10 13:13:39 +01:00
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
buttons << new QToolButton();
|
2012-12-05 22:57:32 +02:00
|
|
|
buttons.first()->setText(tr("I "));
|
2010-12-14 16:52:29 +01:00
|
|
|
buttons.first()->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER)));
|
2014-03-13 09:55:53 +01:00
|
|
|
buttons.first()->setToolTip(tr("Manage imports for components."));
|
2010-12-14 16:52:29 +01:00
|
|
|
buttons.first()->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
QMenu * menu = new QMenu;
|
|
|
|
|
QAction * basicQtAction = new QAction(menu);
|
|
|
|
|
basicQtAction->setCheckable(true);
|
2012-12-05 22:57:32 +02:00
|
|
|
basicQtAction->setText(tr("Basic Qt Quick only"));
|
2010-12-14 16:52:29 +01:00
|
|
|
QAction * meegoAction= new QAction(menu);
|
|
|
|
|
meegoAction->setCheckable(true);
|
2012-12-05 22:57:32 +02:00
|
|
|
meegoAction->setText(tr("Meego Components"));
|
2010-12-14 16:52:29 +01:00
|
|
|
menu->addAction(basicQtAction);
|
|
|
|
|
menu->addAction(meegoAction);
|
|
|
|
|
buttons.first()->setMenu(menu);
|
|
|
|
|
|
|
|
|
|
connect(basicQtAction, SIGNAL(toggled(bool)), this, SLOT(onQtBasicOnlyChecked(bool)));
|
|
|
|
|
connect(this, SIGNAL(qtBasicOnlyChecked(bool)), basicQtAction, 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
|
|
|
{
|
2012-08-29 15:57:03 +02:00
|
|
|
if (m_stackedWidget->currentIndex() == 0) {
|
|
|
|
|
m_itemLibraryModel->setSearchText(searchFilter);
|
2010-03-10 12:45:49 +02:00
|
|
|
emit resetItemsView();
|
2012-08-29 15:57:03 +02:00
|
|
|
m_itemsView->update();
|
2010-02-16 17:24:18 +02:00
|
|
|
} else {
|
|
|
|
|
QStringList nameFilterList;
|
|
|
|
|
if (searchFilter.contains('.')) {
|
|
|
|
|
nameFilterList.append(QString("*%1*").arg(searchFilter));
|
|
|
|
|
} else {
|
|
|
|
|
foreach (const QByteArray &extension, QImageReader::supportedImageFormats()) {
|
2013-03-05 12:19:19 +01:00
|
|
|
nameFilterList.append(QString("*%1*.%2").arg(searchFilter, QString::fromUtf8(extension)));
|
2010-02-16 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
m_resourcesFileSystemModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
m_resourcesFileSystemModel->setNameFilterDisables(false);
|
|
|
|
|
m_resourcesFileSystemModel->setNameFilters(nameFilterList);
|
|
|
|
|
m_resourcesView->expandToDepth(1);
|
|
|
|
|
m_resourcesView->scrollToTop();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 22:01:55 +01:00
|
|
|
void ItemLibraryWidget::setModel(Model *model)
|
|
|
|
|
{
|
2012-08-29 15:57:03 +02:00
|
|
|
m_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();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-20 17:49:40 +01:00
|
|
|
void ItemLibraryWidget::emitImportChecked()
|
|
|
|
|
{
|
2012-08-29 15:57:03 +02:00
|
|
|
if (!m_model)
|
2011-01-20 17:49:40 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool qtOnlyImport = false;
|
|
|
|
|
bool meegoImport = false;
|
|
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
foreach (const Import &import, m_model->imports()) {
|
2011-01-20 17:49:40 +01:00
|
|
|
if (import.isLibraryImport()) {
|
|
|
|
|
if (import.url().contains(QString("meego"), Qt::CaseInsensitive))
|
|
|
|
|
meegoImport = true;
|
|
|
|
|
if (import.url().contains(QString("Qt"), Qt::CaseInsensitive) || import.url().contains(QString("QtQuick"), Qt::CaseInsensitive))
|
|
|
|
|
qtOnlyImport = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 13:27:25 +02:00
|
|
|
if (meegoImport)
|
2011-01-20 17:49:40 +01:00
|
|
|
qtOnlyImport = false;
|
|
|
|
|
|
|
|
|
|
emit qtBasicOnlyChecked(qtOnlyImport);
|
|
|
|
|
emit meegoChecked(meegoImport);
|
|
|
|
|
}
|
2010-12-14 16:52:29 +01:00
|
|
|
|
2013-08-15 13:09:54 +02:00
|
|
|
void ItemLibraryWidget::setCurrentIndexOfStackedWidget(int index)
|
|
|
|
|
{
|
2013-08-15 13:10:37 +02:00
|
|
|
if (index == 2)
|
|
|
|
|
m_filterLineEdit->setVisible(false);
|
|
|
|
|
else
|
|
|
|
|
m_filterLineEdit->setVisible(true);
|
|
|
|
|
|
2013-08-15 13:09:54 +02:00
|
|
|
m_stackedWidget->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
void ItemLibraryWidget::setImportFilter(FilterChangeFlag flag)
|
|
|
|
|
{
|
2011-06-30 17:20:40 +02:00
|
|
|
return;
|
2010-12-15 16:18:34 +01:00
|
|
|
|
|
|
|
|
static bool block = false;
|
2012-08-29 15:57:03 +02:00
|
|
|
if (!m_model)
|
2010-12-14 16:52:29 +01:00
|
|
|
return;
|
|
|
|
|
if (flag == m_filterFlag)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-12-15 16:18:34 +01:00
|
|
|
if (block == true)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-12-16 11:01:22 +01:00
|
|
|
|
2011-01-20 17:49:40 +01:00
|
|
|
FilterChangeFlag oldfilterFlag = m_filterFlag;
|
|
|
|
|
|
|
|
|
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
try {
|
|
|
|
|
block = true;
|
2012-08-22 13:27:25 +02:00
|
|
|
if (flag == QtBasic)
|
2014-05-12 14:09:02 +02:00
|
|
|
removeImport(QStringLiteral("com.nokia.meego"));
|
2012-08-22 13:27:25 +02:00
|
|
|
else if (flag == Meego)
|
2014-05-12 14:09:02 +02:00
|
|
|
addImport(QStringLiteral("com.nokia.meego"), QStringLiteral("1.0"));
|
2011-01-20 17:49:40 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
block = false;
|
|
|
|
|
m_filterFlag = flag;
|
2011-05-09 14:36:28 +02:00
|
|
|
} catch (RewritingException &) {
|
2011-01-20 17:49:40 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
|
m_filterFlag = oldfilterFlag;
|
|
|
|
|
block = false;
|
|
|
|
|
// do something about it
|
2010-12-14 16:52:29 +01:00
|
|
|
}
|
2011-01-20 17:49:40 +01:00
|
|
|
|
|
|
|
|
emitImportChecked();
|
2010-12-14 16:52:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::onQtBasicOnlyChecked(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (b)
|
|
|
|
|
setImportFilter(QtBasic);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::onMeegoChecked(bool b)
|
|
|
|
|
{
|
|
|
|
|
if (b)
|
|
|
|
|
setImportFilter(Meego);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-10 17:57:42 +01:00
|
|
|
void ItemLibraryWidget::updateModel()
|
2010-05-12 11:56:23 +02:00
|
|
|
{
|
2012-08-29 15:57:03 +02:00
|
|
|
m_itemLibraryModel->update(m_itemLibraryInfo.data(), m_model.data());
|
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
|
|
|
{
|
2013-08-15 13:09:54 +02:00
|
|
|
setSearchFilter(m_filterLineEdit->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
|
|
|
{
|
2012-08-29 15:57:03 +02:00
|
|
|
if (m_resourcesView->model() == m_resourcesFileSystemModel.data()) {
|
|
|
|
|
m_resourcesFileSystemModel->setRootPath(resourcePath);
|
|
|
|
|
m_resourcesView->setRootIndex(m_resourcesFileSystemModel->index(resourcePath));
|
2011-07-27 13:32:10 +02:00
|
|
|
}
|
2010-04-19 14:36:02 +03:00
|
|
|
updateSearch();
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-06 15:20:54 +01:00
|
|
|
void ItemLibraryWidget::startDragAndDropDelayed(int itemLibraryId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-01-06 15:20:54 +01:00
|
|
|
m_itemLibraryId = itemLibraryId;
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(startDragAndDrop()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::startDragAndDrop()
|
|
|
|
|
{
|
|
|
|
|
QMimeData *mimeData = m_itemLibraryModel->getMimeData(m_itemLibraryId);
|
2013-11-19 17:44:16 +01:00
|
|
|
QDrag *drag = new QDrag(this);
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2014-01-06 15:20:54 +01:00
|
|
|
drag->setPixmap(m_itemLibraryModel->getIcon(m_itemLibraryId).pixmap(32, 32));
|
2010-02-16 17:24:18 +02:00
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
void ItemLibraryWidget::removeImport(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
if (!m_model)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<Import> toBeRemovedImportList;
|
|
|
|
|
foreach (const Import &import, m_model->imports())
|
|
|
|
|
if (import.isLibraryImport() && import.url().compare(name, Qt::CaseInsensitive) == 0)
|
|
|
|
|
toBeRemovedImportList.append(import);
|
2011-02-10 15:44:40 +01:00
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
m_model->changeImports(QList<Import>(), toBeRemovedImportList);
|
|
|
|
|
}
|
2011-02-10 15:44:40 +01:00
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
void ItemLibraryWidget::addImport(const QString &name, const QString &version)
|
|
|
|
|
{
|
|
|
|
|
if (!m_model)
|
|
|
|
|
return;
|
|
|
|
|
m_model->changeImports(QList<Import>() << Import::createLibraryImport(name, version), QList<Import>());
|
|
|
|
|
}
|
2010-12-14 16:52:29 +01:00
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
QIcon ItemLibraryFileIconProvider::icon(const QFileInfo &info) const
|
|
|
|
|
{
|
|
|
|
|
QPixmap pixmap(info.absoluteFilePath());
|
|
|
|
|
if (pixmap.isNull()) {
|
|
|
|
|
QIcon defaultIcon(QFileIconProvider::icon(info));
|
|
|
|
|
pixmap = defaultIcon.pixmap(defaultIcon.actualSize(m_iconSize));
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-31 14:22:35 +01:00
|
|
|
if (pixmap.isNull())
|
|
|
|
|
return pixmap;
|
|
|
|
|
|
2012-08-29 15:57:03 +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()))
|
|
|
|
|
return pixmap.scaled(m_iconSize, Qt::KeepAspectRatio,
|
|
|
|
|
Qt::SmoothTransformation);
|
|
|
|
|
|
|
|
|
|
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-12-14 16:52:29 +01:00
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
ItemLibraryFileIconProvider::ItemLibraryFileIconProvider(const QSize &iconSize)
|
|
|
|
|
: QFileIconProvider(),
|
|
|
|
|
m_iconSize(iconSize)
|
|
|
|
|
{}
|
2010-01-07 12:14:35 +01:00
|
|
|
}
|