Fix and improve fit zoom: 1 click = fit zoom, 2 click = restore previous zoom

parent 82988191
Pipeline #1714 passed with stage
in 14 minutes and 53 seconds
......@@ -2590,13 +2590,7 @@ void MainWindow::slotZoomOut(bool zoomOnMouse)
void MainWindow::slotFitZoom()
{
/*
if (pCore->projectManager()->currentTimeline()) {
m_zoomSlider->setValue(pCore->projectManager()->currentTimeline()->fitZoom());
// Make sure to reset scroll bar to start
pCore->projectManager()->currentTimeline()->projectView()->scrollToStart();
}
*/
m_timelineTabs->fitZoom();
}
void MainWindow::slotSetZoom(int value, bool zoomOnMouse)
......
......@@ -33,6 +33,18 @@ Rectangle {
id: compositionMenu
}
function fitZoom() {
return scrollView.width / (timeline.duration * 1.1)
}
function scrollPos() {
return scrollView.flickableItem.contentX
}
function goToStart(pos) {
scrollView.flickableItem.contentX = pos
}
function updatePalette() {
root.color = activePalette.window
root.textColor = activePalette.text
......
......@@ -167,10 +167,6 @@ QMap<int, QString> TimelineController::getTrackNames(bool videoOnly)
void TimelineController::setScaleFactorOnMouse(double scale, bool zoomOnMouse)
{
/*if (m_duration * scale < width() - 160) {
// Don't allow scaling less than full project's width
scale = (width() - 160.0) / m_duration;
}*/
if (m_root) {
m_root->setProperty("zoomOnMouse", zoomOnMouse ? qMin(getMousePos(), duration()) : -1);
m_scale = scale;
......
......@@ -69,6 +69,7 @@ void TimelineTabs::connectTimeline(TimelineWidget *timeline)
connect(this, &TimelineTabs::showThumbnailsChanged, timeline->controller(), &TimelineController::showThumbnailsChanged);
connect(this, &TimelineTabs::showAudioThumbnailsChanged, timeline->controller(), &TimelineController::showAudioThumbnailsChanged);
connect(this, &TimelineTabs::changeZoom, timeline, &TimelineWidget::slotChangeZoom);
connect(this, &TimelineTabs::fitZoom, timeline, &TimelineWidget::slotFitZoom);
connect(timeline->controller(), &TimelineController::showTransitionModel, this, &TimelineTabs::showTransitionModel);
connect(timeline->controller(), &TimelineController::updateZoom, [&](double value) { emit updateZoom(getCurrentTimeline()->zoomForScale(value)); });
connect(timeline->controller(), &TimelineController::showItemEffectStack, this, &TimelineTabs::showItemEffectStack);
......
......@@ -70,6 +70,7 @@ signals:
This is an input signal, forwarded to the timelines
*/
void changeZoom(int value, bool zoomOnMouse);
void fitZoom();
/* @brief Requests that a given parameter model is displayed in the asset panel */
void showTransitionModel(int tid, std::shared_ptr<AssetParameterModel>);
/* @brief Requests that a given effectstack model is displayed in the asset panel */
......
......@@ -155,6 +155,26 @@ void TimelineWidget::slotChangeZoom(int value, bool zoomOnMouse)
m_proxy->setScaleFactorOnMouse(pixelScale / comboScale[value], zoomOnMouse);
}
void TimelineWidget::slotFitZoom()
{
QVariant returnedValue;
double prevScale = m_proxy->scaleFactor();
QMetaObject::invokeMethod(rootObject(), "fitZoom", Q_RETURN_ARG(QVariant, returnedValue));
double scale = returnedValue.toDouble();
QMetaObject::invokeMethod(rootObject(), "scrollPos", Q_RETURN_ARG(QVariant, returnedValue));
int scrollPos = returnedValue.toInt();
if (qFuzzyCompare(prevScale, scale)) {
scale = m_prevScale;
scrollPos = m_scrollPos;
} else {
m_prevScale = prevScale;
m_scrollPos = scrollPos;
scrollPos = 0;
}
m_proxy->setScaleFactorOnMouse(scale, false);
QMetaObject::invokeMethod(rootObject(), "goToStart", Q_ARG(QVariant, scrollPos));
}
Mlt::Tractor *TimelineWidget::tractor()
{
return m_proxy->tractor();
......
......@@ -59,6 +59,7 @@ protected:
public slots:
void slotChangeZoom(int value, bool zoomOnMouse);
void slotFitZoom();
void zoneUpdated(const QPoint &zone);
/* @brief Favorite effects have changed, reload model for context menu */
void updateEffectFavorites();
......@@ -77,6 +78,10 @@ private:
std::shared_ptr<AssetTreeModel> m_effectsModel;
std::unique_ptr<AssetFilter> m_effectsProxyModel;
std::unique_ptr<QSortFilterProxyModel> m_sortModel;
/* @brief Keep last scale before fit to restore it on second click */
double m_prevScale;
/* @brief Keep last scroll position before fit to restore it on second click */
int m_scrollPos;
/* @brief Returns an alphabetically sorted list of favorite effects or transitions */
const QStringList sortedItems(const QStringList &items, bool isTransition);
......
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