ported seekablewidget to timebasedview

Cuts down on a lot of code duplication and opens up usage of the new TimelineViewSelectionManager framework
This commit is contained in:
itsmattkc
2022-05-01 15:45:20 -07:00
parent f04ff5f1ff
commit cdcd83c09a
32 changed files with 425 additions and 1213 deletions
+37 -28
View File
@@ -58,6 +58,17 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare
// Connect context menu
connect(this, &TimeRuler::customContextMenuRequested, this, &TimeRuler::ShowContextMenu);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//horizontalScrollBar()->setVisible(false);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setBackgroundRole(QPalette::Window);
setFrameShape(QFrame::NoFrame);
// NOTE: One day it might be preferable to use AlignBottom because the lines are anchored to
// the bottom of the widget. However, for now this makes sense since we just ported this
// from a QWidget's paintEvent.
setAlignment(Qt::AlignLeft | Qt::AlignTop);
}
void TimeRuler::SetPlaybackCache(PlaybackCache *cache)
@@ -83,15 +94,13 @@ void TimeRuler::SetPlaybackCache(PlaybackCache *cache)
update();
}
void TimeRuler::paintEvent(QPaintEvent *)
void TimeRuler::drawForeground(QPainter *p, const QRectF &rect)
{
// Nothing to paint if the timebase is invalid
if (timebase().isNull()) {
return;
}
QPainter p(this);
// Draw timeline points if connected
if (timeline_points()) {
int marker_bottom = height() - text_height();
@@ -104,7 +113,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
marker_bottom -= cache_status_height_;
}
DrawTimelinePoints(&p, marker_bottom);
DrawTimelinePoints(p, marker_bottom);
}
double width_of_frame = timebase_dbl() * GetScale();
@@ -173,11 +182,11 @@ void TimeRuler::paintEvent(QPaintEvent *)
}
// Set line color to main text color
p.setBrush(Qt::NoBrush);
p.setPen(palette().text().color());
p->setBrush(Qt::NoBrush);
p->setPen(palette().text().color());
// Calculate line dimensions
QFontMetrics fm = p.fontMetrics();
QFontMetrics fm = p->fontMetrics();
int line_bottom = height();
if (show_cache_status_) {
@@ -197,8 +206,8 @@ void TimeRuler::paintEvent(QPaintEvent *)
// FIXME: Hardcoded number
const int kAverageTextWidth = 200;
for (int i=-kAverageTextWidth;i<width()+kAverageTextWidth;i++) {
double screen_pt = static_cast<double>(i + GetScroll());
for (int i=GetScroll()-kAverageTextWidth;i<GetScroll()+width()+kAverageTextWidth;i++) {
double screen_pt = static_cast<double>(i);
if (long_interval > -1) {
int this_long_unit = qFloor(screen_pt/long_interval);
@@ -208,7 +217,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
if (text_visible_) {
QRect text_rect;
Qt::Alignment text_align;
QString timecode_str = Timecode::time_to_timecode(ScreenToTime(i), timebase(), Core::instance()->GetTimecodeDisplay());
QString timecode_str = Timecode::time_to_timecode(SceneToTime(i), timebase(), Core::instance()->GetTimecodeDisplay());
int timecode_width = QtUtils::QFontMetricsWidth(fm, timecode_str);
int timecode_left;
@@ -226,9 +235,9 @@ void TimeRuler::paintEvent(QPaintEvent *)
}
if (timecode_left > last_text_draw) {
p.drawText(text_rect,
static_cast<int>(text_align),
timecode_str);
p->drawText(text_rect,
static_cast<int>(text_align),
timecode_str);
last_text_draw = timecode_left + timecode_width;
@@ -238,7 +247,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
}
}
p.drawLine(i, line_y, i, line_bottom);
p->drawLine(i, line_y, i, line_bottom);
last_long_unit = this_long_unit;
}
}
@@ -246,7 +255,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
if (short_interval > -1) {
int this_short_unit = qFloor(screen_pt/short_interval);
if (this_short_unit != last_short_unit) {
p.drawLine(i, short_y, i, line_bottom);
p->drawLine(i, short_y, i, line_bottom);
last_short_unit = this_short_unit;
}
}
@@ -257,40 +266,40 @@ void TimeRuler::paintEvent(QPaintEvent *)
// FIXME: Hardcoded to get video length, if we ever need audio length, this will have to change
rational len = playback_cache_->viewer_parent()->GetVideoLength();
int cache_screen_length = qMin(TimeToScreen(len), width());
int cache_screen_length = qMin(TimeToScene(len), qreal(width()));
if (cache_screen_length > 0) {
int cache_y = height() - cache_status_height_;
p.fillRect(0, cache_y, cache_screen_length , cache_status_height_, Qt::green);
p->fillRect(0, cache_y, cache_screen_length , cache_status_height_, Qt::green);
foreach (const TimeRange& range, playback_cache_->GetInvalidatedRanges(len)) {
int range_left = TimeToScreen(range.in());
int range_left = TimeToScene(range.in());
if (range_left >= width()) {
continue;
}
int range_right = TimeToScreen(range.out());
int range_right = TimeToScene(range.out());
if (range_right < 0) {
continue;
}
int adjusted_left = qMax(0, range_left);
p.fillRect(adjusted_left,
cache_y,
qMin(width(), range_right) - adjusted_left,
cache_status_height_,
Qt::red);
p->fillRect(adjusted_left,
cache_y,
qMin(width(), range_right) - adjusted_left,
cache_status_height_,
Qt::red);
}
}
}
// Draw the playhead if it's on screen at the moment
int playhead_pos = TimeToScreen(GetTime());
p.setPen(Qt::NoPen);
p.setBrush(PLAYHEAD_COLOR);
DrawPlayhead(&p, playhead_pos, line_bottom);
int playhead_pos = TimeToScene(GetTime());
p->setPen(Qt::NoPen);
p->setBrush(PLAYHEAD_COLOR);
DrawPlayhead(p, playhead_pos, line_bottom);
}
void TimeRuler::TimebaseChangedEvent(const rational &tb)