2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2010-01-07 12:14:35 +01:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.GPLv3 included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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>
|
2014-06-11 13:44:04 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2014-06-06 16:06:32 +02:00
|
|
|
#include <utils/stylehelper.h>
|
|
|
|
|
|
2010-12-14 16:52:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2014-06-11 13:44:04 +02:00
|
|
|
#include <coreplugin/icore.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>
|
2014-06-11 13:44:04 +02:00
|
|
|
#include <QShortcut>
|
2013-09-13 17:06:10 +02:00
|
|
|
#include <QQuickItem>
|
2010-01-07 12:14:35 +01:00
|
|
|
|
2014-06-30 14:53:34 +02:00
|
|
|
#include <private/qquickwidget_p.h> // mouse ungrabbing workaround on quickitems
|
|
|
|
|
#include <private/qquickwindow_p.h> // mouse ungrabbing workaround on quickitems
|
|
|
|
|
|
|
|
|
|
|
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),
|
2014-09-11 15:49:10 +02:00
|
|
|
m_itemViewQuickWidget(new QQuickWidget),
|
2014-05-14 14:26:06 +02:00
|
|
|
m_resourcesView(new ItemLibraryTreeView(this)),
|
2014-06-19 17:50:34 +02:00
|
|
|
m_filterFlag(QtBasic)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-05-15 17:52:13 +02:00
|
|
|
ItemLibraryModel::registerQmlTypes();
|
2013-08-06 16:45:59 +02: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 */
|
2014-09-11 15:49:10 +02:00
|
|
|
m_itemViewQuickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
2014-05-14 14:26:06 +02:00
|
|
|
m_itemLibraryModel = new ItemLibraryModel(this);
|
2012-08-29 15:57:03 +02:00
|
|
|
|
2014-09-11 15:49:10 +02:00
|
|
|
QQmlContext *rootContext = m_itemViewQuickWidget->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());
|
2014-06-19 17:50:34 +02:00
|
|
|
rootContext->setContextProperty(QStringLiteral("rootView"), this);
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2014-09-11 15:49:10 +02:00
|
|
|
m_itemViewQuickWidget->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
|
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-09-11 15:49:10 +02:00
|
|
|
m_itemViewQuickWidget->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
|
|
|
|
2014-09-11 15:49:10 +02:00
|
|
|
|
2012-08-29 15:57:03 +02:00
|
|
|
m_stackedWidget = new QStackedWidget(this);
|
2014-09-11 15:49:10 +02:00
|
|
|
m_stackedWidget->addWidget(m_itemViewQuickWidget.data());
|
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 */
|
2015-07-16 17:06:52 +02:00
|
|
|
setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/stylesheet.css"))));
|
|
|
|
|
m_resourcesView->setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(QLatin1String(":/qmldesigner/scrollbar.css"))));
|
2014-06-11 13:44:04 +02:00
|
|
|
|
|
|
|
|
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F5), this);
|
|
|
|
|
connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));
|
|
|
|
|
|
|
|
|
|
// init the first load of the QML UI elements
|
|
|
|
|
reloadQmlSource();
|
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();
|
2015-07-16 17:06:52 +02:00
|
|
|
if (imports.contains(QLatin1String("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;
|
|
|
|
|
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);
|
2014-09-11 15:49:10 +02:00
|
|
|
m_itemViewQuickWidget->update();
|
2010-02-16 17:24:18 +02:00
|
|
|
} else {
|
|
|
|
|
QStringList nameFilterList;
|
2015-07-16 17:06:52 +02:00
|
|
|
if (searchFilter.contains(QLatin1Char('.'))) {
|
|
|
|
|
nameFilterList.append(QString(QStringLiteral("*%1*")).arg(searchFilter));
|
2010-02-16 17:24:18 +02:00
|
|
|
} else {
|
|
|
|
|
foreach (const QByteArray &extension, QImageReader::supportedImageFormats()) {
|
2015-07-16 17:06:52 +02:00
|
|
|
nameFilterList.append(QString(QStringLiteral("*%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()) {
|
2015-07-16 17:06:52 +02:00
|
|
|
if (import.url().contains(QLatin1String("meego"), Qt::CaseInsensitive))
|
2011-01-20 17:49:40 +01:00
|
|
|
meegoImport = true;
|
2015-07-16 17:06:52 +02:00
|
|
|
if (import.url().contains(QLatin1String("Qt"), Qt::CaseInsensitive) || import.url().contains(QLatin1String("QtQuick"), Qt::CaseInsensitive))
|
2011-01-20 17:49:40 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 13:44:04 +02:00
|
|
|
QString ItemLibraryWidget::qmlSourcesPath()
|
|
|
|
|
{
|
|
|
|
|
return Core::ICore::resourcePath() + QStringLiteral("/qmldesigner/itemLibraryQmlSources");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ItemLibraryWidget::reloadQmlSource()
|
|
|
|
|
{
|
|
|
|
|
QString itemLibraryQmlFilePath = qmlSourcesPath() + QStringLiteral("/ItemsView.qml");
|
|
|
|
|
QTC_ASSERT(QFileInfo::exists(itemLibraryQmlFilePath), return);
|
2014-09-11 15:49:10 +02:00
|
|
|
m_itemViewQuickWidget->engine()->clearComponentCache();
|
|
|
|
|
m_itemViewQuickWidget->setSource(QUrl::fromLocalFile(itemLibraryQmlFilePath));
|
2014-06-11 13:44:04 +02:00
|
|
|
}
|
|
|
|
|
|
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;
|
2014-11-28 11:15:37 +01:00
|
|
|
} catch (const 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-09-11 15:49:10 +02:00
|
|
|
static void ungrabMouseOnQMLWorldWorkAround(QQuickWidget *quickWidget)
|
2014-06-30 14:53:34 +02:00
|
|
|
{
|
2014-09-11 15:49:10 +02:00
|
|
|
const QQuickWidgetPrivate *widgetPrivate = QQuickWidgetPrivate::get(quickWidget);
|
|
|
|
|
if (widgetPrivate && widgetPrivate->offscreenWindow && widgetPrivate->offscreenWindow->mouseGrabberItem())
|
|
|
|
|
widgetPrivate->offscreenWindow->mouseGrabberItem()->ungrabMouse();
|
2014-06-30 14:53:34 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-30 13:32:13 +02:00
|
|
|
void ItemLibraryWidget::startDragAndDrop(QVariant itemLibraryId)
|
2010-01-07 12:14:35 +01:00
|
|
|
{
|
2014-06-19 17:50:34 +02:00
|
|
|
m_currentitemLibraryEntry = itemLibraryId.value<ItemLibraryEntry>();
|
2014-01-06 15:20:54 +01:00
|
|
|
|
2014-06-19 17:50:34 +02:00
|
|
|
QMimeData *mimeData = m_itemLibraryModel->getMimeData(m_currentitemLibraryEntry);
|
2013-11-19 17:44:16 +01:00
|
|
|
QDrag *drag = new QDrag(this);
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2014-06-19 17:50:34 +02:00
|
|
|
drag->setPixmap(m_currentitemLibraryEntry.libraryEntryIconPath());
|
2010-02-16 17:24:18 +02:00
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
|
|
|
|
|
|
drag->exec();
|
2014-06-30 14:53:34 +02:00
|
|
|
|
2014-09-11 15:49:10 +02:00
|
|
|
ungrabMouseOnQMLWorldWorkAround(m_itemViewQuickWidget.data());
|
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
|
|
|
}
|