diff --git a/olive.pro b/olive.pro index 4a98ac142..cde6760c0 100644 --- a/olive.pro +++ b/olive.pro @@ -51,7 +51,8 @@ SOURCES += \ project/effect.cpp \ effects/effects.cpp \ playback/cacher.cpp \ - io/exportthread.cpp + io/exportthread.cpp \ + ui/timelineheader.cpp HEADERS += \ mainwindow.h \ @@ -78,7 +79,8 @@ HEADERS += \ panels/panels.h \ playback/cacher.h \ io/exportthread.h \ - ui/timelinetools.h + ui/timelinetools.h \ + ui/timelineheader.h FORMS += \ mainwindow.ui \ diff --git a/olive.pro.user b/olive.pro.user index 3ec776c11..d8765f1e2 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/panels/timeline.cpp b/panels/timeline.cpp index bd578d6cd..efb77e721 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -41,7 +41,7 @@ Timeline::Timeline(QWidget *parent) : sequence = NULL; set_sequence(NULL); - connect(&playback_updater, SIGNAL(timeout()), this, SLOT(repaint_timeline())); + connect(&playback_updater, SIGNAL(timeout()), this, SLOT(repaint_timeline())); } Timeline::~Timeline() @@ -87,8 +87,7 @@ bool Timeline::toggle_play() { } void Timeline::play() { - playhead_start = playhead; - playback_timer.start(); + playhead_start = playhead; start_msecs = QDateTime::currentMSecsSinceEpoch(); playback_updater.start(); playing = true; @@ -121,6 +120,7 @@ void Timeline::set_sequence(Sequence *s) { } ui->pushButton_4->setEnabled(!null_sequence); ui->pushButton_5->setEnabled(!null_sequence); + ui->headers->setEnabled(!null_sequence); ui->video_area->setEnabled(!null_sequence); ui->audio_area->setEnabled(!null_sequence); @@ -134,7 +134,7 @@ void Timeline::set_sequence(Sequence *s) { } bool Timeline::focused() { - return (ui->video_area->hasFocus() || ui->audio_area->hasFocus()); + return (ui->headers->hasFocus() || ui->video_area->hasFocus() || ui->audio_area->hasFocus()); } void Timeline::undo() { @@ -154,10 +154,10 @@ void Timeline::redo() { } void Timeline::repaint_timeline() { - if (playing) { -// playhead = playhead_start + (playback_timer.elapsed() * 0.001 * sequence->frame_rate); + if (playing) { playhead = round(playhead_start + ((QDateTime::currentMSecsSinceEpoch()-start_msecs) * 0.001 * sequence->frame_rate)); } + ui->headers->update(); ui->video_area->update(); ui->audio_area->update(); if (last_frame != playhead) { @@ -379,3 +379,15 @@ void Timeline::split_at_playhead() { if (split_selected) redraw_all_clips(); } + +long Timeline::getFrameFromScreenPoint(int x) { + long f = round((float) x / zoom); + if (f < 0) { + return 0; + } + return f; +} + +int Timeline::getScreenPointFromFrame(long frame) { + return (int) round(frame*zoom); +} diff --git a/panels/timeline.h b/panels/timeline.h index ad500423d..e896375f5 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -66,6 +66,9 @@ public: void split_at_playhead(); void set_sequence(Sequence* s); + int getScreenPointFromFrame(long frame); + long getFrameFromScreenPoint(int x); + Sequence* sequence; long playhead; @@ -81,7 +84,6 @@ public: bool playing; long playhead_start; qint64 start_msecs; - QTime playback_timer; QTimer playback_updater; // shared information diff --git a/panels/timeline.ui b/panels/timeline.ui index 3739b8700..0b9e68c5d 100644 --- a/panels/timeline.ui +++ b/panels/timeline.ui @@ -6,8 +6,8 @@ 0 0 - 840 - 535 + 523 + 227 @@ -312,11 +312,14 @@ 0 0 - 796 - 506 + 479 + 198 + + 0 + 0 @@ -329,6 +332,16 @@ 0 + + + + + 0 + 15 + + + + @@ -372,6 +385,12 @@
ui/timelinewidget.h
1 + + TimelineHeader + QWidget +
ui/timelineheader.h
+ 1 +
diff --git a/project/sequence.cpp b/project/sequence.cpp index d9189e2f3..3f9f9aa6d 100644 --- a/project/sequence.cpp +++ b/project/sequence.cpp @@ -114,8 +114,12 @@ void Sequence::split_clip(int i, long frame) { } void Sequence::undo_add_current() { - undo_pointer++; - undo_stack.resize(undo_pointer); + if (undo_stack.size() == UNDO_LIMIT) { + undo_stack.removeFirst(); + } else { + undo_pointer++; + undo_stack.resize(undo_pointer); + } undo_stack.append(clips); } diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 24fb73cd2..3be02d42a 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -42,8 +42,8 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) { QPoint pos = event->pos(); event->accept(); QList items = panel_project->source_table->selectedItems(); - long entry_point = getFrameFromScreenPoint(pos.x(), false); - panel_timeline->drag_frame_start = entry_point + getFrameFromScreenPoint(50, false); + long entry_point = panel_timeline->getFrameFromScreenPoint(pos.x()); + panel_timeline->drag_frame_start = entry_point + panel_timeline->getFrameFromScreenPoint(50); panel_timeline->drag_track_start = (bottom_align) ? -1 : 0; for (int i=0;idrag_track_start = panel_timeline->cursor_track; } else { QPoint pos = event->pos(); - panel_timeline->drag_frame_start = getFrameFromScreenPoint(pos.x(), false); + panel_timeline->drag_frame_start = panel_timeline->getFrameFromScreenPoint(pos.x()); panel_timeline->drag_track_start = getTrackFromScreenPoint(pos.y()); } @@ -347,7 +347,7 @@ void validate_snapping(Ghost& g, long* frame_diff) { void TimelineWidget::update_ghosts(QPoint& mouse_pos) { int mouse_track = getTrackFromScreenPoint(mouse_pos.y()); - long frame_diff = getFrameFromScreenPoint(mouse_pos.x(), false) - panel_timeline->drag_frame_start; + long frame_diff = panel_timeline->getFrameFromScreenPoint(mouse_pos.x()) - panel_timeline->drag_frame_start; int track_diff = mouse_track - panel_timeline->drag_track_start; long validator; @@ -511,10 +511,10 @@ void TimelineWidget::update_ghosts(QPoint& mouse_pos) { void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) { - panel_timeline->cursor_frame = getFrameFromScreenPoint(event->pos().x(), false); + panel_timeline->cursor_frame = panel_timeline->getFrameFromScreenPoint(event->pos().x()); panel_timeline->cursor_track = getTrackFromScreenPoint(event->pos().y()); - int limit = getFrameFromScreenPoint(10, false); + int limit = panel_timeline->getFrameFromScreenPoint(10); if (panel_timeline->snapping && panel_timeline->cursor_frame > panel_timeline->playhead-limit-1 && panel_timeline->cursor_frame < panel_timeline->playhead+limit+1) { panel_timeline->cursor_frame = panel_timeline->playhead; } @@ -634,8 +634,8 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { int lim = 5; int mouse_track = getTrackFromScreenPoint(pos.y()); - long mouse_frame_lower = getFrameFromScreenPoint(pos.x()-lim, false)-1; - long mouse_frame_upper = getFrameFromScreenPoint(pos.x()+lim, false)+1; + long mouse_frame_lower = panel_timeline->getFrameFromScreenPoint(pos.x()-lim)-1; + long mouse_frame_upper = panel_timeline->getFrameFromScreenPoint(pos.x()+lim)+1; bool found = false; for (int i=0;isequence->clip_count();i++) { Clip& c = panel_timeline->sequence->get_clip(i); @@ -671,7 +671,7 @@ int color_brightness(int r, int g, int b) { void TimelineWidget::redraw_clips() { // Draw clips - int panel_width = getScreenPointFromFrame(panel_timeline->sequence->getEndFrame()) + 100; + int panel_width = panel_timeline->getScreenPointFromFrame(panel_timeline->sequence->getEndFrame()) + 100; setMinimumWidth(panel_width); clip_pixmap = QPixmap(panel_width, height()); @@ -688,7 +688,7 @@ void TimelineWidget::redraw_clips() { audio_track_limit = clip.track; } - QRect clip_rect(getScreenPointFromFrame(clip.timeline_in), getScreenPointFromTrack(clip.track), clip.getLength() * panel_timeline->zoom, track_height); + QRect clip_rect(panel_timeline->getScreenPointFromFrame(clip.timeline_in), getScreenPointFromTrack(clip.track), clip.getLength() * panel_timeline->zoom, track_height); clip_painter.fillRect(clip_rect, QColor(clip.color_r, clip.color_g, clip.color_b)); clip_painter.setPen(Qt::white); clip_painter.drawLine(clip_rect.bottomLeft(), clip_rect.topLeft()); @@ -742,8 +742,8 @@ void TimelineWidget::paintEvent(QPaintEvent*) { const Selection& s = panel_timeline->selections.at(i); if (is_track_visible(s.track)) { int selection_y = getScreenPointFromTrack(s.track); - int selection_x = getScreenPointFromFrame(s.in); - p.fillRect(selection_x, selection_y, getScreenPointFromFrame(s.out) - selection_x, track_height, QColor(0, 0, 0, 64)); + int selection_x = panel_timeline->getScreenPointFromFrame(s.in); + p.fillRect(selection_x, selection_y, panel_timeline->getScreenPointFromFrame(s.out) - selection_x, track_height, QColor(0, 0, 0, 64)); } } @@ -751,9 +751,9 @@ void TimelineWidget::paintEvent(QPaintEvent*) { for (int i=0;ighosts.size();i++) { const Ghost& g = panel_timeline->ghosts.at(i); if (is_track_visible(g.track)) { - int ghost_x = getScreenPointFromFrame(g.in); + int ghost_x = panel_timeline->getScreenPointFromFrame(g.in); int ghost_y = getScreenPointFromTrack(g.track); - int ghost_width = getScreenPointFromFrame(g.out - g.in) - 1; + int ghost_width = panel_timeline->getScreenPointFromFrame(g.out - g.in) - 1; int ghost_height = track_height - 1; p.setPen(QColor(255, 255, 0)); for (int j=0;jplayhead); + int playhead_x = panel_timeline->getScreenPointFromFrame(panel_timeline->playhead); p.drawLine(playhead_x, rect().top(), playhead_x, rect().bottom()); p.setPen(QColor(0, 0, 0, 64)); @@ -774,14 +774,14 @@ void TimelineWidget::paintEvent(QPaintEvent*) { // draw snap point if (panel_timeline->snapping && panel_timeline->snapped) { p.setPen(Qt::white); - int snap_x = getScreenPointFromFrame(panel_timeline->snap_point); + int snap_x = panel_timeline->getScreenPointFromFrame(panel_timeline->snap_point); p.drawLine(snap_x, 0, snap_x, height()); } // Draw edit cursor if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) { if (is_track_visible(panel_timeline->cursor_track)) { - int cursor_x = getScreenPointFromFrame(panel_timeline->cursor_frame); + int cursor_x = panel_timeline->getScreenPointFromFrame(panel_timeline->cursor_frame); int cursor_y = getScreenPointFromTrack(panel_timeline->cursor_track); p.setPen(Qt::gray); @@ -799,18 +799,6 @@ bool TimelineWidget::is_track_visible(int track) { // screen point <-> frame/track functions // ************************************** -long TimelineWidget::getFrameFromScreenPoint(int x, bool f) { - float div = (float) x / panel_timeline->zoom; - if (div < 0) { - return 0; - } - if (f) { - return floor(div); - } else { - return round(div); - } -} - int TimelineWidget::getTrackFromScreenPoint(int y) { if (bottom_align) { y -= rect().bottom(); @@ -823,10 +811,6 @@ int TimelineWidget::getTrackFromScreenPoint(int y) { return (int)floor((float) (y)/ (float) temp_track_height); } -int TimelineWidget::getScreenPointFromFrame(long frame) { - return (int) round(frame*panel_timeline->zoom); -} - int TimelineWidget::getScreenPointFromTrack(int track) { int temp_track_height = track_height; if (show_track_lines) temp_track_height++; diff --git a/ui/timelinewidget.h b/ui/timelinewidget.h index a743884ff..168bbb624 100644 --- a/ui/timelinewidget.h +++ b/ui/timelinewidget.h @@ -35,10 +35,8 @@ protected: private: void init_ghosts(); void update_ghosts(QPoint& mouse_pos); - bool is_track_visible(int track); - long getFrameFromScreenPoint(int x, bool floor); - int getTrackFromScreenPoint(int y); - int getScreenPointFromFrame(long frame); + bool is_track_visible(int track); + int getTrackFromScreenPoint(int y); int getScreenPointFromTrack(int track); int getClipIndexFromCoords(long frame, int track); int track_height;