Commit fc2822fa authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Cleanup handling of favorite effects and make effect basket (favorites) work again

parent ff834f9b
......@@ -190,6 +190,11 @@ QVariant TreeItem::dataColumn(int column) const
return m_itemData.value(column);
}
void TreeItem::setData(int column, const QVariant dataColumn)
{
m_itemData[column] = dataColumn;
}
std::weak_ptr<TreeItem> TreeItem::parentItem() const
{
return m_parentItem;
......
......@@ -104,6 +104,7 @@ public:
@param column Index of the column to look-up
*/
QVariant dataColumn(int column) const;
void setData(int column, const QVariant dataColumn);
/* @brief Return the index of current item amongst father's children
Returns -1 on error (eg: no parent set)
......
......@@ -57,9 +57,6 @@ public:
/* @brief Return description of asset */
QString getDescription(const QString &assetId) const;
/* @brief Check whether a given asset is favorite */
bool isFavorite(const QString &assetId) const;
/* @brief Set an asset as favorite (or not)*/
virtual void setFavorite(const QString & assetId, bool favorite) = 0;
......@@ -75,7 +72,6 @@ protected:
double version;
QDomElement xml;
AssetType type;
bool favorite = false;
};
// Reads the blacklist file and populate appropriate structure
......
......@@ -175,12 +175,6 @@ template <typename AssetType> QString AbstractAssetsRepository<AssetType>::getDe
return m_assets.at(assetId).description;
}
template <typename AssetType> bool AbstractAssetsRepository<AssetType>::isFavorite(const QString & assetId) const
{
Q_ASSERT(m_assets.count(assetId) > 0);
return m_assets.at(assetId).favorite;
}
template <typename AssetType> bool AbstractAssetsRepository<AssetType>::parseInfoFromXml(const QDomElement &currentAsset, Info &res) const
{
QLocale locale;
......
......@@ -39,6 +39,7 @@ QHash<int, QByteArray> AssetTreeModel::roleNames() const
QHash<int, QByteArray> roles;
roles[IdRole] = "identifier";
roles[NameRole] = "name";
roles[FavoriteRole] = "favorite";
return roles;
}
......@@ -63,14 +64,7 @@ bool AssetTreeModel::isFavorite(const QModelIndex &index) const
if (item->depth() == 1) {
return false;
}
auto id = item->dataColumn(AssetTreeModel::idCol).toString();
if (EffectsRepository::get()->exists(id)) {
return EffectsRepository::get()->isFavorite(id);
}
if (TransitionsRepository::get()->exists(id)) {
return TransitionsRepository::get()->isFavorite(id);
}
return false;
return item->dataColumn(AssetTreeModel::favCol).toBool();
}
void AssetTreeModel::setFavorite(const QModelIndex &index, bool favorite)
......@@ -82,6 +76,7 @@ void AssetTreeModel::setFavorite(const QModelIndex &index, bool favorite)
if (item->depth() == 1) {
return;
}
item->setData(AssetTreeModel::favCol, favorite);
auto id = item->dataColumn(AssetTreeModel::idCol).toString();
if (EffectsRepository::get()->exists(id)) {
EffectsRepository::get()->setFavorite(id, favorite);
......@@ -119,6 +114,9 @@ QVariant AssetTreeModel::data(const QModelIndex &index, int role) const
if (role == IdRole) {
return item->dataColumn(AssetTreeModel::idCol);
}
if (role == FavoriteRole) {
return item->dataColumn(AssetTreeModel::favCol);
}
if (role != NameRole) {
return QVariant();
......
......@@ -33,7 +33,7 @@ class AssetTreeModel : public AbstractTreeModel
public:
explicit AssetTreeModel(QObject *parent = 0);
enum { IdRole = Qt::UserRole + 1, NameRole };
enum { IdRole = Qt::UserRole + 1, NameRole, FavoriteRole };
// Helper function to retrieve name
QString getName(const QModelIndex &index) const;
......
......@@ -74,6 +74,7 @@ bool AssetListWidget::isFavorite(const QModelIndex &index) const
void AssetListWidget::setFavorite(const QModelIndex &index, bool favorite)
{
return m_model->setFavorite(m_proxyModel->mapToSource(index), favorite);
}
QString AssetListWidget::getDescription(const QModelIndex &index) const
......
......@@ -220,7 +220,6 @@ Rectangle {
Layout.fillWidth: true
alternatingRowColors: false
headerVisible: false
property var selectedAssetImage: undefined
selection: sel
selectionMode: SelectionMode.SingleSelection
itemDelegate: Rectangle {
......@@ -250,12 +249,19 @@ Rectangle {
Image{
id: assetThumb
visible: assetDelegate.isItem
property bool isFavorite: model.favorite
onIsFavoriteChanged: {
// ''
//cache = false
//source = 'image://asseticon/' + styleData.value
}
height: parent.height
width: height
source: 'image://asseticon/' + styleData.value
}
Label {
id: text
id: assetText
font.bold : assetThumb.isFavorite
text: assetlist.getName(styleData.index)
}
}
......@@ -278,7 +284,7 @@ Rectangle {
})
} else {
drag.target = undefined
treeView.selectedAssetImage = assetThumb
assetContextMenu.isItemFavorite = assetThumb.isFavorite
assetContextMenu.popup()
mouse.accepted = false
}
......@@ -301,17 +307,15 @@ Rectangle {
}
Menu {
id: assetContextMenu
property bool isItemFavorite
MenuItem {
id: favMenu
text: assetlist.isFavorite(sel.currentIndex) ? "Remove from favorites" : "Add to favorites"
text: assetContextMenu.isItemFavorite ? "Remove from favorites" : "Add to favorites"
property url thumbSource
onTriggered: {
assetlist.setFavorite(sel.currentIndex, !assetlist.isFavorite(sel.currentIndex))
assetlist.setFavorite(sel.currentIndex, !assetContextMenu.isItemFavorite)
// Force thumb reload
thumbSource = treeView.selectedAssetImage.source
treeView.selectedAssetImage.source = ''
treeView.selectedAssetImage.cache = false
treeView.selectedAssetImage.source = thumbSource
}
}
}
......
......@@ -80,38 +80,19 @@ QImage AssetIconProvider::makeIcon(const QString &effectId, const QString &effec
QString t = QStringLiteral("#") + QString::number(hex, 16).toUpper().left(6);
QColor col(t);
bool isAudio = false;
bool isFavorite = false;
if (m_effect) {
isAudio = EffectsRepository::get()->getType(effectId) == EffectType::Audio;
isFavorite = EffectsRepository::get()->isFavorite(effectId);
} else {
auto type = TransitionsRepository::get()->getType(effectId);
isAudio = (type == TransitionType::AudioComposition) || (type == TransitionType::AudioTransition);
isFavorite = TransitionsRepository::get()->isFavorite(effectId);
}
if (isAudio || isFavorite) {
if (isAudio) {
pix.fill(Qt::transparent);
} else {
pix.fill(col);
}
QPainter p(&pix);
if (isFavorite) {
p.setPen(Qt::NoPen);
p.setBrush(col);
static const QPointF points[3] = {
QPointF(2, 23),
QPointF(15, 0),
QPointF(28, 23)
};
p.drawPolygon(points, 3);
static const QPointF points2[3] = {
QPointF(2, 8),
QPointF(15, 30),
QPointF(28, 8)
};
p.drawPolygon(points2, 3);
p.setPen(QPen());
} else if (isAudio) {
if (isAudio) {
p.setPen(Qt::NoPen);
p.setBrush(col);
p.drawEllipse(pix.rect());
......
......@@ -96,7 +96,7 @@ std::shared_ptr<EffectTreeModel> EffectTreeModel::construct(const QString &categ
// we create the data list corresponding to this profile
QList<QVariant> data;
bool isFav = EffectsRepository::get()->isFavorite(effect.first);
bool isFav = KdenliveSettings::favorite_effects().contains(effect.first);
qDebug() << effect.second << effect.first << "in " << targetCategory->dataColumn(0).toString();
data << effect.second << effect.first << QVariant::fromValue(type) << isFav;
......
......@@ -47,6 +47,11 @@ EffectListWidget::EffectListWidget(QWidget *parent)
setup();
}
void EffectListWidget::updateFavorite(const QModelIndex &index)
{
m_proxyModel->dataChanged(index, index, QVector<int>());
}
EffectListWidget::~EffectListWidget()
{
delete m_proxy;
......@@ -71,3 +76,4 @@ QString EffectListWidget::getMimeType(const QString &assetId) const
Q_UNUSED(assetId);
return QStringLiteral("kdenlive/effect");
}
......@@ -43,6 +43,7 @@ public:
/*@brief Return mime type used for drag and drop. It will be kdenlive/effect*/
QString getMimeType(const QString &assetId) const override;
void updateFavorite(const QModelIndex &index);
private:
EffectListWidgetProxy *m_proxy;
......@@ -65,7 +66,7 @@ public:
}
Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); }
Q_INVOKABLE bool isFavorite(const QModelIndex &index) const { return q->isFavorite(index); }
Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite); q->reloadBasket();}
Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite); q->updateFavorite(index); q->reloadBasket();}
Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
......
......@@ -55,10 +55,8 @@ void EffectsRepository::setFavorite(const QString &id, bool favorite)
Q_ASSERT(exists(id));
if (favorite) {
m_favorites << id;
m_assets[id].favorite = true;
} else {
m_favorites.remove(id);
m_assets[id].favorite = false;
}
KdenliveSettings::setFavorite_effects(QStringList::fromSet(m_favorites));
}
......@@ -82,10 +80,6 @@ void EffectsRepository::parseCustomAssetFile(const QString &file_name, std::unor
info.type = EffectType::Custom;
QString tag = base.attribute(QStringLiteral("tag"), QString());
QString id = base.hasAttribute(QStringLiteral("id")) ? base.attribute(QStringLiteral("id")) : tag;
if (m_favorites.contains(id)) {
info.favorite = true;
}
QString name = base.attribute(QStringLiteral("name"), QString());
info.name = name;
info.id = id;
......@@ -132,9 +126,6 @@ void EffectsRepository::parseCustomAssetFile(const QString &file_name, std::unor
} else {
result.type = EffectType::Video;
}
if (m_favorites.contains(result.id)) {
result.favorite = true;
}
customAssets[result.id] = result;
}
......@@ -158,9 +149,6 @@ void EffectsRepository::parseType(QScopedPointer<Mlt::Properties> &metadata, Inf
if (QString(tags.get(0)) == QLatin1String("Audio")) {
res.type = EffectType::Audio;
}
if (m_favorites.contains(res.id)) {
res.favorite = true;
}
}
QString EffectsRepository::assetBlackListPath() const
......
......@@ -18,30 +18,32 @@
***************************************************************************/
#include "effectbasket.h"
#include "effectslistview.h"
#include "effectslistwidget.h"
#include "kdenlivesettings.h"
#include "effects/effectsrepository.hpp"
#include <klocalizedstring.h>
#include <QDomDocument>
#include <QListWidget>
#include <QMimeData>
EffectBasket::EffectBasket(EffectsListView *effectList)
: QListWidget(effectList)
, m_effectList(effectList)
EffectBasket::EffectBasket(QWidget *parent)
: QListWidget(parent)
{
setFrameStyle(QFrame::NoFrame);
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
m_effectList->creatFavoriteBasket(this);
slotReloadBasket();
connect(this, &QListWidget::itemActivated, this, &EffectBasket::slotAddEffect);
}
void EffectBasket::slotReloadBasket()
{
m_effectList->creatFavoriteBasket(this);
for (const QString &effectId : KdenliveSettings::favorite_effects()) {
if (EffectsRepository::get()->exists(effectId)) {
QListWidgetItem *it = new QListWidgetItem(EffectsRepository::get()->getName(effectId));
it->setData(Qt::UserRole, effectId);
addItem(it);
}
}
}
QMimeData *EffectBasket::mimeData(const QList<QListWidgetItem *> list) const
......@@ -51,12 +53,9 @@ QMimeData *EffectBasket::mimeData(const QList<QListWidgetItem *> list) const
}
QDomDocument doc;
QListWidgetItem *item = list.at(0);
int type = item->data(EffectsListWidget::TypeRole).toInt();
QStringList info = item->data(EffectsListWidget::IdRole).toStringList();
QDomElement effect = EffectsListWidget::itemEffect(type, info);
doc.appendChild(doc.importNode(effect, true));
QString effectId = item->data(Qt::UserRole).toString();
auto *mime = new QMimeData;
mime->setData(QStringLiteral("kdenlive/effectslist"), doc.toString().toUtf8());
mime->setData(QStringLiteral("kdenlive/effect"), effectId.toUtf8());
return mime;
}
......@@ -70,8 +69,8 @@ void EffectBasket::showEvent(QShowEvent *event)
void EffectBasket::slotAddEffect(QListWidgetItem *item)
{
int type = item->data(EffectsListWidget::TypeRole).toInt();
QStringList info = item->data(EffectsListWidget::IdRole).toStringList();
QDomElement effect = EffectsListWidget::itemEffect(type, info);
emit addEffect(effect);
QString assetId = item->data(Qt::UserRole).toString();
QVariantMap mimeData;
mimeData.insert(QStringLiteral("kdenlive/effect"), assetId);
emit activateAsset(mimeData);
}
......@@ -20,11 +20,8 @@
#ifndef EFFECTBASKET_H
#define EFFECTBASKET_H
#include <QDomElement>
#include <QListWidget>
class EffectsListView;
/**
* @class EffectBasket
* @brief A list of favorite effects that can be embedded in a toolbar
......@@ -36,15 +33,12 @@ class EffectBasket : public QListWidget
Q_OBJECT
public:
explicit EffectBasket(EffectsListView *effectList);
explicit EffectBasket(QWidget *parent);
protected:
QMimeData *mimeData(const QList<QListWidgetItem *> list) const override;
void showEvent(QShowEvent *event) override;
private:
EffectsListView *m_effectList;
public slots:
void slotReloadBasket();
......@@ -52,7 +46,7 @@ private slots:
void slotAddEffect(QListWidgetItem *item);
signals:
void addEffect(const QDomElement &);
void activateAsset(const QVariantMap &);
};
#endif
......@@ -400,9 +400,9 @@ void MainWindow::init()
buildDynamicActions();
// Create Effect Basket (dropdown list of favorites)
m_effectBasket = new EffectBasket(m_effectList);
m_effectBasket = new EffectBasket(this);
connect(m_effectBasket, &EffectBasket::activateAsset, pCore->projectManager(), &ProjectManager::activateAsset);
connect(m_effectList2, &EffectListWidget::reloadBasket, m_effectBasket, &EffectBasket::slotReloadBasket);
connect(m_effectBasket, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
auto *widgetlist = new QWidgetAction(this);
widgetlist->setDefaultWidget(m_effectBasket);
// widgetlist->setText(i18n("Favorite Effects"));
......
......@@ -66,7 +66,7 @@ std::shared_ptr<TransitionTreeModel> TransitionTreeModel::construct(bool flat, Q
// we create the data list corresponding to this transition
QList<QVariant> data;
bool isFav = TransitionsRepository::get()->isFavorite(transition.first);
bool isFav = KdenliveSettings::favorite_effects().contains(transition.first);
qDebug() << transition.second << transition.first << "in " << targetCategory->dataColumn(0).toString();
data << transition.second << transition.first << QVariant::fromValue(type) << isFav;
......
......@@ -55,10 +55,8 @@ void TransitionsRepository::setFavorite(const QString &id, bool favorite)
Q_ASSERT(exists(id));
if (favorite) {
m_favorites << id;
m_assets[id].favorite = true;
} else {
m_favorites.remove(id);
m_assets[id].favorite = false;
}
KdenliveSettings::setFavorite_transitions(QStringList::fromSet(m_favorites));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment