Effects can now be switched as favorites from effects list widget and appear...

Effects can now be switched as favorites from effects list widget and appear in the favorite effect basket
parent 54813bbe
......@@ -60,6 +60,9 @@ public:
/* @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;
/* @brief Returns a DomElement representing the asset's properties */
QDomElement getXml(const QString &assetId) const;
......
......@@ -73,6 +73,23 @@ bool AssetTreeModel::isFavorite(const QModelIndex &index) const
return false;
}
void AssetTreeModel::setFavorite(const QModelIndex &index, bool favorite)
{
if (!index.isValid()) {
return;
}
std::shared_ptr<TreeItem> item = getItemById((int)index.internalId());
if (item->depth() == 1) {
return;
}
auto id = item->dataColumn(AssetTreeModel::idCol).toString();
if (EffectsRepository::get()->exists(id)) {
EffectsRepository::get()->setFavorite(id, favorite);
} else if (TransitionsRepository::get()->exists(id)) {
TransitionsRepository::get()->setFavorite(id, favorite);
}
}
QString AssetTreeModel::getDescription(const QModelIndex &index) const
{
if (!index.isValid()) {
......
......@@ -41,6 +41,7 @@ public:
QString getDescription(const QModelIndex &index) const;
// Helper function to retrieve if an effect is categorized as favorite
bool isFavorite(const QModelIndex &index) const;
void setFavorite(const QModelIndex &index, bool favorite);
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
......
......@@ -23,6 +23,7 @@
#include "assets/assetlist/view/qmltypes/asseticonprovider.hpp"
#include <KDeclarative/KDeclarative>
#include <kdeclarative_version.h>
#include <QQmlContext>
#include <QQuickItem>
#include <QStandardPaths>
......@@ -33,7 +34,12 @@ AssetListWidget::AssetListWidget(QWidget *parent)
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
#if KDECLARATIVE_VERSION >= QT_VERSION_CHECK(5, 45, 0)
kdeclarative.setupEngine(engine());
kdeclarative.setupContext();
#else
kdeclarative.setupBindings();
#endif
}
AssetListWidget::~AssetListWidget()
......@@ -65,6 +71,11 @@ bool AssetListWidget::isFavorite(const QModelIndex &index) const
return m_model->isFavorite(m_proxyModel->mapToSource(index));
}
void AssetListWidget::setFavorite(const QModelIndex &index, bool favorite)
{
return m_model->setFavorite(m_proxyModel->mapToSource(index), favorite);
}
QString AssetListWidget::getDescription(const QModelIndex &index) const
{
return m_model->getDescription(m_proxyModel->mapToSource(index));
......
......@@ -48,6 +48,9 @@ public:
/* @brief Returns true if this effect belongs to favorites */
bool isFavorite(const QModelIndex &index) const;
/* @brief Returns true if this effect belongs to favorites */
void setFavorite(const QModelIndex &index, bool favorite = true);
/* @brief Returns the description of the asset given its model index */
QString getDescription(const QModelIndex &index) const;
......
......@@ -220,6 +220,7 @@ Rectangle {
Layout.fillWidth: true
alternatingRowColors: false
headerVisible: false
property var selectedAssetImage: undefined
selection: sel
selectionMode: SelectionMode.SingleSelection
itemDelegate: Rectangle {
......@@ -247,6 +248,7 @@ Rectangle {
anchors.bottomMargin: 2
spacing: 2
Image{
id: assetThumb
visible: assetDelegate.isItem
height: parent.height
width: height
......@@ -257,16 +259,6 @@ Rectangle {
text: assetlist.getName(styleData.index)
}
}
Menu {
id: assetContextMenu
MenuItem {
text: "Add to favorites"
onTriggered: {
console.log('Asset selected: ', styleData.value, ' Fav: ', assetlist.isFavorite(styleData.index))
}
}
}
MouseArea {
id: dragArea
anchors.fill: parent
......@@ -285,9 +277,10 @@ Rectangle {
parent.Drag.imageSource = result.url
})
} else {
console.log('left mouse pressed!!')
drag.target = undefined
treeView.selectedAssetImage = assetThumb
assetContextMenu.popup()
mouse.accepted = false
}
console.log(parent.Drag.keys)
} else {
......@@ -306,6 +299,22 @@ Rectangle {
}
}
}
Menu {
id: assetContextMenu
MenuItem {
id: favMenu
text: assetlist.isFavorite(sel.currentIndex) ? "Remove from favorites" : "Add to favorites"
property url thumbSource
onTriggered: {
assetlist.setFavorite(sel.currentIndex, !assetlist.isFavorite(sel.currentIndex))
// Force thumb reload
thumbSource = treeView.selectedAssetImage.source
treeView.selectedAssetImage.source = ''
treeView.selectedAssetImage.cache = false
treeView.selectedAssetImage.source = thumbSource
}
}
}
TableViewColumn { role: "identifier"; title: "Name"; }
model: assetListModel
......
......@@ -46,6 +46,9 @@ public:
private:
EffectListWidgetProxy *m_proxy;
signals:
void reloadBasket();
};
// see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property
......@@ -61,7 +64,8 @@ public:
{
}
Q_INVOKABLE QString getName(const QModelIndex &index) const { return q->getName(index); }
Q_INVOKABLE int isFavorite(const QModelIndex &index) const { return q->isFavorite(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 QString getDescription(const QModelIndex &index) const { return q->getDescription(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
......
......@@ -21,6 +21,7 @@
#include "effectsrepository.hpp"
#include "core.h"
#include "kdenlivesettings.h"
#include "xml/xml.hpp"
#include <QDir>
#include <QFile>
......@@ -46,7 +47,20 @@ Mlt::Properties *EffectsRepository::retrieveListFromMlt()
void EffectsRepository::parseFavorites()
{
m_favorites = {QStringLiteral("sepia")};
m_favorites = KdenliveSettings::favorite_effects().toSet();
}
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));
}
Mlt::Properties *EffectsRepository::getMetadata(const QString &effectId)
......
......@@ -47,6 +47,7 @@ public:
/* @brief returns a fresh instance of the given effect */
Mlt::Filter *getEffect(const QString &effectId) const;
void setFavorite(const QString &id, bool favorite) override;
protected:
// Constructor is protected because class is a Singleton
......
......@@ -36,7 +36,6 @@ EffectBasket::EffectBasket(EffectsListView *effectList)
setSelectionMode(QAbstractItemView::SingleSelection);
setDragEnabled(true);
m_effectList->creatFavoriteBasket(this);
connect(m_effectList, &EffectsListView::reloadBasket, this, &EffectBasket::slotReloadBasket);
connect(this, &QListWidget::itemActivated, this, &EffectBasket::slotAddEffect);
}
......
......@@ -45,8 +45,10 @@ protected:
private:
EffectsListView *m_effectList;
private slots:
public slots:
void slotReloadBasket();
private slots:
void slotAddEffect(QListWidgetItem *item);
signals:
......
......@@ -945,6 +945,10 @@
<label>List of favorite effects ids.</label>
<default></default>
</entry>
<entry name="favorite_transitions" type="StringList">
<label>List of favorite transitions ids.</label>
<default></default>
</entry>
<entry name="selected_effecttab" type="Int">
<label>Last opened tab in effects list.</label>
<default>0</default>
......
......@@ -401,6 +401,7 @@ void MainWindow::init()
// Create Effect Basket (dropdown list of favorites)
m_effectBasket = new EffectBasket(m_effectList);
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);
......
......@@ -48,6 +48,7 @@
class AssetPanel;
class AudioGraphSpectrum;
class EffectStackView2;
class EffectBasket;
class EffectListWidget;
class TransitionListWidget;
class EffectStackView;
......@@ -240,7 +241,7 @@ private:
KXMLGUIClient *m_extraFactory;
bool m_themeInitialized;
bool m_isDarkTheme;
QListWidget *m_effectBasket;
EffectBasket *m_effectBasket;
/** @brief Update widget style. */
void doChangeStyle();
void updateActionsToolTip();
......
......@@ -22,7 +22,6 @@
#include <KMessageBox>
#include <KDeclarative/KDeclarative>
#include <KDeclarative/KDeclarative>
#include <kdeclarative_version.h>
#include <QApplication>
#include <QOpenGLFunctions_3_2_Core>
......
......@@ -38,6 +38,7 @@
#include "utils/clipboardproxy.hpp"
#include <KDeclarative/KDeclarative>
#include <kdeclarative_version.h>
// #include <QUrl>
#include <QAction>
#include <QQmlContext>
......@@ -51,6 +52,15 @@ const int TimelineWidget::comboScale[] = {1, 2, 5, 10, 25, 50, 125, 250, 500, 75
TimelineWidget::TimelineWidget(QWidget *parent)
: QQuickWidget(parent)
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
#if KDECLARATIVE_VERSION >= QT_VERSION_CHECK(5, 45, 0)
kdeclarative.setupEngine(engine());
kdeclarative.setupContext();
#else
kdeclarative.setupBindings();
#endif
registerTimelineItems();
m_transitionModel = TransitionTreeModel::construct(true, this);
m_transitionProxyModel.reset(new AssetFilter(this));
......@@ -59,9 +69,6 @@ TimelineWidget::TimelineWidget(QWidget *parent)
m_transitionProxyModel->sort(0, Qt::AscendingOrder);
m_proxy = new TimelineController(this);
connect(m_proxy, &TimelineController::zoneMoved, this, &TimelineWidget::zoneMoved);
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
kdeclarative.setupBindings();
setResizeMode(QQuickWidget::SizeRootObjectToView);
m_thumbnailer = new ThumbnailProvider;
engine()->addImageProvider(QStringLiteral("thumbnail"), m_thumbnailer);
......
......@@ -43,6 +43,9 @@ public:
private:
TransitionListWidgetProxy *m_proxy;
signals:
void reloadBasket();
};
// see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property
......@@ -58,6 +61,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 QString getDescription(const QModelIndex &index) const { return q->getDescription(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
......
......@@ -47,6 +47,20 @@ Mlt::Properties *TransitionsRepository::retrieveListFromMlt()
void TransitionsRepository::parseFavorites()
{
m_favorites = KdenliveSettings::favorite_transitions().toSet();
}
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));
}
Mlt::Properties *TransitionsRepository::getMetadata(const QString &assetId)
......
......@@ -53,6 +53,7 @@ public:
/* @brief Returns the id of the transition to be used for compositing */
const QString getCompositingTransition();
void setFavorite(const QString &id, bool favorite) override;
protected:
// Constructor is protected because class is a Singleton
......
......@@ -23,6 +23,7 @@
#include "transitions/transitionsrepository.hpp"
#include <KDeclarative/KDeclarative>
#include <kdeclarative_version.h>
#include <QQmlContext>
#include <QStringListModel>
......@@ -32,7 +33,12 @@ TransitionParameterView::TransitionParameterView(QWidget *parent)
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
#if KDECLARATIVE_VERSION >= QT_VERSION_CHECK(5, 45, 0)
kdeclarative.setupEngine(engine());
kdeclarative.setupContext();
#else
kdeclarative.setupBindings();
#endif
// Set void model for the moment
auto *model = new QStringListModel();
......
Markdown is supported
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