Commit 0a892205 authored by Nicolas Carion's avatar Nicolas Carion
Browse files

Update view to display keyframe list

parent da4d6336
......@@ -30,12 +30,18 @@
#include <QDebug>
KeyframeModelList::KeyframeModelList(double init_value, std::weak_ptr<AssetParameterModel> model, const QModelIndex &index, std::weak_ptr<DocUndoStack> undo_stack, QObject *parent)
KeyframeModelList::KeyframeModelList(double init_value, 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)
{
std::shared_ptr<KeyframeModel> parameter (new KeyframeModel(init_value, model, index, undo_stack, parent));
addParameter(index, init_value);
connect(m_parameters.begin()->second.get(), &KeyframeModel::modelChanged, this, &KeyframeModelList::modelChanged);
}
void KeyframeModelList::addParameter(const QModelIndex &index, double init_value)
{
std::shared_ptr<KeyframeModel> parameter (new KeyframeModel(init_value, m_model, index, m_undoStack));
m_parameters.insert({index, std::move(parameter)});
}
......@@ -61,6 +67,7 @@ bool KeyframeModelList::applyOperation(const std::function<bool(std::shared_ptr<
}
return res;
}
bool KeyframeModelList::addKeyframe(GenTime pos, KeyframeType type)
{
QWriteLocker locker(&m_lock);
......
......@@ -33,6 +33,7 @@
#include <map>
#include <memory>
#include <unordered_map>
#include <QObject>
class AssetParameterModel;
class DocUndoStack;
......@@ -42,15 +43,19 @@ class DocUndoStack;
but we regroup all of these in a common class to provide unified access.
*/
class KeyframeModelList
class KeyframeModelList : public QObject
{
Q_OBJECT
public:
/* @brief Construct a keyframe list bound to the given asset
@param init_value and index correspond to the first parameter
*/
explicit KeyframeModelList(double init_value, std::weak_ptr<AssetParameterModel> model, const QModelIndex &index, std::weak_ptr<DocUndoStack> undo_stack, QObject *parent = nullptr);
explicit KeyframeModelList(double init_value, std::weak_ptr<AssetParameterModel> model, const QModelIndex &index, std::weak_ptr<DocUndoStack> undo_stack);
/* @brief Add a keyframable parameter to be managed by this model */
void addParameter(const QModelIndex &index, double init_value);
/* @brief Adds a keyframe at the given position. If there is already one then we update it.
@param pos defines the position of the keyframe, relative to the clip
......@@ -108,6 +113,9 @@ 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);
signals:
void modelChanged();
private:
std::weak_ptr<AssetParameterModel> m_model;
......
......@@ -26,7 +26,7 @@
#include <KColorScheme>
#include <QFontDatabase>
KeyframeView::KeyframeView(std::shared_ptr<KeyframeModel> model, QWidget *parent)
KeyframeView::KeyframeView(std::shared_ptr<KeyframeModelList> model, QWidget *parent)
: QWidget(parent)
, m_model(model)
, m_duration(1)
......@@ -49,7 +49,7 @@ KeyframeView::KeyframeView(std::shared_ptr<KeyframeModel> model, QWidget *parent
m_lineHeight = m_size / 2;
setMinimumHeight(m_size);
setMaximumHeight(m_size);
connect(m_model.get(), &KeyframeModel::modelChanged, [&](){
connect(m_model.get(), &KeyframeModelList::modelChanged, [&](){
emit atKeyframe(m_model->hasKeyframe(m_position));
update();
});
......@@ -65,20 +65,20 @@ void KeyframeView::slotSetPosition(int pos)
}
}
void KeyframeView::slotAddKeyframe(int pos, double value)
void KeyframeView::slotAddKeyframe(int pos)
{
if (pos < 0) {
pos = m_position;
}
m_model->addKeyframe(GenTime(pos, pCore->getCurrentFps()), m_currentType, value);
m_model->addKeyframe(GenTime(pos, pCore->getCurrentFps()), m_currentType);
}
void KeyframeView::slotAddRemove(double value)
void KeyframeView::slotAddRemove()
{
if (m_model->hasKeyframe(m_position)) {
slotRemoveKeyframe(m_position);
} else {
slotAddKeyframe(m_position, value);
slotAddKeyframe(m_position);
}
}
......@@ -221,8 +221,7 @@ void KeyframeView::mouseDoubleClickEvent(QMouseEvent *event)
}
// add new keyframe
double value = m_model->getInterpolatedValue(pos);
m_model->addKeyframe(position, m_currentType, value);
m_model->addKeyframe(position, m_currentType);
} else {
QWidget::mouseDoubleClickEvent(event);
}
......
......@@ -21,15 +21,18 @@
#define KEYFRAMEVIEW_H
#include "effects/keyframes/keyframemodel.hpp"
#include "effects/keyframes/keyframemodellist.hpp"
#include <QWidget>
#include <memory>
class KeyframeModelList;
class KeyframeView : public QWidget
{
Q_OBJECT
public:
explicit KeyframeView(std::shared_ptr<KeyframeModel> model, QWidget *parent = nullptr);
explicit KeyframeView(std::shared_ptr<KeyframeModelList> model, QWidget *parent = nullptr);
void setDuration(int dur);
public slots:
......@@ -42,11 +45,11 @@ public slots:
/* @brief Add a keyframe with given parameter value at given pos.
If pos is negative, then keyframe is added at current position
*/
void slotAddKeyframe(int pos = -1, double value = 0);
void slotAddKeyframe(int pos = -1);
/* @brief If there is a keyframe at current position, it is removed.
Otherwise, we add a new one with given value.
*/
void slotAddRemove(double value);
void slotAddRemove();
void slotGoToNext();
void slotGoToPrev();
......@@ -59,7 +62,7 @@ protected:
void wheelEvent(QWheelEvent *event) override;
private:
std::shared_ptr<KeyframeModel> m_model;
std::shared_ptr<KeyframeModelList> m_model;
int m_duration;
int m_position;
int m_currentKeyframe;
......
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