Commit 25c1628e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Center view when seeking to timeline clip.

Fixes #844
parent 8fc74398
...@@ -201,6 +201,10 @@ Rectangle { ...@@ -201,6 +201,10 @@ Rectangle {
} }
return col return col
} }
function centerViewOnCursor() {
scrollView.contentX = Math.max(0, root.consumerPosition * timeline.scaleFactor - (scrollView.width / 2))
}
function clearDropData() { function clearDropData() {
clipBeingDroppedId = -1 clipBeingDroppedId = -1
......
...@@ -1653,6 +1653,7 @@ void TimelineController::focusItem(int itemId) ...@@ -1653,6 +1653,7 @@ void TimelineController::focusItem(int itemId)
{ {
int start = m_model->getItemPosition(itemId); int start = m_model->getItemPosition(itemId);
setPosition(start); setPosition(start);
emit centerView();
} }
int TimelineController::headerWidth() const int TimelineController::headerWidth() const
......
...@@ -697,6 +697,9 @@ signals: ...@@ -697,6 +697,9 @@ signals:
/* @brief User enabled / disabled snapping, update timeline behavior /* @brief User enabled / disabled snapping, update timeline behavior
*/ */
void snapChanged(); void snapChanged();
/* @brief Center timeline view on current position
*/
void centerView();
Q_INVOKABLE void ungrabHack(); Q_INVOKABLE void ungrabHack();
}; };
......
...@@ -87,6 +87,7 @@ void TimelineTabs::connectTimeline(TimelineWidget *timeline) ...@@ -87,6 +87,7 @@ void TimelineTabs::connectTimeline(TimelineWidget *timeline)
connect(timeline->controller(), &TimelineController::updateZoom, this, [&](double value) { emit updateZoom(getCurrentTimeline()->zoomForScale(value)); }); connect(timeline->controller(), &TimelineController::updateZoom, this, [&](double value) { emit updateZoom(getCurrentTimeline()->zoomForScale(value)); });
connect(timeline->controller(), &TimelineController::showItemEffectStack, this, &TimelineTabs::showItemEffectStack); connect(timeline->controller(), &TimelineController::showItemEffectStack, this, &TimelineTabs::showItemEffectStack);
connect(timeline->controller(), &TimelineController::showSubtitle, this, &TimelineTabs::showSubtitle); connect(timeline->controller(), &TimelineController::showSubtitle, this, &TimelineTabs::showSubtitle);
connect(timeline->controller(), &TimelineController::centerView, timeline, &TimelineWidget::slotCenterView);
} }
void TimelineTabs::disconnectTimeline(TimelineWidget *timeline) void TimelineTabs::disconnectTimeline(TimelineWidget *timeline)
......
...@@ -365,6 +365,11 @@ void TimelineWidget::slotChangeZoom(int value, bool zoomOnMouse) ...@@ -365,6 +365,11 @@ void TimelineWidget::slotChangeZoom(int value, bool zoomOnMouse)
m_proxy->setScaleFactorOnMouse(pixelScale / comboScale[value], zoomOnMouse); m_proxy->setScaleFactorOnMouse(pixelScale / comboScale[value], zoomOnMouse);
} }
void TimelineWidget::slotCenterView()
{
QMetaObject::invokeMethod(rootObject(), "centerViewOnCursor");
}
void TimelineWidget::slotFitZoom() void TimelineWidget::slotFitZoom()
{ {
QVariant returnedValue; QVariant returnedValue;
......
...@@ -66,6 +66,8 @@ protected: ...@@ -66,6 +66,8 @@ protected:
public slots: public slots:
void slotChangeZoom(int value, bool zoomOnMouse); void slotChangeZoom(int value, bool zoomOnMouse);
void slotFitZoom(); void slotFitZoom();
/* @brief Center timeline view on current timeline cursor position */
void slotCenterView();
void zoneUpdated(const QPoint &zone); void zoneUpdated(const QPoint &zone);
void zoneUpdatedWithUndo(const QPoint &oldZone, const QPoint &newZone); void zoneUpdatedWithUndo(const QPoint &oldZone, const QPoint &newZone);
/* @brief Favorite effects have changed, reload model for context menu */ /* @brief Favorite effects have changed, reload model for context menu */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment