moved more functions to the base class in the vein of the previous commit
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
|
||||
@@ -11,6 +12,26 @@ TimelineViewBase::TimelineViewBase(QWidget *parent) :
|
||||
playhead_scene_left_(-1),
|
||||
playhead_scene_right_(-1)
|
||||
{
|
||||
setScene(&scene_);
|
||||
|
||||
// Create end item
|
||||
end_item_ = new TimelineViewEndItem();
|
||||
scene_.addItem(end_item_);
|
||||
|
||||
// Set default scale
|
||||
SetScale(1.0);
|
||||
|
||||
connect(&scene_, SIGNAL(changed(const QList<QRectF>&)), this, SLOT(UpdateSceneRect()));
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetScale(const double &scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
|
||||
// Force redraw for playhead
|
||||
viewport()->update();
|
||||
|
||||
end_item_->SetScale(scale_);
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetTimebase(const rational &timebase)
|
||||
@@ -78,3 +99,50 @@ bool TimelineViewBase::PlayheadRelease(QMouseEvent *event)
|
||||
{
|
||||
return dragging_playhead_;
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetEndTime(const rational &length)
|
||||
{
|
||||
end_item_->SetEndTime(length);
|
||||
}
|
||||
|
||||
void TimelineViewBase::UpdateSceneRect()
|
||||
{
|
||||
QRectF bounding_rect = scene_.itemsBoundingRect();
|
||||
|
||||
// Ensure the scene height is always AT LEAST the height of the view
|
||||
// The scrollbar appears to have a 1px margin on the top and bottom, hence the -2
|
||||
int minimum_height = height() - horizontalScrollBar()->height() - 2;
|
||||
|
||||
if (alignment() & Qt::AlignBottom) {
|
||||
// Ensure the scene left and bottom are always 0
|
||||
bounding_rect.setBottomLeft(QPointF(0, 0));
|
||||
|
||||
if (bounding_rect.top() > minimum_height) {
|
||||
bounding_rect.setTop(-minimum_height);
|
||||
}
|
||||
} else {
|
||||
// Ensure the scene left and top are always 0
|
||||
bounding_rect.setTopLeft(QPointF(0, 0));
|
||||
|
||||
if (bounding_rect.height() < minimum_height) {
|
||||
bounding_rect.setHeight(minimum_height);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the scene is always the full length of the timeline with a gap at the end to work with
|
||||
end_item_->SetEndPadding(width()/4);
|
||||
|
||||
// If the scene is already this rect, do nothing
|
||||
if (scene_.sceneRect() == bounding_rect) {
|
||||
return;
|
||||
}
|
||||
|
||||
scene_.setSceneRect(bounding_rect);
|
||||
}
|
||||
|
||||
void TimelineViewBase::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
|
||||
UpdateSceneRect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user