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:
@@ -26,17 +26,17 @@
|
||||
|
||||
#include "common/qtutils.h"
|
||||
#include "core.h"
|
||||
#include "widget/marker/markerundo.h"
|
||||
#include "widget/timebased/timebasedwidget.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
#define super TimeBasedView
|
||||
|
||||
SeekableWidget::SeekableWidget(QWidget* parent) :
|
||||
TimelineScaledWidget(parent),
|
||||
super(parent),
|
||||
timeline_points_(nullptr),
|
||||
scroll_(0),
|
||||
snap_service_(nullptr),
|
||||
dragging_(false)
|
||||
dragging_(false),
|
||||
selection_manager_(this)
|
||||
{
|
||||
QFontMetrics fm = fontMetrics();
|
||||
|
||||
@@ -46,19 +46,18 @@ SeekableWidget::SeekableWidget(QWidget* parent) :
|
||||
playhead_width_ = QtUtils::QFontMetricsWidth(fm, "H");
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
}
|
||||
|
||||
void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points)
|
||||
{
|
||||
if (timeline_points_) {
|
||||
selection_manager_.ClearSelection();
|
||||
|
||||
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));
|
||||
disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
|
||||
disconnect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
|
||||
|
||||
foreach(Marker* marker_widget, marker_map_.values()) {
|
||||
marker_widget->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
timeline_points_ = points;
|
||||
@@ -68,47 +67,26 @@ void SeekableWidget::ConnectTimelinePoints(TimelinePoints *points)
|
||||
connect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
|
||||
connect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
|
||||
connect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast<void (SeekableWidget::*)()>(&SeekableWidget::update));
|
||||
|
||||
connect(timeline_points_->markers(), &TimelineMarkerList::MarkerAdded, this, &SeekableWidget::addMarker);
|
||||
connect(timeline_points_->markers(), &TimelineMarkerList::MarkerRemoved, this, &SeekableWidget::removeMarker);
|
||||
}
|
||||
|
||||
if (timeline_points() && !timeline_points()->markers()->list().isEmpty()) {
|
||||
foreach (TimelineMarker *marker, timeline_points()->markers()->list()) {
|
||||
if (!marker_map_.keys().contains(marker)) {
|
||||
addMarker(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateMarkerPositions();
|
||||
|
||||
update();
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void SeekableWidget::SetSnapService(SnapService *service)
|
||||
void SeekableWidget::DeleteSelected()
|
||||
{
|
||||
snap_service_ = service;
|
||||
}
|
||||
|
||||
void SeekableWidget::DeleteSelected() {
|
||||
MultiUndoCommand* command = new MultiUndoCommand();
|
||||
|
||||
foreach (TimelineMarker *marker, GetActiveTimelineMarkers()) {
|
||||
command->add_child(new MarkerRemoveCommand(Core::instance()->GetActiveProject(), marker, timeline_points_->markers()));
|
||||
foreach (TimelineMarker *marker, selection_manager_.GetSelectedObjects()) {
|
||||
command->add_child(new MarkerRemoveCommand(marker));
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
const int &SeekableWidget::GetScroll() const
|
||||
{
|
||||
return scroll_;
|
||||
}
|
||||
|
||||
void SeekableWidget::CopySelected(bool cut)
|
||||
{
|
||||
CopyMarkersToClipboard(GetActiveTimelineMarkers());
|
||||
qDebug() << "COPY IS STUB";
|
||||
//CopyMarkersToClipboard(selection_manager_.GetSelectedObjects());
|
||||
|
||||
if (cut) {
|
||||
DeleteSelected();
|
||||
@@ -117,14 +95,15 @@ void SeekableWidget::CopySelected(bool cut)
|
||||
|
||||
void SeekableWidget::PasteMarkers(bool insert, rational insert_time)
|
||||
{
|
||||
MultiUndoCommand *command = new MultiUndoCommand();
|
||||
PasteMarkersFromClipboard(timeline_points()->markers(), command, insert_time);
|
||||
//MultiUndoCommand *command = new MultiUndoCommand();
|
||||
//PasteMarkersFromClipboard(timeline_points()->markers(), command, insert_time);
|
||||
qDebug() << "PASTE IS STUB";
|
||||
}
|
||||
|
||||
void SeekableWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
SeekToScreenPoint(event->pos().x());
|
||||
SeekToScenePoint(mapToScene(event->pos()).x());
|
||||
dragging_ = true;
|
||||
|
||||
DeselectAllMarkers();
|
||||
@@ -134,7 +113,7 @@ void SeekableWidget::mousePressEvent(QMouseEvent *event)
|
||||
void SeekableWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
SeekToScreenPoint(event->pos().x());
|
||||
SeekToScenePoint(mapToScene(event->pos()).x());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,18 +121,19 @@ void SeekableWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (snap_service_) {
|
||||
snap_service_->HideSnaps();
|
||||
if (GetSnapService()) {
|
||||
GetSnapService()->HideSnaps();
|
||||
}
|
||||
|
||||
dragging_ = false;
|
||||
}
|
||||
|
||||
void SeekableWidget::ScaleChangedEvent(const double &)
|
||||
void SeekableWidget::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
updateMarkerPositions();
|
||||
super::focusOutEvent(event);
|
||||
|
||||
update();
|
||||
// Deselect everything when we lose focus
|
||||
DeselectAllMarkers();
|
||||
}
|
||||
|
||||
TimelinePoints *SeekableWidget::timeline_points() const
|
||||
@@ -161,131 +141,38 @@ TimelinePoints *SeekableWidget::timeline_points() const
|
||||
return timeline_points_;
|
||||
}
|
||||
|
||||
void SeekableWidget::SetTime(const rational &r)
|
||||
{
|
||||
time_ = r;
|
||||
|
||||
updateMarkerPositions();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void SeekableWidget::SetScroll(int s)
|
||||
{
|
||||
scroll_ = s;
|
||||
|
||||
updateMarkerPositions();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
QVector<TimelineMarker *> SeekableWidget::GetActiveTimelineMarkers() {
|
||||
QVector<TimelineMarker*> active_timelineMarkers;
|
||||
foreach (TimelineMarker *marker, timeline_points()->markers()->list()) {
|
||||
if (marker->active()) {
|
||||
active_timelineMarkers.append(marker);
|
||||
}
|
||||
}
|
||||
|
||||
return active_timelineMarkers;
|
||||
}
|
||||
|
||||
|
||||
void SeekableWidget::DeselectAllMarkers()
|
||||
{
|
||||
if (timebase().isNull()) {
|
||||
return;
|
||||
}
|
||||
if (!timeline_points()) {
|
||||
return;
|
||||
}
|
||||
foreach(TimelineMarker* marker, timeline_points()->markers()->list()) {
|
||||
marker->set_active(false);
|
||||
}
|
||||
}
|
||||
selection_manager_.ClearSelection();
|
||||
|
||||
void SeekableWidget::addMarker(TimelineMarker* marker)
|
||||
{
|
||||
if (!marker_map_.contains(marker)) {
|
||||
Marker *marker_widget = new Marker(this);
|
||||
marker_map_.insert(marker, marker_widget);
|
||||
|
||||
/*
|
||||
Markers are stored as TimelineMarkers and represented in the UI as Markers. As a single
|
||||
TimelineMarker can be represented in various views it is necessary to make sure all instances
|
||||
of the TimelineMarker's (UI) Markers are kept in sync. To do this, whenever a Marker is updated
|
||||
in some way, it signals that change to the relevant TimelineMarker which in turn broadcasts
|
||||
that update out to all the relevant Markers.
|
||||
*/
|
||||
|
||||
connect(marker_widget, &Marker::ColorChanged, this, &SeekableWidget::SetMarkerColor);
|
||||
connect(marker, &TimelineMarker::ColorChanged, marker_widget, &Marker::SetColor);
|
||||
|
||||
connect(marker_widget, &Marker::ActiveChanged, marker, &TimelineMarker::set_active);
|
||||
connect(marker, &TimelineMarker::ActiveChanged, marker_widget, &Marker::SetActive);
|
||||
|
||||
connect(marker_widget, &Marker::NameChanged, marker, &TimelineMarker::set_name_undo);
|
||||
connect(marker, &TimelineMarker::NameChanged, marker_widget, &Marker::SetName);
|
||||
|
||||
connect(marker_widget, &Marker::TimeChanged, marker, &TimelineMarker::set_time_undo);
|
||||
connect(marker, &TimelineMarker::TimeChanged, marker_widget, &Marker::SetTime);
|
||||
|
||||
marker_widget->move(TimeToScreen(marker->time().in())-2, text_height_);
|
||||
marker_widget->SetColor(marker->color());
|
||||
marker_widget->SetName(marker->name());
|
||||
marker_widget->show();
|
||||
}
|
||||
}
|
||||
|
||||
void SeekableWidget::removeMarker(TimelineMarker *marker)
|
||||
{
|
||||
marker_map_.value(marker)->deleteLater();
|
||||
marker_map_.take(marker);
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void SeekableWidget::SetMarkerColor(int c)
|
||||
{
|
||||
MultiUndoCommand *command = new MultiUndoCommand();
|
||||
|
||||
foreach(TimelineMarker* marker, GetActiveTimelineMarkers()) {
|
||||
command->add_child(new MarkerChangeColorCommand(Core::instance()->GetActiveProject(), marker, c));
|
||||
foreach(TimelineMarker* marker, selection_manager_.GetSelectedObjects()) {
|
||||
command->add_child(new MarkerChangeColorCommand(marker, c));
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
void SeekableWidget::updateMarkerPositions()
|
||||
{
|
||||
foreach (TimelineMarker* marker, marker_map_.keys()) {
|
||||
Marker *m = marker_map_.value(marker);
|
||||
m->move(TimeToScreen(marker->time().in())-2, text_height_);
|
||||
}
|
||||
}
|
||||
|
||||
int SeekableWidget::TimeToScreen(const rational &time) const
|
||||
{
|
||||
return qFloor(TimeToScene(time)) - scroll_;
|
||||
}
|
||||
|
||||
rational SeekableWidget::ScreenToTime(int x) const
|
||||
{
|
||||
return qMax(rational(0), SceneToTime(x + scroll_));
|
||||
}
|
||||
|
||||
void SeekableWidget::SeekToScreenPoint(int screen)
|
||||
void SeekableWidget::SeekToScenePoint(qreal scene)
|
||||
{
|
||||
if (timebase().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
rational playhead_time = ScreenToTime(screen);
|
||||
rational playhead_time = SceneToTime(scene);
|
||||
|
||||
if (Core::instance()->snapping() && snap_service_) {
|
||||
if (Core::instance()->snapping() && GetSnapService()) {
|
||||
rational movement;
|
||||
|
||||
snap_service_->SnapPoint({playhead_time},
|
||||
&movement,
|
||||
SnapService::kSnapAll & ~SnapService::kSnapToPlayhead);
|
||||
GetSnapService()->SnapPoint({playhead_time},
|
||||
&movement,
|
||||
SnapService::kSnapAll & ~SnapService::kSnapToPlayhead);
|
||||
|
||||
playhead_time += movement;
|
||||
}
|
||||
@@ -305,20 +192,20 @@ void SeekableWidget::DrawTimelinePoints(QPainter* p, int marker_bottom)
|
||||
|
||||
// Draw in/out workarea
|
||||
if (timeline_points()->workarea()->enabled()) {
|
||||
int workarea_left = qMax(0, TimeToScreen(timeline_points()->workarea()->in()));
|
||||
int workarea_left = qMax(0.0, TimeToScene(timeline_points()->workarea()->in()));
|
||||
int workarea_right;
|
||||
|
||||
if (timeline_points()->workarea()->out() == TimelineWorkArea::kResetOut) {
|
||||
workarea_right = width();
|
||||
} else {
|
||||
workarea_right = qMin(width(), TimeToScreen(timeline_points()->workarea()->out()));
|
||||
workarea_right = qMin(qreal(width()), TimeToScene(timeline_points()->workarea()->out()));
|
||||
}
|
||||
|
||||
p->fillRect(workarea_left, 0, workarea_right - workarea_left, height(), palette().highlight());
|
||||
}
|
||||
|
||||
// Draw markers
|
||||
if (marker_bottom > 0 && !timeline_points()->markers()->list().isEmpty()) {
|
||||
if (marker_bottom > 0 && !timeline_points()->markers()->list().empty()) {
|
||||
|
||||
int marker_top = marker_bottom - text_height_;
|
||||
|
||||
@@ -327,8 +214,8 @@ void SeekableWidget::DrawTimelinePoints(QPainter* p, int marker_bottom)
|
||||
p->setBrush(Qt::green);
|
||||
|
||||
foreach (TimelineMarker* marker, timeline_points()->markers()->list()) {
|
||||
int marker_left = TimeToScreen(marker->time().in());
|
||||
int marker_right = TimeToScreen(marker->time().out());
|
||||
int marker_left = TimeToScene(marker->time().in());
|
||||
int marker_right = TimeToScene(marker->time().out());
|
||||
|
||||
if (marker_left >= width() || marker_right < 0) {
|
||||
continue;
|
||||
|
||||
@@ -22,35 +22,29 @@
|
||||
#define SEEKABLEWIDGET_H
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "timeline/timelinepoints.h"
|
||||
#include "widget/snapservice/snapservice.h"
|
||||
#include "widget/timebased/timescaledobject.h"
|
||||
#include "widget/marker/marker.h"
|
||||
#include "widget/marker/markercopypaste.h"
|
||||
#include "widget/timebased/timebasedviewselectionmanager.h"
|
||||
//#include "widget/marker/markercopypaste.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SeekableWidget : public TimelineScaledWidget, public MarkerCopyPasteService
|
||||
class SeekableWidget : public TimeBasedView//, public MarkerCopyPasteService
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SeekableWidget(QWidget *parent = nullptr);
|
||||
|
||||
const rational& GetTime() const
|
||||
int GetScroll() const
|
||||
{
|
||||
return time_;
|
||||
return horizontalScrollBar()->value();
|
||||
}
|
||||
|
||||
const int& GetScroll() const;
|
||||
|
||||
void ConnectTimelinePoints(TimelinePoints* points);
|
||||
|
||||
void SetSnapService(SnapService* service);
|
||||
|
||||
SnapService* GetSnapService() { return snap_service_; };
|
||||
|
||||
bool IsDraggingPlayhead() const
|
||||
{
|
||||
return dragging_;
|
||||
@@ -62,35 +56,28 @@ public:
|
||||
|
||||
void PasteMarkers(bool insert, rational insert_time);
|
||||
|
||||
QVector<TimelineMarker*> GetActiveTimelineMarkers();
|
||||
|
||||
void DeselectAllMarkers();
|
||||
|
||||
void SeekToScreenPoint(int screen);
|
||||
|
||||
int TimeToScreen(const rational& time) const;
|
||||
rational ScreenToTime(int x) const;
|
||||
void SeekToScenePoint(qreal scene);
|
||||
|
||||
public slots:
|
||||
void SetTime(const rational &r);
|
||||
|
||||
void SetScroll(int s);
|
||||
|
||||
void addMarker(TimelineMarker* marker);
|
||||
|
||||
void removeMarker(TimelineMarker* marker);
|
||||
|
||||
void updateMarkerPositions();
|
||||
void SetScroll(int i)
|
||||
{
|
||||
horizontalScrollBar()->setValue(i);
|
||||
}
|
||||
|
||||
void SetMarkerColor(int c);
|
||||
|
||||
protected:
|
||||
/*void SetMarkerTime();
|
||||
|
||||
void SetMarkerName();*/
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
virtual void ScaleChangedEvent(const double&) override;
|
||||
virtual void focusOutEvent(QFocusEvent *event) override;
|
||||
|
||||
void DrawTimelinePoints(QPainter *p, int marker_bottom = 0);
|
||||
|
||||
@@ -106,30 +93,16 @@ protected:
|
||||
return playhead_width_;
|
||||
}
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted whenever the time changes on this ruler, either by user or programmatically
|
||||
*/
|
||||
void TimeChanged(const rational &time);
|
||||
|
||||
private:
|
||||
rational time_;
|
||||
|
||||
TimelinePoints* timeline_points_;
|
||||
|
||||
int scroll_;
|
||||
|
||||
int text_height_;
|
||||
|
||||
int playhead_width_;
|
||||
|
||||
SnapService* snap_service_;
|
||||
|
||||
bool dragging_;
|
||||
|
||||
QMap<TimelineMarker*, Marker*> marker_map_;
|
||||
|
||||
QMap<TimelineMarker*, Marker*> active_markers_map_;
|
||||
TimeBasedViewSelectionManager<TimelineMarker> selection_manager_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
void SetPlaybackCache(PlaybackCache* cache);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
virtual void TimebaseChangedEvent(const rational& tb) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user