Commit 94d991dd authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

When only 1 keyframe is present, always allow adjusting param values

parent 800258e0
......@@ -306,6 +306,12 @@ int KeyframeModel::rowCount(const QModelIndex &parent) const
return static_cast<int>(m_keyframeList.size());
}
bool KeyframeModel::singleKeyframe() const
{
READ_LOCK();
return m_keyframeList.size() <= 1;
}
Keyframe KeyframeModel::getKeyframe(const GenTime &pos, bool *ok) const
{
READ_LOCK();
......
......@@ -109,6 +109,9 @@ public:
*/
Keyframe getKeyframe(const GenTime &pos, bool *ok) const;
/* @brief Returns true if we only have 1 keyframe
*/
bool singleKeyframe() const;
/* @brief Returns the keyframe located after given position.
If there is a keyframe at given position it is ignored.
@param ok is a return parameter to tell if a keyframe was found.
......
......@@ -117,6 +117,11 @@ bool KeyframeModelList::updateKeyframe(GenTime pos, double value, const QPersist
Q_ASSERT(m_parameters.count(index) > 0);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
if (singleKeyframe()) {
bool ok = false;
Keyframe kf = m_parameters.begin()->second->getNextKeyframe(GenTime(-1), &ok);
pos = kf.first;
}
bool res = m_parameters.at(index)->updateKeyframe(pos, value, undo, redo);
if (res) {
PUSH_UNDO(undo, redo, i18n("Update keyframe"));
......@@ -132,6 +137,13 @@ Keyframe KeyframeModelList::getKeyframe(const GenTime &pos, bool *ok) const
return m_parameters.begin()->second->getKeyframe(pos, ok);
}
bool KeyframeModelList::singleKeyframe() const
{
READ_LOCK();
Q_ASSERT(m_parameters.size() > 0);
return m_parameters.begin()->second->singleKeyframe();
}
Keyframe KeyframeModelList::getNextKeyframe(const GenTime &pos, bool *ok) const
{
READ_LOCK();
......
......@@ -87,6 +87,10 @@ public:
*/
Keyframe getKeyframe(const GenTime &pos, bool *ok) const;
/* @brief Returns true if we only have 1 keyframe
*/
bool singleKeyframe() const;
/* @brief Returns the keyframe located after given position.
If there is a keyframe at given position it is ignored.
@param ok is a return parameter to tell if a keyframe was found.
......
......@@ -56,7 +56,7 @@ KeyframeView::KeyframeView(std::shared_ptr<KeyframeModelList> model, QWidget *pa
void KeyframeView::slotModelChanged()
{
emit atKeyframe(m_model->hasKeyframe(m_position));
emit atKeyframe(m_model->hasKeyframe(m_position), m_model->singleKeyframe());
emit modified();
update();
}
......@@ -64,7 +64,7 @@ void KeyframeView::slotSetPosition(int pos)
{
if (pos != m_position) {
m_position = pos;
emit atKeyframe(m_model->hasKeyframe(pos));
emit atKeyframe(m_model->hasKeyframe(pos), m_model->singleKeyframe());
emit seekToPos(pos);
update();
}
......@@ -221,7 +221,7 @@ void KeyframeView::mouseDoubleClickEvent(QMouseEvent *event)
m_currentKeyframe = m_currentKeyframeOriginal = -1;
}
if (keyframe.first.frames(pCore->getCurrentFps()) == m_position) {
emit atKeyframe(false);
emit atKeyframe(false, m_model->singleKeyframe());
}
return;
}
......
......@@ -17,8 +17,8 @@
* along with Kdenlive. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef KEYFRAMEVIEW_H
#define KEYFRAMEVIEW_H
#ifndef KEYFRAMEVIEW2_H
#define KEYFRAMEVIEW2_H
#include "assets/keyframes/model/keyframemodel.hpp"
#include "assets/keyframes/model/keyframemodellist.hpp"
......@@ -80,7 +80,7 @@ private:
signals:
void seekToPos(int pos);
void atKeyframe(bool);
void atKeyframe(bool isKeyframe, bool singleKeyframe);
void modified();
};
......
......@@ -138,7 +138,7 @@ void KeyframeWidget::updateTimecodeFormat()
m_time->slotUpdateTimeCodeFormat();
}
void KeyframeWidget::slotAtKeyframe(bool atKeyframe)
void KeyframeWidget::slotAtKeyframe(bool atKeyframe, bool singleKeyframe)
{
if (atKeyframe) {
m_buttonAddDelete->setIcon(KoIconUtils::themedIcon(QStringLiteral("list-remove")));
......@@ -148,7 +148,7 @@ void KeyframeWidget::slotAtKeyframe(bool atKeyframe)
m_buttonAddDelete->setToolTip(i18n("Add keyframe"));
}
for (const auto &w : m_parameters) {
w.second->setEnabled(atKeyframe);
w.second->setEnabled(atKeyframe || singleKeyframe);
}
}
......
......@@ -58,7 +58,7 @@ public slots:
private slots:
/* brief Update the value of the widgets to reflect keyframe change */
void slotRefreshParams();
void slotAtKeyframe(bool atKeyframe);
void slotAtKeyframe(bool atKeyframe, bool singleKeyframe);
private:
QGridLayout *m_lay;
......
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