began UI for keyframing
Largely extending the existing NodeParamView with functionality from the previous release.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# Olive - Non-Linear Video Editor
|
||||
# Copyright (C) 2019 Olive Team
|
||||
#
|
||||
# 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/keyframeview/keyframeview.h
|
||||
widget/keyframeview/keyframeview.cpp
|
||||
widget/keyframeview/keyframeviewitem.h
|
||||
widget/keyframeview/keyframeviewitem.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "keyframeview.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
KeyframeView::KeyframeView(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
|
||||
ruler_ = new TimeRuler();
|
||||
ruler_->SetTextVisible(true);
|
||||
layout->addWidget(ruler_);
|
||||
|
||||
view_ = new QGraphicsView();
|
||||
view_->setScene(&scene_);
|
||||
view_->setBackgroundRole(QPalette::Base);
|
||||
view_->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
view_->setDragMode(QGraphicsView::RubberBandDrag);
|
||||
layout->addWidget(view_);
|
||||
}
|
||||
|
||||
void KeyframeView::SetTimebase(const rational &timebase)
|
||||
{
|
||||
ruler_->SetTimebase(timebase);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef KEYFRAMEVIEW_H
|
||||
#define KEYFRAMEVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "keyframeviewitem.h"
|
||||
#include "widget/timeruler/timeruler.h"
|
||||
|
||||
class KeyframeView : public QWidget
|
||||
{
|
||||
public:
|
||||
KeyframeView(QWidget* parent = nullptr);
|
||||
|
||||
void AddKeyframe(const rational& time, int y);
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
private:
|
||||
TimeRuler* ruler_;
|
||||
QGraphicsView* view_;
|
||||
|
||||
QGraphicsScene scene_;
|
||||
};
|
||||
|
||||
#endif // KEYFRAMEVIEW_H
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "keyframeviewitem.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QWidget>
|
||||
|
||||
#include "common/qtversionabstraction.h"
|
||||
|
||||
KeyframeViewItem::KeyframeViewItem(QGraphicsItem *parent) :
|
||||
QGraphicsRectItem(parent),
|
||||
key_(nullptr),
|
||||
scale_(1.0)
|
||||
{
|
||||
keyframe_size_ = QFontMetricsWidth(qApp->fontMetrics(), "Oi");
|
||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||
setFlag(QGraphicsItem::ItemIsMovable);
|
||||
}
|
||||
|
||||
void KeyframeViewItem::SetKeyframe(NodeKeyframe *key)
|
||||
{
|
||||
key_ = key;
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void KeyframeViewItem::SetVerticalCenter(int middle)
|
||||
{
|
||||
middle_ = middle;
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void KeyframeViewItem::SetScale(double scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void KeyframeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
if (!key_) {
|
||||
return;
|
||||
}
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
painter->setBrush(widget->palette().highlight());
|
||||
} else {
|
||||
painter->setBrush(widget->palette().text());
|
||||
}
|
||||
|
||||
switch (key_->type()) {
|
||||
case NodeKeyframe::kLinear:
|
||||
{
|
||||
QPointF points[] = {
|
||||
QPointF(rect().center().x(), rect().top()),
|
||||
QPointF(rect().right(), rect().center().y()),
|
||||
QPointF(rect().center().x(), rect().bottom()),
|
||||
QPointF(rect().left(), rect().center().y())
|
||||
};
|
||||
|
||||
painter->drawPolygon(points, 4);
|
||||
break;
|
||||
}
|
||||
case NodeKeyframe::kBezier:
|
||||
painter->drawEllipse(rect());
|
||||
break;
|
||||
case NodeKeyframe::kHold:
|
||||
painter->drawRect(rect());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void KeyframeViewItem::UpdateRect()
|
||||
{
|
||||
if (!key_) {
|
||||
return;
|
||||
}
|
||||
|
||||
double x_center = key_->time().toDouble() * scale_;
|
||||
|
||||
setRect(x_center - keyframe_size_/2, middle_ - keyframe_size_/2, keyframe_size_, keyframe_size_);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef KEYFRAMEVIEWITEM_H
|
||||
#define KEYFRAMEVIEWITEM_H
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
#include "node/keyframe.h"
|
||||
|
||||
class KeyframeViewItem : public QGraphicsRectItem
|
||||
{
|
||||
public:
|
||||
KeyframeViewItem(QGraphicsItem *parent = nullptr);
|
||||
|
||||
void SetKeyframe(NodeKeyframe* key);
|
||||
|
||||
void SetVerticalCenter(int middle);
|
||||
|
||||
void SetScale(double scale);
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||
|
||||
private:
|
||||
void UpdateRect();
|
||||
|
||||
NodeKeyframe* key_;
|
||||
|
||||
double scale_;
|
||||
|
||||
int middle_;
|
||||
|
||||
int keyframe_size_;
|
||||
};
|
||||
|
||||
#endif // KEYFRAMEVIEWITEM_H
|
||||
Reference in New Issue
Block a user