summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Baptiste Mardelle <jb@kdenlive.org>2016-12-04 20:37:04 (GMT)
committerJean-Baptiste Mardelle <jb@kdenlive.org>2016-12-04 20:37:04 (GMT)
commitb753b3cfb55ce2eb3ad27a1c546d9b70fcd17265 (patch)
treec6dd42b99f7ae66573bb2dfbf235c1acac078056
parent12d1eb7ca5bd24ad88115c5cb6321f6a86cbe3d2 (diff)
Ctrl+Mouse Wheel now zooms on mouse position
BUG: 369198
-rw-r--r--src/mainwindow.cpp19
-rw-r--r--src/mainwindow.h6
-rw-r--r--src/timeline/customtrackview.cpp18
-rw-r--r--src/timeline/customtrackview.h6
-rw-r--r--src/timeline/timeline.cpp4
-rw-r--r--src/timeline/timeline.h2
6 files changed, 31 insertions, 24 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index da0c844..b602606 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1927,8 +1927,8 @@ void MainWindow::connectDocument()
connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), m_effectStack, SLOT(slotTransitionItemSelected(Transition*,int,QPoint,bool)), Qt::DirectConnection);
connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), this, SLOT(slotActivateTransitionView(Transition*)));
- connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
- connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
+ connect(trackView->projectView(), SIGNAL(zoomIn(bool)), this, SLOT(slotZoomIn(bool)));
+ connect(trackView->projectView(), SIGNAL(zoomOut(bool)), this, SLOT(slotZoomOut(bool)));
connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
connect(trackView, SIGNAL(displayMessage(QString,MessageType)), m_messageLabel, SLOT(setMessage(QString,MessageType)));
connect(trackView->projectView(), SIGNAL(displayMessage(QString,MessageType)), m_messageLabel, SLOT(setMessage(QString,MessageType)));
@@ -2640,15 +2640,15 @@ void MainWindow::slotAddVideoEffect(QAction *result)
}
-void MainWindow::slotZoomIn()
+void MainWindow::slotZoomIn(bool zoomOnMouse)
{
- m_zoomSlider->setValue(m_zoomSlider->value() - 1);
+ slotSetZoom(m_zoomSlider->value() - 1, zoomOnMouse);
slotShowZoomSliderToolTip();
}
-void MainWindow::slotZoomOut()
+void MainWindow::slotZoomOut(bool zoomOnMouse)
{
- m_zoomSlider->setValue(m_zoomSlider->value() + 1);
+ slotSetZoom(m_zoomSlider->value() + 1, zoomOnMouse);
slotShowZoomSliderToolTip();
}
@@ -2661,13 +2661,12 @@ void MainWindow::slotFitZoom()
}
}
-void MainWindow::slotSetZoom(int value)
+void MainWindow::slotSetZoom(int value, bool zoomOnMouse)
{
- value = qMax(m_zoomSlider->minimum(), value);
- value = qMin(m_zoomSlider->maximum(), value);
+ value = qBound(m_zoomSlider->minimum(), value, m_zoomSlider->maximum());
if (pCore->projectManager()->currentTimeline()) {
- pCore->projectManager()->currentTimeline()->slotChangeZoom(value);
+ pCore->projectManager()->currentTimeline()->slotChangeZoom(value, -1, zoomOnMouse);
}
m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 1fea110..014abf1 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -298,11 +298,11 @@ private slots:
/** @brief Sets the timeline zoom slider to @param value.
*
* Also disables zoomIn and zoomOut actions if they cannot be used at the moment. */
- void slotSetZoom(int value);
+ void slotSetZoom(int value, bool zoomOnMouse = false);
/** @brief Decreases the timeline zoom level by 1. */
- void slotZoomIn();
+ void slotZoomIn(bool zoomOnMouse = false);
/** @brief Increases the timeline zoom level by 1. */
- void slotZoomOut();
+ void slotZoomOut(bool zoomOnMouse = false);
/** @brief Makes the timeline zoom level fit the timeline content. */
void slotFitZoom();
/** @brief Updates the zoom slider tooltip to fit @param zoomlevel. */
diff --git a/src/timeline/customtrackview.cpp b/src/timeline/customtrackview.cpp
index 67b1052..4f66199 100644
--- a/src/timeline/customtrackview.cpp
+++ b/src/timeline/customtrackview.cpp
@@ -195,7 +195,7 @@ void CustomTrackView::initTools()
m_toolManagers.insert(AbstractToolManager::TrimType, trim);
m_toolManagers.insert(AbstractToolManager::SpacerType, new SpacerManager(this, m_commandStack));
m_toolManagers.insert(AbstractToolManager::ResizeType, new ResizeManager(this, m_commandStack));
-
+
AbstractToolManager *razorManager = new RazorManager(this, m_commandStack);
m_toolManagers.insert(AbstractToolManager::RazorType, razorManager);
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), razorManager, SLOT(updateTimelineItems()));
@@ -410,8 +410,8 @@ void CustomTrackView::wheelEvent(QWheelEvent * e)
{
if (e->modifiers() == Qt::ControlModifier) {
if (m_moveOpMode == None || m_moveOpMode == WaitingForConfirm || m_moveOpMode == ZoomTimeline) {
- if (e->delta() > 0) emit zoomIn();
- else emit zoomOut();
+ if (e->delta() > 0) emit zoomIn(true);
+ else emit zoomOut(true);
}
} else if (e->modifiers() == Qt::AltModifier) {
if (m_moveOpMode == None || m_moveOpMode == WaitingForConfirm || m_moveOpMode == ZoomTimeline) {
@@ -5854,10 +5854,11 @@ void CustomTrackView::setTool(ProjectTool tool)
m_currentToolManager->initTool(m_tracksHeight * m_scene->scale().y());
}
-void CustomTrackView::setScale(double scaleFactor, double verticalScale)
+void CustomTrackView::setScale(double scaleFactor, double verticalScale, bool zoomOnMouse)
{
QMatrix newmatrix;
+ int lastMousePos = getMousePos();
newmatrix = newmatrix.scale(scaleFactor, verticalScale);
m_scene->isZooming = true;
m_scene->setScale(scaleFactor, verticalScale);
@@ -5900,7 +5901,14 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height());
}
double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
- centerOn(QPointF(cursorPos(), verticalPos));
+ if (zoomOnMouse) {
+ // Zoom on mouse position
+ centerOn(QPointF(lastMousePos, verticalPos));
+ int diff = scaleFactor * (getMousePos() - lastMousePos);
+ horizontalScrollBar()->setValue(horizontalScrollBar()->value() - diff);
+ } else {
+ centerOn(QPointF(cursorPos(), verticalPos));
+ }
m_currentToolManager->updateTimelineItems();
m_scene->isZooming = false;
}
diff --git a/src/timeline/customtrackview.h b/src/timeline/customtrackview.h
index fbd3461..7c68fb9 100644
--- a/src/timeline/customtrackview.h
+++ b/src/timeline/customtrackview.h
@@ -79,7 +79,7 @@ public:
void deleteClip(ItemInfo info, bool refresh = true);
void addMarker(const QString &id, const CommentedTime &marker);
void addData(const QString &id, const QString &key, const QString &data);
- void setScale(double scaleFactor, double verticalScale);
+ void setScale(double scaleFactor, double verticalScale, bool zoomOnMouse = false);
void deleteClip(const QString &clipId, QUndoCommand *deleteCommand);
/** @brief An effect was dropped on @param clip */
void slotDropEffect(ClipItem *clip, QDomElement effect, GenTime pos, int track);
@@ -586,8 +586,8 @@ private slots:
signals:
void cursorMoved(int, int);
- void zoomIn();
- void zoomOut();
+ void zoomIn(bool zoomOnMouse);
+ void zoomOut(bool zoomOnMouse);
void mousePosition(int);
/** @brief A clip was selected in timeline, update the effect stack
* @param clip The clip
diff --git a/src/timeline/timeline.cpp b/src/timeline/timeline.cpp
index 827e3b1..3fdccc5 100644
--- a/src/timeline/timeline.cpp
+++ b/src/timeline/timeline.cpp
@@ -568,7 +568,7 @@ void Timeline::moveCursorPos(int pos)
m_trackview->setCursorPos(pos);
}
-void Timeline::slotChangeZoom(int horizontal, int vertical)
+void Timeline::slotChangeZoom(int horizontal, int vertical, bool zoomOnMouse)
{
m_ruler->setPixelPerMark(horizontal);
m_scale = (double) m_trackview->getFrameWidth() / m_ruler->comboScale[horizontal];
@@ -576,7 +576,7 @@ void Timeline::slotChangeZoom(int horizontal, int vertical)
if (vertical == -1) {
// user called zoom
m_doc->setZoom(horizontal, m_verticalZoom);
- m_trackview->setScale(m_scale, m_scene->scale().y());
+ m_trackview->setScale(m_scale, m_scene->scale().y(), zoomOnMouse);
} else {
m_verticalZoom = vertical;
if (m_verticalZoom == 0)
diff --git a/src/timeline/timeline.h b/src/timeline/timeline.h
index 5e317a6..ac340ce 100644
--- a/src/timeline/timeline.h
+++ b/src/timeline/timeline.h
@@ -191,7 +191,7 @@ public:
public slots:
void slotDeleteClip(const QString &clipId, QUndoCommand *deleteCommand);
- void slotChangeZoom(int horizontal, int vertical = -1);
+ void slotChangeZoom(int horizontal, int vertical = -1, bool zoomOnMouse = false);
void setDuration(int dur);
void slotSetZone(const QPoint &p, bool updateDocumentProperties = true);
/** @brief Save a snapshot image of current timeline view */