Commit 3dad3f43 authored by Nicolas Carion's avatar Nicolas Carion

clang-format

parent 20407bda
......@@ -148,8 +148,7 @@ QModelIndex AbstractTreeModel::getIndexFromId(int id) const
return QModelIndex();
}
Q_ASSERT(m_allItems.count(id) > 0);
if (auto ptr = m_allItems.at(id).lock())
return getIndexFromItem(ptr);
if (auto ptr = m_allItems.at(id).lock()) return getIndexFromItem(ptr);
Q_ASSERT(false);
return QModelIndex();
......@@ -313,17 +312,17 @@ Fun AbstractTreeModel::removeItem_lambda(int id)
Fun AbstractTreeModel::moveItem_lambda(int id, int destRow)
{
Fun lambda = [](){return true;};
Fun lambda = []() { return true; };
std::vector<std::shared_ptr<TreeItem> > oldStack;
std::vector<std::shared_ptr<TreeItem>> oldStack;
auto item = getItemById(id);
if (item->row() == destRow) {
//nothing to do
// nothing to do
return lambda;
}
if (auto parent = item->parentItem().lock()) {
if (destRow > parent->childCount() || destRow < 0) {
return [](){return false;};
return []() { return false; };
}
int parentId = parent->getId();
// remove the element to move
......@@ -340,11 +339,11 @@ Fun AbstractTreeModel::moveItem_lambda(int id, int destRow)
}
}
// insert back in order
for (const auto & elem : oldStack) {
for (const auto &elem : oldStack) {
oper = addItem_lambda(elem, parentId);
PUSH_LAMBDA(oper, lambda);
}
return lambda;
}
return [](){return false;};
return []() { return false; };
}
......@@ -22,10 +22,10 @@
#ifndef ABSTRACTTREEMODEL_H
#define ABSTRACTTREEMODEL_H
#include "undohelper.hpp"
#include <QAbstractItemModel>
#include <memory>
#include <unordered_map>
#include "undohelper.hpp"
/* @brief This class represents a generic tree hierarchy
*/
......
......@@ -264,4 +264,3 @@ bool TreeItem::isRoot() const
{
return m_isRoot;
}
......@@ -22,11 +22,11 @@
#ifndef TREEITEM_H
#define TREEITEM_H
#include "definitions.h"
#include <QList>
#include <QVariant>
#include <memory>
#include <unordered_map>
#include "definitions.h"
/* @brief This class is a generic class to represent items of a tree-like model
It works in tandem with AbstractTreeModel or one of its derived classes.
......@@ -43,7 +43,7 @@
*/
class AbstractTreeModel;
class TreeItem : public enable_shared_from_this_virtual<TreeItem>
class TreeItem : public enable_shared_from_this_virtual<TreeItem>
{
public:
/* @brief Construct a TreeItem
......@@ -134,6 +134,7 @@ public:
Note that it should be consistent with what the model thinks, but it may have been
messed up at some point if someone wrongly constructed the object with isRoot = true */
bool isRoot() const;
protected:
/* @brief Finish construction of object given its pointer
This is a separated function so that it can be called from derived classes */
......
......@@ -89,4 +89,3 @@ QVariant AssetTreeModel::data(const QModelIndex &index, int role) const
}
return item->dataColumn(index.column());
}
......@@ -20,27 +20,27 @@
***************************************************************************/
#include "assetpanel.hpp"
#include "core.cpp"
#include "definitions.h"
#include "effects/effectstack/model/effectitemmodel.hpp"
#include "effects/effectstack/model/effectstackmodel.hpp"
#include "effects/effectstack/view/effectstackview.hpp"
#include "transitions/view/transitionstackview.hpp"
#include "kdenlivesettings.h"
#include "model/assetparametermodel.hpp"
#include "transitions/transitionsrepository.hpp"
#include "view/assetparameterview.hpp"
#include "transitions/view/transitionstackview.hpp"
#include "utils/KoIconUtils.h"
#include "definitions.h"
#include "core.cpp"
#include "view/assetparameterview.hpp"
#include <KColorScheme>
#include <KColorUtils>
#include <KSqueezedTextLabel>
#include <QApplication>
#include <QDebug>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QVBoxLayout>
#include <klocalizedstring.h>
AssetPanel::AssetPanel(QWidget *parent)
......@@ -99,7 +99,8 @@ void AssetPanel::showTransition(int tid, std::shared_ptr<AssetParameterModel> tr
m_transitionWidget->setModel(transitionModel, QPair<int, int>(-1, -1), QSize(), true);
}
void AssetPanel::showEffectStack(const QString &itemName, std::shared_ptr<EffectStackModel> effectsModel, QPair<int, int> range, QSize frameSize, bool showKeyframes)
void AssetPanel::showEffectStack(const QString &itemName, std::shared_ptr<EffectStackModel> effectsModel, QPair<int, int> range, QSize frameSize,
bool showKeyframes)
{
if (effectsModel == nullptr) {
// Item is not ready
......@@ -116,34 +117,34 @@ void AssetPanel::showEffectStack(const QString &itemName, std::shared_ptr<Effect
bool showSplit = false;
bool enableKeyframes = false;
switch (id.first) {
case ObjectType::TimelineClip:
title = i18n("%1 effects", itemName);
showSplit = true;
enableKeyframes = true;
break;
case ObjectType::TimelineComposition:
title = i18n("%1 parameters", itemName);
enableKeyframes = true;
break;
case ObjectType::TimelineTrack:
title = i18n("Track %1 effects", itemName);
//TODO: track keyframes
//enableKeyframes = true;
break;
case ObjectType::BinClip:
title = i18n("Bin %1 effects", itemName);
showSplit = true;
break;
default:
title = itemName;
break;
case ObjectType::TimelineClip:
title = i18n("%1 effects", itemName);
showSplit = true;
enableKeyframes = true;
break;
case ObjectType::TimelineComposition:
title = i18n("%1 parameters", itemName);
enableKeyframes = true;
break;
case ObjectType::TimelineTrack:
title = i18n("Track %1 effects", itemName);
// TODO: track keyframes
// enableKeyframes = true;
break;
case ObjectType::BinClip:
title = i18n("Bin %1 effects", itemName);
showSplit = true;
break;
default:
title = itemName;
break;
}
m_assetTitle->setText(title);
m_splitButton->setVisible(showSplit);
m_timelineButton->setVisible(enableKeyframes);
m_timelineButton->setChecked(showKeyframes);
// Disable built stack until properly implemented
//m_switchBuiltStack->setVisible(true);
// m_switchBuiltStack->setVisible(true);
m_effectStackWidget->setVisible(true);
m_effectStackWidget->setModel(effectsModel, range, frameSize);
}
......
......@@ -22,10 +22,10 @@
#ifndef KEYFRAMELISTMODEL_H
#define KEYFRAMELISTMODEL_H
#include "assets/model/assetparametermodel.hpp"
#include "definitions.h"
#include "gentime.h"
#include "undohelper.hpp"
#include "assets/model/assetparametermodel.hpp"
#include <QAbstractListModel>
#include <QReadWriteLock>
......@@ -42,12 +42,7 @@ class EffectItemModel;
We store them in a sorted fashion using a std::map
*/
enum class KeyframeType
{
Linear = 0,
Discrete,
Curve
};
enum class KeyframeType { Linear = 0, Discrete, Curve };
Q_DECLARE_METATYPE(KeyframeType)
using Keyframe = std::pair<GenTime, KeyframeType>;
......@@ -61,9 +56,10 @@ public:
@param model is the asset this parameter belong to
@param index is the index of this parameter in its model
*/
explicit KeyframeModel(std::weak_ptr<AssetParameterModel> model, const QModelIndex &index, std::weak_ptr<DocUndoStack> undo_stack, QObject *parent = nullptr);
explicit KeyframeModel(std::weak_ptr<AssetParameterModel> model, const QModelIndex &index, std::weak_ptr<DocUndoStack> undo_stack,
QObject *parent = nullptr);
enum { TypeRole = Qt::UserRole + 1, PosRole, FrameRole, ValueRole, NormalizedValueRole};
enum { TypeRole = Qt::UserRole + 1, PosRole, FrameRole, ValueRole, NormalizedValueRole };
friend class KeyframeModelList;
/* @brief Adds a keyframe at the given position. If there is already one then we update it.
......@@ -153,7 +149,6 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
protected:
/** @brief Helper function that generate a lambda to change type / value of given keyframe */
Fun updateKeyframe_lambda(GenTime pos, KeyframeType type, QVariant value, bool notify);
......@@ -179,8 +174,8 @@ protected:
/* @brief this function does the opposite: given a MLT representation of an animation, build the corresponding model */
void parseAnimProperty(const QString &prop);
private:
private:
std::weak_ptr<AssetParameterModel> m_model;
std::weak_ptr<DocUndoStack> m_undoStack;
QPersistentModelIndex m_index;
......@@ -198,6 +193,6 @@ public:
auto begin() -> decltype(m_keyframeList.begin()) { return m_keyframeList.begin(); }
auto end() -> decltype(m_keyframeList.end()) { return m_keyframeList.end(); }
};
//Q_DECLARE_METATYPE(KeyframeModel *)
// Q_DECLARE_METATYPE(KeyframeModel *)
#endif
......@@ -20,34 +20,32 @@
***************************************************************************/
#include "keyframemodellist.hpp"
#include "doc/docundostack.hpp"
#include "assets/model/assetparametermodel.hpp"
#include "core.h"
#include "macros.hpp"
#include "klocalizedstring.h"
#include "doc/docundostack.hpp"
#include "keyframemodel.hpp"
#include "assets/model/assetparametermodel.hpp"
#include "klocalizedstring.h"
#include "macros.hpp"
#include <QDebug>
KeyframeModelList::KeyframeModelList(std::weak_ptr<AssetParameterModel> model, const QModelIndex &index, std::weak_ptr<DocUndoStack> undo_stack)
: m_model(model)
, m_undoStack(undo_stack)
, m_lock(QReadWriteLock::Recursive)
{
qDebug() <<"Construct keyframemodellist. Checking model:"<<m_model.expired();
qDebug() << "Construct keyframemodellist. Checking model:" << m_model.expired();
addParameter(index);
connect(m_parameters.begin()->second.get(), &KeyframeModel::modelChanged, this, &KeyframeModelList::modelChanged);
}
void KeyframeModelList::addParameter(const QModelIndex &index)
{
std::shared_ptr<KeyframeModel> parameter (new KeyframeModel(m_model, index, m_undoStack));
std::shared_ptr<KeyframeModel> parameter(new KeyframeModel(m_model, index, m_undoStack));
m_parameters.insert({index, std::move(parameter)});
}
bool KeyframeModelList::applyOperation(const std::function<bool(std::shared_ptr<KeyframeModel>, Fun&, Fun&)> &op, const QString &undoString)
bool KeyframeModelList::applyOperation(const std::function<bool(std::shared_ptr<KeyframeModel>, Fun &, Fun &)> &op, const QString &undoString)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(m_parameters.size() > 0);
......@@ -55,7 +53,7 @@ bool KeyframeModelList::applyOperation(const std::function<bool(std::shared_ptr<
Fun redo = []() { return true; };
bool res = true;
for (const auto& param : m_parameters) {
for (const auto &param : m_parameters) {
res = op(param.second, undo, redo);
if (!res) {
bool undone = undo();
......@@ -74,7 +72,7 @@ bool KeyframeModelList::addKeyframe(GenTime pos, KeyframeType type)
QWriteLocker locker(&m_lock);
Q_ASSERT(m_parameters.size() > 0);
bool update = (m_parameters.begin()->second->hasKeyframe(pos) > 0);
auto op = [pos, type](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo){
auto op = [pos, type](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo) {
QVariant value = param->getInterpolatedValue(pos);
return param->addKeyframe(pos, type, value, true, undo, redo);
};
......@@ -85,9 +83,7 @@ bool KeyframeModelList::removeKeyframe(GenTime pos)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(m_parameters.size() > 0);
auto op = [pos](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo){
return param->removeKeyframe(pos, undo, redo);
};
auto op = [pos](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo) { return param->removeKeyframe(pos, undo, redo); };
return applyOperation(op, i18n("Delete keyframe"));
}
......@@ -95,9 +91,7 @@ bool KeyframeModelList::removeAllKeyframes()
{
QWriteLocker locker(&m_lock);
Q_ASSERT(m_parameters.size() > 0);
auto op = [](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo){
return param->removeAllKeyframes(undo, redo);
};
auto op = [](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo) { return param->removeAllKeyframes(undo, redo); };
return applyOperation(op, i18n("Delete all keyframes"));
}
......@@ -105,9 +99,7 @@ bool KeyframeModelList::moveKeyframe(GenTime oldPos, GenTime pos, bool logUndo)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(m_parameters.size() > 0);
auto op = [oldPos, pos](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo){
return param->moveKeyframe(oldPos, pos, undo, redo);
};
auto op = [oldPos, pos](std::shared_ptr<KeyframeModel> param, Fun &undo, Fun &redo) { return param->moveKeyframe(oldPos, pos, undo, redo); };
return applyOperation(op, logUndo ? i18n("Move keyframe") : QString());
}
......@@ -195,7 +187,6 @@ Keyframe KeyframeModelList::getClosestKeyframe(const GenTime &pos, bool *ok) con
return m_parameters.begin()->second->getClosestKeyframe(pos, ok);
}
bool KeyframeModelList::hasKeyframe(int frame) const
{
READ_LOCK();
......@@ -206,12 +197,12 @@ bool KeyframeModelList::hasKeyframe(int frame) const
void KeyframeModelList::refresh()
{
QWriteLocker locker(&m_lock);
for (const auto& param : m_parameters) {
for (const auto &param : m_parameters) {
param.second->refresh();
}
}
QVariant KeyframeModelList::getInterpolatedValue(int pos, const QPersistentModelIndex& index) const
QVariant KeyframeModelList::getInterpolatedValue(int pos, const QPersistentModelIndex &index) const
{
READ_LOCK();
Q_ASSERT(m_parameters.count(index) > 0);
......@@ -225,4 +216,3 @@ KeyframeModel *KeyframeModelList::getKeyModel()
}
return nullptr;
}
......@@ -22,18 +22,18 @@
#ifndef KEYFRAMELISTMODELLIST_H
#define KEYFRAMELISTMODELLIST_H
#include "gentime.h"
#include "definitions.h"
#include "gentime.h"
#include "keyframemodel.hpp"
#include "undohelper.hpp"
#include <QAbstractListModel>
#include <QReadWriteLock>
#include <QObject>
#include <map>
#include <memory>
#include <unordered_map>
#include <QObject>
class AssetParameterModel;
class DocUndoStack;
......@@ -43,7 +43,6 @@ class DocUndoStack;
but we regroup all of these in a common class to provide unified access.
*/
class KeyframeModelList : public QObject
{
Q_OBJECT
......@@ -117,21 +116,19 @@ public:
/* @brief Return the interpolated value of a parameter.
@param pos is the position where we interpolate
@param index is the index of the queried parameter. */
QVariant getInterpolatedValue(int pos, const QPersistentModelIndex& index) const;
QVariant getInterpolatedValue(int pos, const QPersistentModelIndex &index) const;
void refresh();
Q_INVOKABLE KeyframeModel *getKeyModel();
protected:
/** @brief Helper function to apply a given operation on all parameters */
bool applyOperation(const std::function<bool(std::shared_ptr<KeyframeModel>, Fun&, Fun&)> &op, const QString &undoString);
bool applyOperation(const std::function<bool(std::shared_ptr<KeyframeModel>, Fun &, Fun &)> &op, const QString &undoString);
signals:
void modelChanged();
private:
std::weak_ptr<AssetParameterModel> m_model;
std::weak_ptr<DocUndoStack> m_undoStack;
std::unordered_map<QPersistentModelIndex, std::shared_ptr<KeyframeModel>> m_parameters;
......
......@@ -210,7 +210,7 @@ void KeyframeView::mouseReleaseEvent(QMouseEvent *event)
GenTime targetPos(m_currentKeyframe, pCore->getCurrentFps());
bool ok1 = m_model->moveKeyframe(targetPos, initPos, false);
bool ok2 = m_model->moveKeyframe(initPos, targetPos, true);
qDebug() << "RELEASING keyframe move"<<ok1<<ok2<<initPos.frames(pCore->getCurrentFps())<<targetPos.frames(pCore->getCurrentFps());
qDebug() << "RELEASING keyframe move" << ok1 << ok2 << initPos.frames(pCore->getCurrentFps()) << targetPos.frames(pCore->getCurrentFps());
}
}
......@@ -268,18 +268,19 @@ void KeyframeView::paintEvent(QPaintEvent *event)
double scaledPos = pos * m_scale;
p.drawLine(QPointF(scaledPos, headOffset), QPointF(scaledPos, m_lineHeight + headOffset / 2.0));
switch (keyframe.second.first) {
case KeyframeType::Linear: {
QPolygonF position = QPolygonF() << QPointF(-headOffset / 2.0, headOffset / 2.0) << QPointF(0, 0) << QPointF(headOffset / 2.0, headOffset / 2.0) << QPointF(0, headOffset);
position.translate(scaledPos, 0);
p.drawPolygon(position);
break;
}
case KeyframeType::Discrete:
p.drawRect(QRectF(scaledPos - headOffset / 2.0, 0, headOffset, headOffset));
break;
default:
p.drawEllipse(QRectF(scaledPos - headOffset / 2.0, 0, headOffset, headOffset));
break;
case KeyframeType::Linear: {
QPolygonF position = QPolygonF() << QPointF(-headOffset / 2.0, headOffset / 2.0) << QPointF(0, 0) << QPointF(headOffset / 2.0, headOffset / 2.0)
<< QPointF(0, headOffset);
position.translate(scaledPos, 0);
p.drawPolygon(position);
break;
}
case KeyframeType::Discrete:
p.drawRect(QRectF(scaledPos - headOffset / 2.0, 0, headOffset, headOffset));
break;
default:
p.drawEllipse(QRectF(scaledPos - headOffset / 2.0, 0, headOffset, headOffset));
break;
}
}
......
......@@ -23,9 +23,9 @@
#define ASSETCOMMAND_H
#include "assetparametermodel.hpp"
#include <QPersistentModelIndex>
#include <QTime>
#include <QUndoCommand>
#include <QPersistentModelIndex>
class AssetCommand : public QUndoCommand
{
......
......@@ -29,8 +29,8 @@
#include <QLocale>
#include <QString>
AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomElement &assetXml, const QString &assetId, ObjectId ownerId, Kdenlive::MonitorId monitor,
QObject *parent)
AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomElement &assetXml, const QString &assetId, ObjectId ownerId,
Kdenlive::MonitorId monitor, QObject *parent)
: QAbstractListModel(parent)
, monitorId(monitor)
, m_xml(assetXml)
......@@ -83,7 +83,7 @@ AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomEleme
if (isFixed) {
m_fixedParams[name] = value;
}
qDebug() << "PARAMETER"<<name<<type<<value<<isFixed;
qDebug() << "PARAMETER" << name << type << value << isFixed;
setParameter(name, value);
if (isFixed) {
// fixed parameters are not displayed so we don't store them.
......@@ -97,20 +97,18 @@ AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomEleme
currentRow.name = title.isEmpty() ? name : title;
m_params[name] = currentRow;
m_rows.push_back(name);
}
qDebug() << "END parsing of "<<assetId<<". Number of found parameters"<<m_rows.size();
qDebug() << "END parsing of " << assetId << ". Number of found parameters" << m_rows.size();
emit modelChanged();
}
void AssetParameterModel::prepareKeyframes()
{
if (m_keyframes)
return;
if (m_keyframes) return;
int ix = 0;
for (const auto& name: m_rows) {
for (const auto &name : m_rows) {
if (m_params[name].type == ParamType::KeyframeParam || m_params[name].type == ParamType::AnimatedRect) {
addKeyframeParam(index(ix, 0));
addKeyframeParam(index(ix, 0));
}
ix++;
}
......@@ -387,4 +385,3 @@ std::shared_ptr<KeyframeModelList> AssetParameterModel::getKeyframeModel()
{
return m_keyframes;
}
......@@ -24,9 +24,9 @@
#include "assets/model/assetcommand.hpp"
#include "assets/model/assetparametermodel.hpp"
#include "assets/view/widgets/abstractparamwidget.hpp"
#include "assets/view/widgets/keyframewidget.hpp"
#include "core.h"
#include "widgets/animationwidget.h"
#include "assets/view/widgets/keyframewidget.hpp"
#include <QDebug>
#include <QFontDatabase>
......@@ -55,13 +55,14 @@ void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &mo
for (int i = 0; i < model->rowCount(); ++i) {
QModelIndex index = model->index(i, 0);
auto type = model->data(index, AssetParameterModel::TypeRole).value<ParamType>();
if (m_mainKeyframeWidget && (type == ParamType::Geometry || type == ParamType::Animated || type == ParamType::RestrictedAnim || type == ParamType::KeyframeParam)) {
if (m_mainKeyframeWidget &&
(type == ParamType::Geometry || type == ParamType::Animated || type == ParamType::RestrictedAnim || type == ParamType::KeyframeParam)) {
// Keyframe widget can have some extra params that should'nt build a new widget
qDebug()<<"// FOUND ADDED PARAM";
qDebug() << "// FOUND ADDED PARAM";
m_mainKeyframeWidget->addParameter(index);
} else {
auto w = AbstractParamWidget::construct(model, index, range, frameSize, this);
qDebug()<<"// FOUND GEOM PARAM";
qDebug() << "// FOUND GEOM PARAM";
/*if (type == ParamType::Geometry || type == ParamType::Animated || type == ParamType::RestrictedAnim || type == ParamType::AnimatedRect) {
animWidget = static_cast<AnimationWidget *>(w);
}*/
......@@ -93,7 +94,7 @@ void AssetParameterView::resetValues()
void AssetParameterView::setRange(QPair<int, int> range)
{
qDebug() << "SETTING RANGE"<<range;
qDebug() << "SETTING RANGE" << range;
QMutexLocker lock(&m_lock);
for (int i = 0; i < m_widgets.size(); ++i) {
auto w = m_widgets[i];
......
......@@ -22,8 +22,8 @@
#include "assets/model/assetparametermodel.hpp"