Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Cleanup, get rid of old effectslistview, effects now added to correct object on activate

parent 7bd1d6b5
......@@ -27,6 +27,9 @@
/* @brief This class represents an effect hierarchy to be displayed as a tree
*/
class TreeItem;
class QMenu;
class KActionCategory;
class AssetTreeModel : public AbstractTreeModel
{
......@@ -44,6 +47,7 @@ public:
void setFavorite(const QModelIndex &index, bool favorite);
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
virtual void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) = 0;
// for convenience, we store the column of each data field
static int nameCol, idCol, favCol, typeCol;
......
......@@ -295,3 +295,11 @@ void AssetPanel::parameterChanged(QString name, int value)
Q_UNUSED(name)
emit changeSpeed(value);
}
void AssetPanel::addEffect(const QString &effectId)
{
if (!m_effectStackWidget->isVisible()) {
return;
}
m_effectStackWidget->addEffect(effectId);
}
......@@ -62,6 +62,8 @@ public:
void updatePalette();
/* @brief Returns the object type / id of effectstack owner */
ObjectId effectStackOwner();
/* @brief Add an effect to the current stack owner */
void addEffect(const QString &effectId);
public slots:
/** @brief Clear panel if displaying itemId */
......
......@@ -30,6 +30,8 @@
#include <array>
#include <vector>
#include <KActionCategory>
#include <QMenu>
#include <QDebug>
EffectTreeModel::EffectTreeModel(QObject *parent)
......@@ -123,3 +125,22 @@ void EffectTreeModel::reloadEffect(const QString &path)
data << asset.second << asset.first << QVariant::fromValue(EffectType::Custom) << isFav;
m_customCategory->appendChild(data);
}
void EffectTreeModel::reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions)
{
for (int i = 0; i < rowCount(); i++) {
std::shared_ptr<TreeItem> item = rootItem->child(i);
if (item->childCount() > 0) {
QMenu *catMenu = new QMenu(item->dataColumn(nameCol).toString(), effectsMenu);
effectsMenu->addMenu(catMenu);
for (int j = 0; j < item->childCount(); j++) {
std::shared_ptr<TreeItem> child = item->child(j);
QAction *a = new QAction(child->dataColumn(nameCol).toString(), catMenu);
const QString id = child->dataColumn(idCol).toString();
a->setData(id);
catMenu->addAction(a);
effectActions->addAction("transition_" + id, a);
}
}
}
}
......@@ -28,6 +28,7 @@
/* @brief This class represents an effect hierarchy to be displayed as a tree
*/
class TreeItem;
class EffectTreeModel : public AssetTreeModel
{
......@@ -37,6 +38,7 @@ protected:
public:
static std::shared_ptr<EffectTreeModel> construct(const QString &categoryFile, QObject *parent);
void reloadEffect(const QString &path);
void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) override;
protected:
std::shared_ptr<TreeItem> m_customCategory;
......
......@@ -26,6 +26,8 @@
#include <QQmlContext>
#include <QStandardPaths>
#include <KActionCategory>
#include <QMenu>
EffectListWidget::EffectListWidget(QWidget *parent)
: AssetListWidget(parent)
......@@ -86,3 +88,7 @@ void EffectListWidget::reloadCustomEffect(const QString &path)
static_cast<EffectTreeModel *>(m_model.get())->reloadEffect(path);
}
void EffectListWidget::reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions)
{
m_model->reloadAssetMenu(effectsMenu, effectActions);
}
......@@ -31,6 +31,8 @@
class EffectFilter;
class EffectTreeModel;
class EffectListWidgetProxy;
class KActionCategory;
class QMenu;
class EffectListWidget : public AssetListWidget
{
......@@ -44,6 +46,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);
void reloadEffectMenu(QMenu *effectsMenu, KActionCategory *effectActions);
public slots:
void reloadCustomEffect(const QString &path);
......
......@@ -329,6 +329,13 @@ ObjectId EffectStackView::stackOwner() const
return ObjectId(ObjectType::NoItem, -1);
}
void EffectStackView::addEffect(const QString &effectId)
{
if (m_model) {
m_model->appendEffect(effectId);
}
}
/*
void EffectStackView::switchBuiltStack(bool show)
{
......
......@@ -61,6 +61,9 @@ public:
void setModel(std::shared_ptr<EffectStackModel> model, const QSize frameSize);
void unsetModel(bool reset = true);
ObjectId stackOwner() const;
/** @brief Add an effect to the current stack
*/
void addEffect(const QString &effectId);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
......
set(kdenlive_SRCS
${kdenlive_SRCS}
effectslist/effectslist.cpp
effectslist/effectslistview.cpp
# effectslist/effectslistview.cpp
effectslist/effectslistwidget.cpp
effectslist/initeffects.cpp
effectslist/effectbasket.cpp
......
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef EFFECTSLISTVIEW_H
#define EFFECTSLISTVIEW_H
#include "gentime.h"
#include "ui_effectlist_ui.h"
#include <KTreeWidgetSearchLine>
#include <QDomDocument>
#include <QDragEnterEvent>
#include <QMimeData>
#include <QToolButton>
class EffectsList;
class EffectsListWidget;
class QTreeWidget;
class KActionCategory;
class QListWidget;
class TreeEventEater : public QObject
{
Q_OBJECT
public:
explicit TreeEventEater(QObject *parent = nullptr);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
signals:
void clearSearchLine();
};
class MyTreeWidgetSearchLine : public KTreeWidgetSearchLine
{
Q_OBJECT
public:
explicit MyTreeWidgetSearchLine(QWidget *parent = nullptr);
protected:
bool itemMatches(const QTreeWidgetItem *item, const QString &pattern) const override;
};
/**
* @class MyDropButton
* @brief A QToolButton accepting effect drops
* @author Jean-Baptiste Mardelle
*/
class MyDropButton : public QToolButton
{
Q_OBJECT
public:
explicit MyDropButton(QWidget *parent = nullptr)
: QToolButton(parent)
{
setAcceptDrops(true);
setAutoExclusive(true);
setCheckable(true);
setAutoRaise(true);
}
protected:
void dragEnterEvent(QDragEnterEvent *event) override
{
if (event->mimeData()->hasFormat(QStringLiteral("kdenlive/effectslist"))) {
event->accept();
}
}
void dropEvent(QDropEvent *event) override
{
const QString effects = QString::fromUtf8(event->mimeData()->data(QStringLiteral("kdenlive/effectslist")));
QDomDocument doc;
doc.setContent(effects, true);
QString id = doc.documentElement().attribute(QStringLiteral("id"));
if (id.isEmpty()) {
id = doc.documentElement().attribute(QStringLiteral("tag"));
}
emit addEffectToFavorites(id);
}
signals:
void addEffectToFavorites(QString);
};
/**
* @class EffectsListView
* @brief Manages the controls for the treewidget containing the effects.
* @author Jean-Baptiste Mardelle
*/
class EffectsListView : public QWidget, public Ui::EffectList_UI
{
Q_OBJECT
public:
enum LISTMODE { EffectMode = 0, TransitionMode = 1 };
explicit EffectsListView(LISTMODE mode = EffectMode, QWidget *parent = nullptr);
/** @brief Re-initializes the list of effects. */
void reloadEffectList(QMenu *effectsMenu, KActionCategory *effectActions);
QMenu *getEffectsMenu();
// void slotAddEffect(GenTime pos, int track, QString name);
/** @brief Palette was changed, update styles. */
void updatePalette();
void refreshIcons();
void creatFavoriteBasket(QListWidget *list);
private:
/** @brief tells us if this is an effect or transition list
*/
LISTMODE m_mode;
EffectsListWidget *m_effectsList;
MyTreeWidgetSearchLine *m_search_effect;
const QString customStyleSheet() const;
/** @brief Custom button to display favorite effects, accepts drops to add effect to favorites.
*/
MyDropButton *m_effectsFavorites;
/** @brief Action triggering remove effect from favorites or delete custom effect, depending on active tab.
*/
QAction *m_removeAction;
QAction *m_favoriteAction;
QMenu *m_contextMenu;
private slots:
/** @brief Applies the type filter to the effect list.
* @param pos Index of the combo box; where 0 = All, 1 = Video, 2 = Audio, 3 = GPU, 4 = Custom */
void filterList();
/** @brief Updates the info panel to match the selected effect. */
void slotUpdateInfo();
/** @brief Toggles the info panel's visibility. */
void showInfoPanel();
/** @brief Emits addEffect signal for the selected effect. */
void slotEffectSelected();
/** @brief Removes the XML file for the selected effect.
*
* Only used for custom effects */
void slotRemoveEffect();
/** @brief Makes sure the item fits the type filter.
* @param item Current item
* @param hidden Hidden or not
*
* This is necessary to make the search obey to the type filter.
* Called when the visibility of this item was changed by searching */
void slotUpdateSearch(QTreeWidgetItem *item, bool hidden);
/** @brief Expands folders that match our search.
* @param text Current search string */
void slotAutoExpand(const QString &text);
/** @brief Add an effect to the favorites
* @param id id of the effect we want */
void slotAddFavorite(const QString &id);
/** @brief Add currently selected effect to the favorites */
void slotAddToFavorites();
void slotDisplayMenu(QTreeWidgetItem *item, const QPoint &pos);
signals:
void addEffect(const QDomElement &);
void reloadEffects();
void reloadBasket();
};
#endif
......@@ -33,7 +33,6 @@
#include "doc/kdenlivedoc.h"
#include "effects/effectlist/view/effectlistwidget.hpp"
#include "effectslist/effectbasket.h"
#include "effectslist/effectslistview.h"
#include "effectslist/effectslistwidget.h"
#include "effectslist/initeffects.h"
#include "hidetitlebars.h"
......@@ -149,8 +148,6 @@ static QString defaultStyle(const char *fallback = nullptr)
MainWindow::MainWindow(QWidget *parent)
: KXmlGuiWindow(parent)
, m_exitCode(EXIT_SUCCESS)
, m_effectList(nullptr)
, m_transitionList(nullptr)
, m_assetPanel(nullptr)
, m_clipMonitor(nullptr)
, m_projectMonitor(nullptr)
......@@ -335,17 +332,12 @@ void MainWindow::init()
m_effectStackDock = addDock(i18n("Properties"), QStringLiteral("effect_stack"), m_assetPanel);
m_effectList = new EffectsListView();
m_effectList2 = new EffectListWidget(this);
connect(m_effectList2, &EffectListWidget::activateAsset, pCore->projectManager(), &ProjectManager::activateAsset);
connect(m_assetPanel, &AssetPanel::reloadEffect, m_effectList2, &EffectListWidget::reloadCustomEffect);
m_effectListDock = addDock(i18n("Effects"), QStringLiteral("effect_list"), m_effectList2);
m_transitionList = new EffectsListView(EffectsListView::TransitionMode);
m_transitionList2 = new TransitionListWidget(this);
// m_transitionListDock = addDock(i18n("Transitions"), QStringLiteral("transition_list"), m_transitionList);
m_transitionListDock = addDock(i18n("Transitions"), QStringLiteral("transition_list"), m_transitionList2);
// Add monitors here to keep them at the right of the window
......@@ -386,11 +378,10 @@ void MainWindow::init()
// Build effects menu
m_effectsMenu = new QMenu(i18n("Add Effect"), this);
m_effectActions = new KActionCategory(i18n("Effects"), actionCollection());
m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
m_effectList2->reloadEffectMenu(m_effectsMenu, m_effectActions);
m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
m_transitionActions = new KActionCategory(i18n("Transitions"), actionCollection());
m_transitionList->reloadEffectList(m_transitionsMenu, m_transitionActions);
auto *scmanager = new ScopeManager(this);
......@@ -491,8 +482,8 @@ void MainWindow::init()
// Setup and fill effects and transitions menus.
QMenu *m = static_cast<QMenu *>(factory()->container(QStringLiteral("video_effects_menu"), this));
connect(m, &QMenu::triggered, this, &MainWindow::slotAddVideoEffect);
connect(m_effectsMenu, &QMenu::triggered, this, &MainWindow::slotAddVideoEffect);
connect(m, &QMenu::triggered, this, &MainWindow::slotAddEffect);
connect(m_effectsMenu, &QMenu::triggered, this, &MainWindow::slotAddEffect);
connect(m_transitionsMenu, &QMenu::triggered, this, &MainWindow::slotAddTransition);
m_timelineContextMenu = new QMenu(this);
......@@ -515,9 +506,6 @@ void MainWindow::init()
m_timelineContextTransitionMenu->addAction(actionCollection()->action(QStringLiteral("auto_transition")));
connect(m_effectList, &EffectsListView::addEffect, this, &MainWindow::slotAddEffect);
connect(m_effectList, &EffectsListView::reloadEffects, this, &MainWindow::slotReloadEffects);
slotConnectMonitors();
m_timelineToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
......@@ -623,16 +611,10 @@ void MainWindow::slotThemeChanged(const QString &name)
if (m_assetPanel) {
m_assetPanel->updatePalette();
}
if (m_effectList) {
m_effectList->updatePalette();
}
if (m_effectList2) {
// Trigger a repaint to have icons adapted
m_effectList2->reset();
}
if (m_transitionList) {
m_transitionList->updatePalette();
}
if (m_transitionList2) {
// Trigger a repaint to have icons adapted
m_transitionList2->reset();
......@@ -677,9 +659,6 @@ void MainWindow::slotThemeChanged(const QString &name)
if (pCore->monitorManager()) {
pCore->monitorManager()->refreshIcons();
}
if (m_effectList) {
m_effectList->refreshIcons();
}
for (QAction *action : actionCollection()->actions()) {
QIcon icon = action->icon();
......@@ -836,7 +815,7 @@ void MainWindow::saveNewToolbarConfig()
void MainWindow::slotReloadEffects()
{
initEffects::parseCustomEffectsFile();
m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
m_effectList2->reloadEffectMenu(m_effectsMenu, m_effectActions);
}
void MainWindow::configureNotifications()
......@@ -849,35 +828,6 @@ void MainWindow::slotFullScreen()
KToggleFullScreenAction::setFullScreen(this, actionCollection()->action(QStringLiteral("fullscreen"))->isChecked());
}
void MainWindow::slotAddEffect(const QDomElement &effect)
{
Q_UNUSED(effect)
// TODO refac : reimplement
/*
if (effect.isNull()) {
qCDebug(KDENLIVE_LOG) << "--- ERROR, TRYING TO APPEND nullptr EFFECT";
return;
}
QDomElement effectToAdd = effect.cloneNode().toElement();
EFFECTMODE status = m_effectStack->effectStatus();
switch (status) {
case TIMELINE_TRACK:
pCore->projectManager()->currentTimeline()->projectView()->slotAddTrackEffect(effectToAdd, m_effectStack->trackIndex());
break;
case TIMELINE_CLIP:
pCore->projectManager()->currentTimeline()->projectView()->slotAddEffectToCurrentItem(effectToAdd);
break;
case MASTER_CLIP:
// TODO refac reimplement this.
// pCore->bin()->slotEffectDropped(QString(), effectToAdd);
break;
default:
// No clip selected
m_messageLabel->setMessage(i18n("Select a clip if you want to apply an effect"), ErrorMessage);
}
*/
}
void MainWindow::slotConnectMonitors()
{
// connect(m_projectList, SIGNAL(deleteProjectClips(QStringList,QMap<QString,QString>)), this,
......@@ -1920,19 +1870,6 @@ void MainWindow::addTimelineClip(const QString &url)
}
}
void MainWindow::addEffect(const QString &effectName)
{
QStringList effectInfo;
effectInfo << effectName << effectName;
const QDomElement effect = EffectsListWidget::itemEffect(5, effectInfo);
if (!effect.isNull()) {
slotAddEffect(effect);
} else {
qCDebug(KDENLIVE_LOG) << " * * *EFFECT: " << effectName << " NOT AVAILABLE";
exitApp();
}
}
void MainWindow::scriptRender(const QString &url)
{
slotRenderProject();
......@@ -2643,45 +2580,27 @@ void MainWindow::slotAddTransition(QAction *result)
*/
}
void MainWindow::slotAddVideoEffect(QAction *result)
void MainWindow::slotAddEffect(QAction *result)
{
qDebug()<<"// EFFECTS MENU TRIGGERED: "<<result->data().toString();
if (!result) {
return;
}
QStringList info = result->data().toStringList();
if (info.isEmpty() || info.size() < 3) {
return;
}
QDomElement effect;
int effectType = info.last().toInt();
switch (effectType) {
case EffectsList::EFFECT_VIDEO:
case EffectsList::EFFECT_GPU:
effect = videoEffects.getEffectByTag(info.at(0), info.at(1));
break;
case EffectsList::EFFECT_AUDIO:
effect = audioEffects.getEffectByTag(info.at(0), info.at(1));
break;
case EffectsList::EFFECT_CUSTOM:
effect = customEffects.getEffectByTag(info.at(0), info.at(1));
break;
default:
effect = videoEffects.getEffectByTag(info.at(0), info.at(1));
if (!effect.isNull()) {
break;
}
effect = audioEffects.getEffectByTag(info.at(0), info.at(1));
if (!effect.isNull()) {
break;
}
effect = customEffects.getEffectByTag(info.at(0), info.at(1));
break;
}
QString effectId = result->data().toString();
addEffect(effectId);
}
if (!effect.isNull()) {
slotAddEffect(effect);
void MainWindow::addEffect(const QString &effectId)
{
if (m_assetPanel->effectStackOwner().first == ObjectType::TimelineClip) {
// Add effect to the current timeline selection
QVariantMap effectData;
effectData.insert(QStringLiteral("kdenlive/effect"), effectId);
pCore->window()->getMainTimeline()->controller()->addAsset(effectData);
} else if (m_assetPanel->effectStackOwner().first == ObjectType::TimelineTrack || m_assetPanel->effectStackOwner().first == ObjectType::BinClip) {
m_assetPanel->addEffect(effectId);
} else {
m_messageLabel->setMessage(i18n("Cannot find effect %1 / %2", info.at(0), info.at(1)), ErrorMessage);
pCore->displayMessage(i18n("Select an item to add effect"), InformationMessage);
}
}
......
......@@ -52,7 +52,6 @@ class EffectBasket;
class EffectListWidget;
class TransitionListWidget;
class EffectStackView;
class EffectsListView;
class KIconLoader;
class KdenliveDoc;
class Monitor;
......@@ -149,9 +148,7 @@ private:
QDockWidget *m_projectBinDock;
QDockWidget *m_effectListDock;
EffectsListView *m_effectList;
QDockWidget *m_transitionListDock;
EffectsListView *m_transitionList;
TransitionListWidget *m_transitionList2;
EffectListWidget *m_effectList2;
......@@ -253,7 +250,7 @@ public slots:
Q_SCRIPTABLE void setRenderingFinished(const QString &url, int status, const QString &error);
Q_SCRIPTABLE void addProjectClip(const QString &url);
Q_SCRIPTABLE void addTimelineClip(const QString &url);
Q_SCRIPTABLE void addEffect(const QString &effectName);
Q_SCRIPTABLE void addEffect(const QString &effectId);
Q_SCRIPTABLE void scriptRender(const QString &url);
Q_NOREPLY void exitApp();
......@@ -282,7 +279,6 @@ private slots:
void slotConnectMonitors();
void slotUpdateMousePosition(int pos);
void slotUpdateProjectDuration(int pos);
void slotAddEffect(const QDomElement &effect);
void slotEditProjectSettings();
void slotSwitchMarkersComments();
void slotSwitchSnap();
......@@ -337,7 +333,7 @@ private slots:
void slotDeselectTimelineTransition();
void slotSelectAddTimelineClip();
void slotSelectAddTimelineTransition();
void slotAddVideoEffect(QAction *result);
void slotAddEffect(QAction *result);
void slotAddTransition(QAction *result);
void slotAddProjectClip(const QUrl &url, const QStringList &folderInfo);
void slotAddProjectClipList(const QList<QUrl> &urls);
......
......@@ -867,13 +867,10 @@ void ProjectManager::adjustProjectDuration()
void ProjectManager::activateAsset(const QVariantMap effectData)
{
if (pCore->monitorManager()->projectMonitor()->isActive()) {
pCore->window()->getMainTimeline()->controller()->addAsset(effectData);
if (effectData.contains(QStringLiteral("kdenlive/effect"))) {
pCore->window()->addEffect(effectData.value(QStringLiteral("kdenlive/effect")).toString());
} else {
QString effect = effectData.value(QStringLiteral("kdenlive/effect")).toString();
QStringList effectString;
effectString << effect;
pCore->bin()->slotAddEffect(QString(), effectString);
pCore->window()->getMainTimeline()->controller()->addAsset(effectData);
}
}
......
......@@ -25,6 +25,8 @@
#include "transitions/transitionsrepository.hpp"
#include <KLocalizedString>
#include <KActionCategory>
#include <QMenu>
#include <QDebug>
TransitionTreeModel::TransitionTreeModel(QObject *parent)
......@@ -74,3 +76,22 @@ std::shared_ptr<TransitionTreeModel> TransitionTreeModel::construct(bool flat, Q
}
return self;
}
void TransitionTreeModel::reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions)
{
for (int i = 0; i < rowCount(); i++) {
std::shared_ptr<TreeItem> item = rootItem->child(i);
if (item->childCount() > 0) {
QMenu *catMenu = new QMenu(item->dataColumn(nameCol).toString(), effectsMenu);
effectsMenu->addMenu(catMenu);
for (int j = 0; j < item->childCount(); j++) {
std::shared_ptr<TreeItem> child = item->child(j);
QAction *a = new QAction(child->dataColumn(nameCol).toString(), catMenu);
const QString id = child->dataColumn(idCol).toString();
a->setData(id);
catMenu->addAction(a);
effectActions->addAction("transition_" + id, a);
}
}
}
}
......@@ -37,6 +37,7 @@ protected:
public:
// if flat = true, then the categories are not created
static std::shared_ptr<TransitionTreeModel> construct(bool flat = false, QObject *parent = nullptr);
void reloadAssetMenu(QMenu *effectsMenu, KActionCategory *effectActions) override;
protected:
};
......
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