timeline: made ghosts a foreground drawn object
Minor optimization, minor UI improvement, somewhat more manageable code.
This commit is contained in:
@@ -38,6 +38,7 @@ OLIVE_NAMESPACE_ENTER
|
||||
TimelineView::TimelineView(Qt::Alignment vertical_alignment, QWidget *parent) :
|
||||
TimelineViewBase(parent),
|
||||
selections_(nullptr),
|
||||
ghosts_(nullptr),
|
||||
show_beam_cursor_(false),
|
||||
connected_track_list_(nullptr)
|
||||
{
|
||||
@@ -229,21 +230,7 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
TimelineViewBase::drawForeground(painter, rect);
|
||||
|
||||
if (show_beam_cursor_
|
||||
&& connected_track_list_
|
||||
&& cursor_coord_.GetTrack().type() == connected_track_list_->type()) {
|
||||
painter->setPen(Qt::gray);
|
||||
|
||||
double cursor_x = TimeToScene(cursor_coord_.GetFrame());
|
||||
int track_index = cursor_coord_.GetTrack().index();
|
||||
int track_y = GetTrackY(track_index);
|
||||
|
||||
painter->drawLine(cursor_x,
|
||||
track_y,
|
||||
cursor_x,
|
||||
track_y + GetTrackHeight(track_index));
|
||||
}
|
||||
|
||||
// Draw selections
|
||||
if (selections_ && !selections_->isEmpty()) {
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QColor(0, 0, 0, 64));
|
||||
@@ -261,6 +248,39 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw ghosts
|
||||
if (ghosts_ && !ghosts_->isEmpty()) {
|
||||
painter->setPen(QPen(Qt::yellow, 2));
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, (*ghosts_)) {
|
||||
if (ghost->GetTrack().type() == connected_track_list_->type()) {
|
||||
int track_index = ghost->GetAdjustedTrack().index();
|
||||
|
||||
painter->drawRect(TimeToScene(ghost->GetAdjustedIn()),
|
||||
GetTrackY(track_index),
|
||||
TimeToScene(ghost->GetAdjustedLength()),
|
||||
GetTrackHeight(track_index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw beam cursor
|
||||
if (show_beam_cursor_
|
||||
&& connected_track_list_
|
||||
&& cursor_coord_.GetTrack().type() == connected_track_list_->type()) {
|
||||
painter->setPen(Qt::gray);
|
||||
|
||||
double cursor_x = TimeToScene(cursor_coord_.GetFrame());
|
||||
int track_index = cursor_coord_.GetTrack().index();
|
||||
int track_y = GetTrackY(track_index);
|
||||
|
||||
painter->drawLine(cursor_x,
|
||||
track_y,
|
||||
cursor_x,
|
||||
track_y + GetTrackHeight(track_index));
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::ToolChangedEvent(Tool::Item tool)
|
||||
|
||||
@@ -64,6 +64,11 @@ public:
|
||||
selections_ = s;
|
||||
}
|
||||
|
||||
void SetGhostList(QVector<TimelineViewGhostItem*>* ghosts)
|
||||
{
|
||||
ghosts_ = ghosts;
|
||||
}
|
||||
|
||||
signals:
|
||||
void MousePressed(TimelineViewMouseEvent* event);
|
||||
void MouseMoved(TimelineViewMouseEvent* event);
|
||||
@@ -115,6 +120,8 @@ private:
|
||||
|
||||
QHash<TrackReference, TimeRangeList>* selections_;
|
||||
|
||||
QVector<TimelineViewGhostItem*>* ghosts_;
|
||||
|
||||
bool show_beam_cursor_;
|
||||
|
||||
TimelineCoordinate cursor_coord_;
|
||||
|
||||
@@ -24,18 +24,17 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
TimelineViewGhostItem::TimelineViewGhostItem(QGraphicsItem *parent) :
|
||||
TimelineViewRect(parent),
|
||||
TimelineViewGhostItem::TimelineViewGhostItem() :
|
||||
track_adj_(0),
|
||||
stream_(nullptr),
|
||||
mode_(Timeline::kNone),
|
||||
can_have_zero_length_(true),
|
||||
can_move_tracks_(true)
|
||||
can_move_tracks_(true),
|
||||
invisible_(false)
|
||||
{
|
||||
SetInvisible(false);
|
||||
}
|
||||
|
||||
TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const TrackReference& track, int y, int height)
|
||||
TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const TrackReference& track)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
@@ -43,8 +42,7 @@ TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const Trac
|
||||
ghost->SetOut(block->out());
|
||||
ghost->SetMediaIn(block->media_in());
|
||||
ghost->SetTrack(track);
|
||||
ghost->SetYCoords(y, height);
|
||||
ghost->setData(kAttachedBlock, Node::PtrToValue(block));
|
||||
ghost->SetData(kAttachedBlock, Node::PtrToValue(block));
|
||||
|
||||
switch (block->type()) {
|
||||
case Block::kClip:
|
||||
@@ -76,7 +74,7 @@ void TimelineViewGhostItem::SetCanMoveTracks(bool e)
|
||||
can_move_tracks_ = e;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetInvisible(bool invisible)
|
||||
/*void TimelineViewGhostItem::SetInvisible(bool invisible)
|
||||
{
|
||||
setBrush(Qt::NoBrush);
|
||||
|
||||
@@ -85,7 +83,7 @@ void TimelineViewGhostItem::SetInvisible(bool invisible)
|
||||
} else {
|
||||
setPen(QPen(Qt::yellow, 2)); // FIXME: Make customizable via CSS
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
const rational &TimelineViewGhostItem::GetIn() const
|
||||
{
|
||||
@@ -115,15 +113,11 @@ rational TimelineViewGhostItem::GetAdjustedLength() const
|
||||
void TimelineViewGhostItem::SetIn(const rational &in)
|
||||
{
|
||||
in_ = in;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetOut(const rational &out)
|
||||
{
|
||||
out_ = out;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetMediaIn(const rational &media_in)
|
||||
@@ -134,15 +128,11 @@ void TimelineViewGhostItem::SetMediaIn(const rational &media_in)
|
||||
void TimelineViewGhostItem::SetInAdjustment(const rational &in_adj)
|
||||
{
|
||||
in_adj_ = in_adj;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetOutAdjustment(const rational &out_adj)
|
||||
{
|
||||
out_adj_ = out_adj;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetTrackAdjustment(const int &track_adj)
|
||||
@@ -213,13 +203,4 @@ bool TimelineViewGhostItem::HasBeenAdjusted() const
|
||||
|| GetTrackAdjustment() != 0;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::UpdateRect()
|
||||
{
|
||||
rational length = GetAdjustedOut() - GetAdjustedIn();
|
||||
|
||||
setRect(0, y_, TimeToScene(length), height_ - 1);
|
||||
|
||||
setPos(TimeToScene(GetAdjustedIn()), 0);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -32,7 +32,7 @@ OLIVE_NAMESPACE_ENTER
|
||||
/**
|
||||
* @brief A graphical representation of changes the user is making before they apply it
|
||||
*/
|
||||
class TimelineViewGhostItem : public TimelineViewRect
|
||||
class TimelineViewGhostItem
|
||||
{
|
||||
public:
|
||||
enum DataType {
|
||||
@@ -44,17 +44,15 @@ public:
|
||||
kTrimShouldBeIgnored
|
||||
};
|
||||
|
||||
TimelineViewGhostItem(QGraphicsItem* parent = nullptr);
|
||||
TimelineViewGhostItem();
|
||||
|
||||
static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track, int y, int height);
|
||||
static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track);
|
||||
|
||||
bool CanHaveZeroLength() const;
|
||||
|
||||
bool GetCanMoveTracks() const;
|
||||
void SetCanMoveTracks(bool e);
|
||||
|
||||
void SetInvisible(bool invisible);
|
||||
|
||||
const rational& GetIn() const;
|
||||
const rational& GetOut() const;
|
||||
const rational& GetMediaIn() const;
|
||||
@@ -86,7 +84,35 @@ public:
|
||||
|
||||
bool HasBeenAdjusted() const;
|
||||
|
||||
virtual void UpdateRect() override;
|
||||
QVariant GetData(int key) const
|
||||
{
|
||||
return data_.value(key);
|
||||
}
|
||||
|
||||
void SetData(int key, const QVariant& value)
|
||||
{
|
||||
data_.insert(key, value);
|
||||
}
|
||||
|
||||
const TrackReference& GetTrack() const
|
||||
{
|
||||
return track_;
|
||||
}
|
||||
|
||||
void SetTrack(const TrackReference& track)
|
||||
{
|
||||
track_ = track;
|
||||
}
|
||||
|
||||
bool IsInvisible() const
|
||||
{
|
||||
return invisible_;
|
||||
}
|
||||
|
||||
void SetInvisible(bool e)
|
||||
{
|
||||
invisible_ = e;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -107,6 +133,13 @@ private:
|
||||
|
||||
bool can_have_zero_length_;
|
||||
bool can_move_tracks_;
|
||||
|
||||
TrackReference track_;
|
||||
|
||||
QHash<int, QVariant> data_;
|
||||
|
||||
bool invisible_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
Reference in New Issue
Block a user