Commit fa91274a authored by Nicolas Carion's avatar Nicolas Carion
Browse files

Add an asset panel widget and start to clean references to old effectstack code

parent f6cf8896
......@@ -4,6 +4,7 @@ set(kdenlive_SRCS
assets/assetlist/view/assetlistwidget.cpp
assets/assetlist/model/assetfilter.cpp
assets/assetlist/model/assettreemodel.cpp
assets/assetpanel.cpp
assets/model/assetparametermodel.cpp
assets/view/assetparameterview.cpp
assets/view/widgets/abstractparamwidget.cpp
......
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.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) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "assetpanel.hpp"
#include "effects/effectstack/model/effectstackmodel.cpp"
#include "kdenlivesettings.h"
#include "model/assetparametermodel.hpp"
#include "view/assetparameterview.hpp"
#include <KColorScheme>
#include <KColorUtils>
#include <QApplication>
AssetPanel::AssetPanel(QWidget *parent)
: QScrollArea(parent)
, m_lay(new QVBoxLayout(this))
, m_transitionWidget(new AssetParameterView(this))
{
m_lay->addWidget(m_transitionWidget);
m_transitionWidget->setVisible(false);
}
void AssetPanel::showTransition(std::shared_ptr<AssetParameterModel> transitionModel)
{
clear();
m_transitionWidget->setVisible(true);
m_transitionWidget->setModel(transitionModel);
}
void AssetPanel::showEffectStack(std::shared_ptr<EffectStackModel> effectsModel)
{
clear();
}
void AssetPanel::clear()
{
m_transitionWidget->setVisible(false);
m_transitionWidget->unsetModel();
}
void AssetPanel::updatePalette()
{
QString styleSheet = getStyleSheet();
setStyleSheet(styleSheet);
m_transitionWidget->setStyleSheet(styleSheet);
}
// static
const QString AssetPanel::getStyleSheet()
{
KColorScheme scheme(QApplication::palette().currentColorGroup(), KColorScheme::View, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
QColor selected_bg = scheme.decoration(KColorScheme::FocusColor).color();
QColor hgh = KColorUtils::mix(QApplication::palette().window().color(), selected_bg, 0.2);
QColor hover_bg = scheme.decoration(KColorScheme::HoverColor).color();
QColor light_bg = scheme.shade(KColorScheme::LightShade);
QColor alt_bg = scheme.background(KColorScheme::NormalBackground).color();
QString stylesheet;
// effect background
stylesheet.append(QStringLiteral("QFrame#decoframe {border-top-left-radius:5px;border-top-right-radius:5px;border-bottom:2px solid "
"palette(mid);border-top:1px solid palette(light);} QFrame#decoframe[active=\"true\"] {background: %1;}")
.arg(hgh.name()));
// effect in group background
stylesheet.append(
QStringLiteral("QFrame#decoframesub {border-top:1px solid palette(light);} QFrame#decoframesub[active=\"true\"] {background: %1;}").arg(hgh.name()));
// group background
stylesheet.append(QStringLiteral(
"QFrame#decoframegroup {border-top-left-radius:5px;border-top-right-radius:5px;border:2px solid palette(dark);margin:0px;margin-top:2px;} "));
// effect title bar
stylesheet.append(QStringLiteral("QFrame#frame {margin-bottom:2px;border-top-left-radius:5px;border-top-right-radius:5px;} QFrame#frame[target=\"true\"] "
"{background: palette(highlight);}"));
// group effect title bar
stylesheet.append(QStringLiteral("QFrame#framegroup {border-top-left-radius:2px;border-top-right-radius:2px;background: palette(dark);} "
"QFrame#framegroup[target=\"true\"] {background: palette(highlight);} "));
// draggable effect bar content
stylesheet.append(QStringLiteral("QProgressBar::chunk:horizontal {background: palette(button);border-top-left-radius: 4px;border-bottom-left-radius: 4px;} "
"QProgressBar::chunk:horizontal#dragOnly {background: %1;border-top-left-radius: 4px;border-bottom-left-radius: 4px;} "
"QProgressBar::chunk:horizontal:hover {background: %2;}")
.arg(alt_bg.name(), selected_bg.name()));
// draggable effect bar
stylesheet.append(QStringLiteral("QProgressBar:horizontal {border: 1px solid palette(dark);border-top-left-radius: 4px;border-bottom-left-radius: "
"4px;border-right:0px;background:%3;padding: 0px;text-align:left center} QProgressBar:horizontal:disabled {border: 1px "
"solid palette(button)} QProgressBar:horizontal#dragOnly {background: %3} QProgressBar:horizontal[inTimeline=\"true\"] { "
"border: 1px solid %1;border-right: 0px;background: %2;padding: 0px;text-align:left center } "
"QProgressBar::chunk:horizontal[inTimeline=\"true\"] {background: %1;}")
.arg(hover_bg.name(), light_bg.name(), alt_bg.name()));
// spin box for draggable widget
stylesheet.append(
QStringLiteral("QAbstractSpinBox#dragBox {border: 1px solid palette(dark);border-top-right-radius: 4px;border-bottom-right-radius: "
"4px;padding-right:0px;} QAbstractSpinBox::down-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox:disabled#dragBox {border: 1px "
"solid palette(button);} QAbstractSpinBox::up-button#dragBox {width:0px;padding:0px;} QAbstractSpinBox[inTimeline=\"true\"]#dragBox { "
"border: 1px solid %1;} QAbstractSpinBox:hover#dragBox {border: 1px solid %2;} ")
.arg(hover_bg.name(), selected_bg.name()));
// group editable labels
stylesheet.append(QStringLiteral("MyEditableLabel { background-color: transparent; color: palette(bright-text); border-radius: 2px;border: 1px solid "
"transparent;} MyEditableLabel:hover {border: 1px solid palette(highlight);} "));
// transparent qcombobox
stylesheet.append(QStringLiteral("QComboBox { background-color: transparent;} "));
return stylesheet;
}
/***************************************************************************
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive. See www.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) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* 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, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef ASSETPANEL_H
#define ASSETPANEL_H
#include <QScrollArea>
#include <QVBoxLayout>
#include <memory>
/** @brief This class is the widget that provides interaction with the asset currently selected.
That is, it either displays an effectStack or the parameters of a transition
*/
class AssetParameterModel;
class AssetParameterView;
class EffectStackModel;
class AssetPanel : public QScrollArea
{
Q_OBJECT
public:
AssetPanel(QWidget *parent);
/* @brief Shows the parameters of the given transition model */
void showTransition(std::shared_ptr<AssetParameterModel> transition_model);
/* @brief Shows the parameters of the given effect stack model */
void showEffectStack(std::shared_ptr<EffectStackModel> effectsModel);
/* @brief Clear the panel so that it doesn't display anything */
void clear();
/* @brief This method should be called when the style changes */
void updatePalette();
protected:
/** @brief Return the stylesheet used to display the panel (based on current palette). */
static const QString getStyleSheet();
QVBoxLayout *m_lay;
AssetParameterView *m_transitionWidget;
};
#endif
......@@ -40,20 +40,10 @@ AssetParameterView::AssetParameterView(QWidget *parent)
void AssetParameterView::setModel(std::shared_ptr<AssetParameterModel> model)
{
if (m_model) {
// if a model is already there, we have to disconnect signals first
disconnect(m_model.get(), &AssetParameterModel::dataChanged, this, &AssetParameterView::refresh);
}
unsetModel();
m_model = model;
connect(m_model.get(), &AssetParameterModel::dataChanged, this, &AssetParameterView::refresh);
// clear layout
m_widgets.clear();
QLayoutItem *child;
while ((child = m_lay->takeAt(0)) != nullptr) {
delete child;
}
for (int i = 0; i < model->rowCount(); ++i) {
QModelIndex index = model->index(i, 0);
......@@ -65,6 +55,24 @@ void AssetParameterView::setModel(std::shared_ptr<AssetParameterModel> model)
m_lay->addStretch();
}
void AssetParameterView::unsetModel()
{
if (m_model) {
// if a model is already there, we have to disconnect signals first
disconnect(m_model.get(), &AssetParameterModel::dataChanged, this, &AssetParameterView::refresh);
}
// clear layout
m_widgets.clear();
QLayoutItem *child;
while ((child = m_lay->takeAt(0)) != nullptr) {
delete child;
}
// Release ownership of smart pointer
m_model.reset();
}
void AssetParameterView::refresh(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
Q_UNUSED(roles);
......
......@@ -45,6 +45,9 @@ public:
/** Sets the model to be displayed by current view */
void setModel(std::shared_ptr<AssetParameterModel> model);
/** Set the widget to display no model (this yield ownership on the smart-ptr)*/
void unsetModel();
protected:
/** @brief This is a handler for the dataChanged slot of the model.
It basically instructs the widgets in the given range to be refreshed */
......
......@@ -80,7 +80,7 @@ public:
virtual ProjectFolder *folder(const QString &id) = 0;
virtual ProjectClip *clipAt(int ix) = 0;
/** @brief Recursively disable/enable bin effects. */
virtual void disableEffects(bool disable) = 0;
virtual void setBinEffectsEnabled(bool enabled) = 0;
/** @brief Returns the clip's id. */
const QString &clipId() const;
......
......@@ -627,7 +627,7 @@ Bin::Bin(QWidget *parent)
pCore->window()->actionCollection()->addAction(QStringLiteral("bin_view_mode_icon"), iconViewAction);
QAction *disableEffects = new QAction(i18n("Disable Bin Effects"), this);
connect(disableEffects, &QAction::triggered, this, &Bin::slotDisableEffects);
connect(disableEffects, &QAction::triggered, [this](bool disable) { this->setBinEffectsEnabled(!disable); });
disableEffects->setIcon(KoIconUtils::themedIcon(QStringLiteral("favorite")));
disableEffects->setData("disable_bin_effects");
disableEffects->setCheckable(true);
......@@ -1273,7 +1273,7 @@ void Bin::setDocument(KdenliveDoc *project)
// connect(m_itemModel, SIGNAL(updateCurrentItem()), this, SLOT(autoSelect()));
slotInitView(nullptr);
bool binEffectsDisabled = getDocumentProperty(QStringLiteral("disablebineffects")).toInt() == 1;
setBinEffectsDisabledStatus(binEffectsDisabled);
setBinEffectsEnabled(!binEffectsDisabled);
autoSelect();
}
......@@ -3599,25 +3599,19 @@ void Bin::showSlideshowWidget(ProjectClip *clip)
delete dia;
}
void Bin::slotDisableEffects(bool disable)
{
m_itemModel->getRootFolder()->disableEffects(disable);
pCore->projectManager()->disableBinEffects(disable);
m_monitor->refreshMonitorIfActive();
}
void Bin::setBinEffectsDisabledStatus(bool disabled)
void Bin::setBinEffectsEnabled(bool enabled)
{
QAction *disableEffects = pCore->window()->actionCollection()->action(QStringLiteral("disable_bin_effects"));
if (disableEffects) {
if (disabled == disableEffects->isChecked()) {
if (enabled == disableEffects->isChecked()) {
return;
}
disableEffects->blockSignals(true);
disableEffects->setChecked(disabled);
disableEffects->setChecked(enabled);
disableEffects->blockSignals(false);
}
pCore->projectManager()->disableBinEffects(disabled);
m_itemModel->setBinEffectsEnabled(enabled);
pCore->projectManager()->disableBinEffects(!enabled);
}
void Bin::slotRenameItem()
......
......@@ -290,8 +290,10 @@ public:
void emitMessage(const QString &, int, MessageType);
void rebuildMenu();
void refreshIcons();
/** @brief Update status of disable effects action (when loading a document). */
void setBinEffectsDisabledStatus(bool disabled);
/** @brief This function change the global enabled state of the bin effects
*/
void setBinEffectsEnabled(bool enabled);
void requestAudioThumbs(const QString &id, long duration);
/** @brief Proxy status for the project changed, update. */
......@@ -366,8 +368,6 @@ private slots:
void slotZoomView(bool zoomIn);
/** @brief Widget gained focus, make sure we display effects for master clip. */
void slotGotFocus();
/** @brief Dis/Enable all bin effects. */
void slotDisableEffects(bool disable);
/** @brief Rename a Bin Item. */
void slotRenameItem();
void slotCreateAudioThumbs();
......
......@@ -1228,9 +1228,9 @@ bool ProjectClip::isSplittable() const
return (m_clipType == AV || m_clipType == Playlist);
}
void ProjectClip::disableEffects(bool disable)
void ProjectClip::setBinEffectsEnabled(bool enabled)
{
ClipController::disableEffects(disable);
ClipController::setBinEffectsEnabled(enabled);
}
void ProjectClip::registerTimelineClip(std::weak_ptr<TimelineModel> timeline, int clipId)
......
......@@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "abstractprojectitem.h"
#include "definitions.h"
#include "effects/effectstack/model/effectstackmodel.hpp"
#include "mltcontroller/clipcontroller.h"
#include "timeline2/model/timelinemodel.hpp"
......@@ -135,7 +134,7 @@ public:
Mlt::Producer *thumbProducer();
/** @brief Recursively disable/enable bin effects. */
void disableEffects(bool disable) override;
void setBinEffectsEnabled(bool enabled) override;
/** @brief Set properties on this clip. TODO: should we store all in MLT or use extra m_properties ?. */
void setProperties(const QMap<QString, QString> &properties, bool refreshPanel = false);
......
......@@ -111,11 +111,11 @@ ProjectClip *ProjectFolder::clipAt(int index)
return nullptr;
}
void ProjectFolder::disableEffects(bool disable)
void ProjectFolder::setBinEffectsEnabled(bool enabled)
{
for (int i = 0; i < childCount(); ++i) {
AbstractProjectItem *item = static_cast<AbstractProjectItem *>(child(i));
item->disableEffects(disable);
item->setBinEffectsEnabled(enabled);
}
}
......
......@@ -63,7 +63,7 @@ public:
ProjectFolder *folder(const QString &id) override;
/** @brief Recursively disable/enable bin effects. */
void disableEffects(bool disable) override;
void setBinEffectsEnabled(bool enabled) override;
/** @brief Calls AbstractProjectItem::setCurrent and blank the bin monitor. */
void setCurrent(bool current, bool notify = true) override;
......
......@@ -67,7 +67,7 @@ ProjectClip *ProjectFolderUp::clipAt(int index)
return nullptr;
}
void ProjectFolderUp::disableEffects(bool)
void ProjectFolderUp::setBinEffectsEnabled(bool)
{
}
......
......@@ -67,7 +67,7 @@ public:
ProjectClip *clipAt(int index) override;
/** @brief Recursively disable/enable bin effects. */
void disableEffects(bool disable) override;
void setBinEffectsEnabled(bool enabled) override;
/** @brief Returns an xml description of the folder. */
QDomElement toXml(QDomDocument &document, bool includeMeta = false) override;
......
......@@ -262,6 +262,11 @@ ProjectFolder *ProjectItemModel::getFolderByBinId(const QString &binId)
return static_cast<AbstractProjectItem *>(rootItem)->folder(binId);
}
void ProjectItemModel::setBinEffectsEnabled(bool enabled)
{
return static_cast<AbstractProjectItem *>(rootItem)->setBinEffectsEnabled(enabled);
}
QStringList ProjectItemModel::getEnclosingFolderInfo(const QModelIndex &index) const
{
QStringList noInfo;
......
......@@ -52,6 +52,10 @@ public:
*/
ProjectFolder *getFolderByBinId(const QString &binId);
/** @brief This function change the global enabled state of the bin effects
*/
void setBinEffectsEnabled(bool enabled);
/** @brief Returns some info about the folder containing the given index */
QStringList getEnclosingFolderInfo(const QModelIndex &index) const;
......
......@@ -88,7 +88,7 @@ ProjectFolder *ProjectSubClip::folder(const QString &id)
return nullptr;
}
void ProjectSubClip::disableEffects(bool)
void ProjectSubClip::setBinEffectsEnabled(bool)
{
}
......
......@@ -56,7 +56,7 @@ public:
ProjectSubClip *subClip(int in, int out);
ProjectClip *clipAt(int ix) override;
/** @brief Recursively disable/enable bin effects. */
void disableEffects(bool disable) override;
void setBinEffectsEnabled(bool enabled) override;
QDomElement toXml(QDomDocument &document, bool includeMeta = false) override;
/** @brief Returns the clip's duration. */
......
......@@ -27,7 +27,7 @@ EffectItemModel::EffectItemModel(const QList<QVariant> &data, Mlt::Properties *e
: TreeItem(data, static_cast<AbstractTreeModel *>(stack))
, AssetParameterModel(effect, xml, effectId)
, m_enabled(true)
, m_timelineEffectsEnabled(true)
, m_effectStackEnabled(true)
{
}
......@@ -67,15 +67,15 @@ void EffectItemModel::setEnabled(bool enabled)
updateEnable();
}
void EffectItemModel::setTimelineEffectsEnabled(bool enabled)
void EffectItemModel::setEffectStackEnabled(bool enabled)
{
m_timelineEffectsEnabled = enabled;
m_effectStackEnabled = enabled;
updateEnable();
}
bool EffectItemModel::isEnabled() const
{
return m_enabled && m_timelineEffectsEnabled;
return m_enabled && m_effectStackEnabled;
}
void EffectItemModel::updateEnable()
......
......@@ -45,8 +45,8 @@ public:
/* @brief This function change the individual enabled state of the effect */
void setEnabled(bool enabled);
/* @brief This function change the global (timeline-wise) enabled state of the effect */
void setTimelineEffectsEnabled(bool enabled);
/* @brief This function change the global (effectstack-wise) enabled state of the effect */
void setEffectStackEnabled(bool enabled);
/* @brief Returns whether the effect is enabled */
bool isEnabled() const;
......@@ -60,7 +60,7 @@ protected:
void updateEnable();
bool m_enabled;
bool m_timelineEffectsEnabled;
bool m_effectStackEnabled;
};
#endif
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