timeline: added thumbnail modes that affect how much is rendered
This commit is contained in:
@@ -1140,14 +1140,20 @@ void TimelineWidget::ShowContextMenu()
|
||||
toggle_audio_units->setChecked(use_audio_time_units_);
|
||||
connect(toggle_audio_units, &QAction::triggered, this, &TimelineWidget::SetUseAudioTimeUnits);
|
||||
|
||||
QAction* show_thumbnails = menu.addAction(tr("Show Thumbnails"));
|
||||
show_thumbnails->setCheckable(true);
|
||||
show_thumbnails->setChecked(views_.first()->view()->GetShowThumbnails());
|
||||
connect(show_thumbnails, &QAction::triggered, this, &TimelineWidget::SetViewThumbnailsEnabled);
|
||||
{
|
||||
Menu *thumbnail_menu = new Menu(tr("Show Thumbnails"), &menu);
|
||||
menu.addMenu(thumbnail_menu);
|
||||
|
||||
thumbnail_menu->AddActionWithData(tr("Disabled"), Timeline::kThumbnailOff, OLIVE_CONFIG("TimelineThumbnailMode"));
|
||||
thumbnail_menu->AddActionWithData(tr("Only At In/Out Points"), Timeline::kThumbnailInOut, OLIVE_CONFIG("TimelineThumbnailMode"));
|
||||
thumbnail_menu->AddActionWithData(tr("Enabled"), Timeline::kThumbnailOn, OLIVE_CONFIG("TimelineThumbnailMode"));
|
||||
|
||||
connect(thumbnail_menu, &Menu::triggered, this, &TimelineWidget::SetViewThumbnailsEnabled);
|
||||
}
|
||||
|
||||
QAction* show_waveforms = menu.addAction(tr("Show Waveforms"));
|
||||
show_waveforms->setCheckable(true);
|
||||
show_waveforms->setChecked(views_.first()->view()->GetShowWaveforms());
|
||||
show_waveforms->setChecked(OLIVE_CONFIG("TimelineWaveformMode").toInt() == Timeline::kWaveformsEnabled);
|
||||
connect(show_waveforms, &QAction::triggered, this, &TimelineWidget::SetViewWaveformsEnabled);
|
||||
|
||||
menu.addSeparator();
|
||||
@@ -1211,16 +1217,14 @@ void TimelineWidget::AddableObjectChanged()
|
||||
|
||||
void TimelineWidget::SetViewWaveformsEnabled(bool e)
|
||||
{
|
||||
foreach (TimelineAndTrackView* tview, views_) {
|
||||
tview->view()->SetShowWaveforms(e);
|
||||
}
|
||||
OLIVE_CONFIG("TimelineWaveformMode") = e ? Timeline::kWaveformsEnabled : Timeline::kWaveformsDisabled;
|
||||
UpdateViewports();
|
||||
}
|
||||
|
||||
void TimelineWidget::SetViewThumbnailsEnabled(bool e)
|
||||
void TimelineWidget::SetViewThumbnailsEnabled(QAction *action)
|
||||
{
|
||||
foreach (TimelineAndTrackView* tview, views_) {
|
||||
tview->view()->SetShowThumbnails(e);
|
||||
}
|
||||
OLIVE_CONFIG("TimelineThumbnailMode") = action->data();
|
||||
UpdateViewports();
|
||||
}
|
||||
|
||||
void TimelineWidget::FrameRateChanged()
|
||||
|
||||
@@ -423,7 +423,7 @@ private slots:
|
||||
|
||||
void SetViewWaveformsEnabled(bool e);
|
||||
|
||||
void SetViewThumbnailsEnabled(bool e);
|
||||
void SetViewThumbnailsEnabled(QAction *action);
|
||||
|
||||
void FrameRateChanged();
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ TimelineView::TimelineView(Qt::Alignment vertical_alignment, QWidget *parent) :
|
||||
ghosts_(nullptr),
|
||||
show_beam_cursor_(false),
|
||||
connected_track_list_(nullptr),
|
||||
show_thumbnails_(true),
|
||||
show_waveforms_(true),
|
||||
transition_overlay_out_(nullptr),
|
||||
transition_overlay_in_(nullptr)
|
||||
{
|
||||
@@ -486,7 +484,6 @@ void TimelineView::DrawBlock(QPainter *painter, bool foreground, Block *block, q
|
||||
int text_height = fm.height();
|
||||
int text_padding = text_height/4; // This ties into the track minimum height being 1.5
|
||||
int text_total_height = text_height + text_padding + text_padding;
|
||||
Q_UNUSED(text_total_height)
|
||||
|
||||
if (foreground) {
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
@@ -524,43 +521,52 @@ void TimelineView::DrawBlock(QPainter *painter, bool foreground, Block *block, q
|
||||
QRect preview_rect = r.toRect();
|
||||
|
||||
// Draw clip thumbnails
|
||||
if (clip->GetTrackType() == Track::kVideo && show_thumbnails_ && preview_rect.height() > r.height()/3) {
|
||||
if (clip->GetTrackType() == Track::kVideo
|
||||
&& OLIVE_CONFIG("TimelineThumbnailMode").toInt() != Timeline::kThumbnailOff
|
||||
&& preview_rect.height() > r.height()/3) {
|
||||
if (const FrameHashCache *thumbs = clip->thumbnails()) {
|
||||
// Start thumbnails underneath clip name
|
||||
preview_rect.adjust(0, text_total_height, 0, 0);
|
||||
|
||||
QRect thumb_rect;
|
||||
painter->setClipRect(preview_rect);
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter->setClipRect(preview_rect);
|
||||
|
||||
Sequence *s = clip->track()->sequence();
|
||||
int width = s->GetVideoParams().width();
|
||||
int height = s->GetVideoParams().height();
|
||||
int start;
|
||||
if (height > 0) { // Prevent divide by zero/invalid params
|
||||
double scale = double(preview_rect.height())/double(height);
|
||||
thumb_rect.setWidth(width * scale);
|
||||
start = (preview_rect.left() - int(qFloor(block_in))) / thumb_rect.width() + qFloor(block_in);
|
||||
} else {
|
||||
start = preview_rect.left();
|
||||
}
|
||||
if (OLIVE_CONFIG("TimelineThumbnailMode") == Timeline::kThumbnailOn) {
|
||||
|
||||
for (int i=start; i<preview_rect.right(); i+=thumb_rect.width()+1) {
|
||||
rational time_here = SceneToTime(i - block_in, GetScale(), connected_track_list_->parent()->GetVideoParams().frame_rate_as_time_base()) + media_in;
|
||||
QString thumbnail = thumbs->GetValidCacheFilename(time_here);
|
||||
|
||||
if (!thumbnail.isEmpty()) {
|
||||
QImage img;
|
||||
if (img.load(thumbnail, "jpg")) {
|
||||
double scale = double(preview_rect.height())/double(img.height());
|
||||
thumb_rect = QRect(i, preview_rect.top(), img.width() * scale, preview_rect.height());
|
||||
painter->drawImage(thumb_rect, img);
|
||||
}
|
||||
Sequence *s = clip->track()->sequence();
|
||||
int width = s->GetVideoParams().width();
|
||||
int height = s->GetVideoParams().height();
|
||||
int start;
|
||||
if (height > 0) { // Prevent divide by zero/invalid params
|
||||
double scale = double(preview_rect.height())/double(height);
|
||||
thumb_rect.setWidth(width * scale);
|
||||
start = (((preview_rect.left() - int(qFloor(block_in))) / thumb_rect.width()) * thumb_rect.width()) + qFloor(block_in);
|
||||
} else {
|
||||
start = preview_rect.left();
|
||||
}
|
||||
|
||||
for (int i=start; i<preview_rect.right(); i+=thumb_rect.width()+1) {
|
||||
rational time_here = SceneToTime(i - block_in, GetScale(), connected_track_list_->parent()->GetVideoParams().frame_rate_as_time_base()) + media_in;
|
||||
DrawThumbnail(painter, thumbs, time_here, i, preview_rect, &thumb_rect);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
rational time = clip->media_range().in();
|
||||
time = Timecode::snap_time_to_timebase(time, thumbs->GetTimebase(), Timecode::kFloor);
|
||||
DrawThumbnail(painter, thumbs, time, block_left, preview_rect, &thumb_rect);
|
||||
|
||||
}
|
||||
|
||||
painter->setClipping(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Draw waveform
|
||||
if (clip->GetTrackType() == Track::kAudio && show_waveforms_) {
|
||||
if (clip->GetTrackType() == Track::kAudio
|
||||
&& OLIVE_CONFIG("TimelineWaveformMode").toInt() == Timeline::kWaveformsEnabled) {
|
||||
if (const AudioWaveformCache *wave = clip->waveform()) {
|
||||
rational waveform_start = SceneToTime(block_left - block_in, GetScale(), connected_track_list_->parent()->GetAudioParams().sample_rate_as_time_base()) + media_in;
|
||||
painter->setPen(shadow_color);
|
||||
@@ -733,6 +739,20 @@ qreal TimelineView::GetTimelineRightBound() const
|
||||
return GetTimelineLeftBound() + viewport()->width();
|
||||
}
|
||||
|
||||
void TimelineView::DrawThumbnail(QPainter *painter, const FrameHashCache *thumbs, const rational &time, int x, const QRect &preview_rect, QRect *thumb_rect) const
|
||||
{
|
||||
QString thumbnail = thumbs->GetValidCacheFilename(time);
|
||||
|
||||
if (!thumbnail.isEmpty()) {
|
||||
QImage img;
|
||||
if (img.load(thumbnail, "jpg")) {
|
||||
double scale = double(preview_rect.height())/double(img.height());
|
||||
*thumb_rect = QRect(x, preview_rect.top(), img.width() * scale, preview_rect.height());
|
||||
painter->drawImage(*thumb_rect, img);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int TimelineView::GetTrackY(int track_index) const
|
||||
{
|
||||
if (!connected_track_list_ || !connected_track_list_->GetTrackCount()) {
|
||||
|
||||
@@ -73,28 +73,6 @@ public:
|
||||
|
||||
Block* GetItemAtScenePos(const rational& time, int track_index) const;
|
||||
|
||||
bool GetShowWaveforms() const
|
||||
{
|
||||
return show_waveforms_;
|
||||
}
|
||||
|
||||
void SetShowWaveforms(bool e)
|
||||
{
|
||||
show_waveforms_ = e;
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
bool GetShowThumbnails() const
|
||||
{
|
||||
return show_thumbnails_;
|
||||
}
|
||||
|
||||
void SetShowThumbnails(bool e)
|
||||
{
|
||||
show_thumbnails_ = e;
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
signals:
|
||||
void MousePressed(TimelineViewMouseEvent* event);
|
||||
void MouseMoved(TimelineViewMouseEvent* event);
|
||||
@@ -154,6 +132,8 @@ private:
|
||||
|
||||
qreal GetTimelineRightBound() const;
|
||||
|
||||
void DrawThumbnail(QPainter *painter, const FrameHashCache *thumbs, const rational &time, int x, const QRect &preview_rect, QRect *thumb_rect) const;
|
||||
|
||||
QHash<Track::Reference, TimeRangeList>* selections_;
|
||||
|
||||
QVector<TimelineViewGhostItem*>* ghosts_;
|
||||
@@ -164,9 +144,6 @@ private:
|
||||
|
||||
TrackList* connected_track_list_;
|
||||
|
||||
bool show_thumbnails_;
|
||||
bool show_waveforms_;
|
||||
|
||||
ClipBlock *transition_overlay_out_;
|
||||
ClipBlock *transition_overlay_in_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user