began some rewrites to timeline drawing

This commit is contained in:
itsmattkc
2021-01-14 10:30:20 +11:00
parent fbdda3d6d4
commit f7883bd02c
60 changed files with 3134 additions and 951 deletions
+60 -17
View File
@@ -229,6 +229,13 @@ void TimelineView::drawBackground(QPainter *painter, const QRectF &rect)
void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
{
if (!connected_track_list_) {
return;
}
// Draw block backgrounds
DrawBlocks(painter, false);
// Draw selections
if (selections_ && !selections_->isEmpty()) {
painter->setPen(Qt::NoPen);
@@ -248,6 +255,9 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
}
}
// Draw block foregrounds
DrawBlocks(painter, true);
// Draw ghosts
if (ghosts_ && !ghosts_->isEmpty()) {
painter->setPen(QPen(Qt::yellow, 2));
@@ -268,7 +278,6 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
// Draw beam cursor
if (show_beam_cursor_
&& connected_track_list_
&& cursor_coord_.GetTrack().type() == connected_track_list_->type()) {
painter->setPen(Qt::gray);
@@ -328,20 +337,20 @@ Track::Type TimelineView::ConnectedTrackType()
return connected_track_list_->type();
}
return Timeline::kTrackTypeNone;
return Track::kNone;
}
Stream::Type TimelineView::TrackTypeToStreamType(Track::Type track_type)
{
switch (track_type) {
case Timeline::kTrackTypeNone:
case Timeline::kTrackTypeCount:
case Track::kNone:
case Track::kCount:
break;
case Timeline::kTrackTypeVideo:
case Track::kVideo:
return Stream::kVideo;
case Timeline::kTrackTypeAudio:
case Track::kAudio:
return Stream::kAudio;
case Timeline::kTrackTypeSubtitle:
case Track::kSubtitle:
return Stream::kSubtitle;
}
@@ -355,7 +364,7 @@ TimelineCoordinate TimelineView::ScreenToCoordinate(const QPoint& pt)
TimelineCoordinate TimelineView::SceneToCoordinate(const QPointF& pt)
{
return TimelineCoordinate(SceneToTime(pt.x()), TrackReference(ConnectedTrackType(), SceneToTrack(pt.y())));
return TimelineCoordinate(SceneToTime(pt.x()), Track::Reference(ConnectedTrackType(), SceneToTrack(pt.y())));
}
TimelineViewMouseEvent TimelineView::CreateMouseEvent(QMouseEvent *event)
@@ -370,11 +379,53 @@ TimelineViewMouseEvent TimelineView::CreateMouseEvent(const QPoint& pos, Qt::Mou
return TimelineViewMouseEvent(scene_pt.x(),
GetScale(),
timebase(),
TrackReference(ConnectedTrackType(), SceneToTrack(scene_pt.y())),
Track::Reference(ConnectedTrackType(), SceneToTrack(scene_pt.y())),
button,
modifiers);
}
void TimelineView::DrawBlocks(QPainter *painter, bool foreground)
{
rational start_time = SceneToTime(0);
rational end_time = SceneToTime(viewport()->width());
foreach (Track* track, connected_track_list_->GetTracks()) {
// Get first visible block in this track
Block* block = track->NearestBlockBeforeOrAt(start_time);
while (block) {
if (block->type() == Block::kClip) {
qreal block_left = qMax(0.0, TimeToScene(block->in()));
qreal block_right = qMin(qreal(viewport()->width()), TimeToScene(block->out()));
QRectF r(block_left,
GetTrackY(track->Index()),
block_right - block_left,
GetTrackHeight(track->Index()));
if (foreground) {
painter->setPen(Qt::white);
painter->setBrush(Qt::NoBrush);
painter->drawText(r, block->GetLabel());
} else {
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(128, 128, 192));
painter->drawRect(r);
}
}
if (block->out() >= end_time) {
// Rest of the clips are offscreen, can break loop now
break;
}
block = block->next();
}
}
}
int TimelineView::GetHeightOfAllTracks() const
{
if (connected_track_list_) {
@@ -436,15 +487,7 @@ void TimelineView::SetScrollCoordinates(const QPoint &pt)
void TimelineView::ConnectTrackList(TrackList *list)
{
if (connected_track_list_) {
disconnect(connected_track_list_, SIGNAL(TrackHeightChanged(int, int)), viewport(), SLOT(update()));
}
connected_track_list_ = list;
if (connected_track_list_) {
connect(connected_track_list_, SIGNAL(TrackHeightChanged(int, int)), viewport(), SLOT(update()));
}
}
void TimelineView::SetBeamCursor(const TimelineCoordinate &coord)
@@ -56,7 +56,7 @@ public:
void SetBeamCursor(const TimelineCoordinate& coord);
void SetSelectionList(QHash<TrackReference, TimeRangeList>* s)
void SetSelectionList(QHash<Track::Reference, TimeRangeList>* s)
{
selections_ = s;
}
@@ -66,6 +66,8 @@ public:
ghosts_ = ghosts;
}
int SceneToTrack(double y);
signals:
void MousePressed(TimelineViewMouseEvent* event);
void MouseMoved(TimelineViewMouseEvent* event);
@@ -107,15 +109,15 @@ private:
TimelineViewMouseEvent CreateMouseEvent(QMouseEvent* event);
TimelineViewMouseEvent CreateMouseEvent(const QPoint &pos, Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
int GetHeightOfAllTracks() const;
void DrawBlocks(QPainter* painter, bool foreground);
int SceneToTrack(double y);
int GetHeightOfAllTracks() const;
void UserSetTime(const int64_t& time);
void UpdatePlayheadRect();
QHash<TrackReference, TimeRangeList>* selections_;
QHash<Track::Reference, TimeRangeList>* selections_;
QVector<TimelineViewGhostItem*>* ghosts_;
@@ -25,7 +25,6 @@
#include "project/item/footage/footage.h"
#include "timeline/timelinecommon.h"
#include "timeline/trackreference.h"
namespace olive {
/**
@@ -52,14 +51,14 @@ public:
{
}
static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track)
static TimelineViewGhostItem* FromBlock(Block *block)
{
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
ghost->SetIn(block->in());
ghost->SetOut(block->out());
ghost->SetMediaIn(block->media_in());
ghost->SetTrack(track);
ghost->SetTrack(block->track()->ToReference());
ghost->SetData(kAttachedBlock, Node::PtrToValue(block));
switch (block->type()) {
@@ -187,9 +186,9 @@ public:
return media_in_ + media_in_adj_;
}
TrackReference GetAdjustedTrack() const
Track::Reference GetAdjustedTrack() const
{
return TrackReference(track_.type(), track_.index() + track_adj_);
return Track::Reference(track_.type(), track_.index() + track_adj_);
}
const Timeline::MovementMode& GetMode() const
@@ -220,12 +219,12 @@ public:
data_.insert(key, value);
}
const TrackReference& GetTrack() const
const Track::Reference& GetTrack() const
{
return track_;
}
void SetTrack(const TrackReference& track)
void SetTrack(const Track::Reference& track)
{
track_ = track;
}
@@ -258,7 +257,7 @@ private:
bool can_have_zero_length_;
bool can_move_tracks_;
TrackReference track_;
Track::Reference track_;
QHash<int, QVariant> data_;
@@ -36,7 +36,7 @@ public:
TimelineViewMouseEvent(const qreal& scene_x,
const double& scale_x,
const rational& timebase,
const TrackReference &track,
const Track::Reference &track,
const Qt::MouseButton &button,
const Qt::KeyboardModifiers& modifiers = Qt::NoModifier) :
scene_x_(scene_x),
@@ -74,7 +74,7 @@ public:
return TimeScaledObject::SceneToTime(scene_x_, scale_x_, timebase_, round);
}
const TrackReference& GetTrack() const
const Track::Reference& GetTrack() const
{
return track_;
}
@@ -121,7 +121,7 @@ private:
double scale_x_;
rational timebase_;
TrackReference track_;
Track::Reference track_;
Qt::MouseButton button_;