waveformview: made UI seekable

This commit is contained in:
itsmattkc
2020-03-14 01:57:40 +11:00
parent 73d693f2d5
commit 7f2dcc8200
12 changed files with 233 additions and 185 deletions
+2
View File
@@ -16,6 +16,8 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timeruler/seekablewidget.h
widget/timeruler/seekablewidget.cpp
widget/timeruler/timeruler.h
widget/timeruler/timeruler.cpp
PARENT_SCOPE
+110
View File
@@ -0,0 +1,110 @@
#include "seekablewidget.h"
#include <QMouseEvent>
#include <QtMath>
SeekableWidget::SeekableWidget(QWidget* parent) :
TimelineScaledWidget(parent),
time_(0),
timeline_points_(nullptr),
scroll_(0)
{
}
void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points)
{
if (timeline_points_) {
disconnect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
disconnect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
}
timeline_points_ = points;
if (timeline_points_) {
connect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
connect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
}
update();
}
const int64_t &SeekableWidget::GetTime() const
{
return time_;
}
const int &SeekableWidget::GetScroll() const
{
return scroll_;
}
void SeekableWidget::mousePressEvent(QMouseEvent *event)
{
SeekToScreenPoint(event->pos().x());
}
void SeekableWidget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {
SeekToScreenPoint(event->pos().x());
}
}
void SeekableWidget::ScaleChangedEvent(const double &)
{
update();
}
TimelinePoints *SeekableWidget::timeline_points() const
{
return timeline_points_;
}
void SeekableWidget::SetTime(const int64_t &r)
{
time_ = r;
update();
}
void SeekableWidget::SetScroll(int s)
{
scroll_ = s;
update();
}
double SeekableWidget::ScreenToUnitFloat(int screen)
{
return (screen + scroll_) / GetScale() / timebase_dbl();
}
int64_t SeekableWidget::ScreenToUnit(int screen)
{
return qFloor(ScreenToUnitFloat(screen));
}
int64_t SeekableWidget::ScreenToUnitRounded(int screen)
{
return qRound64(ScreenToUnitFloat(screen));
}
int SeekableWidget::UnitToScreen(int64_t unit)
{
return qFloor(static_cast<double>(unit) * GetScale() * timebase_dbl()) - scroll_;
}
int SeekableWidget::TimeToScreen(const rational &time)
{
return qFloor(time.toDouble() * GetScale()) - scroll_;
}
void SeekableWidget::SeekToScreenPoint(int screen)
{
int64_t timestamp = qMax(static_cast<int64_t>(0), ScreenToUnitRounded(screen));
SetTime(timestamp);
emit TimeChanged(timestamp);
}
+72
View File
@@ -0,0 +1,72 @@
#ifndef SEEKABLEWIDGET_H
#define SEEKABLEWIDGET_H
#include "common/rational.h"
#include "timeline/timelinepoints.h"
#include "widget/timelinewidget/view/timelineplayhead.h"
#include "widget/timelinewidget/timelinescaledobject.h"
class SeekableWidget : public TimelineScaledWidget
{
Q_OBJECT
public:
SeekableWidget(QWidget *parent = nullptr);
const int64_t& GetTime() const;
const int& GetScroll() const;
void ConnectTimelinePoints(TimelinePoints* points);
public slots:
void SetTime(const int64_t &r);
void SetScroll(int s);
protected:
void SeekToScreenPoint(int screen);
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void ScaleChangedEvent(const double&) override;
TimelinePoints* timeline_points() const;
double ScreenToUnitFloat(int screen);
int64_t ScreenToUnit(int screen);
int64_t ScreenToUnitRounded(int screen);
int UnitToScreen(int64_t unit);
int TimeToScreen(const rational& time);
inline const QColor& GetPlayheadColor() const
{
return style_.GetPlayheadColor();
}
inline const QColor& GetPlayheadHighlightColor() const
{
return style_.GetPlayheadHighlightColor();
}
signals:
/**
* @brief Signal emitted whenever the time changes on this ruler, either by user or programatically
*/
void TimeChanged(int64_t);
private:
int64_t time_;
TimelinePlayhead style_;
TimelinePoints* timeline_points_;
int scroll_;
};
#endif // SEEKABLEWIDGET_H
+10 -102
View File
@@ -21,9 +21,7 @@
#include "timeruler.h"
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
#include <QtMath>
#include "common/timecodefunctions.h"
#include "common/qtutils.h"
@@ -31,13 +29,10 @@
#include "core.h"
TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* parent) :
TimelineScaledWidget(parent),
scroll_(0),
SeekableWidget(parent),
text_visible_(text_visible),
centered_text_(true),
time_(0),
show_cache_status_(cache_status_visible),
timeline_points_(nullptr)
show_cache_status_(cache_status_visible)
{
QFontMetrics fm = fontMetrics();
@@ -58,28 +53,6 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare
UpdateHeight();
}
void TimeRuler::ConnectTimelinePoints(TimelinePoints *points)
{
if (timeline_points_) {
disconnect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, &TimeRuler::TimelineWorkareaChanged);
disconnect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, &TimeRuler::TimelineWorkareaChanged);
}
timeline_points_ = points;
if (timeline_points_) {
connect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, &TimeRuler::TimelineWorkareaChanged);
connect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, &TimeRuler::TimelineWorkareaChanged);
}
update();
}
const int64_t &TimeRuler::GetTime()
{
return time_;
}
void TimeRuler::SetCacheStatusLength(const rational &length)
{
if (show_cache_status_) {
@@ -91,20 +64,6 @@ void TimeRuler::SetCacheStatusLength(const rational &length)
}
}
void TimeRuler::SetTime(const int64_t &r)
{
time_ = r;
update();
}
void TimeRuler::SetScroll(int s)
{
scroll_ = s;
update();
}
void TimeRuler::CacheInvalidatedRange(const TimeRange& range)
{
if (show_cache_status_) {
@@ -133,15 +92,15 @@ void TimeRuler::paintEvent(QPaintEvent *)
QPainter p(this);
// Draw timeline points if connected
if (timeline_points_) {
if (timeline_points_->workarea()->enabled()) {
int workarea_left = qMax(0, TimeToScreen(timeline_points_->workarea()->in()));
if (timeline_points()) {
if (timeline_points()->workarea()->enabled()) {
int workarea_left = qMax(0, TimeToScreen(timeline_points()->workarea()->in()));
int workarea_right;
if (timeline_points_->workarea()->out() == TimelineWorkArea::kResetOut) {
if (timeline_points()->workarea()->out() == TimelineWorkArea::kResetOut) {
workarea_right = width();
} else {
workarea_right = qMin(width(), TimeToScreen(timeline_points_->workarea()->out()));
workarea_right = qMin(width(), TimeToScreen(timeline_points()->workarea()->out()));
}
p.fillRect(workarea_left, 0, workarea_right - workarea_left, height(), palette().highlight());
@@ -239,7 +198,7 @@ void TimeRuler::paintEvent(QPaintEvent *)
const int kAverageTextWidth = 200;
for (int i=-kAverageTextWidth;i<width()+kAverageTextWidth;i++) {
double screen_pt = static_cast<double>(i + scroll_);
double screen_pt = static_cast<double>(i + GetScroll());
if (long_interval > -1) {
int this_long_unit = qFloor(screen_pt/long_interval);
@@ -318,26 +277,14 @@ void TimeRuler::paintEvent(QPaintEvent *)
}
// Draw the playhead if it's on screen at the moment
int playhead_pos = UnitToScreen(time_);
int playhead_pos = UnitToScreen(GetTime());
if (playhead_pos + playhead_width_ >= 0 && playhead_pos - playhead_width_ < width()) {
p.setPen(Qt::NoPen);
p.setBrush(style_.PlayheadColor());
p.setBrush(GetPlayheadColor());
DrawPlayhead(&p, playhead_pos, line_bottom);
}
}
void TimeRuler::mousePressEvent(QMouseEvent *event)
{
SeekToScreenPoint(event->pos().x());
}
void TimeRuler::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {
SeekToScreenPoint(event->pos().x());
}
}
void TimeRuler::TimebaseChangedEvent(const rational &tb)
{
timebase_flipped_dbl_ = tb.flipped().toDouble();
@@ -345,11 +292,6 @@ void TimeRuler::TimebaseChangedEvent(const rational &tb)
update();
}
void TimeRuler::ScaleChangedEvent(const double &)
{
update();
}
void TimeRuler::DrawPlayhead(QPainter *p, int x, int y)
{
p->setRenderHint(QPainter::Antialiasing);
@@ -374,40 +316,6 @@ int TimeRuler::CacheStatusHeight() const
return fontMetrics().height() / 4;
}
double TimeRuler::ScreenToUnitFloat(int screen)
{
return (screen + scroll_) / GetScale() / timebase_dbl();
}
int64_t TimeRuler::ScreenToUnit(int screen)
{
return qFloor(ScreenToUnitFloat(screen));
}
int TimeRuler::UnitToScreen(int64_t unit)
{
return qFloor(static_cast<double>(unit) * GetScale() * timebase_dbl()) - scroll_;
}
int TimeRuler::TimeToScreen(const rational &time)
{
return qFloor(time.toDouble() * GetScale()) - scroll_;
}
void TimeRuler::SeekToScreenPoint(int screen)
{
int64_t timestamp = qMax(0, qRound(ScreenToUnitFloat(screen)));
SetTime(timestamp);
emit TimeChanged(timestamp);
}
void TimeRuler::TimelineWorkareaChanged()
{
update();
}
void TimeRuler::UpdateHeight()
{
int height = text_height_;
+2 -45
View File
@@ -24,13 +24,10 @@
#include <QTimer>
#include <QWidget>
#include "common/rational.h"
#include "common/timerange.h"
#include "timeline/timelinepoints.h"
#include "widget/timelinewidget/timelinescaledobject.h"
#include "widget/timelinewidget/view/timelineplayhead.h"
#include "seekablewidget.h"
class TimeRuler : public TimelineScaledWidget
class TimeRuler : public SeekableWidget
{
Q_OBJECT
public:
@@ -38,15 +35,7 @@ public:
void SetCenteredText(bool c);
void ConnectTimelinePoints(TimelinePoints* points);
const int64_t& GetTime();
public slots:
void SetTime(const int64_t &r);
void SetScroll(int s);
void CacheInvalidatedRange(const TimeRange &range);
void CacheTimeReady(const rational& time);
@@ -56,19 +45,8 @@ public slots:
protected:
virtual void paintEvent(QPaintEvent* e) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void TimebaseChangedEvent(const rational& tb) override;
virtual void ScaleChangedEvent(const double&);
signals:
/**
* @brief Signal emitted whenever the time changes on this ruler, either by user or programatically
*/
void TimeChanged(int64_t);
private:
void UpdateHeight();
@@ -76,16 +54,6 @@ private:
int CacheStatusHeight() const;
double ScreenToUnitFloat(int screen);
int64_t ScreenToUnit(int screen);
int UnitToScreen(int64_t unit);
int TimeToScreen(const rational& time);
void SeekToScreenPoint(int screen);
int text_height_;
int cache_status_height_;
@@ -94,29 +62,18 @@ private:
int playhead_width_;
int scroll_;
bool text_visible_;
bool centered_text_;
double timebase_flipped_dbl_;
int64_t time_;
TimelinePlayhead style_;
bool show_cache_status_;
rational cache_length_;
TimeRangeList dirty_cache_ranges_;
TimelinePoints* timeline_points_;
private slots:
void TimelineWorkareaChanged();
};
#endif // TIMERULER_H