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

Commit 8002a203 authored by Nicolas Carion's avatar Nicolas Carion

Implementing an asset widget for keyframes

parent 0a892205
......@@ -13,6 +13,7 @@ set(kdenlive_SRCS
assets/view/widgets/boolparamwidget.cpp
assets/view/widgets/doubleparamwidget.cpp
# assets/view/widgets/keyframeedit.cpp
assets/view/widgets/keyframewidget.cpp
assets/view/widgets/listparamwidget.cpp
# assets/view/widgets/positioneditwidget.cpp
PARENT_SCOPE)
......
/***************************************************************************
* Copyright (C) 2011 by Till Theato (root@ttill.de) *
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive (www.kdenlive.org). *
* *
* Kdenlive 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. *
* *
* Kdenlive 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 Kdenlive. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "keyframewidget.hpp"
#include "effects/keyframes/view/keyframeview.hpp"
#include "effects/keyframes/keyframemodellist.hpp"
#include "timecodedisplay.h"
#include "utils/KoIconUtils.h"
#include "core.h"
#include <QGridLayout>
#include <QToolButton>
#include <klocalizedstring.h>
KeyframeWidget::KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, double init_value, const Timecode &t, int duration, QWidget *parent)
: QWidget(parent)
, m_model(model)
, m_index(index)
, m_keyframes(new KeyframeModelList(init_value, model, index, pCore->undoStack()))
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
auto *l = new QGridLayout(this);
m_keyframeview = new KeyframeView(m_keyframes, this);
m_keyframeview->setDuration(duration);
m_buttonAddDelete = new QToolButton(this);
m_buttonAddDelete->setAutoRaise(true);
m_buttonAddDelete->setIcon(KoIconUtils::themedIcon(QStringLiteral("list-add")));
m_buttonAddDelete->setToolTip(i18n("Add keyframe"));
m_buttonPrevious = new QToolButton(this);
m_buttonPrevious->setAutoRaise(true);
m_buttonPrevious->setIcon(KoIconUtils::themedIcon(QStringLiteral("media-skip-backward")));
m_buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
m_buttonNext = new QToolButton(this);
m_buttonNext->setAutoRaise(true);
m_buttonNext->setIcon(KoIconUtils::themedIcon(QStringLiteral("media-skip-forward")));
m_buttonNext->setToolTip(i18n("Go to next keyframe"));
m_time = new TimecodeDisplay(t, this);
m_time->setRange(0, duration);
l->addWidget(m_keyframeview, 0, 0, 1, -1);
l->addWidget(m_buttonPrevious, 1, 0);
l->addWidget(m_buttonAddDelete, 1, 1);
l->addWidget(m_buttonNext, 1, 2);
l->addWidget(m_time, 1, 3, Qt::AlignRight);
connect(m_time, &TimecodeDisplay::timeCodeEditingFinished, [&](){slotSetPosition(-1, true);});
connect(m_keyframeview, &KeyframeView::positionChanged, [&](int p){slotSetPosition(p, true);});
connect(m_keyframeview, &KeyframeView::atKeyframe, this, &KeyframeWidget::slotAtKeyframe);
connect(m_buttonAddDelete, &QAbstractButton::pressed, m_keyframeview, &KeyframeView::slotAddRemove);
connect(m_buttonPrevious, &QAbstractButton::pressed, m_keyframeview, &KeyframeView::slotGoToPrev);
connect(m_buttonNext, &QAbstractButton::pressed, m_keyframeview, &KeyframeView::slotGoToNext);
}
KeyframeWidget::~KeyframeWidget()
{
delete m_keyframeview;
delete m_buttonAddDelete;
delete m_buttonPrevious;
delete m_buttonNext;
delete m_time;
}
void KeyframeWidget::slotSetPosition(int pos, bool update)
{
if (pos < 0) {
pos = m_time->getValue();
m_keyframeview->slotSetPosition(pos);
} else {
m_time->setValue(pos);
m_keyframeview->slotSetPosition(pos);
}
if (update) {
emit positionChanged(pos);
}
}
int KeyframeWidget::getPosition() const
{
return m_time->getValue();
}
void KeyframeWidget::addKeyframe(int pos)
{
blockSignals(true);
m_keyframeview->slotAddKeyframe(pos);
blockSignals(false);
setEnabled(true);
}
void KeyframeWidget::updateTimecodeFormat()
{
m_time->slotUpdateTimeCodeFormat();
}
void KeyframeWidget::slotAtKeyframe(bool atKeyframe)
{
if (atKeyframe) {
m_buttonAddDelete->setIcon(KoIconUtils::themedIcon(QStringLiteral("list-remove")));
m_buttonAddDelete->setToolTip(i18n("Delete keyframe"));
} else {
m_buttonAddDelete->setIcon(KoIconUtils::themedIcon(QStringLiteral("list-add")));
m_buttonAddDelete->setToolTip(i18n("Add keyframe"));
}
}
/***************************************************************************
* Copyright (C) 2011 by Till Theato (root@ttill.de) *
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive (www.kdenlive.org). *
* *
* Kdenlive 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. *
* *
* Kdenlive 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 Kdenlive. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef KEYFRAMEWIDGET_H
#define KEYFRAMEWIDGET_H
#include "timecode.h"
#include <QWidget>
#include <QPersistentModelIndex>
#include <memory>
class AssetParameterModel;
class KeyframeModelList;
class KeyframeView;
class QToolButton;
class TimecodeDisplay;
class KeyframeWidget : public QWidget
{
Q_OBJECT
public:
explicit KeyframeWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, double init_value, const Timecode &t, int duration, QWidget *parent = nullptr);
~KeyframeWidget();
int getPosition() const;
void addKeyframe(int pos = -1);
void updateTimecodeFormat();
public slots:
void slotSetPosition(int pos = -1, bool update = true);
private slots:
void slotAtKeyframe(bool atKeyframe);
signals:
void positionChanged(int pos);
private:
std::shared_ptr<AssetParameterModel> m_model;
QPersistentModelIndex m_index;
std::shared_ptr<KeyframeModelList> m_keyframes;
KeyframeView *m_keyframeview;
QToolButton *m_buttonAddDelete;
QToolButton *m_buttonPrevious;
QToolButton *m_buttonNext;
TimecodeDisplay *m_time;
};
#endif
/***************************************************************************
* Copyright (C) 2011 by Till Theato (root@ttill.de) *
* Copyright (C) 2017 by Nicolas Carion *
* This file is part of Kdenlive (www.kdenlive.org). *
* *
* Kdenlive is free software: you can redistribute it and/or modify *
......
......@@ -80,12 +80,6 @@ private:
signals:
void positionChanged(int pos);
void atKeyframe(bool);
void keyframeSelected();
void keyframeMoving(int oldPos, int currentPos);
void keyframeMoved(int oldPos, int newPos);
void keyframeAdded(int pos);
void keyframeRemoved(int pos);
};
#endif
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