timeline/renderer: automatically update timeline view when a visual waveform

has updated
This commit is contained in:
itsmattkc
2020-03-07 02:44:15 +11:00
parent b2792b7c58
commit f2d6d3b32c
6 changed files with 38 additions and 32 deletions
+17 -5
View File
@@ -662,10 +662,9 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
case Block::kTransition:
case Block::kGap:
{
TimelineViewBlockItem* item = new TimelineViewBlockItem();
// Set up clip with view parameters (clip item will automatically size its rect accordingly)
item->SetBlock(block);
TimelineViewBlockItem* item = new TimelineViewBlockItem(block);
item->SetYCoords(GetTrackY(track), GetTrackHeight(track));
item->SetScale(GetScale());
item->SetTrack(track);
@@ -677,6 +676,10 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
views_.at(track.type())->view()->scene()->addItem(item);
connect(block, &Block::Refreshed, this, &TimelineWidget::BlockChanged);
if (block->type() == Block::kClip) {
connect(static_cast<ClipBlock*>(block), &ClipBlock::PreviewUpdated, this, &TimelineWidget::PreviewUpdated);
}
break;
}
}
@@ -721,13 +724,22 @@ void TimelineWidget::ViewSelectionChanged()
void TimelineWidget::BlockChanged()
{
TimelineViewRect* rect = block_items_[static_cast<Block*>(sender())];
TimelineViewRect* rect = block_items_.value(static_cast<Block*>(sender()));
if (rect != nullptr) {
if (rect) {
rect->UpdateRect();
}
}
void TimelineWidget::PreviewUpdated()
{
TimelineViewRect* rect = block_items_.value(static_cast<Block*>(sender()));
if (rect) {
rect->update();
}
}
void TimelineWidget::UpdateHorizontalSplitters()
{
QSplitter* sender_splitter = static_cast<QSplitter*>(sender());
@@ -425,6 +425,8 @@ private slots:
*/
void BlockChanged();
void PreviewUpdated();
void UpdateHorizontalSplitters();
void UpdateTimecodeWidthFromSplitters(QSplitter *s);
@@ -34,23 +34,12 @@
#include "config/config.h"
#include "node/block/transition/transition.h"
TimelineViewBlockItem::TimelineViewBlockItem(QGraphicsItem* parent) :
TimelineViewBlockItem::TimelineViewBlockItem(Block *block, QGraphicsItem* parent) :
TimelineViewRect(parent),
block_(nullptr)
block_(block)
{
setBrush(Qt::white);
setCursor(Qt::DragMoveCursor);
}
Block *TimelineViewBlockItem::block()
{
return block_;
}
void TimelineViewBlockItem::SetBlock(Block *block)
{
block_ = block;
setFlag(QGraphicsItem::ItemIsSelectable,
block_->type() == Block::kClip
|| block_->type() == Block::kGap
@@ -59,12 +48,13 @@ void TimelineViewBlockItem::SetBlock(Block *block)
UpdateRect();
}
Block *TimelineViewBlockItem::block() const
{
return block_;
}
void TimelineViewBlockItem::UpdateRect()
{
if (block_ == nullptr) {
return;
}
double item_left = TimeToScene(block_->in());
double item_width = TimeToScene(block_->length());
@@ -81,12 +71,6 @@ void TimelineViewBlockItem::UpdateRect()
void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget)
if (block_ == nullptr) {
return;
}
switch (block_->type()) {
case Block::kClip:
{
@@ -30,10 +30,9 @@
class TimelineViewBlockItem : public TimelineViewRect
{
public:
TimelineViewBlockItem(QGraphicsItem* parent = nullptr);
TimelineViewBlockItem(Block* block, QGraphicsItem* parent = nullptr);
Block* block();
void SetBlock(Block *block);
Block* block() const;
virtual void UpdateRect() override;