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

Timeline context menu now only shows favorite effects / compositions

parent 63987d13
......@@ -52,7 +52,7 @@ public:
AssetType getType(const QString &assetId) const;
/* @brief Return name of asset */
QString getName(const QString &assetId) const;
Q_INVOKABLE QString getName(const QString &assetId) const;
/* @brief Return description of asset */
QString getDescription(const QString &assetId) const;
......
......@@ -45,6 +45,11 @@ public:
/** @brief Returns true if the ModelIndex in the source model is visible after filtering
*/
bool isVisible(const QModelIndex &sourceIndex);
/** @brief If we are in favorite view, invalidate filter to refresh. Call this after a favorite has changed
*/
virtual void reloadFilterOnFavorite() = 0;
QVariantList getCategories();
Q_INVOKABLE QModelIndex getNextChild(const QModelIndex &current);
Q_INVOKABLE QModelIndex getPreviousChild(const QModelIndex &current);
......
......@@ -259,7 +259,7 @@ Rectangle {
Image{
id: assetThumb
visible: assetDelegate.isItem
property bool isFavorite: model.favorite
property bool isFavorite: model == undefined || model.favorite == undefined ? false : model.favorite
height: parent.height
width: height
source: 'image://asseticon/' + styleData.value
......
......@@ -27,7 +27,7 @@
#include "projectclip.h"
#include <mlt++/Mlt.h>
QString BinPlaylist::binPlaylistId = QStringLiteral("main_bin");
QString BinPlaylist::binPlaylistId = QString("main_bin");
BinPlaylist::BinPlaylist()
: m_binPlaylist(new Mlt::Playlist(pCore->getCurrentProfile()->profile()))
......
......@@ -37,6 +37,13 @@ void EffectFilter::setFilterType(bool enabled, EffectType type)
invalidateFilter();
}
void EffectFilter::reloadFilterOnFavorite()
{
if (m_type_enabled && m_type_value == EffectType::Favorites) {
invalidateFilter();
}
}
bool EffectFilter::filterType(const std::shared_ptr<TreeItem> &item) const
{
if (!m_type_enabled) {
......
......@@ -41,6 +41,7 @@ public:
@param type Effect type to display
*/
void setFilterType(bool enabled, EffectType type);
void reloadFilterOnFavorite() override;
protected:
bool filterType(const std::shared_ptr<TreeItem> &item) const;
......
......@@ -50,6 +50,8 @@ EffectListWidget::EffectListWidget(QWidget *parent)
void EffectListWidget::updateFavorite(const QModelIndex &index)
{
m_proxyModel->dataChanged(index, index, QVector<int>());
m_proxyModel->reloadFilterOnFavorite();
emit reloadFavorites();
}
EffectListWidget::~EffectListWidget()
......
......@@ -52,7 +52,7 @@ private:
EffectListWidgetProxy *m_proxy;
signals:
void reloadBasket();
void reloadFavorites();
};
// see https://bugreports.qt.io/browse/QTBUG-57714, don't expose a QWidget as a context property
......@@ -69,7 +69,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->updateFavorite(index); q->reloadBasket();}
Q_INVOKABLE void setFavorite(const QModelIndex &index, bool favorite) const { q->setFavorite(index, favorite);q->updateFavorite(index);}
Q_INVOKABLE QString getDescription(const QModelIndex &index) const { return q->getDescription(index); }
Q_INVOKABLE QVariantMap getMimeData(const QString &assetId) const { return q->getMimeData(assetId); }
......
......@@ -22,14 +22,15 @@
#include "effectsrepository.hpp"
#include "core.h"
#include "kdenlivesettings.h"
#include "profiles/profilemodel.hpp"
#include "xml/xml.hpp"
#include <mlt++/Mlt.h>
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#include <QTextStream>
#include "profiles/profilemodel.hpp"
#include <mlt++/Mlt.h>
#include <KLocalizedString>
std::unique_ptr<EffectsRepository> EffectsRepository::instance;
std::once_flag EffectsRepository::m_onceFlag;
......@@ -38,6 +39,21 @@ EffectsRepository::EffectsRepository()
: AbstractAssetsRepository<EffectType>()
{
init();
// Check that our favorite effects are valid
QStringList invalidEffect;
for (const QString &effect : KdenliveSettings::favorite_effects()) {
if (!exists(effect)) {
invalidEffect << effect;
}
}
if (!invalidEffect.isEmpty()) {
pCore->displayMessage(i18n("Some of your favorite effects are invalid and were removed: %1", invalidEffect.join(QLatin1Char(','))), ErrorMessage);
QStringList newFavorites = KdenliveSettings::favorite_effects();
for (const QString &effect : invalidEffect) {
newFavorites.removeAll(effect);
}
KdenliveSettings::setFavorite_effects(newFavorites);
}
}
Mlt::Properties *EffectsRepository::retrieveListFromMlt()
......
......@@ -37,6 +37,7 @@ EffectBasket::EffectBasket(QWidget *parent)
void EffectBasket::slotReloadBasket()
{
clear();
for (const QString &effectId : KdenliveSettings::favorite_effects()) {
if (EffectsRepository::get()->exists(effectId)) {
QListWidgetItem *it = new QListWidgetItem(EffectsRepository::get()->getName(effectId));
......@@ -44,6 +45,7 @@ void EffectBasket::slotReloadBasket()
addItem(it);
}
}
sortItems();
}
QMimeData *EffectBasket::mimeData(const QList<QListWidgetItem *> list) const
......
......@@ -943,11 +943,11 @@
</entry>
<entry name="favorite_effects" type="StringList">
<label>List of favorite effects ids.</label>
<default></default>
<default>volume,lift_gamma_gain,qtblend</default>
</entry>
<entry name="favorite_transitions" type="StringList">
<label>List of favorite transitions ids.</label>
<default></default>
<default>qtblend</default>
</entry>
<entry name="selected_effecttab" type="Int">
<label>Last opened tab in effects list.</label>
......
......@@ -402,7 +402,7 @@ void MainWindow::init()
// Create Effect Basket (dropdown list of favorites)
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_effectList2, &EffectListWidget::reloadFavorites, m_effectBasket, &EffectBasket::slotReloadBasket);
auto *widgetlist = new QWidgetAction(this);
widgetlist->setDefaultWidget(m_effectBasket);
// widgetlist->setText(i18n("Favorite Effects"));
......@@ -2096,6 +2096,9 @@ void MainWindow::connectDocument()
m_normalEditTool->setChecked(true);
connect(m_projectMonitor, &Monitor::durationChanged, this, &MainWindow::slotUpdateProjectDuration);
pCore->monitorManager()->setDocument(project);
connect(m_effectList2, &EffectListWidget::reloadFavorites, getMainTimeline(), &TimelineWidget::updateEffectFavorites);
connect(m_transitionList2, &TransitionListWidget::reloadFavorites, getMainTimeline(), &TimelineWidget::updateTransitionFavorites);
// TODO REFAC: fix
// trackView->updateProfile(1.0);
// Init document zone
......
......@@ -26,6 +26,7 @@ import QtQml.Models 2.2
Menu {
id: menuRoot
property alias menuModel: itemRepeater.model
property bool isTransition: false
signal assetSelected(string assetId)
......@@ -34,8 +35,8 @@ Menu {
onObjectAdded: menuRoot.insertItem( index, object )
onObjectRemoved: menuRoot.removeItem( object )
delegate: MenuItem {
text: name
property string assetId: identifier
text: timeline.getAssetName(modelData, isTransition) //name
property string assetId: modelData //identifier
onTriggered: {
console.log(assetId)
menuRoot.assetSelected(assetId)
......
......@@ -303,7 +303,7 @@ Rectangle {
Loader {
id: thumbsLoader
anchors.fill: parent
source: parentTrack.isAudio ? "ClipAudioThumbs.qml" : "ClipThumbs.qml"
source: parentTrack.isAudio ? "ClipAudioThumbs.qml" : clipType == ProducerType.Color ? "" : "ClipThumbs.qml"
}
Rectangle {
......
......@@ -94,6 +94,7 @@ Menu {
AssetMenu {
title: i18n('Insert a composition...')
menuModel: transitionModel
isTransition: true
onAssetSelected: {
timeline.addCompositionToClip(assetId, clipId)
}
......
......@@ -94,6 +94,7 @@ Menu {
AssetMenu {
title: i18n('Insert a composition...')
menuModel: transitionModel
isTransition: true
onAssetSelected: {
timeline.addCompositionToClip(assetId, clipId)
}
......
......@@ -366,6 +366,7 @@ Rectangle {
AssetMenu {
title: i18n('Insert a composition...')
menuModel: transitionModel
isTransition: true
onAssetSelected: {
var track = Logic.getTrackIdFromPos(menu.clickedY - ruler.height)
var frame = Math.round((menu.clickedX + scrollView.flickableItem.contentX) / timeline.scaleFactor)
......
......@@ -1726,3 +1726,8 @@ void TimelineController::updateClipActions()
act->setEnabled(enableAction);
}
}
const QString TimelineController::getAssetName(const QString &assetId, bool isTransition)
{
return isTransition ? TransitionsRepository::get()->getName(assetId) : EffectsRepository::get()->getName(assetId);
}
......@@ -380,6 +380,7 @@ public:
void selectCurrentItem(ObjectType type, bool select, bool addToCurrent = false);
/** @brief Set target tracks (video, audio) */
void setTargetTracks(QPair<int, int> targets);
Q_INVOKABLE const QString getAssetName(const QString &assetId, bool isTransition);
public slots:
void selectMultitrack();
......
......@@ -94,6 +94,26 @@ TimelineWidget::~TimelineWidget()
delete m_proxy;
}
void TimelineWidget::updateEffectFavorites()
{
rootContext()->setContextProperty("effectModel", sortedItems(KdenliveSettings::favorite_effects(), false));
}
void TimelineWidget::updateTransitionFavorites()
{
rootContext()->setContextProperty("transitionModel", sortedItems(KdenliveSettings::favorite_transitions(), true));
}
const QStringList TimelineWidget::sortedItems(const QStringList &items, bool isTransition)
{
QMap <QString, QString> sortedItems;
for (const QString & effect : items) {
sortedItems.insert(m_proxy->getAssetName(effect, isTransition), effect);
}
return sortedItems.values();
}
void TimelineWidget::setModel(std::shared_ptr<TimelineItemModel> model)
{
m_thumbnailer->resetProject();
......@@ -105,8 +125,9 @@ void TimelineWidget::setModel(std::shared_ptr<TimelineItemModel> model)
rootContext()->setContextProperty("multitrack", sortModel);
rootContext()->setContextProperty("controller", model.get());
rootContext()->setContextProperty("timeline", m_proxy);
rootContext()->setContextProperty("transitionModel", m_transitionProxyModel.get());
rootContext()->setContextProperty("effectModel", m_effectsProxyModel.get());
rootContext()->setContextProperty("transitionModel", sortedItems(KdenliveSettings::favorite_transitions(), true)); //m_transitionProxyModel.get());
//rootContext()->setContextProperty("effectModel", m_effectsProxyModel.get());
rootContext()->setContextProperty("effectModel", sortedItems(KdenliveSettings::favorite_effects(), false));
rootContext()->setContextProperty("guidesModel", pCore->projectManager()->current()->getGuideModel().get());
rootContext()->setContextProperty("clipboard", new ClipboardProxy(this));
setSource(QUrl(QStringLiteral("qrc:/qml/timeline.qml")));
......
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